expand bbox for Canvas::Line to get rid of artifacts caused when moving them around...
[ardour.git] / gtk2_ardour / location_ui.cc
index f3029cd062bbcb9c50eabd698039c608fa69e24b..30a5b62426dc422e97fe632d00ea377974eb8467 100644 (file)
 
 #include <gtkmm2ext/utils.h>
 
-#include "ardour/utils.h"
-#include "ardour/configuration.h"
 #include "ardour/session.h"
 #include "pbd/memento_command.h"
 
 #include "ardour_ui.h"
 #include "clock_group.h"
+#include "main_clock.h"
 #include "gui_thread.h"
 #include "keyboard.h"
 #include "location_ui.h"
@@ -56,14 +55,15 @@ LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
         , hide_check_button (_("Hide"))
         , lock_check_button (_("Lock"))
         , glue_check_button (_("Glue"))
-        , scms_check_button (_("SCMS"))
-        , preemph_check_button (_("Pre-Emphasis"))
         , _clock_group (0)
 {
          i_am_the_modifier = 0;
 
          remove_button.set_image (*manage (new Image (Stock::REMOVE, Gtk::ICON_SIZE_MENU)));
 
+        start_to_playhead_button.set_name ("LocationEditCdButton");
+        end_to_playhead_button.set_name ("LocationEditCdButton");
+
          number_label.set_name ("LocationEditNumberLabel");
          name_label.set_name ("LocationEditNameLabel");
          name_entry.set_name ("LocationEditNameEntry");
@@ -81,12 +81,11 @@ LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
          composer_label.set_name ("LocationEditNumberLabel");
          composer_entry.set_name ("LocationEditNameEntry");
 
-         isrc_label.set_text ("ISRC: ");
-         isrc_label.set_size_request (30, -1);
-         performer_label.set_text ("Performer: ");
-         performer_label.set_size_request (60, -1);
-         composer_label.set_text ("Composer: ");
-         composer_label.set_size_request (60, -1);
+         isrc_label.set_text (X_("ISRC:"));
+         performer_label.set_text (_("Performer:"));
+         composer_label.set_text (_("Composer:"));
+        scms_label.set_text (X_("SCMS"));
+        preemph_label.set_text (_("Pre-Emphasis"));
 
          isrc_entry.set_size_request (112, -1);
          isrc_entry.set_max_length(12);
@@ -100,14 +99,24 @@ LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
 
          name_label.set_alignment (0, 0.5);
 
+        Gtk::HBox* front_spacing = manage (new HBox);
+        front_spacing->set_size_request (20, -1);
+        Gtk::HBox* mid_spacing = manage (new HBox);
+        mid_spacing->set_size_request (20, -1);
+
+        cd_track_details_hbox.set_spacing (4);
+        cd_track_details_hbox.pack_start (*front_spacing, false, false);
          cd_track_details_hbox.pack_start (isrc_label, false, false);
          cd_track_details_hbox.pack_start (isrc_entry, false, false);
-         cd_track_details_hbox.pack_start (scms_check_button, false, false);
-         cd_track_details_hbox.pack_start (preemph_check_button, false, false);
          cd_track_details_hbox.pack_start (performer_label, false, false);
          cd_track_details_hbox.pack_start (performer_entry, true, true);
          cd_track_details_hbox.pack_start (composer_label, false, false);
          cd_track_details_hbox.pack_start (composer_entry, true, true);
+        cd_track_details_hbox.pack_start (*mid_spacing, false, false);
+         cd_track_details_hbox.pack_start (scms_label, false, false);
+         cd_track_details_hbox.pack_start (scms_check_button, false, false);
+         cd_track_details_hbox.pack_start (preemph_label, false, false);
+         cd_track_details_hbox.pack_start (preemph_check_button, false, false);
 
          isrc_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::isrc_entry_changed));
          performer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::performer_entry_changed));
@@ -131,6 +140,7 @@ LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
 
         start_to_playhead_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocStart));
          start_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocStart));
+        start_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &start_clock), false);
 
         end_hbox.set_spacing (2);
          end_hbox.pack_start (end_clock, false, false);
@@ -138,6 +148,7 @@ LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
 
         end_to_playhead_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocEnd));
          end_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocEnd));
+        end_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &end_clock), false);
 
          length_clock.ValueChanged.connect (sigc::bind ( sigc::mem_fun(*this, &LocationEditRow::clock_changed), LocLength));
 
@@ -237,6 +248,8 @@ LocationEditRow::set_location (Location *loc)
                name_label.set_text (location->name());
                name_label.set_size_request (80, -1);
 
+               remove_button.hide ();
+
                if (!name_label.get_parent()) {
                        item_table.attach (name_label, 1, 2, 0, 1, FILL, FILL, 4, 0);
                }
@@ -313,17 +326,17 @@ LocationEditRow::set_location (Location *loc)
                length_clock.hide();
        }
 
-       set_clock_sensitivity ();
+       set_clock_editable_status ();
 
        --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());
