set displayed filepath when loading in state
This commit is contained in:
16
Source/ExposesComponents.h
Normal file
16
Source/ExposesComponents.h
Normal 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;
|
||||
|
||||
};
|
@ -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;
|
||||
}
|
@ -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)
|
||||
};
|
14
Source/FilePickerFragment.h
Normal file
14
Source/FilePickerFragment.h
Normal 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;
|
||||
};
|
@ -135,6 +135,6 @@ bool JuicySFAudioProcessorEditor::keyStateChanged (bool isKeyDown) {
|
||||
// return false;
|
||||
}
|
||||
|
||||
const FilePicker& JuicySFAudioProcessorEditor::getFilePicker() {
|
||||
|
||||
FilePickerFragment& JuicySFAudioProcessorEditor::getFilePicker() {
|
||||
return filePicker;
|
||||
}
|
@ -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
|
||||
|
@ -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<ExposesComponents*> (editor) != nullptr);
|
||||
ExposesComponents* exposesComponents = dynamic_cast<ExposesComponents*> (editor);
|
||||
exposesComponents->getFilePicker().setDisplayedFilePath(soundFontPath);
|
||||
}
|
||||
|
||||
// const String& currentSoundFontAbsPath = fluidSynthModel->getCurrentSoundFontAbsPath();
|
||||
|
Reference in New Issue
Block a user