diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index 23a73ccf25..dbe8f7c477 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -263,6 +263,9 @@ class LIBARDOUR_API TriggerBox : public Processor bool can_support_io_configuration (const ChanCount& in, ChanCount& out); bool configure_io (ChanCount in, ChanCount out); + int32_t order() const { return _order; } + void set_order(int32_t n); + typedef std::vector Triggers; Trigger* trigger (Triggers::size_type); @@ -314,6 +317,7 @@ class LIBARDOUR_API TriggerBox : public Processor PBD::RingBuffer _bang_queue; PBD::RingBuffer _unbang_queue; DataType _data_type; + int32_t _order; Glib::Threads::RWLock trigger_lock; /* protects all_triggers */ Triggers all_triggers; PBD::RingBuffer explicit_queue; /* user queued triggers */ diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 63c7ac1772..cb70d32eb4 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -4214,6 +4214,7 @@ Session::reassign_track_numbers () { int64_t tn = 0; int64_t bn = 0; + uint32_t trigger_order = 0; RouteList r (*(routes.reader ())); r.sort (Stripable::Sorter()); @@ -4223,10 +4224,15 @@ Session::reassign_track_numbers () assert (!(*i)->is_auditioner()); if (boost::dynamic_pointer_cast (*i)) { (*i)->set_track_number(++tn); - } - else if (!(*i)->is_master() && !(*i)->is_monitor()) { + } else if (!(*i)->is_master() && !(*i)->is_monitor()) { (*i)->set_track_number(--bn); } + + boost::shared_ptr tb = (*i)->triggerbox(); + if (tb) { + tb->set_order (trigger_order); + trigger_order++; + } } const uint32_t decimals = ceilf (log10f (tn + 1)); const bool decimals_changed = _track_number_decimals != decimals; diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index c6c7f50c81..6173c56838 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -929,6 +929,7 @@ TriggerBox::TriggerBox (Session& s, DataType dt) , _bang_queue (1024) , _unbang_queue (1024) , _data_type (dt) + , _order (-1) , explicit_queue (64) , implicit_queue (64) , currently_playing (0) @@ -965,6 +966,12 @@ TriggerBox::clear_implicit () implicit_queue.reset (); } +void +TriggerBox::set_order (int32_t n) +{ + _order = n; +} + void TriggerBox::queue_explict (Trigger* t) { @@ -1188,15 +1195,24 @@ TriggerBox::set_first_midi_note (int n) int TriggerBox::note_to_trigger (int midi_note, int channel) { - Stripable* s = dynamic_cast (owner()); - const int column = s->presentation_info().order(); + const int column = _order; int first_note; + int top; switch (_midi_map_mode) { case AbletonPush: - first_note = 92 + column; - return (midi_note - first_note) / 8; /* gives row index */ + /* the top row of pads generate MIDI note 92, 93, 94 and so on. + Each lower row generates notes 8 below the one above it. + */ + top = 92 + column; + for (int row = 0; row < 8; ++row) { + if (midi_note == top - (row * 8)) { + return row; + } + } + return -1; + break; case SequentialNote: first_note = _first_midi_note - (column * all_triggers.size()); @@ -1230,6 +1246,8 @@ TriggerBox::process_midi_trigger_requests (BufferSet& bufs) int trigger_number = note_to_trigger ((*ev).note(), (*ev).channel()); + DEBUG_TRACE (DEBUG::Triggers, string_compose ("note %1 received on %2, translated to trigger num %3\n", (int) (*ev).note(), (int) (*ev).channel(), trigger_number)); + if (trigger_number < 0) { /* not for us */ continue; @@ -1648,6 +1666,7 @@ TriggerBox::get_state (void) node.set_property (X_("type"), X_("triggerbox")); node.set_property (X_("data-type"), _data_type.to_string()); + node.set_property (X_("order"), _order); XMLNode* trigger_child (new XMLNode (X_("Triggers"))); @@ -1676,6 +1695,7 @@ int TriggerBox::set_state (const XMLNode& node, int version) { node.get_property (X_("data-type"), _data_type); + node.get_property (X_("order"), _order); XMLNode* tnode (node.child (X_("Triggers"))); assert (tnode);