00001
00021
00022
00023
00024
00025 #ifndef __SYNFIG_AUDIOCONTAINER_H
00026 #define __SYNFIG_AUDIOCONTAINER_H
00027
00028
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
00039 const float DEF_DISPLAYSAMPLERATE = 400;
00040
00041
00042
00043
00044 namespace studio {
00045
00046 class AudioContainer;
00047
00048
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;
00057
00058
00059 etl::loose_handle<AudioContainer> parent;
00060
00061 public:
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
00088
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;
00098
00099
00100 public:
00101
00102 AudioContainer();
00103 ~AudioContainer();
00104
00105 public:
00106 void set_offset(const double &s);
00107 double get_offset() const;
00108
00109 public:
00110 etl::handle<AudioProfile> get_profile(float samplerate = DEF_DISPLAYSAMPLERATE);
00111 bool get_current_time(double &out);
00112
00113 public:
00114 bool load(const std::string &filename, const std::string &filedirectory = "");
00115 void clear();
00116
00117
00118 void play(double t);
00119 void stop();
00120
00121 bool is_playing() const;
00122
00123
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 }
00136
00137
00138
00139 #endif