# Cinder

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# include/cinder/audio/Output.h

Go to the documentation of this file.

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