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"
26 #include <glibmm/fileutils.h>
27 #include <glibmm/miscutils.h>
29 #include "pbd/error.h"
30 #include "pbd/convert.h"
31 #include "pbd/enumwriter.h"
33 #include "ardour/midi_playlist.h"
34 #include "ardour/midi_playlist_source.h"
35 #include "ardour/midi_region.h"
36 #include "ardour/debug.h"
37 #include "ardour/filename_extensions.h"
38 #include "ardour/session.h"
39 #include "ardour/session_directory.h"
40 #include "ardour/session_playlists.h"
41 #include "ardour/source_factory.h"
46 using namespace ARDOUR;
49 MidiPlaylistSource::MidiPlaylistSource (Session& s, const ID& orig, const std::string& name, boost::shared_ptr<MidiPlaylist> p,
50 uint32_t chn, frameoffset_t begin, framecnt_t len, Source::Flag flags)
51 : Source (s, DataType::AUDIO, name)
52 , MidiSource (s, name, flags)
53 , PlaylistSource (s, orig, name, p, DataType::AUDIO, begin, len, flags)
57 MidiPlaylistSource::MidiPlaylistSource (Session& s, const XMLNode& node)
59 , MidiSource (s, node)
60 , PlaylistSource (s, node)
62 /* PlaylistSources are never writable, renameable, removable or destructive */
63 _flags = Flag (_flags & ~(Writable|CanRename|Removable|RemovableIfEmpty|RemoveAtDestroy|Destructive));
65 /* ancestors have already called ::set_state() in their XML-based
69 if (set_state (node, Stateful::loading_state_version, false)) {
70 throw failed_constructor ();
74 MidiPlaylistSource::~MidiPlaylistSource ()
79 MidiPlaylistSource::get_state ()
81 XMLNode& node (MidiSource::get_state ());
83 /* merge PlaylistSource state */
85 PlaylistSource::add_state (node);
92 MidiPlaylistSource::set_state (const XMLNode& node, int version)
94 return set_state (node, version, true);
98 MidiPlaylistSource::set_state (const XMLNode& node, int version, bool with_descendants)
100 if (with_descendants) {
101 if (Source::set_state (node, version) ||
102 MidiSource::set_state (node, version) ||
103 PlaylistSource::set_state (node, version)) {
112 MidiPlaylistSource::length (framepos_t) const
114 pair<framepos_t,framepos_t> extent = _playlist->get_extent();
115 return extent.second - extent.first;
119 MidiPlaylistSource::read_unlocked (Evoral::EventSink<framepos_t>& dst,
121 framepos_t start, framecnt_t cnt,
122 MidiStateTracker* tracker) const
124 boost::shared_ptr<MidiPlaylist> mp = boost::dynamic_pointer_cast<MidiPlaylist> (_playlist);
130 return mp->read (dst, start, cnt);
134 MidiPlaylistSource::write_unlocked (MidiRingBuffer<framepos_t>& dst,
138 fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::write_unlocked() called - should be impossible") << endmsg;
144 MidiPlaylistSource::append_event_unlocked_beats(const Evoral::Event<Evoral::MusicalTime>& /*ev*/)
146 fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::append_event_unlocked_beats() called - should be impossible") << endmsg;
151 MidiPlaylistSource::append_event_unlocked_frames(const Evoral::Event<framepos_t>& ev, framepos_t source_start)
153 fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::append_event_unlocked_frames() called - should be impossible") << endmsg;
158 MidiPlaylistSource::load_model (bool, bool)
160 fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::load_model() called - should be impossible") << endmsg;
165 MidiPlaylistSource::destroy_model ()
167 fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::destroy_model() called - should be impossible") << endmsg;
172 MidiPlaylistSource::flush_midi ()
178 MidiPlaylistSource::empty () const
180 return !_playlist || _playlist->empty();