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