2424#include " AudioEditor.h"
2525#include " ../../Audio/AudioComponent.h"
2626#include " ../../AccessClass.h"
27+ #include " ../../UI/LookAndFeel/MaterialSliderLookAndFeel.h"
28+
29+
30+ static const Colour COLOUR_SLIDER_TRACK (Colour::fromRGB (92 , 92 , 92 ));
31+ static const Colour COLOUR_SLIDER_TRACK_FILL (Colour::fromRGB (255 , 255 , 255 ));
32+
33+ static const Font FONT_LABEL (" Small Text" , 12 , Font::plain);
34+
2735
2836MuteButton::MuteButton ()
2937 : ImageButton (" MuteButton" )
3038{
3139 Image offimage = ImageCache::getFromMemory (BinaryData::muteoff_png, BinaryData::muteoff_pngSize);
32- Image onimage = ImageCache::getFromMemory (BinaryData::muteon_png, BinaryData::muteon_pngSize);
40+ Image onimage = ImageCache::getFromMemory (BinaryData::muteon_png, BinaryData::muteon_pngSize);
3341
3442 setImages (false , true , true ,
3543 offimage, 1 .0f , Colours::white.withAlpha (0 .0f ),
3644 offimage, 1 .0f , Colours::black.withAlpha (0 .0f ),
37- onimage, 1 .0f , Colours::white. withAlpha ( 0 . 0f ) );
45+ onimage, 1 .0f , Colours::lightgrey );
3846
3947 setClickingTogglesState (true );
4048
@@ -52,8 +60,7 @@ AudioWindowButton::AudioWindowButton()
5260{
5361 setClickingTogglesState (true );
5462
55- font = Font (" Small Text" , 12 , Font::plain);
56- textString = " AUDIO" ;
63+ textString = " :AUDIO" ;
5764 setTooltip (" Change the buffer size" );
5865}
5966
@@ -70,8 +77,10 @@ void AudioWindowButton::paintButton (Graphics& g, bool isMouseOver, bool isButto
7077 else
7178 g.setColour (Colours::lightgrey);
7279
73- g.setFont (font);
74- g.drawSingleLineText (textString, 0 , 15 );
80+ const bool isLatencyLabelVisible = getParentComponent ()->getWidth () >= 450 ;
81+ auto textToDraw = isLatencyLabelVisible ? textString : textString.fromLastOccurrenceOf (" :" , false , true );
82+ g.setFont (FONT_LABEL);
83+ g.drawSingleLineText (textToDraw, 0 , 15 );
7584}
7685
7786
@@ -99,18 +108,27 @@ AudioEditor::AudioEditor (AudioNode* owner)
99108 addAndMakeVisible (audioWindowButton);
100109
101110 volumeSlider = new Slider (" Volume Slider" );
102- volumeSlider->setRange (0 ,100 ,1 );
103- volumeSlider->addListener (this );
111+ volumeSlider->setSliderStyle (Slider::LinearHorizontal);
104112 volumeSlider->setTextBoxStyle (Slider::NoTextBox,
105113 false , 0 , 0 );
106- volumeSlider->setColour (Slider::trackColourId, Colours::yellow);
114+ volumeSlider->setRange (0 , 100 , 1 );
115+ volumeSlider->setColour (Slider::backgroundColourId, COLOUR_SLIDER_TRACK);
116+ volumeSlider->setColour (Slider::trackColourId, COLOUR_SLIDER_TRACK_FILL);
117+ volumeSlider->setColour (Slider::thumbColourId, COLOUR_SLIDER_TRACK_FILL);
118+ volumeSlider->setLookAndFeel (materialSliderLookAndFeel);
119+ volumeSlider->addListener (this );
107120 addAndMakeVisible (volumeSlider);
108121
109122 noiseGateSlider = new Slider (" Noise Gate Slider" );
110- noiseGateSlider->setRange (0 ,100 ,1 );
111- noiseGateSlider->addListener (this );
123+ volumeSlider->setSliderStyle (Slider::LinearHorizontal);
112124 noiseGateSlider->setTextBoxStyle (Slider::NoTextBox,
113125 false , 0 , 0 );
126+ noiseGateSlider->setRange (0 ,100 ,1 );
127+ noiseGateSlider->setColour (Slider::backgroundColourId, COLOUR_SLIDER_TRACK);
128+ noiseGateSlider->setColour (Slider::trackColourId, COLOUR_SLIDER_TRACK_FILL);
129+ noiseGateSlider->setColour (Slider::thumbColourId, COLOUR_SLIDER_TRACK_FILL);
130+ noiseGateSlider->setLookAndFeel (materialSliderLookAndFeel);
131+ noiseGateSlider->addListener (this );
114132 addAndMakeVisible (noiseGateSlider);
115133}
116134
@@ -122,14 +140,24 @@ AudioEditor::~AudioEditor()
122140
123141void AudioEditor::resized ()
124142{
125- const int height = getHeight ();
126- const int sliderWidth = 50 ;
127- const int sliderHeight = height - 5 ;
128-
129- muteButton->setBounds (0 , 5 , 30 , 25 );
130- volumeSlider->setBounds (35 , 8 , sliderWidth, sliderHeight);
131- noiseGateSlider->setBounds (85 , 8 , sliderWidth, sliderHeight);
132- audioWindowButton->setBounds (140 , 5 , 200 , height);
143+ const int width = getWidth ();
144+ const int height = getHeight ();
145+
146+ // Since width of the label on button is always the same, we should reserve it.
147+ const bool isLatencyLabelVisible = width >= 450 ;
148+ const int audioWindowButtonWidth = isLatencyLabelVisible ? 110 : 60 ;
149+ const int gateLabelWidth = 45 ;
150+
151+ const int availableWidth = width - audioWindowButtonWidth - gateLabelWidth;
152+ const int sliderWidth = availableWidth * 0.4 ;
153+ const int sliderHeight = height - 6 ;
154+ const int sliderY = (height - sliderHeight) / 2 ;
155+ const int margin = availableWidth * 0.03 ;
156+
157+ muteButton->setBounds (margin, 5 , 20 , 20 );
158+ volumeSlider->setBounds (margin + 30 , sliderY, sliderWidth, sliderHeight);
159+ noiseGateSlider->setBounds (volumeSlider->getRight () + margin + gateLabelWidth, sliderY, sliderWidth, sliderHeight);
160+ audioWindowButton->setBounds (width - audioWindowButtonWidth + 2 , 5 , audioWindowButtonWidth, height);
133161}
134162
135163
@@ -143,7 +171,7 @@ bool AudioEditor::keyPressed (const KeyPress& key)
143171void AudioEditor::updateBufferSizeText ()
144172{
145173 String t = String (AccessClass::getAudioComponent ()->getBufferSizeMs ());
146- t += " ms" ;
174+ t = " Latency: " + t + " ms" ;
147175
148176 audioWindowButton->setText (t);
149177}
@@ -221,10 +249,12 @@ void AudioEditor::sliderValueChanged (Slider* slider)
221249
222250void AudioEditor::paint (Graphics& g)
223251{
224- g.setColour (Colours::grey);
225- g.setFont (10 );
226- g.drawText (" VOLUME:" , 40 , 1 , 50 , 10 , Justification::left, false );
227- g.drawText (" GATE:" , 90 , 1 , 50 , 10 , Justification::left, false );
252+ g.fillAll (Colours::green);
253+
254+ const int margin = getWidth () * 0.03 ;
255+ g.setColour (Colours::lightgrey);
256+ g.setFont (FONT_LABEL);
257+ g.drawSingleLineText (" GATE:" , volumeSlider->getBounds ().getRight () + margin, 20 );
228258}
229259
230260
0 commit comments