X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fmidi_region.cc;h=e29fb1e65979c77f6407f323fd857fb2c077ea1b;hb=e55e3fde7cec89c49e01046a2db276b2d8f30958;hp=78c238233e031fa2fcc6070a4958e91eceb96bb3;hpb=2a52135c663e9a60b5f0cc9cc6673799c3ea5549;p=ardour.git diff --git a/libs/ardour/midi_region.cc b/libs/ardour/midi_region.cc index 78c238233e..e29fb1e659 100644 --- a/libs/ardour/midi_region.cc +++ b/libs/ardour/midi_region.cc @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -52,6 +53,7 @@ MidiRegion::MidiRegion (boost::shared_ptr src, nframes_t start, nfra : Region (src, start, length, PBD::basename_nosuffix(src->name()), DataType::MIDI, 0, Region::Flag(Region::DefaultFlags|Region::External)) { assert(_name.find("/") == string::npos); + midi_source(0)->Switched.connect(sigc::mem_fun(this, &MidiRegion::switch_source)); } /* Basic MidiRegion constructor (one channel) */ @@ -59,13 +61,15 @@ MidiRegion::MidiRegion (boost::shared_ptr src, nframes_t start, nfra : Region (src, start, length, name, DataType::MIDI, layer, flags) { assert(_name.find("/") == string::npos); + midi_source(0)->Switched.connect(sigc::mem_fun(this, &MidiRegion::switch_source)); } /* Basic MidiRegion constructor (many channels) */ -MidiRegion::MidiRegion (SourceList& srcs, nframes_t start, nframes_t length, const string& name, layer_t layer, Flag flags) +MidiRegion::MidiRegion (const SourceList& srcs, nframes_t start, nframes_t length, const string& name, layer_t layer, Flag flags) : Region (srcs, start, length, name, DataType::MIDI, layer, flags) { assert(_name.find("/") == string::npos); + midi_source(0)->Switched.connect(sigc::mem_fun(this, &MidiRegion::switch_source)); } @@ -74,12 +78,14 @@ MidiRegion::MidiRegion (boost::shared_ptr other, nframes_t off : Region (other, offset, length, name, layer, flags) { assert(_name.find("/") == string::npos); + midi_source(0)->Switched.connect(sigc::mem_fun(this, &MidiRegion::switch_source)); } MidiRegion::MidiRegion (boost::shared_ptr other) : Region (other) { assert(_name.find("/") == string::npos); + midi_source(0)->Switched.connect(sigc::mem_fun(this, &MidiRegion::switch_source)); } MidiRegion::MidiRegion (boost::shared_ptr src, const XMLNode& node) @@ -89,17 +95,19 @@ MidiRegion::MidiRegion (boost::shared_ptr src, const XMLNode& node) throw failed_constructor(); } + midi_source(0)->Switched.connect(sigc::mem_fun(this, &MidiRegion::switch_source)); assert(_name.find("/") == string::npos); assert(_type == DataType::MIDI); } -MidiRegion::MidiRegion (SourceList& srcs, const XMLNode& node) +MidiRegion::MidiRegion (const SourceList& srcs, const XMLNode& node) : Region (srcs, node) { if (set_state (node)) { throw failed_constructor(); } + midi_source(0)->Switched.connect(sigc::mem_fun(this, &MidiRegion::switch_source)); assert(_name.find("/") == string::npos); assert(_type == DataType::MIDI); } @@ -109,26 +117,22 @@ MidiRegion::~MidiRegion () } nframes_t -MidiRegion::read_at (MidiRingBuffer& out, nframes_t position, - nframes_t dur, - uint32_t chan_n, nframes_t read_frames, nframes_t skip_frames) const +MidiRegion::read_at (MidiRingBuffer& out, nframes_t position, nframes_t dur, uint32_t chan_n, NoteMode mode) const { - return _read_at (_sources, out, position, dur, chan_n, read_frames, skip_frames); + return _read_at (_sources, out, position, dur, chan_n, mode); } nframes_t -MidiRegion::master_read_at (MidiRingBuffer& out, nframes_t position, - nframes_t dur, uint32_t chan_n) const +MidiRegion::master_read_at (MidiRingBuffer& out, nframes_t position, nframes_t dur, uint32_t chan_n, NoteMode mode) const { - return _read_at (_master_sources, out, position, dur, chan_n, 0, 0); + return _read_at (_master_sources, out, position, dur, chan_n, mode); } nframes_t -MidiRegion::_read_at (const SourceList& srcs, MidiRingBuffer& dst, - nframes_t position, nframes_t dur, - uint32_t chan_n, nframes_t read_frames, nframes_t skip_frames) const +MidiRegion::_read_at (const SourceList& srcs, MidiRingBuffer& dst, nframes_t position, nframes_t dur, uint32_t chan_n, NoteMode mode) const { - // cerr << _name << "._read_at(" << position << ") - " << _position << endl; + /*cerr << "MidiRegion " << _name << "._read_at(" << position << ") - " + << position << " duration: " << dur << endl;*/ nframes_t internal_offset = 0; nframes_t src_offset = 0; @@ -166,11 +170,35 @@ MidiRegion::_read_at (const SourceList& srcs, MidiRingBuffer& dst, _read_data_count = 0; boost::shared_ptr src = midi_source(chan_n); - if (src->read (dst, _start + internal_offset, to_read, _position) != to_read) { + src->set_note_mode(mode); + + nframes_t output_buffer_position = 0; + nframes_t negative_output_buffer_position = 0; + if (_position >= _start) { + // handle resizing of beginnings of regions correctly + output_buffer_position = _position - _start; + } else { + // when _start is greater than _position, we have to subtract + // _start from the note times in the midi source + negative_output_buffer_position = _start; + } + + if (src->midi_read ( + // the destination buffer + dst, + // where to start reading in the region + _start + internal_offset, + // how many bytes + to_read, + // the offset in the output buffer + output_buffer_position, + // what to substract from note times written in the output buffer + negative_output_buffer_position + ) != to_read) { return 0; /* "read nothing" */ } - _read_data_count += src->read_data_count(); // FIXME: semantics? + _read_data_count += src->read_data_count(); return to_read; } @@ -179,27 +207,24 @@ XMLNode& MidiRegion::state (bool full) { XMLNode& node (Region::state (full)); - XMLNode *child; char buf[64]; char buf2[64]; LocaleGuard lg (X_("POSIX")); - snprintf (buf, sizeof (buf), "0x%x", (int) _flags); - node.add_property ("flags", buf); + node.add_property ("flags", enum_2_string (_flags)); + // XXX these should move into Region + for (uint32_t n=0; n < _sources.size(); ++n) { snprintf (buf2, sizeof(buf2), "source-%d", n); _sources[n]->id().print (buf, sizeof(buf)); node.add_property (buf2, buf); } - snprintf (buf, sizeof (buf), "%u", (uint32_t) _sources.size()); - node.add_property ("channels", buf); - - child = node.add_child ("Envelope"); - - if ( ! full) { - child->add_property ("default", "yes"); + for (uint32_t n=0; n < _master_sources.size(); ++n) { + snprintf (buf2, sizeof(buf2), "master-source-%d", n); + _master_sources[n]->id().print (buf, sizeof (buf)); + node.add_property (buf2, buf); } if (full && _extra_xml) { @@ -210,32 +235,52 @@ MidiRegion::state (bool full) } int -MidiRegion::set_state (const XMLNode& node) +MidiRegion::set_live_state (const XMLNode& node, Change& what_changed, bool send) { - const XMLNodeList& nlist = node.children(); const XMLProperty *prop; LocaleGuard lg (X_("POSIX")); - Region::set_state (node); + Region::set_live_state (node, what_changed, false); + uint32_t old_flags = _flags; + if ((prop = node.property ("flags")) != 0) { - _flags = Flag (strtol (prop->value().c_str(), (char **) 0, 16)); + _flags = Flag (string_2_enum (prop->value(), _flags)); + + //_flags = Flag (strtol (prop->value().c_str(), (char **) 0, 16)); + + _flags = Flag (_flags & ~Region::LeftOfSplit); + _flags = Flag (_flags & ~Region::RightOfSplit); } - /* Now find child items */ - for (XMLNodeConstIterator niter = nlist.begin(); niter != nlist.end(); ++niter) { - - XMLNode *child; - //XMLProperty *prop; - - child = (*niter); - - /** Hello, children */ + if ((old_flags ^ _flags) & Muted) { + what_changed = Change (what_changed|MuteChanged); + } + if ((old_flags ^ _flags) & Opaque) { + what_changed = Change (what_changed|OpacityChanged); + } + if ((old_flags ^ _flags) & Locked) { + what_changed = Change (what_changed|LockChanged); + } + + if (send) { + send_change (what_changed); } return 0; } +int +MidiRegion::set_state (const XMLNode& node) +{ + /* Region::set_state() calls the virtual set_live_state(), + which will get us back to AudioRegion::set_live_state() + to handle the relevant stuff. + */ + + return Region::set_state (node); +} + void MidiRegion::recompute_at_end () { @@ -288,6 +333,12 @@ MidiRegion::separate_by_channel (Session& session, vector& v) const return -1; } +int +MidiRegion::exportme (ARDOUR::Session&, ARDOUR::ExportSpecification&) +{ + return -1; +} + boost::shared_ptr MidiRegion::midi_source (uint32_t n) const { @@ -295,3 +346,18 @@ MidiRegion::midi_source (uint32_t n) const return boost::dynamic_pointer_cast(source(n)); } + +void +MidiRegion::switch_source(boost::shared_ptr src) +{ + boost::shared_ptr msrc = boost::dynamic_pointer_cast(src); + if (!msrc) + return; + + // MIDI regions have only one source + _sources.clear(); + _sources.push_back(msrc); + + set_name(msrc->name()); +} +