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:
		@ -234,6 +234,7 @@
 | 
				
			|||||||
		526AF36E1188174AB300DA7B /* Pills.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Pills.h; path = ../../Source/Pills.h; sourceTree = SOURCE_ROOT; };
 | 
							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; };
 | 
							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>"; };
 | 
				
			||||||
		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; };
 | 
				
			||||||
@ -553,6 +554,7 @@
 | 
				
			|||||||
				4C295CB748DFF39857513207 /* PluginProcessor.h */,
 | 
									4C295CB748DFF39857513207 /* PluginProcessor.h */,
 | 
				
			||||||
				457D4946B07CC4A74EB0FAE1 /* PluginEditor.cpp */,
 | 
									457D4946B07CC4A74EB0FAE1 /* PluginEditor.cpp */,
 | 
				
			||||||
				B3E8D1BE528BBA1B6004672E /* PluginEditor.h */,
 | 
									B3E8D1BE528BBA1B6004672E /* PluginEditor.h */,
 | 
				
			||||||
 | 
									596723D094319DA06FDDCDC6 /* StateChangeSubscriber.h */,
 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
			name = Source;
 | 
								name = Source;
 | 
				
			||||||
			sourceTree = "<group>";
 | 
								sourceTree = "<group>";
 | 
				
			||||||
 | 
				
			|||||||
