Display length & check digit of entered EAN-13 in metadata dialogue
[ardour.git] / gtk2_ardour / location_ui.cc
index ea6a3f544c24cbe9483ba538d302fcd66e02d15e..f56006e5ceb0b26ff8797ce6fc81371197ea796d 100644 (file)
 
 #include "ardour_ui.h"
 #include "clock_group.h"
+#include "main_clock.h"
 #include "gui_thread.h"
 #include "keyboard.h"
 #include "location_ui.h"
 #include "prompter.h"
 #include "utils.h"
+#include "public_editor.h"
 
 #include "i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
+using namespace ARDOUR_UI_UTILS;
 using namespace PBD;
 using namespace Gtk;
 using namespace Gtkmm2ext;
@@ -60,6 +63,9 @@ LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
 
          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");
@@ -159,6 +165,7 @@ LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
 
          set_location (loc);
          set_number (num);
+         cd_toggled(); // show/hide cd-track details
  }
 
  LocationEditRow::~LocationEditRow()
@@ -303,6 +310,10 @@ LocationEditRow::set_location (Location *loc)
                end_clock.show();
                length_clock.show();
 
+               if (location->is_cd_marker()) {
+                       show_cd_track_details ();
+               }
+
                ARDOUR_UI::instance()->set_tip (remove_button, _("Remove this range"));
                ARDOUR_UI::instance()->set_tip (start_clock, _("Start time - middle click to locate here"));
                ARDOUR_UI::instance()->set_tip (end_clock, _("End time - middle click to locate here"));
@@ -322,17 +333,19 @@ 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), 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());
+        /* connect to per-location signals, since this row only cares about this location */
+
+       location->NameChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::name_changed, this), gui_context());
+        location->StartChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::start_changed, this), gui_context());
+        location->EndChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::end_changed, this), gui_context());
+        location->Changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::location_changed, this), gui_context());
+        location->FlagsChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::flags_changed, this), gui_context()); 
+        location->LockChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::lock_changed, this), gui_context());
+        location->PositionLockStyleChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::position_lock_style_changed, this), gui_context());
 }
 
 void
@@ -442,6 +455,34 @@ LocationEditRow::clock_changed (LocationPart part)
        }
 }
 
+void
+LocationEditRow::show_cd_track_details ()
+{
+
+       if (location->cd_info.find("isrc") != location->cd_info.end()) {
+               isrc_entry.set_text(location->cd_info["isrc"]);
+       }
+       if (location->cd_info.find("performer") != location->cd_info.end()) {
+               performer_entry.set_text(location->cd_info["performer"]);
+       }
+       if (location->cd_info.find("composer") != location->cd_info.end()) {
+               composer_entry.set_text(location->cd_info["composer"]);
+       }
+       if (location->cd_info.find("scms") != location->cd_info.end()) {
+               scms_check_button.set_active(true);
+       }
+       if (location->cd_info.find("preemph") != location->cd_info.end()) {
+               preemph_check_button.set_active(true);
+       }
+
+
+       if (!cd_track_details_hbox.get_parent()) {
+               item_table.attach (cd_track_details_hbox, 0, 7, 1, 2, FILL | EXPAND, FILL, 4, 0);
+       }
+       // item_table.resize(2, 7);
+       cd_track_details_hbox.show_all();
+}
+
 void
 LocationEditRow::cd_toggled ()
 {
@@ -463,29 +504,9 @@ LocationEditRow::cd_toggled ()
 
        location->set_cd (cd_check_button.get_active(), this);
 
-       if (location->is_cd_marker() && !(location->is_mark())) {
+       if (location->is_cd_marker()) {
 
-               if (location->cd_info.find("isrc") != location->cd_info.end()) {
-                       isrc_entry.set_text(location->cd_info["isrc"]);
-               }
-               if (location->cd_info.find("performer") != location->cd_info.end()) {
-                       performer_entry.set_text(location->cd_info["performer"]);
-               }
-               if (location->cd_info.find("composer") != location->cd_info.end()) {
-                       composer_entry.set_text(location->cd_info["composer"]);
-               }
-               if (location->cd_info.find("scms") != location->cd_info.end()) {
-                       scms_check_button.set_active(true);
-               }
-               if (location->cd_info.find("preemph") != location->cd_info.end()) {
-                       preemph_check_button.set_active(true);
-               }
-
-               if (!cd_track_details_hbox.get_parent()) {
-                       item_table.attach (cd_track_details_hbox, 0, 7, 1, 2, FILL | EXPAND, FILL, 4, 0);
-               }
-               // item_table.resize(2, 7);
-               cd_track_details_hbox.show_all();
+               show_cd_track_details ();
 
        } else if (cd_track_details_hbox.get_parent()){
 
@@ -571,7 +592,7 @@ LocationEditRow::preemph_toggled ()
 }
 
 void
-LocationEditRow::end_changed (ARDOUR::Location *)
+LocationEditRow::end_changed ()
 {
        ENSURE_GUI_THREAD (*this, &LocationEditRow::end_changed, loc)
 
@@ -587,7 +608,7 @@ LocationEditRow::end_changed (ARDOUR::Location *)
 }
 
 void
-LocationEditRow::start_changed (ARDOUR::Location*)
+LocationEditRow::start_changed ()
 {
        if (!location) return;
 
@@ -606,7 +627,7 @@ LocationEditRow::start_changed (ARDOUR::Location*)
 }
 
 void
-LocationEditRow::name_changed (ARDOUR::Location *)
+LocationEditRow::name_changed ()
 {
        if (!location) return;
 
@@ -621,7 +642,7 @@ LocationEditRow::name_changed (ARDOUR::Location *)
 }
 
 void
-LocationEditRow::location_changed (ARDOUR::Location*)
+LocationEditRow::location_changed ()
 {
 
        if (!location) return;
@@ -632,14 +653,14 @@ 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--;
 
 }
 
 void
-LocationEditRow::flags_changed (ARDOUR::Location*, void *)
+LocationEditRow::flags_changed ()
 {
        if (!location) {
                return;
@@ -655,7 +676,7 @@ LocationEditRow::flags_changed (ARDOUR::Location*, void *)
 }
 
 void
-LocationEditRow::lock_changed (ARDOUR::Location*)
+LocationEditRow::lock_changed ()
 {
        if (!location) {
                return;
@@ -665,13 +686,13 @@ LocationEditRow::lock_changed (ARDOUR::Location*)
 
        lock_check_button.set_active (location->locked());
 
-       set_clock_sensitivity ();
+       set_clock_editable_status ();
 
        i_am_the_modifier--;
 }
 
 void
-LocationEditRow::position_lock_style_changed (ARDOUR::Location*)
+LocationEditRow::position_lock_style_changed ()
 {
        if (!location) {
                return;
@@ -691,11 +712,11 @@ LocationEditRow::focus_name()
 }
 
 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());
 }
 
 /*------------------------------------------------------------------------*/
@@ -818,7 +839,9 @@ LocationUI::LocationUI ()
 
 LocationUI::~LocationUI()
 {
-        delete _clock_group;
+       loop_edit_row.unset_clock_group ();
+       punch_edit_row.unset_clock_group ();
+       delete _clock_group;
 }
 
 gint
@@ -833,12 +856,12 @@ LocationUI::do_location_remove (ARDOUR::Location *loc)
                return FALSE;
        }
 
-       _session->begin_reversible_command (_("remove marker"));
+       PublicEditor::instance().begin_reversible_command (_("remove marker"));
        XMLNode &before = _session->locations()->get_state();
        _session->locations()->remove (loc);
        XMLNode &after = _session->locations()->get_state();
        _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
-       _session->commit_reversible_command ();
+       PublicEditor::instance().commit_reversible_command ();
 
        return FALSE;
 }
@@ -939,7 +962,7 @@ LocationUI::location_removed (Location* location)
 }
 
 void
