int init(CSOUND *csound) { int result = OK; #pragma omp critical (critical_section_fluid_load) { soundFontId = -1; toa(iFluidSynth, fluidSynth); listPresets = (int) *iListPresets; CS_TYPE* argType = csound->GetTypeForArg(iFilename); if(strcmp("S", argType->varTypeName) == 0) filename = csound->Strdup(csound, ((STRINGDAT *)iFilename)->data); else filename = csound->strarg2name(csound, (char*) NULL, (std::isnan(*iFilename) ? csound->GetString(csound, *iFilename) : (char *) iFilename), (char *)"fluid.sf2.", std::isnan(*iFilename)); filepath = csound->FindInputFile(csound, filename, "SFDIR;SSDIR"); if (filepath && fluid_is_soundfont(filepath)) { log(csound, "Loading SoundFont : %s.\n", filepath); soundFontId = fluid_synth_sfload(fluidSynth, filepath, 0); log(csound, "fluidSynth: 0x%p soundFontId: %d.\n", fluidSynth, soundFontId); } *iInstrumentNumber = (MYFLT) soundFontId; if (soundFontId < 0) { csound->InitError(csound, Str("fluid: unable to load %s"), filename); } csound->NotifyFileOpened(csound, filepath, CSFTYPE_SOUNDFONT, 0, 0); if (soundFontId < 0) { result = NOTOK; } else if (listPresets) { fluid_sfont_t *fluidSoundfont = fluid_synth_get_sfont_by_id(fluidSynth, soundFontId); fluid_preset_t fluidPreset; fluidSoundfont->iteration_start(fluidSoundfont); OPARMS oparms; csound->GetOParms(csound, &oparms); if (oparms.msglevel & 0x7) while (fluidSoundfont->iteration_next(fluidSoundfont, &fluidPreset)) { log(csound, "SoundFont: %3d Bank: %3d Preset: %3d %s\n", soundFontId, fluidPreset.get_banknum(&fluidPreset), fluidPreset.get_num(&fluidPreset), fluidPreset.get_name(&fluidPreset)); } } } return result; }
/** Create temporary fluid synthesiser and get the list of presets for the combo box. */ static void get_presets(FluidUI *self) { fluid_preset_t p; fluid_settings_t *settings = new_fluid_settings(); fluid_synth_t *synth = new_fluid_synth(settings); fluid_synth_sfload(synth, SOUNDFONT_FILE, 1); fluid_sfont_t *sfont = fluid_synth_get_sfont_by_id(synth, 1); sfont->iteration_start(sfont); while (sfont->iteration_next(sfont, &p)) { gtk_combo_box_text_append_text((GtkComboBoxText *)self->combo_box, p.get_name(&p)); } delete_fluid_synth(synth); delete_fluid_settings(settings); }
QString ISynth::getPatchName(int /*ch*/, int val, bool /*drum*/) const { int prog = val & 0xff; if(val == MusECore::CTRL_VAL_UNKNOWN || prog == 0xff) return "<unknown>"; prog &= 0x7f; int hbank = (val & 0xff0000) >> 16; int lbank = (val & 0xff00) >> 8; if (hbank > 127) hbank = 0; if (lbank > 127) lbank = 0; if (lbank == 127) // drum HACK lbank = 128; const char* name = "<unknown>"; if (_busy) { //#ifdef FS_DEBUG printf("fluid: getPatchName(): busy!\n"); //#endif return name; } fluid_font = fluid_synth_get_sfont_by_id(_fluidsynth, hbank); if (fluid_font) { fluid_preset_t* preset = (*fluid_font->get_preset)(fluid_font, lbank, prog); if (preset) name = (*preset->get_name)(preset); else { //#ifdef FS_DEBUG fprintf(stderr, "no fluid preset for bank %d prog %d\n", lbank, prog); //#endif } } else fprintf(stderr, "ISynth::getPatchName(): no fluid font id=%d found\n", hbank); return name; }
/* * Class: org_tritonus_midi_sb_fluidsynth_FluidSoundbank * Method: nGetInstruments * Signature: (I)[Lorg/tritonus/midi/sb/fluidsynth/FluidSoundbank/FluidInstrument; */ JNIEXPORT jobjectArray JNICALL Java_org_tritonus_midi_sb_fluidsynth_FluidSoundbank_nGetInstruments (JNIEnv *env, jobject obj, jint sfontID) { //printf("3a\n"); //printf("4"); jclass fluidsoundbankclass; jfieldID synthFieldID; jobject synthobj; jclass fluidinstrclass; jmethodID initid; int count = 0; jobjectArray instruments; jstring instrname; jobject instrument; fluid_sfont_t* sfont; fluid_preset_t preset; int offset; int i = 0; fluid_synth_t* synth; fluidsoundbankclass = (*env)->FindClass(env, "org/tritonus/midi/sb/fluidsynth/FluidSoundbank"); synthFieldID = (*env)->GetFieldID(env, fluidsoundbankclass, "synth", "Lorg/tritonus/midi/device/fluidsynth/FluidSynthesizer;"); synthobj = (*env)->GetObjectField(env, obj, synthFieldID); synth = get_synth(env, synthobj); #ifdef VARIADIC_MACROS out("nGetInstruments: synth: %p\n", synth); #else if (debug_flag) { fprintf(debug_file, "nGetInstruments: synth: %p\n", synth); fflush(debug_file); } #endif if (synth) { fluidinstrclass = (*env)->FindClass(env, "org/tritonus/midi/sb/fluidsynth/FluidSoundbank$FluidInstrument"); if (!fluidinstrclass) printf("could not get class id"); //printf("5"); initid = (*env)->GetMethodID(env, fluidinstrclass, "<init>", "(Lorg/tritonus/midi/sb/fluidsynth/FluidSoundbank;IILjava/lang/String;)V"); if (!initid) printf("could not get method id"); //printf("6"); sfont = fluid_synth_get_sfont_by_id(synth, sfontID); if (sfont != NULL) { sfont->iteration_start(sfont); while (sfont->iteration_next(sfont, &preset)) { count++; } } //printf("7"); instruments = (*env)->NewObjectArray(env, count, fluidinstrclass, NULL); sfont = fluid_synth_get_sfont_by_id(synth, sfontID); offset = fluid_synth_get_bank_offset(synth, sfontID); if (sfont == NULL) return 0; sfont->iteration_start(sfont); while (sfont->iteration_next(sfont, &preset)) { instrname = (*env)->NewStringUTF(env, // fluid_preset_get_name(&preset) preset.get_name(&preset) ); instrument = (*env)->NewObject(env, fluidinstrclass, initid, obj, // (jint) fluid_preset_get_banknum(&preset) + offset, (jint) (preset.get_banknum(&preset) + offset), // (jint) fluid_preset_get_num(&preset), (jint) (preset.get_num(&preset)), (jobject) instrname); (*env)->SetObjectArrayElement(env, instruments, i++, instrument); } return instruments; } else return NULL; }