From 98335084c70707cbbd07ac5a7248c0998412d815 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 17 Jun 2016 00:15:55 -0400 Subject: [PATCH] turn on all buttons that be envisaged as useful in ardour (for now); add support for edit-range-from-playhead ops --- libs/surfaces/push2/buttons.cc | 32 ++++++++++++++++ libs/surfaces/push2/push2.cc | 70 +++++++++++++++++++++++++--------- libs/surfaces/push2/push2.h | 13 +++++-- 3 files changed, 92 insertions(+), 23 deletions(-) diff --git a/libs/surfaces/push2/buttons.cc b/libs/surfaces/push2/buttons.cc index 803f1e5ed9..016cd78a17 100644 --- a/libs/surfaces/push2/buttons.cc +++ b/libs/surfaces/push2/buttons.cc @@ -61,3 +61,35 @@ Push2::button_solo () { cancel_all_solo (); } + +void +Push2::button_new () +{ + access_action ("Editor/start-range-from-playhead"); + + id_button_map[New]->set_color (LED::White); + id_button_map[New]->set_state (LED::NoTransition); + write (id_button_map[New]->state_msg()); + + /* blink the button for the other half of this operation */ + + id_button_map[FixedLength]->set_color (LED::White); + id_button_map[FixedLength]->set_state (LED::Blinking4th); + write (id_button_map[FixedLength]->state_msg()); +} + + +void +Push2::button_fixed_length () +{ + access_action ("Editor/finish-range-from-playhead"); + + /* turn off both buttons for this operation */ + + id_button_map[New]->set_color (LED::Black); + id_button_map[New]->set_state (LED::NoTransition); + write (id_button_map[New]->state_msg()); + id_button_map[FixedLength]->set_color (LED::Black); + id_button_map[FixedLength]->set_state (LED::NoTransition); + write (id_button_map[FixedLength]->state_msg()); +} diff --git a/libs/surfaces/push2/push2.cc b/libs/surfaces/push2/push2.cc index fe033a8076..e83f393ff5 100644 --- a/libs/surfaces/push2/push2.cc +++ b/libs/surfaces/push2/push2.cc @@ -82,11 +82,12 @@ Push2::Push2 (ARDOUR::Session& s) mid_layout[n]->set_text (string_compose ("Inst %1", n)); } + build_maps (); + if (open ()) { throw failed_constructor (); } - build_maps (); } Push2::~Push2 () @@ -166,6 +167,23 @@ Push2::close () return 0; } +void +Push2::init_buttons () +{ + ButtonID buttons[] = { Mute, Solo, Master, Up, Right, Left, Down, Note, Session, Mix, AddTrack, Delete, Undo, + Metronome, Shift, Select, Play, RecordEnable, Automate, Repeat, Note, Session, DoubleLoop, + Quantize, Duplicate, + }; + + for (size_t n = 0; n < sizeof (buttons) / sizeof (buttons[0]); ++n) { + Button* b = id_button_map[buttons[n]]; + + b->set_color (LED::White); + b->set_state (LED::OneShot24th); + write (b->state_msg()); + } +} + bool Push2::probe () { @@ -325,7 +343,7 @@ Push2::redraw () context->move_to (650, 25); tc_clock_layout->update_from_cairo_context (context); tc_clock_layout->show_in_cairo_context (context); - context->move_to (650, 60); + context->move_to (650, 60); bbt_clock_layout->update_from_cairo_context (context); bbt_clock_layout->show_in_cairo_context (context); @@ -423,6 +441,8 @@ Push2::set_active (bool yn) periodic_connection = periodic_timeout->connect (sigc::mem_fun (*this, &Push2::periodic)); periodic_timeout->attach (main_loop()->get_context()); + init_buttons (); + } else { stop (); @@ -635,6 +655,7 @@ Push2::build_maps () MAKE_COLOR_BUTTON (Lower5, 25); MAKE_COLOR_BUTTON (Lower6, 26); MAKE_COLOR_BUTTON (Lower7, 27); + MAKE_COLOR_BUTTON (Master, 28); MAKE_COLOR_BUTTON (Mute, 60); MAKE_COLOR_BUTTON_PRESS (Solo, 61, &Push2::button_solo); MAKE_COLOR_BUTTON (Stop, 29); @@ -674,8 +695,8 @@ Push2::build_maps () MAKE_WHITE_BUTTON (DoubleLoop, 117); MAKE_WHITE_BUTTON (Quantize, 116); MAKE_WHITE_BUTTON (Duplicate, 88); - MAKE_WHITE_BUTTON (New, 87); - MAKE_WHITE_BUTTON (FixedLength, 90); + MAKE_WHITE_BUTTON_PRESS (New, 87, &Push2::button_new); + MAKE_WHITE_BUTTON_PRESS (FixedLength, 90, &Push2::button_fixed_length); MAKE_WHITE_BUTTON_PRESS (Up, 46, &Push2::button_up); MAKE_WHITE_BUTTON_PRESS (Right, 45, &Push2::button_right); MAKE_WHITE_BUTTON_PRESS (Down, 47, &Push2::button_down); @@ -684,6 +705,9 @@ Push2::build_maps () MAKE_WHITE_BUTTON (Accent, 57); MAKE_WHITE_BUTTON (Scale, 58); MAKE_WHITE_BUTTON (Layout, 31); + MAKE_WHITE_BUTTON (Note, 50); + MAKE_WHITE_BUTTON (Session, 51); + MAKE_WHITE_BUTTON (Layout, 31); MAKE_WHITE_BUTTON (OctaveUp, 55); MAKE_WHITE_BUTTON (PageRight, 63); MAKE_WHITE_BUTTON (OctaveDown, 54); @@ -739,16 +763,17 @@ Push2::notify_record_state_changed () return; } - b->second->set_color (LED::Red); - switch (session->record_status ()) { case Session::Disabled: - b->second->set_state (LED::Off); + b->second->set_color (LED::White); + b->second->set_state (LED::NoTransition); break; case Session::Enabled: + b->second->set_color (LED::Red); b->second->set_state (LED::Blinking4th); break; case Session::Recording: + b->second->set_color (LED::Red); b->second->set_state (LED::OneShot24th); break; } @@ -759,20 +784,25 @@ Push2::notify_record_state_changed () void Push2::notify_transport_state_changed () { - IDButtonMap::iterator b = id_button_map.find (Play); - - if (b == id_button_map.end()) { - return; - } + Button* b = id_button_map[Play]; if (session->transport_rolling()) { - b->second->set_state (LED::OneShot24th); - b->second->set_color (LED::Green); + b->set_state (LED::OneShot24th); + b->set_color (LED::Green); } else { - b->second->set_state (LED::Off); + + /* disable any blink on FixedLength from pending edit range op */ + Button* fl = id_button_map[FixedLength]; + + fl->set_color (LED::Black); + fl->set_state (LED::NoTransition); + write (fl->state_msg()); + + b->set_color (LED::White); + b->set_state (LED::NoTransition); } - write (b->second->state_msg()); + write (b->state_msg()); } void @@ -793,7 +823,8 @@ Push2::notify_parameter_changed (std::string param) b->second->set_state (LED::Blinking4th); b->second->set_color (LED::White); } else { - b->second->set_state (LED::Off); + b->second->set_color (LED::White); + b->second->set_state (LED::NoTransition); } write (b->second->state_msg ()); } @@ -802,7 +833,7 @@ Push2::notify_parameter_changed (std::string param) void Push2::notify_solo_active_changed (bool yn) { - IDButtonMap::iterator b = id_button_map.find (Solo); + IDButtonMap::iterator b = id_button_map.find (Solo); if (b == id_button_map.end()) { return; @@ -812,7 +843,8 @@ Push2::notify_solo_active_changed (bool yn) b->second->set_state (LED::Blinking4th); b->second->set_color (LED::Red); } else { - b->second->set_state (LED::Off); + b->second->set_state (LED::NoTransition); + b->second->set_color (LED::White); } write (b->second->state_msg()); diff --git a/libs/surfaces/push2/push2.h b/libs/surfaces/push2/push2.h index c50452fc65..2ec73779d4 100644 --- a/libs/surfaces/push2/push2.h +++ b/libs/surfaces/push2/push2.h @@ -155,7 +155,7 @@ class Push2 : public ARDOUR::ControlProtocol struct LED { enum State { - Off, + NoTransition, OneShot24th, OneShot16th, OneShot8th, @@ -174,6 +174,7 @@ class Push2 : public ARDOUR::ControlProtocol }; enum Colors { + Black = 0, Red = 127, Green = 126, Blue = 125, @@ -182,7 +183,7 @@ class Push2 : public ARDOUR::ControlProtocol White = 122 }; - LED (uint8_t e) : _extra (e), _color_index (0), _state (Off) {} + LED (uint8_t e) : _extra (e), _color_index (0), _state (NoTransition) {} virtual ~LED() {} uint8_t extra () const { return _extra; } @@ -206,7 +207,7 @@ class Push2 : public ARDOUR::ControlProtocol , x (xx) , y (yy) {} - MidiByteArray state_msg () const { return MidiByteArray (3, 0x90|_state, _extra, (_state == Off) ? 0 : _color_index); } + MidiByteArray state_msg () const { return MidiByteArray (3, 0x90|_state, _extra, _color_index); } int coord () const { return (y * 8) + x; } int note_number() const { return extra(); } @@ -237,7 +238,7 @@ class Push2 : public ARDOUR::ControlProtocol , release_method (release) {} - MidiByteArray state_msg () const { return MidiByteArray (3, 0xb0|_state, _extra, (_state == Off) ? 0 : _color_index); } + MidiByteArray state_msg () const { return MidiByteArray (3, 0xb0|_state, _extra, _color_index); } int controller_number() const { return extra(); } ButtonID id; @@ -277,6 +278,8 @@ class Push2 : public ARDOUR::ControlProtocol typedef std::map IDButtonMap; IDButtonMap id_button_map; + void init_buttons (); + /* map of Pads by note number */ typedef std::map NNPadMap; NNPadMap nn_pad_map; @@ -332,6 +335,8 @@ class Push2 : public ARDOUR::ControlProtocol void button_metronome (); void button_repeat (); void button_solo (); + void button_fixed_length (); + void button_new (); /* widgets */ -- 2.30.2