X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_rulers.cc;h=7f6ac56d5bf728acb2e5a2858c2e6cf676a720df;hb=76c25a4a4459b8e550c3c687458d04db0beaee77;hp=276ec0bf3d6b05afac8edc4e138337e6cf64d11b;hpb=dc9484d1449d04923849316a3ac7c74c4c49ec23;p=ardour.git diff --git a/gtk2_ardour/editor_rulers.cc b/gtk2_ardour/editor_rulers.cc index 276ec0bf3d..7f6ac56d5b 100644 --- a/gtk2_ardour/editor_rulers.cc +++ b/gtk2_ardour/editor_rulers.cc @@ -138,6 +138,34 @@ Editor::ruler_button_press (GdkEventButton* ev) ruler_grabbed_widget = grab_widget; } + gint x,y; + Gdk::ModifierType state; + + /* need to use the correct x,y, the event lies */ + time_canvas_event_box.get_window()->get_pointer (x, y, state); + + nframes_t where = leftmost_frame + pixel_to_frame (x); + + switch (ev->button) { + case 1: + /* transport playhead */ + snap_to (where); + session->request_locate (where); + break; + + case 2: + /* edit cursor */ + if (snap_type != Editing::SnapToEditCursor) { + snap_to (where); + } + edit_cursor->set_position (where); + edit_cursor_clock.set (where); + break; + + default: + break; + } + return TRUE; } @@ -150,7 +178,6 @@ Editor::ruler_button_release (GdkEventButton* ev) /* need to use the correct x,y, the event lies */ time_canvas_event_box.get_window()->get_pointer (x, y, state); - ruler_pressed_button = 0; if (session == 0) { @@ -160,7 +187,7 @@ Editor::ruler_button_release (GdkEventButton* ev) hide_verbose_canvas_cursor(); stop_canvas_autoscroll(); - jack_nframes_t where = leftmost_frame + pixel_to_frame (x); + nframes_t where = leftmost_frame + pixel_to_frame (x); switch (ev->button) { case 1: @@ -229,12 +256,12 @@ Editor::ruler_mouse_motion (GdkEventMotion* ev) track_canvas.c2w (x, y, wcx, wcy); track_canvas.w2c (wcx, wcy, cx, cy); - jack_nframes_t where = leftmost_frame + pixel_to_frame (x); + nframes_t where = leftmost_frame + pixel_to_frame (x); /// ripped from maybe_autoscroll, and adapted to work here - jack_nframes_t one_page = (jack_nframes_t) rint (canvas_width * frames_per_unit); - jack_nframes_t rightmost_frame = leftmost_frame + one_page; + nframes_t one_page = (nframes_t) rint (canvas_width * frames_per_unit); + nframes_t rightmost_frame = leftmost_frame + one_page; if (autoscroll_timeout_tag < 0) { if (where > rightmost_frame) { @@ -288,7 +315,7 @@ Editor::ruler_mouse_motion (GdkEventMotion* ev) void -Editor::popup_ruler_menu (jack_nframes_t where, ItemType t) +Editor::popup_ruler_menu (nframes_t where, ItemType t) { using namespace Menu_Helpers; @@ -310,11 +337,13 @@ Editor::popup_ruler_menu (jack_nframes_t where, ItemType t) case MarkerBarItem: ruler_items.push_back (MenuElem (_("New location marker"), bind ( mem_fun(*this, &Editor::mouse_add_new_marker), where))); ruler_items.push_back (MenuElem (_("Clear all locations"), mem_fun(*this, &Editor::clear_markers))); + ruler_items.push_back (MenuElem (_("Unhide locations"), mem_fun(*this, &Editor::unhide_markers))); ruler_items.push_back (SeparatorElem ()); break; case RangeMarkerBarItem: //ruler_items.push_back (MenuElem (_("New Range"))); ruler_items.push_back (MenuElem (_("Clear all ranges"), mem_fun(*this, &Editor::clear_ranges))); + ruler_items.push_back (MenuElem (_("Unhide ranges"), mem_fun(*this, &Editor::unhide_ranges))); ruler_items.push_back (SeparatorElem ()); break; @@ -344,7 +373,7 @@ Editor::popup_ruler_menu (jack_nframes_t where, ItemType t) mitem->set_active(true); } - ruler_items.push_back (CheckMenuElem (X_("SMPTE"), bind (mem_fun(*this, &Editor::ruler_toggled), (int)ruler_metric_smpte))); + ruler_items.push_back (CheckMenuElem (X_("Timecode"), bind (mem_fun(*this, &Editor::ruler_toggled), (int)ruler_metric_smpte))); mitem = (CheckMenuItem *) &ruler_items.back(); if (ruler_shown[ruler_metric_smpte]) { mitem->set_active(true); @@ -394,7 +423,7 @@ Editor::popup_ruler_menu (jack_nframes_t where, ItemType t) mitem->set_active(true); } - editor_ruler_menu->popup (1, 0); + editor_ruler_menu->popup (1, gtk_get_current_event_time()); no_ruler_shown_update = false; } @@ -440,7 +469,7 @@ Editor::store_ruler_visibility () session->add_extra_xml (*node); session->set_dirty (); } - + void Editor::restore_ruler_visibility () { @@ -695,8 +724,8 @@ Editor::update_just_smpte () an uint32_t (or larger) to a float ... what to do ? */ - jack_nframes_t page = (jack_nframes_t) floor (canvas_width * frames_per_unit); - jack_nframes_t rightmost_frame = leftmost_frame + page; + nframes_t page = (nframes_t) floor (canvas_width * frames_per_unit); + nframes_t rightmost_frame = leftmost_frame + page; if (ruler_shown[ruler_metric_smpte]) { gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_smpte_ruler), leftmost_frame, rightmost_frame, @@ -707,7 +736,7 @@ Editor::update_just_smpte () void Editor::update_fixed_rulers () { - jack_nframes_t rightmost_frame; + nframes_t rightmost_frame; if (session == 0) { return; @@ -717,7 +746,7 @@ Editor::update_fixed_rulers () an uint32_t (or larger) to a float ... what to do ? */ - jack_nframes_t page = (jack_nframes_t) floor (canvas_width * frames_per_unit); + nframes_t page = (nframes_t) floor (canvas_width * frames_per_unit); ruler_metrics[ruler_metric_smpte].units_per_pixel = frames_per_unit; ruler_metrics[ruler_metric_frames].units_per_pixel = frames_per_unit; @@ -756,7 +785,7 @@ Editor::update_tempo_based_rulers () an uint32_t (or larger) to a float ... what to do ? */ - jack_nframes_t page = (jack_nframes_t) floor (canvas_width * frames_per_unit); + nframes_t page = (nframes_t) floor (canvas_width * frames_per_unit); ruler_metrics[ruler_metric_bbt].units_per_pixel = frames_per_unit; if (ruler_shown[ruler_metric_bbt]) { @@ -794,10 +823,10 @@ Editor::_metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble u gint Editor::metric_get_smpte (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars) { - jack_nframes_t range; - jack_nframes_t pos; - jack_nframes_t spacer; - jack_nframes_t fr; + nframes_t range; + nframes_t pos; + nframes_t spacer; + nframes_t fr; SMPTE::Time smpte; gchar buf[16]; gint nmarks = 0; @@ -815,34 +844,34 @@ Editor::metric_get_smpte (GtkCustomRulerMark **marks, gdouble lower, gdouble upp fr = session->frame_rate(); - if (lower > (spacer = (jack_nframes_t)(128 * Editor::get_current_zoom ()))) { + if (lower > (spacer = (nframes_t)(128 * Editor::get_current_zoom ()))) { lower = lower - spacer; } else { lower = 0; } upper = upper + spacer; - range = (jack_nframes_t) floor (upper - lower); + range = (nframes_t) floor (upper - lower); if (range < (2 * session->frames_per_smpte_frame())) { /* 0 - 2 frames */ show_bits = true; mark_modulo = 20; - nmarks = 1 + 160; + nmarks = 1 + (2 * Config->get_subframes_per_frame()); } else if (range <= (fr / 4)) { /* 2 frames - 0.250 second */ show_frames = true; mark_modulo = 1; - nmarks = 1 + (range / (jack_nframes_t)session->frames_per_smpte_frame()); + nmarks = 1 + (range / (nframes_t)session->frames_per_smpte_frame()); } else if (range <= (fr / 2)) { /* 0.25-0.5 second */ show_frames = true; mark_modulo = 2; - nmarks = 1 + (range / (jack_nframes_t)session->frames_per_smpte_frame()); + nmarks = 1 + (range / (nframes_t)session->frames_per_smpte_frame()); } else if (range <= fr) { /* 0.5-1 second */ show_frames = true; mark_modulo = 5; - nmarks = 1 + (range / (jack_nframes_t)session->frames_per_smpte_frame()); + nmarks = 1 + (range / (nframes_t)session->frames_per_smpte_frame()); } else if (range <= 2 * fr) { /* 1-2 seconds */ show_frames = true; mark_modulo = 10; - nmarks = 1 + (range / (jack_nframes_t)session->frames_per_smpte_frame()); + nmarks = 1 + (range / (nframes_t)session->frames_per_smpte_frame()); } else if (range <= 8 * fr) { /* 2-8 seconds */ show_seconds = true; mark_modulo = 1; @@ -893,14 +922,14 @@ Editor::metric_get_smpte (GtkCustomRulerMark **marks, gdouble lower, gdouble upp nmarks = 1 + 24; } else { - /* not possible if jack_nframes_t is a 32 bit quantity */ + /* not possible if nframes_t is a 32 bit quantity */ show_hours = true; mark_modulo = 4; nmarks = 1 + 24; } - pos = (jack_nframes_t) floor (lower); + pos = (nframes_t) floor (lower); *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks); @@ -1042,13 +1071,12 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper uint32_t magic_accent_number = 1; gint nmarks; char buf[64]; - gint n; - jack_nframes_t pos; + gint n = 0; + nframes_t pos; bool bar_helper_on = true; BBT_Time next_beat; - jack_nframes_t next_beat_pos; - jack_nframes_t ilower = (jack_nframes_t) floor (lower); + nframes_t next_beat_pos; if ((desirable_marks = maxchars / 7) == 0) { return 0; @@ -1090,7 +1118,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper beats = current_bbt_points->size() - bars; /*Only show the bar helper if there aren't many bars on the screen */ - if (bars > 2) { + if (bars > 1) { bar_helper_on = false; } @@ -1101,17 +1129,18 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper uint32_t tick = 0; uint32_t skip; uint32_t t; - jack_nframes_t frame_skip; + nframes_t frame_skip; double frame_skip_error; double accumulated_error; double position_of_helper; bool i_am_accented = false; bool we_need_ticks = false; + bool helper_active = false; - position_of_helper = ilower + (30 * Editor::get_current_zoom ()); + position_of_helper = lower + (30 * Editor::get_current_zoom ()); if (desirable_marks >= (beats)) { - nmarks = ((beats + 1) * bbt_beat_subdivision) + 1; + nmarks = (beats * bbt_beat_subdivision) + 1; we_need_ticks = true; } else { nmarks = beats + 1; @@ -1120,19 +1149,23 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks); (*marks)[0].label = g_strdup(" "); - (*marks)[0].position = ilower; + (*marks)[0].position = lower; (*marks)[0].style = GtkCustomRulerMarkMicro; - for (n = 1, i = current_bbt_points->begin(); n < nmarks && i != current_bbt_points->end(); i++) { + for (n = 1, i = current_bbt_points->begin(); n < nmarks && i != current_bbt_points->end(); ++i) { - if ((*i).frame < ilower && (bar_helper_on)) { + if ((*i).frame < lower && (bar_helper_on)) { snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat); (*marks)[0].label = g_strdup (buf); + helper_active = true; } else { if ((*i).type == TempoMap::Bar) { - (((*i).frame < position_of_helper) && bar_helper_on) ? - snprintf (buf, sizeof(buf), " ") : snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar); + if (((*i).frame < position_of_helper) && helper_active) { + snprintf (buf, sizeof(buf), " "); + } else { + snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar); + } (*marks)[n].label = g_strdup (buf); (*marks)[n].position = (*i).frame; (*marks)[n].style = GtkCustomRulerMarkMajor; @@ -1156,7 +1189,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper /* Add the tick marks */ - if (we_need_ticks && (*i).type != TempoMap::Bar) { + if (we_need_ticks && (*i).type == TempoMap::Beat) { /* Find the next beat */ @@ -1172,7 +1205,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper next_beat_pos = session->tempo_map().frame_time(next_beat); - frame_skip = (jack_nframes_t) floor (frame_skip_error = (session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute())); + frame_skip = (nframes_t) floor (frame_skip_error = (session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute())); frame_skip_error -= frame_skip; skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision); @@ -1198,7 +1231,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper (*marks)[n].label = g_strdup (buf); - /* Error compensation for float to jack_nframes_t*/ + /* Error compensation for float to nframes_t*/ accumulated_error += frame_skip_error; if (accumulated_error > 1) { pos += 1; @@ -1224,14 +1257,14 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper /* we're in bar land */ - if (desirable_marks < (uint32_t) (bars / 256)) { + if (desirable_marks < (bars / 256)) { nmarks = 1; *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks); snprintf (buf, sizeof(buf), "too many bars... (currently %" PRIu32 ")", bars ); (*marks)[0].style = GtkCustomRulerMarkMajor; (*marks)[0].label = g_strdup (buf); - (*marks)[0].position = ilower; - } else if (desirable_marks < (uint32_t) (nmarks = (gint) (bars / 64))) { + (*marks)[0].position = lower; + } else if (desirable_marks < (uint32_t)(nmarks = (gint) (bars / 64) + 1)) { *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks); for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < nmarks; i++) { if ((*i).type == TempoMap::Bar) { @@ -1253,7 +1286,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper } } } - } else if (desirable_marks < (uint32_t) (nmarks = (gint)(bars / 16))) { + } else if (desirable_marks < (uint32_t)(nmarks = (bars / 16) + 1)) { *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks); for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < nmarks; i++) { if ((*i).type == TempoMap::Bar) { @@ -1275,7 +1308,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper } } } - } else if (desirable_marks < (uint32_t) (nmarks = (gint)(bars / 4))){ + } else if (desirable_marks < (uint32_t)(nmarks = (bars / 4) + 1)){ *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks); for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < nmarks; ++i) { if ((*i).type == TempoMap::Bar) { @@ -1298,8 +1331,8 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper } } } else { - nmarks = bars; - *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks); + nmarks = bars + 1; + *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks ); for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < nmarks; i++) { if ((*i).type == TempoMap::Bar) { if ((*i).bar % 4 == 1) { @@ -1319,17 +1352,17 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper } } } - return nmarks; + return n; } } gint Editor::metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars) { - jack_nframes_t mark_interval; - jack_nframes_t pos; - jack_nframes_t ilower = (jack_nframes_t) floor (lower); - jack_nframes_t iupper = (jack_nframes_t) floor (upper); + nframes_t mark_interval; + nframes_t pos; + nframes_t ilower = (nframes_t) floor (lower); + nframes_t iupper = (nframes_t) floor (upper); gchar buf[16]; gint nmarks; gint n; @@ -1357,15 +1390,15 @@ Editor::metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble up } static void -sample_to_clock_parts ( jack_nframes_t sample, - jack_nframes_t sample_rate, +sample_to_clock_parts ( nframes_t sample, + nframes_t sample_rate, long *hrs_p, long *mins_p, long *secs_p, long *millisecs_p) { - jack_nframes_t left; + nframes_t left; long hrs; long mins; long secs; @@ -1391,11 +1424,11 @@ sample_to_clock_parts ( jack_nframes_t sample, gint Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars) { - jack_nframes_t range; - jack_nframes_t fr; - jack_nframes_t mark_interval; - jack_nframes_t pos; - jack_nframes_t spacer; + nframes_t range; + nframes_t fr; + nframes_t mark_interval; + nframes_t pos; + nframes_t spacer; long hrs, mins, secs, millisecs; gchar buf[16]; gint nmarks; @@ -1404,8 +1437,8 @@ Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble up bool show_seconds = false; bool show_minutes = false; bool show_hours = false; - jack_nframes_t ilower = (jack_nframes_t) floor (lower); - jack_nframes_t iupper = (jack_nframes_t) floor (upper); + nframes_t ilower = (nframes_t) floor (lower); + nframes_t iupper = (nframes_t) floor (upper); if (session == 0) { return 0; @@ -1414,7 +1447,7 @@ Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble up fr = session->frame_rate(); /* to prevent 'flashing' */ - if (lower > (spacer = (jack_nframes_t)(128 * Editor::get_current_zoom ()))) { + if (lower > (spacer = (nframes_t)(128 * Editor::get_current_zoom ()))) { lower = lower - spacer; } else { lower = 0; @@ -1486,7 +1519,7 @@ Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble up mark_modulo = 2; } else { - /* not possible if jack_nframes_t is a 32 bit quantity */ + /* not possible if nframes_t is a 32 bit quantity */ mark_interval = 4 * 60 * 60 * fr; /* show 4 hrs */ }