Move panner bypass state up to the PannerShell so that it is preserved even when...
[ardour2.git] / libs / ardour / midi_playlist_source.cc
blob3b2c8dbb489ec574a1e168fd35b0e877c3b22dcd
1 /*
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.
19 #ifdef WAF_BUILD
20 #include "libardour-config.h"
21 #endif
23 #include <vector>
24 #include <cstdio>
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"
43 #include "i18n.h"
45 using namespace std;
46 using namespace ARDOUR;
47 using namespace PBD;
49 /*******************************************************************************
50 As of May 2011, it appears too complex to support compound regions for MIDI
51 because of the need to be able to edit the data represented by the region. It
52 seems that it would be a better idea to render the consituent regions into a
53 new MIDI file and create a new region based on that, an operation we have been
54 calling "consolidate"
56 This code has been in place as a stub in case anyone gets any brilliant ideas
57 on other ways to approach this issue.
58 ********************************************************************************/
60 MidiPlaylistSource::MidiPlaylistSource (Session& s, const ID& orig, const std::string& name, boost::shared_ptr<MidiPlaylist> p,
61 uint32_t chn, frameoffset_t begin, framecnt_t len, Source::Flag flags)
62 : Source (s, DataType::MIDI, name)
63 , MidiSource (s, name, flags)
64 , PlaylistSource (s, orig, name, p, DataType::MIDI, begin, len, flags)
68 MidiPlaylistSource::MidiPlaylistSource (Session& s, const XMLNode& node)
69 : Source (s, node)
70 , MidiSource (s, node)
71 , PlaylistSource (s, node)
73 /* PlaylistSources are never writable, renameable, removable or destructive */
74 _flags = Flag (_flags & ~(Writable|CanRename|Removable|RemovableIfEmpty|RemoveAtDestroy|Destructive));
76 /* ancestors have already called ::set_state() in their XML-based
77 constructors.
80 if (set_state (node, Stateful::loading_state_version, false)) {
81 throw failed_constructor ();
85 MidiPlaylistSource::~MidiPlaylistSource ()
89 XMLNode&
90 MidiPlaylistSource::get_state ()
92 XMLNode& node (MidiSource::get_state ());
94 /* merge PlaylistSource state */
96 PlaylistSource::add_state (node);
98 return node;
103 MidiPlaylistSource::set_state (const XMLNode& node, int version)
105 return set_state (node, version, true);
109 MidiPlaylistSource::set_state (const XMLNode& node, int version, bool with_descendants)
111 if (with_descendants) {
112 if (Source::set_state (node, version) ||
113 MidiSource::set_state (node, version) ||
114 PlaylistSource::set_state (node, version)) {
115 return -1;
119 return 0;
122 framecnt_t
123 MidiPlaylistSource::length (framepos_t) const
125 pair<framepos_t,framepos_t> extent = _playlist->get_extent();
126 return extent.second - extent.first;
129 framepos_t
130 MidiPlaylistSource::read_unlocked (Evoral::EventSink<framepos_t>& dst,
131 framepos_t position,
132 framepos_t start, framecnt_t cnt,
133 MidiStateTracker* tracker) const
135 boost::shared_ptr<MidiPlaylist> mp = boost::dynamic_pointer_cast<MidiPlaylist> (_playlist);
137 if (!mp) {
138 return 0;
141 return mp->read (dst, start, cnt);
144 framepos_t
145 MidiPlaylistSource::write_unlocked (MidiRingBuffer<framepos_t>& dst,
146 framepos_t position,
147 framecnt_t cnt)
149 fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::write_unlocked() called - should be impossible") << endmsg;
150 /*NOTREACHED*/
151 return 0;
154 void
155 MidiPlaylistSource::append_event_unlocked_beats(const Evoral::Event<Evoral::MusicalTime>& /*ev*/)
157 fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::append_event_unlocked_beats() called - should be impossible") << endmsg;
158 /*NOTREACHED*/
161 void
162 MidiPlaylistSource::append_event_unlocked_frames(const Evoral::Event<framepos_t>& ev, framepos_t source_start)
164 fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::append_event_unlocked_frames() called - should be impossible") << endmsg;
165 /*NOTREACHED*/
168 void
169 MidiPlaylistSource::load_model (bool, bool)
171 /* nothing to do */
174 void
175 MidiPlaylistSource::destroy_model ()
177 /* nothing to do */
180 void
181 MidiPlaylistSource::flush_midi ()
186 bool
187 MidiPlaylistSource::empty () const
189 return !_playlist || _playlist->empty();