FluidSynth / fluidsynth

Software synthesizer based on the SoundFont 2 specifications
https://www.fluidsynth.org
GNU Lesser General Public License v2.1
1.76k stars 246 forks source link

Add a function to create a sequencer event from a midi event #1078

Closed jimhen3ry closed 2 years ago

jimhen3ry commented 2 years ago

Related discussion

This idea was suggested by Tom M. at the end of Discussion #1072 .

Is your feature request related to a problem?

MIDI input can be in the form of a FluidSynth MIDI Event (fluid_midi_event_t), e.g. input from the MIDI Player. An application that receives FluidSynth MIDI Events can send them to the synthesizer with fluid_synth_handle_midi_event(). Alternatively, MIDI Events can be sent to the FluidSynth Sequencer with fluid_sequencer_add_midi_event_to_buffer().

fluid_sequencer_add_midi_event_to_buffer() "[t]ransforms 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." There is no straightforward way of sending a MIDI Event to the Sequencer for sending at a later time.

Describe the solution you'd like

Add a function to transform an incoming MIDI event to a sequencer event without adding the event to a sequencer queue. This would allow an application to use fluid_sequencer_send_at() to send a MIDI Event to the Sequencer for sending at a later time.

fluid_event_from_midi_event(fluid_event_t, const fluid_midi_event_t) is the proposed function to be added.

Additional context

It is proposed that the added function would only add the provided MIDI Event to the provided Sequencer Event. The application would need to add additional items to the Sequencer Event, e.g. a destination sequencer with fluid_event_set_dest(), before adding the Sequencer Event to a sequencer queue.

The current fluid_sequencer_add_midi_event_to_buffer() would be rewritten to place its current code for transforming an incoming MIDI event to a sequencer event in the new function and use that new function.

jimhen3ry commented 2 years ago

I have added fluid_event_from_midi_event(fluid_event_t, const fluid_midi_event_t) to midi/fluid_seqbind.c and added a FLUIDSYNTH_API line to include/seqbind.h. I have rewritten fluid_sequencer_add_midi_event_to_buffer() to use fluid_event_from_midi_event(). I did a commit of these changes in an issue1078 branch based on the 2.2.X branch. I did what I could think of to test these changes on a 64 bit Windows machine.

I have not contributed to an open source project before. I need some hand holding on how you would like me to proceed from here.

jimhen3ry commented 2 years ago

Attached is a patch file for my proposed changes: patch1078.txt

derselbst commented 2 years ago

Looks good, thanks. Ofc, it doesn't compile because the const qualifier is being discarded. I will fix this by next week.

I have not contributed to an open source project before. I need some hand holding on how you would like me to proceed from here.

You could have also forked this repo, commit and push your changes to your fork, and then create a PullRequest to propose the changes. But this way is fine either, now I opened the PullRequest: #1080

derselbst commented 2 years ago

Merged and will be part of 2.2.7, thanks!