summaryrefslogblamecommitdiffstats
path: root/src/generator.c
blob: ab2206f9f48cf9c72c69ee0a065b279789fef551 (plain) (tree)
1
2
3
4
5
6
7
8

                      




                      
                                                              


                   
                                           


                




























































                                                                               
#include <libconfig.h>

#include "generator.h"



float
generate(generator * g, synth_t * s, int i, sound_node * root)
{
  float sample = 0;

  sampe = play_tree(root, s->midi_note[i]);
  
  return sample;
}

int
sound_tree_add_node(sound_node * root, const char * cmp)
{

}

int
load_preset(sound_node * tree, const char * path)
{
  config_t cfg;
  config_setting_t *setting, *x;
  const char *str;

  config_init(&cfg);
  if (! config_read_file(&cfg, "../preset.synth")) {
    fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
            config_error_line(&cfg), config_error_text(&cfg));
    config_destroy(&cfg);
    return(EXIT_FAILURE);
  }  
  setting = config_lookup(&cfg, "patch");
  if (setting != NULL) {
    int count = config_setting_length(setting);

    for(int i = 0; i < count; ++i) {
      x = config_setting_get_elem(setting, i);
      printf("%s = %f\n", config_setting_name(x), config_setting_get_float(x));
      // TODO
      sound_tree_add_node(tree, name);
    }
  }


  setting = config_tree_setting(&cfg);
  if (setting != NULL) {
    int count = config_setting_length(setting);

    for(int i = 0; i < count; ++i) {
      chat * name = config_setting_name(x);
      x = config_setting_get_elem(setting, i);
      printf("%s -- %d\n", config_setting_name(x), config_setting_type(x));

      if (name[0] == 'o') { // osc
        // TODO
        configure_osc(tree, id);
      } else if (name[0] == 'a') { // adsr
        // TODO
        configure_adsr(tree, id);
      } else if (name[0] == 'l') { // lfo
        // TODO
        configure_lfo(tree, id);
      } else {
        printf("%s: wrong!", name);
      }
    }
  }
  
  config_destroy(&cfg);

}