From 9bbb27d780c10eea95f5a8e44b4634bc80c8206e Mon Sep 17 00:00:00 2001 From: Alex Birch Date: Tue, 10 Apr 2018 00:11:22 +0100 Subject: [PATCH] copy JUCE demo plugin more closely. worry about coupling later; for now get ownership in right place. update lastUIW/H on resize. --- Source/PluginEditor.cpp | 31 ++++++++++++++------------- Source/PluginEditor.h | 8 +++---- Source/PluginProcessor.cpp | 43 +++++++++++++++++++++++--------------- Source/PluginProcessor.h | 9 +++++--- 4 files changed, 53 insertions(+), 38 deletions(-) diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 5202253..ce17c60 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -22,9 +22,9 @@ JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor (JuicySFAudioProcessor& // set resize limits for this plug-in setResizeLimits (400, 300, 800, 600); - setSize (400, 300); + setSize (p.lastUIWidth, p.lastUIHeight); - processor.subscribeToStateChanges(this); +// processor.subscribeToStateChanges(this); midiKeyboard.setName ("MIDI Keyboard"); @@ -40,20 +40,20 @@ JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor (JuicySFAudioProcessor& JuicySFAudioProcessorEditor::~JuicySFAudioProcessorEditor() { - processor.unsubscribeFromStateChanges(this); +// 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())); -} +//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())); +//} //============================================================================== void JuicySFAudioProcessorEditor::paint (Graphics& g) @@ -85,6 +85,9 @@ void JuicySFAudioProcessorEditor::resized() midiKeyboard.setBounds (r.removeFromBottom (pianoHeight).reduced(padding, 0)); tablesComponent.setBounds(r.reduced(0, padding)); + processor.lastUIWidth = getWidth(); + processor.lastUIHeight = getHeight(); + // Rectangle r2 (getLocalBounds()); // r2.reduce(0, padding); // r2.removeFromBottom(pianoHeight); diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 60c3890..a19da4e 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -20,8 +20,8 @@ //============================================================================== /** */ -class JuicySFAudioProcessorEditor : public AudioProcessorEditor, - public StateChangeSubscriber +class JuicySFAudioProcessorEditor : public AudioProcessorEditor/*, + public StateChangeSubscriber*/ { public: JuicySFAudioProcessorEditor (JuicySFAudioProcessor&); @@ -34,8 +34,8 @@ public: bool keyPressed(const KeyPress &key) override; bool keyStateChanged (bool isKeyDown) override; - void getStateInformation (XmlElement& xml) override; - void setStateInformation (XmlElement* xmlState) override; +// void getStateInformation (XmlElement& xml) override; +// void setStateInformation (XmlElement* xmlState) override; private: // This reference is provided as a quick way for your editor to diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 1d48cbf..45f3668 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -19,9 +19,10 @@ AudioProcessor* JUCE_CALLTYPE createPluginFilter(); //============================================================================== JuicySFAudioProcessor::JuicySFAudioProcessor() : AudioProcessor (getBusesProperties()), - fluidSynthModel()/*, lastUIWidth(400), - lastUIHeight(300)*/ + lastUIHeight(300), + fluidSynthModel(), + soundFontPath(String()) { initialiseSynth(); } @@ -187,10 +188,14 @@ void JuicySFAudioProcessor::getStateInformation (MemoryBlock& destData) // Create an outer XML element.. XmlElement xml ("MYPLUGINSETTINGS"); - list::iterator p; - for(p = stateChangeSubscribers.begin(); p != stateChangeSubscribers.end(); p++) { - (*p)->getStateInformation(xml); - } + // add some attributes to it.. + xml.setAttribute ("uiWidth", lastUIWidth); + xml.setAttribute ("uiHeight", lastUIHeight); + +// list::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()) @@ -213,10 +218,14 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt // make sure that it's actually our type of XML object.. if (xmlState->hasTagName ("MYPLUGINSETTINGS")) { - list::iterator p; - for(p = stateChangeSubscribers.begin(); p != stateChangeSubscribers.end(); p++) { - (*p)->setStateInformation(xmlState); - } +// list::iterator p; +// for(p = stateChangeSubscribers.begin(); p != stateChangeSubscribers.end(); p++) { +// (*p)->setStateInformation(xmlState); +// } + + // ok, now pull out our last window size.. + lastUIWidth = jmax (xmlState->getIntAttribute ("uiWidth", lastUIWidth), 400); + lastUIHeight = jmax (xmlState->getIntAttribute ("uiHeight", lastUIHeight), 300); // Now reload our parameters.. for (auto* param : getParameters()) @@ -226,13 +235,13 @@ 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); -} +//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 { diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index d7b79b6..ccef604 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -65,8 +65,11 @@ public: MidiKeyboardState keyboardState; - void subscribeToStateChanges(StateChangeSubscriber* subscriber); - void unsubscribeFromStateChanges(StateChangeSubscriber* subscriber); +// void subscribeToStateChanges(StateChangeSubscriber* subscriber); +// void unsubscribeFromStateChanges(StateChangeSubscriber* subscriber); + + int lastUIWidth, lastUIHeight; + String soundFontPath; private: void initialiseSynth(); @@ -75,7 +78,7 @@ private: fluid_synth_t* fluidSynth; Synthesiser synth; - list stateChangeSubscribers; +// list stateChangeSubscribers; static BusesProperties getBusesProperties();