VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_audio_formats / format / juce_AudioFormatReaderSource.cpp
blob7c47f86a9caf9dc90513038816af7a0564e883e5
1 /*
2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
23 ==============================================================================
26 namespace juce
29 AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const r,
30 const bool deleteReaderWhenThisIsDeleted)
31 : reader (r, deleteReaderWhenThisIsDeleted),
32 nextPlayPos (0),
33 looping (false)
35 jassert (reader != nullptr);
38 AudioFormatReaderSource::~AudioFormatReaderSource() {}
40 int64 AudioFormatReaderSource::getTotalLength() const { return reader->lengthInSamples; }
41 void AudioFormatReaderSource::setNextReadPosition (int64 newPosition) { nextPlayPos = newPosition; }
42 void AudioFormatReaderSource::setLooping (bool shouldLoop) { looping = shouldLoop; }
44 int64 AudioFormatReaderSource::getNextReadPosition() const
46 return looping ? nextPlayPos % reader->lengthInSamples
47 : nextPlayPos;
50 void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/, double /*sampleRate*/) {}
51 void AudioFormatReaderSource::releaseResources() {}
53 void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
55 if (info.numSamples > 0)
57 const int64 start = nextPlayPos;
59 if (looping)
61 const int64 newStart = start % reader->lengthInSamples;
62 const int64 newEnd = (start + info.numSamples) % reader->lengthInSamples;
64 if (newEnd > newStart)
66 reader->read (info.buffer, info.startSample,
67 (int) (newEnd - newStart), newStart, true, true);
69 else
71 const int endSamps = (int) (reader->lengthInSamples - newStart);
73 reader->read (info.buffer, info.startSample,
74 endSamps, newStart, true, true);
76 reader->read (info.buffer, info.startSample + endSamps,
77 (int) newEnd, 0, true, true);
80 nextPlayPos = newEnd;
82 else
84 reader->read (info.buffer, info.startSample,
85 info.numSamples, start, true, true);
86 nextPlayPos += info.numSamples;
91 } // namespace juce