forked from getdunne/VanillaJuce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuiEgTab.cpp
87 lines (77 loc) · 3.23 KB
/
GuiEgTab.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "GuiEgTab.h"
GuiEgTab::GuiEgTab (SynthSound* pSynthSound)
: pSound(pSynthSound)
, attackLabel("attack", TRANS("Attack Time (sec)"))
, decayLabel("decay", TRANS("Decay Time (sec)"))
, sustainLabel("sustain", TRANS("Sustain Level (%)"))
, releaseLabel("release", TRANS("Release Time (sec)"))
{
auto initLabel = [this](Label& label)
{
addAndMakeVisible(label);
label.setFont (Font (15.00f, Font::plain).withTypefaceStyle ("Regular"));
label.setJustificationType (Justification::centredRight);
label.setEditable (false, false, false);
label.setColour (TextEditor::textColourId, Colours::black);
label.setColour (TextEditor::backgroundColourId, Colour (0x00000000));
};
initLabel(attackLabel);
initLabel(decayLabel);
initLabel(sustainLabel);
initLabel(releaseLabel);
auto initSlider = [this](Slider& slider)
{
addAndMakeVisible(slider);
slider.setSliderStyle (Slider::LinearHorizontal);
slider.setTextBoxStyle (Slider::TextBoxRight, false, 80, 20);
slider.addListener (this);
};
initSlider(attackSlider); attackSlider.setRange (0, 10, 0);
initSlider(decaySlider); decaySlider.setRange (0, 10, 0);
initSlider(sustainSlider); sustainSlider.setRange (0, 100, 1);
initSlider(releaseSlider); releaseSlider.setRange (0, 10, 0);
notify();
}
void GuiEgTab::paint (Graphics& g)
{
g.fillAll (Colour (0xff323e44));
}
void GuiEgTab::resized()
{
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;
attackLabel.setBounds (labelLeft, top, labelWidth, controlHeight);
attackSlider.setBounds (controlLeft, top, sliderWidth, controlHeight);
top += controlHeight + gapHeight;
decayLabel.setBounds (labelLeft, top, labelWidth, controlHeight);
decaySlider.setBounds (controlLeft, top, sliderWidth, controlHeight);
top += controlHeight + gapHeight;
sustainLabel.setBounds (labelLeft, top, labelWidth, controlHeight);
sustainSlider.setBounds (controlLeft, top, sliderWidth, controlHeight);
top += controlHeight + gapHeight;
releaseLabel.setBounds (labelLeft, top, labelWidth, controlHeight);
releaseSlider.setBounds (controlLeft, top, sliderWidth, controlHeight);
}
void GuiEgTab::sliderValueChanged (Slider* sliderThatWasMoved)
{
float value = (float)(sliderThatWasMoved->getValue());
SynthParameters* pParams = pSound->pParams;
if (sliderThatWasMoved == &attackSlider) pParams->ampEgAttackTimeSeconds = value;
else if (sliderThatWasMoved == &decaySlider) pParams->ampEgDecayTimeSeconds = value;
else if (sliderThatWasMoved == &sustainSlider) pParams->ampEgSustainLevel = 0.01f * value;
else if (sliderThatWasMoved == &releaseSlider) pParams->ampEgReleaseTimeSeconds = value;
pSound->parameterChanged();
}
void GuiEgTab::notify()
{
SynthParameters* pParams = pSound->pParams;
attackSlider.setValue(pParams->ampEgAttackTimeSeconds);
decaySlider.setValue(pParams->ampEgDecayTimeSeconds);
sustainSlider.setValue(100.0f * pParams->ampEgSustainLevel);
releaseSlider.setValue(pParams->ampEgReleaseTimeSeconds);
}