-LocationUI::map_locations (Locations::LocationList& locations)
+LocationUI::map_locations (const Locations::LocationList& locations)
 {
        Locations::LocationList::iterator i;
        gint n;
@@ -948,9 +971,8 @@ LocationUI::map_locations (Locations::LocationList& locations)
        LocationSortByStart cmp;
 
        temp.sort (cmp);
-       locations = temp;
 
-       for (n = 0, i = locations.begin(); i != locations.end(); ++n, ++i) {
+       for (n = 0, i = temp.begin(); i != temp.end(); ++n, ++i) {
 
                Location* location = *i;
 
@@ -995,15 +1017,15 @@ LocationUI::add_new_location()
                framepos_t where = _session->audible_frame();
                _session->locations()->next_available_name(markername,"mark");
                Location *location = new Location (*_session, where, where, markername, Location::IsMark);
-               if (Config->get_name_new_markers()) {
+               if (ARDOUR_UI::config()->get_name_new_markers()) {
                        newest_location = location;
                }
-               _session->begin_reversible_command (_("add marker"));
+               PublicEditor::instance().begin_reversible_command (_("add marker"));
                XMLNode &before = _session->locations()->get_state();
                _session->locations()->add (location, true);
                XMLNode &after = _session->locations()->get_state();
                _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
-               _session->commit_reversible_command ();
+               PublicEditor::instance().commit_reversible_command ();
        }
 
 }
@@ -1017,12 +1039,12 @@ LocationUI::add_new_range()
                framepos_t where = _session->audible_frame();
                _session->locations()->next_available_name(rangename,"unnamed");
                Location *location = new Location (*_session, where, where, rangename, Location::IsRangeMarker);
-               _session->begin_reversible_command (_("add range marker"));
+               PublicEditor::instance().begin_reversible_command (_("add range marker"));
                XMLNode &before = _session->locations()->get_state();
                _session->locations()->add (location, true);
                XMLNode &after = _session->locations()->get_state();
                _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
-               _session->commit_reversible_command ();
+               PublicEditor::instance().commit_reversible_command ();
        }
 }
 
@@ -1054,10 +1076,10 @@ LocationUI::set_session(ARDOUR::Session* s)
        SessionHandlePtr::set_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), 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());
+               _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::refresh_location_list, this), gui_context());
+
                _clock_group->set_clock_mode (clock_mode_from_session_instant_xml ());
        }
 
@@ -1067,17 +1089,6 @@ LocationUI::set_session(ARDOUR::Session* s)
        refresh_location_list ();
 }
 
-void
-LocationUI::locations_changed (Locations::Change c)
-{
-       /* removal is signalled by both a removed and a changed signal emission from Locations,
-          so we don't need to refresh the list on a removal
-       */
-       if (c != Locations::REMOVAL) {
-               refresh_location_list ();
-       }
-}
-
 void
 LocationUI::session_going_away()
 {
@@ -1117,7 +1128,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);
@@ -1149,8 +1160,7 @@ LocationUIWindow::on_map ()
 bool
 LocationUIWindow::on_delete_event (GdkEventAny*)
 {
-       hide ();
-       return true;
+       return false;
 }
 
 void
@@ -1158,6 +1168,7 @@ LocationUIWindow::set_session (Session *s)
 {
        ArdourWindow::set_session (s);
        _ui.set_session (s);
+       _ui.show_all ();
 }
 
 void