@ -22,8 +22,9 @@ JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor (JuicySFAudioProcessor&
 | 
				
			|||||||
    // set resize limits for this plug-in
 | 
					    // set resize limits for this plug-in
 | 
				
			||||||
    setResizeLimits (400, 300, 800, 600);
 | 
					    setResizeLimits (400, 300, 800, 600);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    setSize (p.getLastUIWidth(),
 | 
					    setSize (400, 300);
 | 
				
			||||||
            p.getLastUIHeight());
 | 
					
 | 
				
			||||||
 | 
					    processor.subscribeToStateChanges(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    midiKeyboard.setName ("MIDI Keyboard");
 | 
					    midiKeyboard.setName ("MIDI Keyboard");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -39,6 +40,19 @@ JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor (JuicySFAudioProcessor&
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
JuicySFAudioProcessorEditor::~JuicySFAudioProcessorEditor()
 | 
					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);
 | 
					//    r3.removeFromTop(filePickerHeight);
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
//    filePicker.setBounds(r3);
 | 
					//    filePicker.setBounds(r3);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    processor.setLastUIWidth(getWidth());
 | 
					 | 
				
			||||||
    processor.setLastUIHeight(getHeight());
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool JuicySFAudioProcessorEditor::keyPressed(const KeyPress &key) {
 | 
					bool JuicySFAudioProcessorEditor::keyPressed(const KeyPress &key) {
 | 
				
			||||||
 | 
				
			|||||||
@ -15,11 +15,13 @@
 | 
				
			|||||||
#include "TablesComponent.h"
 | 
					#include "TablesComponent.h"
 | 
				
			||||||
#include "SurjectiveMidiKeyboardComponent.h"
 | 
					#include "SurjectiveMidiKeyboardComponent.h"
 | 
				
			||||||
#include "FilePicker.h"
 | 
					#include "FilePicker.h"
 | 
				
			||||||
 | 
					#include "StateChangeSubscriber.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//==============================================================================
 | 
					//==============================================================================
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
class JuicySFAudioProcessorEditor  : public AudioProcessorEditor
 | 
					class JuicySFAudioProcessorEditor  : public AudioProcessorEditor,
 | 
				
			||||||
 | 
					                                     public StateChangeSubscriber
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    JuicySFAudioProcessorEditor (JuicySFAudioProcessor&);
 | 
					    JuicySFAudioProcessorEditor (JuicySFAudioProcessor&);
 | 
				
			||||||
@ -32,6 +34,9 @@ public:
 | 
				
			|||||||
    bool keyPressed(const KeyPress &key) override;
 | 
					    bool keyPressed(const KeyPress &key) override;
 | 
				
			||||||
    bool keyStateChanged (bool isKeyDown) override;
 | 
					    bool keyStateChanged (bool isKeyDown) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void getStateInformation (XmlElement& xml) override;
 | 
				
			||||||
 | 
					    void setStateInformation (XmlElement* xmlState) 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
 | 
				
			||||||
    // access the processor object that created it.
 | 
					    // access the processor object that created it.
 | 
				
			||||||
 | 
				
			|||||||
@ -19,9 +19,9 @@ AudioProcessor* JUCE_CALLTYPE createPluginFilter();
 | 
				
			|||||||
//==============================================================================
 | 
					//==============================================================================
 | 
				
			||||||
JuicySFAudioProcessor::JuicySFAudioProcessor()
 | 
					JuicySFAudioProcessor::JuicySFAudioProcessor()
 | 
				
			||||||
     : AudioProcessor (getBusesProperties()),
 | 
					     : AudioProcessor (getBusesProperties()),
 | 
				
			||||||
       fluidSynthModel(),
 | 
					       fluidSynthModel()/*,
 | 
				
			||||||
       lastUIWidth(400),
 | 
					       lastUIWidth(400),
 | 
				
			||||||
       lastUIHeight(300)
 | 
					       lastUIHeight(300)*/
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    initialiseSynth();
 | 
					    initialiseSynth();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -187,9 +187,10 @@ void JuicySFAudioProcessor::getStateInformation (MemoryBlock& destData)
 | 
				
			|||||||
    // Create an outer XML element..
 | 
					    // Create an outer XML element..
 | 
				
			||||||
    XmlElement xml ("MYPLUGINSETTINGS");
 | 
					    XmlElement xml ("MYPLUGINSETTINGS");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // add some attributes to it..
 | 
					    list<StateChangeSubscriber*>::iterator p;
 | 
				
			||||||
    xml.setAttribute ("uiWidth", lastUIWidth);
 | 
					    for(p = stateChangeSubscribers.begin(); p != stateChangeSubscribers.end(); p++) {
 | 
				
			||||||
    xml.setAttribute ("uiHeight", lastUIHeight);
 | 
					        (*p)->getStateInformation(xml);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Store the values of all our parameters, using their param ID as the XML attribute
 | 
					    // Store the values of all our parameters, using their param ID as the XML attribute
 | 
				
			||||||
    for (auto* param : getParameters())
 | 
					    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..
 | 
					        // make sure that it's actually our type of XML object..
 | 
				
			||||||
        if (xmlState->hasTagName ("MYPLUGINSETTINGS"))
 | 
					        if (xmlState->hasTagName ("MYPLUGINSETTINGS"))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // ok, now pull out our last window size..
 | 
					            list<StateChangeSubscriber*>::iterator p;
 | 
				
			||||||
            lastUIWidth  = jmax (xmlState->getIntAttribute ("uiWidth", lastUIWidth), 400);
 | 
					            for(p = stateChangeSubscribers.begin(); p != stateChangeSubscribers.end(); p++) {
 | 
				
			||||||
            lastUIHeight = jmax (xmlState->getIntAttribute ("uiHeight", lastUIHeight), 300);
 | 
					                (*p)->setStateInformation(xmlState);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Now reload our parameters..
 | 
					            // Now reload our parameters..
 | 
				
			||||||
            for (auto* param : getParameters())
 | 
					            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.
 | 
					// FluidSynth only supports float in its process function, so that's all we can support.
 | 
				
			||||||
bool JuicySFAudioProcessor::supportsDoublePrecisionProcessing() const {
 | 
					bool JuicySFAudioProcessor::supportsDoublePrecisionProcessing() const {
 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
@ -239,17 +249,3 @@ AudioProcessor* JUCE_CALLTYPE createPluginFilter()
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    return new JuicySFAudioProcessor();
 | 
					    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 "../JuceLibraryCode/JuceHeader.h"
 | 
				
			||||||
#include "FluidSynthModel.h"
 | 
					#include "FluidSynthModel.h"
 | 
				
			||||||
 | 
					#include "StateChangeSubscriber.h"
 | 
				
			||||||
 | 
					#include <list>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//==============================================================================
 | 
					//==============================================================================
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -61,11 +65,8 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    MidiKeyboardState keyboardState;
 | 
					    MidiKeyboardState keyboardState;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int getLastUIWidth();
 | 
					    void subscribeToStateChanges(StateChangeSubscriber* subscriber);
 | 
				
			||||||
    int getLastUIHeight();
 | 
					    void unsubscribeFromStateChanges(StateChangeSubscriber* subscriber);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    void setLastUIWidth(int width);
 | 
					 | 
				
			||||||
    void setLastUIHeight(int height);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void initialiseSynth();
 | 
					    void initialiseSynth();
 | 
				
			||||||
@ -74,9 +75,9 @@ private:
 | 
				
			|||||||
    fluid_synth_t* fluidSynth;
 | 
					    fluid_synth_t* fluidSynth;
 | 
				
			||||||
    Synthesiser synth;
 | 
					    Synthesiser synth;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static BusesProperties getBusesProperties();
 | 
					    list<StateChangeSubscriber*> stateChangeSubscribers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int lastUIWidth, lastUIHeight;
 | 
					    static BusesProperties getBusesProperties();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//    Model* model;
 | 
					//    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;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
		Reference in New Issue
	
	Block a user