Remove unused variable and the accessor methods for it from ARDOUR_UI
[ardour.git] / gtk2_ardour / audio_clock.cc
index 270da7ab119795e75e5a10cc25cc067aea360cca..8c24f429984e87ee89a637d9518fccb4cb2f8d70 100644 (file)
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #include <cstdio> // for sprintf
 #include <cmath>
 
 #include <pbd/convert.h>
+#include <pbd/enumwriter.h>
 
 #include <gtkmm2ext/utils.h>
 
@@ -40,10 +40,14 @@ using namespace ARDOUR;
 using namespace PBD;
 using namespace sigc;
 using namespace Gtk;
+using namespace std;
 
 using PBD::atoi;
 using PBD::atof;
 
+sigc::signal<void> AudioClock::ModeChanged;
+vector<AudioClock*> AudioClock::clocks;
+
 const uint32_t AudioClock::field_length[(int) AudioClock::AudioFrames+1] = {
        2,   /* SMPTE_Hours */
        2,   /* SMPTE_Minutes */
@@ -58,8 +62,10 @@ const uint32_t AudioClock::field_length[(int) AudioClock::AudioFrames+1] = {
        10   /* Audio Frame */
 };
 
-AudioClock::AudioClock (const string& name, bool allow_edit, bool duration, bool with_extras) 
-       : is_duration (duration),
+AudioClock::AudioClock (std::string clock_name, bool transient, std::string widget_name, bool allow_edit, bool duration, bool with_info) 
+       : _name (clock_name),
+         is_transient (transient),
+         is_duration (duration),
          editable (allow_edit),
          colon1 (":"),
          colon2 (":"),
@@ -71,13 +77,57 @@ AudioClock::AudioClock (const string& name, bool allow_edit, bool duration, bool
 {
        session = 0;
        last_when = 0;
+       last_pdelta = 0;
+       last_sdelta = 0;
        key_entry_state = 0;
        ops_menu = 0;
        dragging = false;
        
+       if (with_info) {
+               frames_upper_info_label = manage (new Label);
+               frames_lower_info_label = manage (new Label);
+               smpte_upper_info_label = manage (new Label);
+               smpte_lower_info_label = manage (new Label);
+               bbt_upper_info_label = manage (new Label);
+               bbt_lower_info_label = manage (new Label);
+               
+               frames_upper_info_label->set_name ("AudioClockFramesUpperInfo");
+               frames_lower_info_label->set_name ("AudioClockFramesLowerInfo");
+               smpte_upper_info_label->set_name ("AudioClockSMPTEUpperInfo");
+               smpte_lower_info_label->set_name ("AudioClockSMPTELowerInfo");
+               bbt_upper_info_label->set_name ("AudioClockBBTUpperInfo");
+               bbt_lower_info_label->set_name ("AudioClockBBTLowerInfo");
+
+               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);
+
+               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);
+               smpte_info_box.pack_start (*smpte_lower_info_label, true, true);
+               bbt_info_box.pack_start (*bbt_upper_info_label, true, true);
+               bbt_info_box.pack_start (*bbt_lower_info_label, true, true);
+               
+       } else {
+               frames_upper_info_label = 0;
+               frames_lower_info_label = 0;
+               smpte_upper_info_label = 0;
+               smpte_lower_info_label = 0;
+               bbt_upper_info_label = 0;
+               bbt_lower_info_label = 0;
+       }       
+       
        audio_frames_ebox.add (audio_frames_label);
-       frames_packer_hbox.set_border_width (2);
-       frames_packer_hbox.pack_start (audio_frames_ebox, false, false);
+       
+       frames_packer.set_homogeneous (false);
+       frames_packer.set_border_width (2);
+       frames_packer.pack_start (audio_frames_ebox, false, false);
+       
+       if (with_info) {
+               frames_packer.pack_start (frames_info_box, false, false, 5);
+       }
+       
+       frames_packer_hbox.pack_start (frames_packer, true, false);
 
        hours_ebox.add (hours_label);
        minutes_ebox.add (minutes_label);
@@ -100,6 +150,10 @@ AudioClock::AudioClock (const string& name, bool allow_edit, bool duration, bool
        smpte_packer.pack_start (colon3, false, false);
        smpte_packer.pack_start (frames_ebox, false, false);
 
+       if (with_info) {
+               smpte_packer.pack_start (smpte_info_box, false, false, 5);
+       }
+
        smpte_packer_hbox.pack_start (smpte_packer, true, false);
 
        bbt_packer.set_homogeneous (false);
@@ -110,34 +164,8 @@ AudioClock::AudioClock (const string& name, bool allow_edit, bool duration, bool
        bbt_packer.pack_start (b2, false, false);
        bbt_packer.pack_start (ticks_ebox, false, false);
 
-       if (with_extras) {
-
-               framerate_label = manage (new Label);
-               pullup_label = manage (new Label);
-
-               framerate_label->set_name ("BBTMeterLabel");
-               pullup_label->set_name ("BBTTempoLabel");
-
-               rate_pullup_box.pack_start (*framerate_label, true, true);
-               rate_pullup_box.pack_start (*pullup_label, true, true);
-
-               smpte_packer.pack_start (rate_pullup_box, false,false, 5);
-
-               meter_label = manage (new Label);
-               tempo_label = manage (new Label);
-
-               meter_label->set_name ("BBTMeterLabel");
-               tempo_label->set_name ("BBTTempoLabel");
-
-               tempo_meter_box.pack_start (*meter_label, true, true);
-               tempo_meter_box.pack_start (*tempo_label, true, true);
-
-               bbt_packer.pack_start (tempo_meter_box, false, false, 5);
-       } else {
-               framerate_label = 0;
-               pullup_label = 0;
-               meter_label = 0;
-               tempo_label = 0;
+       if (with_info) {
+               bbt_packer.pack_start (bbt_info_box, false, false, 5);
        }
 
        bbt_packer_hbox.pack_start (bbt_packer, true, false);
@@ -152,7 +180,50 @@ AudioClock::AudioClock (const string& name, bool allow_edit, bool duration, bool
 
        minsec_packer_hbox.pack_start (minsec_packer, true, false);
 
-       set_name (name);
+       clock_frame.set_shadow_type (Gtk::SHADOW_IN);
+       clock_frame.set_name ("BaseFrame");
+
+       clock_frame.add (clock_base);
+
+       set_widget_name (widget_name);
+
+       _mode = BBT; /* lie to force mode switch */
+       set_mode (SMPTE);
+
+       pack_start (clock_frame, true, true);
+
+       /* the clock base handles button releases for menu popup regardless of
+          editable status. if the clock is editable, the clock base is where
+          we pass focus to after leaving the last editable "field", which
+          will then shutdown editing till the user starts it up again.
+
+          it does this because the focus out event on the field disables
+          keyboard event handling, and we don't connect anything up to
+          notice focus in on the clock base. hence, keyboard event handling
+          stays disabled.
+       */
+
+       clock_base.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
+       clock_base.signal_button_release_event().connect (bind (mem_fun (*this, &AudioClock::field_button_release_event), SMPTE_Hours));
+
+       Session::SMPTEOffsetChanged.connect (mem_fun (*this, &AudioClock::smpte_offset_changed));
+
+       if (editable) {
+               setup_events ();
+       }
+
+       set (last_when, true);
+
+       if (!is_transient) {
+               clocks.push_back (this);
+       }
+}
+
+void
+AudioClock::set_widget_name (string name)
+{
+       Widget::set_name (name);
+
        clock_base.set_name (name);
 
        audio_frames_label.set_name (name);
@@ -186,37 +257,7 @@ AudioClock::AudioClock (const string& name, bool allow_edit, bool duration, bool
        b1.set_name (name);
        b2.set_name (name);
 
-       clock_frame.set_shadow_type (Gtk::SHADOW_IN);
-       clock_frame.set_name ("BaseFrame");
-
-       clock_frame.add (clock_base);
-
-       _mode = BBT; /* lie to force mode switch */
-       set_mode (SMPTE);
-
-       pack_start (clock_frame, true, true);
-
-       /* the clock base handles button releases for menu popup regardless of
-          editable status. if the clock is editable, the clock base is where
-          we pass focus to after leaving the last editable "field", which
-          will then shutdown editing till the user starts it up again.
-
-          it does this because the focus out event on the field disables
-          keyboard event handling, and we don't connect anything up to
-          notice focus in on the clock base. hence, keyboard event handling
-          stays disabled.
-       */
-
-       clock_base.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
-       clock_base.signal_button_release_event().connect (bind (mem_fun (*this, &AudioClock::field_button_release_event), SMPTE_Hours));
-
-       Session::SMPTEOffsetChanged.connect (mem_fun (*this, &AudioClock::smpte_offset_changed));
-
-       if (editable) {
-               setup_events ();
-       }
-
-       set (last_when, true);
+       queue_draw ();
 }
 
 void
@@ -344,17 +385,40 @@ AudioClock::on_realize ()
 }
 
 void
-AudioClock::set (nframes_t when, bool force)
+AudioClock::set (nframes_t when, bool force, nframes_t offset, char which)
 {
 
        if ((!force && !is_visible()) || session == 0) {
                return;
        }
        
-       if (when == last_when && !force) {
+       if (when == last_when && !offset && !force) {
                return;
        }
 
+       bool pdelta = Config->get_primary_clock_delta_edit_cursor();
+       bool sdelta = Config->get_secondary_clock_delta_edit_cursor();
+
+       if (offset && which == 'p' && pdelta) {
+               when = (when > offset) ? when - offset : offset - when;
+       } else if (offset && which == 's' && sdelta) {
+               when = (when > offset) ? when - offset : offset - when;
+       }
+
+       if (which == 'p' && pdelta && !last_pdelta) {
+               set_widget_name("TransportClockDisplayDelta");
+               last_pdelta = true;
+       } else if (which == 'p' && !pdelta && last_pdelta) {
+               set_widget_name("TransportClockDisplay");
+               last_pdelta = false;
+       } else if (which == 's'  && sdelta && !last_sdelta) {
+               set_widget_name("SecondaryClockDisplayDelta");
+               last_sdelta = true;
+       } else if (which == 's' && !sdelta && last_sdelta) {
+               set_widget_name("SecondaryClockDisplay");
+               last_sdelta = false;
+       }
+
        switch (_mode) {
        case SMPTE:
                set_smpte (when, force);
@@ -404,6 +468,27 @@ AudioClock::set_frames (nframes_t when, bool force)
        char buf[32];
        snprintf (buf, sizeof (buf), "%u", when);
        audio_frames_label.set_text (buf);
+       
+       if (frames_upper_info_label) {
+               nframes_t rate = session->frame_rate();
+               
+               if (fmod (rate, 1000.0) == 0.000) {
+                       sprintf (buf, "%uK", rate/1000);
+               } else {
+                       sprintf (buf, "%.3fK", rate/1000.0f);
+               }
+               
+               frames_upper_info_label->set_text (buf);
+               
+               float vid_pullup = Config->get_video_pullup();
+               
+               if (vid_pullup == 0.0) {
+                       frames_lower_info_label->set_text(_("none"));
+               } else {
+                       sprintf (buf, "%-6.4f", vid_pullup);
+                       frames_lower_info_label->set_text (buf);
+               }
+       }
 }      
 
 void
@@ -481,19 +566,25 @@ AudioClock::set_smpte (nframes_t when, bool force)
                frames_label.set_text (buf);
                last_frames = smpte.frames;
        }
-
-       if (framerate_label) {
-               sprintf (buf, "%-5.2f", Config->get_smpte_frames_per_second());
-               framerate_label->set_text (buf);
-
-               float x = Config->get_video_pullup();
-
-               if (x == 0.0) {
-                       pullup_label->set_text (_("none"));
+       
+       if (smpte_upper_info_label) {
+               double smpte_frames = session->smpte_frames_per_second();
+               
+               if ( fmod(smpte_frames, 1.0) == 0.0) {
+                       sprintf (buf, "%u", int (smpte_frames)); 
+               } else {
+                       sprintf (buf, "%.2f", smpte_frames);
+               }
+               
+               smpte_upper_info_label->set_text (buf);
+               
+               if (session->smpte_drop_frames()) {
+                       sprintf (buf, "DF");
                } else {
-                       sprintf (buf, "%-6.4f", x);
-                       pullup_label->set_text (buf);
+                       sprintf (buf, "NDF");
                }
+               
+               smpte_lower_info_label->set_text (buf);
        }
 }
 
@@ -511,12 +602,12 @@ AudioClock::set_bbt (nframes_t when, bool force)
        sprintf (buf, "%04" PRIu32, bbt.ticks);
        ticks_label.set_text (buf);
        
-       if (meter_label) {
+       if (bbt_upper_info_label) {
                TempoMap::Metric m (session->tempo_map().metric_at (when));
                sprintf (buf, "%-5.2f", m.tempo().beats_per_minute());
-               tempo_label->set_text (buf);
+               bbt_lower_info_label->set_text (buf);
                sprintf (buf, "%g|%g", m.meter().beats_per_bar(), m.meter().note_divisor());
-               meter_label->set_text (buf);
+               bbt_upper_info_label->set_text (buf);
        }
 }
 
@@ -526,6 +617,18 @@ AudioClock::set_session (Session *s)
        session = s;
 
        if (s) {
+
+               XMLProperty* prop;
+               XMLNode* node = session->extra_xml (X_("ClockModes"));
+               AudioClock::Mode amode;
+               
+               if (node) {
+                       if ((prop = node->property (_name)) != 0) {
+                               amode = AudioClock::Mode (string_2_enum (prop->value(), amode));
+                               set_mode (amode);
+                       }
+               }
+
                set (last_when, true);
        }
 }
@@ -689,6 +792,17 @@ AudioClock::field_key_release_event (GdkEventKey *ev, Field field)
                                // Check SMPTE fields for sanity (may also adjust fields)
                                smpte_sanitize_display();
                                break;
+                       case Bars:
+                       case Beats:
+                       case Ticks:
+                               // Bars or beats should never be 0
+                               if (atoi(bars_label.get_text()) == 0) {
+                                       bars_label.set_text("001");
+                               }
+                               if (atoi(beats_label.get_text()) == 0) {
+                                       beats_label.set_text("01");
+                               }
+                               break;
                        default:
                                break;
                        }
@@ -984,39 +1098,6 @@ AudioClock::field_button_press_event (GdkEventButton *ev, Field field)
                return FALSE;
                break;
 
-       case 4:
-               if (Keyboard::modifier_state_equals (ev->state, Keyboard::Shift)) {
-                       frames = get_frames (field);
-                       if (frames != 0) {
-                               if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
-                                       frames *= 10;
-                               }
-                               set (current_time() + frames, true);
-                                ValueChanged (); /* EMIT_SIGNAL */
-                       }
-               }
-               break;
-
-       case 5:
-               if (Keyboard::modifier_state_equals (ev->state, Keyboard::Shift)) {
-                       frames = get_frames (field);
-                       if (frames != 0) {
-                               if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
-                                       frames *= 10;
-                               }
-
-                               if ((double)current_time() - (double)frames < 0.0) {
-                                       set (0, true);
-                               }
-                               else {
-                                       set (current_time() - frames, true);
-                               }
-                               
-                                ValueChanged (); /* EMIT_SIGNAL */
-                       }
-               }
-               break;
-
        default:
                return FALSE;
                break;
@@ -1141,7 +1222,7 @@ AudioClock::get_frames (Field field,nframes_t pos,int dir)
                frames = session->frame_rate();
                break;
        case SMPTE_Frames:
-               frames = (nframes_t) floor (session->frame_rate() / Config->get_smpte_frames_per_second());
+               frames = (nframes_t) floor (session->frame_rate() / session->smpte_frames_per_second());
                break;
 
        case AudioFrames:
@@ -1249,7 +1330,7 @@ AudioClock::smpte_sanitize_display()
                seconds_label.set_text("59");
        }
        
-       switch ((long)rint(Config->get_smpte_frames_per_second())) {
+       switch ((long)rint(session->smpte_frames_per_second())) {
        case 24:
                if (atoi(frames_label.get_text()) > 23) {
                        frames_label.set_text("23");
@@ -1269,7 +1350,7 @@ AudioClock::smpte_sanitize_display()
                break;
        }
        
-       if (Config->get_smpte_drop_frames()) {
+       if (session->smpte_drop_frames()) {
                if ((atoi(minutes_label.get_text()) % 10) && (atoi(seconds_label.get_text()) == 0) && (atoi(frames_label.get_text()) < 2)) {
                        frames_label.set_text("02");
                }
@@ -1290,6 +1371,8 @@ AudioClock::smpte_frame_from_display () const
        smpte.minutes = atoi (minutes_label.get_text());
        smpte.seconds = atoi (seconds_label.get_text());
        smpte.frames = atoi (frames_label.get_text());
+       smpte.rate = session->smpte_frames_per_second();
+       smpte.drop= session->smpte_drop_frames();
 
        session->smpte_to_sample( smpte, sample, false /* use_offset */, false /* use_subframes */ );
        
@@ -1803,6 +1886,10 @@ AudioClock::set_mode (Mode m)
        set (last_when, true);
        clock_base.show_all ();
        key_entry_state = 0;
+
+       if (!is_transient) {
+               ModeChanged (); /* EMIT SIGNAL */
+       }
 }
 
 void
@@ -1812,26 +1899,26 @@ AudioClock::set_size_requests ()
 
        switch (_mode) {
        case SMPTE:
-               Gtkmm2ext::set_size_request_to_display_given_text (hours_label, "-88", 2, 2);
-               Gtkmm2ext::set_size_request_to_display_given_text (minutes_label, "88", 2, 2);
-               Gtkmm2ext::set_size_request_to_display_given_text (seconds_label, "88", 2, 2);
-               Gtkmm2ext::set_size_request_to_display_given_text (frames_label, "88", 2, 2);
+               Gtkmm2ext::set_size_request_to_display_given_text (hours_label, "-00", 5, 5);
+               Gtkmm2ext::set_size_request_to_display_given_text (minutes_label, "00", 5, 5);
+               Gtkmm2ext::set_size_request_to_display_given_text (seconds_label, "00", 5, 5);
+               Gtkmm2ext::set_size_request_to_display_given_text (frames_label, "00", 5, 5);
                break;
 
        case BBT:
-               Gtkmm2ext::set_size_request_to_display_given_text (bars_label, "-888", 2, 2);
-               Gtkmm2ext::set_size_request_to_display_given_text (beats_label, "88", 2, 2);
-               Gtkmm2ext::set_size_request_to_display_given_text (ticks_label, "8888", 2, 2);
+               Gtkmm2ext::set_size_request_to_display_given_text (bars_label, "-000", 5, 5);
+               Gtkmm2ext::set_size_request_to_display_given_text (beats_label, "00", 5, 5);
+               Gtkmm2ext::set_size_request_to_display_given_text (ticks_label, "0000", 5, 5);
                break;
 
        case MinSec:
-               Gtkmm2ext::set_size_request_to_display_given_text (ms_hours_label, "99", 2, 2);
-               Gtkmm2ext::set_size_request_to_display_given_text (ms_minutes_label, "99", 2, 2);
-               Gtkmm2ext::set_size_request_to_display_given_text (ms_seconds_label, "99.999", 2, 2);
+               Gtkmm2ext::set_size_request_to_display_given_text (ms_hours_label, "00", 5, 5);
+               Gtkmm2ext::set_size_request_to_display_given_text (ms_minutes_label, "00", 5, 5);
+               Gtkmm2ext::set_size_request_to_display_given_text (ms_seconds_label, "00.000", 5, 5);
                break;
 
        case Frames:
-               Gtkmm2ext::set_size_request_to_display_given_text (audio_frames_label, "4294967296", 2, 2);
+               Gtkmm2ext::set_size_request_to_display_given_text (audio_frames_label, "0000000000", 5, 5);
                break;
 
        case Off: