X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Ftempo_curve.cc;h=d4b5d91a8e410df5ec6e26567e18289813264e4d;hb=84aedbb532c46054f200d7312334da7c17776b8e;hp=b3968e33aa122461eea2307a8d01daf57f57128b;hpb=1927a707c560cfe2a9963fb0fb75d65f5720256d;p=ardour.git diff --git a/gtk2_ardour/tempo_curve.cc b/gtk2_ardour/tempo_curve.cc index b3968e33aa..d4b5d91a8e 100644 --- a/gtk2_ardour/tempo_curve.cc +++ b/gtk2_ardour/tempo_curve.cc @@ -16,7 +16,7 @@ #include -#include "i18n.h" +#include "pbd/i18n.h" PBD::Signal1 TempoCurve::CatchDeletion; @@ -26,42 +26,48 @@ void TempoCurve::setup_sizes(const double timebar_height) { curve_height = floor (timebar_height) - 2.5; } - -TempoCurve::TempoCurve (PublicEditor& ed, ArdourCanvas::Container& parent, guint32 rgba, ARDOUR::TempoSection& temp, framepos_t frame, bool handle_events) +/* ignores Tempo note type - only note_types_per_minute is potentially curved */ +TempoCurve::TempoCurve (PublicEditor& ed, ArdourCanvas::Container& parent, guint32 rgba, ARDOUR::TempoSection& temp, samplepos_t sample, bool handle_events) : editor (ed) , _parent (&parent) , _curve (0) , _shown (false) , _color (rgba) - , _min_tempo (temp.beats_per_minute()) - , _max_tempo (temp.beats_per_minute()) + , _min_tempo (temp.note_types_per_minute()) + , _max_tempo (temp.note_types_per_minute()) , _tempo (temp) - + , _start_text (0) + , _end_text (0) { - frame_position = frame; - unit_position = editor.sample_to_pixel (frame); + sample_position = sample; + unit_position = editor.sample_to_pixel (sample); group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple (unit_position, 1)); #ifdef CANVAS_DEBUG - group->name = string_compose ("Marker::group for %1", _tempo.beats_per_minute()); + group->name = string_compose ("TempoCurve::group for %1", _tempo.note_types_per_minute()); #endif _curve = new ArdourCanvas::FramedCurve (group); #ifdef CANVAS_DEBUG - _curve->name = string_compose ("TempoCurve::_curve for %1", _tempo.beats_per_minute()); + _curve->name = string_compose ("TempoCurve::curve for %1", _tempo.note_types_per_minute()); #endif - _curve->set_fill_mode (ArdourCanvas::FramedCurve::Inside); - _curve->set_points_per_segment (31); - + _curve->set_points_per_segment (3); points = new ArdourCanvas::Points (); - points->push_back (ArdourCanvas::Duple (0.0, 0.0)); - points->push_back (ArdourCanvas::Duple (1.0, 0.0)); - points->push_back (ArdourCanvas::Duple (1.0, curve_height)); - points->push_back (ArdourCanvas::Duple (0.0, curve_height)); - _curve->set (*points); + _start_text = new ArdourCanvas::Text (group); + _end_text = new ArdourCanvas::Text (group); + _start_text->set_font_description (ARDOUR_UI_UTILS::get_font_for_style (N_("MarkerText"))); + _end_text->set_font_description (ARDOUR_UI_UTILS::get_font_for_style (N_("MarkerText"))); + _start_text->set_color (RGBA_TO_UINT (255,255,255,255)); + _end_text->set_color (RGBA_TO_UINT (255,255,255,255)); + char buf[10]; + snprintf (buf, sizeof (buf), "%.3f/%.0f", _tempo.note_types_per_minute(), _tempo.note_type()); + _start_text->set (buf); + snprintf (buf, sizeof (buf), "%.3f", _tempo.end_note_types_per_minute()); + _end_text->set (buf); + set_color_rgba (rgba); editor.ZoomChanged.connect (sigc::mem_fun (*this, &TempoCurve::reposition)); @@ -76,8 +82,7 @@ TempoCurve::TempoCurve (PublicEditor& ed, ArdourCanvas::Container& parent, guint //group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this)); } - set_position (_tempo.frame(), UINT32_MAX); - _curve->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_curve_event), _curve, this)); + group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_curve_event), _curve, this)); } @@ -108,54 +113,76 @@ TempoCurve::the_item() const } void -TempoCurve::set_position (framepos_t frame, framepos_t end_frame) +TempoCurve::set_position (samplepos_t sample, samplepos_t end_sample) { - const double tempo_delta = max (10.0, _max_tempo - _min_tempo); - - unit_position = editor.sample_to_pixel (frame); + unit_position = editor.sample_to_pixel (sample); group->set_x_position (unit_position); - frame_position = frame; - _end_frame = end_frame; - + sample_position = sample; + _end_sample = end_sample; points->clear(); - points = new ArdourCanvas::Points (); + points->push_back (ArdourCanvas::Duple (0.0, curve_height)); - if (end_frame == UINT32_MAX) { - const double tempo_at = _tempo.tempo_at_frame (frame, editor.session()->frame_rate()) * _tempo.note_type(); - const double y_pos = (curve_height) - (((tempo_at - _min_tempo) / (tempo_delta)) * curve_height); + if (sample >= end_sample) { + /* shouldn't happen but ..*/ + const double tempo_at = _tempo.note_types_per_minute(); + const double y_pos = (curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height); points->push_back (ArdourCanvas::Duple (0.0, y_pos)); - points->push_back (ArdourCanvas::Duple (ArdourCanvas::COORD_MAX - 5.0, y_pos)); + points->push_back (ArdourCanvas::Duple (1.0, y_pos)); + + } else if (_tempo.type() == ARDOUR::TempoSection::Constant || _tempo.c() == 0.0) { + const double tempo_at = _tempo.note_types_per_minute(); + const double y_pos = (curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height); + points->push_back (ArdourCanvas::Duple (0.0, y_pos)); + points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel (end_sample - sample), y_pos)); } else { - const framepos_t frame_step = ((end_frame - 1) - frame) / 29; - framepos_t current_frame = frame; - while (current_frame < (end_frame - frame_step)) { - const double tempo_at = _tempo.tempo_at_frame (current_frame, editor.session()->frame_rate()) * _tempo.note_type(); - const double y_pos = (curve_height) - (((tempo_at - _min_tempo) / (tempo_delta)) * curve_height); + const samplepos_t sample_step = max ((end_sample - sample) / 5, (samplepos_t) 1); + samplepos_t current_sample = sample; - points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel (current_frame - frame), y_pos)); + while (current_sample < end_sample) { + const double tempo_at = _tempo.tempo_at_minute (_tempo.minute_at_sample (current_sample)).note_types_per_minute(); + const double y_pos = max ((curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height), 0.0); - current_frame += frame_step; + points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel (current_sample - sample), min (y_pos, curve_height))); + + current_sample += sample_step; } - const double tempo_at = _tempo.tempo_at_frame (end_frame, editor.session()->frame_rate()) * _tempo.note_type(); - const double y_pos = (curve_height) - (((tempo_at - _min_tempo) / (tempo_delta)) * curve_height); + const double tempo_at = _tempo.tempo_at_minute (_tempo.minute_at_sample (end_sample)).note_types_per_minute(); + const double y_pos = max ((curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height), 0.0); - points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel ((end_frame - 1) - frame), y_pos)); + points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel (end_sample - sample), min (y_pos, curve_height))); } _curve->set (*points); + + char buf[10]; + snprintf (buf, sizeof (buf), "%.3f/%.0f", _tempo.note_types_per_minute(), _tempo.note_type()); + _start_text->set (buf); + snprintf (buf, sizeof (buf), "%.3f", _tempo.end_note_types_per_minute()); + _end_text->set (buf); + + _start_text->set_position (ArdourCanvas::Duple (10, .5 )); + _end_text->set_position (ArdourCanvas::Duple (editor.sample_to_pixel (end_sample - sample) - _end_text->text_width() - 10, .5 )); + + if (_end_text->text_width() + _start_text->text_width() + 20 > editor.sample_to_pixel (end_sample - sample)) { + _start_text->hide(); + _end_text->hide(); + } else { + _start_text->show(); + _end_text->show(); + } } void TempoCurve::reposition () { - set_position (frame_position, _end_frame); + set_position (sample_position, _end_sample); } void @@ -163,7 +190,7 @@ TempoCurve::show () { _shown = true; - group->show (); + group->show (); } void @@ -178,7 +205,7 @@ void TempoCurve::set_color_rgba (uint32_t c) { _color = c; - _curve->set_fill_color (UIConfiguration::instance().color_mod ("selection rect", "selection rect")); + _curve->set_fill_color (UIConfiguration::instance().color_mod (_color, "selection rect")); _curve->set_outline_color (_color); }