libardour added.
[ardour.git] / libs / ardour / ardour / audioplaylist.h
1 /*
2     Copyright (C) 2003 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #ifndef __ardour_audio_playlist_h__
22 #define __ardour_audio_playlist_h__
23
24 #include <vector>
25 #include <list>
26
27 #include <ardour/ardour.h>
28 #include <ardour/playlist.h>
29
30 namespace ARDOUR  {
31
32 class Session;
33 class Region;
34 class AudioRegion;
35 class Source;
36
37 class AudioPlaylist : public ARDOUR::Playlist
38 {
39   public:
40         typedef std::list<Crossfade*> Crossfades;
41
42   private:
43         
44         struct State : public ARDOUR::StateManager::State {
45             RegionList regions;
46             std::list<UndoAction> region_states;
47             
48             Crossfades crossfades;
49             std::list<UndoAction> crossfade_states;
50             
51             State (std::string why) : ARDOUR::StateManager::State (why) {}
52             ~State ();
53         };
54         
55    public:
56         AudioPlaylist (Session&, const XMLNode&, bool hidden = false);
57         AudioPlaylist (Session&, string name, bool hidden = false);
58         AudioPlaylist (const AudioPlaylist&, string name, bool hidden = false);
59         AudioPlaylist (const AudioPlaylist&, jack_nframes_t start, jack_nframes_t cnt, string name, bool hidden = false);
60
61         void clear (bool with_delete = false, bool with_save = true);
62
63         jack_nframes_t read (Sample *dst, Sample *mixdown, float *gain_buffer, jack_nframes_t start, jack_nframes_t cnt, uint32_t chan_n=0);
64
65         int set_state (const XMLNode&);
66         UndoAction get_memento() const;
67
68         sigc::signal<void,Crossfade *> NewCrossfade; 
69
70         template<class T> void foreach_crossfade (T *t, void (T::*func)(Crossfade *));
71         void crossfades_at (jack_nframes_t frame, Crossfades&);
72
73         template<class T> void apply_to_history (T& obj, void (T::*method)(const ARDOUR::StateManager::StateMap&, state_id_t)) {
74                 RegionLock rlock (this);
75                 (obj.*method) (states, _current_state_id);
76         }
77
78         bool destroy_region (Region*);
79
80         void get_equivalent_regions (const AudioRegion&, std::vector<AudioRegion*>&);
81         void get_region_list_equivalent_regions (const AudioRegion&, std::vector<AudioRegion*>&);
82
83         void drop_all_states ();
84
85     protected:
86
87         /* state management */
88
89         StateManager::State* state_factory (std::string) const;
90         Change restore_state (StateManager::State&);
91         void send_state_change (Change);
92
93         /* playlist "callbacks" */
94         void notify_crossfade_added (Crossfade *);
95         void flush_notifications ();
96         
97         void refresh_dependents (Region& region);
98         void check_dependents (Region& region, bool norefresh);
99         void remove_dependents (Region& region);
100
101     protected:
102        ~AudioPlaylist (); /* public should use unref() */
103
104     private:
105        Crossfades      _crossfades;
106        Crossfades      _pending_xfade_adds;
107
108        void crossfade_invalidated (Crossfade*);
109        XMLNode& state (bool full_state);
110        void dump () const;
111
112        bool region_changed (Change, Region*);
113        void crossfade_changed (Change);
114        void add_crossfade (Crossfade&);
115 };
116
117 } /* namespace ARDOUR */
118
119 #endif  /* __ardour_audio_playlist_h__ */
120
121