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:
Alex Birch
2018-03-18 23:35:29 +00:00
parent 8459c48c63
commit 89b12b132a
6 changed files with 66 additions and 36 deletions

View File

@ -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) {
@ -119,4 +130,4 @@ bool JuicySFAudioProcessorEditor::keyStateChanged (bool isKeyDown) {
// if (childComponent->keyStateChanged(isKeyDown)) return true;
// }
// return false;
}
}

View File

@ -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.

View File

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

View File

@ -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;
//==============================================================================

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