diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index dc5218f..162a62d 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -161,26 +161,45 @@ void JuicySFAudioProcessor::processBlock (AudioBuffer& buffer, MidiBuffer // TODO: factor into a MidiCollector for (MidiBuffer::Iterator i (midiMessages); i.getNextEvent (m, time);) { - Logger::outputDebugString ( m.getDescription() ); + Logger::outputDebugString ( m.getDescription() ); + + // explicitly not handling note_on/off, or pitch_bend, because these are (for better or worse) + // responsibilities of SoundfontSynthVoice. + // well, by that logic maybe I should move program change onto Voice. but it doesn't feel like a per-voice concern. if (m.isController()) { -// switch(static_cast(m.getControllerNumber())) { -// case GEN_VOLENVATTACK: -// -// break; -// default: -// break; -// } -// m.getControllerValue() -// fluid_event_t *event(new_fluid_event()); -// fluid_event_control_change(event, fluidSynthModel.getChannel(), m.getControllerNumber(), m.getControllerValue()); -// delete_fluid_event(event); fluid_midi_event_t *midi_event(new_fluid_midi_event()); fluid_midi_event_set_type(midi_event, static_cast(CONTROL_CHANGE)); fluid_midi_event_set_channel(midi_event, fluidSynthModel.getChannel()); fluid_midi_event_set_control(midi_event, m.getControllerNumber()); fluid_midi_event_set_value(midi_event, m.getControllerValue()); fluid_synth_handle_midi_event(fluidSynth, midi_event); - + delete_fluid_midi_event(midi_event); + } else if (m.isProgramChange()) { + fluid_midi_event_t *midi_event(new_fluid_midi_event()); + fluid_midi_event_set_type(midi_event, static_cast(PROGRAM_CHANGE)); + fluid_midi_event_set_channel(midi_event, fluidSynthModel.getChannel()); + fluid_midi_event_set_program(midi_event, m.getProgramChangeNumber()); + fluid_synth_handle_midi_event(fluidSynth, midi_event); + delete_fluid_midi_event(midi_event); + } else if (m.isChannelPressure()) { + fluid_midi_event_t *midi_event(new_fluid_midi_event()); + fluid_midi_event_set_type(midi_event, static_cast(CHANNEL_PRESSURE)); + fluid_midi_event_set_channel(midi_event, fluidSynthModel.getChannel()); + fluid_midi_event_set_program(midi_event, m.getChannelPressureValue()); + fluid_synth_handle_midi_event(fluidSynth, midi_event); + delete_fluid_midi_event(midi_event); + } else if (m.isResetAllControllers()) { + fluid_midi_event_t *midi_event(new_fluid_midi_event()); + fluid_midi_event_set_type(midi_event, static_cast(MIDI_SYSTEM_RESET)); + fluid_synth_handle_midi_event(fluidSynth, midi_event); + delete_fluid_midi_event(midi_event); + } else if (m.isSysEx()) { + fluid_midi_event_t *midi_event(new_fluid_midi_event()); + fluid_midi_event_set_type(midi_event, static_cast(MIDI_SYSEX)); + // I assume that the MidiMessage's sysex buffer would be freed anyway when MidiMessage is destroyed, so set dynamic=false + // to ensure that fluidsynth does not attempt to free the sysex buffer during delete_fluid_midi_event() + fluid_midi_event_set_sysex(midi_event, const_cast(m.getSysExData()), m.getSysExDataSize(), static_cast(false)); + fluid_synth_handle_midi_event(fluidSynth, midi_event); delete_fluid_midi_event(midi_event); } } diff --git a/Source/SoundfontSynthVoice.cpp b/Source/SoundfontSynthVoice.cpp index bcf8dc6..aa8d942 100644 --- a/Source/SoundfontSynthVoice.cpp +++ b/Source/SoundfontSynthVoice.cpp @@ -58,12 +58,16 @@ void SoundfontSynthVoice::stopNote (float /*velocity*/, bool allowTailOff) { clearCurrentNote(); fluid_synth_noteoff(synth, 0, this->midiNoteNumber); } -void SoundfontSynthVoice::pitchWheelMoved (int /*newValue*/) { - // who cares? + +// receives input as MIDI 0 to 16383, with 8192 being center +// this is also exactly the input fluidsynth requires +void SoundfontSynthVoice::pitchWheelMoved (int newValue) { + Logger::outputDebugString ( juce::String::formatted("Pitch wheel: %d\n", newValue) ); + fluid_synth_pitch_bend(synth, 0, newValue); } -void SoundfontSynthVoice::controllerMoved (int /*controllerNumber*/, int /*newValue*/) { - // what's a controller? +void SoundfontSynthVoice::controllerMoved (int controllerNumber, int newValue) { + Logger::outputDebugString ( juce::String::formatted("Controlled moved: %d, %d\n", controllerNumber, newValue) ); } void SoundfontSynthVoice::renderNextBlock (AudioBuffer& outputBuffer, int startSample, int numSamples) { @@ -94,4 +98,4 @@ void SoundfontSynthVoice::renderNextBlock (AudioBuffer& outputBuffer, int // } // } // } -//} \ No newline at end of file +//}