diff options
Diffstat (limited to 'libs/ardour')
-rw-r--r-- | libs/ardour/ardour/midi_model.h | 7 | ||||
-rw-r--r-- | libs/ardour/ardour/midi_source.h | 13 | ||||
-rw-r--r-- | libs/ardour/ardour/smf_source.h | 2 | ||||
-rw-r--r-- | libs/ardour/automatable.cc | 2 | ||||
-rw-r--r-- | libs/ardour/midi_model.cc | 62 | ||||
-rw-r--r-- | libs/ardour/midi_source.cc | 77 | ||||
-rw-r--r-- | libs/ardour/midi_stretch.cc | 7 | ||||
-rw-r--r-- | libs/ardour/route.cc | 2 | ||||
-rw-r--r-- | libs/ardour/smf_source.cc | 18 |
9 files changed, 161 insertions, 29 deletions
diff --git a/libs/ardour/ardour/midi_model.h b/libs/ardour/ardour/midi_model.h index 4e348af287..a8303539b5 100644 --- a/libs/ardour/ardour/midi_model.h +++ b/libs/ardour/ardour/midi_model.h @@ -148,6 +148,8 @@ public: InsertMergePolicy insert_merge_policy () const; void set_insert_merge_policy (InsertMergePolicy); + boost::shared_ptr<Evoral::Control> control_factory(const Evoral::Parameter& id); + protected: int resolve_overlaps_unlocked (const NotePtr, void* arg = 0); @@ -170,6 +172,11 @@ public: private: friend class DeltaCommand; + void source_interpolation_changed (Evoral::Parameter, Evoral::ControlList::InterpolationStyle); + void control_list_interpolation_changed (Evoral::Parameter, Evoral::ControlList::InterpolationStyle); + + PBD::ScopedConnectionList _midi_source_connections; + // We cannot use a boost::shared_ptr here to avoid a retain cycle MidiSource* _midi_source; InsertMergePolicy _insert_merge_policy; diff --git a/libs/ardour/ardour/midi_source.h b/libs/ardour/ardour/midi_source.h index 0d0b744a95..8d20f9c7b6 100644 --- a/libs/ardour/ardour/midi_source.h +++ b/libs/ardour/ardour/midi_source.h @@ -117,8 +117,15 @@ class MidiSource : virtual public Source void set_model (boost::shared_ptr<MidiModel>); void drop_model(); + Evoral::ControlList::InterpolationStyle interpolation_of (Evoral::Parameter) const; + void set_interpolation_of (Evoral::Parameter, Evoral::ControlList::InterpolationStyle); + void copy_interpolation_from (boost::shared_ptr<MidiSource>); + void copy_interpolation_from (MidiSource *); + /** Emitted when a different MidiModel is set */ PBD::Signal0<void> ModelChanged; + /** Emitted when a parameter's interpolation style is changed */ + PBD::Signal2<void, Evoral::Parameter, Evoral::ControlList::InterpolationStyle> InterpolationChanged; protected: virtual void flush_midi() = 0; @@ -146,6 +153,12 @@ class MidiSource : virtual public Source mutable double _length_beats; mutable sframes_t _last_read_end; sframes_t _last_write_end; + + /** Map of interpolation styles to use for Parameters; if they are not in this map, + * the correct interpolation style can be obtained from EventTypeMap::interpolation_of () + */ + typedef std::map<Evoral::Parameter, Evoral::ControlList::InterpolationStyle> InterpolationStyleMap; + InterpolationStyleMap _interpolation_style; }; } diff --git a/libs/ardour/ardour/smf_source.h b/libs/ardour/ardour/smf_source.h index d271cb0dba..6dcea9dd60 100644 --- a/libs/ardour/ardour/smf_source.h +++ b/libs/ardour/ardour/smf_source.h @@ -82,8 +82,6 @@ private: sframes_t position, nframes_t cnt); - void set_default_controls_interpolation (); - double _last_ev_time_beats; sframes_t _last_ev_time_frames; /** end time (start + duration) of last call to read_unlocked */ diff --git a/libs/ardour/automatable.cc b/libs/ardour/automatable.cc index bed99d5660..40b6eb2a07 100644 --- a/libs/ardour/automatable.cc +++ b/libs/ardour/automatable.cc @@ -58,7 +58,7 @@ Automatable::Automatable (const Automatable& other) for (Controls::const_iterator i = other._controls.begin(); i != other._controls.end(); ++i) { boost::shared_ptr<Evoral::Control> ac (control_factory (i->first)); - _controls[ac->parameter()] = ac; + add_control (ac); } } int diff --git a/libs/ardour/midi_model.cc b/libs/ardour/midi_model.cc index 6e2c477a99..b5d5d24713 100644 --- a/libs/ardour/midi_model.cc +++ b/libs/ardour/midi_model.cc @@ -41,8 +41,9 @@ using namespace PBD; MidiModel::MidiModel(MidiSource* s) : AutomatableSequence<TimeType>(s->session()) - , _midi_source(s) + , _midi_source (0) { + set_midi_source (s); } /** Start a new Diff command. @@ -761,6 +762,9 @@ MidiModel::DiffCommand::get_state () * user can switch a recorded track (with note durations from some instrument) * to percussive, save, reload, then switch it back to sustained without * destroying the original note durations. + * + * Similarly, control events are written without interpolation (as with the + * `Discrete' mode). */ bool MidiModel::write_to (boost::shared_ptr<MidiSource> source) @@ -773,7 +777,7 @@ MidiModel::write_to (boost::shared_ptr<MidiSource> source) source->drop_model(); source->mark_streaming_midi_write_started(note_mode(), _midi_source->timeline_position()); - for (Evoral::Sequence<TimeType>::const_iterator i = begin(); i != end(); ++i) { + for (Evoral::Sequence<TimeType>::const_iterator i = begin(0, true); i != end(); ++i) { source->append_event_unlocked_beats(*i); } @@ -800,7 +804,7 @@ MidiModel::sync_to_source () _midi_source->mark_streaming_midi_write_started(note_mode(), _midi_source->timeline_position()); - for (Evoral::Sequence<TimeType>::const_iterator i = begin(); i != end(); ++i) { + for (Evoral::Sequence<TimeType>::const_iterator i = begin(0, true); i != end(); ++i) { _midi_source->append_event_unlocked_beats(*i); } @@ -832,7 +836,7 @@ MidiModel::write_section_to (boost::shared_ptr<MidiSource> source, Evoral::Music source->drop_model(); source->mark_streaming_midi_write_started(note_mode(), _midi_source->timeline_position()); - for (Evoral::Sequence<TimeType>::const_iterator i = begin(); i != end(); ++i) { + for (Evoral::Sequence<TimeType>::const_iterator i = begin(0, true); i != end(); ++i) { const Evoral::Event<Evoral::MusicalTime>& ev (*i); if (ev.time() >= begin_time && ev.time() < end_time) { @@ -1138,6 +1142,54 @@ MidiModel::insert_merge_policy () const void MidiModel::set_midi_source (MidiSource* s) { - _midi_source->invalidate (); + if (_midi_source) { + _midi_source->invalidate (); + } + + _midi_source_connections.drop_connections (); + _midi_source = s; + + _midi_source->InterpolationChanged.connect_same_thread ( + _midi_source_connections, boost::bind (&MidiModel::source_interpolation_changed, this, _1, _2) + ); +} + +/** The source has signalled that the interpolation style for a parameter has changed. In order to + * keep MidiSource and ControlList interpolation state the same, we pass this change onto the + * appropriate ControlList. + * + * The idea is that MidiSource and the MidiModel's ControlList states are kept in sync, and the + * MidiSource's InterpolationChanged signal is listened to by the GUI. + */ +void +MidiModel::source_interpolation_changed (Evoral::Parameter p, Evoral::ControlList::InterpolationStyle s) +{ + Glib::Mutex::Lock lm (_control_lock); + control(p)->list()->set_interpolation (s); +} + +/** A ControlList has signalled that its interpolation style has changed. Again, in order to keep + * MidiSource and ControlList interpolation state in sync, we pass this change onto our MidiSource. + */ +void +MidiModel::control_list_interpolation_changed (Evoral::Parameter p, Evoral::ControlList::InterpolationStyle s) +{ + _midi_source->set_interpolation_of (p, s); +} + +boost::shared_ptr<Evoral::Control> +MidiModel::control_factory (Evoral::Parameter const & p) +{ + boost::shared_ptr<Evoral::Control> c = Automatable::control_factory (p); + + /* Set up newly created control's lists to the appropriate interpolation state + from our source. + */ + + assert (_midi_source); + + c->list()->set_interpolation (_midi_source->interpolation_of (p)); + + return c; } diff --git a/libs/ardour/midi_source.cc b/libs/ardour/midi_source.cc index 3f831b348d..dbc41c8ab6 100644 --- a/libs/ardour/midi_source.cc +++ b/libs/ardour/midi_source.cc @@ -97,6 +97,12 @@ MidiSource::get_state () node.add_property ("captured-for", _captured_for); } + for (InterpolationStyleMap::const_iterator i = _interpolation_style.begin(); i != _interpolation_style.end(); ++i) { + XMLNode* child = node.add_child (X_("InterpolationStyle")); + child->add_property (X_("parameter"), EventTypeMap::instance().to_symbol (i->first)); + child->add_property (X_("style"), enum_2_string (i->second)); + } + return node; } @@ -109,6 +115,28 @@ MidiSource::set_state (const XMLNode& node, int /*version*/) _captured_for = prop->value(); } + XMLNodeList children = node.children (); + for (XMLNodeConstIterator i = children.begin(); i != children.end(); ++i) { + if ((*i)->name() == X_("InterpolationStyle")) { + XMLProperty* prop; + + if ((prop = (*i)->property (X_("parameter"))) == 0) { + error << _("Missing parameter property on InterpolationStyle") << endmsg; + return -1; + } + + Evoral::Parameter p = EventTypeMap::instance().new_parameter (prop->value()); + + if ((prop = (*i)->property (X_("style"))) == 0) { + error << _("Missing style property on InterpolationStyle") << endmsg; + return -1; + } + + Evoral::ControlList::InterpolationStyle s = static_cast<Evoral::ControlList::InterpolationStyle> (string_2_enum (prop->value(), s)); + set_interpolation_of (p, s); + } + } + return 0; } @@ -160,7 +188,7 @@ MidiSource::midi_read (Evoral::EventSink<nframes_t>& dst, sframes_t source_start // If the cached iterator is invalid, search for the first event past start if (_last_read_end == 0 || start != _last_read_end || !_model_iter_valid) { DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("*** %1 search for relevant iterator for %1 / %2\n", _name, source_start, start)); - for (i = _model->begin(0, filtered); i != _model->end(); ++i) { + for (i = _model->begin(0, false, filtered); i != _model->end(); ++i) { if (converter.to(i->time()) >= start) { break; } @@ -260,6 +288,7 @@ MidiSource::clone (Evoral::MusicalTime begin, Evoral::MusicalTime end) newpath, false, _session.frame_rate())); newsrc->set_timeline_position(_timeline_position); + newsrc->copy_interpolation_from (this); if (_model) { if (begin == Evoral::MinMusicalTime && end == Evoral::MaxMusicalTime) { @@ -344,3 +373,49 @@ MidiSource::set_model (boost::shared_ptr<MidiModel> m) _model = m; ModelChanged (); /* EMIT SIGNAL */ } + +/** @return Interpolation style that should be used for control parameter \a p */ +Evoral::ControlList::InterpolationStyle +MidiSource::interpolation_of (Evoral::Parameter p) const +{ + InterpolationStyleMap::const_iterator i = _interpolation_style.find (p); + if (i == _interpolation_style.end()) { + return EventTypeMap::instance().interpolation_of (p); + } + + return i->second; +} + +/** Set interpolation style to be used for a given parameter. This change will be + * propagated to anyone who needs to know. + */ +void +MidiSource::set_interpolation_of (Evoral::Parameter p, Evoral::ControlList::InterpolationStyle s) +{ + if (interpolation_of (p) == s) { + return; + } + + if (EventTypeMap::instance().interpolation_of (p) == s) { + /* interpolation type is being set to the default, so we don't need a note in our map */ + _interpolation_style.erase (p); + } else { + _interpolation_style[p] = s; + } + + InterpolationChanged (p, s); /* EMIT SIGNAL */ +} + +void +MidiSource::copy_interpolation_from (boost::shared_ptr<MidiSource> s) +{ + copy_interpolation_from (s.get ()); +} + +void +MidiSource::copy_interpolation_from (MidiSource* s) +{ + _interpolation_style = s->_interpolation_style; + + /* XXX: should probably emit signals here */ +} diff --git a/libs/ardour/midi_stretch.cc b/libs/ardour/midi_stretch.cc index 585e0a07b2..21b5453da4 100644 --- a/libs/ardour/midi_stretch.cc +++ b/libs/ardour/midi_stretch.cc @@ -90,7 +90,10 @@ MidiStretch::run (boost::shared_ptr<Region> r) boost::shared_ptr<MidiModel> new_model = new_src->model(); new_model->start_write(); - for (Evoral::Sequence<MidiModel::TimeType>::const_iterator i = old_model->begin(); + /* Note: pass true into force_discrete for the begin() iterator so that the model doesn't + * do interpolation of controller data when we stretch. + */ + for (Evoral::Sequence<MidiModel::TimeType>::const_iterator i = old_model->begin (0, true); i != old_model->end(); ++i) { const double new_time = i->time() * _request.time_fraction; @@ -103,6 +106,8 @@ MidiStretch::run (boost::shared_ptr<Region> r) new_model->end_write(); new_model->set_edited(true); + new_src->copy_interpolation_from (src); + const int ret = finish (region, nsrcs, new_name); results[0]->set_length((nframes_t) floor (r->length() * _request.time_fraction), NULL); diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index e7f5e28b94..e8ddf678c9 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -109,7 +109,7 @@ Route::init () _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle)); _mute_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle)); - + add_control (_solo_control); add_control (_mute_control); diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index fe5a0f7c8f..bbdf958815 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -257,10 +257,6 @@ SMFSource::write_unlocked (MidiRingBuffer<nframes_t>& source, sframes_t position append_event_unlocked_frames(ev, position); } - if (_model) { - set_default_controls_interpolation(); - } - Evoral::SMF::flush(); free(buf); @@ -471,8 +467,6 @@ SMFSource::load_model (bool lock, bool force_reload) _length_beats = max(_length_beats, ev.time()); } - set_default_controls_interpolation(); - _model->end_write(false); _model->set_edited(false); @@ -482,18 +476,6 @@ SMFSource::load_model (bool lock, bool force_reload) } void -SMFSource::set_default_controls_interpolation () -{ - // set interpolation style to defaults, can be changed by the GUI later - Evoral::ControlSet::Controls controls = _model->controls(); - for (Evoral::ControlSet::Controls::iterator c = controls.begin(); c != controls.end(); ++c) { - (*c).second->list()->set_interpolation( - EventTypeMap::instance().interpolation_of((*c).first)); - } -} - - -void SMFSource::destroy_model () { //cerr << _name << " destroying model " << _model.get() << endl; |