initial version
[synfig.git] / synfig-studio / trunk / src / gtkmm / audiocontainer.h
1 /* === S I N F G =========================================================== */
2 /*!     \file audiocontainer.h
3 **      \brief Sound info header
4 **
5 **      $Id: audiocontainer.h,v 1.1.1.1 2005/01/07 03:34:35 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SINFG_AUDIOCONTAINER_H
25 #define __SINFG_AUDIOCONTAINER_H
26
27 /* === H E A D E R S ======================================================= */
28 #include <sigc++/signal.h>
29
30 #include <ETL/handle>
31
32 #include <vector>
33 #include <string>
34
35 #include <sinfg/time.h>
36
37 /* === M A C R O S ========================================================= */
38 const float DEF_DISPLAYSAMPLERATE = 400;
39 /* === T Y P E D E F S ===================================================== */
40
41 /* === C L A S S E S & S T R U C T S ======================================= */
42
43 namespace studio {
44
45 class AudioContainer;
46
47 //Note: Might want to abstract something to share data between profile and parent
48 class AudioProfile : public etl::shared_object
49 {
50 public:
51         typedef std::vector<char>       SampleProfile;
52         
53 private:
54         SampleProfile   samples;
55         double                  samplerate; //samples / second of the profile
56
57         //reference our parent for any native sound info
58         etl::loose_handle<AudioContainer>       parent;
59
60 public: //samples interface
61
62         SampleProfile::const_iterator   begin() const   {return samples.begin();}
63         SampleProfile::const_iterator   end() const     {return samples.end();}
64         
65         void clear();
66         unsigned int size() const {return samples.size();}
67         
68         char operator[](int i) const
69         {
70                 if(i >= 0 && i < (int)samples.size()) return samples[i];
71                 else return 0;
72         }
73         
74 public: //
75         
76         double get_samplerate() const {return samplerate;}
77         void set_samplerate(double f) {samplerate = f;}
78         
79         double get_offset() const;
80         
81         etl::handle<AudioContainer>     get_parent() const;
82         void set_parent(etl::handle<AudioContainer> i);
83         friend class AudioContainer;
84 };
85
86 /*      Audio container actually implements all the cool stuff
87         Note: May be a bit to monolithic...
88 */
89 class AudioContainer : public sigc::trackable, public etl::shared_object
90 {
91         etl::handle<AudioProfile>       prof;
92         
93         struct  AudioImp;
94         AudioImp *imp;
95         
96         bool    profilevalid; //this is only half useful 
97                 //it makes it so we don't always have to realloc memory when the file switches...
98         
99 public: //structors
100
101         AudioContainer();
102         ~AudioContainer();
103
104 public: //accessor interface
105         void set_offset(const double &s);
106         double get_offset() const;
107
108 public: //info gather interface
109         etl::handle<AudioProfile>       get_profile(float samplerate = DEF_DISPLAYSAMPLERATE);
110         bool get_current_time(double &out);
111
112 public: //operational interface
113         bool load(const std::string &filename, const std::string &filedirectory = "");
114         void clear();
115
116         //play functions...
117         void play(double t);
118         void stop();
119         //Note: this refers to the wrapper concept of the audio, the actual sound may or may not be playing...
120         bool is_playing() const;
121         
122         //scrubbing functions...
123         void start_scrubbing(double t);
124         void stop_scrubbing();
125         void scrub(double t); //!< if we are not currently scrubbing this will not work
126         bool is_scrubbing() const;
127
128         double scrub_time() const;
129
130         bool isRunning() const;
131         bool isPaused() const;
132 };
133         
134 } // END of namespace studio
135
136 /* === E N D =============================================================== */
137
138 #endif