merge with master, primarily for adrian's maximise-mixer change
[ardour.git] / libs / surfaces / mackie / mcp_buttons.cc
index 5999220c5250c111eb7c318f8dd6a1bda20a5172..792813bf33d9798691d6d8b799a68eb94627235b 100644 (file)
@@ -17,6 +17,8 @@
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#include <algorithm>
+
 #include "pbd/memento_command.h"
 
 #include "ardour/debug.h"
@@ -27,6 +29,7 @@
 
 #include "mackie_control_protocol.h"
 #include "surface.h"
+#include "fader.h"
 
 #include "i18n.h"
 
@@ -94,25 +97,18 @@ LedState
 MackieControlProtocol::left_press (Button &)
 {
        Sorted sorted = get_sorted_routes();
-       uint32_t strip_cnt = n_strips ();
+       uint32_t strip_cnt = n_strips (); 
 
        DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank left with current initial = %1 nstrips = %2 tracks/busses = %3\n",
                                                           _current_initial_bank, strip_cnt, sorted.size()));
 
-       if (sorted.size() > strip_cnt) {
-               int new_initial = _current_initial_bank - strip_cnt;
-               if (new_initial < 0) {
-                       new_initial = 0;
-               }
-               
-               if (new_initial != int (_current_initial_bank)) {
-                       switch_banks (new_initial);
-               }
-
-               return on;
+       if (_current_initial_bank > strip_cnt) {
+               switch_banks (_current_initial_bank - strip_cnt);
        } else {
-               return flashing;
+               switch_banks (0);
        }
+
+       return on;
 }
 
 LedState 
@@ -126,26 +122,15 @@ MackieControlProtocol::right_press (Button &)
 {
        Sorted sorted = get_sorted_routes();
        uint32_t strip_cnt = n_strips();
+       uint32_t route_cnt = sorted.size();
 
        DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank right with current initial = %1 nstrips = %2 tracks/busses = %3\n",
-                                                          _current_initial_bank, strip_cnt, sorted.size()));
-
-       if (sorted.size() > strip_cnt) {
-               uint32_t delta = sorted.size() - (strip_cnt + _current_initial_bank);
+                                                          _current_initial_bank, strip_cnt, route_cnt));
 
-               if (delta > strip_cnt) {
-                       delta = strip_cnt;
-               }
-               
-               if (delta > 0) {
-                       switch_banks (_current_initial_bank + delta);
-               }
+       uint32_t new_initial = std::min (_current_initial_bank + strip_cnt, route_cnt - 1);
+       switch_banks (new_initial);
 
-               return on;
-       } else {
-               return flashing;
-       }
-       return off;
+       return on;
 }
 
 LedState 
@@ -236,6 +221,8 @@ MackieControlProtocol::cursor_up_press (Button&)
                } else {
                        VerticalZoomInAll (); /* EMIT SIGNAL */
                }
+       } else {
+               StepTracksUp (); /* EMIT SIGNAL */
        }
        return off;
 }
@@ -255,6 +242,8 @@ MackieControlProtocol::cursor_down_press (Button&)
                } else {
                        VerticalZoomOutAll (); /* EMIT SIGNAL */
                }
+       } else {
+               StepTracksDown (); /* EMIT SIGNAL */
        }
        return off;
 }
@@ -317,14 +306,16 @@ MackieControlProtocol::zoom_release (Mackie::Button &)
 Mackie::LedState 
 MackieControlProtocol::scrub_press (Mackie::Button &)
 {
-       _scrub_mode = !_scrub_mode;
-       return (_scrub_mode ? on : off);
+       if (!surfaces.empty()) {
+               surfaces.front()->next_jog_mode ();
+       }
+       return none;
 }
 
 Mackie::LedState 
 MackieControlProtocol::scrub_release (Mackie::Button &)
 {
-       return (_scrub_mode ? on : off);
+       return none;
 }
 
 LedState
@@ -438,22 +429,21 @@ MackieControlProtocol::frm_left_press (Button &)
        // can use first_mark_before/after as well
        unsigned long elapsed = _frm_left_last.restart();
 
-       Location * loc = session->locations()->first_location_before (
-               session->transport_frame()
-       );
-
+       framepos_t pos = session->locations()->first_mark_before (session->transport_frame());
+       
        // allow a quick double to go past a previous mark
