mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-16 19:56:31 +01:00
hopefully fix up shuttle operation in semitones mode
git-svn-id: svn://localhost/ardour2/branches/3.0@9404 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
449d0cf486
commit
509cd57c74
2 changed files with 74 additions and 34 deletions
|
|
@ -20,8 +20,6 @@
|
||||||
|
|
||||||
#include <cairo/cairo.h>
|
#include <cairo/cairo.h>
|
||||||
|
|
||||||
#include <pbd/stacktrace.h>
|
|
||||||
|
|
||||||
#include "ardour/ardour.h"
|
#include "ardour/ardour.h"
|
||||||
#include "ardour/audioengine.h"
|
#include "ardour/audioengine.h"
|
||||||
#include "ardour/rc_configuration.h"
|
#include "ardour/rc_configuration.h"
|
||||||
|
|
@ -39,6 +37,11 @@ using namespace ARDOUR;
|
||||||
using std::min;
|
using std::min;
|
||||||
using std::max;
|
using std::max;
|
||||||
|
|
||||||
|
gboolean qt (gboolean, gint, gint, gboolean, Gtk::Tooltip*, gpointer)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
ShuttleControl::ShuttleControl ()
|
ShuttleControl::ShuttleControl ()
|
||||||
: _controllable (new ShuttleControllable (*this))
|
: _controllable (new ShuttleControllable (*this))
|
||||||
, binding_proxy (_controllable)
|
, binding_proxy (_controllable)
|
||||||
|
|
@ -62,7 +65,9 @@ ShuttleControl::ShuttleControl ()
|
||||||
|
|
||||||
Config->ParameterChanged.connect (parameter_connection, MISSING_INVALIDATOR, ui_bind (&ShuttleControl::parameter_changed, this, _1), gui_context());
|
Config->ParameterChanged.connect (parameter_connection, MISSING_INVALIDATOR, ui_bind (&ShuttleControl::parameter_changed, this, _1), gui_context());
|
||||||
|
|
||||||
signal_query_tooltip().connect (sigc::mem_fun (*this, &ShuttleControl::on_query_tooltip));
|
/* gtkmm 2.4: the C++ wrapper doesn't work */
|
||||||
|
g_signal_connect ((GObject*) gobj(), "query-tooltip", G_CALLBACK (qt), NULL);
|
||||||
|
// signal_query_tooltip().connect (sigc::mem_fun (*this, &ShuttleControl::on_query_tooltip));
|
||||||
}
|
}
|
||||||
|
|
||||||
ShuttleControl::~ShuttleControl ()
|
ShuttleControl::~ShuttleControl ()
|
||||||
|
|
@ -109,7 +114,7 @@ ShuttleControl::map_transport_state ()
|
||||||
|
|
||||||
if (speed != 0.0) {
|
if (speed != 0.0) {
|
||||||
if (Config->get_shuttle_units() == Semitones) {
|
if (Config->get_shuttle_units() == Semitones) {
|
||||||
shuttle_fract = speed/2.0;
|
shuttle_fract = semitones_as_fract (speed_as_semitones (speed));
|
||||||
} else {
|
} else {
|
||||||
shuttle_fract = speed/shuttle_max_speed;
|
shuttle_fract = speed/shuttle_max_speed;
|
||||||
}
|
}
|
||||||
|
|
@ -248,29 +253,25 @@ ShuttleControl::on_button_release_event (GdkEventButton* ev)
|
||||||
|
|
||||||
switch (ev->button) {
|
switch (ev->button) {
|
||||||
case 1:
|
case 1:
|
||||||
mouse_shuttle (ev->x, true);
|
|
||||||
shuttle_grabbed = false;
|
shuttle_grabbed = false;
|
||||||
remove_modal_grab ();
|
remove_modal_grab ();
|
||||||
|
|
||||||
if (Config->get_shuttle_behaviour() == Sprung) {
|
if (Config->get_shuttle_behaviour() == Sprung) {
|
||||||
if (_session->config.get_auto_play()) {
|
if (_session->config.get_auto_play()) {
|
||||||
shuttle_fract = SHUTTLE_FRACT_SPEED1;
|
|
||||||
_session->request_transport_speed (1.0);
|
_session->request_transport_speed (1.0);
|
||||||
} else {
|
} else {
|
||||||
shuttle_fract = 0;
|
|
||||||
_session->request_transport_speed (0.0);
|
_session->request_transport_speed (0.0);
|
||||||
}
|
}
|
||||||
queue_draw ();
|
} else {
|
||||||
}
|
mouse_shuttle (ev->x, true);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
if (_session->transport_rolling()) {
|
if (_session->transport_rolling()) {
|
||||||
shuttle_fract = SHUTTLE_FRACT_SPEED1;
|
|
||||||
_session->request_transport_speed (1.0);
|
_session->request_transport_speed (1.0);
|
||||||
} else {
|
|
||||||
shuttle_fract = 0;
|
|
||||||
}
|
}
|
||||||
queue_draw ();
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
|
|
@ -279,15 +280,12 @@ ShuttleControl::on_button_release_event (GdkEventButton* ev)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use_shuttle_fract (true);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ShuttleControl::on_query_tooltip (int, int, bool, const Glib::RefPtr<Gtk::Tooltip>&)
|
ShuttleControl::on_query_tooltip (int, int, bool, const Glib::RefPtr<Gtk::Tooltip>&)
|
||||||
{
|
{
|
||||||
std::cerr << "OQT!\n";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -302,11 +300,11 @@ ShuttleControl::on_scroll_event (GdkEventScroll* ev)
|
||||||
|
|
||||||
case GDK_SCROLL_UP:
|
case GDK_SCROLL_UP:
|
||||||
case GDK_SCROLL_RIGHT:
|
case GDK_SCROLL_RIGHT:
|
||||||
shuttle_fract += 0.005;
|
shuttle_fract += 0.005;
|
||||||
break;
|
break;
|
||||||
case GDK_SCROLL_DOWN:
|
case GDK_SCROLL_DOWN:
|
||||||
case GDK_SCROLL_LEFT:
|
case GDK_SCROLL_LEFT:
|
||||||
shuttle_fract -= 0.005;
|
shuttle_fract -= 0.005;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -330,16 +328,21 @@ ShuttleControl::on_motion_notify_event (GdkEventMotion* ev)
|
||||||
gint
|
gint
|
||||||
ShuttleControl::mouse_shuttle (double x, bool force)
|
ShuttleControl::mouse_shuttle (double x, bool force)
|
||||||
{
|
{
|
||||||
double const half_width = get_width() / 2.0;
|
double const center = get_width() / 2.0;
|
||||||
double distance = x - half_width;
|
double distance_from_center = x - center;
|
||||||
|
|
||||||
if (distance > 0) {
|
if (distance_from_center > 0) {
|
||||||
distance = min (distance, half_width);
|
distance_from_center = min (distance_from_center, center);
|
||||||
} else {
|
} else {
|
||||||
distance = max (distance, -half_width);
|
distance_from_center = max (distance_from_center, -center);
|
||||||
}
|
}
|
||||||
|
|
||||||
shuttle_fract = distance / half_width;
|
/* compute shuttle fract as expressing how far between the center
|
||||||
|
and the edge we are. positive values indicate we are right of
|
||||||
|
center, negative values indicate left of center
|
||||||
|
*/
|
||||||
|
|
||||||
|
shuttle_fract = distance_from_center / center; // center == half the width
|
||||||
use_shuttle_fract (force);
|
use_shuttle_fract (force);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -351,11 +354,49 @@ ShuttleControl::set_shuttle_fract (double f)
|
||||||
use_shuttle_fract (false);
|
use_shuttle_fract (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ShuttleControl::speed_as_semitones (float speed)
|
||||||
|
{
|
||||||
|
if (speed < 0.0) {
|
||||||
|
return (int) round (12.0 * fast_log2 (-speed));
|
||||||
|
} else {
|
||||||
|
return (int) round (12.0 * fast_log2 (speed));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float
|
||||||
|
ShuttleControl::semitones_as_speed (int semi)
|
||||||
|
{
|
||||||
|
return pow (2.0, (semi / 12.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
float
|
||||||
|
ShuttleControl::semitones_as_fract (int semi)
|
||||||
|
{
|
||||||
|
double const step = 1.0 / 24.0; // range is 24 semitones up & down
|
||||||
|
return semi * step;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ShuttleControl::fract_as_semitones (float fract)
|
||||||
|
{
|
||||||
|
double const step = 1.0 / 24.0; // range is 24 semitones up & down
|
||||||
|
return (int) round (shuttle_fract / step);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ShuttleControl::use_shuttle_fract (bool force)
|
ShuttleControl::use_shuttle_fract (bool force)
|
||||||
{
|
{
|
||||||
microseconds_t now = get_microseconds();
|
microseconds_t now = get_microseconds();
|
||||||
|
|
||||||
|
if (Config->get_shuttle_units() == Semitones) {
|
||||||
|
shuttle_fract = max (-1.0f, shuttle_fract);
|
||||||
|
shuttle_fract = min (1.0f, shuttle_fract);
|
||||||
|
} else {
|
||||||
|
shuttle_fract = max (-shuttle_max_speed, shuttle_fract);
|
||||||
|
shuttle_fract = min (shuttle_max_speed, shuttle_fract);
|
||||||
|
}
|
||||||
|
|
||||||
/* do not attempt to submit a motion-driven transport speed request
|
/* do not attempt to submit a motion-driven transport speed request
|
||||||
more than once per process cycle.
|
more than once per process cycle.
|
||||||
*/
|
*/
|
||||||
|
|
@ -369,9 +410,7 @@ ShuttleControl::use_shuttle_fract (bool force)
|
||||||
double speed = 0;
|
double speed = 0;
|
||||||
|
|
||||||
if (Config->get_shuttle_units() == Semitones) {
|
if (Config->get_shuttle_units() == Semitones) {
|
||||||
double const step = 1.0 / 24.0; // range is 24 semitones up & down
|
speed = semitones_as_speed (fract_as_semitones (shuttle_fract));
|
||||||
double const semitones = round (shuttle_fract / step);
|
|
||||||
speed = pow (2.0, (semitones / 12.0));
|
|
||||||
} else {
|
} else {
|
||||||
speed = shuttle_max_speed * shuttle_fract;
|
speed = shuttle_max_speed * shuttle_fract;
|
||||||
}
|
}
|
||||||
|
|
@ -421,11 +460,7 @@ ShuttleControl::on_expose_event (GdkEventExpose* event)
|
||||||
snprintf (buf, sizeof (buf), "%d%%", (int) round (speed * 100));
|
snprintf (buf, sizeof (buf), "%d%%", (int) round (speed * 100));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (speed < 0) {
|
snprintf (buf, sizeof (buf), "%+d semitones", speed_as_semitones (speed));
|
||||||
snprintf (buf, sizeof (buf), "-%d semitones", (int) round (12.0 * fast_log2 (-speed)));
|
|
||||||
} else {
|
|
||||||
snprintf (buf, sizeof (buf), "+%d semitones", (int) round (12.0 * fast_log2 (speed)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
snprintf (buf, sizeof (buf), _("Stopped"));
|
snprintf (buf, sizeof (buf), _("Stopped"));
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class ShuttleControl : public Gtk::DrawingArea, public ARDOUR::SessionHandlePtr
|
||||||
float shuttle_max_speed;
|
float shuttle_max_speed;
|
||||||
float last_speed_displayed;
|
float last_speed_displayed;
|
||||||
bool shuttle_grabbed;
|
bool shuttle_grabbed;
|
||||||
double shuttle_fract;
|
float shuttle_fract;
|
||||||
boost::shared_ptr<ShuttleControllable> _controllable;
|
boost::shared_ptr<ShuttleControllable> _controllable;
|
||||||
cairo_pattern_t* pattern;
|
cairo_pattern_t* pattern;
|
||||||
ARDOUR::microseconds_t last_shuttle_request;
|
ARDOUR::microseconds_t last_shuttle_request;
|
||||||
|
|
@ -90,6 +90,11 @@ class ShuttleControl : public Gtk::DrawingArea, public ARDOUR::SessionHandlePtr
|
||||||
|
|
||||||
void set_shuttle_units (ARDOUR::ShuttleUnits);
|
void set_shuttle_units (ARDOUR::ShuttleUnits);
|
||||||
void set_shuttle_style (ARDOUR::ShuttleBehaviour);
|
void set_shuttle_style (ARDOUR::ShuttleBehaviour);
|
||||||
|
|
||||||
|
int speed_as_semitones (float);
|
||||||
|
float semitones_as_speed (int);
|
||||||
|
float semitones_as_fract (int);
|
||||||
|
int fract_as_semitones (float);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __gtk2_ardour_shuttle_control_h__ */
|
#endif /* __gtk2_ardour_shuttle_control_h__ */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue