00001 /* 00002 Copyright (c) 2009, The Barbarian Group 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that 00006 the following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, this list of conditions and 00009 the following disclaimer. 00010 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 00011 the following disclaimer in the documentation and/or other materials provided with the distribution. 00012 00013 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 00014 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00015 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00016 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00017 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00018 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00019 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00020 POSSIBILITY OF SUCH DAMAGE. 00021 */ 00022 00023 #pragma once 00024 00025 #include "cinder/Cinder.h" 00026 #include "cinder/audio/Io.h" 00027 #include "cinder/Exception.h" 00028 00029 namespace cinder { namespace audio { 00030 00031 class Track; 00032 00033 typedef int32_t TrackId; 00034 typedef std::shared_ptr<class cinder::audio::Track> TrackRef; 00035 00036 class OutputImpl; 00037 00038 //TODO: add a track 'controller' that talks to tracks through their Output owner 00039 /*class TrackController { 00040 public: 00041 ~TrackController() {} 00042 private: 00043 TrackController( OutputImpl * output, TrackId track ) : mOutput( output ), mTrackId( trackId ) {} 00044 00045 TrackId mTrackId; 00046 OutputImpl * mOutput; 00047 }*/ 00048 00049 class Track { 00050 public: 00051 virtual ~Track() {} 00052 virtual void play() = 0; 00053 virtual void stop() = 0; 00054 virtual bool isPlaying() const = 0; 00055 00056 virtual void setVolume( float aVolume ) = 0; 00057 virtual float getVolume() const = 0; 00058 00059 virtual double getTime() const = 0; 00060 virtual void setTime( double aTime ) = 0; 00061 00062 virtual void setLooping( bool isLooping ) = 0; 00063 virtual bool isLooping() const = 0; 00064 00065 virtual void enablePcmBuffering( bool isBuffering ) = 0; 00066 virtual bool isPcmBuffering() = 0; 00067 virtual PcmBuffer32fRef getPcmBuffer() = 0; 00068 protected: 00069 Track() {} 00070 }; 00071 00072 class OutputImpl { 00073 public: 00074 virtual ~OutputImpl() {} 00075 00076 virtual void play( SourceRef aSource ) { addTrack( aSource, true ); } 00077 virtual TrackRef addTrack( SourceRef aSource, bool autoplay ) = 0; 00078 virtual void removeTrack( TrackId trackId ) = 0; 00079 00080 virtual float getVolume() const = 0; 00081 virtual void setVolume( float aVolume ) = 0; 00082 00083 //virtual TargetRef getTarget() = 0; 00084 protected: 00085 OutputImpl(); 00086 virtual TrackId availableTrackId() { return mNextTrackId++; } 00087 00088 /*void retainTrack( TrackId trackId ) {} 00089 void releaseTrack( TrackId trackId ) {} 00090 void playTrack( TrackId trackId ) {} 00091 void stopTrack( TrackId trackId ) {} 00092 void setTrackVolume( TrackId trackId, float aVolume ) {} 00093 float getTrackVolume( TrackId trackId ) {} 00094 void setTrackTime( TrackId trackId, double aTime ) {} 00095 float getTrackTime( TrackId trackId ) {}*/ 00096 00097 00098 TrackId mNextTrackId; 00099 00100 friend class Track; 00101 //friend class TrackController; 00102 }; 00103 00104 class Output { 00105 public: 00106 static void play( SourceRef aSource ) { instance()->play( aSource ); } 00107 00108 static TrackRef addTrack( SourceRef aSource, bool autoplay = true ) { return instance()->addTrack( aSource, autoplay ); } 00109 static void removeTrack( TrackId trackId ) { instance()->removeTrack( trackId ); } 00110 00111 static float getVolume() { return instance()->getVolume(); } 00112 static void setVolume( float aVolume ) { instance()->setVolume( aVolume ); } 00113 00114 //static TargetRef getTarget() { return instance()->getTarget(); } 00115 private: 00116 static OutputImpl* instance(); 00117 }; 00118 00119 class OutputException : public Exception {}; 00120 class OutOfTracksException : public Exception {}; 00121 00122 00123 00124 }} //namespace