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