synfig-studio  1.0.3
audiocontainer.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
21 /* ========================================================================= */
22 
23 /* === S T A R T =========================================================== */
24 
25 #ifndef __SYNFIG_AUDIOCONTAINER_H
26 #define __SYNFIG_AUDIOCONTAINER_H
27 
28 /* === H E A D E R S ======================================================= */
29 #include <sigc++/signal.h>
30 
31 #include <ETL/handle>
32 
33 #include <vector>
34 #include <string>
35 
36 #include <synfig/time.h>
37 
38 /* === M A C R O S ========================================================= */
39 const float DEF_DISPLAYSAMPLERATE = 400;
40 /* === T Y P E D E F S ===================================================== */
41 
42 /* === C L A S S E S & S T R U C T S ======================================= */
43 
44 namespace studio {
45 
46 class AudioContainer;
47 
48 //Note: Might want to abstract something to share data between profile and parent
49 class AudioProfile : public etl::shared_object
50 {
51 public:
52  typedef std::vector<char> SampleProfile;
53 
54 private:
55  SampleProfile samples;
56  double samplerate; //samples / second of the profile
57 
58  //reference our parent for any native sound info
59  etl::loose_handle<AudioContainer> parent;
60 
61 public: //samples interface
62 
63  SampleProfile::const_iterator begin() const {return samples.begin();}
64  SampleProfile::const_iterator end() const {return samples.end();}
65 
66  void clear();
67  unsigned int size() const {return samples.size();}
68 
69  char operator[](int i) const
70  {
71  if(i >= 0 && i < (int)samples.size()) return samples[i];
72  else return 0;
73  }
74 
75 public: //
76 
77  double get_samplerate() const {return samplerate;}
78  void set_samplerate(double f) {samplerate = f;}
79 
80  double get_offset() const;
81 
82  etl::handle<AudioContainer> get_parent() const;
83  void set_parent(etl::handle<AudioContainer> i);
84  friend class AudioContainer;
85 };
86 
87 /* Audio container actually implements all the cool stuff
88  Note: May be a bit too monolithic...
89 */
90 class AudioContainer : public sigc::trackable, public etl::shared_object
91 {
92  etl::handle<AudioProfile> prof;
93 
94  struct AudioImp;
95  AudioImp *imp;
96 
97  bool profilevalid; //this is only half useful
98  //it makes it so we don't always have to realloc memory when the file switches...
99 
100 public: //structors
101 
102  AudioContainer();
103  ~AudioContainer();
104 
105 public: //accessor interface
106  void set_offset(const double &s);
107  double get_offset() const;
108 
109 public: //info gather interface
110  etl::handle<AudioProfile> get_profile(float samplerate = DEF_DISPLAYSAMPLERATE);
111  bool get_current_time(double &out);
112 
113 public: //operational interface
114  bool load(const std::string &filename, const std::string &filedirectory = "");
115  void clear();
116 
117  //play functions...
118  void play(double t);
119  void stop();
120  //Note: this refers to the wrapper concept of the audio, the actual sound may or may not be playing...
121  bool is_playing() const;
122 
123  //scrubbing functions...
124  void start_scrubbing(double t);
125  void stop_scrubbing();
126  void scrub(double t);
127  bool is_scrubbing() const;
128 
129  double scrub_time() const;
130 
131  bool isRunning() const;
132  bool isPaused() const;
133 };
134 
135 } // END of namespace studio
136 
137 /* === E N D =============================================================== */
138 
139 #endif