diff --git a/Source/FluidSynthModel.cpp b/Source/FluidSynthModel.cpp index 594c3ef..305d5cc 100644 --- a/Source/FluidSynthModel.cpp +++ b/Source/FluidSynthModel.cpp @@ -55,6 +55,18 @@ void FluidSynthModel::initialise() { } fluid_synth_set_gain(synth, 2.0); + + for(int i{SOUND_CTRL1}; i <= SOUND_CTRL10; i++) + { + 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, channel); + fluid_midi_event_set_control(midi_event, i); + fluid_midi_event_set_value(midi_event, 0); + fluid_synth_handle_midi_event(synth, midi_event); + delete_fluid_midi_event(midi_event); +// fluid_channel_set_cc(channel, i, 0); + } // fluid_synth_bank_select(synth, 0, 3); @@ -68,9 +80,14 @@ void FluidSynthModel::initialise() { // http://www.synthfont.com/SoundFont_NRPNs.PDF float env_amount(20000.0f); +// float env_amount(24000.0f); + + // note: fluid_chan.c#fluid_channel_init_ctrl() + // all SOUND_CTRL are inited with value of 64, not zero. + // "Just like panning, a value of 64 indicates no change for sound ctrls" fluid_mod_t *mod(new_fluid_mod()); - +// fluid_mod_set_source1(mod, static_cast(SOUND_CTRL2), // MIDI CC 71 Timbre/Harmonic Intensity (filter resonance) FLUID_MOD_CC @@ -92,6 +109,7 @@ void FluidSynthModel::initialise() { | FLUID_MOD_POSITIVE); fluid_mod_set_source2(mod, 0, 0); fluid_mod_set_dest(mod, GEN_VOLENVRELEASE); +// fluid_mod_set_amount(mod, 15200.0f); fluid_mod_set_amount(mod, env_amount); fluid_synth_add_default_mod(synth, mod, FLUID_SYNTH_ADD); delete_fluid_mod(mod); @@ -109,6 +127,7 @@ void FluidSynthModel::initialise() { fluid_synth_add_default_mod(synth, mod, FLUID_SYNTH_ADD); delete_fluid_mod(mod); + // soundfont spec says that if cutoff is >20kHz and resonance Q is 0, then no filtering occurs mod = new_fluid_mod(); fluid_mod_set_source1(mod, static_cast(SOUND_CTRL5), // MIDI CC 74 Brightness (cutoff frequency, FILTERFC) @@ -134,6 +153,21 @@ void FluidSynthModel::initialise() { fluid_mod_set_amount(mod, env_amount); fluid_synth_add_default_mod(synth, mod, FLUID_SYNTH_ADD); delete_fluid_mod(mod); + + mod = new_fluid_mod(); + fluid_mod_set_source1(mod, + static_cast(SOUND_CTRL10), // MIDI CC 79 undefined + FLUID_MOD_CC + | FLUID_MOD_UNIPOLAR + | FLUID_MOD_LINEAR + | FLUID_MOD_POSITIVE); + fluid_mod_set_source2(mod, 0, 0); + fluid_mod_set_dest(mod, GEN_VOLENVSUSTAIN); + // fluice_voice.c#fluid_voice_update_param() + // clamps the range to between 0 and 1000, so we'll copy that + fluid_mod_set_amount(mod, 1000.0f); + fluid_synth_add_default_mod(synth, mod, FLUID_SYNTH_ADD); + delete_fluid_mod(mod); initialised = true; } diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index d3c12b6..4777597 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -211,6 +211,14 @@ void JuicySFAudioProcessor::processBlock (AudioBuffer& buffer, MidiBuffer delete_fluid_midi_event(midi_event); } } + +// int pval; + // 73: 64 attack + // 75: decay + // 79: sustain + // 72: 64 release +// fluid_synth_get_cc(fluidSynth, 0, 73, &pval); +// Logger::outputDebugString ( juce::String::formatted("hey: %d\n", pval) ); // and now get our synth to process these midi events and generate its output. synth.renderNextBlock (buffer, midiMessages, 0, numSamples); diff --git a/Source/SoundfontSynthVoice.cpp b/Source/SoundfontSynthVoice.cpp index 30b6afa..221fa70 100644 --- a/Source/SoundfontSynthVoice.cpp +++ b/Source/SoundfontSynthVoice.cpp @@ -24,6 +24,7 @@ void SoundfontSynthVoice::startNote( SynthesiserSound* sound, int /*currentPitchWheelPosition*/) { this->midiNoteNumber = midiNoteNumber; + Logger::outputDebugString ( juce::String::formatted("JUCE noteon: %d, %d\n", midiNoteNumber, velocity) ); fluid_synth_noteon(synth, 0, midiNoteNumber, static_cast(velocity * 127)); // currentAngle = 0.0; @@ -55,6 +56,7 @@ void SoundfontSynthVoice::stopNote (float /*velocity*/, bool allowTailOff) { // clearCurrentNote(); // angleDelta = 0.0; // } + Logger::outputDebugString ( juce::String("JUCE noteoff\n") ); clearCurrentNote(); fluid_synth_noteoff(synth, 0, this->midiNoteNumber); }