Allow strips to add or remove personal sends
[ardour.git] / gtk2_ardour / audio_clock.cc
index e9aa0076bbc217b568bc11121cf7a79706592a06..2656c2b445f128cf31d0217d09fe392f17ae7a0a 100644 (file)
@@ -34,8 +34,9 @@
 #include "ardour/profile.h"
 #include "ardour/lmath.h"
 #include "ardour/session.h"
-#include "ardour/slave.h"
+#include "ardour/transport_master.h"
 #include "ardour/tempo.h"
+#include "ardour/transport_master_manager.h"
 #include "ardour/types.h"
 
 #include "ardour_ui.h"
@@ -108,7 +109,7 @@ AudioClock::AudioClock (const string& clock_name, bool transient, const string&
 
        _mode = BBT; /* lie to force mode switch */
        set_mode (Timecode);
-       set (last_when, true);
+       AudioClock::set (last_when, true);
 
        if (!is_transient) {
                clocks.push_back (this);
@@ -187,7 +188,7 @@ AudioClock::set_font (Pango::FontDescription font)
        tmp->get_pixel_size (em_width, ignore_height);
 
        /* force redraw of markup with new font-size */
-       set (last_when, true);
+       AudioClock::set (last_when, true);
 }
 
 void
@@ -509,7 +510,7 @@ AudioClock::end_edit (bool modify)
                        break;
 
                case Seconds:
-                       // no break
+                       /* fall through */
                case Samples:
                        if (edit_string.length() < 1) {
                                edit_string = pre_edit_string;
@@ -554,7 +555,7 @@ AudioClock::end_edit (bool modify)
                                break;
                        }
 
-                       set (pos, true);
+                       AudioClock::set (pos, true);
                        _layout->set_attributes (normal_attributes);
                        ValueChanged(); /* EMIT_SIGNAL */
                }
@@ -781,14 +782,14 @@ AudioClock::end_edit_relative (bool add)
 
        if (samples != 0) {
                if (add) {
-                       set (current_time() + samples, true);
+                       AudioClock::set (current_time() + samples, true);
                } else {
                        samplepos_t c = current_time();
 
                        if (c > samples || _negative_allowed) {
-                               set (c - samples, true);
+                               AudioClock::set (c - samples, true);
                        } else {
-                               set (0, true);
+                               AudioClock::set (0, true);
                        }
                }
                ValueChanged (); /* EMIT SIGNAL */
@@ -802,7 +803,7 @@ AudioClock::end_edit_relative (bool add)
 void
 AudioClock::session_property_changed (const PropertyChange&)
 {
-       set (last_when, true);
+       AudioClock::set (last_when, true);
 }
 
 void
@@ -814,7 +815,7 @@ AudioClock::session_configuration_changed (std::string p)
        }
 
        if (p == "sync-source" || p == "external-sync") {
-               set (current_time(), true);
+               AudioClock::set (current_time(), true);
                return;
        }
 
@@ -831,7 +832,7 @@ AudioClock::session_configuration_changed (std::string p)
                } else {
                        current = current_time ();
                }
-               set (current, true);
+               AudioClock::set (current, true);
                break;
        default:
                break;
@@ -845,6 +846,7 @@ AudioClock::set (samplepos_t when, bool force, samplecnt_t offset)
                return;
        }
 
+       _offset = offset;
        if (is_duration) {
                when = when - offset;
        }
@@ -937,20 +939,19 @@ AudioClock::set_slave_info ()
                return;
        }
 
-       SyncSource sync_src = Config->get_sync_source();
+       boost::shared_ptr<TransportMaster> tm = TransportMasterManager::instance().current();
 
