Mostly Cosmetic/Design changes to bring trunk and midi branch closer
[ardour.git] / libs / ardour / ardour / midi_region.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_region_h__
21 #define __ardour_midi_region_h__
22
23 #include <vector>
24
25 #include <pbd/fastlog.h>
26 #include <pbd/undo.h>
27
28 #include <ardour/ardour.h>
29 #include <ardour/region.h>
30 #include <ardour/export.h>
31
32 class XMLNode;
33
34 namespace ARDOUR {
35
36 class Route;
37 class Playlist;
38 class Session;
39 class MidiFilter;
40 class MidiSource;
41
42 struct MidiRegionState : public RegionState 
43 {
44     MidiRegionState (std::string why);
45
46 };
47
48 class MidiRegion : public Region
49 {
50   public:
51         typedef vector<MidiSource *> SourceList;
52
53         MidiRegion (MidiSource&, jack_nframes_t start, jack_nframes_t length, bool announce = true);
54         MidiRegion (MidiSource&, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true);
55         MidiRegion (SourceList &, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true);
56         MidiRegion (const MidiRegion&, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true);
57         MidiRegion (const MidiRegion&);
58         MidiRegion (MidiSource&, const XMLNode&);
59         MidiRegion (SourceList &, const XMLNode&);
60         ~MidiRegion();
61
62         bool source_equivalent (const Region&) const;
63
64         bool speed_mismatch (float) const;
65
66         void lock_sources ();
67         void unlock_sources ();
68         MidiSource& source (uint32_t n=0) const { if (n < sources.size()) return *sources[n]; else return *sources[0]; } 
69
70         uint32_t n_channels() { return sources.size(); }
71         vector<string> master_source_names();
72         
73         bool captured() const { return !(_flags & (Region::Flag (Region::Import|Region::External))); }
74
75         virtual jack_nframes_t read_at (unsigned char *buf, unsigned char *mixdown_buffer, 
76                                         char * workbuf, jack_nframes_t position, jack_nframes_t cnt, 
77                                         uint32_t chan_n = 0,
78                                         jack_nframes_t read_frames = 0,
79                                         jack_nframes_t skip_frames = 0) const;
80
81         jack_nframes_t master_read_at (unsigned char *buf, unsigned char *mixdown_buffer, 
82                                        char * workbuf, jack_nframes_t position, jack_nframes_t cnt, uint32_t chan_n=0) const;
83
84
85         XMLNode& state (bool);
86         XMLNode& get_state ();
87         int      set_state (const XMLNode&);
88
89         enum FadeShape {
90                 Linear,
91                 Fast,
92                 Slow,
93                 LogA,
94                 LogB,
95
96         };
97
98         int separate_by_channel (ARDOUR::Session&, vector<MidiRegion*>&) const;
99
100         uint32_t read_data_count() const { return _read_data_count; }
101
102         ARDOUR::Playlist* playlist() const { return _playlist; }
103
104         UndoAction get_memento() const;
105
106         /* export */
107
108         //int exportme (ARDOUR::Session&, ARDOUR::AudioExportSpecification&);
109
110         Region* get_parent();
111
112   private:
113         friend class Playlist;
114
115   private:
116         SourceList        sources;
117         SourceList        master_sources; /* used when timefx are applied, so 
118                                              we can always use the original
119                                              source.
120                                           */
121         StateManager::State* state_factory (std::string why) const;
122         Change restore_state (StateManager::State&);
123
124         jack_nframes_t _read_at (const SourceList&, unsigned char *buf, unsigned char *mixdown_buffer, 
125                                  char * workbuf, jack_nframes_t position, jack_nframes_t cnt, 
126                                  uint32_t chan_n = 0,
127                                  jack_nframes_t read_frames = 0,
128                                  jack_nframes_t skip_frames = 0) const;
129
130         bool verify_start (jack_nframes_t position);
131         bool verify_length (jack_nframes_t position);
132         bool verify_start_mutable (jack_nframes_t& start);
133         bool verify_start_and_length (jack_nframes_t start, jack_nframes_t length);
134
135         void recompute_at_start() {}
136         void recompute_at_end() {}
137
138         void source_deleted (Source*);
139 };
140
141 } /* namespace ARDOUR */
142
143
144 #endif /* __ardour_midi_region_h__ */