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

# audiocontainer.h

Go to the documentation of this file.

    00001 /* === S Y N F I G ========================================================= */
    00021 /* ========================================================================= */
    00022
    00023 /* === S T A R T =========================================================== */
    00024
    00025 #ifndef __SYNFIG_AUDIOCONTAINER_H
    00026 #define __SYNFIG_AUDIOCONTAINER_H
    00027
    00028 /* === H E A D E R S ======================================================= */
    00029 #include <sigc++/signal.h>
    00030
    00031 #include <ETL/handle>
    00032
    00033 #include <vector>
    00034 #include <string>
    00035
    00036 #include <synfig/time.h>
    00037
    00038 /* === M A C R O S ========================================================= */
    00039 const float DEF_DISPLAYSAMPLERATE = 400;
    00040 /* === T Y P E D E F S ===================================================== */
    00041
    00042 /* === C L A S S E S & S T R U C T S ======================================= */
    00043
    00044 namespace studio {
    00045
    00046 class AudioContainer;
    00047
    00048 //Note: Might want to abstract something to share data between profile and parent
    00049 class AudioProfile : public etl::shared_object
    00050 {
    00051 public:
    00052     typedef std::vector<char>   SampleProfile;
    00053
    00054 private:
    00055     SampleProfile   samples;
    00056     double          samplerate; //samples / second of the profile
    00057
    00058     //reference our parent for any native sound info
    00059     etl::loose_handle<AudioContainer>   parent;
    00060
    00061 public: //samples interface
    00062
    00063     SampleProfile::const_iterator   begin() const   {return samples.begin();}
    00064     SampleProfile::const_iterator   end() const     {return samples.end();}
    00065
    00066     void clear();
    00067     unsigned int size() const {return samples.size();}
    00068
    00069     char operator[](int i) const
    00070     {
    00071         if(i >= 0 && i < (int)samples.size()) return samples[i];
    00072         else return 0;
    00073     }
    00074
    00075 public: //
    00076
    00077     double get_samplerate() const {return samplerate;}
    00078     void set_samplerate(double f) {samplerate = f;}
    00079
    00080     double get_offset() const;
    00081
    00082     etl::handle<AudioContainer> get_parent() const;
    00083     void set_parent(etl::handle<AudioContainer> i);
    00084     friend class AudioContainer;
    00085 };
    00086
    00087 /*  Audio container actually implements all the cool stuff
    00088     Note: May be a bit too monolithic...
    00089 */
    00090 class AudioContainer : public sigc::trackable, public etl::shared_object
    00091 {
    00092     etl::handle<AudioProfile>   prof;
    00093
    00094     struct  AudioImp;
    00095     AudioImp *imp;
    00096
    00097     bool    profilevalid; //this is only half useful
    00098         //it makes it so we don't always have to realloc memory when the file switches...
    00099
    00100 public: //structors
    00101
    00102     AudioContainer();
    00103     ~AudioContainer();
    00104
    00105 public: //accessor interface
    00106     void set_offset(const double &s);
    00107     double get_offset() const;
    00108
    00109 public: //info gather interface
    00110     etl::handle<AudioProfile>   get_profile(float samplerate = DEF_DISPLAYSAMPLERATE);
    00111     bool get_current_time(double &out);
    00112
    00113 public: //operational interface
    00114     bool load(const std::string &filename, const std::string &filedirectory = "");
    00115     void clear();
    00116
    00117     //play functions...
    00118     void play(double t);
    00119     void stop();
    00120     //Note: this refers to the wrapper concept of the audio, the actual sound may or may not be playing...
    00121     bool is_playing() const;
    00122
    00123     //scrubbing functions...
    00124     void start_scrubbing(double t);
    00125     void stop_scrubbing();
    00126     void scrub(double t);
    00127     bool is_scrubbing() const;
    00128
    00129     double scrub_time() const;
    00130
    00131     bool isRunning() const;
    00132     bool isPaused() const;
    00133 };
    00134
    00135 } // END of namespace studio
    00136
    00137 /* === E N D =============================================================== */
    00138
    00139 #endif