enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / time_info_box.cc
index 00b760952cff4a9d3930d81a53c303cc6e0efd23..d0d6871cbb0c07a3626e035b12e3e9b4f986c89e 100644 (file)
 #include "gtkmm2ext/actions.h"
 
 #include "ardour/location.h"
+#include "ardour/profile.h"
 #include "ardour/session.h"
 
 #include "time_info_box.h"
 #include "audio_clock.h"
 #include "editor.h"
+#include "control_point.h"
+#include "automation_line.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace Gtk;
 using namespace ARDOUR;
@@ -46,6 +49,8 @@ TimeInfoBox::TimeInfoBox ()
        , syncing_selection (false)
        , syncing_punch (false)
 {
+       set_name (X_("TimeInfoBox"));
+
        selection_start = new AudioClock ("selection-start", false, "selection", false, false, false, false);
        selection_end = new AudioClock ("selection-end", false, "selection", false, false, false, false);
        selection_length = new AudioClock ("selection-length", false, "selection", false, false, true, false);
@@ -53,21 +58,17 @@ TimeInfoBox::TimeInfoBox ()
        punch_start = new AudioClock ("punch-start", false, "punch", false, false, false, false);
        punch_end = new AudioClock ("punch-end", false, "punch", false, false, false, false);
 
-       selection_start->set_draw_background (false);
-       selection_end->set_draw_background (false);
-       selection_length->set_draw_background (false);
-       punch_start->set_draw_background (false);
-       punch_end->set_draw_background (false);
-
        selection_title.set_text (_("Selection"));
        punch_title.set_text (_("Punch"));
 
        set_homogeneous (false);
-       set_spacing (6);
+       set_spacing (0);
        set_border_width (2);
 
        pack_start (left, true, true);
-       pack_start (right, true, true);
+       if (!ARDOUR::Profile->get_trx()) {
+               pack_start (right, true, true);
+       }
 
        left.set_homogeneous (false);
        left.set_spacings (0);
@@ -82,7 +83,7 @@ TimeInfoBox::TimeInfoBox ()
        Gtk::Label* l;
 
        selection_title.set_name ("TimeInfoSelectionTitle");
-       left.attach (selection_title, 0, 2, 0, 1);
+       left.attach (selection_title, 1, 2, 0, 1);
        l = manage (new Label);
        l->set_text (_("Start"));
        l->set_alignment (1.0, 0.5);
@@ -118,7 +119,7 @@ TimeInfoBox::TimeInfoBox ()
        Gtkmm2ext::UI::instance()->set_tip (punch_out_button, _("Stop recording at auto-punch end"));
 
        punch_title.set_name ("TimeInfoSelectionTitle");
-       right.attach (punch_title, 2, 4, 0, 1);
+       right.attach (punch_title, 3, 4, 0, 1);
         right.attach (punch_in_button, 2, 3, 1, 2, FILL, SHRINK);
         right.attach (*punch_start, 3, 4, 1, 2);
         right.attach (punch_out_button, 2, 3, 2, 3, FILL, SHRINK);
@@ -142,7 +143,8 @@ TimeInfoBox::TimeInfoBox ()
        Editor::instance().get_selection().TimeChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
        Editor::instance().get_selection().RegionsChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
 
-       Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), ui_bind (&TimeInfoBox::track_mouse_mode, this), gui_context());
+       Region::RegionPropertyChanged.connect (region_property_connections, invalidator (*this), boost::bind (&TimeInfoBox::region_property_change, this, _1, _2), gui_context());
+       Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), boost::bind (&TimeInfoBox::track_mouse_mode, this), gui_context());
 }
 
 TimeInfoBox::~TimeInfoBox ()
@@ -150,7 +152,7 @@ TimeInfoBox::~TimeInfoBox ()
         delete selection_length;
         delete selection_end;
         delete selection_start;
-        
+
         delete punch_start;
         delete punch_end;
 }
@@ -161,6 +163,33 @@ TimeInfoBox::track_mouse_mode ()
        selection_changed ();
 }
 
+void
+TimeInfoBox::region_property_change (boost::shared_ptr<ARDOUR::Region> /* r */, const PBD::PropertyChange& what_changed)
+{
+       Selection& selection (Editor::instance().get_selection());
+
+       if (selection.regions.empty()) {
+               return;
+       }
+
+       PBD::PropertyChange our_interests;
+
+       our_interests.add (ARDOUR::Properties::position);
+       our_interests.add (ARDOUR::Properties::length);
+       our_interests.add (ARDOUR::Properties::start);
+
+       if (!what_changed.contains (our_interests)) {
+               return;
+       }
+
+       /* TODO: check if RegionSelection includes the given region.
+        * This is not straight foward because RegionSelection is done by
+        * RegionView (not Region itself).
+        */
+
+       //selection_changed ();
+}
+
 bool
 TimeInfoBox::clock_button_release_event (GdkEventButton* ev, AudioClock* src)
 {
@@ -200,7 +229,7 @@ TimeInfoBox::sync_punch_mode (AudioClock* src)
                syncing_punch = false;
        }
 }
