This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
the_plugin_editor [2017/08/30 19:39] shane [The GuiTabs object] |
the_plugin_editor [2017/10/02 19:38] (current) shane [The GuiTabs object] |
||
|---|---|---|---|
| Line 29: | Line 29: | ||
| , guiTabs(p.getSound()) | , guiTabs(p.getSound()) | ||
| { | { | ||
| - | setSize (600, 400); | + | setSize (600, 300); |
| addAndMakeVisible(& | addAndMakeVisible(& | ||
| p.addChangeListener(this); | p.addChangeListener(this); | ||
| Line 46: | Line 46: | ||
| void VanillaJuceAudioProcessorEditor:: | void VanillaJuceAudioProcessorEditor:: | ||
| { | { | ||
| - | guiTabs.setBounds(0, | + | guiTabs.setBounds(0, |
| } | } | ||
| Line 106: | Line 106: | ||
| void GuiTabs:: | void GuiTabs:: | ||
| { | { | ||
| - | tabbedComponent-> | + | tabbedComponent-> |
| } | } | ||
| Line 123: | Line 123: | ||
| ===== The individual tabs ===== | ===== The individual tabs ===== | ||
| + | The three tab classes // | ||
| + | <code cpp> | ||
| + | class GuiMainTab : public Component, public SliderListener | ||
| + | { | ||
| + | public: | ||
| + | GuiMainTab (SynthSound* pSynthSound); | ||
| + | ~GuiMainTab(); | ||
| + | |||
| + | void paint (Graphics& | ||
| + | void resized() override; | ||
| + | void sliderValueChanged (Slider* sliderThatWasMoved) override; | ||
| + | |||
| + | void notify(); | ||
| + | |||
| + | private: | ||
| + | SynthSound* pSound; | ||
| + | |||
| + | ScopedPointer< | ||
| + | ScopedPointer< | ||
| + | ScopedPointer< | ||
| + | ScopedPointer< | ||
| + | ScopedPointer< | ||
| + | ScopedPointer< | ||
| + | |||
| + | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GuiMainTab) | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | This class inherits from // | ||
| + | |||
| + | The constructor takes a // | ||
| + | - To read and write the parameters of the current patch, the tab object can dereference the //pSound// pointer to get at its //pParams// member, which points to the // | ||
| + | - Whenever any of the tab's controls changes any parameter value, it must call // | ||
| + | |||
| + | Note the use of // | ||
| + | |||
| + | The bulk of the constructor code just creates and sets up the three slider controls and their labels. I developed this code by using the Projucer to create a stand-alone GUI program, using its interactive GUI editor, then I looked at the code it produced and adapted that for use here. | ||
| + | <code cpp> | ||
| + | GuiMainTab:: | ||
| + | : pSound(pSynthSound) | ||
| + | { | ||
| + | addAndMakeVisible (masterLevelLabel = new Label (" | ||
| + | masterLevelLabel-> | ||
| + | masterLevelLabel-> | ||
| + | masterLevelLabel-> | ||
| + | masterLevelLabel-> | ||
| + | masterLevelLabel-> | ||
| + | |||
| + | addAndMakeVisible (masterLevelSlider = new Slider (" | ||
| + | masterLevelSlider-> | ||
| + | masterLevelSlider-> | ||
| + | masterLevelSlider-> | ||
| + | masterLevelSlider-> | ||
| + | |||
| + | addAndMakeVisible(pbUpLabel = new Label(" | ||
| + | pbUpLabel-> | ||
| + | pbUpLabel-> | ||
| + | pbUpLabel-> | ||
| + | pbUpLabel-> | ||
| + | pbUpLabel-> | ||
| + | |||
| + | addAndMakeVisible(pbUpSlider = new Slider(" | ||
| + | pbUpSlider-> | ||
| + | pbUpSlider-> | ||
| + | pbUpSlider-> | ||
| + | pbUpSlider-> | ||
| + | |||
| + | addAndMakeVisible(pbDownLabel = new Label(" | ||
| + | pbDownLabel-> | ||
| + | pbDownLabel-> | ||
| + | pbDownLabel-> | ||
| + | pbDownLabel-> | ||
| + | pbDownLabel-> | ||
| + | |||
| + | addAndMakeVisible(pbDownSlider = new Slider(" | ||
| + | pbDownSlider-> | ||
| + | pbDownSlider-> | ||
| + | pbDownSlider-> | ||
| + | pbDownSlider-> | ||
| + | |||
| + | notify(); | ||
| + | } | ||
| + | </ | ||
| + | The constructor ends with a call to this tab's own // | ||
| + | <code cpp> | ||
| + | SynthParameters* pParams = pSound-> | ||
| + | masterLevelSlider-> | ||
| + | pbUpSlider-> | ||
| + | pbDownSlider-> | ||
| + | </ | ||
| + | |||
| + | The // | ||
| + | <code cpp> | ||
| + | void GuiMainTab:: | ||
| + | { | ||
| + | double value = sliderThatWasMoved-> | ||
| + | SynthParameters* pParams = pSound-> | ||
| + | if (sliderThatWasMoved == masterLevelSlider) | ||
| + | { | ||
| + | pParams-> | ||
| + | } | ||
| + | else if (sliderThatWasMoved == pbUpSlider) | ||
| + | { | ||
| + | pParams-> | ||
| + | } | ||
| + | else if (sliderThatWasMoved == pbDownSlider) | ||
| + | { | ||
| + | pParams-> | ||
| + | } | ||
| + | pSound-> | ||
| + | } | ||
| + | </ | ||
| + | The final // | ||
| + | |||
| + | The //paint()// member function takes care of filling the entire background behind the labels and sliders: | ||
| + | <code cpp> | ||
| + | void GuiMainTab:: | ||
| + | { | ||
| + | g.fillAll (Colour (0xff323e44)); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | The // | ||
| + | <code cpp> | ||
| + | void GuiMainTab:: | ||
| + | { | ||
| + | const int labelLeft = 16; | ||
| + | const int controlLeft = 144; | ||
| + | const int labelWidth = 120; | ||
| + | const int sliderWidth = 420; | ||
| + | const int controlHeight = 24; | ||
| + | const int gapHeight = 8; | ||
| + | |||
| + | int top = 20; | ||
| + | masterLevelLabel-> | ||
| + | masterLevelSlider-> | ||
| + | top += controlHeight + 5 * gapHeight; | ||
| + | pbUpLabel-> | ||
| + | pbUpSlider-> | ||
| + | top += controlHeight + gapHeight; | ||
| + | pbDownLabel-> | ||
| + | pbDownSlider-> | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | The code above will lay out the labels and sliders so they are aligned nicely, with certain gaps between them. It does not make any reference to the tab object' | ||
| + | |||
| + | And that's pretty much it for the VanillaJuce GUI. The other two tabs don't differ in any meaningful way. | ||