set displayed filepath when loading in state

This commit is contained in:
Alex Birch 2018-04-11 00:52:44 +01:00
parent 114bb2f10a
commit e8177d51cd
No known key found for this signature in database
GPG Key ID: 305EB1F98D44ACBA
8 changed files with 76 additions and 9 deletions

View File

@ -235,7 +235,9 @@
560D40E30164CA9D05C6AC3B /* MyColours.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MyColours.h; path = ../../Source/MyColours.h; sourceTree = SOURCE_ROOT; }; 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; }; 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 = "<group>"; }; 596723D094319DA06FDDCDC6 /* StateChangeSubscriber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StateChangeSubscriber.h; path = ../../Source/StateChangeSubscriber.h; sourceTree = "<group>"; };
596725F7ACCE2D50FCEC1981 /* ExposesComponents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExposesComponents.h; path = ../../Source/ExposesComponents.h; sourceTree = "<group>"; };
59672C6315E5D06A21B4A2F2 /* SharesParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SharesParams.h; path = ../../Source/SharesParams.h; sourceTree = "<group>"; }; 59672C6315E5D06A21B4A2F2 /* SharesParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SharesParams.h; path = ../../Source/SharesParams.h; sourceTree = "<group>"; };
59672DE3D2595F1C3D7189CB /* FilePickerFragment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FilePickerFragment.h; path = ../../Source/FilePickerFragment.h; sourceTree = "<group>"; };
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; }; 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; }; 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; }; 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 */, B3E8D1BE528BBA1B6004672E /* PluginEditor.h */,
596723D094319DA06FDDCDC6 /* StateChangeSubscriber.h */, 596723D094319DA06FDDCDC6 /* StateChangeSubscriber.h */,
59672C6315E5D06A21B4A2F2 /* SharesParams.h */, 59672C6315E5D06A21B4A2F2 /* SharesParams.h */,
596725F7ACCE2D50FCEC1981 /* ExposesComponents.h */,
59672DE3D2595F1C3D7189CB /* FilePickerFragment.h */,
); );
name = Source; name = Source;
sourceTree = "<group>"; sourceTree = "<group>";

View File

@ -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;
};

View File

@ -18,14 +18,12 @@ FilePicker::FilePicker(
String(), String(),
"Choose a Soundfont file to load into the synthesizer" "Choose a Soundfont file to load into the synthesizer"
), ),
fluidSynthModel(fluidSynthModel) { fluidSynthModel(fluidSynthModel),
currentPath() {
// faster (rounded edges introduce transparency) // faster (rounded edges introduce transparency)
setOpaque (true); setOpaque (true);
const String& currentSoundFontAbsPath = fluidSynthModel->getCurrentSoundFontAbsPath(); setDisplayedFilePath(fluidSynthModel->getCurrentSoundFontAbsPath());
if (currentSoundFontAbsPath.isNotEmpty()) {
fileChooser.setCurrentFile(File(currentSoundFontAbsPath), true, dontSendNotification);
}
addAndMakeVisible (fileChooser); addAndMakeVisible (fileChooser);
fileChooser.addListener (this); fileChooser.addListener (this);
@ -48,5 +46,24 @@ void FilePicker::paint(Graphics& g)
} }
void FilePicker::filenameComponentChanged (FilenameComponent*) { void FilePicker::filenameComponentChanged (FilenameComponent*) {
currentPath = fileChooser.getCurrentFile().getFullPathName();
fluidSynthModel->onFileNameChanged(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;
} }

View File

@ -6,8 +6,10 @@
#include "../JuceLibraryCode/JuceHeader.h" #include "../JuceLibraryCode/JuceHeader.h"
#include "FluidSynthModel.h" #include "FluidSynthModel.h"
#import "FilePickerFragment.h"
class FilePicker: public Component, class FilePicker: public Component,
public FilePickerFragment,
private FilenameComponentListener private FilenameComponentListener
{ {
public: public:
@ -18,12 +20,18 @@ public:
void resized() override; void resized() override;
void paint (Graphics& g) override; void paint (Graphics& g) override;
virtual void setDisplayedFilePath(const String&) override;
private: private:
FilenameComponent fileChooser; FilenameComponent fileChooser;
FluidSynthModel* fluidSynthModel; FluidSynthModel* fluidSynthModel;
String currentPath;
void filenameComponentChanged (FilenameComponent*) override; void filenameComponentChanged (FilenameComponent*) override;
bool shouldChangeDisplayedFilePath(const String &path);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FilePicker) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FilePicker)
}; };

View File

@ -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;
};

View File

@ -135,6 +135,6 @@ bool JuicySFAudioProcessorEditor::keyStateChanged (bool isKeyDown) {
// return false; // return false;
} }
const FilePicker& JuicySFAudioProcessorEditor::getFilePicker() { FilePickerFragment& JuicySFAudioProcessorEditor::getFilePicker() {
return filePicker;
} }

View File

@ -14,13 +14,16 @@
#include "PluginProcessor.h" #include "PluginProcessor.h"
#include "TablesComponent.h" #include "TablesComponent.h"
#include "SurjectiveMidiKeyboardComponent.h" #include "SurjectiveMidiKeyboardComponent.h"
#include "FilePickerFragment.h"
#include "ExposesComponents.h"
#include "FilePicker.h" #include "FilePicker.h"
#include "StateChangeSubscriber.h" #include "StateChangeSubscriber.h"
//============================================================================== //==============================================================================
/** /**
*/ */
class JuicySFAudioProcessorEditor : public AudioProcessorEditor/*, class JuicySFAudioProcessorEditor : public AudioProcessorEditor,
public ExposesComponents/*,
public StateChangeSubscriber*/ public StateChangeSubscriber*/
{ {
public: public:
@ -37,7 +40,7 @@ public:
// void getStateInformation (XmlElement& xml) override; // void getStateInformation (XmlElement& xml) override;
// void setStateInformation (XmlElement* xmlState) override; // void setStateInformation (XmlElement* xmlState) override;
const FilePicker& getFilePicker(); virtual FilePickerFragment& getFilePicker() override;
private: private:
// This reference is provided as a quick way for your editor to // This reference is provided as a quick way for your editor to

View File

@ -12,6 +12,7 @@
#include "PluginEditor.h" #include "PluginEditor.h"
#include "SoundfontSynthVoice.h" #include "SoundfontSynthVoice.h"
#include "SoundfontSynthSound.h" #include "SoundfontSynthSound.h"
#include "ExposesComponents.h"
AudioProcessor* JUCE_CALLTYPE createPluginFilter(); AudioProcessor* JUCE_CALLTYPE createPluginFilter();
@ -241,6 +242,10 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt
AudioProcessorEditor* editor = getActiveEditor(); AudioProcessorEditor* editor = getActiveEditor();
if (editor != nullptr) { if (editor != nullptr) {
editor->setSize(lastUIWidth, lastUIHeight); editor->setSize(lastUIWidth, lastUIHeight);
jassert(dynamic_cast<ExposesComponents*> (editor) != nullptr);
ExposesComponents* exposesComponents = dynamic_cast<ExposesComponents*> (editor);
exposesComponents->getFilePicker().setDisplayedFilePath(soundFontPath);
} }
// const String& currentSoundFontAbsPath = fluidSynthModel->getCurrentSoundFontAbsPath(); // const String& currentSoundFontAbsPath = fluidSynthModel->getCurrentSoundFontAbsPath();