-       if (_session->config.get_external_sync()) {
-               Slave* slave = _session->slave();
+       if (_session->transport_master_is_external()) {
 
-               switch (sync_src) {
+               switch (tm->type()) {
                case Engine:
-                       _left_btn.set_text (sync_source_to_string (sync_src, true), true);
+                       _left_btn.set_text (tm->name(), true);
                        _right_btn.set_text ("", true);
                        break;
                case MIDIClock:
-                       if (slave) {
-                               _left_btn.set_text (sync_source_to_string (sync_src, true), true);
-                               _right_btn.set_text (slave->approximate_current_delta (), true);
+                       if (tm) {
+                               _left_btn.set_text (tm->display_name(), true);
+                               _right_btn.set_text (tm->delta_string (), true);
                        } else {
                                _left_btn.set_text (_("--pending--"), true);
                                _right_btn.set_text ("", true);
@@ -958,17 +959,17 @@ AudioClock::set_slave_info ()
                        break;
                case LTC:
                case MTC:
-                       if (slave) {
+                       if (tm) {
                                bool matching;
-                               TimecodeSlave* tcslave;
-                               if ((tcslave = dynamic_cast<TimecodeSlave*>(_session->slave())) != 0) {
-                                       matching = (tcslave->apparent_timecode_format() == _session->config.get_timecode_format());
+                               boost::shared_ptr<TimecodeTransportMaster> tcmaster;
+                               if ((tcmaster = boost::dynamic_pointer_cast<TimecodeTransportMaster>(tm)) != 0) {
+                                       matching = (tcmaster->apparent_timecode_format() == _session->config.get_timecode_format());
                                        _left_btn.set_text (string_compose ("%1<span face=\"monospace\" foreground=\"%3\">%2</span>",
-                                                               sync_source_to_string(sync_src, true)[0],
-                                                               dynamic_cast<TimecodeSlave*>(slave)->approximate_current_position (),
-                                                               matching ? "#66ff66" : "#ff3333"
+                                                                           tm->display_name()[0],
+                                                                           tcmaster->position_string (),
+                                                                           matching ? "#66ff66" : "#ff3333"
                                                                ), true);
-                                       _right_btn.set_text (slave->approximate_current_delta (), true);
+                                       _right_btn.set_text (tm->delta_string (), true);
                                }
                        } else {
                                _left_btn.set_text (_("--pending--"), true);
@@ -977,8 +978,7 @@ AudioClock::set_slave_info ()
                        break;
                }
        } else {
-               _left_btn.set_text (string_compose ("%1/%2",
-                                       _("INT"), sync_source_to_string(sync_src, true)), true);
+               _left_btn.set_text (string_compose ("%1/%2", _("INT"), tm->display_name()), true);
                _right_btn.set_text ("", true);
        }
 }
@@ -1312,7 +1312,7 @@ AudioClock::set_session (Session *s)
                        }
                }
 
-               set (last_when, true);
+               AudioClock::set (last_when, true);
        }
 }
 
@@ -1744,7 +1744,7 @@ AudioClock::on_scroll_event (GdkEventScroll *ev)
                        if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
                                samples *= 10;
                        }
-                       set (current_time() + samples, true);
+                       AudioClock::set (current_time() + samples, true);
                        ValueChanged (); /* EMIT_SIGNAL */
                }
                break;
@@ -1757,9 +1757,9 @@ AudioClock::on_scroll_event (GdkEventScroll *ev)
                        }
 
                        if (!_negative_allowed && (double)current_time() - (double)samples < 0.0) {
-                               set (0, true);
+                               AudioClock::set (0, true);
                        } else {
-                               set (current_time() - samples, true);
+                               AudioClock::set (current_time() - samples, true);
                        }
 
                        ValueChanged (); /* EMIT_SIGNAL */
@@ -1809,9 +1809,9 @@ AudioClock::on_motion_notify_event (GdkEventMotion *ev)
                samples = get_sample_step (drag_field, pos, dir);
 
                if (samples  != 0 &&  samples * drag_accum < current_time()) {
-                       set ((samplepos_t) floor (pos - drag_accum * samples), false); // minus because up is negative in GTK
+                       AudioClock::set ((samplepos_t) floor (pos - drag_accum * samples), false); // minus because up is negative in GTK
                } else {
-                       set (0 , false);
+                       AudioClock::set (0 , false);
                }
 
                drag_accum= 0;
@@ -1911,7 +1911,6 @@ AudioClock::current_duration (samplepos_t pos) const
        case MinSec:
        case Seconds:
        case Samples:
-               ret = last_when;
                ret = last_when;
                break;
        }
@@ -1920,7 +1919,7 @@ AudioClock::current_duration (samplepos_t pos) const
 }
 
 bool
-AudioClock::bbt_validate_edit (const string& str)
+AudioClock::bbt_validate_edit (string & str)
 {
        AnyTime any;
 
@@ -1937,7 +1936,14 @@ AudioClock::bbt_validate_edit (const string& str)
        }
 
        if (!is_duration && any.bbt.beats == 0) {
-               return false;
+               /* user could not have mean zero beats because for a
+                * non-duration clock that's impossible. Assume that they
+                * mis-entered things and meant Bar|1|ticks
+                */
+
+               char buf[128];
+               snprintf (buf, sizeof (buf), "%" PRIu32 "|%" PRIu32 "|%" PRIu32, any.bbt.bars, 1, any.bbt.ticks);
+               str = buf;
        }
 
        return true;
@@ -2154,7 +2160,7 @@ AudioClock::set_from_playhead ()
                return;
        }
 
-       set (_session->transport_sample());
+       AudioClock::set (_session->transport_sample());
        ValueChanged ();
 }
 
@@ -2237,7 +2243,7 @@ AudioClock::set_mode (Mode m, bool noemit)
                break;
        }
 
-       set (last_when, true);
+       AudioClock::set (last_when, true);
 
        if (!is_transient && !noemit) {
                ModeChanged (); /* EMIT SIGNAL (the static one)*/
@@ -2279,7 +2285,7 @@ AudioClock::set_is_duration (bool yn)
        }
 
        is_duration = yn;
-       set (last_when, true);
+       AudioClock::set (last_when, true);
 }
 
 void
@@ -2295,7 +2301,7 @@ AudioClock::set_off (bool yn)
         * change
         */
 
-       set (last_when, true);
+       AudioClock::set (last_when, true);
 }
 
 void