Use both internal and external UIs
[juce-lv2.git] / juce / source / src / audio / audio_file_formats / juce_AudioSubsectionReader.cpp
blob476ce0d9311eb1b957003ae08cfaefb066f1851e
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../../core/juce_StandardHeader.h"
28 BEGIN_JUCE_NAMESPACE
30 #include "juce_AudioSubsectionReader.h"
33 //==============================================================================
34 AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
35 const int64 startSample_,
36 const int64 length_,
37 const bool deleteSourceWhenDeleted_)
38 : AudioFormatReader (0, source_->getFormatName()),
39 source (source_),
40 startSample (startSample_),
41 deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
43 length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
45 sampleRate = source->sampleRate;
46 bitsPerSample = source->bitsPerSample;
47 lengthInSamples = length;
48 numChannels = source->numChannels;
49 usesFloatingPointData = source->usesFloatingPointData;
52 AudioSubsectionReader::~AudioSubsectionReader()
54 if (deleteSourceWhenDeleted)
55 delete source;
58 //==============================================================================
59 bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
60 int64 startSampleInFile, int numSamples)
62 if (startSampleInFile + numSamples > length)
64 for (int i = numDestChannels; --i >= 0;)
65 if (destSamples[i] != nullptr)
66 zeromem (destSamples[i], sizeof (int) * numSamples);
68 numSamples = jmin (numSamples, (int) (length - startSampleInFile));
70 if (numSamples <= 0)
71 return true;
74 return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
75 startSampleInFile + startSample, numSamples);
78 void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
79 int64 numSamples,
80 float& lowestLeft,
81 float& highestLeft,
82 float& lowestRight,
83 float& highestRight)
85 startSampleInFile = jmax ((int64) 0, startSampleInFile);
86 numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
88 source->readMaxLevels (startSampleInFile + startSample, numSamples,
89 lowestLeft, highestLeft,
90 lowestRight, highestRight);
93 END_JUCE_NAMESPACE