1 /* === S Y N F I G ========================================================= */
2 /*! \file audiocontainer.h
3 ** \brief Sound info header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_AUDIOCONTAINER_H
26 #define __SYNFIG_AUDIOCONTAINER_H
28 /* === H E A D E R S ======================================================= */
29 #include <sigc++/signal.h>
36 #include <synfig/time.h>
38 /* === M A C R O S ========================================================= */
39 const float DEF_DISPLAYSAMPLERATE = 400;
40 /* === T Y P E D E F S ===================================================== */
42 /* === C L A S S E S & S T R U C T S ======================================= */
48 //Note: Might want to abstract something to share data between profile and parent
49 class AudioProfile : public etl::shared_object
52 typedef std::vector<char> SampleProfile;
55 SampleProfile samples;
56 double samplerate; //samples / second of the profile
58 //reference our parent for any native sound info
59 etl::loose_handle<AudioContainer> parent;
61 public: //samples interface
63 SampleProfile::const_iterator begin() const {return samples.begin();}
64 SampleProfile::const_iterator end() const {return samples.end();}
67 unsigned int size() const {return samples.size();}
69 char operator[](int i) const
71 if(i >= 0 && i < (int)samples.size()) return samples[i];
77 double get_samplerate() const {return samplerate;}
78 void set_samplerate(double f) {samplerate = f;}
80 double get_offset() const;
82 etl::handle<AudioContainer> get_parent() const;
83 void set_parent(etl::handle<AudioContainer> i);
84 friend class AudioContainer;
87 /* Audio container actually implements all the cool stuff
88 Note: May be a bit too monolithic...
90 class AudioContainer : public sigc::trackable, public etl::shared_object
92 etl::handle<AudioProfile> prof;
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...
105 public: //accessor interface
106 void set_offset(const double &s);
107 double get_offset() const;
109 public: //info gather interface
110 etl::handle<AudioProfile> get_profile(float samplerate = DEF_DISPLAYSAMPLERATE);
111 bool get_current_time(double &out);
113 public: //operational interface
114 bool load(const std::string &filename, const std::string &filedirectory = "");
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;
123 //scrubbing functions...
124 void start_scrubbing(double t);
125 void stop_scrubbing();
126 void scrub(double t); //!< if we are not currently scrubbing this will not work
127 bool is_scrubbing() const;
129 double scrub_time() const;
131 bool isRunning() const;
132 bool isPaused() const;
135 } // END of namespace studio
137 /* === E N D =============================================================== */