From e1f8eb92681598e3574926100299d1db5e2d416c Mon Sep 17 00:00:00 2001 From: Alex Birch Date: Mon, 1 Jul 2019 21:15:33 +0100 Subject: [PATCH] fix pitch wheel. make logging debug-only. --- .../juicysfplugin.xcodeproj/project.pbxproj | 2 ++ Source/FluidSynthModel.cpp | 2 ++ Source/PluginProcessor.cpp | 20 +++++++++++++------ Source/SoundfontSynthVoice.cpp | 15 +++++++++----- Source/Util.h | 11 ++++++++++ 5 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 Source/Util.h diff --git a/Builds/MacOSX/juicysfplugin.xcodeproj/project.pbxproj b/Builds/MacOSX/juicysfplugin.xcodeproj/project.pbxproj index bc59573..02c0a02 100644 --- a/Builds/MacOSX/juicysfplugin.xcodeproj/project.pbxproj +++ b/Builds/MacOSX/juicysfplugin.xcodeproj/project.pbxproj @@ -284,6 +284,7 @@ 2C62C3F0621604CDB65B55A6 /* Pills.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = Pills.cpp; path = ../../Source/Pills.cpp; sourceTree = SOURCE_ROOT; }; 2C66D01D1DD9006E77E2E260 /* include_juce_data_structures.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = include_juce_data_structures.mm; path = ../../JuceLibraryCode/include_juce_data_structures.mm; sourceTree = SOURCE_ROOT; }; 307CB49DF900DE4A612FF98E /* FluidSynthModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FluidSynthModel.h; path = ../../Source/FluidSynthModel.h; sourceTree = SOURCE_ROOT; }; + 35099D9022CA8EF500CD4523 /* Util.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Util.h; path = ../../Source/Util.h; sourceTree = ""; }; 35880F58CB540AD30D1B0ED3 /* TablesComponent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = TablesComponent.h; path = ../../Source/TablesComponent.h; sourceTree = SOURCE_ROOT; }; 358E45B422BEE53A0087ED8D /* libpcre.1.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libpcre.1.dylib; sourceTree = ""; }; 358E45B522BEE53A0087ED8D /* libvorbisenc.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libvorbisenc.2.dylib; sourceTree = ""; }; @@ -552,6 +553,7 @@ 358E45F422BFC00C0087ED8D /* MidiConstants.h */, 358E45F922C80DCA0087ED8D /* SlidersComponent.cpp */, 358E45FA22C80DCA0087ED8D /* SlidersComponent.h */, + 35099D9022CA8EF500CD4523 /* Util.h */, ); name = Source; sourceTree = ""; diff --git a/Source/FluidSynthModel.cpp b/Source/FluidSynthModel.cpp index 7d3b309..40bddf3 100644 --- a/Source/FluidSynthModel.cpp +++ b/Source/FluidSynthModel.cpp @@ -44,7 +44,9 @@ void FluidSynthModel::initialise() { settings = new_fluid_settings(); // https://sourceforge.net/p/fluidsynth/wiki/FluidSettings/ +#if JUCE_DEBUG fluid_settings_setint(settings, "synth.verbose", 1); +#endif synth = new_fluid_synth(settings); fluid_synth_set_sample_rate(synth, currentSampleRate); diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 4777597..61f1736 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -14,6 +14,7 @@ #include "SoundfontSynthSound.h" #include "ExposesComponents.h" #include "MidiConstants.h" +#include "Util.h" AudioProcessor* JUCE_CALLTYPE createPluginFilter(); @@ -161,7 +162,7 @@ void JuicySFAudioProcessor::processBlock (AudioBuffer& buffer, MidiBuffer // TODO: factor into a MidiCollector for (MidiBuffer::Iterator i (midiMessages); i.getNextEvent (m, time);) { - Logger::outputDebugString ( m.getDescription() ); + DEBUG_PRINT ( m.getDescription() ); // explicitly not handling note_on/off, or pitch_bend, because these are (for better or worse) // responsibilities of SoundfontSynthVoice. @@ -181,6 +182,13 @@ void JuicySFAudioProcessor::processBlock (AudioBuffer& buffer, MidiBuffer 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.isPitchWheel()) { + fluid_midi_event_t *midi_event(new_fluid_midi_event()); + fluid_midi_event_set_type(midi_event, static_cast(PITCH_BEND)); + fluid_midi_event_set_channel(midi_event, fluidSynthModel.getChannel()); + fluid_midi_event_set_pitch(midi_event, m.getPitchWheelValue()); + 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)); @@ -196,11 +204,11 @@ void JuicySFAudioProcessor::processBlock (AudioBuffer& buffer, MidiBuffer fluid_midi_event_set_value(midi_event, m.getAfterTouchValue()); fluid_synth_handle_midi_event(fluidSynth, midi_event); delete_fluid_midi_event(midi_event); - } else if (m.isMetaEvent()) { - 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.isMetaEvent()) { +// 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)); diff --git a/Source/SoundfontSynthVoice.cpp b/Source/SoundfontSynthVoice.cpp index 221fa70..652b995 100644 --- a/Source/SoundfontSynthVoice.cpp +++ b/Source/SoundfontSynthVoice.cpp @@ -4,6 +4,7 @@ #include "SoundfontSynthVoice.h" #include "SoundfontSynthSound.h" +#include "Util.h" SoundfontSynthVoice::SoundfontSynthVoice(fluid_synth_t* synth) : tailOff (0.0), @@ -24,7 +25,7 @@ void SoundfontSynthVoice::startNote( SynthesiserSound* sound, int /*currentPitchWheelPosition*/) { this->midiNoteNumber = midiNoteNumber; - Logger::outputDebugString ( juce::String::formatted("JUCE noteon: %d, %d\n", midiNoteNumber, velocity) ); + DEBUG_PRINT ( juce::String::formatted("JUCE noteon: %d, %d\n", midiNoteNumber, velocity) ); fluid_synth_noteon(synth, 0, midiNoteNumber, static_cast(velocity * 127)); // currentAngle = 0.0; @@ -56,7 +57,7 @@ void SoundfontSynthVoice::stopNote (float /*velocity*/, bool allowTailOff) { // clearCurrentNote(); // angleDelta = 0.0; // } - Logger::outputDebugString ( juce::String("JUCE noteoff\n") ); + DEBUG_PRINT ( juce::String("JUCE noteoff\n") ); clearCurrentNote(); fluid_synth_noteoff(synth, 0, this->midiNoteNumber); } @@ -64,13 +65,17 @@ void SoundfontSynthVoice::stopNote (float /*velocity*/, bool allowTailOff) { // 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); +// fluid_synth_pitch_bend(synth, 0, newValue); +// int ppitch_bend; +// fluid_synth_get_pitch_bend(synth, 0, &ppitch_bend); +// int ppitch_bend_sens; +// fluid_synth_get_pitch_wheel_sens(synth, 0, &ppitch_bend_sens); +// Logger::outputDebugString ( juce::String::formatted("Pitch wheel: %d %d %d\n", newValue, ppitch_bend, ppitch_bend_sens) ); } void SoundfontSynthVoice::controllerMoved (int controllerNumber, int newValue) { // this seems to be "program change" event - Logger::outputDebugString ( juce::String::formatted("Controller moved: %d, %d\n", controllerNumber, newValue) ); + DEBUG_PRINT ( juce::String::formatted("Controller moved: %d, %d\n", controllerNumber, newValue) ); } void SoundfontSynthVoice::renderNextBlock (AudioBuffer& outputBuffer, int startSample, int numSamples) { diff --git a/Source/Util.h b/Source/Util.h new file mode 100644 index 0000000..c186f83 --- /dev/null +++ b/Source/Util.h @@ -0,0 +1,11 @@ +#pragma once + +#include "../JuceLibraryCode/JuceHeader.h" + +#ifndef DEBUG_PRINT + #if JUCE_DEBUG + #define DEBUG_PRINT(str) Logger::outputDebugString(str) + #else + #define DEBUG_PRINT(str) + #endif +#endif