ardour
midi_playlist_source.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 Paul Davis
3 
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.
8 
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.
13 
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.
17 */
18 
19 #ifdef WAF_BUILD
20 #include "libardour-config.h"
21 #endif
22 
23 #include "pbd/error.h"
24 
25 #include "ardour/midi_playlist.h"
27 
28 #include "i18n.h"
29 
30 using namespace std;
31 using namespace ARDOUR;
32 using namespace PBD;
33 
34 namespace ARDOUR {
35 class MidiStateTracker;
36 class Session;
37 template <typename T> class MidiRingBuffer;
38 }
39 
40 namespace Evoral {
41 template <typename T> class EventSink;
42 template <typename Time> class Event;
43 }
44 
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
50 calling "consolidate"
51 
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 ********************************************************************************/
55 
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)
61 {
62 }
63 
65  : Source (s, node)
66  , MidiSource (s, node)
67  , PlaylistSource (s, node)
68 {
69  /* PlaylistSources are never writable, renameable, removable or destructive */
71 
72  /* ancestors have already called ::set_state() in their XML-based
73  constructors.
74  */
75 
76  if (set_state (node, Stateful::loading_state_version, false)) {
77  throw failed_constructor ();
78  }
79 }
80 
82 {
83 }
84 
85 XMLNode&
87 {
88  XMLNode& node (MidiSource::get_state ());
89 
90  /* merge PlaylistSource state */
91 
93 
94  return node;
95 }
96 
97 int
98 MidiPlaylistSource::set_state (const XMLNode& node, int version)
99 {
100  return set_state (node, version, true);
101 }
102 
103 int
104 MidiPlaylistSource::set_state (const XMLNode& node, int version, bool with_descendants)
105 {
106  if (with_descendants) {
107  if (Source::set_state (node, version) ||
108  MidiSource::set_state (node, version) ||
109  PlaylistSource::set_state (node, version)) {
110  return -1;
111  }
112  }
113 
114  return 0;
115 }
116 
119 {
120  pair<framepos_t,framepos_t> extent = _playlist->get_extent();
121  return extent.second - extent.first;
122 }
123 
127  framepos_t /*position*/,
130  MidiChannelFilter*) const
131 {
133 
134  if (!mp) {
135  return 0;
136  }
137 
138  return mp->read (dst, start, cnt);
139 }
140 
144  framepos_t,
145  framecnt_t)
146 {
147  fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::write_unlocked() called - should be impossible") << endmsg;
148  abort(); /*NOTREACHED*/
149  return 0;
150 }
151 
152 void
154 {
155  fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::append_event_beats() called - should be impossible") << endmsg;
156  abort(); /*NOTREACHED*/
157 }
158 
159 void
161 {
162  fatal << string_compose (_("programming error: %1"), "MidiPlaylistSource::append_event_frames() called - should be impossible") << endmsg;
163  abort(); /*NOTREACHED*/
164 }
165 
166 void
168 {
169  /* nothing to do */
170 }
171 
172 void
174 {
175  /* nothing to do */
176 }
177 
178 void
180 {
181 }
182 
183 
184 bool
186 {
187  return !_playlist || _playlist->empty();
188 }
189 
Flag _flags
Definition: source.h:119
framecnt_t length(framepos_t) const
LIBPBD_API Transmitter fatal
int set_state(const XMLNode &, int version)
Glib::Threads::Mutex::Lock Lock
Definition: source.h:54
XMLNode & get_state()
Definition: midi_source.cc:90
framecnt_t read(Evoral::EventSink< framepos_t > &buf, framepos_t start, framecnt_t cnt, uint32_t chan_n=0, MidiChannelFilter *filter=NULL)
void load_model(const Glib::Threads::Mutex::Lock &lock, bool force_reload=false)
shared_ptr< T > dynamic_pointer_cast(shared_ptr< U > const &r)
Definition: shared_ptr.hpp:396
void flush_midi(const Lock &lock)
Definition: Beats.hpp:239
std::ostream & endmsg(std::ostream &ostr)
Definition: transmitter.h:71
framecnt_t read_unlocked(Sample *dst, framepos_t start, framecnt_t cnt) const
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
Definition: region.cc:63
void append_event_frames(const Glib::Threads::Mutex::Lock &lock, const Evoral::Event< framepos_t > &ev, framepos_t source_start)
Definition: id.h:32
#define _(Text)
Definition: i18n.h:11
boost::shared_ptr< Playlist > _playlist
int64_t framecnt_t
Definition: types.h:76
Definition: amp.h:29
void add_state(XMLNode &)
int64_t framepos_t
Definition: types.h:66
int64_t frameoffset_t
Definition: types.h:71
static int loading_state_version
Definition: stateful.h:90
void destroy_model(const Glib::Threads::Mutex::Lock &lock)
const char * name
Definition: xml++.h:95
Definition: debug.h:30
int set_state(const XMLNode &, int version)
Definition: midi_source.cc:114
int set_state(const XMLNode &, int version)
Definition: source.cc:113
Definition: ardour.h:41
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208
std::pair< framepos_t, framepos_t > get_extent() const
Definition: playlist.cc:2254
int set_state(const XMLNode &, int version)
MidiPlaylistSource(Session &, const PBD::ID &orig, const std::string &name, boost::shared_ptr< MidiPlaylist >, uint32_t chn, frameoffset_t begin, framecnt_t len, Source::Flag flags)
framecnt_t write_unlocked(Sample *src, framecnt_t cnt)
bool empty() const
Definition: playlist.cc:2230
void append_event_beats(const Glib::Threads::Mutex::Lock &lock, const Evoral::Event< Evoral::Beats > &ev)