Move control surface options into RC prefs editor. Remove Options menu.
[ardour.git] / gtk2_ardour / audio_clock.cc
index e1b80cc0731bf6e8a1679032da3c256f4b925b0c..28110c685fa70cab14203c985b6d6fe4ef1deb24 100644 (file)
 #include <cstdio> // for sprintf
 #include <cmath>
 
-#include <pbd/convert.h>
-#include <pbd/enumwriter.h>
+#include "pbd/convert.h"
+#include "pbd/enumwriter.h"
 
 #include <gtkmm2ext/utils.h>
 
-#include <ardour/ardour.h>
-#include <ardour/session.h>
-#include <ardour/tempo.h>
-#include <ardour/profile.h>
+#include "ardour/ardour.h"
+#include "ardour/session.h"
+#include "ardour/tempo.h"
+#include "ardour/profile.h"
 #include <sigc++/bind.h>
 
 #include "ardour_ui.h"
@@ -74,7 +74,8 @@ AudioClock::AudioClock (std::string clock_name, bool transient, std::string widg
          colon4 (":"),
          colon5 (":"),
          b1 ("|"),
-         b2 ("|")
+         b2 ("|"),
+         last_when(0)
 {
        session = 0;
        last_when = 0;
@@ -83,7 +84,8 @@ AudioClock::AudioClock (std::string clock_name, bool transient, std::string widg
        key_entry_state = 0;
        ops_menu = 0;
        dragging = false;
-       
+       bbt_reference_time = -1;
+
        if (with_info) {
                frames_upper_info_label = manage (new Label);
                frames_lower_info_label = manage (new Label);
@@ -102,6 +104,9 @@ AudioClock::AudioClock (std::string clock_name, bool transient, std::string widg
                Gtkmm2ext::set_size_request_to_display_given_text(*smpte_upper_info_label, "23.98",0,0);
                Gtkmm2ext::set_size_request_to_display_given_text(*smpte_lower_info_label, "NDF",0,0);
 
+               Gtkmm2ext::set_size_request_to_display_given_text(*bbt_upper_info_label, "88|88",0,0);
+               Gtkmm2ext::set_size_request_to_display_given_text(*bbt_lower_info_label, "888.88",0,0);
+
                frames_info_box.pack_start (*frames_upper_info_label, true, true);
                frames_info_box.pack_start (*frames_lower_info_label, true, true);
                smpte_info_box.pack_start (*smpte_upper_info_label, true, true);
@@ -504,7 +509,7 @@ AudioClock::set_frames (nframes_t when, bool force)
                        frames_upper_info_label->set_text (buf);
                }
                
-               float vid_pullup = Config->get_video_pullup();
+               float vid_pullup = session->config.get_video_pullup();
                
                if (vid_pullup == 0.0) {
                        if (frames_lower_info_label->get_text () != _("none")) {
@@ -631,16 +636,45 @@ AudioClock::set_bbt (nframes_t when, bool force)
        char buf[16];
        BBT_Time bbt;
 
-       session->tempo_map().bbt_time (when, bbt);
+       /* handle a common case */
+       if (is_duration) {
+               if (when == 0) {
+                       bbt.bars = 0;
+                       bbt.beats = 0;
+                       bbt.ticks = 0;  
+               } else {
+                       session->tempo_map().bbt_time (when, bbt);
+                       bbt.bars--;
+                       bbt.beats--;
+               }
+       } else {
+               session->tempo_map().bbt_time (when, bbt);
+       }
+
        sprintf (buf, "%03" PRIu32, bbt.bars);
-       bars_label.set_text (buf);
+       if (force || bars_label.get_text () != buf) {
+               bars_label.set_text (buf);
+       }
        sprintf (buf, "%02" PRIu32, bbt.beats);
-       beats_label.set_text (buf);
+       if (force || beats_label.get_text () != buf) {
+               beats_label.set_text (buf);
+       }
        sprintf (buf, "%04" PRIu32, bbt.ticks);
-       ticks_label.set_text (buf);
+       if (force || ticks_label.get_text () != buf) {
+               ticks_label.set_text (buf);
+       }
        
        if (bbt_upper_info_label) {
-               TempoMap::Metric m (session->tempo_map().metric_at (when));
+               nframes64_t pos;
+
+               if (bbt_reference_time < 0) {
+                       pos = when;
+               } else {
+                       pos = bbt_reference_time;
+               }
+
+               TempoMap::Metric m (session->tempo_map().metric_at (pos));
+
                sprintf (buf, "%-5.2f", m.tempo().beats_per_minute());
                if (bbt_lower_info_label->get_text() != buf) {
                        bbt_lower_info_label->set_text (buf);
@@ -808,13 +842,15 @@ AudioClock::field_key_release_event (GdkEventKey *ev, Field field)
                break;
 
        case GDK_Tab:
+       case GDK_Return:
+       case GDK_KP_Enter:
                move_on = true;
                break;
 
        case GDK_Escape:
-       case GDK_Return:
-       case GDK_KP_Enter:
+               key_entry_state = 0;
                clock_base.grab_focus ();
+               ChangeAborted();  /*  EMIT SIGNAL  */
                return true;
 
        default:
@@ -940,6 +976,13 @@ AudioClock::field_key_release_event (GdkEventKey *ev, Field field)
 
        }
 
+       //if user hit Enter, lose focus
+       switch (ev->keyval) {
+       case GDK_Return:
+       case GDK_KP_Enter:
+               clock_base.grab_focus ();
+       }
+
        return true;
 }
 
@@ -1859,6 +1902,11 @@ AudioClock::bbt_frame_from_display (nframes_t pos) const
        any.bbt.beats = atoi (beats_label.get_text());
        any.bbt.ticks = atoi (ticks_label.get_text());
 
+       if (is_duration) {
+               any.bbt.bars++;
+               any.bbt.beats++;
+       }
+
        nframes_t ret = session->convert_to_frames_at (pos, any);
 
        return ret;
@@ -1956,6 +2004,7 @@ AudioClock::set_mode (Mode m)
 
        if (!is_transient) {
                ModeChanged (); /* EMIT SIGNAL */
+               mode_changed (); /* EMIT SIGNAL */
        }
 }
 
@@ -1994,3 +2043,9 @@ AudioClock::set_size_requests ()
                
        }
 }
+
+void
+AudioClock::set_bbt_reference (nframes64_t pos)
+{
+       bbt_reference_time = pos;
+}