diff --git a/Builds/MacOSX/juicysfplugin.xcodeproj/project.pbxproj b/Builds/MacOSX/juicysfplugin.xcodeproj/project.pbxproj index 5c4d178..709f0fd 100644 --- a/Builds/MacOSX/juicysfplugin.xcodeproj/project.pbxproj +++ b/Builds/MacOSX/juicysfplugin.xcodeproj/project.pbxproj @@ -103,6 +103,7 @@ 4CA8C1CEB3C6978A36AF7B42 /* include_juce_graphics.mm in Sources */ = {isa = PBXBuildFile; fileRef = 75A66C3558F366D3A8477EFE /* include_juce_graphics.mm */; }; 4E15A26240490B6186AF5814 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4FD107636B29A49B998F03CA /* WebKit.framework */; }; 581AADF14FC0294CD5AE416C /* PluginProcessor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E15CB0CA601DF22E4DA35DCF /* PluginProcessor.cpp */; }; + 59672745E274A96D640F0FE2 /* BankAndPreset.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 596728C4D55574331BE8B673 /* BankAndPreset.cpp */; }; 5A2C2B811EF05303FEE1BDFA /* include_juce_audio_devices.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDEEF07090FA0F9AC13D71D4 /* include_juce_audio_devices.mm */; }; 5B904523A612134477A304D3 /* include_juce_audio_utils.mm in Sources */ = {isa = PBXBuildFile; fileRef = 94643E589DC134352A87E8C0 /* include_juce_audio_utils.mm */; }; 5BAAD34574683785C1346B4A /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 937D42F23D12C8F6AE8B7A74 /* CoreMedia.framework */; }; @@ -236,6 +237,8 @@ 571BC08FE42BABE3BAF364C8 /* Info-AUv3_AppExtension.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-AUv3_AppExtension.plist"; sourceTree = SOURCE_ROOT; }; 596723D094319DA06FDDCDC6 /* StateChangeSubscriber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StateChangeSubscriber.h; path = ../../Source/StateChangeSubscriber.h; sourceTree = ""; }; 596725F7ACCE2D50FCEC1981 /* ExposesComponents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExposesComponents.h; path = ../../Source/ExposesComponents.h; sourceTree = ""; }; + 5967269C82E97394125999EA /* BankAndPreset.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BankAndPreset.h; path = ../../Source/BankAndPreset.h; sourceTree = ""; }; + 596728C4D55574331BE8B673 /* BankAndPreset.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BankAndPreset.cpp; path = ../../Source/BankAndPreset.cpp; sourceTree = ""; }; 59672C6315E5D06A21B4A2F2 /* SharesParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SharesParams.h; path = ../../Source/SharesParams.h; sourceTree = ""; }; 59672DE3D2595F1C3D7189CB /* FilePickerFragment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FilePickerFragment.h; path = ../../Source/FilePickerFragment.h; sourceTree = ""; }; 5B3CBC48DAB08EDF53CEE609 /* include_juce_audio_plugin_client_VST3.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = include_juce_audio_plugin_client_VST3.cpp; path = ../../JuceLibraryCode/include_juce_audio_plugin_client_VST3.cpp; sourceTree = SOURCE_ROOT; }; @@ -561,6 +564,8 @@ 59672C6315E5D06A21B4A2F2 /* SharesParams.h */, 596725F7ACCE2D50FCEC1981 /* ExposesComponents.h */, 59672DE3D2595F1C3D7189CB /* FilePickerFragment.h */, + 596728C4D55574331BE8B673 /* BankAndPreset.cpp */, + 5967269C82E97394125999EA /* BankAndPreset.h */, ); name = Source; sourceTree = ""; @@ -951,6 +956,7 @@ 6353630F2BB68A8804506084 /* include_juce_gui_extra.mm in Sources */, 906232DF8DDD023678AB78A3 /* include_juce_opengl.mm in Sources */, B2B7F4D38157F527D17E0B44 /* include_juce_video.mm in Sources */, + 59672745E274A96D640F0FE2 /* BankAndPreset.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Source/BankAndPreset.cpp b/Source/BankAndPreset.cpp new file mode 100644 index 0000000..ebda5c4 --- /dev/null +++ b/Source/BankAndPreset.cpp @@ -0,0 +1,19 @@ +// +// Created by Alex Birch on 13/04/2018. +// Copyright (c) 2018 Birchlabs. All rights reserved. +// + +#include "BankAndPreset.h" + +BankAndPreset::BankAndPreset(int bank, int preset) + : bank(bank), + preset(preset) +{} + +int BankAndPreset::getBank() { + return bank; +} + +int BankAndPreset::getPreset() { + return preset; +} \ No newline at end of file diff --git a/Source/BankAndPreset.h b/Source/BankAndPreset.h new file mode 100644 index 0000000..2898403 --- /dev/null +++ b/Source/BankAndPreset.h @@ -0,0 +1,23 @@ +// +// Created by Alex Birch on 13/04/2018. +// Copyright (c) 2018 Birchlabs. All rights reserved. +// + +#pragma once + +#include "../JuceLibraryCode/JuceHeader.h" + +class BankAndPreset { +public: + BankAndPreset(int bank, int preset); + + int getBank(); + int getPreset(); + +private: + int bank; + int preset; + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BankAndPreset) +}; + diff --git a/Source/FilePicker.cpp b/Source/FilePicker.cpp index d2cada4..38517c0 100644 --- a/Source/FilePicker.cpp +++ b/Source/FilePicker.cpp @@ -47,7 +47,7 @@ void FilePicker::paint(Graphics& g) void FilePicker::filenameComponentChanged (FilenameComponent*) { currentPath = fileChooser.getCurrentFile().getFullPathName(); - fluidSynthModel->onFileNameChanged(fileChooser.getCurrentFile().getFullPathName()); + fluidSynthModel->onFileNameChanged(fileChooser.getCurrentFile().getFullPathName(), -1, -1); } void FilePicker::setDisplayedFilePath(const String& path) { diff --git a/Source/FluidSynthModel.cpp b/Source/FluidSynthModel.cpp index 2d39ece..631eedd 100644 --- a/Source/FluidSynthModel.cpp +++ b/Source/FluidSynthModel.cpp @@ -41,11 +41,7 @@ void FluidSynthModel::initialise() { if (sharesParams.getSoundFontPath().isNotEmpty()) { loadFont(sharesParams.getSoundFontPath()); - if (sharesParams.getPreset() == -1 || sharesParams.getBank() == -1) { - changePreset(sharesParams.getBank(), sharesParams.getPreset()); - } else { - selectFirstPreset(); - } + changePreset(sharesParams.getBank(), sharesParams.getPreset()); } fluid_synth_set_gain(synth, 2.0); @@ -67,7 +63,9 @@ int FluidSynthModel::getChannel() { void FluidSynthModel::changePreset(int bank, int preset) { if (bank == -1 || preset == -1) { - return; + unique_ptr bankAndPreset = getFirstBankAndPreset(); + bank = bankAndPreset->getBank(); + preset = bankAndPreset->getPreset(); } changePresetImpl(bank, preset); sharesParams.setPreset(preset); @@ -91,6 +89,14 @@ const fluid_preset_t FluidSynthModel::getFirstPreset() { return preset; } +unique_ptr FluidSynthModel::getFirstBankAndPreset() { + fluid_preset_t preset = getFirstPreset(); + + int offset = fluid_synth_get_bank_offset(synth, sfont_id); + + return make_unique(preset.get_banknum(&preset) + offset, preset.get_num(&preset)); +}; + void FluidSynthModel::selectFirstPreset() { fluid_preset_t preset = getFirstPreset(); @@ -143,11 +149,12 @@ fluid_synth_t* FluidSynthModel::getSynth() { return synth; } -void FluidSynthModel::onFileNameChanged(const String &absPath) { +void FluidSynthModel::onFileNameChanged(const String &absPath, int bank, int preset) { if (!shouldLoadFont(absPath)) { return; } unloadAndLoadFont(absPath); + changePreset(bank, preset); sharesParams.setSoundFontPath(absPath); eventListeners.call(&FluidSynthModel::Listener::fontChanged, this, absPath); } @@ -158,7 +165,6 @@ void FluidSynthModel::unloadAndLoadFont(const String &absPath) { fluid_synth_sfunload(synth, sfont_id, 1); } loadFont(absPath); - selectFirstPreset(); } void FluidSynthModel::loadFont(const String &absPath) { diff --git a/Source/FluidSynthModel.h b/Source/FluidSynthModel.h index 228007e..62dcdb9 100644 --- a/Source/FluidSynthModel.h +++ b/Source/FluidSynthModel.h @@ -8,11 +8,14 @@ #include "SharesParams.h" #include #include +#include "BankAndPreset.h" #include "PresetsToBanks.h" // https://stackoverflow.com/a/13446565/5257399 -using std::shared_ptr; +//using std::shared_ptr; + +using namespace std; class FluidSynthModel { public: @@ -27,7 +30,7 @@ public: void changePreset(int bank, int preset); int getChannel(); - void onFileNameChanged(const String &absPath); + void onFileNameChanged(const String &absPath, int bank, int preset); //============================================================================== /** @@ -69,6 +72,7 @@ private: const fluid_preset_t getFirstPreset(); void selectFirstPreset(); + unique_ptr getFirstBankAndPreset(); void unloadAndLoadFont(const String &absPath); void loadFont(const String &absPath); diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 25cee40..defb590 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -243,8 +243,7 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt if (auto* p = dynamic_cast (param)) p->setValue ((float) xmlState->getDoubleAttribute (p->paramID, p->getValue())); - fluidSynthModel.onFileNameChanged(soundFontPath); - fluidSynthModel.changePreset(lastBank, lastPreset); + fluidSynthModel.onFileNameChanged(soundFontPath, lastBank, lastPreset); AudioProcessorEditor* editor = getActiveEditor(); if (editor != nullptr) {