From 757b151601696e3c00ec0cca20b9246668fdfcff Mon Sep 17 00:00:00 2001 From: derselbst Date: Tue, 12 Apr 2022 10:47:00 +0200 Subject: [PATCH] Move fluid_event_from_midi_event() to fluid_event.c --- include/fluidsynth/event.h | 1 + include/fluidsynth/seqbind.h | 2 - src/midi/fluid_seqbind.c | 82 ------------------------------------ src/synth/fluid_event.c | 81 +++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 84 deletions(-) diff --git a/include/fluidsynth/event.h b/include/fluidsynth/event.h index e50f974f..643f6c52 100644 --- a/include/fluidsynth/event.h +++ b/include/fluidsynth/event.h @@ -117,6 +117,7 @@ FLUIDSYNTH_API void fluid_event_system_reset(fluid_event_t *evt); FLUIDSYNTH_API void fluid_event_unregistering(fluid_event_t *evt); FLUIDSYNTH_API void fluid_event_scale(fluid_event_t *evt, double new_scale); +FLUIDSYNTH_API int fluid_event_from_midi_event(fluid_event_t *, const fluid_midi_event_t *); /* Accessing event data */ FLUIDSYNTH_API int fluid_event_get_type(fluid_event_t *evt); diff --git a/include/fluidsynth/seqbind.h b/include/fluidsynth/seqbind.h index 085f807d..b8fd1a40 100644 --- a/include/fluidsynth/seqbind.h +++ b/include/fluidsynth/seqbind.h @@ -35,8 +35,6 @@ extern "C" { FLUIDSYNTH_API fluid_seq_id_t fluid_sequencer_register_fluidsynth(fluid_sequencer_t *seq, fluid_synth_t *synth); FLUIDSYNTH_API -int fluid_event_from_midi_event(fluid_event_t *, const fluid_midi_event_t *); -FLUIDSYNTH_API int fluid_sequencer_add_midi_event_to_buffer(void *data, fluid_midi_event_t *event); /* @} */ diff --git a/src/midi/fluid_seqbind.c b/src/midi/fluid_seqbind.c index b0f62591..9ec06f20 100644 --- a/src/midi/fluid_seqbind.c +++ b/src/midi/fluid_seqbind.c @@ -355,88 +355,6 @@ static fluid_seq_id_t get_fluidsynth_dest(fluid_sequencer_t *seq) return -1; } -/** - * Transforms an incoming MIDI event (from a MIDI driver or MIDI router) to a - * sequencer event. - * - * @param evt returned sequencer event - * @param event MIDI event - * @return #FLUID_OK or #FLUID_FAILED - * - * @note This function copies the fields of the MIDI event into the provided - * sequencer event. Calling applications must create the sequencer event and set - * additional fields such as the source and destination of the sequencer event. - * - * @code{.cpp} - * // ... get MIDI event, e.g. using player_callback() - * - * // Send MIDI event to sequencer to play - * fluid_event_t *evt = new_fluid_event(); - * fluid_event_set_source(evt, -1); - * fluid_event_set_dest(evt, seqid); - * fluid_event_from_midi_event(evt, event); - * fluid_sequencer_send_at(sequencer, evt, 50, 0); // relative time - * delete_fluid_event(evt); - * @endcode - * - * @since 2.2.7 - */ -int fluid_event_from_midi_event(fluid_event_t *evt, const fluid_midi_event_t *event) -{ - fluid_return_val_if_fail(event != NULL, FLUID_FAILED); - - int chan = fluid_midi_event_get_channel(event); - - switch (fluid_midi_event_get_type(event)) - { - case NOTE_OFF: - fluid_event_noteoff(evt, chan, (short)fluid_midi_event_get_key(event)); - break; - - case NOTE_ON: - fluid_event_noteon(evt, - fluid_midi_event_get_channel(event), - (short)fluid_midi_event_get_key(event), - (short)fluid_midi_event_get_velocity(event)); - break; - - case CONTROL_CHANGE: - fluid_event_control_change(evt, - chan, - (short)fluid_midi_event_get_control(event), - (short)fluid_midi_event_get_value(event)); - break; - - case PROGRAM_CHANGE: - fluid_event_program_change(evt, chan, (short)fluid_midi_event_get_program(event)); - break; - - case PITCH_BEND: - fluid_event_pitch_bend(evt, chan, fluid_midi_event_get_pitch(event)); - break; - - case CHANNEL_PRESSURE: - fluid_event_channel_pressure(evt, chan, (short)fluid_midi_event_get_program(event)); - break; - - case KEY_PRESSURE: - fluid_event_key_pressure(evt, - chan, - (short)fluid_midi_event_get_key(event), - (short)fluid_midi_event_get_value(event)); - break; - - case MIDI_SYSTEM_RESET: - fluid_event_system_reset(evt); - break; - - default: /* Not yet implemented */ - return FLUID_FAILED; - } - - return FLUID_OK; -} - /** * Transforms an incoming MIDI event (from a MIDI driver or MIDI router) to a * sequencer event and adds it to the sequencer queue for sending as soon as possible. diff --git a/src/synth/fluid_event.c b/src/synth/fluid_event.c index ddc6aa8b..ff8d9f79 100644 --- a/src/synth/fluid_event.c +++ b/src/synth/fluid_event.c @@ -30,6 +30,7 @@ #include "fluid_event.h" #include "fluidsynth_priv.h" +#include "fluid_midi.h" /*************************************************************** * @@ -577,7 +578,87 @@ fluid_event_system_reset(fluid_event_t *evt) evt->type = FLUID_SEQ_SYSTEMRESET; } +/** + * Transforms an incoming MIDI event (from a MIDI driver or MIDI router) to a + * sequencer event. + * + * @param evt returned sequencer event + * @param event MIDI event + * @return #FLUID_OK or #FLUID_FAILED + * + * @note This function copies the fields of the MIDI event into the provided + * sequencer event. Calling applications must create the sequencer event and set + * additional fields such as the source and destination of the sequencer event. + * + * @code{.cpp} + * // ... get MIDI event, e.g. using player_callback() + * + * // Send MIDI event to sequencer to play + * fluid_event_t *evt = new_fluid_event(); + * fluid_event_set_source(evt, -1); + * fluid_event_set_dest(evt, seqid); + * fluid_event_from_midi_event(evt, event); + * fluid_sequencer_send_at(sequencer, evt, 50, 0); // relative time + * delete_fluid_event(evt); + * @endcode + * + * @since 2.2.7 + */ +int fluid_event_from_midi_event(fluid_event_t *evt, const fluid_midi_event_t *event) +{ + fluid_return_val_if_fail(event != NULL, FLUID_FAILED); + int chan = fluid_midi_event_get_channel(event); + + switch (fluid_midi_event_get_type(event)) + { + case NOTE_OFF: + fluid_event_noteoff(evt, chan, (short)fluid_midi_event_get_key(event)); + break; + + case NOTE_ON: + fluid_event_noteon(evt, + fluid_midi_event_get_channel(event), + (short)fluid_midi_event_get_key(event), + (short)fluid_midi_event_get_velocity(event)); + break; + + case CONTROL_CHANGE: + fluid_event_control_change(evt, + chan, + (short)fluid_midi_event_get_control(event), + (short)fluid_midi_event_get_value(event)); + break; + + case PROGRAM_CHANGE: + fluid_event_program_change(evt, chan, (short)fluid_midi_event_get_program(event)); + break; + + case PITCH_BEND: + fluid_event_pitch_bend(evt, chan, fluid_midi_event_get_pitch(event)); + break; + + case CHANNEL_PRESSURE: + fluid_event_channel_pressure(evt, chan, (short)fluid_midi_event_get_program(event)); + break; + + case KEY_PRESSURE: + fluid_event_key_pressure(evt, + chan, + (short)fluid_midi_event_get_key(event), + (short)fluid_midi_event_get_value(event)); + break; + + case MIDI_SYSTEM_RESET: + fluid_event_system_reset(evt); + break; + + default: /* Not yet implemented */ + return FLUID_FAILED; + } + + return FLUID_OK; +} /* * Accessing event data