2 * Copyright (C) 2006-2016 David Robillard <d@drobilla.net>
3 * Copyright (C) 2007-2017 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
5 * Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
6 * Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef __ardour_midi_playlist_h__
24 #define __ardour_midi_playlist_h__
29 #include <boost/utility.hpp>
31 #include "ardour/ardour.h"
32 #include "ardour/midi_cursor.h"
33 #include "ardour/midi_model.h"
34 #include "ardour/midi_state_tracker.h"
35 #include "ardour/note_fixer.h"
36 #include "ardour/playlist.h"
37 #include "evoral/Note.hpp"
38 #include "evoral/Parameter.hpp"
39 #include "ardour/rt_midibuffer.h"
42 template<typename Time> class EventSink;
49 class BeatsSamplesConverter;
50 class MidiChannelFilter;
55 template<typename T> class MidiRingBuffer;
57 class LIBARDOUR_API MidiPlaylist : public ARDOUR::Playlist
60 MidiPlaylist (Session&, const XMLNode&, bool hidden = false);
61 MidiPlaylist (Session&, std::string name, bool hidden = false);
62 MidiPlaylist (boost::shared_ptr<const MidiPlaylist> other, std::string name, bool hidden = false);
64 /** This constructor does NOT notify others (session) */
65 MidiPlaylist (boost::shared_ptr<const MidiPlaylist> other,
73 /** Read a range from the playlist into an event sink.
75 * @param buf Destination for events.
76 * @param start First sample of read range.
77 * @param cnt Number of samples in read range.
78 * @param loop_range If non-null, all event times will be mapped into this loop range.
79 * @param chan_n Must be 0 (this is the audio-style "channel", where each
80 * channel is backed by a separate region, not MIDI channels, which all
81 * exist in the same region and are not handled here).
82 * @param filter Channel filter to apply or NULL to disable filter
83 * @return The number of samples read (time, not an event count).
85 samplecnt_t read (Evoral::EventSink<samplepos_t>& buf,
88 Evoral::Range<samplepos_t>* loop_range,
90 MidiChannelFilter* filter = NULL);
92 void render (MidiChannelFilter*);
93 RTMidiBuffer* rendered();
95 int set_state (const XMLNode&, int version);
97 bool destroy_region (boost::shared_ptr<Region>);
98 void _split_region (boost::shared_ptr<Region>, const MusicSample& position);
100 void set_note_mode (NoteMode m) { _note_mode = m; }
102 std::set<Evoral::Parameter> contained_automation();
104 /** Clear all note trackers. */
105 void reset_note_trackers ();
107 /** Resolve all pending notes and clear all note trackers.
109 * @param dst Sink to write note offs to.
110 * @param time Time stamp of all written note offs.
112 void resolve_note_trackers (Evoral::EventSink<samplepos_t>& dst, samplepos_t time);
115 void remove_dependents (boost::shared_ptr<Region> region);
116 void region_going_away (boost::weak_ptr<Region> region);
119 typedef Evoral::Note<Temporal::Beats> Note;
120 typedef Evoral::Event<samplepos_t> Event;
122 struct RegionTracker : public boost::noncopyable {
123 MidiCursor cursor; ///< Cursor (iterator and read state)
124 MidiStateTracker tracker; ///< Active note tracker
125 NoteFixer fixer; ///< Edit compensation
128 typedef std::map< Region*, boost::shared_ptr<RegionTracker> > NoteTrackers;
132 NoteTrackers _note_trackers;
134 samplepos_t _read_end;
136 RTMidiBuffer _rendered;
139 } /* namespace ARDOUR */
141 #endif /* __ardour_midi_playlist_h__ */