Unified · Split
| @@ -15,7 +15,7 @@ · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | std::vector<juce::String> cButtonNames = std::vector<juce::String> |
| 17 | 17 | { |
| 18 | − | |
| 18 | + "load" | |
| 19 | 19 | }; |
| 20 | 20 | |
| 21 | 21 | std::vector<juce::String> cSliderNames = std::vector<juce::String> |
| @@ -40,6 +40,8 @@ std::vector<float> cSliderValues(cSliderNames.size()); · 18 unmodified lines | ||
| 40 | 40 | std::vector<bool> cButtonStates(cButtonNames.size()); |
| 41 | 41 | std::vector<int> cComboBoxStates(cComboBoxNames.size()); |
| 42 | 42 | |
| 43 | +Array<AudioBuffer<float>> loadedAudio; | |
| 44 | + | |
| 43 | 45 | void setSliderModelValue(String name, float val) |
| 44 | 46 | { |
| 45 | 47 | for (int i = 0; i < cSliderNames.size(); i++) |
| @@ -142,3 +144,4 @@ float getRandomFloat(void) · 96 unmodified lines | ||
| 142 | 144 | { |
| 143 | 145 | return ((float)rand()/RAND_MAX); |
| 144 | 146 | } |
| 147 | + | |
| @@ -39,6 +39,8 @@ extern std::vector<bool> cButtonStates; · 38 unmodified lines | ||
| 39 | 39 | |
| 40 | 40 | extern std::vector<int> cComboBoxStates; |
| 41 | 41 | |
| 42 | +extern Array<AudioBuffer<float>> loadedAudio; | |
| 43 | + | |
| 42 | 44 | void printSliderValues(void); |
| 43 | 45 | bool getButtonState(String name); |
| 44 | 46 | void setButtonState(String name, bool on); |
| @@ -38,6 +38,9 @@ tWaveset ws; · 37 unmodified lines | ||
| 38 | 38 | tBuffer samp; |
| 39 | 39 | tMBSampler sampler; |
| 40 | 40 | |
| 41 | +const int numWavetables = 1; | |
| 42 | +tWavetable wavetables[numWavetables]; | |
| 43 | + | |
| 41 | 44 | float gain; |
| 42 | 45 | float dtime; |
| 43 | 46 | bool buttonState; |
| @@ -54,6 +57,8 @@ LEAF leaf; · 10 unmodified lines | ||
| 54 | 57 | #define MSIZE 2048000 |
| 55 | 58 | char memory[MSIZE]; |
| 56 | 59 | |
| 60 | +int lastLoadedAudioSize = 0; | |
| 61 | + | |
| 57 | 62 | void LEAFTest_init (float sampleRate, int blockSize) |
| 58 | 63 | { |
| 59 | 64 | LEAF_init(&leaf, sampleRate, blockSize, memory, MSIZE, &getRandomFloat); |
| @@ -79,6 +84,9 @@ void LEAFTest_init (float sampleRate, int blockSize) · 19 unmodified lines | ||
| 79 | 84 | |
| 80 | 85 | tWaveset_init(&ws, set, 4, 2048, 10000.f, &leaf); |
| 81 | 86 | tWaveset_setIndexGain(&ws, 0, -1.0f); |
| 87 | + | |
| 88 | + lastLoadedAudioSize = 0; | |
| 89 | + loadedAudio.clear(); | |
| 82 | 90 | } |
| 83 | 91 | |
| 84 | 92 | inline double getSawFall(double angle) { |
| @@ -92,12 +100,12 @@ inline double getSawFall(double angle) { · 7 unmodified lines | ||
| 92 | 100 | |
| 93 | 101 | float LEAFTest_tick (float input) |
| 94 | 102 | { |
| 95 | −// return tRetune_tick(&retune, input)[0]; | |
| 96 | −// return tSimpleRetune_tick(&sretune, input); | |
| 97 | −// tMBPulse_sync(&bpulse, tPhasor_tick(&phasor) * 2.f - 1.f); | |
| 98 | −// return tMBPulse_tick(&bpulse); | |
| 99 | −// return tWavetable_tick(&wt); | |
| 100 | − return tWaveset_tick(&ws); | |
| 103 | + float out = 0.0f; | |
| 104 | + for (int i = 0; i < fmin(loadedAudio.size(), numWavetables); ++i) | |
| 105 | + { | |
| 106 | + out += tWavetable_tick(&wavetables[i]); | |
| 107 | + } | |
| 108 | + return out; | |
| 101 | 109 | } |
| 102 | 110 | |
| 103 | 111 | int firstFrame = 1; |
| @@ -121,6 +129,15 @@ void LEAFTest_block (void) · 17 unmodified lines | ||
| 121 | 129 | val = getSliderValue("slider3"); |
| 122 | 130 | // tRetune_setPitchFactor(&retune, val * 3.0f + 0.5f, 2); |
| 123 | 131 | |
| 132 | + | |
| 133 | + if (lastLoadedAudioSize < loadedAudio.size()) | |
| 134 | + { | |
| 135 | + int i = (loadedAudio.size() - 1) % numWavetables; | |
| 136 | + if (loadedAudio.size() - 1 >= numWavetables) tWavetable_free(&wavetables[i]); | |
| 137 | + tWavetable_init(&wavetables[i], loadedAudio[loadedAudio.size() - 1].getReadPointer(0), loadedAudio[loadedAudio.size() - 1].getNumSamples(), 20000, &leaf); | |
| 138 | + | |
| 139 | + lastLoadedAudioSize = loadedAudio.size(); | |
| 140 | + } | |
| 124 | 141 | } |
| 125 | 142 | |
| 126 | 143 | void LEAFTest_controllerInput (int cnum, float cval) |
| @@ -13,8 +13,9 @@ · 12 unmodified lines | ||
| 13 | 13 | #include "LEAFLink.h" |
| 14 | 14 | |
| 15 | 15 | UIComponent::UIComponent() |
| 16 | − | |
| 17 | 16 | { |
| 17 | + formatManager.registerBasicFormats(); | |
| 18 | + | |
| 18 | 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 | 125 | for (int i = 0; i < cButtonNames.size(); i++) |
| 125 | 126 | { |
| 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, | |
| 128 | 130 | cButtonWidth, |
| 129 | 131 | cButtonHeight); |
| 130 | 132 | } |
| @@ -144,12 +146,36 @@ void UIComponent::sliderValueChanged(Slider* s) · 13 unmodified lines | ||
| 144 | 146 | setSliderValue(s->getName(), s->getValue()); |
| 145 | 147 | } |
| 146 | 148 | |
| 147 | −void UIComponent::buttonStateChanged (Button* b) | |
| 149 | +void UIComponent::buttonStateChanged(Button* b) | |
| 148 | 150 | { |
| 149 | 151 | setButtonState(b->getName(), b->getState()); |
| 150 | 152 | } |
| 151 | 153 | |
| 152 | −void UIComponent::comboBoxChanged (ComboBox* cb) | |
| 154 | +void UIComponent::comboBoxChanged(ComboBox* cb) | |
| 153 | 155 | { |
| 154 | 156 | setComboBoxState(cb->getName(), cb->getSelectedId() - 1); |
| 155 | 157 | } |
| 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 | +} | |
| @@ -35,7 +35,7 @@ public: · 34 unmodified lines | ||
| 35 | 35 | |
| 36 | 36 | void sliderValueChanged(Slider* s) override; |
| 37 | 37 | |
| 38 | − void buttonClicked(Button*b) override {}; | |
| 38 | + void buttonClicked(Button*b) override; | |
| 39 | 39 | void buttonStateChanged(Button* b) override; |
| 40 | 40 | |
| 41 | 41 | void textEditorTextChanged (TextEditor&) override; |
| @@ -59,7 +59,7 @@ private: · 17 unmodified lines | ||
| 59 | 59 | static const int cLabelWidth = cSliderWidth + cXSpacing; |
| 60 | 60 | |
| 61 | 61 | static const int cButtonHeight = 30; |
| 62 | − static const int cButtonWidth = 60; | |
| 62 | + static const int cButtonWidth = 75; | |
| 63 | 63 | |
| 64 | 64 | static const int cBoxHeight = 20; |
| 65 | 65 | static const int cBoxWidth = 100; |
| @@ -70,6 +70,9 @@ private: · 4 unmodified lines | ||
| 70 | 70 | OwnedArray<TextEditor> textFields; |
| 71 | 71 | OwnedArray<ComboBox> comboBoxes; |
| 72 | 72 | |
| 73 | + juce::AudioFormatManager formatManager; | |
| 74 | + std::unique_ptr<juce::AudioFormatReaderSource> readerSource; | |
| 75 | + | |
| 73 | 76 | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UIComponent) |
| 74 | 77 | }; |
| 75 | 78 | |