2019-08-02 17:26:43 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016-2017 Nick Mainsbridge <mainsbridge@gmail.com>
|
|
|
|
* Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2016-05-07 13:03:12 -04:00
|
|
|
#include <sigc++/bind.h>
|
2020-11-16 13:19:22 -05:00
|
|
|
|
|
|
|
#include "temporal/tempo.h"
|
2016-05-07 13:03:12 -04:00
|
|
|
|
|
|
|
#include "canvas/rectangle.h"
|
|
|
|
#include "canvas/container.h"
|
|
|
|
#include "canvas/curve.h"
|
|
|
|
#include "canvas/canvas.h"
|
|
|
|
#include "canvas/debug.h"
|
|
|
|
|
|
|
|
#include "ui_config.h"
|
|
|
|
|
|
|
|
#include "tempo_curve.h"
|
|
|
|
#include "public_editor.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "rgb_macros.h"
|
|
|
|
|
|
|
|
#include <gtkmm2ext/utils.h>
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2016-05-07 13:03:12 -04:00
|
|
|
|
2020-11-16 13:19:22 -05:00
|
|
|
using namespace Temporal;
|
|
|
|
|
2016-05-07 13:03:12 -04:00
|
|
|
PBD::Signal1<void,TempoCurve*> TempoCurve::CatchDeletion;
|
|
|
|
|
2016-05-07 13:54:52 -04:00
|
|
|
static double curve_height = 13.0;
|
|
|
|
|
2022-01-18 21:45:18 -05:00
|
|
|
void
|
|
|
|
TempoCurve::setup_sizes(const double timebar_height)
|
2016-05-07 13:54:52 -04:00
|
|
|
{
|
2022-01-18 21:45:18 -05:00
|
|
|
const double ui_scale = UIConfiguration::instance ().get_ui_scale ();
|
|
|
|
curve_height = floor (timebar_height) - (2.5 * ui_scale);
|
2016-05-07 13:54:52 -04:00
|
|
|
}
|
2022-01-18 21:45:18 -05:00
|
|
|
|
2016-11-05 14:14:20 -04:00
|
|
|
/* ignores Tempo note type - only note_types_per_minute is potentially curved */
|
2022-01-18 21:45:18 -05:00
|
|
|
TempoCurve::TempoCurve (PublicEditor& ed, ArdourCanvas::Item& parent, guint32 rgba, TempoPoint const & temp, bool handle_events, ArdourCanvas::Distance marker_width)
|
2016-05-07 13:03:12 -04:00
|
|
|
|
|
|
|
: editor (ed)
|
|
|
|
, _parent (&parent)
|
|
|
|
, _curve (0)
|
2022-01-18 21:45:18 -05:00
|
|
|
, _duration (UINT32_MAX)
|
|
|
|
, _marker_width (marker_width)
|
2016-05-07 13:03:12 -04:00
|
|
|
, _color (rgba)
|
2016-11-05 14:14:20 -04:00
|
|
|
, _min_tempo (temp.note_types_per_minute())
|
|
|
|
, _max_tempo (temp.note_types_per_minute())
|
2022-03-09 22:16:21 -05:00
|
|
|
, _tempo (&temp)
|
2017-02-27 01:53:31 -05:00
|
|
|
, _start_text (0)
|
|
|
|
, _end_text (0)
|
2016-05-07 13:03:12 -04:00
|
|
|
{
|
2022-01-18 21:45:18 -05:00
|
|
|
/* XXX x arg for Duple should probably be marker width, passed in from owner */
|
|
|
|
group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple (marker_width, 1));
|
2016-05-07 13:03:12 -04:00
|
|
|
#ifdef CANVAS_DEBUG
|
2022-03-09 22:16:21 -05:00
|
|
|
group->name = string_compose ("TempoCurve::group for %1", _tempo->note_types_per_minute());
|
2016-05-07 13:03:12 -04:00
|
|
|
#endif
|
|
|
|
|
2016-05-17 13:26:18 -04:00
|
|
|
_curve = new ArdourCanvas::FramedCurve (group);
|
2016-05-07 13:03:12 -04:00
|
|
|
#ifdef CANVAS_DEBUG
|
2022-03-09 22:16:21 -05:00
|
|
|
_curve->name = string_compose ("TempoCurve::curve for %1", _tempo->note_types_per_minute());
|
2016-05-07 13:03:12 -04:00
|
|
|
#endif
|
2016-05-24 14:10:22 -04:00
|
|
|
_curve->set_points_per_segment (3);
|
2022-01-18 21:45:18 -05:00
|
|
|
_curve->set (points);
|
2016-05-07 13:03:12 -04:00
|
|
|
|
2017-02-27 01:53:31 -05:00
|
|
|
_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];
|
2022-03-09 22:16:21 -05:00
|
|
|
snprintf (buf, sizeof (buf), "%.3f/%d", _tempo->note_types_per_minute(), _tempo->note_type());
|
2017-02-27 01:53:31 -05:00
|
|
|
_start_text->set (buf);
|
2022-03-09 22:16:21 -05:00
|
|
|
snprintf (buf, sizeof (buf), "%.3f", _tempo->end_note_types_per_minute());
|
2017-02-27 01:53:31 -05:00
|
|
|
_end_text->set (buf);
|
|
|
|
|
2016-05-07 13:03:12 -04:00
|
|
|
set_color_rgba (rgba);
|
|
|
|
|
|
|
|
editor.ZoomChanged.connect (sigc::mem_fun (*this, &TempoCurve::reposition));
|
|
|
|
|
|
|
|
/* events will be handled by both the group and the mark itself, so
|
|
|
|
* make sure they can both be used to lookup this object.
|
|
|
|
*/
|
|
|
|
|
2016-05-09 15:25:53 -04:00
|
|
|
_curve->set_data ("tempo curve", this);
|
2016-05-07 13:03:12 -04:00
|
|
|
|
|
|
|
if (handle_events) {
|
|
|
|
//group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
|
|
|
|
}
|
2016-05-09 15:25:53 -04:00
|
|
|
|
2017-02-27 09:05:39 -05:00
|
|
|
group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_curve_event), _curve, this));
|
2016-05-07 13:03:12 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TempoCurve::~TempoCurve ()
|
|
|
|
{
|
|
|
|
CatchDeletion (this); /* EMIT SIGNAL */
|
|
|
|
|
|
|
|
/* destroying the parent group destroys its contents, namely any polygons etc. that we added */
|
|
|
|
delete group;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArdourCanvas::Item&
|
|
|
|
TempoCurve::the_item() const
|
|
|
|
{
|
|
|
|
return *group;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-01-18 21:45:18 -05:00
|
|
|
TempoCurve::set_duration (samplecnt_t duration)
|
2016-05-07 13:03:12 -04:00
|
|
|
{
|
2022-01-18 21:45:18 -05:00
|
|
|
points.clear();
|
|
|
|
points.push_back (ArdourCanvas::Duple (0.0, curve_height));
|
2016-05-07 13:54:52 -04:00
|
|
|
|
2022-01-18 21:45:18 -05:00
|
|
|
ArdourCanvas::Coord duration_pixels = editor.sample_to_pixel (duration);
|
2016-10-16 10:28:33 -04:00
|
|
|
|
2022-03-09 22:16:21 -05:00
|
|
|
if (!_tempo->ramped()) {
|
2016-05-07 13:54:52 -04:00
|
|
|
|
2022-03-09 22:16:21 -05:00
|
|
|
const double tempo_at = _tempo->note_types_per_minute();
|
2016-05-24 14:10:22 -04:00
|
|
|
const double y_pos = (curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height);
|
2016-05-17 13:26:18 -04:00
|
|
|
|
2022-01-18 21:45:18 -05:00
|
|
|
points.push_back (ArdourCanvas::Duple (0.0, y_pos));
|
|
|
|
points.push_back (ArdourCanvas::Duple (duration_pixels, y_pos));
|
2016-05-07 13:03:12 -04:00
|
|
|
|
|
|
|
} else {
|
2016-09-03 13:18:12 -04:00
|
|
|
|
2022-05-02 14:20:48 -04:00
|
|
|
/* we would like at least 5 points for the line, so divide the
|
|
|
|
duration to give us that. If we're tiny (just a few samples,
|
|
|
|
unlikely but ...), do the per-sample thing.
|
|
|
|
*/
|
2022-01-18 21:45:18 -05:00
|
|
|
const samplepos_t sample_step = std::max ((duration) / 5, (samplepos_t) 1);
|
2022-05-02 14:20:48 -04:00
|
|
|
const samplepos_t start_sample = superclock_to_samples (_tempo->sclock(), TEMPORAL_SAMPLE_RATE);
|
|
|
|
const samplepos_t end = start_sample + duration;
|
|
|
|
samplepos_t current_sample = start_sample;
|
|
|
|
double tempo_at;
|
|
|
|
double y_pos;
|
2016-05-17 13:26:18 -04:00
|
|
|
|
2022-05-02 14:20:48 -04:00
|
|
|
while (current_sample < end) {
|
|
|
|
tempo_at = _tempo->note_types_per_minute_at_DOUBLE (timepos_t (current_sample));
|
|
|
|
y_pos = std::max ((curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height), 0.0);
|
2016-05-07 13:03:12 -04:00
|
|
|
|
2022-05-02 14:20:48 -04:00
|
|
|
points.push_back (ArdourCanvas::Duple (editor.sample_to_pixel (current_sample - start_sample), std::min (y_pos, curve_height)));
|
2016-05-17 13:26:18 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
current_sample += sample_step;
|
2016-05-07 13:03:12 -04:00
|
|
|
}
|
2016-05-23 16:49:52 -04:00
|
|
|
|
2022-05-02 14:20:48 -04:00
|
|
|
tempo_at = _tempo->note_types_per_minute_at_DOUBLE (timepos_t (end));
|
|
|
|
y_pos = std::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), std::min (y_pos, curve_height)));
|
2016-05-07 13:03:12 -04:00
|
|
|
}
|
|
|
|
|
2022-01-18 21:45:18 -05:00
|
|
|
_curve->set (points);
|
2017-02-27 01:53:31 -05:00
|
|
|
|
|
|
|
char buf[10];
|
2022-01-18 21:45:18 -05:00
|
|
|
|
2022-03-09 22:16:21 -05:00
|
|
|
snprintf (buf, sizeof (buf), "%.3f/%d", _tempo->note_types_per_minute(), _tempo->note_type());
|
2017-02-27 01:53:31 -05:00
|
|
|
_start_text->set (buf);
|
2022-03-09 22:16:21 -05:00
|
|
|
snprintf (buf, sizeof (buf), "%.3f", _tempo->end_note_types_per_minute());
|
2017-02-27 01:53:31 -05:00
|
|
|
_end_text->set (buf);
|
|
|
|
|
2022-01-18 21:45:18 -05:00
|
|
|
const double ui_scale = UIConfiguration::instance ().get_ui_scale ();
|
2017-02-27 01:53:31 -05:00
|
|
|
|
2022-01-18 21:45:18 -05:00
|
|
|
_start_text->set_position (ArdourCanvas::Duple (_marker_width + (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) {
|
2017-02-27 01:53:31 -05:00
|
|
|
_start_text->hide();
|
|
|
|
_end_text->hide();
|
|
|
|
} else {
|
|
|
|
_start_text->show();
|
|
|
|
_end_text->show();
|
|
|
|
}
|
2022-01-18 21:45:18 -05:00
|
|
|
|
|
|
|
_duration = duration;
|
2016-05-07 13:03:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TempoCurve::reposition ()
|
|
|
|
{
|
2022-01-18 21:45:18 -05:00
|
|
|
set_duration (_duration);
|
2016-05-07 13:03:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TempoCurve::show ()
|
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
group->show ();
|
2016-05-07 13:03:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TempoCurve::hide ()
|
|
|
|
{
|
|
|
|
group->hide ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TempoCurve::set_color_rgba (uint32_t c)
|
|
|
|
{
|
|
|
|
_color = c;
|
2017-02-26 10:26:08 -05:00
|
|
|
_curve->set_fill_color (UIConfiguration::instance().color_mod (_color, "selection rect"));
|
2016-05-07 13:03:12 -04:00
|
|
|
_curve->set_outline_color (_color);
|
|
|
|
|
|
|
|
}
|
2022-03-09 22:16:21 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
TempoCurve::reset_point (TempoPoint const & tp)
|
|
|
|
{
|
|
|
|
_tempo = &tp;
|
|
|
|
}
|