static void save_fxbp(SoundPlugin *plugin, wchar_t *wfilename, bool is_fxb){ Data *data = (Data*)plugin->data; AudioPluginInstance *instance = data->audio_instance; MemoryBlock memoryBlock; bool result = VSTPluginFormat::saveToFXBFile(instance, memoryBlock, is_fxb); if (result==false){ GFX_Message(NULL, "Unable to create FXB/FXP data for this plugin"); return; } String filename(wfilename); File file(filename); Result result2 = file.create(); if (result2.failed()){ GFX_Message(NULL, "Unable to create file %s (%s)", STRING_get_chars(wfilename), result2.getErrorMessage().toRawUTF8()); return; } bool result3 = file.replaceWithData(memoryBlock.getData(), memoryBlock.getSize()); if (result3==false){ GFX_Message(NULL, "Unable to write data to file %s (disk full?)", STRING_get_chars(wfilename)); return; } printf("\n\n\n ***************** result: %d\n\n\n\n",result); }
static const char *get_chars(const hash_t *hash, const char *key, int i){ hash_element_t *element = HASH_get(hash,key,i,STRING_TYPE); if(element==NULL) return NULL; return STRING_get_chars(element->a.string); }
// Has been used for debugging. Not sure if I planned to use it for anything else. void SAMPLER_save_sample(struct SoundPlugin *plugin, const wchar_t *filename, int sample_number){ Data *data = (Data*)plugin->data; const Sample *sample = &data->samples[sample_number]; SF_INFO sf_info; memset(&sf_info,0,sizeof(sf_info)); sf_info.samplerate = 22050; sf_info.channels = 1; sf_info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16; if(sf_format_check(&sf_info)==0){ fprintf (stderr, "\nFileformat not supported by libsndfile.\n"); return; } SNDFILE *sndfile = sf_open(STRING_get_chars(filename),SFM_WRITE,&sf_info); if(sndfile==NULL){ fprintf(stderr,"could not open file\n"); return; } sf_writef_float(sndfile,sample->sound,sample->num_frames); sf_close(sndfile); }
static float *load_interleaved_samples(const wchar_t *filename, SF_INFO *sf_info){ SNDFILE *sndfile = sf_open(STRING_get_chars(filename),SFM_READ,sf_info); if(sndfile==NULL) return NULL; float *ret = talloc_atomic(sizeof(float) * sf_info->channels * sf_info->frames); int allocated_frames = sf_info->frames; int total_read_frames = sf_readf_float(sndfile, ret, sf_info->frames); if(total_read_frames==0) return NULL; while(true){ float samples[1024*sf_info->channels]; int read_now = sf_readf_float(sndfile, samples, 1024); if(read_now==0) break; if(total_read_frames + read_now > allocated_frames){ allocated_frames = (total_read_frames+read_now) * 2; ret = talloc_realloc(ret, allocated_frames * sizeof(float) * sf_info->channels); } memcpy(ret + (total_read_frames*sf_info->channels), samples, sizeof(float)*1024*sf_info->channels); total_read_frames += read_now; } sf_close(sndfile); sf_info->frames = total_read_frames; return ret; }
const char *getSaveFilename(char *text, char *filetypes, char *dir){ struct Tracker_Windows *window=getWindowFromNum(-1);if(window==NULL) return ""; const wchar_t *ret = GFX_GetSaveFileName(window, NULL, text, STRING_create(dir), filetypes); if(ret==NULL) return ""; else return STRING_get_chars(ret); }
static void recreate_from_state(struct SoundPlugin *plugin, hash_t *state){ const wchar_t *filename = HASH_get_string(state, "filename"); int instrument_number = HASH_get_int(state, "instrument_number"); int resampler_type = HASH_get_int(state, "resampler_type"); if(filename==NULL){ RError("filename==NULL"); return; } if(set_new_sample(plugin,filename,instrument_number,resampler_type)==false) RWarning("Could not load soundfile \"%s\". (instrument number: %d)\n",STRING_get_chars(filename),instrument_number); }
void PLUGINHOST_load_fxbp(SoundPlugin *plugin, wchar_t *wfilename){ Data *data = (Data*)plugin->data; AudioPluginInstance *instance = data->audio_instance; String filename(wfilename); File file(filename); MemoryBlock memoryBlock; bool success = file.loadFileAsData(memoryBlock); if (success==false){ GFX_Message(NULL, "Unable to load %s", STRING_get_chars(wfilename)); return; } success = VSTPluginFormat::loadFromFXBFile(instance, memoryBlock.getData(), memoryBlock.getSize()); if (success==false){ GFX_Message(NULL, "Could not use %s for this plugin", STRING_get_chars(wfilename)); return; } printf("************** size: %d\n",(int)memoryBlock.getSize()); }
virtual void setGuiValue(dyn_t val){ { QAbstractButton *button = dynamic_cast<QAbstractButton*>(_widget); if (button!=NULL){ if(val.type==BOOL_TYPE) button->setChecked(val.bool_number); else handleError("Button->setValue received %s, expected BOOL_TYPE", DYN_type_name(val.type)); return; } } { QAbstractSlider *slider = dynamic_cast<QAbstractSlider*>(_widget); if (slider!=NULL){ if(val.type==INT_TYPE) slider->setValue(val.bool_number); else handleError("Slider->setValue received %s, expected INT_TYPE", DYN_type_name(val.type)); return; } } { QLabel *label = dynamic_cast<QLabel*>(_widget); if (label!=NULL){ if(val.type==STRING_TYPE) label->setText(STRING_get_qstring(val.string)); else handleError("Text->setValue received %s, expected STRING_TYPE", DYN_type_name(val.type)); return; } } { QLineEdit *line_edit = dynamic_cast<QLineEdit*>(_widget); if (line_edit!=NULL){ if(val.type==STRING_TYPE) line_edit->setText(STRING_get_qstring(val.string)); else handleError("Line->setValue received %s, expected STRING_TYPE", DYN_type_name(val.type)); return; } } { QTextEdit *text_edit = dynamic_cast<QTextEdit*>(_widget); if (text_edit!=NULL){ if(val.type==STRING_TYPE) text_edit->setPlainText(STRING_get_chars(val.string)); else handleError("Text->setValue received %s, expected STRING_TYPE", DYN_type_name(val.type)); return; } } { QSpinBox *spinbox = dynamic_cast<QSpinBox*>(_widget); if (spinbox!=NULL){ if (val.type==INT_TYPE) spinbox->setValue((int)val.int_number); else handleError("IntText->setValue received %s, expected INT_TYPE", DYN_type_name(val.type)); return; } } { QDoubleSpinBox *doublespinbox = dynamic_cast<QDoubleSpinBox*>(_widget); if (doublespinbox!=NULL){ if (val.type==FLOAT_TYPE) doublespinbox->setValue(val.float_number); else handleError("FloatText->setValue received %s, expected FLOAT_TYPE", DYN_type_name(val.type)); return; } } handleError("Gui #%d does not have a setValue method", _gui_num); }
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; }
static bool Load(const wchar_t *filename){ struct Root *newroot; dc.success=true; curr_disk_line = 0; dc.file=DISK_open_for_reading(filename); if(dc.file==NULL){ GFX_Message(NULL,"Could not open \"%s\" for loading\n",STRING_get_chars(filename)); return false; } DC_fgets(); if (dc.success==false) return false; if(strcmp("RADIUM SONG",dc.ls)){ GFX_Message(NULL,"First line in song was not 'RADIUM SONG', but '%s'. Last: %d\n",dc.ls,dc.ls[strlen(dc.ls)-1]); DISK_close_and_delete(dc.file); return false; } disk_load_version=DC_LoadF(); if (dc.success==false) return false; if(disk_load_version>0.4201 && disk_load_version<0.50){ disk_load_version=0.51; dc.colorize=true; dc.startcolor=5; }else{ dc.colorize=false; } #if 0 if (disk_load_version < 0.75){ GFX_Message(NULL, "<p>Note! The portamento behavior for polyphonic tracks changed in Radium V3.4.9" "</p>" "<p>" "Before Radium V3.4.9, the default final portamento value was the pitch value of the next note after the <i>start</i> of the note. " "Now, the default final portamento value is the pitch value of the next note after the <i>end</i> of the note." "</p>" "<p>" "Old songs with portamento in polyphonic tracks might not sound the same." "</p>" ); } #endif if(disk_load_version>DISKVERSION+0.0001){ GFX_Message(NULL,"Need a newer version of Radium to load this song. The song version is %f, while this program only supports %f.\n",disk_load_version,DISKVERSION); return false; }else{ printf("Song diskVersion: %f\n",disk_load_version); } dc.filename=filename; dc.playlist=NULL; DC_Next(); if (dc.success==false) return false; if(strcmp(dc.ls,"OSSTUFF")){ GFX_Message(NULL, "OSSTUFF not found, but: '%s'. File: '%s'\n",dc.ls,STRING_get_chars(filename)); DISK_close_and_delete(dc.file); EndProgram(); exit(4); } LoadOsStuff(); printf("dc.ls: -%s-\n",dc.ls); if(strcmp(dc.ls,"ROOT")){ GFX_Message(NULL, "ROOT not found. Found '%s' instead.\n", dc.ls); DISK_close_and_delete(dc.file); EndProgram(); exit(5); } newroot=LoadRoot(); DISK_close_and_delete(dc.file); if(!dc.success){ GFX_Message(NULL, "Loading failed.\n"); EndProgram(); exit(6); } ResetUndo(); #ifdef _AMIGA CloseHelpWindow(); CloseCPPWindowWindow(); CloseBlockSelectWindow(); #endif CloseAllTrackerWindows(); GL_lock();{ GL_pause_gl_thread_a_short_while(); }GL_unlock(); //GL_draw_lock();{ PLAYER_lock();{ //<-- Locks within locks are dangerous. But it doesn't matter since the player isn't playing now anyway. root=newroot; //BANG! }PLAYER_unlock(); //}GL_draw_unlock(); Undo_start_ignoring_undo_operations();{ DLoadRoot(newroot); }Undo_stop_ignoring_undo_operations(); GL_create_all(root->song->tracker_windows); if(COMMENT_show_after_loading()) COMMENTDIALOG_open(); #ifdef _AMIGA currpatch=-1; #endif ResetUndo(); return true; }
static SoundPluginType *create_plugin_type(const char *name, int uid, const wchar_t *file_or_identifier, SoundPluginTypeContainer *container){ //, const wchar_t *library_file_full_path){ printf("b02 %s\n",STRING_get_chars(file_or_identifier)); fflush(stdout); // return; SoundPluginType *plugin_type = (SoundPluginType*)calloc(1,sizeof(SoundPluginType)); TypeData *typeData = (TypeData*)calloc(1, sizeof(TypeData)); typeData->file_or_identifier = wcsdup(file_or_identifier); typeData->uid = uid; //typeData->library_file_full_path = wcsdup(library_file_full_path); typeData->wrapper_type = AudioProcessor::wrapperType_VST; plugin_type->data = typeData; plugin_type->type_name = "VST"; plugin_type->name = strdup(name); plugin_type->container = container; plugin_type->is_instrument = true; // we don't know yet, so we set it to true. plugin_type->buffer_size_is_changed = buffer_size_is_changed; plugin_type->RT_process = RT_process; plugin_type->create_plugin_data = create_plugin_data; plugin_type->cleanup_plugin_data = cleanup_plugin_data; plugin_type->gui_is_visible = gui_is_visible; plugin_type->show_gui = show_gui; plugin_type->hide_gui = hide_gui; plugin_type->play_note = play_note; plugin_type->set_note_volume = set_note_volume; plugin_type->stop_note = stop_note; plugin_type->send_raw_midi_message = send_raw_midi_message; plugin_type->get_effect_value = get_effect_value; plugin_type->set_effect_value = set_effect_value; plugin_type->get_display_value_string=get_display_value_string; plugin_type->get_effect_name=get_effect_name; plugin_type->get_effect_description=get_effect_description; plugin_type->create_state = create_state; plugin_type->recreate_from_state = recreate_from_state; plugin_type->get_num_presets = get_num_presets; plugin_type->get_current_preset = get_current_preset; plugin_type->set_current_preset = set_current_preset; plugin_type->get_preset_name = get_preset_name; plugin_type->set_preset_name = set_preset_name; printf("\n\n\nPopulated %s/%s\n",plugin_type->type_name,plugin_type->name); PR_add_plugin_type_no_menu(plugin_type); return plugin_type; }
void loadBlock(const char *filename_c){ struct Tracker_Windows *window=getWindowFromNum(-1);if(window==NULL) return; bool success = false; bool have_made_undo = false; if (filename_c==NULL || !strcmp(filename_c, "")) filename_c = "/tmp/block.block"; const wchar_t *filename = STRING_create(filename_c); int num_blocks = root->song->num_blocks; if (Load_Initialize(filename, "RADIUM BLOCK")==false) { goto exit; return; } if(strcmp(dc.ls,"WBLOCK")){ handleError("Loading failed.\nExpected \"WBLOCK\", but found instead: '%s'.\nFile: '%s'\n",dc.ls,STRING_get_chars(filename)); DISK_close_and_delete(dc.file); goto exit; return; } struct WBlocks *wblock = LoadWBlock(); wblock->l.num = num_blocks; DC_Next(); if(strcmp(dc.ls,"BLOCK")){ handleError("Loading failed.\nExpected \"BLOCK\", but found instead: '%s'.\nFile: '%s'\n",dc.ls,STRING_get_chars(filename)); DISK_close_and_delete(dc.file); goto exit; } struct Blocks *block = LoadBlock(); block->l.num = num_blocks; DISK_close_and_delete(dc.file); if(!dc.success){ handleError("Loading failed.\n"); goto exit; } printf("Got it: %p / %p\n",wblock,block); ADD_UNDO(Block_Insert(num_blocks)); have_made_undo = true; /* DC_ListAdd1(&root->song->blocks,block); DC_ListAdd1(&root->song->tracker_windows->wblocks, wblock); */ wblock->block = block; window->curr_track = 0; DLoadBlocks(root, block); DLoadWBlocks(window, window, wblock); CB_PasteBlock(window, wblock, window->wblock); success = true; exit: if (success==false) if (have_made_undo) Undo_CancelLastUndo(); }
static void *create_data(const wchar_t *filename, float samplerate){ Data *data = calloc(1,sizeof(Data)); data->pitch = 16384/2; data->pitch_range = 1; data->modulation = 0; data->sustain_on = 0; data->signal_from_RT = RSEMAPHORE_create(0); data->settings = new_fluid_settings(); if(data->settings==NULL){ RError("Unable to create fluidsynth settings"); delete_data(data); return NULL; } if(fluid_settings_setnum(data->settings, "synth.sample-rate", samplerate)==0){ RError("Unable to set sample rate of fluidsynth to %f\n",samplerate); //delete_data(data); //return NULL; } if(fluid_settings_setint(data->settings, "synth.threadsafe-api", 0)==0){ printf("Unable to set threadsafe-api to 0 (we don't need it)\n"); } if(fluid_settings_setint(data->settings, "synth.chorus.active", 0)==0){ printf("Unable to set synth.chorus.active to 0 (we don't use it)\n"); } if(fluid_settings_setint(data->settings, "synth.reverb.active", 0)==0){ printf("Unable to set synth.reverb.active to 0 (we don't use it)\n"); } // TODO: Decide whether we need fluidsynth's reverb and chorus. //fluid_settings_setstr(settings, "synth.reverb.active", "yes"); //fluid_settings_setstr(settings, "synth.chorus.active", "no"); data->synth = new_fluid_synth(data->settings); if(data->synth==NULL){ RError("Unable to create fluidsynth synth"); delete_data(data); return NULL; } data->sequencer = new_fluid_sequencer2(0); if(data->sequencer==NULL){ RError("Unable to create fluidsynth sequencer"); delete_data(data); return NULL; } fluid_sequencer_set_time_scale(data->sequencer, samplerate); // it's a shame that time in fluidsynth is only 32 bit. Hopefully the values wrap properly around....... data->time_scale = fluid_sequencer_get_time_scale(data->sequencer); data->samplerate = samplerate; #if 0 // This test always succeeds. Max time_scale in fluidsynth is 1000.0. :-( if( data->time_scale != sample_rate){ RError("Could not set time scale to %f (set to %f instead)\n",(float)samplerate,(float)fluid_sequencer_get_time_scale(data->sequencer)); } #endif data->synth_seq_ID = fluid_sequencer_register_fluidsynth(data->sequencer, data->synth); data->event = new_fluid_event(); if(data->event==NULL){ RError("Unable to create fluidsynth event"); delete_data(data); return NULL; } data->filename = wcsdup(OS_loading_get_resolved_file_path(filename)); data->soundfont_id = fluid_synth_sfload(data->synth,STRING_get_chars(data->filename),true); if(data->soundfont_id==FLUID_FAILED){ printf("Soundfont loading failed for \"%s\"\n",STRING_get_chars(data->filename)); delete_data(data); return NULL; } return data; }