2 Copyright (C) 2011 Paul Davis
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.
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.
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.
20 #include "libardour-config.h"
23 #include "pbd/error.h"
25 #include "ardour/midi_playlist.h"
26 #include "ardour/midi_playlist_source.h"
31 using namespace ARDOUR;
35 class MidiStateTracker;
37 template <typename T> class MidiRingBuffer;
41 template <typename T> class EventSink;
42 template <typename Time> class Event;
45 /*******************************************************************************
46 As of May 2011, it appears too complex to support compound regions for MIDI
47 because of the need to be able to edit the data represented by the region. It
48 seems that it would be a better idea to render the consituent regions into a
49 new MIDI file and create a new region based on that, an operation we have been
52 This code has been in place as a stub in case anyone gets any brilliant ideas
53 on other ways to approach this issue.
54 ********************************************************************************/
56 MidiPlaylistSource::MidiPlaylistSource (Session& s, const ID& orig, const std::string& name, boost::shared_ptr<MidiPlaylist> p,
57 uint32_t /*chn*/, frameoffset_t begin, framecnt_t len, Source::Flag flags)
58 : Source (s, DataType::MIDI, name)
59 , MidiSource (s, name, flags)
60 , PlaylistSource (s, orig, name, p, DataType::MIDI, begin, len, flags)
64 MidiPlaylistSource::MidiPlaylistSource (Session& s, const XMLNode& node)
66 , MidiSource (s, node)
67 , PlaylistSource (s, node)
69 /* PlaylistSources are never writable, renameable, removable or destructive */
70 _flags = Flag (_flags & ~(Writable|CanRename|Removable|RemovableIfEmpty|RemoveAtDestroy|Destructive));
72 /* ancestors have already called ::set_state() in their XML-based
76 if (set_state (node, Stateful::loading_state_version, false)) {
77 throw failed_constructor ();
81 MidiPlaylistSource::~MidiPlaylistSource ()
86 MidiPlaylistSource::get_state ()
88 XMLNode& node (MidiSource::get_state ());
90 /* merge PlaylistSource state */
92 PlaylistSource::add_state (node);
98 MidiPlaylistSource::set_state (const XMLNode& node, int version)
100 return set_state (node, version, true);
104 MidiPlaylistSource::set_state (const XMLNode& node, int version, bool with_descendants)
106 if (with_descendants) {
107 if (Source::set_state (node, version) ||
108 MidiSource::set_state (node, version) ||
109 PlaylistSource::set_state (node, version)) {
118 MidiPlaylistSource::length (framepos_t) const
120 pair<framepos_t,framepos_t> extent = _playlist->get_extent();
121 return extent.second - extent.first;
125 MidiPlaylistSource::read_unlocked (Evoral::EventSink<framepos_t>& dst,
126 framepos_t /*position*/,
127 framepos_t start, framecnt_t cnt,
128 MidiStateTracker*) const
130 boost::shared_ptr<MidiPlaylist> mp = boost::dynamic_pointer_cast<MidiPlaylist> (_playlist);
136 return mp->read (dst, start, cnt);
140 MidiPlaylistSource::write_unlocked (MidiRingBuffer<framepos_t>&,
144 fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::write_unlocked() called - should be impossible") << endmsg;
150 MidiPlaylistSource::append_event_unlocked_beats(const Evoral::Event<Evoral::MusicalTime>& /*ev*/)
152 fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::append_event_unlocked_beats() called - should be impossible") << endmsg;
157 MidiPlaylistSource::append_event_unlocked_frames(const Evoral::Event<framepos_t>& /* ev */, framepos_t /*source_start*/)
159 fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::append_event_unlocked_frames() called - should be impossible") << endmsg;
164 MidiPlaylistSource::load_model (bool, bool)
170 MidiPlaylistSource::destroy_model ()
176 MidiPlaylistSource::flush_midi ()
182 MidiPlaylistSource::empty () const
184 return !_playlist || _playlist->empty();