diff --git a/doc/recent_changes.txt b/doc/recent_changes.txt index 503857d5..f7423532 100644 --- a/doc/recent_changes.txt +++ b/doc/recent_changes.txt @@ -10,6 +10,7 @@ - The sequencer's queue no longer blocks the synthesizer thread, due to being busy arranging its events internally. - Events that share the same tick was given a new, documented order, see fluid_sequencer_send_at(). - The sequencer's scale can now be used for arbitrary tempo changes. Previously, the scale of the sequencer was limited to 1000. The only limitation now is >0. + - There is now a dedicated event type for changing the sequencer's time scale, see fluid_event_scale(). - The dynamic-sample-loader has learned support to pin samples, see fluid_synth_pin_preset() and fluid_synth_unpin_preset() - Added getter and setter functions for individual effect groups - Support for UTF-8 filenames under Windows, see fluid_synth_sfload() diff --git a/include/fluidsynth/event.h b/include/fluidsynth/event.h index 3da4ce23..e50f974f 100644 --- a/include/fluidsynth/event.h +++ b/include/fluidsynth/event.h @@ -61,6 +61,7 @@ enum fluid_seq_event_type FLUID_SEQ_KEYPRESSURE, /**< Polyphonic aftertouch event @since 2.0.0 */ FLUID_SEQ_SYSTEMRESET, /**< System reset event @since 1.1.0 */ FLUID_SEQ_UNREGISTERING, /**< Called when a sequencer client is being unregistered. @since 1.1.0 */ + FLUID_SEQ_SCALE, /**< Sets a new time scale for the sequencer @since 2.2.0 */ FLUID_SEQ_LASTEVENT /**< @internal Defines the count of events enums @warning This symbol is not part of the public API and ABI stability guarantee and may change at any time! */ @@ -115,6 +116,8 @@ FLUIDSYNTH_API void fluid_event_system_reset(fluid_event_t *evt); /* Only when unregistering clients */ FLUIDSYNTH_API void fluid_event_unregistering(fluid_event_t *evt); +FLUIDSYNTH_API void fluid_event_scale(fluid_event_t *evt, double new_scale); + /* Accessing event data */ FLUIDSYNTH_API int fluid_event_get_type(fluid_event_t *evt); FLUIDSYNTH_API fluid_seq_id_t fluid_event_get_source(fluid_event_t *evt); @@ -129,6 +132,7 @@ FLUIDSYNTH_API void *fluid_event_get_data(fluid_event_t *evt); FLUIDSYNTH_API unsigned int fluid_event_get_duration(fluid_event_t *evt); FLUIDSYNTH_API short fluid_event_get_bank(fluid_event_t *evt); FLUIDSYNTH_API int fluid_event_get_pitch(fluid_event_t *evt); +FLUIDSYNTH_API double fluid_event_get_scale(fluid_event_t *evt); FLUIDSYNTH_API unsigned int fluid_event_get_sfont_id(fluid_event_t *evt); /* @} */ diff --git a/src/midi/fluid_seqbind.c b/src/midi/fluid_seqbind.c index 9fb01ffa..eb922297 100644 --- a/src/midi/fluid_seqbind.c +++ b/src/midi/fluid_seqbind.c @@ -185,7 +185,6 @@ fluid_seq_fluidsynth_callback(unsigned int time, fluid_event_t *evt, fluid_seque switch(fluid_event_get_type(evt)) { - case FLUID_SEQ_NOTEON: fluid_synth_noteon(synth, fluid_event_get_channel(evt), fluid_event_get_key(evt), fluid_event_get_velocity(evt)); break; @@ -326,6 +325,10 @@ fluid_seq_fluidsynth_callback(unsigned int time, fluid_event_t *evt, fluid_seque /* nothing in fluidsynth */ break; + case FLUID_SEQ_SCALE: + fluid_sequencer_set_time_scale(seq, fluid_event_get_scale(evt)); + break; + default: break; } diff --git a/src/synth/fluid_event.c b/src/synth/fluid_event.c index 9621cede..3741c65c 100644 --- a/src/synth/fluid_event.c +++ b/src/synth/fluid_event.c @@ -479,6 +479,20 @@ fluid_event_unregistering(fluid_event_t *evt) evt->type = FLUID_SEQ_UNREGISTERING; } +/** + * Set a sequencer event to be a scale change event. + * Useful for scheduling tempo changes. + * @param evt Sequencer event structure + * @param new_scale The new time scale to apply to the sequencer, see fluid_sequencer_set_time_scale() + * @since 2.2.0 + */ +void +fluid_event_scale(fluid_event_t *evt, double new_scale) +{ + evt->type = FLUID_SEQ_SCALE; + evt->scale = new_scale; +} + /** * Set a sequencer event to be a channel-wide aftertouch event. * @param evt Sequencer event structure @@ -744,3 +758,15 @@ fluid_event_get_sfont_id(fluid_event_t *evt) { return evt->duration; } + +/** + * Gets time scale field from a sequencer event structure. + * @param evt Sequencer event structure + * @return SoundFont identifier value. + * + * Used by the #FLUID_SEQ_SCALE event type. + */ +double fluid_event_get_scale(fluid_event_t *evt) +{ + return evt->scale; +} diff --git a/src/synth/fluid_event.h b/src/synth/fluid_event.h index 7c60a872..4a0cca5d 100644 --- a/src/synth/fluid_event.h +++ b/src/synth/fluid_event.h @@ -46,6 +46,7 @@ struct _fluid_event_t fluid_note_id_t id; int pitch; unsigned int duration; + double scale; void *data; };