Consistent use of abort() /* NOTREACHED */
[ardour.git] / libs / surfaces / mackie / mackie_control_protocol.cc
index 064d763d1e41ae5184a47e020567d125b60aeb52..9887ed9402a37f7115ae4758f2f3bea6a6fa9595 100644 (file)
@@ -1,21 +1,26 @@
 /*
-       Copyright (C) 2006,2007 John Anderson
-       Copyright (C) 2012 Paul Davis
-
-       This program is free software; you can redistribute it and/or modify
-       it under the terms of the GNU General Public License as published by
-       the Free Software Foundation; either version 2 of the License, or
-       (at your option) any later version.
-
-       This program is distributed in the hope that it will be useful,
-       but WITHOUT ANY WARRANTY; without even the implied warranty of
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-       GNU General Public License for more details.
-
-       You should have received a copy of the GNU General Public License
-       along with this program; if not, write to the Free Software
-       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ * Copyright (C) 2006-2007 John Anderson
+ * Copyright (C) 2007-2010 David Robillard <d@drobilla.net>
+ * Copyright (C) 2007-2017 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2015-2016 Len Ovens <len@ovenwerks.net>
+ * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2016-2018 Ben Loftis <ben@harrisonconsoles.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 #include <fcntl.h>
 #include <iostream>
@@ -111,7 +116,7 @@ MackieControlProtocol::MackieControlProtocol (Session& session)
        : ControlProtocol (session, X_("Mackie"))
        , AbstractUI<MackieControlUIRequest> (name())
        , _current_initial_bank (0)
-       , _frame_last (0)
+       , _sample_last (0)
        , _timecode_type (ARDOUR::AnyTime::BBT)
        , _gui (0)
        , _scrub_mode (false)
@@ -218,7 +223,7 @@ void
 MackieControlProtocol::next_track()
 {
        Sorted sorted = get_sorted_stripables();
-       if (_current_initial_bank + n_strips() < sorted.size()) {
+       if (_current_initial_bank + 1 < sorted.size()) {
                switch_banks (_current_initial_bank + 1);
        }
 }
@@ -459,13 +464,25 @@ MackieControlProtocol::set_active (bool yn)
                /* set up periodic task for timecode display and metering and automation
                 */
 
-               Glib::RefPtr<Glib::TimeoutSource> periodic_timeout = Glib::TimeoutSource::create (100); // milliseconds
+               // set different refresh time for qcon and standard mackie MCU
+
+               int iTimeCodeRefreshTime = 100; // default value for mackie MCU (100ms)
+               int iStripDisplayRefreshTime = 10; // default value for Mackie MCU (10ms)
+
+               if(_device_info.is_qcon()){
+                       // set faster timecode display refresh speed (55ms)
+                       iTimeCodeRefreshTime = 55;
+                       // set slower refresh time on qcon than on mackie (15ms)
+                       iStripDisplayRefreshTime = 15;
+               }
+
+               Glib::RefPtr<Glib::TimeoutSource> periodic_timeout = Glib::TimeoutSource::create (iTimeCodeRefreshTime); // milliseconds
                periodic_connection = periodic_timeout->connect (sigc::mem_fun (*this, &MackieControlProtocol::periodic));
                periodic_timeout->attach (main_loop()->get_context());
 
                /* periodic task used to update strip displays */
 
-               Glib::RefPtr<Glib::TimeoutSource> redisplay_timeout = Glib::TimeoutSource::create (10); // milliseconds
+               Glib::RefPtr<Glib::TimeoutSource> redisplay_timeout = Glib::TimeoutSource::create (iStripDisplayRefreshTime); // milliseconds
                redisplay_connection = redisplay_timeout->connect (sigc::mem_fun (*this, &MackieControlProtocol::redisplay));
                redisplay_timeout->attach (main_loop()->get_context());
 
@@ -1098,11 +1115,11 @@ MackieControlProtocol::set_state (const XMLNode & node, int version)
 }
 
 string
