diff --git a/libs/surfaces/cc121/cc121.cc b/libs/surfaces/cc121/cc121.cc index 7c4f757eaf..afae36d524 100644 --- a/libs/surfaces/cc121/cc121.cc +++ b/libs/surfaces/cc121/cc121.cc @@ -388,46 +388,54 @@ CC121::encoder_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb) { DEBUG_TRACE (DEBUG::CC121, "encoder handler"); + boost::shared_ptr r = boost::dynamic_pointer_cast (_current_stripable); /* Extract absolute value*/ float adj = static_cast(tb->value & ~0x40); - /* Get direction (negative values start at 0x40)*/ float sign = (tb->value & 0x40) ? -1.0 : 1.0; + + /* Get amount of change (encoder clicks) * (change per click) + * Create an exponential curve + */ + float curve = sign * powf (adj, (1.f + 10.f) / 10.f); + adj = curve * (31.f / 1000.f); + switch(tb->controller_number) { case 0x10: /* pan */ - DEBUG_TRACE (DEBUG::CC121, "PAN encoder"); - if (_current_stripable) { - /* Get amount of change (encoder clicks) * (change per click)*/ - /*Create an exponential curve*/ - float curve = sign * powf (adj, (1.f + 10.f) / 10.f); - adj = curve * (31.f / 1000.f); - ardour_pan_azimuth (adj); - } + if (r) { set_controllable (r->pan_azimuth_control(), adj); } break; case 0x20: /* EQ 1 Q */ + if (r) { set_controllable (r->eq_q_controllable(0), adj); } break; case 0x21: /* EQ 2 Q */ + if (r) { set_controllable (r->eq_q_controllable(1), adj); } break; case 0x22: /* EQ 3 Q */ + if (r) { set_controllable (r->eq_q_controllable(2), adj); } break; case 0x23: /* EQ 4 Q */ + if (r) { set_controllable (r->eq_q_controllable(3), adj); } break; case 0x30: /* EQ 1 Frequency */ + if (r) { set_controllable (r->eq_freq_controllable(0), adj); } break; case 0x31: /* EQ 2 Frequency */ + if (r) { set_controllable (r->eq_freq_controllable(1), adj); } break; case 0x32: /* EQ 3 Frequency */ + if (r) { set_controllable (r->eq_freq_controllable(2), adj); } break; case 0x33: /* EQ 4 Frequency */ + if (r) { set_controllable (r->eq_freq_controllable(3), adj); } break; case 0x3C: /* AI */ @@ -450,15 +458,19 @@ CC121::encoder_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb) break; case 0x40: /* EQ 1 Gain */ + if (r) { set_controllable (r->eq_gain_controllable(0), adj); } break; case 0x41: /* EQ 2 Gain */ + if (r) { set_controllable (r->eq_gain_controllable(1), adj); } break; case 0x42: /* EQ 3 Gain */ + if (r) { set_controllable (r->eq_gain_controllable(2), adj); } break; case 0x43: /* EQ 4 Gain */ + if (r) { set_controllable (r->eq_gain_controllable(3), adj); } break; case 0x50: /* Value */ diff --git a/libs/surfaces/cc121/cc121.h b/libs/surfaces/cc121/cc121.h index ee9a3a5ccd..7c5bd39170 100644 --- a/libs/surfaces/cc121/cc121.h +++ b/libs/surfaces/cc121/cc121.h @@ -329,9 +329,7 @@ class CC121 : public ARDOUR::ControlProtocol, public AbstractUI { void jog (); void rec_enable (); - void ardour_pan_azimuth (float); - void ardour_pan_width (float); - void mixbus_pan (float); + void set_controllable (boost::shared_ptr, float); void punch (); }; diff --git a/libs/surfaces/cc121/operations.cc b/libs/surfaces/cc121/operations.cc index 67aafda777..f66f4fd2c8 100644 --- a/libs/surfaces/cc121/operations.cc +++ b/libs/surfaces/cc121/operations.cc @@ -246,93 +246,18 @@ CC121::use_monitor () } void -CC121::ardour_pan_azimuth (float delta) +CC121::set_controllable (boost::shared_ptr ac, float delta) { - if (!_current_stripable) { + if (!ac || delta == 0) { return; } - - boost::shared_ptr r = boost::dynamic_pointer_cast (_current_stripable); - - if (!r) { - return; - } - - boost::shared_ptr pannable = r->pannable (); - - if (!pannable) { - return; - } - - boost::shared_ptr azimuth = pannable->pan_azimuth_control; - - if (!azimuth) { - return; - } - - azimuth->set_value (azimuth->interface_to_internal (azimuth->internal_to_interface (azimuth->get_value()) + (delta)), Controllable::NoGroup); + ac->start_touch (ac->session().transport_sample()); + double v = ac->internal_to_interface (ac->get_value()); + v = std::max (0.0, std::min (1.0, v + delta)); + ac->set_value (ac->interface_to_internal(v), PBD::Controllable::NoGroup); } -void -CC121::ardour_pan_width(float delta) -{ - if (!_current_stripable) { - return; - } - - boost::shared_ptr r = boost::dynamic_pointer_cast (_current_stripable); - - if (!r) { - return; - } - - boost::shared_ptr pannable = r->pannable (); - - if (!pannable) { - return; - } - - boost::shared_ptr width = pannable->pan_width_control; - - if (!width) { - return; - } - - width->set_value (width->interface_to_internal (width->internal_to_interface (width->get_value()) + (delta)), Controllable::NoGroup); -} - -void -CC121::mixbus_pan (float delta) -{ -#ifdef MIXBUS - if (!_current_stripable) { - return; - } - boost::shared_ptr r = boost::dynamic_pointer_cast (_current_stripable); - - if (!r) { - return; - } - - - const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h - boost::shared_ptr plug = r->ch_post(); - - if (!plug) { - return; - } - - boost::shared_ptr azimuth = boost::dynamic_pointer_cast (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan))); - - if (!azimuth) { - return; - } - - azimuth->set_value (azimuth->interface_to_internal (azimuth->internal_to_interface (azimuth->get_value()) + (delta)), Controllable::NoGroup); -#endif -} - void CC121::punch () {