+       location->start_changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::start_changed, this, _1), gui_context());
+       location->end_changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::end_changed, this, _1), gui_context());
+       location->name_changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::name_changed, this, _1), gui_context());
+       location->changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::location_changed, this, _1), gui_context());
+       location->FlagsChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::flags_changed, this, _1, _2), gui_context());
+       location->LockChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::lock_changed, this, _1), gui_context());
+       location->PositionLockStyleChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::position_lock_style_changed, this, _1), gui_context());
 }
 
 void
@@ -402,6 +415,16 @@ LocationEditRow::to_playhead_button_pressed (LocationPart part)
        }
 }
 
+bool
+LocationEditRow::locate_to_clock (GdkEventButton* ev, AudioClock* clock)
+{
+       if (Keyboard::is_button2_event (ev)) {
+               _session->request_locate (clock->current_time());
+               return true;
+       }
+       return false;
+}
+
 void
 LocationEditRow::clock_changed (LocationPart part)
 {
@@ -613,7 +636,7 @@ LocationEditRow::location_changed (ARDOUR::Location*)
        end_clock.set (location->end());
        length_clock.set (location->length());
 
-       set_clock_sensitivity ();
+       set_clock_editable_status ();
 
        i_am_the_modifier--;
 
@@ -646,7 +669,7 @@ LocationEditRow::lock_changed (ARDOUR::Location*)
 
        lock_check_button.set_active (location->locked());
 
-       set_clock_sensitivity ();
+       set_clock_editable_status ();
 
        i_am_the_modifier--;
 }
@@ -666,16 +689,17 @@ LocationEditRow::position_lock_style_changed (ARDOUR::Location*)
 }
 
 void
-LocationEditRow::focus_name() {
-       name_entry.grab_focus();
+LocationEditRow::focus_name()
+{
+       name_entry.grab_focus ();
 }
 
 void
-LocationEditRow::set_clock_sensitivity ()
+LocationEditRow::set_clock_editable_status ()
 {
-       start_clock.set_sensitive (!location->locked());
-       end_clock.set_sensitive (!location->locked());
-       length_clock.set_sensitive (!location->locked());
+       start_clock.set_editable (!location->locked());
+       end_clock.set_editable (!location->locked());
+       length_clock.set_editable (!location->locked());
 }
 
 /*------------------------------------------------------------------------*/
@@ -841,9 +865,9 @@ LocationUI::location_redraw_ranges ()
 }
 
 struct LocationSortByStart {
-    bool operator() (Location *a, Location *b) {
-           return a->start() < b->start();
-    }
+       bool operator() (Location *a, Location *b) {
+               return a->start() < b->start();
+       }
 };
 
 void
@@ -858,7 +882,7 @@ LocationUI::location_added (Location* location)
                loc.sort (LocationSortByStart ());
 
                LocationEditRow* erow = manage (new LocationEditRow (_session, location));
-
+               
                 erow->set_clock_group (*_clock_group);
                erow->remove_requested.connect (sigc::mem_fun (*this, &LocationUI::location_remove_requested));
 
@@ -889,6 +913,11 @@ LocationUI::location_added (Location* location)
 
                range_rows.show_all ();
                location_rows.show_all ();
+
+               if (location == newest_location) {
+                       newest_location = 0;
+                       erow->focus_name();
+               }
        }
 }
 
@@ -938,10 +967,6 @@ LocationUI::map_locations (Locations::LocationList& locations)
 
                         Box_Helpers::BoxList & loc_children = location_rows.children();
                        loc_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
-                       if (location == newest_location) {
-                               newest_location = 0;
-                               erow->focus_name();
-                       }
                } else if (location->is_auto_punch()) {
                        punch_edit_row.set_session (_session);
                        punch_edit_row.set_location (location);
@@ -1035,8 +1060,8 @@ LocationUI::set_session(ARDOUR::Session* s)
        if (_session) {
                _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::locations_changed, this, _1), gui_context());
                _session->locations()->StateChanged.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::refresh_location_list, this), gui_context());
-               _session->locations()->added.connect (_session_connections, invalidator (*this), ui_bind (&LocationUI::location_added, this, _1), gui_context());
-               _session->locations()->removed.connect (_session_connections, invalidator (*this), ui_bind (&LocationUI::location_removed, this, _1), gui_context());
+               _session->locations()->added.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_added, this, _1), gui_context());
+               _session->locations()->removed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_removed, this, _1), gui_context());
                _clock_group->set_clock_mode (clock_mode_from_session_instant_xml ());
        }
 
@@ -1096,7 +1121,7 @@ LocationUI::clock_mode_from_session_instant_xml () const
 
        XMLProperty* p = node->property (X_("clock-mode"));
        if (!p) {
-               return AudioClock::Frames;
+               return ARDOUR_UI::instance()->secondary_clock->mode();
        }
              
        return (AudioClock::Mode) string_2_enum (p->value (), AudioClock::Mode);