Setup clock sensitivity with lock correctly.
[ardour.git] / gtk2_ardour / location_ui.cc
index fda29be193a336d4ecd87b44b589c32d12765313..cf6862f2d6c55343ec5680be5b95e4916345abc9 100644 (file)
@@ -51,6 +51,8 @@ LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
          length_clock (X_("locationlength"), true, X_("LocationEditRowClock"), true, false, true),
          cd_check_button (_("CD")),
          hide_check_button (_("Hide")),
+         lock_check_button (_("Lock")),
+         glue_check_button (_("Glue")),
          scms_check_button (_("SCMS")),
          preemph_check_button (_("Pre-Emphasis"))
 
@@ -68,6 +70,8 @@ LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
        end_go_button.set_name ("LocationEditGoButton");
        cd_check_button.set_name ("LocationEditCdButton");
        hide_check_button.set_name ("LocationEditHideButton");
+       lock_check_button.set_name ("LocationEditLockButton");
+       glue_check_button.set_name ("LocationEditGlueButton");
        remove_button.set_name ("LocationEditRemoveButton");
        isrc_label.set_name ("LocationEditNumberLabel");
        isrc_entry.set_name ("LocationEditNameEntry");
@@ -137,6 +141,8 @@ LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
 
        cd_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::cd_toggled));
        hide_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::hide_toggled));
+       lock_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::lock_toggled));
+       glue_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::glue_toggled));
 
        remove_button.signal_clicked().connect(sigc::mem_fun(*this, &LocationEditRow::remove_button_pressed));
 
@@ -187,12 +193,20 @@ LocationEditRow::set_location (Location *loc)
 
        location = loc;
 
-       if (!location) return;
+       if (!location) {
+               return;
+       }
+
+       ++i_am_the_modifier;
 
        if (!hide_check_button.get_parent()) {
                item_table.attach (hide_check_button, 5, 6, 0, 1, FILL, Gtk::FILL, 4, 0);
+               item_table.attach (lock_check_button, 6, 7, 0, 1, FILL, Gtk::FILL, 4, 0);
+               item_table.attach (glue_check_button, 7, 8, 0, 1, FILL, Gtk::FILL, 4, 0);
        }
        hide_check_button.set_active (location->is_hidden());
+       lock_check_button.set_active (location->locked());
+       glue_check_button.set_active (location->position_lock_style() == MusicTime);
 
        if (location->is_auto_loop() || location-> is_auto_punch()) {
                // use label instead of entry
@@ -222,7 +236,7 @@ LocationEditRow::set_location (Location *loc)
                        item_table.attach (cd_check_button, 4, 5, 0, 1, FILL, FILL, 4, 0);
                }
                if (!remove_button.get_parent()) {
-                       item_table.attach (remove_button, 6, 7, 0, 1, FILL, FILL, 4, 0);
+                       item_table.attach (remove_button, 8, 9, 0, 1, FILL, FILL, 4, 0);
                }
 
                if (location->is_session_range()) {
@@ -239,6 +253,8 @@ LocationEditRow::set_location (Location *loc)
                }
 
                hide_check_button.show();
+               lock_check_button.show();
+               glue_check_button.show();
        }
 
        start_clock.set (location->start(), true);
@@ -277,15 +293,17 @@ LocationEditRow::set_location (Location *loc)
                length_clock.hide();
        }
 
-       start_clock.set_sensitive (!location->locked());
-       end_clock.set_sensitive (!location->locked());
-       length_clock.set_sensitive (!location->locked());
+       set_clock_sensitivity ();
+
+       --i_am_the_modifier;
 
        location->start_changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::start_changed, this, _1), gui_context());
        location->end_changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::end_changed, this, _1), gui_context());
        location->name_changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::name_changed, this, _1), gui_context());
        location->changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::location_changed, this, _1), gui_context());
        location->FlagsChanged.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::flags_changed, this, _1, _2), gui_context());
+       location->LockChanged.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::lock_changed, this, _1), gui_context());
+       location->PositionLockStyleChanged.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::position_lock_style_changed, this, _1), gui_context());
 }
 
 void
@@ -363,7 +381,9 @@ LocationEditRow::go_button_pressed (LocationPart part)
 void
 LocationEditRow::clock_changed (LocationPart part)
 {
-       if (i_am_the_modifier || !location) return;
+       if (i_am_the_modifier || !location) {
+               return;
+       }
 
        switch (part) {
        case LocStart:
@@ -377,7 +397,6 @@ LocationEditRow::clock_changed (LocationPart part)
        default:
                break;
        }
-
 }
 
 void
@@ -444,11 +463,41 @@ LocationEditRow::cd_toggled ()
 void
 LocationEditRow::hide_toggled ()
 {
-       if (i_am_the_modifier || !location) return;
+       if (i_am_the_modifier || !location) {
+               return;
+       }
 
        location->set_hidden (hide_check_button.get_active(), this);
 }
 
+void
+LocationEditRow::lock_toggled ()
+{
+       if (i_am_the_modifier || !location) {
+               return;
+       }
+
+       if (location->locked()) {
+               location->unlock ();
+       } else {
+               location->lock ();
+       }
+}
+
+void
+LocationEditRow::glue_toggled ()
+{
+       if (i_am_the_modifier || !location) {
+               return;
+       }
+
+       if (location->position_lock_style() == AudioTime) {
+               location->set_position_lock_style (MusicTime);
+       } else {
+               location->set_position_lock_style (AudioTime);
+       }
+}
+
 void
 LocationEditRow::remove_button_pressed ()
 {
@@ -553,9 +602,7 @@ LocationEditRow::location_changed (ARDOUR::Location *loc)
        end_clock.set (location->end());
        length_clock.set (location->length());
 
-       start_clock.set_sensitive (!location->locked());
-       end_clock.set_sensitive (!location->locked());
-       length_clock.set_sensitive (!location->locked());
+       set_clock_sensitivity ();
 
        i_am_the_modifier--;
 
@@ -564,14 +611,45 @@ LocationEditRow::location_changed (ARDOUR::Location *loc)
 void
 LocationEditRow::flags_changed (ARDOUR::Location *loc, void *src)
 {
-       ENSURE_GUI_THREAD (*this, &LocationEditRow::flags_changed, loc, src)
-
-       if (!location) return;
+       if (!location) {
+               return;
+       }
 
        i_am_the_modifier++;
 
        cd_check_button.set_active (location->is_cd_marker());
        hide_check_button.set_active (location->is_hidden());
+       glue_check_button.set_active (location->position_lock_style() == MusicTime);
+
+       i_am_the_modifier--;
+}
+
+void
+LocationEditRow::lock_changed (ARDOUR::Location *loc)
+{
+       if (!location) {
+               return;
+       }
+
+       i_am_the_modifier++;
+
+       lock_check_button.set_active (location->locked());
+
+       set_clock_sensitivity ();
+
+       i_am_the_modifier--;
+}
+
+void
+LocationEditRow::position_lock_style_changed (ARDOUR::Location* loc)
+{
+       if (!location) {
+               return;
+       }
+
+       i_am_the_modifier++;
+
+       glue_check_button.set_active (location->position_lock_style() == MusicTime);
 
        i_am_the_modifier--;
 }
@@ -829,7 +907,7 @@ LocationUI::add_new_location()
        if (_session) {
                nframes_t where = _session->audible_frame();
                _session->locations()->next_available_name(markername,"mark");
-               Location *location = new Location (where, where, markername, Location::IsMark);
+               Location *location = new Location (*_session, where, where, markername, Location::IsMark);
                if (Config->get_name_new_markers()) {
                        newest_location = location;
                }
@@ -851,7 +929,7 @@ LocationUI::add_new_range()
        if (_session) {
                nframes_t where = _session->audible_frame();
                _session->locations()->next_available_name(rangename,"unnamed");
-               Location *location = new Location (where, where, rangename, Location::IsRangeMarker);
+               Location *location = new Location (*_session, where, where, rangename, Location::IsRangeMarker);
                _session->begin_reversible_command (_("add range marker"));
                XMLNode &before = _session->locations()->get_state();
                _session->locations()->add (location, true);
@@ -932,6 +1010,14 @@ LocationUI::session_going_away()
        SessionHandlePtr::session_going_away ();
 }
 
+void
+LocationEditRow::set_clock_sensitivity ()
+{
+       start_clock.set_sensitive (!location->locked());
+       end_clock.set_sensitive (!location->locked());
+       length_clock.set_sensitive (!location->locked());
+}
+
 /*------------------------*/
 
 LocationUIWindow::LocationUIWindow ()