Command handler decoupled. Moved config file loading after starting everything.

This commit is contained in:
Bernat Arlandis i Mañó 2009-03-23 15:58:33 +00:00 committed by derselbst
parent 0e2e67d6f5
commit 3c14435a8c
6 changed files with 425 additions and 233 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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 */

File diff suppressed because it is too large Load Diff

View File

@ -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);

View File

@ -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
*/