13
0

polish the way we print tempo numerics in tempo ruler

This commit is contained in:
Paul Davis 2023-08-31 10:34:41 -06:00
parent 43d6d4187c
commit da9140a390
3 changed files with 26 additions and 9 deletions

View File

@ -794,7 +794,7 @@ TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Item& parent, Ardo
_mapping_text->set_ignore_events (true);
char buf[64];
snprintf (buf, sizeof (buf), "%.1f", _tempo->note_types_per_minute ());
TempoCurve::format_tempo (_tempo->note_types_per_minute(), _tempo->note_type(), buf, sizeof (buf));
_mapping_text->set (buf);
}
@ -825,7 +825,7 @@ TempoMarker::update ()
_mapping_text->set_position (ArdourCanvas::Duple (std::max (3., unit_position), _mapping_text->position().y));
char buf[64];
snprintf (buf, sizeof (buf), "%.1f", _tempo->note_types_per_minute ());
TempoCurve::format_tempo (_tempo->note_types_per_minute(), _tempo->note_type(), buf, sizeof (buf));
_mapping_text->set (buf);
}

View File

@ -86,9 +86,9 @@ TempoCurve::TempoCurve (PublicEditor& ed, ArdourCanvas::Item& parent, guint32 rg
_start_text->set_color (RGBA_TO_UINT (255,255,255,255));
_end_text->set_color (RGBA_TO_UINT (255,255,255,255));
char buf[128];
snprintf (buf, sizeof (buf), "%.1f/%d", _tempo->note_types_per_minute(), _tempo->note_type());
format_tempo (_tempo->note_types_per_minute(), _tempo->note_type(), buf, sizeof(buf));
_start_text->set (buf);
snprintf (buf, sizeof (buf), "%.1f", _tempo->end_note_types_per_minute());
format_tempo (_tempo->end_note_types_per_minute(), _tempo->note_type(), buf, sizeof(buf));
_end_text->set (buf);
set_color_rgba (rgba);
@ -118,6 +118,24 @@ TempoCurve::~TempoCurve ()
delete group;
}
void
TempoCurve::format_tempo (double ntpm, int nt, char* buf, size_t bufsize)
{
if (UIConfiguration::instance().get_allow_non_quarter_pulse()) {
if (fmod (ntpm, 1.0) < 0.1) {
snprintf (buf, bufsize, "%d/%d", (int) ntpm, nt);
} else {
snprintf (buf, bufsize, "%.1f/%d", ntpm, nt);
}
} else {
if (fmod (ntpm, 1.0) < 0.1) {
snprintf (buf, bufsize, "%d", (int) ntpm);
} else {
snprintf (buf, bufsize, "%.1f", ntpm);
}
}
}
ArdourCanvas::Item&
TempoCurve::the_item() const
{
@ -170,15 +188,12 @@ TempoCurve::set_duration (samplecnt_t duration)
_curve->set (points);
char buf[129];
snprintf (buf, sizeof (buf), "%.1f/%d", _tempo->note_types_per_minute(), _tempo->note_type());
_start_text->set (buf);
snprintf (buf, sizeof (buf), "%.1f", _tempo->end_note_types_per_minute());
format_tempo (_tempo->end_note_types_per_minute(), _tempo->note_type(), buf, sizeof(buf));
_end_text->set (buf);
const double ui_scale = UIConfiguration::instance ().get_ui_scale ();
_start_text->set_position (ArdourCanvas::Duple (_marker_width + (10 * ui_scale), (.5 * ui_scale)));
_start_text->set_position (ArdourCanvas::Duple ((10 * ui_scale), (.5 * ui_scale)));
_end_text->set_position (ArdourCanvas::Duple (duration_pixels - _end_text->text_width() - _marker_width - (10. * ui_scale), (.5 * ui_scale)));
if (_end_text->text_width() + _start_text->text_width() + (20.0 * ui_scale) > duration_pixels) {

View File

@ -61,6 +61,8 @@ public:
void set_max_tempo (const double& max) { _max_tempo = max; }
void set_min_tempo (const double& min) { _min_tempo = min; }
static void format_tempo (double ntpm, int nt, char*, size_t);
protected:
PublicEditor& editor;