00001 /* 00002 ============================================================================== 00003 00004 This file is part of the JUCE library - "Jules' Utility Class Extensions" 00005 Copyright 2004-7 by Raw Material Software ltd. 00006 00007 ------------------------------------------------------------------------------ 00008 00009 JUCE can be redistributed and/or modified under the terms of the 00010 GNU General Public License, as published by the Free Software Foundation; 00011 either version 2 of the License, or (at your option) any later version. 00012 00013 JUCE is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with JUCE; if not, visit www.gnu.org/licenses or write to the 00020 Free Software Foundation, Inc., 59 Temple Place, Suite 330, 00021 Boston, MA 02111-1307 USA 00022 00023 ------------------------------------------------------------------------------ 00024 00025 If you'd like to release a closed-source product which uses JUCE, commercial 00026 licenses are also available: visit www.rawmaterialsoftware.com/juce for 00027 more information. 00028 00029 ============================================================================== 00030 */ 00031 00032 #ifndef __JUCE_AUDIOTRANSPORTSOURCE_JUCEHEADER__ 00033 #define __JUCE_AUDIOTRANSPORTSOURCE_JUCEHEADER__ 00034 00035 #include "juce_BufferingAudioSource.h" 00036 #include "juce_ResamplingAudioSource.h" 00037 #include "../../events/juce_ChangeBroadcaster.h" 00038 00039 00040 //============================================================================== 00053 class JUCE_API AudioTransportSource : public PositionableAudioSource, 00054 public ChangeBroadcaster 00055 { 00056 public: 00057 //============================================================================== 00062 AudioTransportSource(); 00063 00065 ~AudioTransportSource(); 00066 00067 //============================================================================== 00085 void setSource (PositionableAudioSource* const newSource, 00086 int readAheadBufferSize = 0, 00087 double sourceSampleRateToCorrectFor = 0.0); 00088 00089 //============================================================================== 00097 void setPosition (double newPosition); 00098 00103 double getCurrentPosition() const; 00104 00107 bool hasStreamFinished() const throw() { return inputStreamEOF; } 00108 00109 //============================================================================== 00115 void start(); 00116 00122 void stop(); 00123 00125 bool isPlaying() const throw() { return playing; } 00126 00127 //============================================================================== 00133 void setGain (const float newGain) throw(); 00134 00139 float getGain() const throw() { return gain; } 00140 00141 00142 //============================================================================== 00144 void prepareToPlay (int samplesPerBlockExpected, double sampleRate); 00145 00147 void releaseResources(); 00148 00150 void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill); 00151 00152 //============================================================================== 00154 void setNextReadPosition (int newPosition); 00155 00157 int getNextReadPosition() const; 00158 00160 int getTotalLength() const; 00161 00163 bool isLooping() const; 00164 00165 //============================================================================== 00166 juce_UseDebuggingNewOperator 00167 00168 private: 00169 PositionableAudioSource* source; 00170 ResamplingAudioSource* resamplerSource; 00171 BufferingAudioSource* bufferingSource; 00172 PositionableAudioSource* positionableSource; 00173 AudioSource* masterSource; 00174 00175 CriticalSection callbackLock; 00176 float volatile gain, lastGain; 00177 bool volatile playing, stopped; 00178 double sampleRate, sourceSampleRate; 00179 int blockSize, readAheadBufferSize; 00180 bool isPrepared, inputStreamEOF; 00181 00182 AudioTransportSource (const AudioTransportSource&); 00183 const AudioTransportSource& operator= (const AudioTransportSource&); 00184 }; 00185 00186 00187 #endif // __JUCE_AUDIOTRANSPORTSOURCE_JUCEHEADER__