MCPcopy Create free account
hub / github.com/StrangeLoopsAudio/gRainbow / parse

Method parse

Source/Components/TrimSelection.cpp:145–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143}
144
145void TrimSelection::parse(const juce::AudioBuffer<float>& audioBuffer, double sampleRate, juce::String& error) {
146 cleanup(); // in case while trim selecting, user selects a new file
147 mSampleRate = sampleRate;
148 const double duration = static_cast<double>(audioBuffer.getNumSamples()) / mSampleRate;
149 if (duration <= MIN_SELECTION_SEC) {
150 error = juce::String("The audio file is ") + juce::String(duration) + " seconds but must be greater than " +
151 juce::String(MIN_SELECTION_SEC) + " seconds.";
152 // If another valid file was opened, cancel as that selection will now fail as the formatReader is bad now
153 onCancel();
154 return;
155 }
156
157 // It is slightly faster to use the setReader() with the AudioFormatReader for the thumbnail and make use of
158 // juce::AudioThumbnailCache, but the main reasons to add the thumbnail block manually are
159 // 1. The file might be at a different sampleRate than the audio buffer which can seem like it doesn't match the playback
160 // 2. It is possible to update the thumbnail if the audio buffer is modified
161 // 3. It is not obvious that setReader() will delete the AudioFormatReader when called a second time
162 mThumbnail.clear();
163 mThumbnail.reset(audioBuffer.getNumChannels(), mSampleRate, audioBuffer.getNumSamples());
164 mThumbnail.addBlock(0, audioBuffer, 0, audioBuffer.getNumSamples());
165
166 audioSampleDuration = duration;
167 // start with everything selected
168 mSelectedRange = juce::Range<double>(0.0, audioSampleDuration);
169 updatePointMarker();
170}
171
172void TrimSelection::resized() {
173 // Layout of component

Callers 1

loadFileMethod · 0.80

Calls 2

clearMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected