From dc9484d1449d04923849316a3ac7c74c4c49ec23 Mon Sep 17 00:00:00 2001 From: Nick Mainsbridge Date: Sun, 10 Sep 2006 17:49:03 +0000 Subject: more fiddling about with placing bits of the scroll/zoom operation in the idle callback. fix some ruler bugs. overall this should be smoother. git-svn-id: svn://localhost/ardour2/trunk@912 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor.cc | 17 ++---- gtk2_ardour/editor.h | 5 +- gtk2_ardour/editor_canvas.cc | 15 +++-- gtk2_ardour/editor_rulers.cc | 10 ++-- gtk2_ardour/editor_tempodisplay.cc | 113 +++++++++++++++---------------------- gtk2_ardour/route_time_axis.cc | 1 - 6 files changed, 69 insertions(+), 92 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index b9d14d4475..6b8fc782dc 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -882,6 +882,9 @@ Editor::reposition_x_origin (jack_nframes_t frame) } horizontal_adjustment.set_value (frame/frames_per_unit); + } else { + update_fixed_rulers(); + tempo_map_changed (Change (0)); } } @@ -965,19 +968,10 @@ void Editor::canvas_horizontally_scrolled () { - Glib::signal_idle().connect (mem_fun(*this, &Editor::lazy_canvas_horizontally_scrolled)); -} - -bool -Editor::lazy_canvas_horizontally_scrolled () -{ - - leftmost_frame = (jack_nframes_t) floor (horizontal_adjustment.get_value() * frames_per_unit); - + leftmost_frame = (jack_nframes_t) floor (horizontal_adjustment.get_value() * frames_per_unit); update_fixed_rulers (); tempo_map_changed (Change (0)); - return false; } void @@ -995,7 +989,6 @@ Editor::deferred_reposition_and_zoom (jack_nframes_t frame, double nfpu) set_frames_per_unit (nfpu); reposition_x_origin (frame); - tempo_map_changed (Change (0)); repos_zoom_queued = false; return FALSE; @@ -1291,7 +1284,7 @@ Editor::connect_to_session (Session *t) horizontal_adjustment.set_value (0); restore_ruler_visibility (); - tempo_map_changed (Change (0)); + //tempo_map_changed (Change (0)); session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); edit_cursor->set_position (0); diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 81bbbdaaab..226cdfb532 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -229,6 +229,7 @@ class Editor : public PublicEditor void set_show_measures (bool yn); bool show_measures () const { return _show_measures; } + bool initial_ruler_update_required; #ifdef FFT_ANALYSIS /* analysis window */ @@ -679,7 +680,6 @@ class Editor : public PublicEditor void tie_vertical_scrolling (); void canvas_horizontally_scrolled (); - bool lazy_canvas_horizontally_scrolled (); void reposition_and_zoom (jack_nframes_t sample, double fpu); gint deferred_reposition_and_zoom (jack_nframes_t sample, double fpu); @@ -1191,7 +1191,8 @@ class Editor : public PublicEditor ArdourCanvas::Group* time_line_group; ArdourCanvas::SimpleLine* get_time_line (); void hide_measures (); - bool draw_measures (); + void draw_measures (); + bool lazy_hide_and_draw_measures (); void new_tempo_section (); diff --git a/gtk2_ardour/editor_canvas.cc b/gtk2_ardour/editor_canvas.cc index 946df13334..0c3436ec40 100644 --- a/gtk2_ardour/editor_canvas.cc +++ b/gtk2_ardour/editor_canvas.cc @@ -266,8 +266,10 @@ Editor::initialize_canvas () edit_cursor = new Cursor (*this, "blue", &Editor::canvas_edit_cursor_event); playhead_cursor = new Cursor (*this, "red", &Editor::canvas_playhead_cursor_event); - + + initial_ruler_update_required = true; track_canvas.signal_size_allocate().connect (mem_fun(*this, &Editor::track_canvas_allocate)); + } void @@ -317,10 +319,15 @@ Editor::track_canvas_allocate (Gtk::Allocation alloc) transport_punchout_line->property_y2() = canvas_height; } - update_fixed_rulers (); - - if (is_visible()) { + if (is_visible() && initial_ruler_update_required) { + /* + this is really dumb, but signal_size_allocate() gets emitted intermittently + depending on whether the canvas contents are visible or not. + we only want to do this once + */ + update_fixed_rulers(); tempo_map_changed (Change (0)); + initial_ruler_update_required = false; } Resized (); /* EMIT_SIGNAL */ diff --git a/gtk2_ardour/editor_rulers.cc b/gtk2_ardour/editor_rulers.cc index befbe3f8d6..276ec0bf3d 100644 --- a/gtk2_ardour/editor_rulers.cc +++ b/gtk2_ardour/editor_rulers.cc @@ -818,9 +818,9 @@ Editor::metric_get_smpte (GtkCustomRulerMark **marks, gdouble lower, gdouble upp if (lower > (spacer = (jack_nframes_t)(128 * Editor::get_current_zoom ()))) { lower = lower - spacer; } else { - upper = upper + spacer - lower; lower = 0; } + upper = upper + spacer; range = (jack_nframes_t) floor (upper - lower); if (range < (2 * session->frames_per_smpte_frame())) { /* 0 - 2 frames */ @@ -1110,8 +1110,8 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper position_of_helper = ilower + (30 * Editor::get_current_zoom ()); - if (desirable_marks >= (beats / 2)) { - nmarks = ((beats + 4) * bbt_beat_subdivision) + 1; + if (desirable_marks >= (beats)) { + nmarks = ((beats + 1) * bbt_beat_subdivision) + 1; we_need_ticks = true; } else { nmarks = beats + 1; @@ -1156,7 +1156,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper /* Add the tick marks */ - if (we_need_ticks) { + if (we_need_ticks && (*i).type != TempoMap::Bar) { /* Find the next beat */ @@ -1417,9 +1417,9 @@ Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble up if (lower > (spacer = (jack_nframes_t)(128 * Editor::get_current_zoom ()))) { lower = lower - spacer; } else { - upper = upper + spacer; lower = 0; } + upper = upper + spacer; range = iupper - ilower; if (range < (fr / 50)) { diff --git a/gtk2_ardour/editor_tempodisplay.cc b/gtk2_ardour/editor_tempodisplay.cc index e922299992..e7299542db 100644 --- a/gtk2_ardour/editor_tempodisplay.cc +++ b/gtk2_ardour/editor_tempodisplay.cc @@ -100,25 +100,23 @@ Editor::tempo_map_changed (Change ignored) BBT_Time previous_beat, next_beat; // the beats previous to the leftmost frame and after the rightmost frame session->bbt_time(leftmost_frame, previous_beat); + session->bbt_time(leftmost_frame + current_page_frames(), next_beat); - previous_beat.ticks = 0; if (previous_beat.beats > 1) { previous_beat.beats -= 1; } else if (previous_beat.bars > 1) { previous_beat.bars--; previous_beat.beats += 1; } - - session->bbt_time(leftmost_frame + current_page_frames(), next_beat); + previous_beat.ticks = 0; if (session->tempo_map().meter_at(leftmost_frame + current_page_frames()).beats_per_bar () > next_beat.beats + 1) { next_beat.beats += 1; - next_beat.ticks = 0; } else { next_beat.bars += 1; next_beat.beats = 1; - next_beat.ticks = 0; } + next_beat.ticks = 0; if (current_bbt_points) { delete current_bbt_points; @@ -127,16 +125,7 @@ Editor::tempo_map_changed (Change ignored) if (session) { current_bbt_points = session->tempo_map().get_points (session->tempo_map().frame_time (previous_beat), session->tempo_map().frame_time (next_beat)); - - /* - TempoMap::BBTPointList::iterator i; - cerr << "******************" << endl << "current bbt points dump: " << endl; - for (i = current_bbt_points->begin(); i != current_bbt_points->end(); i++) { - cerr << (*i).bar << " : " << (*i).beat << endl; - } - cerr << "******************" << endl; - */ - + update_tempo_based_rulers (); } else { current_bbt_points = 0; } @@ -148,11 +137,10 @@ void Editor::redisplay_tempo () { - hide_measures (); - if (session && current_bbt_points) { - Glib::signal_idle().connect (mem_fun (*this, &Editor::draw_measures)); - update_tempo_based_rulers (); + Glib::signal_idle().connect (mem_fun (*this, &Editor::lazy_hide_and_draw_measures)); + } else { + hide_measures (); } } @@ -160,7 +148,7 @@ void Editor::hide_measures () { for (TimeLineList::iterator i = used_measure_lines.begin(); i != used_measure_lines.end(); ++i) { - (*i)->hide(); + (*i)->hide(); free_measure_lines.push_back (*i); } used_measure_lines.clear (); @@ -184,69 +172,61 @@ Editor::get_time_line () } bool +Editor::lazy_hide_and_draw_measures () +{ + hide_measures (); + draw_measures (); + return false; +} + +void Editor::draw_measures () { if (session == 0 || _show_measures == false) { - return false; + return; } TempoMap::BBTPointList::iterator i; ArdourCanvas::SimpleLine *line; - gdouble xpos, last_xpos; - uint32_t cnt; + gdouble xpos; + double x1, x2, y1, y2, beat_density; + + uint32_t beats = 0; + uint32_t bars = 0; uint32_t color; if (current_bbt_points == 0 || current_bbt_points->empty()) { - return false; + return; } - cnt = 0; - last_xpos = 0; + track_canvas.get_scroll_region (x1, y1, x2, y2); /* get the first bar spacing */ - gdouble last_beat = DBL_MAX; - gdouble beat_spacing = 0; - - for (i = current_bbt_points->begin(); i != current_bbt_points->end() && beat_spacing == 0; ++i) { - TempoMap::BBTPoint& p = (*i); + i = current_bbt_points->end(); + i--; + bars = (*i).bar - (*current_bbt_points->begin()).bar; + beats = current_bbt_points->size() - bars; - switch (p.type) { - case TempoMap::Bar: - break; - - case TempoMap::Beat: - xpos = frame_to_unit (p.frame); - if (last_beat < xpos) { - beat_spacing = xpos - last_beat; - } - last_beat = xpos; - } - } + beat_density = (beats * 10.0f) / track_canvas.get_width (); - if (beat_spacing < 12.0) { + if (beat_density > 2.0f) { /* if the lines are too close together, they become useless */ - return false; + return; } - double x1, x2, y1, y2; - track_canvas.get_scroll_region (x1, y1, x2, y2); - for (i = current_bbt_points->begin(); i != current_bbt_points->end(); ++i) { - TempoMap::BBTPoint& p = (*i); - - switch (p.type) { + switch ((*i).type) { case TempoMap::Bar: break; case TempoMap::Beat: - xpos = frame_to_unit (p.frame); - if (p.beat == 1) { + if ((*i).beat == 1) { color = color_map[cMeasureLineBeat]; } else { color = color_map[cMeasureLineBar]; @@ -255,22 +235,19 @@ Editor::draw_measures () are large. */ - if (beat_spacing < 25.0) { - break; + if (beat_density > 0.25) { + break; } } - - if (cnt == 0 || xpos - last_xpos > 4.0) { - line = get_time_line (); - line->property_x1() = xpos; - line->property_x2() = xpos; - line->property_y2() = y2; - line->property_color_rgba() = color; - line->raise_to_top(); - line->show(); - last_xpos = xpos; - ++cnt; - } + + xpos = frame_to_unit ((*i).frame); + line = get_time_line (); + line->property_x1() = xpos; + line->property_x2() = xpos; + line->property_y2() = y2; + line->property_color_rgba() = color; + //line->raise_to_top(); + line->show(); break; } } @@ -279,7 +256,7 @@ Editor::draw_measures () cursor_group->raise_to_top(); time_line_group->lower_to_bottom(); - return false; + return; } void diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index 68c108c917..470a6d0b88 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -133,7 +133,6 @@ RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::sh if (is_track()) { rec_enable_button->set_active (false); rec_enable_button->set_name ("TrackRecordEnableButton"); - //rec_enable_button->signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false); rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press)); controls_table.attach (*rec_enable_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0); ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record")); -- cgit v1.2.3