X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Faudio_clock.cc;h=39af8bee7ddb69a37bae5ae6c1e628ef22937db7;hb=b529cbc5dc0b92f01ff01d5f40786ff025fbb63b;hp=8c6f3a7d8277f7ffddafe4f9821a7b708b89ff2f;hpb=912da52a539981193941d8739fa6f103b5e406db;p=ardour.git diff --git a/gtk2_ardour/audio_clock.cc b/gtk2_ardour/audio_clock.cc index 8c6f3a7d82..39af8bee7d 100644 --- a/gtk2_ardour/audio_clock.cc +++ b/gtk2_ardour/audio_clock.cc @@ -58,7 +58,7 @@ 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_tempo_and_meter) +AudioClock::AudioClock (std::string name, bool allow_edit, bool duration, bool with_info) : is_duration (duration), editable (allow_edit), colon1 (":"), @@ -75,9 +75,51 @@ AudioClock::AudioClock (const string& name, bool allow_edit, bool duration, bool 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 +142,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,20 +156,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_tempo_and_meter) { - 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 { - 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); @@ -138,7 +172,46 @@ AudioClock::AudioClock (const string& name, bool allow_edit, bool duration, bool minsec_packer_hbox.pack_start (minsec_packer, true, false); + clock_frame.set_shadow_type (Gtk::SHADOW_IN); + clock_frame.set_name ("BaseFrame"); + + clock_frame.add (clock_base); + set_name (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); +} + +void +AudioClock::set_name (string name) +{ + Widget::set_name (name); + clock_base.set_name (name); audio_frames_label.set_name (name); @@ -172,37 +245,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 @@ -326,38 +369,11 @@ AudioClock::on_realize () /* styles are not available until the widgets are bound to a window */ - switch (_mode) { - case SMPTE: - Gtkmm2ext::set_size_request_to_display_given_text (hours_label, "-88", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (minutes_label, "88", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (seconds_label, "88", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (frames_label, "88", 0, 2); - break; - - case BBT: - Gtkmm2ext::set_size_request_to_display_given_text (bars_label, "-888", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (beats_label, "88", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (ticks_label, "8888", 0, 2); - break; - - case MinSec: - Gtkmm2ext::set_size_request_to_display_given_text (ms_hours_label, "99", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (ms_minutes_label, "99", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (ms_seconds_label, "99", 0, 2); - break; - - case Frames: - Gtkmm2ext::set_size_request_to_display_given_text (audio_frames_label, "4294967296", 0, 2); - break; - - case Off: - break; - - } + set_size_requests (); } void -AudioClock::set (jack_nframes_t when, bool force) +AudioClock::set (nframes_t when, bool force) { if ((!force && !is_visible()) || session == 0) { @@ -395,7 +411,7 @@ AudioClock::set (jack_nframes_t when, bool force) void AudioClock::smpte_offset_changed () { - jack_nframes_t current; + nframes_t current; switch (_mode) { case SMPTE: @@ -412,37 +428,58 @@ AudioClock::smpte_offset_changed () } void -AudioClock::set_frames (jack_nframes_t when, bool force) +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 -AudioClock::set_minsec (jack_nframes_t when, bool force) +AudioClock::set_minsec (nframes_t when, bool force) { char buf[32]; - jack_nframes_t left; + nframes_t left; int hrs; int mins; float secs; left = when; hrs = (int) floor (left / (session->frame_rate() * 60.0f * 60.0f)); - left -= (jack_nframes_t) floor (hrs * session->frame_rate() * 60.0f * 60.0f); + left -= (nframes_t) floor (hrs * session->frame_rate() * 60.0f * 60.0f); mins = (int) floor (left / (session->frame_rate() * 60.0f)); - left -= (jack_nframes_t) floor (mins * session->frame_rate() * 60.0f); + left -= (nframes_t) floor (mins * session->frame_rate() * 60.0f); secs = left / (float) session->frame_rate(); if (force || hrs != ms_last_hrs) { - sprintf (buf, "%d", hrs); + sprintf (buf, "%02d", hrs); ms_hours_label.set_text (buf); ms_last_hrs = hrs; } if (force || mins != ms_last_mins) { - sprintf (buf, "%d", mins); + sprintf (buf, "%02d", mins); ms_minutes_label.set_text (buf); ms_last_mins = mins; } @@ -455,7 +492,7 @@ AudioClock::set_minsec (jack_nframes_t when, bool force) } void -AudioClock::set_smpte (jack_nframes_t when, bool force) +AudioClock::set_smpte (nframes_t when, bool force) { char buf[32]; SMPTE::Time smpte; @@ -494,10 +531,30 @@ AudioClock::set_smpte (jack_nframes_t when, bool force) frames_label.set_text (buf); last_frames = smpte.frames; } + + if (smpte_upper_info_label) { + float 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, "NDF"); + } + + smpte_lower_info_label->set_text (buf); + } } void -AudioClock::set_bbt (jack_nframes_t when, bool force) +AudioClock::set_bbt (nframes_t when, bool force) { char buf[16]; BBT_Time bbt; @@ -510,12 +567,12 @@ AudioClock::set_bbt (jack_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); } } @@ -952,7 +1009,7 @@ AudioClock::field_button_press_event (GdkEventButton *ev, Field field) { if (session == 0) return FALSE; - jack_nframes_t frames = 0; + nframes_t frames = 0; switch (ev->button) { case 1: @@ -1029,7 +1086,7 @@ AudioClock::field_button_scroll_event (GdkEventScroll *ev, Field field) { if (session == 0) return FALSE; - jack_nframes_t frames = 0; + nframes_t frames = 0; switch (ev->direction) { @@ -1098,8 +1155,8 @@ AudioClock::field_motion_notify_event (GdkEventMotion *ev, Field field) if (trunc(drag_accum) != 0) { - jack_nframes_t frames; - jack_nframes_t pos ; + nframes_t frames; + nframes_t pos ; int dir; dir = (drag_accum < 0 ? 1:-1); pos = current_time(); @@ -1107,7 +1164,7 @@ AudioClock::field_motion_notify_event (GdkEventMotion *ev, Field field) if (frames != 0 && frames * drag_accum < current_time()) { - set ((jack_nframes_t) floor (pos - drag_accum * frames), false); // minus because up is negative in computer-land + set ((nframes_t) floor (pos - drag_accum * frames), false); // minus because up is negative in computer-land } else { set (0 , false); @@ -1123,24 +1180,24 @@ AudioClock::field_motion_notify_event (GdkEventMotion *ev, Field field) return TRUE; } -jack_nframes_t -AudioClock::get_frames (Field field,jack_nframes_t pos,int dir) +nframes_t +AudioClock::get_frames (Field field,nframes_t pos,int dir) { - jack_nframes_t frames = 0; + nframes_t frames = 0; BBT_Time bbt; switch (field) { case SMPTE_Hours: - frames = (jack_nframes_t) floor (3600.0 * session->frame_rate()); + frames = (nframes_t) floor (3600.0 * session->frame_rate()); break; case SMPTE_Minutes: - frames = (jack_nframes_t) floor (60.0 * session->frame_rate()); + frames = (nframes_t) floor (60.0 * session->frame_rate()); break; case SMPTE_Seconds: frames = session->frame_rate(); break; case SMPTE_Frames: - frames = (jack_nframes_t) floor (session->frame_rate() / session->smpte_frames_per_second); + frames = (nframes_t) floor (session->frame_rate() / session->smpte_frames_per_second()); break; case AudioFrames: @@ -1148,10 +1205,10 @@ AudioClock::get_frames (Field field,jack_nframes_t pos,int dir) break; case MS_Hours: - frames = (jack_nframes_t) floor (3600.0 * session->frame_rate()); + frames = (nframes_t) floor (3600.0 * session->frame_rate()); break; case MS_Minutes: - frames = (jack_nframes_t) floor (60.0 * session->frame_rate()); + frames = (nframes_t) floor (60.0 * session->frame_rate()); break; case MS_Seconds: frames = session->frame_rate(); @@ -1180,10 +1237,10 @@ AudioClock::get_frames (Field field,jack_nframes_t pos,int dir) return frames; } -jack_nframes_t -AudioClock::current_time (jack_nframes_t pos) const +nframes_t +AudioClock::current_time (nframes_t pos) const { - jack_nframes_t ret = 0; + nframes_t ret = 0; switch (_mode) { case SMPTE: @@ -1208,10 +1265,10 @@ AudioClock::current_time (jack_nframes_t pos) const return ret; } -jack_nframes_t -AudioClock::current_duration (jack_nframes_t pos) const +nframes_t +AudioClock::current_duration (nframes_t pos) const { - jack_nframes_t ret = 0; + nframes_t ret = 0; switch (_mode) { case SMPTE: @@ -1248,7 +1305,7 @@ AudioClock::smpte_sanitize_display() seconds_label.set_text("59"); } - switch ((long)rint(session->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"); @@ -1268,14 +1325,14 @@ AudioClock::smpte_sanitize_display() break; } - if (session->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"); } } } -jack_nframes_t +nframes_t AudioClock::smpte_frame_from_display () const { if (session == 0) { @@ -1283,12 +1340,14 @@ AudioClock::smpte_frame_from_display () const } SMPTE::Time smpte; - jack_nframes_t sample; + nframes_t sample; smpte.hours = atoi (hours_label.get_text()); 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 */ ); @@ -1304,10 +1363,10 @@ AudioClock::smpte_frame_from_display () const // Testcode for smpte<->sample conversions (P.S.) SMPTE::Time smpte1; - jack_nframes_t sample1; - jack_nframes_t oldsample = 0; + nframes_t sample1; + nframes_t oldsample = 0; SMPTE::Time smpte2; - jack_nframes_t sample_increment; + nframes_t sample_increment; sample_increment = (long)rint(session->frame_rate() / session->smpte_frames_per_second); @@ -1666,7 +1725,7 @@ AudioClock::smpte_frame_from_display () const return sample; } -jack_nframes_t +nframes_t AudioClock::minsec_frame_from_display () const { if (session == 0) { @@ -1677,13 +1736,13 @@ AudioClock::minsec_frame_from_display () const int mins = atoi (ms_minutes_label.get_text()); float secs = atof (ms_seconds_label.get_text()); - jack_nframes_t sr = session->frame_rate(); + nframes_t sr = session->frame_rate(); - return (jack_nframes_t) floor ((hrs * 60.0f * 60.0f * sr) + (mins * 60.0f * sr) + (secs * sr)); + return (nframes_t) floor ((hrs * 60.0f * 60.0f * sr) + (mins * 60.0f * sr) + (secs * sr)); } -jack_nframes_t -AudioClock::bbt_frame_from_display (jack_nframes_t pos) const +nframes_t +AudioClock::bbt_frame_from_display (nframes_t pos) const { if (session == 0) { error << "AudioClock::current_time() called with BBT mode but without session!" << endmsg; @@ -1697,14 +1756,14 @@ AudioClock::bbt_frame_from_display (jack_nframes_t pos) const any.bbt.beats = atoi (beats_label.get_text()); any.bbt.ticks = atoi (ticks_label.get_text()); - jack_nframes_t ret = session->convert_to_frames_at (pos, any); + nframes_t ret = session->convert_to_frames_at (pos, any); return ret; } -jack_nframes_t -AudioClock::bbt_frame_duration_from_display (jack_nframes_t pos) const +nframes_t +AudioClock::bbt_frame_duration_from_display (nframes_t pos) const { if (session == 0) { error << "AudioClock::current_time() called with BBT mode but without session!" << endmsg; @@ -1721,10 +1780,10 @@ AudioClock::bbt_frame_duration_from_display (jack_nframes_t pos) const return session->tempo_map().bbt_duration_at(pos,bbt,1); } -jack_nframes_t +nframes_t AudioClock::audio_frame_from_display () const { - return (jack_nframes_t) atoi (audio_frames_label.get_text()); + return (nframes_t) atoi (audio_frames_label.get_text()); } void @@ -1739,7 +1798,7 @@ AudioClock::build_ops_menu () MenuList& mode_items = mode_menu->items(); mode_menu->set_name ("ArdourContextMenu"); - mode_items.push_back (MenuElem (_("SMPTE"), bind (mem_fun(*this, &AudioClock::set_mode), SMPTE))); + mode_items.push_back (MenuElem (_("Timecode"), bind (mem_fun(*this, &AudioClock::set_mode), SMPTE))); mode_items.push_back (MenuElem (_("Bars:Beats"), bind (mem_fun(*this, &AudioClock::set_mode), BBT))); mode_items.push_back (MenuElem (_("Minutes:Seconds"), bind (mem_fun(*this, &AudioClock::set_mode), MinSec))); mode_items.push_back (MenuElem (_("Audio Frames"), bind (mem_fun(*this, &AudioClock::set_mode), Frames))); @@ -1775,40 +1834,66 @@ AudioClock::set_mode (Mode m) } _mode = m; - + switch (_mode) { case SMPTE: clock_base.add (smpte_packer_hbox); - Gtkmm2ext::set_size_request_to_display_given_text (hours_label, "-88", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (minutes_label, "88", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (seconds_label, "88", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (frames_label, "88", 0, 2); break; case BBT: clock_base.add (bbt_packer_hbox); - Gtkmm2ext::set_size_request_to_display_given_text (bars_label, "-888", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (beats_label, "88", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (ticks_label, "8888", 0, 2); break; case MinSec: clock_base.add (minsec_packer_hbox); - Gtkmm2ext::set_size_request_to_display_given_text (ms_hours_label, "99", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (ms_minutes_label, "99", 0, 2); - Gtkmm2ext::set_size_request_to_display_given_text (ms_seconds_label, "99", 0, 2); break; case Frames: clock_base.add (frames_packer_hbox); - Gtkmm2ext::set_size_request_to_display_given_text (audio_frames_label, "4294967296", 0, 2); + break; case Off: break; } + set_size_requests (); + set (last_when, true); clock_base.show_all (); key_entry_state = 0; } +void +AudioClock::set_size_requests () +{ + /* note that in some fonts, "88" is narrower than "00", hence the 2 pixel padding */ + + switch (_mode) { + case SMPTE: + 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, "-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, "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, "0000000000", 5, 5); + break; + + case Off: + break; + + } +}