copy JUCE demo plugin more closely. worry about coupling later; for now get ownership in right place. update lastUIW/H on resize.

This commit is contained in:
Alex Birch 2018-04-10 00:11:22 +01:00
parent 89b12b132a
commit 9bbb27d780
No known key found for this signature in database
GPG Key ID: 305EB1F98D44ACBA
4 changed files with 53 additions and 38 deletions

View File

@ -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<int> r2 (getLocalBounds());
// r2.reduce(0, padding);
// r2.removeFromBottom(pianoHeight);

View File

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

View File

@ -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<StateChangeSubscriber*>::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<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())
@ -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<StateChangeSubscriber*>::iterator p;
for(p = stateChangeSubscribers.begin(); p != stateChangeSubscribers.end(); p++) {
(*p)->setStateInformation(xmlState);
}
// list<StateChangeSubscriber*>::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 {

View File

@ -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<StateChangeSubscriber*> stateChangeSubscribers;
// list<StateChangeSubscriber*> stateChangeSubscribers;
static BusesProperties getBusesProperties();