-MackieControlProtocol::format_bbt_timecode (framepos_t now_frame)
+MackieControlProtocol::format_bbt_timecode (samplepos_t now_sample)
 {
        Timecode::BBT_Time bbt_time;
 
-       session->bbt_time (now_frame, bbt_time);
+       session->bbt_time (now_sample, bbt_time);
 
        // The Mackie protocol spec is built around a BBT time display of
        //
@@ -1125,14 +1142,14 @@ MackieControlProtocol::format_bbt_timecode (framepos_t now_frame)
 }
 
 string
-MackieControlProtocol::format_timecode_timecode (framepos_t now_frame)
+MackieControlProtocol::format_timecode_timecode (samplepos_t now_sample)
 {
        Timecode::Time timecode;
-       session->timecode_time (now_frame, timecode);
+       session->timecode_time (now_sample, timecode);
 
        // According to the Logic docs
        // digits: 888/88/88/888
-       // Timecode mode: Hours/Minutes/Seconds/Frames
+       // Timecode mode: Hours/Minutes/Seconds/Samples
        ostringstream os;
        os << setw(2) << setfill('0') << timecode.hours;
        os << ' ';
@@ -1159,23 +1176,23 @@ MackieControlProtocol::update_timecode_display()
                return;
        }
 
-       // do assignment here so current_frame is fixed
-       framepos_t current_frame = session->transport_frame();
+       // do assignment here so current_sample is fixed
+       samplepos_t current_sample = session->transport_sample();
        string timecode;
        // For large jumps in play head possition do full reset
-       int moved = (current_frame - _frame_last) / session->frame_rate ();
+       int moved = (current_sample - _sample_last) / session->sample_rate ();
        if (moved) {
                DEBUG_TRACE (DEBUG::MackieControl, "Timecode reset\n");
                _timecode_last = string (10, ' ');
        }
-       _frame_last = current_frame;
+       _sample_last = current_sample;
 
        switch (_timecode_type) {
        case ARDOUR::AnyTime::BBT:
-               timecode = format_bbt_timecode (current_frame);
+               timecode = format_bbt_timecode (current_sample);
                break;
        case ARDOUR::AnyTime::Timecode:
-               timecode = format_timecode_timecode (current_frame);
+               timecode = format_timecode_timecode (current_sample);
                break;
        default:
                return;
@@ -1382,8 +1399,21 @@ MackieControlProtocol::notify_record_state_changed ()
                                ls = on;
                                break;
                        case Session::Enabled:
-                               DEBUG_TRACE (DEBUG::MackieControl, "record state changed to enabled, LED flashing\n");
-                               ls = flashing;
+                               
+                               if(_device_info.is_qcon()){
+                                       // For qcon the rec button is two state only (on/off)
+                                       DEBUG_TRACE (DEBUG::MackieControl, "record state changed to enabled, LED on (QCon)\n");
+                                       ls = on;
+                                       break;
+
+                               }
+                               else{
+                                       // For standard Mackie MCU the record LED is flashing
+                                       DEBUG_TRACE (DEBUG::MackieControl, "record state changed to enabled, LED flashing\n");
+                                       ls = flashing;
+                                       break;
+                               }
+
                                break;
                        }
 
@@ -1641,7 +1671,7 @@ MackieControlProtocol::midi_input_handler (IOCondition ioc, MIDI::Port* port)
                }
 
                // DEBUG_TRACE (DEBUG::MackieControl, string_compose ("data available on %1\n", port->name()));
-               framepos_t now = session->engine().sample_time();
+               samplepos_t now = session->engine().sample_time();
                port->parse (now);
        }
 
@@ -1991,13 +2021,21 @@ MackieControlProtocol::update_fader_automation_state ()
                update_global_button (Button::Latch, off);
                update_global_button (Button::Grp, off);
                break;
+       case Latch:
+               update_global_button (Button::Read, off);
+               update_global_button (Button::Write, off);
+               update_global_button (Button::Touch, off);
+               update_global_button (Button::Trim, off);
+               update_global_button (Button::Latch, on);
+               update_global_button (Button::Grp, off);
+               break;
        }
 }
 
-framepos_t
-MackieControlProtocol::transport_frame() const
+samplepos_t
+MackieControlProtocol::transport_sample() const
 {
-       return session->transport_frame();
+       return session->transport_sample();
 }
 
 void