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
1313 #include "LEAFLink.h"
1414
1515 UIComponent::UIComponent()
16−
1716 {
17+ formatManager.registerBasicFormats();
18+
1819 for (int i = 0; i < cSliderNames.size(); i++)
1920 {
2021
@@ -123,8 +124,9 @@ void UIComponent::resized() · 102 unmodified lines
123124
124125 for (int i = 0; i < cButtonNames.size(); i++)
125126 {
126− buttons[i] ->setBounds(cLeftOffset + ((cButtonWidth + cXSpacing) * i),
127− 500,
127+ buttons[i] ->setBounds(cLeftOffset + ((cButtonWidth + cXSpacing) * i) -
128+ (cButtonNames[i].length() * 2.0f),
129+ 290,
128130 cButtonWidth,
129131 cButtonHeight);
130132 }
@@ -144,12 +146,36 @@ void UIComponent::sliderValueChanged(Slider* s) · 13 unmodified lines
144146 setSliderValue(s->getName(), s->getValue());
145147 }
146148
147−void UIComponent::buttonStateChanged (Button* b)
149+void UIComponent::buttonStateChanged(Button* b)
148150 {
149151 setButtonState(b->getName(), b->getState());
150152 }
151153
152−void UIComponent::comboBoxChanged (ComboBox* cb)
154+void UIComponent::comboBoxChanged(ComboBox* cb)
153155 {
154156 setComboBoxState(cb->getName(), cb->getSelectedId() - 1);
155157 }
158+
159+
160+void 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