示例#1
0
bool FLUIDSYNTH_set_new_preset(SoundPlugin *plugin, const wchar_t *sf2_file, int bank_num, int preset_num){
  Data *data = plugin->data;

  if(!STRING_equals2(sf2_file, data->filename)){

    Data *new_data = create_data(sf2_file, data->samplerate);
    if(new_data==NULL)
      return false;

    if(SP_is_plugin_running(plugin)){

      PLAYER_lock();{  // Hmm. lock for setting a variable type that is atomic on all target platforms?
        data->new_data = new_data;
      }PLAYER_unlock();
      
      RSEMAPHORE_wait(data->signal_from_RT,1);

    } else{

      plugin->data = new_data;

    }

    delete_data(data);
    data = new_data;
  }

  data->bank_num = bank_num;
  data->preset_num = preset_num;

  fluid_synth_bank_select(data->synth,0,bank_num);
  fluid_synth_program_change(data->synth,0,preset_num);

  if(plugin->patch != NULL)
    GFX_update_instrument_widget(plugin->patch);

  return true;
}
示例#2
0
hash_t *HASH_load(disk_t *file){

  wchar_t *line = L"";
  while(STRING_starts_with(line, "#") || STRING_equals2(STRING_trim(line), L""))
    line = READ_LINE(file);
  
  int version;
  if(STRING_equals(line,">> HASH MAP BEGIN")){
    version = 1;
  } else if (STRING_equals(line,">> HASH MAP V2 BEGIN")){
    version = 2;
  } else if (STRING_equals(line,">> HASH MAP V3 BEGIN")){
    version = 3;
  } else  if (STRING_starts_with(line, ">> HASH MAP V")){
    version = 3;
    vector_t v = {0};
    int try_anyway = VECTOR_push_back(&v, "Try anyway (program might crash and/or behave unstable)");
    int ok = VECTOR_push_back(&v, "Ok");

    int res = GFX_Message(&v, "Need a newer version of Radium to load this file");

    if (res!=try_anyway)
      return NULL;
    (void)ok;

  } else {
    GFX_Message(NULL, "Trying to load something which is not a hash map. First line: \"%S\"", line);
    return NULL;
  }

  line = READ_LINE(file);
  
  int elements_size = STRING_get_int(line);

  hash_t *hash=HASH_create(elements_size);
  hash->version = version;

  line = READ_LINE(file);
  
  while(!STRING_equals(line,"<< HASH MAP END") && !STRING_equals(line,"<< HASH MAP V2 END") && !STRING_equals(line,"<< HASH MAP V3 END")){
    const char *key = STRING_get_chars(line);
    int i = 0;

    if(version > 1){

      line = READ_LINE(file);
      
      i = STRING_get_int(line);
      int new_size = i+1;
      if(new_size > hash->num_array_elements)
        hash->num_array_elements = new_size;

    } else if(!strncmp(key,"<int hash>",strlen("<int hash>"))) {

      sscanf(key, "<int hash> %d", &i);
      key = "";
      hash->num_array_elements++;

    }

    bool success;
    dyn_t dyn = DYN_load(file, &success);
    if (!success)
      return NULL;

    put_dyn(hash, key, i, dyn);
            
    line = READ_LINE(file);
  }

  return hash;  
}