Clean up MidiPlaylist::read, kill copy-paste code.
[ardour.git] / libs / ardour / ardour / midi_playlist.h
1 /*
2     Copyright (C) 2006 Paul Davis
3     Author: David Robillard
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 #include "evoral/Parameter.hpp"
29
30 namespace Evoral {
31 template<typename Time> class EventSink;
32 }
33
34 namespace ARDOUR
35 {
36
37 class Session;
38 class MidiRegion;
39 class Source;
40 class MidiStateTracker;
41
42 template<typename T> class MidiRingBuffer;
43
44 class LIBARDOUR_API MidiPlaylist : public ARDOUR::Playlist
45 {
46 public:
47         MidiPlaylist (Session&, const XMLNode&, bool hidden = false);
48         MidiPlaylist (Session&, std::string name, bool hidden = false);
49         MidiPlaylist (boost::shared_ptr<const MidiPlaylist> other, std::string name, bool hidden = false);
50
51         /** This constructor does NOT notify others (session) */
52         MidiPlaylist (boost::shared_ptr<const MidiPlaylist> other,
53                       framepos_t                            start,
54                       framecnt_t                            cnt,
55                       std::string                           name,
56                       bool                                  hidden = false);
57
58         ~MidiPlaylist ();
59
60         /** Read a range from the playlist into an event sink.
61          *
62          * @param buf Destination for events.
63          * @param start First frame of read range.
64          * @param cnt Number of frames in read range.
65          * @param chan_n Must be 0 (this is the audio-style "channel", where each
66          * channel is backed by a separate region, not MIDI channels, which all
67          * exist in the same region and are not handled here).
68          * @return The number of frames read (time, not an event count).
69          */
70         framecnt_t read (Evoral::EventSink<framepos_t>& buf,
71                          framepos_t                     start,
72                          framecnt_t                     cnt,
73                          uint32_t                       chan_n = 0);
74
75         int set_state (const XMLNode&, int version);
76
77         bool destroy_region (boost::shared_ptr<Region>);
78
79         void set_note_mode (NoteMode m) { _note_mode = m; }
80
81         std::set<Evoral::Parameter> contained_automation();
82
83         /** Clear all note trackers. */
84         void reset_note_trackers ();
85
86         /** Resolve all pending notes and clear all note trackers.
87          *
88          * @param dst Sink to write note offs to.
89          * @param time Time stamp of all written note offs.
90          */
91         void resolve_note_trackers (Evoral::EventSink<framepos_t>& dst, framepos_t time);
92
93 protected:
94
95         void remove_dependents (boost::shared_ptr<Region> region);
96
97 private:
98         void dump () const;
99
100         bool region_changed (const PBD::PropertyChange&, boost::shared_ptr<Region>);
101
102         NoteMode _note_mode;
103
104         typedef std::map<Region*,MidiStateTracker*> NoteTrackers;
105         NoteTrackers _note_trackers;
106 };
107
108 } /* namespace ARDOUR */
109
110 #endif  /* __ardour_midi_playlist_h__ */
111
112