diff --git a/Builds/MacOSX/juicysfplugin.xcodeproj/project.pbxproj b/Builds/MacOSX/juicysfplugin.xcodeproj/project.pbxproj index 1d0e430..5c4d178 100644 --- a/Builds/MacOSX/juicysfplugin.xcodeproj/project.pbxproj +++ b/Builds/MacOSX/juicysfplugin.xcodeproj/project.pbxproj @@ -235,7 +235,9 @@ 560D40E30164CA9D05C6AC3B /* MyColours.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MyColours.h; path = ../../Source/MyColours.h; sourceTree = SOURCE_ROOT; }; 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 = ""; }; 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; }; 5BC90F629770BCF4193FABDD /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 63942F8053F1E4E72C1BE98C /* FilePicker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = FilePicker.cpp; path = ../../Source/FilePicker.cpp; sourceTree = SOURCE_ROOT; }; @@ -557,6 +559,8 @@ B3E8D1BE528BBA1B6004672E /* PluginEditor.h */, 596723D094319DA06FDDCDC6 /* StateChangeSubscriber.h */, 59672C6315E5D06A21B4A2F2 /* SharesParams.h */, + 596725F7ACCE2D50FCEC1981 /* ExposesComponents.h */, + 59672DE3D2595F1C3D7189CB /* FilePickerFragment.h */, ); name = Source; sourceTree = ""; diff --git a/Source/ExposesComponents.h b/Source/ExposesComponents.h new file mode 100644 index 0000000..2cc0112 --- /dev/null +++ b/Source/ExposesComponents.h @@ -0,0 +1,16 @@ +// +// Created by Alex Birch on 11/04/2018. +// Copyright (c) 2018 Birchlabs. All rights reserved. +// + +#pragma once + +#import "FilePickerFragment.h" + +class ExposesComponents { +public: + virtual ~ExposesComponents() {} + + virtual FilePickerFragment& getFilePicker() = 0; + +}; \ No newline at end of file diff --git a/Source/FilePicker.cpp b/Source/FilePicker.cpp index 6203630..d2cada4 100644 --- a/Source/FilePicker.cpp +++ b/Source/FilePicker.cpp @@ -18,14 +18,12 @@ FilePicker::FilePicker( String(), "Choose a Soundfont file to load into the synthesizer" ), - fluidSynthModel(fluidSynthModel) { + fluidSynthModel(fluidSynthModel), + currentPath() { // faster (rounded edges introduce transparency) setOpaque (true); - const String& currentSoundFontAbsPath = fluidSynthModel->getCurrentSoundFontAbsPath(); - if (currentSoundFontAbsPath.isNotEmpty()) { - fileChooser.setCurrentFile(File(currentSoundFontAbsPath), true, dontSendNotification); - } + setDisplayedFilePath(fluidSynthModel->getCurrentSoundFontAbsPath()); addAndMakeVisible (fileChooser); fileChooser.addListener (this); @@ -48,5 +46,24 @@ void FilePicker::paint(Graphics& g) } void FilePicker::filenameComponentChanged (FilenameComponent*) { + currentPath = fileChooser.getCurrentFile().getFullPathName(); fluidSynthModel->onFileNameChanged(fileChooser.getCurrentFile().getFullPathName()); +} + +void FilePicker::setDisplayedFilePath(const String& path) { + if (!shouldChangeDisplayedFilePath(path)) { + return; + } + currentPath = path; + fileChooser.setCurrentFile(File(path), true, dontSendNotification); +} + +bool FilePicker::shouldChangeDisplayedFilePath(const String &path) { + if (path.isEmpty()) { + return false; + } + if (path == currentPath) { + return false; + } + return true; } \ No newline at end of file diff --git a/Source/FilePicker.h b/Source/FilePicker.h index 6090a7f..2f8ccce 100644 --- a/Source/FilePicker.h +++ b/Source/FilePicker.h @@ -6,8 +6,10 @@ #include "../JuceLibraryCode/JuceHeader.h" #include "FluidSynthModel.h" +#import "FilePickerFragment.h" class FilePicker: public Component, + public FilePickerFragment, private FilenameComponentListener { public: @@ -18,12 +20,18 @@ public: void resized() override; void paint (Graphics& g) override; + + virtual void setDisplayedFilePath(const String&) override; private: FilenameComponent fileChooser; FluidSynthModel* fluidSynthModel; + String currentPath; + void filenameComponentChanged (FilenameComponent*) override; + bool shouldChangeDisplayedFilePath(const String &path); + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FilePicker) }; \ No newline at end of file diff --git a/Source/FilePickerFragment.h b/Source/FilePickerFragment.h new file mode 100644 index 0000000..96968db --- /dev/null +++ b/Source/FilePickerFragment.h @@ -0,0 +1,14 @@ +// +// Created by Alex Birch on 11/04/2018. +// Copyright (c) 2018 Birchlabs. All rights reserved. +// + +#pragma once +#include "../JuceLibraryCode/JuceHeader.h" + +class FilePickerFragment { +public: + virtual ~FilePickerFragment() {} + + virtual void setDisplayedFilePath(const String&) = 0; +}; \ No newline at end of file diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 670b4f5..7136e11 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -135,6 +135,6 @@ bool JuicySFAudioProcessorEditor::keyStateChanged (bool isKeyDown) { // return false; } -const FilePicker& JuicySFAudioProcessorEditor::getFilePicker() { - +FilePickerFragment& JuicySFAudioProcessorEditor::getFilePicker() { + return filePicker; } \ No newline at end of file diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index d580d89..217516b 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -14,13 +14,16 @@ #include "PluginProcessor.h" #include "TablesComponent.h" #include "SurjectiveMidiKeyboardComponent.h" +#include "FilePickerFragment.h" +#include "ExposesComponents.h" #include "FilePicker.h" #include "StateChangeSubscriber.h" //============================================================================== /** */ -class JuicySFAudioProcessorEditor : public AudioProcessorEditor/*, +class JuicySFAudioProcessorEditor : public AudioProcessorEditor, + public ExposesComponents/*, public StateChangeSubscriber*/ { public: @@ -37,7 +40,7 @@ public: // void getStateInformation (XmlElement& xml) override; // void setStateInformation (XmlElement* xmlState) override; - const FilePicker& getFilePicker(); + virtual FilePickerFragment& getFilePicker() override; private: // This reference is provided as a quick way for your editor to diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 0c7bf67..319b2a9 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -12,6 +12,7 @@ #include "PluginEditor.h" #include "SoundfontSynthVoice.h" #include "SoundfontSynthSound.h" +#include "ExposesComponents.h" AudioProcessor* JUCE_CALLTYPE createPluginFilter(); @@ -241,6 +242,10 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt AudioProcessorEditor* editor = getActiveEditor(); if (editor != nullptr) { editor->setSize(lastUIWidth, lastUIHeight); + + jassert(dynamic_cast (editor) != nullptr); + ExposesComponents* exposesComponents = dynamic_cast (editor); + exposesComponents->getFilePicker().setDisplayedFilePath(soundFontPath); } // const String& currentSoundFontAbsPath = fluidSynthModel->getCurrentSoundFontAbsPath();