-       
+
 
 void
 TimeInfoBox::set_session (Session* s)
@@ -216,14 +245,14 @@ TimeInfoBox::set_session (Session* s)
 
        if (s) {
                Location* punch = s->locations()->auto_punch_location ();
-               
+
                if (punch) {
                        watch_punch (punch);
                }
-               
+
                punch_changed (punch);
 
-               _session->auto_punch_location_changed.connect (_session_connections, MISSING_INVALIDATOR, 
+               _session->auto_punch_location_changed.connect (_session_connections, MISSING_INVALIDATOR,
                                                               boost::bind (&TimeInfoBox::punch_location_changed, this, _1), gui_context());
        }
 }
@@ -236,50 +265,40 @@ TimeInfoBox::selection_changed ()
 
        switch (Editor::instance().current_mouse_mode()) {
 
+       case Editing::MouseContent:
+               /* displaying MIDI note selection is tricky */
+               selection_start->set_off (true);
+               selection_end->set_off (true);
+               selection_length->set_off (true);
+               break;
+
        case Editing::MouseObject:
-               if (Editor::instance().internal_editing()) {
-                       /* displaying MIDI note selection is tricky */
-                       
-                       selection_start->set_off (true);
-                       selection_end->set_off (true);
-                       selection_length->set_off (true);
+               if (selection.regions.empty()) {
+                       if (selection.points.empty()) {
+                               Glib::RefPtr<Action> act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range");
+                               Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
 
-               } else {
-                       if (selection.regions.empty()) {
-                               if (selection.points.empty()) {
-                                       Glib::RefPtr<Action> act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range");
-                                       Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
-
-                                       if (tact && tact->get_active() && !selection.time.empty()) {
-                                               /* show selected range */
-                                               selection_start->set_off (false);
-                                               selection_end->set_off (false);
-                                               selection_length->set_off (false);
-                                               selection_start->set (selection.time.start());
-                                               selection_end->set (selection.time.end_frame());
-                                               selection_length->set (selection.time.length());
-                                       } else {
-                                               selection_start->set_off (true);
-                                               selection_end->set_off (true);
-                                               selection_length->set_off (true);
-                                       }
-                               } else {
-                                       s = max_framepos;
-                                       e = 0;
-                                       for (PointSelection::iterator i = selection.points.begin(); i != selection.points.end(); ++i) {
-                                               s = min (s, (framepos_t) i->start);
-                                               e = max (e, (framepos_t) i->end);
-                                       }
+                               if (tact && tact->get_active() && !selection.time.empty()) {
+                                       /* show selected range */
                                        selection_start->set_off (false);
                                        selection_end->set_off (false);
                                        selection_length->set_off (false);
-                                       selection_start->set (s);
-                                       selection_end->set (e);
-                                       selection_length->set (e - s + 1);
+                                       selection_start->set (selection.time.start());
+                                       selection_end->set (selection.time.end_frame());
+                                       selection_length->set (selection.time.length());
+                               } else {
+                                       selection_start->set_off (true);
+                                       selection_end->set_off (true);
+                                       selection_length->set_off (true);
                                }
                        } else {
-                               s = selection.regions.start();
-                               e = selection.regions.end_frame();
+                               s = max_framepos;
+                               e = 0;
+                               for (PointSelection::iterator i = selection.points.begin(); i != selection.points.end(); ++i) {
+                                       framepos_t const p = (*i)->line().session_position ((*i)->model ());
+                                       s = min (s, p);
+                                       e = max (e, p);
+                               }
                                selection_start->set_off (false);
                                selection_end->set_off (false);
                                selection_length->set_off (false);
@@ -287,6 +306,15 @@ TimeInfoBox::selection_changed ()
                                selection_end->set (e);
                                selection_length->set (e - s + 1);
                        }
+               } else {
+                       s = selection.regions.start();
+                       e = selection.regions.end_frame();
+                       selection_start->set_off (false);
+                       selection_end->set_off (false);
+                       selection_length->set_off (false);
+                       selection_start->set (s);
+                       selection_end->set (e);
+                       selection_length->set (e - s + 1);
                }
                break;
 
@@ -295,7 +323,7 @@ TimeInfoBox::selection_changed ()
                        Glib::RefPtr<Action> act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range");
                        Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
 
-                       if (tact && tact->get_active() &&  !selection.regions.empty()) {        
+                       if (tact && tact->get_active() &&  !selection.regions.empty()) {
                                /* show selected regions */
                                s = selection.regions.start();
                                e = selection.regions.end_frame();
@@ -323,7 +351,7 @@ TimeInfoBox::selection_changed ()
        default:
                selection_start->set_off (true);
                selection_end->set_off (true);
-               selection_length->set_off (true);       
+               selection_length->set_off (true);
                break;
        }
 }
@@ -333,7 +361,7 @@ TimeInfoBox::punch_location_changed (Location* loc)
 {
        if (loc) {
                watch_punch (loc);
-       } 
+       }
 }
 
 void
@@ -361,5 +389,5 @@ TimeInfoBox::punch_changed (Location* loc)
 
        punch_start->set (loc->start());
        punch_end->set (loc->end());
-}      
+}