History

add wav file loading to test JUCE project

Matthew Wang committed 5 years ago

Commit 7ea48641 parent be773ed5 files · +65 −14Browse files

Showing the changes to TestPlugin/Source/UIComponent.cpp (1 of 5 files). Show all

Unified · Split

TestPlugin/Source/UIComponent.cpp+31−5
@@ -13,8 +13,9 @@ · 12 unmodified lines
13#include "LEAFLink.h"13#include "LEAFLink.h"
14 14
15UIComponent::UIComponent()15UIComponent::UIComponent()
16
17{16{
17 formatManager.registerBasicFormats();
18
18 for (int i = 0; i < cSliderNames.size(); i++)19 for (int i = 0; i < cSliderNames.size(); i++)
19 {20 {
20 21
@@ -123,8 +124,9 @@ void UIComponent::resized() · 102 unmodified lines
123 124
124 for (int i = 0; i < cButtonNames.size(); i++)125 for (int i = 0; i < cButtonNames.size(); i++)
125 {126 {
126 buttons[i] ->setBounds(cLeftOffset + ((cButtonWidth + cXSpacing) * i),127 buttons[i] ->setBounds(cLeftOffset + ((cButtonWidth + cXSpacing) * i) -
127 500,128 (cButtonNames[i].length() * 2.0f),
129 290,
128 cButtonWidth,130 cButtonWidth,
129 cButtonHeight);131 cButtonHeight);
130 }132 }
@@ -144,12 +146,36 @@ void UIComponent::sliderValueChanged(Slider* s) · 13 unmodified lines
144 setSliderValue(s->getName(), s->getValue());146 setSliderValue(s->getName(), s->getValue());
145}147}
146 148
147void UIComponent::buttonStateChanged (Button* b)149void UIComponent::buttonStateChanged(Button* b)
148{150{
149 setButtonState(b->getName(), b->getState());151 setButtonState(b->getName(), b->getState());
150}152}
151 153
152void UIComponent::comboBoxChanged (ComboBox* cb)154void UIComponent::comboBoxChanged(ComboBox* cb)
153{155{
154 setComboBoxState(cb->getName(), cb->getSelectedId() - 1);156 setComboBoxState(cb->getName(), cb->getSelectedId() - 1);
155}157}
158
159
160void UIComponent::buttonClicked(Button *b)
161{
162 if (b->getName() == "load")
163 {
164 juce::FileChooser chooser ("Select a Wave file to play...", {}, "*.wav");
165
166 if (chooser.browseForFileToOpen())
167 {
168 auto file = chooser.getResult();
169 auto* reader = formatManager.createReaderFor (file);
170
171 if (reader != nullptr)
172 {
173 AudioBuffer<float> buffer = AudioBuffer<float>(reader->numChannels, int(reader->lengthInSamples));
174
175 reader->read(&buffer, 0, buffer.getNumSamples(), 0, true, true);
176
177 loadedAudio.add(buffer);
178 }
179 }
180 }
181}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t