From 3c14435a8ccc15cb78ce581bb6509713da9e8b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernat=20Arlandis=20i=20Ma=C3=B1=C3=B3?= Date: Mon, 23 Mar 2009 15:58:33 +0000 Subject: [PATCH 1/8] Command handler decoupled. Moved config file loading after starting everything. --- include/fluidsynth/shell.h | 12 +- include/fluidsynth/synth.h | 28 ++- include/fluidsynth/types.h | 2 +- src/bindings/fluid_cmd.c | 476 +++++++++++++++++++++++++------------ src/bindings/fluid_cmd.h | 91 +++---- src/fluidsynth.c | 49 ++-- 6 files changed, 425 insertions(+), 233 deletions(-) diff --git a/include/fluidsynth/shell.h b/include/fluidsynth/shell.h index ba0ebf4c..bb32bf7c 100644 --- a/include/fluidsynth/shell.h +++ b/include/fluidsynth/shell.h @@ -63,11 +63,16 @@ typedef struct { char* help; /**< A help string */ } fluid_cmd_t; +typedef struct { + fluid_synth_t* synth; + fluid_midi_router_t* router; + fluid_cmd_hash_t* commands; +} fluid_cmd_handler_t; /* The command handler */ FLUIDSYNTH_API -fluid_cmd_handler_t* new_fluid_cmd_handler(fluid_synth_t* synth); +fluid_cmd_handler_t* new_fluid_cmd_handler(fluid_synth_t* synth, fluid_midi_router_t* router); FLUIDSYNTH_API void delete_fluid_cmd_handler(fluid_cmd_handler_t* handler); @@ -112,12 +117,11 @@ FLUIDSYNTH_API void delete_fluid_shell(fluid_shell_t* shell); * @param addr The IP address of the client (can be NULL) * @return Should return a new command handler for the connection (new_fluid_cmd_handler()). */ -typedef fluid_cmd_handler_t* (*fluid_server_newclient_func_t)(void* data, char* addr); +typedef fluid_cmd_handler_t* (*fluid_server_newclient_func_t)(void* data, char* addr, char* addr2); FLUIDSYNTH_API fluid_server_t* new_fluid_server(fluid_settings_t* settings, - fluid_server_newclient_func_t func, - void* data); + fluid_cmd_handler_t* handler); FLUIDSYNTH_API void delete_fluid_server(fluid_server_t* server); diff --git a/include/fluidsynth/synth.h b/include/fluidsynth/synth.h index e3803d33..71d60cef 100644 --- a/include/fluidsynth/synth.h +++ b/include/fluidsynth/synth.h @@ -139,8 +139,19 @@ FLUIDSYNTH_API int fluid_synth_get_bank_offset(fluid_synth_t* synth, int sfont_i /* Reverb */ -FLUIDSYNTH_API void fluid_synth_set_reverb(fluid_synth_t* synth, double roomsize, - double damping, double width, double level); + /* + * + * Reverb + * + */ + + /** Set the parameters for the built-in reverb unit */ +FLUIDSYNTH_API void fluid_synth_set_reverb_roomsize(fluid_synth_t* synth, double roomsize); +FLUIDSYNTH_API void fluid_synth_set_reverb_damp(fluid_synth_t* synth, double damping); +FLUIDSYNTH_API void fluid_synth_set_reverb_width(fluid_synth_t* synth, double width); +FLUIDSYNTH_API void fluid_synth_set_reverb_level(fluid_synth_t* synth, double level); + + /** Turn on (1) / off (0) the built-in reverb unit */ FLUIDSYNTH_API void fluid_synth_set_reverb_on(fluid_synth_t* synth, int on); FLUIDSYNTH_API double fluid_synth_get_reverb_roomsize(fluid_synth_t* synth); FLUIDSYNTH_API double fluid_synth_get_reverb_damp(fluid_synth_t* synth); @@ -163,8 +174,17 @@ enum fluid_chorus_mod { FLUID_CHORUS_MOD_TRIANGLE = 1 /**< Triangle wave chorus modulation */ }; -FLUIDSYNTH_API void fluid_synth_set_chorus(fluid_synth_t* synth, int nr, double level, - double speed, double depth_ms, int type); + /** Set up the chorus. It should be turned on with fluid_synth_set_chorus_on. + * If faulty parameters are given, all new settings are discarded. + * Keep in mind, that the needed CPU time is proportional to 'nr'. + */ +FLUIDSYNTH_API void fluid_synth_set_chorus_nr(fluid_synth_t* synth, int nr); +FLUIDSYNTH_API void fluid_synth_set_chorus_level(fluid_synth_t* synth, double level); +FLUIDSYNTH_API void fluid_synth_set_chorus_speed(fluid_synth_t* synth, double speed); +FLUIDSYNTH_API void fluid_synth_set_chorus_depth(fluid_synth_t* synth, double depth_ms); +FLUIDSYNTH_API void fluid_synth_set_chorus_type(fluid_synth_t* synth, int type); + + /** Turn on (1) / off (0) the built-in chorus unit */ FLUIDSYNTH_API void fluid_synth_set_chorus_on(fluid_synth_t* synth, int on); FLUIDSYNTH_API int fluid_synth_get_chorus_nr(fluid_synth_t* synth); FLUIDSYNTH_API double fluid_synth_get_chorus_level(fluid_synth_t* synth); diff --git a/include/fluidsynth/types.h b/include/fluidsynth/types.h index a019bbde..82b2624e 100644 --- a/include/fluidsynth/types.h +++ b/include/fluidsynth/types.h @@ -49,7 +49,7 @@ typedef struct _fluid_midi_event_t fluid_midi_event_t; /**< MIDI event typedef struct _fluid_midi_driver_t fluid_midi_driver_t; /**< MIDI driver instance */ typedef struct _fluid_midi_router_t fluid_midi_router_t; /**< MIDI router instance */ typedef struct _fluid_midi_router_rule_t fluid_midi_router_rule_t; /**< MIDI router rule */ -typedef struct _fluid_hashtable_t fluid_cmd_handler_t; /**< Command handler */ +typedef struct _fluid_hashtable_t fluid_cmd_hash_t; /**< Command handler hash table */ typedef struct _fluid_shell_t fluid_shell_t; /**< Command shell */ typedef struct _fluid_server_t fluid_server_t; /**< TCP/IP shell server instance */ typedef struct _fluid_event_t fluid_event_t; /**< Sequencer event */ diff --git a/src/bindings/fluid_cmd.c b/src/bindings/fluid_cmd.c index 5c2267e3..68408d98 100644 --- a/src/bindings/fluid_cmd.c +++ b/src/bindings/fluid_cmd.c @@ -68,6 +68,8 @@ fluid_cmd_t fluid_commands[] = { "help Show help topics ('help TOPIC' for more info)" }, { "quit", "general", (fluid_cmd_func_t) fluid_handle_quit, NULL, "quit Quit the synthesizer" }, + { "source", "general", (fluid_cmd_func_t) fluid_handle_source, NULL, + "source filename Load a file and parse every line as a command" }, { "noteon", "event", (fluid_cmd_func_t) fluid_handle_noteon, NULL, "noteon chan key vel Send noteon" }, { "noteoff", "event", (fluid_cmd_func_t) fluid_handle_noteoff, NULL, @@ -162,19 +164,19 @@ fluid_cmd_t fluid_commands[] = { { "ladspa_setnode", "ladspa", (fluid_cmd_func_t) fluid_LADSPA_handle_setnode, NULL, "ladspa_setnode node value Assigns `value' to `node'"}, #endif - { "router_clear", "router", (fluid_cmd_func_t) fluid_midi_router_handle_clear, NULL, + { "router_clear", "router", (fluid_cmd_func_t) fluid_handle_router_clear, NULL, "router_clear Clears all routing rules from the midi router"}, - { "router_default", "router", (fluid_cmd_func_t) fluid_midi_router_handle_default, NULL, + { "router_default", "router", (fluid_cmd_func_t) fluid_handle_router_default, NULL, "router_default Resets the midi router to default state"}, - { "router_begin", "router", (fluid_cmd_func_t) fluid_midi_router_handle_begin, NULL, + { "router_begin", "router", (fluid_cmd_func_t) fluid_handle_router_begin, NULL, "router_begin [note|cc|prog|pbend|cpress|kpress]: Starts a new routing rule"}, - { "router_chan", "router", (fluid_cmd_func_t) fluid_midi_router_handle_chan, NULL, + { "router_chan", "router", (fluid_cmd_func_t) fluid_handle_router_chan, NULL, "router_chan min max mul add filters and maps midi channels on current rule"}, - { "router_par1", "router", (fluid_cmd_func_t) fluid_midi_router_handle_par1, NULL, + { "router_par1", "router", (fluid_cmd_func_t) fluid_handle_router_par1, NULL, "router_par1 min max mul add filters and maps parameter 1 (key/ctrl nr)"}, - { "router_par2", "router", (fluid_cmd_func_t) fluid_midi_router_handle_par2, NULL, + { "router_par2", "router", (fluid_cmd_func_t) fluid_handle_router_par2, NULL, "router_par2 min max mul add filters and maps parameter 2 (vel/cc val)"}, - { "router_end", "router", (fluid_cmd_func_t) fluid_midi_router_handle_end, NULL, + { "router_end", "router", (fluid_cmd_func_t) fluid_handle_router_end, NULL, "router_end closes and commits the current routing rule"}, { NULL, NULL, NULL, NULL, NULL } }; @@ -407,7 +409,7 @@ fluid_get_sysconf(char* buf, int len) * handlers */ int -fluid_handle_noteon(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_noteon(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { if (ac < 3) { fluid_ostream_printf(out, "noteon: too few arguments\n"); @@ -417,11 +419,11 @@ fluid_handle_noteon(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out fluid_ostream_printf(out, "noteon: invalid argument\n"); return -1; } - return fluid_synth_noteon(synth, atoi(av[0]), atoi(av[1]), atoi(av[2])); + return fluid_synth_noteon(handler->synth, atoi(av[0]), atoi(av[1]), atoi(av[2])); } int -fluid_handle_noteoff(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_noteoff(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { if (ac < 2) { fluid_ostream_printf(out, "noteoff: too few arguments\n"); @@ -431,11 +433,11 @@ fluid_handle_noteoff(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t ou fluid_ostream_printf(out, "noteon: invalid argument\n"); return -1; } - return fluid_synth_noteoff(synth, atoi(av[0]), atoi(av[1])); + return fluid_synth_noteoff(handler->synth, atoi(av[0]), atoi(av[1])); } int -fluid_handle_pitch_bend(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_pitch_bend(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { if (ac < 2) { fluid_ostream_printf(out, "pitch_bend: too few arguments\n"); @@ -449,7 +451,7 @@ fluid_handle_pitch_bend(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t } int -fluid_handle_pitch_bend_range(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_pitch_bend_range(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int channum; int value; @@ -468,7 +470,7 @@ fluid_handle_pitch_bend_range(fluid_synth_t* synth, int ac, char** av, fluid_ost } int -fluid_handle_cc(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_cc(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { if (ac < 3) { fluid_ostream_printf(out, "cc: too few arguments\n"); @@ -478,11 +480,11 @@ fluid_handle_cc(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) fluid_ostream_printf(out, "cc: invalid argument\n"); return -1; } - return fluid_synth_cc(synth, atoi(av[0]), atoi(av[1]), atoi(av[2])); + return fluid_synth_cc(handler->synth, atoi(av[0]), atoi(av[1]), atoi(av[2])); } int -fluid_handle_prog(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_prog(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { if (ac < 2) { fluid_ostream_printf(out, "prog: too few arguments\n"); @@ -492,11 +494,11 @@ fluid_handle_prog(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) fluid_ostream_printf(out, "prog: invalid argument\n"); return -1; } - return fluid_synth_program_change(synth, atoi(av[0]), atoi(av[1])); + return fluid_synth_program_change(handler->synth, atoi(av[0]), atoi(av[1])); } int -fluid_handle_select(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_select(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int sfont_id; int chan; @@ -519,17 +521,17 @@ fluid_handle_select(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out prog = atoi(av[3]); if (sfont_id != 0) { - return fluid_synth_program_select(synth, chan, sfont_id, bank, prog); + return fluid_synth_program_select(handler->synth, chan, sfont_id, bank, prog); } else { - if (fluid_synth_bank_select(synth, chan, bank) == FLUID_OK) { - return fluid_synth_program_change(synth, chan, prog); + if (fluid_synth_bank_select(handler->synth, chan, bank) == FLUID_OK) { + return fluid_synth_program_change(handler->synth, chan, prog); } return FLUID_FAILED; } } int -fluid_handle_inst(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_inst(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int font; fluid_sfont_t* sfont; @@ -548,8 +550,8 @@ fluid_handle_inst(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) font = atoi(av[0]); - sfont = fluid_synth_get_sfont_by_id(synth, font); - offset = fluid_synth_get_bank_offset(synth, font); + sfont = fluid_synth_get_sfont_by_id(handler->synth, font); + offset = fluid_synth_get_bank_offset(handler->synth, font); if (sfont == NULL) { fluid_ostream_printf(out, "inst: invalid font number\n"); @@ -570,7 +572,7 @@ fluid_handle_inst(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) int -fluid_handle_channels(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_channels(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { fluid_synth_channel_info_t info; int verbose = 0; @@ -578,24 +580,22 @@ fluid_handle_channels(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t o if (ac > 0 && strcmp( av[0], "-verbose") == 0) verbose = 1; - for (i = 0; i < fluid_synth_count_midi_channels (synth); i++) - { - fluid_synth_get_channel_info (synth, i, &info); - - if (!verbose) - fluid_ostream_printf (out, "chan %d, %s\n", i, - info.assigned ? info.name : "no preset"); - else - fluid_ostream_printf (out, "chan %d, sfont %d, bank %d, preset %d, %s\n", i, - info.sfont_id, info.bank, info.program, - info.assigned ? info.name : "no preset"); + for (i = 0; i < fluid_synth_count_midi_channels(handler->synth); i++) { + preset = fluid_synth_get_channel_preset(handler->synth, i); + if (preset == NULL) fluid_ostream_printf(out, "chan %d, no preset\n", i); + else if (!verbose) fluid_ostream_printf(out, "chan %d, %s\n", i, fluid_preset_get_name(preset)); + else fluid_ostream_printf(out, "chan %d, sfont %d, bank %d, preset %d, %s\n", i, + fluid_sfont_get_id( preset->sfont), + fluid_preset_get_banknum(preset), + fluid_preset_get_num(preset), + fluid_preset_get_name(preset)); } return 0; } int -fluid_handle_load(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_load(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { char buf[1024]; int id; @@ -615,7 +615,7 @@ fluid_handle_load(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) /* Load the SoundFont without resetting the programs. The reset will * be done later (if requested). */ - id = fluid_synth_sfload(synth, fluid_expand_path(av[0], buf, 1024), 0); + id = fluid_synth_sfload(handler->synth, fluid_expand_path(av[0], buf, 1024), 0); if (id == -1) { fluid_ostream_printf(out, "failed to load the SoundFont\n"); @@ -625,19 +625,19 @@ fluid_handle_load(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) } if (offset) { - fluid_synth_set_bank_offset(synth, id, offset); + fluid_synth_set_bank_offset(handler->synth, id, offset); } /* The reset should be done after the offset is set. */ if (reset) { - fluid_synth_program_reset(synth); + fluid_synth_program_reset(handler->synth); } return 0; } int -fluid_handle_unload(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_unload(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int reset = 1; if (ac < 1) { @@ -651,7 +651,7 @@ fluid_handle_unload(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out if (ac == 2) { reset = atoi(av[1]); } - if (fluid_synth_sfunload(synth, atoi(av[0]), reset) != 0) { + if (fluid_synth_sfunload(handler->synth, atoi(av[0]), reset) != 0) { fluid_ostream_printf(out, "failed to unload the SoundFont\n"); return -1; } @@ -659,7 +659,7 @@ fluid_handle_unload(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out } int -fluid_handle_reload(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_reload(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { if (ac < 1) { fluid_ostream_printf(out, "reload: too few arguments\n"); @@ -669,7 +669,7 @@ fluid_handle_reload(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out fluid_ostream_printf(out, "reload: expected a number as argument\n"); return -1; } - if (fluid_synth_sfreload(synth, atoi(av[0])) == -1) { + if (fluid_synth_sfreload(handler->synth, atoi(av[0])) == -1) { fluid_ostream_printf(out, "failed to reload the SoundFont\n"); return -1; } @@ -678,13 +678,13 @@ fluid_handle_reload(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out int -fluid_handle_fonts(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_fonts(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int i; fluid_sfont_t* sfont; int num; - num = fluid_synth_sfcount(synth); + num = fluid_synth_sfcount(handler->synth); if (num == 0) { fluid_ostream_printf(out, "no SoundFont loaded (try load)\n"); @@ -694,7 +694,7 @@ fluid_handle_fonts(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) fluid_ostream_printf(out, "ID Name\n"); for (i = 0; i < num; i++) { - sfont = fluid_synth_get_sfont(synth, i); + sfont = fluid_synth_get_sfont(handler->synth, i); if (sfont) { fluid_ostream_printf(out, "%2d %s\n", fluid_sfont_get_id(sfont), @@ -709,7 +709,7 @@ fluid_handle_fonts(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) } int -fluid_handle_mstat(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_mstat(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { /* fluid_ostream_printf(out, "Dvr=%s, Dev=%s\n", */ /* fluid_midi_handler_get_driver_name(midi), */ @@ -729,7 +729,7 @@ fluid_handle_mstat(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) * Response to 'rev_preset' command. * Load the values from a reverb preset into the reverb unit. */ int -fluid_handle_reverbpreset(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_reverbpreset(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int reverb_preset_number; if (ac < 1) { @@ -737,7 +737,7 @@ fluid_handle_reverbpreset(fluid_synth_t* synth, int ac, char** av, fluid_ostream return -1; } reverb_preset_number = atoi(av[0]); - if (fluid_synth_set_reverb_preset(synth, reverb_preset_number)!=FLUID_OK){ + if (fluid_synth_set_reverb_preset(handler->synth, reverb_preset_number)!=FLUID_OK){ fluid_ostream_printf(out, "rev_preset: Failed. Parameter out of range?\n"); return -1; }; @@ -748,7 +748,7 @@ fluid_handle_reverbpreset(fluid_synth_t* synth, int ac, char** av, fluid_ostream * Response to 'rev_setroomsize' command. * Load the new room size into the reverb unit. */ int -fluid_handle_reverbsetroomsize(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_reverbsetroomsize(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { fluid_real_t room_size; if (ac < 1) { @@ -764,8 +764,7 @@ fluid_handle_reverbsetroomsize(fluid_synth_t* synth, int ac, char** av, fluid_os fluid_ostream_printf(out, "rev_setroomsize: Room size too big!\n"); return -1; } - fluid_synth_set_reverb_full (synth, FLUID_REVMODEL_SET_ROOMSIZE, - room_size, 0.0, 0.0, 0.0); + fluid_synth_set_reverb_roomsize(handler->synth, room_size); return 0; } @@ -773,7 +772,7 @@ fluid_handle_reverbsetroomsize(fluid_synth_t* synth, int ac, char** av, fluid_os * Response to 'rev_setdamp' command. * Load the new damp factor into the reverb unit. */ int -fluid_handle_reverbsetdamp(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_reverbsetdamp(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { fluid_real_t damp; if (ac < 1) { @@ -785,8 +784,7 @@ fluid_handle_reverbsetdamp(fluid_synth_t* synth, int ac, char** av, fluid_ostrea fluid_ostream_printf(out, "rev_setdamp: damp must be between 0 and 1!\n"); return -1; } - fluid_synth_set_reverb_full (synth, FLUID_REVMODEL_SET_DAMPING, - 0.0, damp, 0.0, 0.0); + fluid_synth_set_reverb_damp(handler->synth, damp); return 0; } @@ -794,7 +792,7 @@ fluid_handle_reverbsetdamp(fluid_synth_t* synth, int ac, char** av, fluid_ostrea * Response to 'rev_setwidth' command. * Load the new width into the reverb unit. */ int -fluid_handle_reverbsetwidth(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_reverbsetwidth(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { fluid_real_t width; if (ac < 1) { @@ -806,8 +804,7 @@ fluid_handle_reverbsetwidth(fluid_synth_t* synth, int ac, char** av, fluid_ostre fluid_ostream_printf(out, "rev_setroomsize: Too wide! (0..100)\n"); return 0; } - fluid_synth_set_reverb_full (synth, FLUID_REVMODEL_SET_WIDTH, - 0.0, 0.0, width, 0.0); + fluid_synth_set_reverb_width(handler->synth, width); return 0; } @@ -815,7 +812,7 @@ fluid_handle_reverbsetwidth(fluid_synth_t* synth, int ac, char** av, fluid_ostre * Response to 'rev_setlevel' command. * Load the new level into the reverb unit. */ int -fluid_handle_reverbsetlevel(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_reverbsetlevel(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { fluid_real_t level; if (ac < 1) { @@ -827,8 +824,7 @@ fluid_handle_reverbsetlevel(fluid_synth_t* synth, int ac, char** av, fluid_ostre fluid_ostream_printf(out, "rev_setlevel: Value too high! (Value of 10 =+20 dB)\n"); return 0; } - fluid_synth_set_reverb_full (synth, FLUID_REVMODEL_SET_LEVEL, - 0.0, 0.0, 0.0, level); + fluid_synth_set_reverb_level(handler->synth, level); return 0; } @@ -836,7 +832,7 @@ fluid_handle_reverbsetlevel(fluid_synth_t* synth, int ac, char** av, fluid_ostre * Response to 'reverb' command. * Change the FLUID_REVERB flag in the synth */ int -fluid_handle_reverb(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_reverb(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { if (ac < 1) { fluid_ostream_printf(out, "reverb: too few arguments.\n"); @@ -844,9 +840,9 @@ fluid_handle_reverb(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out } if ((strcmp(av[0], "0") == 0) || (strcmp(av[0], "off") == 0)) { - fluid_synth_set_reverb_on(synth,0); + fluid_synth_set_reverb_on(handler->synth,0); } else if ((strcmp(av[0], "1") == 0) || (strcmp(av[0], "on") == 0)) { - fluid_synth_set_reverb_on(synth,1); + fluid_synth_set_reverb_on(handler->synth,1); } else { fluid_ostream_printf(out, "reverb: invalid arguments %s [0|1|on|off]", av[0]); return -1; @@ -859,7 +855,7 @@ fluid_handle_reverb(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out /* Purpose: * Response to 'chorus_setnr' command */ int -fluid_handle_chorusnr(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_chorusnr(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int nr; if (ac < 1) { @@ -867,13 +863,14 @@ fluid_handle_chorusnr(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t o return -1; } nr = atoi(av[0]); - return fluid_synth_set_chorus_full (synth, FLUID_CHORUS_SET_NR, nr, 0.0, 0.0, 0.0, 0); + fluid_synth_set_chorus_nr(handler->synth, nr); + return 0; } /* Purpose: * Response to 'chorus_setlevel' command */ int -fluid_handle_choruslevel(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_choruslevel(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { fluid_real_t level; if (ac < 1) { @@ -881,13 +878,15 @@ fluid_handle_choruslevel(fluid_synth_t* synth, int ac, char** av, fluid_ostream_ return -1; } level = atof(av[0]); - return fluid_synth_set_chorus_full (synth, FLUID_CHORUS_SET_LEVEL, 0, level, 0.0, 0.0, 0); + fluid_synth_set_chorus_level(handler->synth, level); + return 0; + } /* Purpose: * Response to 'chorus_setspeed' command */ int -fluid_handle_chorusspeed(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_chorusspeed(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { fluid_real_t speed; if (ac < 1) { @@ -895,13 +894,14 @@ fluid_handle_chorusspeed(fluid_synth_t* synth, int ac, char** av, fluid_ostream_ return -1; } speed = atof(av[0]); - return fluid_synth_set_chorus_full (synth, FLUID_CHORUS_SET_SPEED, 0, 0.0, speed, 0.0, 0); + fluid_synth_set_chorus_speed(handler->synth, speed); + return 0; } /* Purpose: * Response to 'chorus_setdepth' command */ int -fluid_handle_chorusdepth(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_chorusdepth(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { fluid_real_t depth; if (ac < 1) { @@ -909,11 +909,12 @@ fluid_handle_chorusdepth(fluid_synth_t* synth, int ac, char** av, fluid_ostream_ return -1; } depth = atof(av[0]); - return fluid_synth_set_chorus_full (synth, FLUID_CHORUS_SET_DEPTH, 0, 0.0, 0.0, depth, 0); + fluid_synth_set_chorus_depth(handler->synth, depth); + return 0; } int -fluid_handle_chorus(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_chorus(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { if (ac < 1) { fluid_ostream_printf(out, "chorus: too few arguments\n"); @@ -921,9 +922,9 @@ fluid_handle_chorus(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out } if ((strcmp(av[0], "0") == 0) || (strcmp(av[0], "off") == 0)) { - fluid_synth_set_chorus_on(synth,0); + fluid_synth_set_chorus_on(handler->synth,0); } else if ((strcmp(av[0], "1") == 0) || (strcmp(av[0], "on") == 0)) { - fluid_synth_set_chorus_on(synth,1); + fluid_synth_set_chorus_on(handler->synth,1); } else { fluid_ostream_printf(out, "chorus: invalid arguments %s [0|1|on|off]", av[0]); return -1; @@ -966,7 +967,7 @@ fluid_handle_source(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostre /* Purpose: * Response to 'gain' command. */ int -fluid_handle_gain(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_gain(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { float gain; @@ -982,25 +983,25 @@ fluid_handle_gain(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) return -1; }; - fluid_synth_set_gain(synth, gain); + fluid_synth_set_gain(handler->synth, gain); return 0; } /* Response to voice_count command */ static int -fluid_handle_voice_count (fluid_synth_t *synth, int ac, char **av, +fluid_handle_voice_count (fluid_cmd_handler_t* handler, int ac, char **av, fluid_ostream_t out) { fluid_ostream_printf (out, "voice_count: %d\n", - fluid_synth_get_active_voice_count (synth)); + fluid_synth_get_active_voice_count (handler->synth)); return FLUID_OK; } /* Purpose: * Response to 'interp' command. */ int -fluid_handle_interp(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_interp(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int interp; int chan=-1; /* -1: Set all channels */ @@ -1017,7 +1018,7 @@ fluid_handle_interp(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out return -1; }; - fluid_synth_set_interp_method(synth, chan, interp); + fluid_synth_set_interp_method(handler->synth, chan, interp); return 0; } @@ -1025,7 +1026,7 @@ fluid_handle_interp(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out /* Purpose: * Response to 'interp' command. */ int -fluid_handle_interpc(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_interpc(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int interp; int chan; @@ -1038,7 +1039,7 @@ fluid_handle_interpc(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t ou chan = atoi(av[0]); interp = atoi(av[1]); - if ((chan < 0) || (chan >= fluid_synth_count_midi_channels(synth))){ + if ((chan < 0) || (chan >= fluid_synth_count_midi_channels(handler->synth))){ fluid_ostream_printf(out, "interp: Bad value for channel number.\n"); return -1; }; @@ -1047,13 +1048,13 @@ fluid_handle_interpc(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t ou return -1; }; - fluid_synth_set_interp_method(synth, chan, interp); + fluid_synth_set_interp_method(handler->synth, chan, interp); return 0; } int -fluid_handle_tuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_tuning(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { char *name; int bank, prog; @@ -1085,13 +1086,13 @@ fluid_handle_tuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out return -1; }; - fluid_synth_create_key_tuning(synth, bank, prog, name, NULL); + fluid_synth_create_key_tuning(handler->synth, bank, prog, name, NULL); return 0; } int -fluid_handle_tune(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_tune(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int bank, prog, key; double pitch; @@ -1137,13 +1138,13 @@ fluid_handle_tune(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) return -1; }; - fluid_synth_tune_notes(synth, bank, prog, 1, &key, &pitch, 0); + fluid_synth_tune_notes(handler->synth, bank, prog, 1, &key, &pitch, 0); return 0; } int -fluid_handle_settuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_settuning(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int chan, bank, prog; @@ -1157,7 +1158,7 @@ fluid_handle_settuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t return -1; } chan = atoi(av[0]); - if ((chan < 0) || (chan >= fluid_synth_count_midi_channels(synth))){ + if ((chan < 0) || (chan >= fluid_synth_count_midi_channels(handler->synth))){ fluid_ostream_printf(out, "tune: invalid channel number.\n"); return -1; }; @@ -1182,13 +1183,13 @@ fluid_handle_settuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t return -1; }; - fluid_synth_select_tuning(synth, chan, bank, prog); + fluid_synth_select_tuning(handler->synth, chan, bank, prog); return 0; } int -fluid_handle_resettuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_resettuning(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int chan; @@ -1202,27 +1203,27 @@ fluid_handle_resettuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_ return -1; } chan = atoi(av[0]); - if ((chan < 0) || (chan >= fluid_synth_count_midi_channels(synth))){ + if ((chan < 0) || (chan >= fluid_synth_count_midi_channels(handler->synth))){ fluid_ostream_printf(out, "tune: invalid channel number.\n"); return -1; }; - fluid_synth_reset_tuning(synth, chan); + fluid_synth_reset_tuning(handler->synth, chan); return 0; } int -fluid_handle_tunings(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_tunings(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int bank, prog; char name[256]; int count = 0; - fluid_synth_tuning_iteration_start(synth); + fluid_synth_tuning_iteration_start(handler->synth); - while (fluid_synth_tuning_iteration_next(synth, &bank, &prog)) { - fluid_synth_tuning_dump(synth, bank, prog, name, 256, NULL); + while (fluid_synth_tuning_iteration_next(handler->synth, &bank, &prog)) { + fluid_synth_tuning_dump(handler->synth, bank, prog, name, 256, NULL); fluid_ostream_printf(out, "%03d-%03d %s\n", bank, prog, name); count++; } @@ -1235,7 +1236,7 @@ fluid_handle_tunings(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t ou } int -fluid_handle_dumptuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_dumptuning(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int bank, prog, i; double pitch[128]; @@ -1266,7 +1267,7 @@ fluid_handle_dumptuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t return -1; }; - fluid_synth_tuning_dump(synth, bank, prog, name, 256, pitch); + fluid_synth_tuning_dump(handler->synth, bank, prog, name, 256, pitch); fluid_ostream_printf(out, "%03d-%03d %s:\n", bank, prog, name); @@ -1278,7 +1279,7 @@ fluid_handle_dumptuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t } int -fluid_handle_set(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_set(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { int hints; int ival; @@ -1288,13 +1289,13 @@ fluid_handle_set(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) return -1; } - switch (fluid_settings_get_type (synth->settings, av[0])) + switch (fluid_settings_get_type (handler->synth->settings, av[0])) { case FLUID_NO_TYPE: fluid_ostream_printf (out, "set: Parameter '%s' not found.\n", av[0]); break; case FLUID_INT_TYPE: - if (fluid_settings_get_hints (synth->settings, av[0], &hints) == FLUID_OK + if (fluid_settings_get_hints (handler->synth->settings, av[0], &hints) == FLUID_OK && hints & FLUID_HINT_TOGGLED) { if (FLUID_STRCMP (av[1], "yes") == 0 || FLUID_STRCMP (av[1], "True") == 0 @@ -1305,13 +1306,13 @@ fluid_handle_set(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) } else ival = atoi (av[1]); - fluid_settings_setint (synth->settings, av[0], ival); + fluid_settings_setint (handler->synth->settings, av[0], ival); break; case FLUID_NUM_TYPE: - fluid_settings_setnum (synth->settings, av[0], atof (av[1])); + fluid_settings_setnum (handler->synth->settings, av[0], atof (av[1])); break; case FLUID_STR_TYPE: - fluid_settings_setstr(synth->settings, av[0], av[1]); + fluid_settings_setstr(handler->synth->settings, av[0], av[1]); break; case FLUID_SET_TYPE: fluid_ostream_printf (out, "set: Parameter '%s' is a node.\n", av[0]); @@ -1322,35 +1323,35 @@ fluid_handle_set(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) } int -fluid_handle_get(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_get(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { if (ac < 1) { fluid_ostream_printf(out, "get: too few arguments.\n"); return -1; } - switch (fluid_settings_get_type(fluid_synth_get_settings(synth), av[0])) { + switch (fluid_settings_get_type(fluid_synth_get_settings(handler->synth), av[0])) { case FLUID_NO_TYPE: fluid_ostream_printf(out, "get: no such setting '%s'.\n", av[0]); return -1; case FLUID_NUM_TYPE: { double value; - fluid_settings_getnum(synth->settings, av[0], &value); + fluid_settings_getnum(handler->synth->settings, av[0], &value); fluid_ostream_printf(out, "%.3f", value); break; } case FLUID_INT_TYPE: { int value; - fluid_settings_getint(synth->settings, av[0], &value); + fluid_settings_getint(handler->synth->settings, av[0], &value); fluid_ostream_printf(out, "%d", value); break; } case FLUID_STR_TYPE: { char* s; - fluid_settings_dupstr(synth->settings, av[0], &s); /* ++ alloc string */ + fluid_settings_dupstr(handler->synth->settings, av[0], &s); /* ++ alloc string */ fluid_ostream_printf(out, "%s", s ? s : "NULL"); if (s) FLUID_FREE (s); /* -- free string */ break; @@ -1423,16 +1424,16 @@ static void fluid_handle_settings_iter2(void* data, char* name, int type) } int -fluid_handle_settings(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_settings(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { struct _fluid_handle_settings_data_t data; data.len = 0; - data.synth = synth; + data.synth = handler->synth; data.out = out; - fluid_settings_foreach(fluid_synth_get_settings(synth), &data, fluid_handle_settings_iter1); - fluid_settings_foreach(fluid_synth_get_settings(synth), &data, fluid_handle_settings_iter2); + fluid_settings_foreach(fluid_synth_get_settings(handler->synth), &data, fluid_handle_settings_iter1); + fluid_settings_foreach(fluid_synth_get_settings(handler->synth), &data, fluid_handle_settings_iter2); return 0; } @@ -1455,9 +1456,9 @@ void fluid_handle_print_option(void* data, char* name, char* option) } int -fluid_handle_info(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_info(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { - fluid_settings_t* settings = fluid_synth_get_settings(synth); + fluid_settings_t* settings = fluid_synth_get_settings(handler->synth); struct _fluid_handle_option_data_t data; if (ac < 1) { @@ -1559,21 +1560,21 @@ fluid_handle_info(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) } int -fluid_handle_reset(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_reset(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { - fluid_synth_system_reset(synth); + fluid_synth_system_reset(handler->synth); return 0; } int -fluid_handle_quit(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_quit(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { fluid_ostream_printf(out, "cheers!\n"); return -2; } int -fluid_handle_help(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) +fluid_handle_help(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { /* Purpose: * Prints the help text for the command line commands. @@ -1627,6 +1628,185 @@ fluid_handle_help(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) return 0; } +int fluid_handle_router_clear(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) +{ + fluid_midi_router_t* router=handler->router; + + if (ac != 0) { + fluid_ostream_printf(out, "router_clear needs no arguments.\n"); + goto error_recovery; + } + + /* Disable rules and mark for destruction */ + fluid_midi_router_disable_all_rules(router); + + /* Free unused rules */ + fluid_midi_router_free_unused_rules(router); + + return 0; + error_recovery: + return -1; +}; + +int fluid_handle_router_default(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) +{ + fluid_midi_router_t* router=handler->router; + + if (ac != 0) { + fluid_ostream_printf(out, "router_default needs no arguments.\n"); + return -1; + } + + /* Disable rules and mark for destruction */ + fluid_midi_router_disable_all_rules(router); + + /* Create default rules */ + if (fluid_midi_router_create_default_rules(router) != FLUID_OK){ + FLUID_LOG(FLUID_ERR, "create_default_rules failed"); + goto error_recovery; + }; + + /* Free unused rules */ + fluid_midi_router_free_unused_rules(router); + + return 0; + error_recovery: + return -1; +}; + +int fluid_handle_router_begin(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) +{ + fluid_midi_router_t* router=handler->router; + fluid_midi_router_rule_t** dest=NULL; + + if (ac != 1) { + fluid_ostream_printf(out, "router_begin needs no arguments.\n"); + goto error_recovery; + } + + if (FLUID_STRCMP(av[0],"note") == 0){ + dest=& router->note_rules; + } else if (FLUID_STRCMP(av[0],"cc") == 0){ + dest=& router->cc_rules; + } else if (FLUID_STRCMP(av[0],"prog") == 0){ + dest=& router->progchange_rules; + } else if (FLUID_STRCMP(av[0],"pbend") == 0){ + dest=& router->pitchbend_rules; + } else if (FLUID_STRCMP(av[0],"cpress") == 0){ + dest=& router->channel_pressure_rules; + } else if (FLUID_STRCMP(av[0],"kpress") == 0){ + dest=& router->key_pressure_rules; + }; + + if (dest == NULL){ + fluid_ostream_printf(out, "router_begin args: note, cc, prog, pbend, cpress, kpress\n"); + goto error_recovery; + }; + + if (fluid_midi_router_begin(router, dest) != FLUID_OK){ + goto error_recovery; + }; + + /* Free unused rules (give it a try) */ + fluid_midi_router_free_unused_rules(router); + + return 0; + + error_recovery: + return -1; +}; + +int fluid_handle_router_end(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) +{ + fluid_midi_router_t* router=handler->router; + + if (ac != 0) { + fluid_ostream_printf(out, "router_end needs no arguments."); + goto error_recovery; + } + + if (fluid_midi_router_end(router) != FLUID_OK){ + FLUID_LOG(FLUID_ERR, "midi_router_end failed"); + goto error_recovery; + }; + + /* Free unused rules (give it a try) */ + fluid_midi_router_free_unused_rules(router); + + return 0; + + error_recovery: + return -1; +}; + +int fluid_handle_router_chan(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) +{ + fluid_midi_router_t* router=handler->router; + + if (ac != 4) { + fluid_ostream_printf(out, "router_chan needs four args: min, max, mul, add."); + goto error_recovery; + } + + router->new_rule_chan_min=atoi(av[0]); + router->new_rule_chan_max=atoi(av[1]); + router->new_rule_chan_mul=atoi(av[2]); + router->new_rule_chan_add=atoi(av[3]); + + /* Free unused rules (give it a try) */ + fluid_midi_router_free_unused_rules(router); + + return 0; + + error_recovery: + return -1; +}; + +int fluid_handle_router_par1(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) +{ + fluid_midi_router_t* router=handler->router; + + if (ac != 4) { + fluid_ostream_printf(out, "router_par1 needs four args: min, max, mul, add."); + goto error_recovery; + } + + router->new_rule_par1_min=atoi(av[0]); + router->new_rule_par1_max=atoi(av[1]); + router->new_rule_par1_mul=atoi(av[2]); + router->new_rule_par1_add=atoi(av[3]); + + /* Free unused rules (give it a try) */ + fluid_midi_router_free_unused_rules(router); + + return 0; + + error_recovery: + return -1; +}; + +int fluid_handle_router_par2(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) +{ + fluid_midi_router_t* router=handler->router; + + if (ac != 4) { + fluid_ostream_printf(out, "router_par2 needs four args: min, max, mul, add."); + goto error_recovery; + } + + router->new_rule_par2_min=atoi(av[0]); + router->new_rule_par2_max=atoi(av[1]); + router->new_rule_par2_mul=atoi(av[2]); + router->new_rule_par2_add=atoi(av[3]); + + /* Free unused rules (give it a try) */ + fluid_midi_router_free_unused_rules(router); + return 0; + + error_recovery: + return -1; +}; + int fluid_is_number(char* a) { @@ -1725,33 +1905,30 @@ fluid_cmd_handler_destroy_hash_value (void *value) * added to the new handler. * @return New command handler */ -fluid_cmd_handler_t * -new_fluid_cmd_handler(fluid_synth_t* synth) +fluid_cmd_handler_t* new_fluid_cmd_handler(fluid_synth_t* synth, fluid_midi_router_t* router) { int i; fluid_cmd_handler_t* handler; - fluid_cmd_t source = { - "source", "general", (fluid_cmd_func_t) fluid_handle_source, NULL, - "source filename Load a file and parse every line as a command" - }; - - handler = new_fluid_hashtable_full (fluid_str_hash, fluid_str_equal, - NULL, fluid_cmd_handler_destroy_hash_value); + handler = FLUID_NEW(fluid_cmd_handler_t); if (handler == NULL) { return NULL; } - - if (synth != NULL) { - for (i = 0; fluid_commands[i].name != NULL; i++) { - fluid_commands[i].data = synth; - fluid_cmd_handler_register(handler, &fluid_commands[i]); - fluid_commands[i].data = NULL; - } + handler->commands = new_fluid_hashtable_full (fluid_str_hash, fluid_str_equal, + NULL, fluid_cmd_handler_destroy_hash_value); + if (handler->commands == NULL) { + FLUID_FREE(handler); + return NULL; } - source.data = handler; - fluid_cmd_handler_register(handler, &source); + handler->synth = synth; + handler->router = router; + + if (synth != NULL) { + for (i = 0; fluid_commands[i].name != NULL; i++) { + fluid_cmd_handler_register(handler, &fluid_commands[i]); + } + } return handler; } @@ -1763,7 +1940,8 @@ new_fluid_cmd_handler(fluid_synth_t* synth) void delete_fluid_cmd_handler(fluid_cmd_handler_t* handler) { - delete_fluid_hashtable (handler); + delete_fluid_hashtable(handler->commands); + FLUID_FREE(handler); } /** @@ -1776,7 +1954,7 @@ int fluid_cmd_handler_register(fluid_cmd_handler_t* handler, fluid_cmd_t* cmd) { fluid_cmd_t* copy = fluid_cmd_copy(cmd); - fluid_hashtable_insert(handler, copy->name, copy); + fluid_hashtable_insert(handler->commands, copy->name, copy); return FLUID_OK; } @@ -1789,7 +1967,7 @@ fluid_cmd_handler_register(fluid_cmd_handler_t* handler, fluid_cmd_t* cmd) int fluid_cmd_handler_unregister(fluid_cmd_handler_t* handler, const char *cmd) { - return fluid_hashtable_remove(handler, cmd); + return fluid_hashtable_remove(handler->commands, cmd); } int @@ -1797,7 +1975,7 @@ fluid_cmd_handler_handle(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ { fluid_cmd_t* cmd; - cmd = fluid_hashtable_lookup(handler, av[0]); + cmd = fluid_hashtable_lookup(handler->commands, av[0]); if (cmd && cmd->handler) return (*cmd->handler)(cmd->data, ac - 1, av + 1, out); @@ -1815,7 +1993,7 @@ struct _fluid_server_t { fluid_server_socket_t* socket; fluid_settings_t* settings; fluid_server_newclient_func_t newclient; - void* data; + fluid_cmd_handler_t* handler; fluid_list_t* clients; fluid_mutex_t mutex; }; @@ -1834,8 +2012,7 @@ static void fluid_server_close(fluid_server_t* server); */ fluid_server_t* new_fluid_server(fluid_settings_t* settings, - fluid_server_newclient_func_t newclient, - void* data) + fluid_cmd_handler_t* handler) { fluid_server_t* server; int port; @@ -1848,8 +2025,7 @@ new_fluid_server(fluid_settings_t* settings, server->settings = settings; server->clients = NULL; - server->newclient = newclient; - server->data = data; + server->handler = handler; fluid_mutex_init(server->mutex); @@ -1919,7 +2095,7 @@ fluid_server_handle_connection(fluid_server_t* server, fluid_socket_t client_soc fluid_client_t* client; fluid_cmd_handler_t* handler; - handler = server->newclient(server->data, addr); + handler = new_fluid_cmd_handler(server->handler->synth, server->handler->router); if (handler == NULL) { return -1; } diff --git a/src/bindings/fluid_cmd.h b/src/bindings/fluid_cmd.h index b81bc425..0fa5323e 100644 --- a/src/bindings/fluid_cmd.h +++ b/src/bindings/fluid_cmd.h @@ -23,6 +23,7 @@ #include "fluidsynth_priv.h" + void fluid_shell_settings(fluid_settings_t* settings); @@ -32,50 +33,58 @@ int fluid_is_empty(char* a); char* fluid_expand_path(char* path, char* new_path, int len); /** the handlers for the command lines */ -int fluid_handle_help(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_quit(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_noteon(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_noteoff(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_pitch_bend(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_pitch_bend_range(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_cc(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_prog(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_select(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_inst(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_channels(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_load(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_unload(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_reload(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_fonts(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_mstat(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_reverbpreset(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_reverbsetroomsize(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_reverbsetdamp(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_reverbsetwidth(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_reverbsetlevel(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_chorusnr(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_choruslevel(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_chorusspeed(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_chorusdepth(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_chorus(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_reverb(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_gain(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_interp(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_interpc(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_tuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_tune(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_settuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_resettuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_tunings(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_dumptuning(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_reset(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); +int fluid_handle_help(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_quit(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_noteon(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_noteoff(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_pitch_bend(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_pitch_bend_range(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_cc(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_prog(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_select(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_inst(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_channels(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_load(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_unload(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_reload(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_fonts(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_mstat(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_reverbpreset(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_reverbsetroomsize(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_reverbsetdamp(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_reverbsetwidth(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_reverbsetlevel(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_chorusnr(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_choruslevel(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_chorusspeed(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_chorusdepth(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_chorus(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_reverb(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_gain(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_interp(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_interpc(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_tuning(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_tune(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_settuning(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_resettuning(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_tunings(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_dumptuning(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_reset(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); int fluid_handle_source(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); int fluid_handle_echo(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); -int fluid_handle_set(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_get(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_info(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_handle_settings(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); +int fluid_handle_set(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_get(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_info(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_settings(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); + +int fluid_handle_router_clear(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_router_default(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_router_begin(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_router_end(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_router_chan(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_router_par1(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); +int fluid_handle_router_par2(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out); fluid_cmd_t* fluid_cmd_copy(fluid_cmd_t* cmd); diff --git a/src/fluidsynth.c b/src/fluidsynth.c index 822c118c..d2149da6 100644 --- a/src/fluidsynth.c +++ b/src/fluidsynth.c @@ -56,10 +56,6 @@ void print_usage(void); void print_help(fluid_settings_t *settings); void print_welcome(void); -#if !defined(MACINTOSH) -static fluid_cmd_handler_t* newclient(void* data, char* addr); -#endif - /* * the globals */ @@ -614,12 +610,6 @@ int main(int argc, char** argv) exit(-1); } - cmd_handler = new_fluid_cmd_handler(synth); - if (cmd_handler == NULL) { - fprintf(stderr, "Failed to create the command handler\n"); - goto cleanup; - } - /* load the soundfonts (check that all non options are SoundFont or MIDI files) */ for (i = arg1; i < argc; i++) { if (fluid_is_soundfont(argv[i])) @@ -664,8 +654,6 @@ int main(int argc, char** argv) "will be available. You can access the synthesizer \n" "through the console.\n"); } else { - fluid_synth_set_midi_router(synth, router); /* Fixme, needed for command handler */ -// fluid_sequencer_register_fluidsynth(sequencer, synth); mdriver = new_fluid_midi_driver( settings, dump ? fluid_midi_dump_prerouter : fluid_midi_router_handle_midi_event, @@ -679,17 +667,6 @@ int main(int argc, char** argv) } #endif - /* run commands specified in config file */ - if (config_file != NULL) { - fluid_source(cmd_handler, config_file); - } else if (fluid_get_userconf(buf, 512) != NULL) { - fluid_source(cmd_handler, buf); - } else if (fluid_get_sysconf(buf, 512) != NULL) { - fluid_source(cmd_handler, buf); - } - - - /* play the midi files, if any */ for (i = arg1; i < argc; i++) { if ((argv[i][0] != '-') && fluid_is_midifile(argv[i])) { @@ -723,10 +700,25 @@ int main(int argc, char** argv) fluid_player_play(player); } + cmd_handler = new_fluid_cmd_handler(synth, router); + if (cmd_handler == NULL) { + fprintf(stderr, "Failed to create the command handler\n"); + goto cleanup; + } + + /* try to load the user or system configuration */ + if (config_file != NULL) { + fluid_source(cmd_handler, config_file); + } else if (fluid_get_userconf(buf, 512) != NULL) { + fluid_source(cmd_handler, buf); + } else if (fluid_get_sysconf(buf, 512) != NULL) { + fluid_source(cmd_handler, buf); + } + /* run the server, if requested */ #if !defined(MACINTOSH) if (with_server) { - server = new_fluid_server(settings, newclient, synth); + server = new_fluid_server(settings, cmd_handler); if (server == NULL) { fprintf(stderr, "Failed to create the server.\n" "Continuing without it.\n"); @@ -734,7 +726,6 @@ int main(int argc, char** argv) } #endif - #ifdef LASH_ENABLED if (enabled_lash) fluid_lash_create_thread (synth); @@ -824,14 +815,6 @@ int main(int argc, char** argv) return 0; } -#if !defined(MACINTOSH) -static fluid_cmd_handler_t* newclient(void* data, char* addr) -{ - fluid_synth_t* synth = (fluid_synth_t*) data; - return new_fluid_cmd_handler(synth); -} -#endif - /* * print_usage */ From 17aacf4fd9a342b4f68aa59c9606b97e29b7ef08 Mon Sep 17 00:00:00 2001 From: derselbst Date: Tue, 3 Oct 2017 18:10:27 +0200 Subject: [PATCH 2/8] decouple cmd_handler for midi_router --- src/bindings/fluid_cmd.c | 222 +++++++++++++++++------------------ src/midi/fluid_midi_router.c | 188 ----------------------------- src/midi/fluid_midi_router.h | 7 -- 3 files changed, 110 insertions(+), 307 deletions(-) diff --git a/src/bindings/fluid_cmd.c b/src/bindings/fluid_cmd.c index 68408d98..6a55a415 100644 --- a/src/bindings/fluid_cmd.c +++ b/src/bindings/fluid_cmd.c @@ -1628,184 +1628,182 @@ fluid_handle_help(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream return 0; } -int fluid_handle_router_clear(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) -{ - fluid_midi_router_t* router=handler->router; - - if (ac != 0) { - fluid_ostream_printf(out, "router_clear needs no arguments.\n"); - goto error_recovery; +#define CHECK_VALID_ROUTER(_router, _out) \ + if (router == NULL) { \ + fluid_ostream_printf(out, "cannot execute router command without a midi router.\n"); \ + return FLUID_FAILED; \ } - /* Disable rules and mark for destruction */ - fluid_midi_router_disable_all_rules(router); +/* Command handler for "router_clear" command */ +int fluid_handle_router_clear(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) +{ + fluid_midi_router_t *router = handler->router; - /* Free unused rules */ - fluid_midi_router_free_unused_rules(router); + if (ac != 0) { + fluid_ostream_printf (out, "router_clear needs no arguments.\n"); + return FLUID_FAILED; + } - return 0; - error_recovery: - return -1; -}; + CHECK_VALID_ROUTER (router, out); + fluid_midi_router_clear_rules (router); + + return FLUID_OK; +} + +/* Command handler for "router_default" command */ int fluid_handle_router_default(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { - fluid_midi_router_t* router=handler->router; + fluid_midi_router_t *router = handler->router; if (ac != 0) { fluid_ostream_printf(out, "router_default needs no arguments.\n"); - return -1; + return FLUID_FAILED; } - /* Disable rules and mark for destruction */ - fluid_midi_router_disable_all_rules(router); + CHECK_VALID_ROUTER (router, out); - /* Create default rules */ - if (fluid_midi_router_create_default_rules(router) != FLUID_OK){ - FLUID_LOG(FLUID_ERR, "create_default_rules failed"); - goto error_recovery; - }; + fluid_midi_router_set_default_rules (router); - /* Free unused rules */ - fluid_midi_router_free_unused_rules(router); - - return 0; - error_recovery: - return -1; -}; + return FLUID_OK; +} +/* Command handler for "router_begin" command */ int fluid_handle_router_begin(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { - fluid_midi_router_t* router=handler->router; - fluid_midi_router_rule_t** dest=NULL; + fluid_midi_router_t* router = handler->router; if (ac != 1) { - fluid_ostream_printf(out, "router_begin needs no arguments.\n"); - goto error_recovery; + fluid_ostream_printf (out, "router_begin requires [note|cc|prog|pbend|cpress|kpress]\n"); + return FLUID_FAILED; } - if (FLUID_STRCMP(av[0],"note") == 0){ - dest=& router->note_rules; - } else if (FLUID_STRCMP(av[0],"cc") == 0){ - dest=& router->cc_rules; - } else if (FLUID_STRCMP(av[0],"prog") == 0){ - dest=& router->progchange_rules; - } else if (FLUID_STRCMP(av[0],"pbend") == 0){ - dest=& router->pitchbend_rules; - } else if (FLUID_STRCMP(av[0],"cpress") == 0){ - dest=& router->channel_pressure_rules; - } else if (FLUID_STRCMP(av[0],"kpress") == 0){ - dest=& router->key_pressure_rules; - }; + CHECK_VALID_ROUTER (router, out); - if (dest == NULL){ - fluid_ostream_printf(out, "router_begin args: note, cc, prog, pbend, cpress, kpress\n"); - goto error_recovery; - }; + if (FLUID_STRCMP (av[0], "note") == 0) + router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_NOTE; + else if (FLUID_STRCMP (av[0], "cc") == 0) + router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_CC; + else if (FLUID_STRCMP (av[0], "prog") == 0) + router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_PROG_CHANGE; + else if (FLUID_STRCMP (av[0], "pbend") == 0) + router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_PITCH_BEND; + else if (FLUID_STRCMP (av[0], "cpress") == 0) + router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_CHANNEL_PRESSURE; + else if (FLUID_STRCMP (av[0], "kpress") == 0) + router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_KEY_PRESSURE; + else + { + fluid_ostream_printf (out, "router_begin requires [note|cc|prog|pbend|cpress|kpress]\n"); + return FLUID_FAILED; + } - if (fluid_midi_router_begin(router, dest) != FLUID_OK){ - goto error_recovery; - }; + if (router->cmd_rule) + delete_fluid_midi_router_rule (router->cmd_rule); - /* Free unused rules (give it a try) */ - fluid_midi_router_free_unused_rules(router); + router->cmd_rule = new_fluid_midi_router_rule (); - return 0; + if (!router->cmd_rule) + return FLUID_FAILED; - error_recovery: - return -1; -}; + return FLUID_OK; +} +/* Command handler for "router_end" command */ int fluid_handle_router_end(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { - fluid_midi_router_t* router=handler->router; + fluid_midi_router_t* router = handler->router; if (ac != 0) { - fluid_ostream_printf(out, "router_end needs no arguments."); - goto error_recovery; + fluid_ostream_printf (out, "router_end needs no arguments.\n"); + return FLUID_FAILED; } - if (fluid_midi_router_end(router) != FLUID_OK){ - FLUID_LOG(FLUID_ERR, "midi_router_end failed"); - goto error_recovery; - }; + CHECK_VALID_ROUTER (router, out); - /* Free unused rules (give it a try) */ - fluid_midi_router_free_unused_rules(router); + if (!router->cmd_rule) + { + fluid_ostream_printf (out, "No active router_begin command.\n"); + return FLUID_FAILED; + } - return 0; + /* Add the rule */ + if (fluid_midi_router_add_rule (router, router->cmd_rule, router->cmd_rule_type) != FLUID_OK) + delete_fluid_midi_router_rule (router->cmd_rule); /* Free on failure */ - error_recovery: - return -1; -}; + router->cmd_rule = NULL; + return FLUID_OK; +} + +/* Command handler for "router_chan" command */ int fluid_handle_router_chan(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { - fluid_midi_router_t* router=handler->router; + fluid_midi_router_t* router = handler->router; if (ac != 4) { fluid_ostream_printf(out, "router_chan needs four args: min, max, mul, add."); - goto error_recovery; + return FLUID_FAILED; } - router->new_rule_chan_min=atoi(av[0]); - router->new_rule_chan_max=atoi(av[1]); - router->new_rule_chan_mul=atoi(av[2]); - router->new_rule_chan_add=atoi(av[3]); + CHECK_VALID_ROUTER (router, out); - /* Free unused rules (give it a try) */ - fluid_midi_router_free_unused_rules(router); + if (!router->cmd_rule) + { + fluid_ostream_printf (out, "No active router_begin command.\n"); + return FLUID_FAILED; + } - return 0; - - error_recovery: - return -1; -}; + fluid_midi_router_rule_set_chan (router->cmd_rule, atoi (av[0]), atoi (av[1]), + atof (av[2]), atoi (av[3])); + return FLUID_OK; +} +/* Command handler for "router_par1" command */ int fluid_handle_router_par1(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { - fluid_midi_router_t* router=handler->router; + fluid_midi_router_t* router = handler->router; if (ac != 4) { fluid_ostream_printf(out, "router_par1 needs four args: min, max, mul, add."); - goto error_recovery; + return FLUID_FAILED; } - router->new_rule_par1_min=atoi(av[0]); - router->new_rule_par1_max=atoi(av[1]); - router->new_rule_par1_mul=atoi(av[2]); - router->new_rule_par1_add=atoi(av[3]); + CHECK_VALID_ROUTER (router, out); - /* Free unused rules (give it a try) */ - fluid_midi_router_free_unused_rules(router); + if (!router->cmd_rule) + { + fluid_ostream_printf (out, "No active router_begin command.\n"); + return FLUID_FAILED; + } - return 0; - - error_recovery: - return -1; -}; + fluid_midi_router_rule_set_param1 (router->cmd_rule, atoi (av[0]), atoi (av[1]), + atof (av[2]), atoi (av[3])); + return FLUID_OK; +} +/* Command handler for "router_par2" command */ int fluid_handle_router_par2(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { - fluid_midi_router_t* router=handler->router; + fluid_midi_router_t* router = synth->midi_router; if (ac != 4) { fluid_ostream_printf(out, "router_par2 needs four args: min, max, mul, add."); - goto error_recovery; + return FLUID_FAILED; } - router->new_rule_par2_min=atoi(av[0]); - router->new_rule_par2_max=atoi(av[1]); - router->new_rule_par2_mul=atoi(av[2]); - router->new_rule_par2_add=atoi(av[3]); + CHECK_VALID_ROUTER (router, out); - /* Free unused rules (give it a try) */ - fluid_midi_router_free_unused_rules(router); - return 0; + if (!router->cmd_rule) + { + fluid_ostream_printf (out, "No active router_begin command.\n"); + return FLUID_FAILED; + } - error_recovery: - return -1; -}; + fluid_midi_router_rule_set_param2 (router->cmd_rule, atoi (av[0]), atoi (av[1]), + atof (av[2]), atoi (av[3])); + return FLUID_OK; +} int fluid_is_number(char* a) diff --git a/src/midi/fluid_midi_router.c b/src/midi/fluid_midi_router.c index 195b4fce..cb09a62e 100644 --- a/src/midi/fluid_midi_router.c +++ b/src/midi/fluid_midi_router.c @@ -742,194 +742,6 @@ send_event: return ret_val; } -#define CHECK_VALID_ROUTER(_router, _out) \ - if (router == NULL) { \ - fluid_ostream_printf(out, "cannot execute router command without a midi router.\n"); \ - return FLUID_FAILED; \ - } - -/* Command handler for "router_clear" command */ -int -fluid_midi_router_handle_clear (fluid_synth_t* synth, int ac, char** av, - fluid_ostream_t out) -{ - fluid_midi_router_t *router = synth->midi_router; - - if (ac != 0) { - fluid_ostream_printf (out, "router_clear needs no arguments.\n"); - return FLUID_FAILED; - } - - CHECK_VALID_ROUTER (router, out); - - fluid_midi_router_clear_rules (router); - - return FLUID_OK; -} - -/* Command handler for "router_default" command */ -int -fluid_midi_router_handle_default(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) -{ - fluid_midi_router_t *router = synth->midi_router; - - if (ac != 0) { - fluid_ostream_printf(out, "router_default needs no arguments.\n"); - return FLUID_FAILED; - } - - CHECK_VALID_ROUTER (router, out); - - fluid_midi_router_set_default_rules (router); - - return FLUID_OK; -} - -/* Command handler for "router_begin" command */ -int -fluid_midi_router_handle_begin (fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) -{ - fluid_midi_router_t* router = synth->midi_router; - - if (ac != 1) { - fluid_ostream_printf (out, "router_begin requires [note|cc|prog|pbend|cpress|kpress]\n"); - return FLUID_FAILED; - } - - CHECK_VALID_ROUTER (router, out); - - if (FLUID_STRCMP (av[0], "note") == 0) - router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_NOTE; - else if (FLUID_STRCMP (av[0], "cc") == 0) - router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_CC; - else if (FLUID_STRCMP (av[0], "prog") == 0) - router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_PROG_CHANGE; - else if (FLUID_STRCMP (av[0], "pbend") == 0) - router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_PITCH_BEND; - else if (FLUID_STRCMP (av[0], "cpress") == 0) - router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_CHANNEL_PRESSURE; - else if (FLUID_STRCMP (av[0], "kpress") == 0) - router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_KEY_PRESSURE; - else - { - fluid_ostream_printf (out, "router_begin requires [note|cc|prog|pbend|cpress|kpress]\n"); - return FLUID_FAILED; - } - - if (router->cmd_rule) - delete_fluid_midi_router_rule (router->cmd_rule); - - router->cmd_rule = new_fluid_midi_router_rule (); - - if (!router->cmd_rule) - return FLUID_FAILED; - - return FLUID_OK; -} - -/* Command handler for "router_end" command */ -int -fluid_midi_router_handle_end (fluid_synth_t* synth, int ac, char** av, - fluid_ostream_t out) -{ - fluid_midi_router_t* router = synth->midi_router; - - if (ac != 0) { - fluid_ostream_printf (out, "router_end needs no arguments.\n"); - return FLUID_FAILED; - } - - CHECK_VALID_ROUTER (router, out); - - if (!router->cmd_rule) - { - fluid_ostream_printf (out, "No active router_begin command.\n"); - return FLUID_FAILED; - } - - /* Add the rule */ - if (fluid_midi_router_add_rule (router, router->cmd_rule, router->cmd_rule_type) != FLUID_OK) - delete_fluid_midi_router_rule (router->cmd_rule); /* Free on failure */ - - router->cmd_rule = NULL; - - return FLUID_OK; -} - -/* Command handler for "router_chan" command */ -int -fluid_midi_router_handle_chan (fluid_synth_t* synth, int ac, char** av, - fluid_ostream_t out) -{ - fluid_midi_router_t* router = synth->midi_router; - - if (ac != 4) { - fluid_ostream_printf(out, "router_chan needs four args: min, max, mul, add."); - return FLUID_FAILED; - } - - CHECK_VALID_ROUTER (router, out); - - if (!router->cmd_rule) - { - fluid_ostream_printf (out, "No active router_begin command.\n"); - return FLUID_FAILED; - } - - fluid_midi_router_rule_set_chan (router->cmd_rule, atoi (av[0]), atoi (av[1]), - atof (av[2]), atoi (av[3])); - return FLUID_OK; -} - -/* Command handler for "router_par1" command */ -int -fluid_midi_router_handle_par1 (fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) -{ - fluid_midi_router_t* router = synth->midi_router; - - if (ac != 4) { - fluid_ostream_printf(out, "router_par1 needs four args: min, max, mul, add."); - return FLUID_FAILED; - } - - CHECK_VALID_ROUTER (router, out); - - if (!router->cmd_rule) - { - fluid_ostream_printf (out, "No active router_begin command.\n"); - return FLUID_FAILED; - } - - fluid_midi_router_rule_set_param1 (router->cmd_rule, atoi (av[0]), atoi (av[1]), - atof (av[2]), atoi (av[3])); - return FLUID_OK; -} - -/* Command handler for "router_par2" command */ -int -fluid_midi_router_handle_par2 (fluid_synth_t* synth, int ac, char** av, - fluid_ostream_t out) -{ - fluid_midi_router_t* router = synth->midi_router; - - if (ac != 4) { - fluid_ostream_printf(out, "router_par2 needs four args: min, max, mul, add."); - return FLUID_FAILED; - } - - CHECK_VALID_ROUTER (router, out); - - if (!router->cmd_rule) - { - fluid_ostream_printf (out, "No active router_begin command.\n"); - return FLUID_FAILED; - } - - fluid_midi_router_rule_set_param2 (router->cmd_rule, atoi (av[0]), atoi (av[1]), - atof (av[2]), atoi (av[3])); - return FLUID_OK; -} - /** * MIDI event callback function to display event information to stdout * @param data MIDI router instance diff --git a/src/midi/fluid_midi_router.h b/src/midi/fluid_midi_router.h index 3f850c4f..5a5068d5 100644 --- a/src/midi/fluid_midi_router.h +++ b/src/midi/fluid_midi_router.h @@ -28,12 +28,5 @@ #include "fluid_midi.h" #include "fluid_sys.h" -int fluid_midi_router_handle_clear(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_midi_router_handle_default(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_midi_router_handle_begin(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_midi_router_handle_chan(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_midi_router_handle_par1(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_midi_router_handle_par2(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); -int fluid_midi_router_handle_end(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out); #endif From 77749637d2f336e1546f4328c9bb00471eacbff7 Mon Sep 17 00:00:00 2001 From: derselbst Date: Tue, 3 Oct 2017 20:17:48 +0200 Subject: [PATCH 3/8] add individual reverb setters to synth API --- include/fluidsynth/synth.h | 10 ++++---- src/synth/fluid_synth.c | 48 ++++++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/include/fluidsynth/synth.h b/include/fluidsynth/synth.h index 71d60cef..cfae62d1 100644 --- a/include/fluidsynth/synth.h +++ b/include/fluidsynth/synth.h @@ -146,10 +146,12 @@ FLUIDSYNTH_API int fluid_synth_get_bank_offset(fluid_synth_t* synth, int sfont_i */ /** Set the parameters for the built-in reverb unit */ -FLUIDSYNTH_API void fluid_synth_set_reverb_roomsize(fluid_synth_t* synth, double roomsize); -FLUIDSYNTH_API void fluid_synth_set_reverb_damp(fluid_synth_t* synth, double damping); -FLUIDSYNTH_API void fluid_synth_set_reverb_width(fluid_synth_t* synth, double width); -FLUIDSYNTH_API void fluid_synth_set_reverb_level(fluid_synth_t* synth, double level); +FLUIDSYNTH_API int fluid_synth_set_reverb(fluid_synth_t* synth, double roomsize, + double damping, double width, double level); +FLUIDSYNTH_API int fluid_synth_set_reverb_roomsize(fluid_synth_t* synth, double roomsize); +FLUIDSYNTH_API int fluid_synth_set_reverb_damp(fluid_synth_t* synth, double damping); +FLUIDSYNTH_API int fluid_synth_set_reverb_width(fluid_synth_t* synth, double width); +FLUIDSYNTH_API int fluid_synth_set_reverb_level(fluid_synth_t* synth, double level); /** Turn on (1) / off (0) the built-in reverb unit */ FLUIDSYNTH_API void fluid_synth_set_reverb_on(fluid_synth_t* synth, int on); diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 49d97666..5ad35580 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -3842,18 +3842,55 @@ fluid_synth_set_reverb_preset(fluid_synth_t* synth, int num) * @param damping Reverb damping value (0.0-1.0) * @param width Reverb width value (0.0-100.0) * @param level Reverb level value (0.0-1.0) + * @return FLUID_OK on success, FLUID_FAILED otherwise * * @note Not realtime safe and therefore should not be called from synthesis * context at the risk of stalling audio output. */ -void +int fluid_synth_set_reverb(fluid_synth_t* synth, double roomsize, double damping, double width, double level) { - fluid_synth_set_reverb_full (synth, FLUID_REVMODEL_SET_ALL, + return fluid_synth_set_reverb_full (synth, FLUID_REVMODEL_SET_ALL, roomsize, damping, width, level); } +/** + * Set reverb roomsize. See fluid_synth_set_reverb() for further info. + * @return FLUID_OK on success, FLUID_FAILED otherwise + */ +int fluid_synth_set_reverb_roomsize(fluid_synth_t* synth, double roomsize) +{ + return fluid_synth_set_reverb_full(synth, FLUID_REVMODEL_SET_ROOMSIZE, roomsize, 0, 0, 0); +} + +/** + * Set reverb damping. See fluid_synth_set_reverb() for further info. + * @return FLUID_OK on success, FLUID_FAILED otherwise + */ +int fluid_synth_set_reverb_damp(fluid_synth_t* synth, double damping) +{ + return fluid_synth_set_reverb_full(synth, FLUID_REVMODEL_SET_DAMPING, 0, damping, 0, 0); +} + +/** + * Set reverb width. See fluid_synth_set_reverb() for further info. + * @return FLUID_OK on success, FLUID_FAILED otherwise + */ +int fluid_synth_set_reverb_width(fluid_synth_t* synth, double width) +{ + return fluid_synth_set_reverb_full(synth, FLUID_REVMODEL_SET_WIDTH, 0, 0, width, 0); +} + +/** + * Set reverb level. See fluid_synth_set_reverb() for further info. + * @return FLUID_OK on success, FLUID_FAILED otherwise + */ +int fluid_synth_set_reverb_level(fluid_synth_t* synth, double level) +{ + return fluid_synth_set_reverb_full(synth, FLUID_REVMODEL_SET_LEVEL, 0, 0, 0, level); +} + /** * Set one or more reverb parameters. * @param synth FluidSynth instance @@ -3871,6 +3908,8 @@ int fluid_synth_set_reverb_full(fluid_synth_t* synth, int set, double roomsize, double damping, double width, double level) { + int ret; + fluid_return_val_if_fail (synth != NULL, FLUID_FAILED); if (!(set & FLUID_REVMODEL_SET_ALL)) @@ -3892,12 +3931,13 @@ fluid_synth_set_reverb_full(fluid_synth_t* synth, int set, double roomsize, if (set & FLUID_REVMODEL_SET_LEVEL) fluid_atomic_float_set (&synth->reverb_level, level); - fluid_rvoice_eventhandler_push5(synth->eventhandler, + /* finally enqueue an rvoice event to the mixer to actual update reverb */ + ret = fluid_rvoice_eventhandler_push5(synth->eventhandler, fluid_rvoice_mixer_set_reverb_params, synth->eventhandler->mixer, set, roomsize, damping, width, level, 0.0f); - FLUID_API_RETURN(FLUID_OK); + FLUID_API_RETURN(ret); } /** From c8007e655b798b4ad181149e373f07cf34db0961 Mon Sep 17 00:00:00 2001 From: derselbst Date: Tue, 3 Oct 2017 21:12:35 +0200 Subject: [PATCH 4/8] add individual chorus setters to synth API --- include/fluidsynth/synth.h | 12 ++++--- src/synth/fluid_synth.c | 68 +++++++++++++++++++++++++++++++------- 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/include/fluidsynth/synth.h b/include/fluidsynth/synth.h index cfae62d1..70305417 100644 --- a/include/fluidsynth/synth.h +++ b/include/fluidsynth/synth.h @@ -180,11 +180,13 @@ enum fluid_chorus_mod { * If faulty parameters are given, all new settings are discarded. * Keep in mind, that the needed CPU time is proportional to 'nr'. */ -FLUIDSYNTH_API void fluid_synth_set_chorus_nr(fluid_synth_t* synth, int nr); -FLUIDSYNTH_API void fluid_synth_set_chorus_level(fluid_synth_t* synth, double level); -FLUIDSYNTH_API void fluid_synth_set_chorus_speed(fluid_synth_t* synth, double speed); -FLUIDSYNTH_API void fluid_synth_set_chorus_depth(fluid_synth_t* synth, double depth_ms); -FLUIDSYNTH_API void fluid_synth_set_chorus_type(fluid_synth_t* synth, int type); +FLUIDSYNTH_API int fluid_synth_set_chorus(fluid_synth_t* synth, int nr, double level, + double speed, double depth_ms, int type); +FLUIDSYNTH_API int fluid_synth_set_chorus_nr(fluid_synth_t* synth, int nr); +FLUIDSYNTH_API int fluid_synth_set_chorus_level(fluid_synth_t* synth, double level); +FLUIDSYNTH_API int fluid_synth_set_chorus_speed(fluid_synth_t* synth, double speed); +FLUIDSYNTH_API int fluid_synth_set_chorus_depth(fluid_synth_t* synth, double depth_ms); +FLUIDSYNTH_API int fluid_synth_set_chorus_type(fluid_synth_t* synth, int type); /** Turn on (1) / off (0) the built-in chorus unit */ FLUIDSYNTH_API void fluid_synth_set_chorus_on(fluid_synth_t* synth, int on); diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 5ad35580..ee64b140 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -3909,11 +3909,9 @@ fluid_synth_set_reverb_full(fluid_synth_t* synth, int set, double roomsize, double damping, double width, double level) { int ret; - fluid_return_val_if_fail (synth != NULL, FLUID_FAILED); - - if (!(set & FLUID_REVMODEL_SET_ALL)) - set = FLUID_REVMODEL_SET_ALL; + /* if non of the flags is set, fail */ + fluid_return_val_if_fail (set & FLUID_REVMODEL_SET_ALL, FLUID_FAILED); /* Synth shadow values are set here so that they will be returned if querried */ @@ -4030,15 +4028,60 @@ fluid_synth_set_chorus_on(fluid_synth_t* synth, int on) * @param depth_ms Chorus depth (max value depends on synth sample rate, * 0.0-21.0 is safe for sample rate values up to 96KHz) * @param type Chorus waveform type (#fluid_chorus_mod) + * @return FLUID_OK on success, FLUID_FAILED otherwise */ -void -fluid_synth_set_chorus(fluid_synth_t* synth, int nr, double level, +int fluid_synth_set_chorus(fluid_synth_t* synth, int nr, double level, double speed, double depth_ms, int type) { - fluid_synth_set_chorus_full (synth, FLUID_CHORUS_SET_ALL, nr, level, speed, + return fluid_synth_set_chorus_full (synth, FLUID_CHORUS_SET_ALL, nr, level, speed, depth_ms, type); } +/** + * Set the chorus voice count. See fluid_synth_set_chorus() for further info. + * @return FLUID_OK on success, FLUID_FAILED otherwise + */ +int fluid_synth_set_chorus_nr(fluid_synth_t* synth, int nr) +{ + return fluid_synth_set_chorus_full (synth, FLUID_CHORUS_SET_NR, nr, 0, 0, 0, 0); +} + +/** + * Set the chorus level. See fluid_synth_set_chorus() for further info. + * @return FLUID_OK on success, FLUID_FAILED otherwise + */ +int fluid_synth_set_chorus_level(fluid_synth_t* synth, double level) +{ + return fluid_synth_set_chorus_full (synth, FLUID_CHORUS_SET_LEVEL, 0, level, 0, 0, 0); +} + +/** + * Set the chorus speed. See fluid_synth_set_chorus() for further info. + * @return FLUID_OK on success, FLUID_FAILED otherwise + */ +int fluid_synth_set_chorus_speed(fluid_synth_t* synth, double speed) +{ + return fluid_synth_set_chorus_full (synth, FLUID_CHORUS_SET_SPEED, 0, 0, speed, 0, 0); +} + +/** + * Set the chorus depth. See fluid_synth_set_chorus() for further info. + * @return FLUID_OK on success, FLUID_FAILED otherwise + */ +int fluid_synth_set_chorus_depth(fluid_synth_t* synth, double depth_ms) +{ + return fluid_synth_set_chorus_full (synth, FLUID_CHORUS_SET_DEPTH, 0, 0, 0, depth_ms, 0); +} + +/** + * Set the chorus type. See fluid_synth_set_chorus() for further info. + * @return FLUID_OK on success, FLUID_FAILED otherwise + */ +int fluid_synth_set_chorus_type(fluid_synth_t* synth, int type) +{ + return fluid_synth_set_chorus_full (synth, FLUID_CHORUS_SET_TYPE, 0, 0, 0, 0, type); +} + /** * Set one or more chorus parameters. * @param synth FluidSynth instance @@ -4050,15 +4093,16 @@ fluid_synth_set_chorus(fluid_synth_t* synth, int nr, double level, * @param depth_ms Chorus depth (max value depends on synth sample rate, * 0.0-21.0 is safe for sample rate values up to 96KHz) * @param type Chorus waveform type (#fluid_chorus_mod) + * @return FLUID_OK on success, FLUID_FAILED otherwise */ int fluid_synth_set_chorus_full(fluid_synth_t* synth, int set, int nr, double level, double speed, double depth_ms, int type) { + int ret; fluid_return_val_if_fail (synth != NULL, FLUID_FAILED); - - if (!(set & FLUID_CHORUS_SET_ALL)) - set = FLUID_CHORUS_SET_ALL; + /* if non of the flags is set, fail */ + fluid_return_val_if_fail (set & FLUID_CHORUS_SET_ALL, FLUID_FAILED); /* Synth shadow values are set here so that they will be returned if queried */ fluid_synth_api_enter(synth); @@ -4078,12 +4122,12 @@ fluid_synth_set_chorus_full(fluid_synth_t* synth, int set, int nr, double level, if (set & FLUID_CHORUS_SET_TYPE) fluid_atomic_int_set (&synth->chorus_type, type); - fluid_rvoice_eventhandler_push5(synth->eventhandler, + ret = fluid_rvoice_eventhandler_push5(synth->eventhandler, fluid_rvoice_mixer_set_chorus_params, synth->eventhandler->mixer, set, nr, level, speed, depth_ms, type); - FLUID_API_RETURN(FLUID_OK); + FLUID_API_RETURN(ret); } /** From f4a3c7302e213575245b93d9b40e2b60449b63f2 Mon Sep 17 00:00:00 2001 From: derselbst Date: Tue, 3 Oct 2017 21:42:36 +0200 Subject: [PATCH 5/8] avoid midi_router cmd conflicts if multiple cmd handlers are used + fix build --- include/fluidsynth/shell.h | 4 +++ src/bindings/fluid_cmd.c | 50 ++++++++++++++++++------------------ src/midi/fluid_midi_router.c | 4 --- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/include/fluidsynth/shell.h b/include/fluidsynth/shell.h index bb32bf7c..4ba4c3be 100644 --- a/include/fluidsynth/shell.h +++ b/include/fluidsynth/shell.h @@ -63,10 +63,14 @@ typedef struct { char* help; /**< A help string */ } fluid_cmd_t; +/* the shell cmd handler struct */ typedef struct { fluid_synth_t* synth; fluid_midi_router_t* router; fluid_cmd_hash_t* commands; + + fluid_midi_router_rule_t *cmd_rule; /* Rule currently being processed by shell command handler */ + int cmd_rule_type; /* Type of the rule (#fluid_midi_router_rule_type) */ } fluid_cmd_handler_t; /* The command handler */ diff --git a/src/bindings/fluid_cmd.c b/src/bindings/fluid_cmd.c index 6a55a415..c03e6ce6 100644 --- a/src/bindings/fluid_cmd.c +++ b/src/bindings/fluid_cmd.c @@ -51,7 +51,7 @@ static int fluid_shell_run(fluid_shell_t* shell); static void fluid_shell_init(fluid_shell_t* shell, fluid_settings_t* settings, fluid_cmd_handler_t* handler, fluid_istream_t in, fluid_ostream_t out); -static int fluid_handle_voice_count (fluid_synth_t *synth, int ac, char **av, +static int fluid_handle_voice_count (fluid_cmd_handler_t* handler, int ac, char **av, fluid_ostream_t out); void fluid_shell_settings(fluid_settings_t* settings) @@ -447,7 +447,7 @@ fluid_handle_pitch_bend(fluid_cmd_handler_t* handler, int ac, char** av, fluid_o fluid_ostream_printf(out, "pitch_bend: invalid argument\n"); return -1; } - return fluid_synth_pitch_bend(synth, atoi(av[0]), atoi(av[1])); + return fluid_synth_pitch_bend(handler->synth, atoi(av[0]), atoi(av[1])); } int @@ -465,7 +465,7 @@ fluid_handle_pitch_bend_range(fluid_cmd_handler_t* handler, int ac, char** av, f } channum = atoi(av[0]); value = atoi(av[1]); - fluid_channel_set_pitch_wheel_sensitivity(synth->channel[channum], value); + fluid_channel_set_pitch_wheel_sensitivity(handler->synth->channel[channum], value); return 0; } @@ -574,7 +574,7 @@ fluid_handle_inst(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream int fluid_handle_channels(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { - fluid_synth_channel_info_t info; + fluid_preset_t* preset; int verbose = 0; int i; @@ -1681,29 +1681,29 @@ int fluid_handle_router_begin(fluid_cmd_handler_t* handler, int ac, char** av, f CHECK_VALID_ROUTER (router, out); if (FLUID_STRCMP (av[0], "note") == 0) - router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_NOTE; + handler->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_NOTE; else if (FLUID_STRCMP (av[0], "cc") == 0) - router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_CC; + handler->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_CC; else if (FLUID_STRCMP (av[0], "prog") == 0) - router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_PROG_CHANGE; + handler->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_PROG_CHANGE; else if (FLUID_STRCMP (av[0], "pbend") == 0) - router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_PITCH_BEND; + handler->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_PITCH_BEND; else if (FLUID_STRCMP (av[0], "cpress") == 0) - router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_CHANNEL_PRESSURE; + handler->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_CHANNEL_PRESSURE; else if (FLUID_STRCMP (av[0], "kpress") == 0) - router->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_KEY_PRESSURE; + handler->cmd_rule_type = FLUID_MIDI_ROUTER_RULE_KEY_PRESSURE; else { fluid_ostream_printf (out, "router_begin requires [note|cc|prog|pbend|cpress|kpress]\n"); return FLUID_FAILED; } - if (router->cmd_rule) - delete_fluid_midi_router_rule (router->cmd_rule); + if (handler->cmd_rule) + delete_fluid_midi_router_rule (handler->cmd_rule); - router->cmd_rule = new_fluid_midi_router_rule (); + handler->cmd_rule = new_fluid_midi_router_rule (); - if (!router->cmd_rule) + if (!handler->cmd_rule) return FLUID_FAILED; return FLUID_OK; @@ -1721,17 +1721,17 @@ int fluid_handle_router_end(fluid_cmd_handler_t* handler, int ac, char** av, flu CHECK_VALID_ROUTER (router, out); - if (!router->cmd_rule) + if (!handler->cmd_rule) { fluid_ostream_printf (out, "No active router_begin command.\n"); return FLUID_FAILED; } /* Add the rule */ - if (fluid_midi_router_add_rule (router, router->cmd_rule, router->cmd_rule_type) != FLUID_OK) - delete_fluid_midi_router_rule (router->cmd_rule); /* Free on failure */ + if (fluid_midi_router_add_rule (router, handler->cmd_rule, handler->cmd_rule_type) != FLUID_OK) + delete_fluid_midi_router_rule (handler->cmd_rule); /* Free on failure */ - router->cmd_rule = NULL; + handler->cmd_rule = NULL; return FLUID_OK; } @@ -1748,13 +1748,13 @@ int fluid_handle_router_chan(fluid_cmd_handler_t* handler, int ac, char** av, fl CHECK_VALID_ROUTER (router, out); - if (!router->cmd_rule) + if (!handler->cmd_rule) { fluid_ostream_printf (out, "No active router_begin command.\n"); return FLUID_FAILED; } - fluid_midi_router_rule_set_chan (router->cmd_rule, atoi (av[0]), atoi (av[1]), + fluid_midi_router_rule_set_chan (handler->cmd_rule, atoi (av[0]), atoi (av[1]), atof (av[2]), atoi (av[3])); return FLUID_OK; } @@ -1771,13 +1771,13 @@ int fluid_handle_router_par1(fluid_cmd_handler_t* handler, int ac, char** av, fl CHECK_VALID_ROUTER (router, out); - if (!router->cmd_rule) + if (!handler->cmd_rule) { fluid_ostream_printf (out, "No active router_begin command.\n"); return FLUID_FAILED; } - fluid_midi_router_rule_set_param1 (router->cmd_rule, atoi (av[0]), atoi (av[1]), + fluid_midi_router_rule_set_param1 (handler->cmd_rule, atoi (av[0]), atoi (av[1]), atof (av[2]), atoi (av[3])); return FLUID_OK; } @@ -1785,7 +1785,7 @@ int fluid_handle_router_par1(fluid_cmd_handler_t* handler, int ac, char** av, fl /* Command handler for "router_par2" command */ int fluid_handle_router_par2(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream_t out) { - fluid_midi_router_t* router = synth->midi_router; + fluid_midi_router_t* router = handler->router; if (ac != 4) { fluid_ostream_printf(out, "router_par2 needs four args: min, max, mul, add."); @@ -1794,13 +1794,13 @@ int fluid_handle_router_par2(fluid_cmd_handler_t* handler, int ac, char** av, fl CHECK_VALID_ROUTER (router, out); - if (!router->cmd_rule) + if (!handler->cmd_rule) { fluid_ostream_printf (out, "No active router_begin command.\n"); return FLUID_FAILED; } - fluid_midi_router_rule_set_param2 (router->cmd_rule, atoi (av[0]), atoi (av[1]), + fluid_midi_router_rule_set_param2 (handler->cmd_rule, atoi (av[0]), atoi (av[1]), atof (av[2]), atoi (av[3])); return FLUID_OK; } diff --git a/src/midi/fluid_midi_router.c b/src/midi/fluid_midi_router.c index cb09a62e..215d692e 100644 --- a/src/midi/fluid_midi_router.c +++ b/src/midi/fluid_midi_router.c @@ -42,10 +42,6 @@ struct _fluid_midi_router_t { void* event_handler_data; /* One arg for the callback */ int nr_midi_channels; /* For clipping the midi channel */ - - /* FIXME - If there are multiple command handlers, they will conflict! */ - fluid_midi_router_rule_t *cmd_rule; /* Rule currently being processed by shell command handler */ - int cmd_rule_type; /* Type of the rule (fluid_midi_router_rule_type) */ }; struct _fluid_midi_router_rule_t { From 23d15db8facc4b38855af1ab5be8130958d4321f Mon Sep 17 00:00:00 2001 From: derselbst Date: Wed, 4 Oct 2017 14:30:46 +0200 Subject: [PATCH 6/8] remove fluid_synth_set_midi_router() only needed by shell command handler previously --- src/synth/fluid_synth.c | 17 ----------------- src/synth/fluid_synth.h | 1 - 2 files changed, 18 deletions(-) diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index ee64b140..275caace 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -4953,23 +4953,6 @@ fluid_synth_get_gen(fluid_synth_t* synth, int chan, int param) FLUID_API_RETURN(result); } -/** - * Assign a MIDI router to a synth. - * @param synth FluidSynth instance - * @param router MIDI router to assign to the synth - * - * @note This should only be done once and prior to using the synth. - */ -void -fluid_synth_set_midi_router(fluid_synth_t* synth, fluid_midi_router_t* router) -{ - fluid_return_if_fail (synth != NULL); - fluid_synth_api_enter(synth); - - synth->midi_router = router; - fluid_synth_api_exit(synth); -}; - /** * Handle MIDI event from MIDI router, used as a callback function. * @param data FluidSynth instance diff --git a/src/synth/fluid_synth.h b/src/synth/fluid_synth.h index 2a47a32b..7280d78e 100644 --- a/src/synth/fluid_synth.h +++ b/src/synth/fluid_synth.h @@ -162,7 +162,6 @@ struct _fluid_synth_t fluid_tuning_t*** tuning; /**< 128 banks of 128 programs for the tunings */ fluid_private_t tuning_iter; /**< Tuning iterators per each thread */ - fluid_midi_router_t* midi_router; /**< The midi router. Could be done nicer. */ fluid_sample_timer_t* sample_timers; /**< List of timers triggered before a block is processed */ unsigned int min_note_length_ticks; /**< If note-offs are triggered just after a note-on, they will be delayed */ From e36e39249b76ac71787dba66abc199eea321df04 Mon Sep 17 00:00:00 2001 From: derselbst Date: Fri, 6 Oct 2017 10:59:41 +0200 Subject: [PATCH 7/8] update API docs for new chorus/reverb setters --- doc/fluidsynth-v11-devdoc.txt | 5 ++++- include/fluidsynth/synth.h | 7 ------- src/synth/fluid_synth.c | 3 ++- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/doc/fluidsynth-v11-devdoc.txt b/doc/fluidsynth-v11-devdoc.txt index 0336daa9..482b89a4 100644 --- a/doc/fluidsynth-v11-devdoc.txt +++ b/doc/fluidsynth-v11-devdoc.txt @@ -74,17 +74,20 @@ Changes in FluidSynth @NEXT_RELEASE@ concerning developers: - remove deprecated fluid_synth_get_program() and fluid_synth_get_channel_preset(), use fluid_synth_get_channel_info() instead - remove deprecated fluid_settings_getstr() +- remove deprecated fluid_synth_set_midi_router() - remove deprecated FLUID_HINT_INTEGER - remove misspelled FLUID_SEQ_PITCHWHHELSENS macro - remove obsolete "audio.[out|in]put-channels" settings - remove unimplemented "synth.dump" setting - remove fluid_synth_set_gen2(), fluid_synth_set_gen() now behaves as fluid_synth_set_gen2() -- all public \c fluid_settings_* functions that return an int that shall not be interpreted as a bool consistently return either FLUID_OK or FLUID_FAILED +- all public \c fluid_settings_* functions that return an integer which is not meant to be interpreted as bool consistently return either FLUID_OK or FLUID_FAILED - struct fluid_mod_t was removed from public API - struct _fluid_gen_t, fluid_gen_set_default_values() and enum fluid_gen_flags were removed from public API - add "synth.volenv" a setting for volume envelope processing - add support for polyonic key pressure events, see fluid_event_key_pressure() - add fluid_synth_add_default_mod() for manipulating default modulators +- add individual reverb setters: fluid_synth_set_reverb_roomsize(), fluid_synth_set_reverb_damp(), fluid_synth_set_reverb_width(), fluid_synth_set_reverb_level() +- add individual chorus setters: fluid_synth_set_chorus_nr(), fluid_synth_set_chorus_level(), fluid_synth_set_chorus_speed(), fluid_synth_set_chorus_depth(), fluid_synth_set_chorus_type() \section NewIn1_1_7 Whats new in 1.1.7? diff --git a/include/fluidsynth/synth.h b/include/fluidsynth/synth.h index 70305417..12cba85f 100644 --- a/include/fluidsynth/synth.h +++ b/include/fluidsynth/synth.h @@ -145,7 +145,6 @@ FLUIDSYNTH_API int fluid_synth_get_bank_offset(fluid_synth_t* synth, int sfont_i * */ - /** Set the parameters for the built-in reverb unit */ FLUIDSYNTH_API int fluid_synth_set_reverb(fluid_synth_t* synth, double roomsize, double damping, double width, double level); FLUIDSYNTH_API int fluid_synth_set_reverb_roomsize(fluid_synth_t* synth, double roomsize); @@ -153,7 +152,6 @@ FLUIDSYNTH_API int fluid_synth_set_reverb_damp(fluid_synth_t* synth, double damp FLUIDSYNTH_API int fluid_synth_set_reverb_width(fluid_synth_t* synth, double width); FLUIDSYNTH_API int fluid_synth_set_reverb_level(fluid_synth_t* synth, double level); - /** Turn on (1) / off (0) the built-in reverb unit */ FLUIDSYNTH_API void fluid_synth_set_reverb_on(fluid_synth_t* synth, int on); FLUIDSYNTH_API double fluid_synth_get_reverb_roomsize(fluid_synth_t* synth); FLUIDSYNTH_API double fluid_synth_get_reverb_damp(fluid_synth_t* synth); @@ -176,10 +174,6 @@ enum fluid_chorus_mod { FLUID_CHORUS_MOD_TRIANGLE = 1 /**< Triangle wave chorus modulation */ }; - /** Set up the chorus. It should be turned on with fluid_synth_set_chorus_on. - * If faulty parameters are given, all new settings are discarded. - * Keep in mind, that the needed CPU time is proportional to 'nr'. - */ FLUIDSYNTH_API int fluid_synth_set_chorus(fluid_synth_t* synth, int nr, double level, double speed, double depth_ms, int type); FLUIDSYNTH_API int fluid_synth_set_chorus_nr(fluid_synth_t* synth, int nr); @@ -188,7 +182,6 @@ FLUIDSYNTH_API int fluid_synth_set_chorus_speed(fluid_synth_t* synth, double spe FLUIDSYNTH_API int fluid_synth_set_chorus_depth(fluid_synth_t* synth, double depth_ms); FLUIDSYNTH_API int fluid_synth_set_chorus_type(fluid_synth_t* synth, int type); - /** Turn on (1) / off (0) the built-in chorus unit */ FLUIDSYNTH_API void fluid_synth_set_chorus_on(fluid_synth_t* synth, int on); FLUIDSYNTH_API int fluid_synth_get_chorus_nr(fluid_synth_t* synth); FLUIDSYNTH_API double fluid_synth_get_chorus_level(fluid_synth_t* synth); diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 275caace..fcf7f671 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -4019,7 +4019,8 @@ fluid_synth_set_chorus_on(fluid_synth_t* synth, int on) } /** - * Set chorus parameters. + * Set chorus parameters. It should be turned on with fluid_synth_set_chorus_on(). + * Keep in mind, that the needed CPU time is proportional to 'nr'. * @param synth FluidSynth instance * @param nr Chorus voice count (0-99, CPU time consumption proportional to * this value) From 5ae62791ae1e39e0d9c1afe67f57549c2cb4ae63 Mon Sep 17 00:00:00 2001 From: Tom M Date: Fri, 6 Oct 2017 13:15:09 +0200 Subject: [PATCH 8/8] dont hardcode buf size --- src/fluidsynth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fluidsynth.c b/src/fluidsynth.c index 3c1f290e..dd813c5d 100644 --- a/src/fluidsynth.c +++ b/src/fluidsynth.c @@ -695,9 +695,9 @@ int main(int argc, char** argv) /* try to load the user or system configuration */ if (config_file != NULL) { fluid_source(cmd_handler, config_file); - } else if (fluid_get_userconf(buf, 512) != NULL) { + } else if (fluid_get_userconf(buf, sizeof(buf)*sizeof(buf[0])) != NULL) { fluid_source(cmd_handler, buf); - } else if (fluid_get_sysconf(buf, 512) != NULL) { + } else if (fluid_get_sysconf(buf, sizeof(buf)*sizeof(buf[0])) != NULL) { fluid_source(cmd_handler, buf); }