-       if (session->transport_rolling() && elapsed < 500 && loc != 0) {
-               Location * loc_two_back = session->locations()->first_location_before (loc->start());
-               if (loc_two_back != 0)
-               {
-                       loc = loc_two_back;
+       if (session->transport_rolling() && elapsed < 500 && pos >= 0) {
+               framepos_t pos_two_back = session->locations()->first_mark_before (pos);
+               if (pos_two_back >= 0) {
+                       pos = pos_two_back;
                }
        }
 
        // move to the location, if it's valid
-       if (loc != 0) {
-               session->request_locate (loc->start(), session->transport_rolling());
+       if (pos >= 0) {
+               session->request_locate (pos, session->transport_rolling());
+       } else {
+               session->request_locate (session->current_start_frame(), session->transport_rolling());
        }
 
        return on;
@@ -469,10 +459,12 @@ LedState
 MackieControlProtocol::frm_right_press (Button &)
 {
        // can use first_mark_before/after as well
-       Location * loc = session->locations()->first_location_after (session->transport_frame());
+       framepos_t pos = session->locations()->first_mark_after (session->transport_frame());
        
-       if (loc != 0) {
-               session->request_locate (loc->start(), session->transport_rolling());
+       if (pos >= 0) {
+               session->request_locate (pos, session->transport_rolling());
+       } else {
+               session->request_locate (session->current_end_frame(), session->transport_rolling());
        }
                
        return on;
@@ -504,7 +496,7 @@ MackieControlProtocol::play_press (Button &)
           again, jump back to where we started last time
        */
 
-       transport_play (session->transport_rolling() == 1.0);
+       transport_play (session->transport_speed() == 1.0);
        return none;
 }
 
@@ -530,7 +522,11 @@ MackieControlProtocol::record_release (Button &)
 LedState 
 MackieControlProtocol::rewind_press (Button &)
 {
-       rewind ();
+       if (_modifier_state == MODIFIER_CONTROL) {
+               goto_start ();
+       } else {
+               rewind ();
+       }
        return none;
 }
 
@@ -543,7 +539,11 @@ MackieControlProtocol::rewind_release (Button &)
 LedState 
 MackieControlProtocol::ffwd_press (Button &)
 {
-       ffwd ();
+       if (_modifier_state == MODIFIER_CONTROL) {
+               goto_end();
+       } else {
+               ffwd ();
+       }
        return none;
 }
 
@@ -663,10 +663,10 @@ MackieControlProtocol::enter_release (Button &)
 { 
        return off;
 }
+
 LedState
 MackieControlProtocol::F1_press (Button &) 
 { 
-       f_press (0);
        return off; 
 }
 LedState
@@ -677,7 +677,6 @@ MackieControlProtocol::F1_release (Button &)
 LedState
 MackieControlProtocol::F2_press (Button &) 
 { 
-       f_press (1);
        return off; 
 }
 LedState
@@ -688,7 +687,6 @@ MackieControlProtocol::F2_release (Button &)
 LedState
 MackieControlProtocol::F3_press (Button &) 
 { 
-       f_press (2);
        return off; 
 }
 LedState
@@ -699,7 +697,6 @@ MackieControlProtocol::F3_release (Button &)
 LedState
 MackieControlProtocol::F4_press (Button &) 
 { 
-       f_press (3);
        return off; 
 }
 LedState
@@ -710,7 +707,6 @@ MackieControlProtocol::F4_release (Button &)
 LedState
 MackieControlProtocol::F5_press (Button &) 
 { 
-       f_press (4);
        return off; 
 }
 LedState
@@ -721,7 +717,6 @@ MackieControlProtocol::F5_release (Button &)
 LedState
 MackieControlProtocol::F6_press (Button &) 
 { 
-       f_press (5);
        return off; 
 }
 LedState
@@ -732,7 +727,6 @@ MackieControlProtocol::F6_release (Button &)
 LedState
 MackieControlProtocol::F7_press (Button &) 
 { 
-       f_press (6);
        return off; 
 }
 LedState
@@ -820,8 +814,12 @@ MackieControlProtocol::dyn_release (Button &)
 LedState
 MackieControlProtocol::flip_press (Button &) 
 { 
-       set_flip_mode (!_flip_mode);
-       return (_flip_mode ? on : off);
+       if (_flip_mode != Normal) {
+               set_flip_mode (Normal);
+       } else {
+               set_flip_mode (Mirror);
+       }
+       return ((_flip_mode != Normal) ? on : off);
 }
 LedState
 MackieControlProtocol::flip_release (Button &) 
@@ -1001,6 +999,33 @@ MackieControlProtocol::user_b_release (Button &)
        return off; 
 }
 
+LedState
+MackieControlProtocol::master_fader_touch_press (Mackie::Button &)
+{
+       DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_press\n");
+
+       Fader* master_fader = surfaces.front()->master_fader();
+
+       boost::shared_ptr<AutomationControl> ac = master_fader->control ();
+
+       master_fader->set_in_use (true);
+       master_fader->start_touch (transport_frame());
+
+       return none;
+}
+LedState
+MackieControlProtocol::master_fader_touch_release (Mackie::Button &)
+{
+       DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_release\n");
+
+       Fader* master_fader = surfaces.front()->master_fader();
+
+       master_fader->set_in_use (false);
+       master_fader->stop_touch (transport_frame(), true);
+
+       return none;
+}
+
 Mackie::LedState 
 MackieControlProtocol::snapshot_press (Mackie::Button&) 
 {
@@ -1014,12 +1039,14 @@ MackieControlProtocol::snapshot_release (Mackie::Button&)
 Mackie::LedState 
 MackieControlProtocol::read_press (Mackie::Button&) 
 {
-       return none;
+       _metering_active = !_metering_active;
+       notify_metering_state_changed ();
+       return _metering_active;
 }
 Mackie::LedState 
 MackieControlProtocol::read_release (Mackie::Button&) 
 {
-       return none;
+       return _metering_active;
 }
 Mackie::LedState 
 MackieControlProtocol::write_press (Mackie::Button&)