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 typedef int32_t TrackId; 00032 typedef std::shared_ptr<class Track> TrackRef; 00033 00034 class OutputImpl; 00035 00036 //TODO: add a track 'controller' that talks to tracks through their Output owner 00037 /*class TrackController { 00038 public: 00039 ~TrackController() {} 00040 private: 00041 TrackController( OutputImpl * output, TrackId track ) : mOutput( output ), mTrackId( trackId ) {} 00042 00043 TrackId mTrackId; 00044 OutputImpl * mOutput; 00045 }*/ 00046 00047 class Track { 00048 public: 00049 virtual ~Track() {} 00050 virtual void play() = 0; 00051 virtual void stop() = 0; 00052 virtual bool isPlaying() const = 0; 00053 00054 virtual void setVolume( float aVolume ) = 0; 00055 virtual float getVolume() const = 0; 00056 00057 virtual double getTime() const = 0; 00058 virtual void setTime( double aTime ) = 0; 00059 00060 virtual void setLooping( bool isLooping ) = 0; 00061 virtual bool isLooping() const = 0; 00062 00063 virtual void enablePcmBuffering( bool isBuffering ) = 0; 00064 virtual bool isPcmBuffering() = 0; 00065 virtual PcmBuffer32fRef getPcmBuffer() = 0; 00066 protected: 00067 Track() {} 00068 }; 00069 00070 class OutputImpl { 00071 public: 00072 virtual ~OutputImpl() {} 00073 00074 virtual void play( SourceRef aSource ) { addTrack( aSource, true ); } 00075 virtual TrackRef addTrack( SourceRef aSource, bool autoplay ) = 0; 00076 virtual void removeTrack( TrackId trackId ) = 0; 00077 00078 virtual float getVolume() const = 0; 00079 virtual void setVolume( float aVolume ) = 0; 00080 00081 //virtual TargetRef getTarget() = 0; 00082 protected: 00083 OutputImpl(); 00084 virtual TrackId availableTrackId() { return mNextTrackId++; } 00085 00086 /*void retainTrack( TrackId trackId ) {} 00087 void releaseTrack( TrackId trackId ) {} 00088 void playTrack( TrackId trackId ) {} 00089 void stopTrack( TrackId trackId ) {} 00090 void setTrackVolume( TrackId trackId, float aVolume ) {} 00091 float getTrackVolume( TrackId trackId ) {} 00092 void setTrackTime( TrackId trackId, double aTime ) {} 00093 float getTrackTime( TrackId trackId ) {}*/ 00094 00095 00096 TrackId mNextTrackId; 00097 00098 friend class Track; 00099 //friend class TrackController; 00100 }; 00101 00102 class Output { 00103 public: 00104 static void play( SourceRef aSource ) { instance()->play( aSource ); } 00105 00106 static TrackRef addTrack( SourceRef aSource, bool autoplay = true ) { return instance()->addTrack( aSource, autoplay ); } 00107 static void removeTrack( TrackId trackId ) { instance()->removeTrack( trackId ); } 00108 00109 static float getVolume() { return instance()->getVolume(); } 00110 static void setVolume( float aVolume ) { instance()->setVolume( aVolume ); } 00111 00112 //static TargetRef getTarget() { return instance()->getTarget(); } 00113 private: 00114 static OutputImpl* instance(); 00115 }; 00116 00117 class OutputException : public Exception {}; 00118 class OutOfTracksException : public Exception {}; 00119 00120 00121 00122 }} //namespace