make a pattern for notifying subscribers about VST state save/load. but it seems to run too early for Editor to benefit.
This commit is contained in:
parent
8459c48c63
commit
89b12b132a
|
@ -234,6 +234,7 @@
|
|||
526AF36E1188174AB300DA7B /* Pills.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Pills.h; path = ../../Source/Pills.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; };
|
||||
596723D094319DA06FDDCDC6 /* StateChangeSubscriber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StateChangeSubscriber.h; path = ../../Source/StateChangeSubscriber.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; };
|
||||
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; };
|
||||
|
@ -553,6 +554,7 @@
|
|||
4C295CB748DFF39857513207 /* PluginProcessor.h */,
|
||||
457D4946B07CC4A74EB0FAE1 /* PluginEditor.cpp */,
|
||||
B3E8D1BE528BBA1B6004672E /* PluginEditor.h */,
|
||||
596723D094319DA06FDDCDC6 /* StateChangeSubscriber.h */,
|
||||
);
|
||||
name = Source;
|
||||
sourceTree = "<group>";
|
||||
|
|
|
@ -22,8 +22,9 @@ JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor (JuicySFAudioProcessor&
|
|||
// set resize limits for this plug-in
|
||||
setResizeLimits (400, 300, 800, 600);
|
||||
|
||||
setSize (p.getLastUIWidth(),
|
||||
p.getLastUIHeight());
|
||||
setSize (400, 300);
|
||||
|
||||
processor.subscribeToStateChanges(this);
|
||||
|
||||
midiKeyboard.setName ("MIDI Keyboard");
|
||||
|
||||
|
@ -39,6 +40,19 @@ JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor (JuicySFAudioProcessor&
|
|||
|
||||
JuicySFAudioProcessorEditor::~JuicySFAudioProcessorEditor()
|
||||
{
|
||||
processor.unsubscribeFromStateChanges(this);
|
||||
}
|
||||
|
||||
void JuicySFAudioProcessorEditor::getStateInformation (XmlElement& xml) {
|
||||
// save
|
||||
xml.setAttribute ("uiWidth", getWidth());
|
||||
xml.setAttribute ("uiHeight", getHeight());
|
||||
}
|
||||
|
||||
void JuicySFAudioProcessorEditor::setStateInformation (XmlElement* xmlState) {
|
||||
// load
|
||||
setSize (xmlState->getIntAttribute ("uiWidth", getWidth()),
|
||||
xmlState->getIntAttribute ("uiHeight", getHeight()));
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
@ -81,9 +95,6 @@ void JuicySFAudioProcessorEditor::resized()
|
|||
// r3.removeFromTop(filePickerHeight);
|
||||
//
|
||||
// filePicker.setBounds(r3);
|
||||
|
||||
processor.setLastUIWidth(getWidth());
|
||||
processor.setLastUIHeight(getHeight());
|
||||
}
|
||||
|
||||
bool JuicySFAudioProcessorEditor::keyPressed(const KeyPress &key) {
|
||||
|
|
|
@ -15,11 +15,13 @@
|
|||
#include "TablesComponent.h"
|
||||
#include "SurjectiveMidiKeyboardComponent.h"
|
||||
#include "FilePicker.h"
|
||||
#include "StateChangeSubscriber.h"
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
*/
|
||||
class JuicySFAudioProcessorEditor : public AudioProcessorEditor
|
||||
class JuicySFAudioProcessorEditor : public AudioProcessorEditor,
|
||||
public StateChangeSubscriber
|
||||
{
|
||||
public:
|
||||
JuicySFAudioProcessorEditor (JuicySFAudioProcessor&);
|
||||
|
@ -32,6 +34,9 @@ public:
|
|||
bool keyPressed(const KeyPress &key) override;
|
||||
bool keyStateChanged (bool isKeyDown) override;
|
||||
|
||||
void getStateInformation (XmlElement& xml) override;
|
||||
void setStateInformation (XmlElement* xmlState) override;
|
||||
|
||||
private:
|
||||
// This reference is provided as a quick way for your editor to
|
||||
// access the processor object that created it.
|
||||
|
|
|
@ -19,9 +19,9 @@ AudioProcessor* JUCE_CALLTYPE createPluginFilter();
|
|||
//==============================================================================
|
||||
JuicySFAudioProcessor::JuicySFAudioProcessor()
|
||||
: AudioProcessor (getBusesProperties()),
|
||||
fluidSynthModel(),
|
||||
fluidSynthModel()/*,
|
||||
lastUIWidth(400),
|
||||
lastUIHeight(300)
|
||||
lastUIHeight(300)*/
|
||||
{
|
||||
initialiseSynth();
|
||||
}
|
||||
|
@ -187,9 +187,10 @@ void JuicySFAudioProcessor::getStateInformation (MemoryBlock& destData)
|
|||
// Create an outer XML element..
|
||||
XmlElement xml ("MYPLUGINSETTINGS");
|
||||
|
||||
// add some attributes to it..
|
||||
xml.setAttribute ("uiWidth", lastUIWidth);
|
||||
xml.setAttribute ("uiHeight", lastUIHeight);
|
||||
list<StateChangeSubscriber*>::iterator p;
|
||||
for(p = stateChangeSubscribers.begin(); p != stateChangeSubscribers.end(); p++) {
|
||||
(*p)->getStateInformation(xml);
|
||||
}
|
||||
|
||||
// Store the values of all our parameters, using their param ID as the XML attribute
|
||||
for (auto* param : getParameters())
|
||||
|
@ -212,9 +213,10 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt
|
|||
// make sure that it's actually our type of XML object..
|
||||
if (xmlState->hasTagName ("MYPLUGINSETTINGS"))
|
||||
{
|
||||
// ok, now pull out our last window size..
|
||||
lastUIWidth = jmax (xmlState->getIntAttribute ("uiWidth", lastUIWidth), 400);
|
||||
lastUIHeight = jmax (xmlState->getIntAttribute ("uiHeight", lastUIHeight), 300);
|
||||
list<StateChangeSubscriber*>::iterator p;
|
||||
for(p = stateChangeSubscribers.begin(); p != stateChangeSubscribers.end(); p++) {
|
||||
(*p)->setStateInformation(xmlState);
|
||||
}
|
||||
|
||||
// Now reload our parameters..
|
||||
for (auto* param : getParameters())
|
||||
|
@ -224,6 +226,14 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt
|
|||
}
|
||||
}
|
||||
|
||||
void JuicySFAudioProcessor::subscribeToStateChanges(StateChangeSubscriber* subscriber) {
|
||||
stateChangeSubscribers.push_back(subscriber);
|
||||
}
|
||||
|
||||
void JuicySFAudioProcessor::unsubscribeFromStateChanges(StateChangeSubscriber* subscriber) {
|
||||
stateChangeSubscribers.remove(subscriber);
|
||||
}
|
||||
|
||||
// FluidSynth only supports float in its process function, so that's all we can support.
|
||||
bool JuicySFAudioProcessor::supportsDoublePrecisionProcessing() const {
|
||||
return false;
|
||||
|
@ -239,17 +249,3 @@ AudioProcessor* JUCE_CALLTYPE createPluginFilter()
|
|||
{
|
||||
return new JuicySFAudioProcessor();
|
||||
}
|
||||
|
||||
void JuicySFAudioProcessor::setLastUIWidth(int width) {
|
||||
this->lastUIWidth = width;
|
||||
}
|
||||
void JuicySFAudioProcessor::setLastUIHeight(int height) {
|
||||
this->lastUIHeight = height;
|
||||
}
|
||||
|
||||
int JuicySFAudioProcessor::getLastUIWidth() {
|
||||
return lastUIWidth;
|
||||
}
|
||||
int JuicySFAudioProcessor::getLastUIHeight() {
|
||||
return lastUIHeight;
|
||||
}
|
|
@ -12,6 +12,10 @@
|
|||
|
||||
#include "../JuceLibraryCode/JuceHeader.h"
|
||||
#include "FluidSynthModel.h"
|
||||
#include "StateChangeSubscriber.h"
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
|
@ -61,11 +65,8 @@ public:
|
|||
|
||||
MidiKeyboardState keyboardState;
|
||||
|
||||
int getLastUIWidth();
|
||||
int getLastUIHeight();
|
||||
|
||||
void setLastUIWidth(int width);
|
||||
void setLastUIHeight(int height);
|
||||
void subscribeToStateChanges(StateChangeSubscriber* subscriber);
|
||||
void unsubscribeFromStateChanges(StateChangeSubscriber* subscriber);
|
||||
|
||||
private:
|
||||
void initialiseSynth();
|
||||
|
@ -74,9 +75,9 @@ private:
|
|||
fluid_synth_t* fluidSynth;
|
||||
Synthesiser synth;
|
||||
|
||||
static BusesProperties getBusesProperties();
|
||||
list<StateChangeSubscriber*> stateChangeSubscribers;
|
||||
|
||||
int lastUIWidth, lastUIHeight;
|
||||
static BusesProperties getBusesProperties();
|
||||
|
||||
// Model* model;
|
||||
//==============================================================================
|
||||
|
|
15
Source/StateChangeSubscriber.h
Normal file
15
Source/StateChangeSubscriber.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
//
|
||||
// Created by Alex Birch on 18/03/2018.
|
||||
// Copyright (c) 2018 Birchlabs. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../JuceLibraryCode/JuceHeader.h"
|
||||
|
||||
class StateChangeSubscriber {
|
||||
public:
|
||||
virtual ~StateChangeSubscriber() {} // pass pointer ownership to another party without exposing the concrete derived class
|
||||
virtual void getStateInformation (XmlElement& xml) = 0;
|
||||
virtual void setStateInformation (XmlElement* xmlState) = 0;
|
||||
};
|
Loading…
Reference in New Issue
Block a user