summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2012-04-11 13:39:25 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2012-04-11 13:39:25 +0000
commit8c9f9e746bfc56c5ae2edd482f434774c93ebb9d (patch)
tree2f5b313159636d11c7d5cb29437355da8fe42d23 /libs
parent02c8ccf348fb16b740089c3ec39053a8b00c1f82 (diff)
MCP: further objectification of event handling code
git-svn-id: svn://localhost/ardour2/branches/3.0@11896 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r--libs/surfaces/mackie/mackie_control_protocol.cc4
-rw-r--r--libs/surfaces/mackie/strip.cc83
-rw-r--r--libs/surfaces/mackie/strip.h4
-rw-r--r--libs/surfaces/mackie/surface.cc130
-rw-r--r--libs/surfaces/mackie/surface.h2
5 files changed, 92 insertions, 131 deletions
diff --git a/libs/surfaces/mackie/mackie_control_protocol.cc b/libs/surfaces/mackie/mackie_control_protocol.cc
index 43c30d2ac8..74f2073aef 100644
--- a/libs/surfaces/mackie/mackie_control_protocol.cc
+++ b/libs/surfaces/mackie/mackie_control_protocol.cc
@@ -861,9 +861,7 @@ MackieControlProtocol::control_in_use_timeout (Surface* surface, Control* in_use
in_use_control->set_in_use (false);
if (touch_control) {
- // empty control_state
- ControlState control_state;
- surface->handle_control_event (*touch_control, control_state);
+ /* figure out what to do here */
}
// only call this method once from the timer
diff --git a/libs/surfaces/mackie/strip.cc b/libs/surfaces/mackie/strip.cc
index e75adf72ae..05b3563362 100644
--- a/libs/surfaces/mackie/strip.cc
+++ b/libs/surfaces/mackie/strip.cc
@@ -32,6 +32,7 @@
#include "ardour/track.h"
#include "ardour/pannable.h"
#include "ardour/panner.h"
+#include "ardour/panner_shell.h"
#include "ardour/rc_configuration.h"
#include "ardour/meter.h"
@@ -403,49 +404,39 @@ Strip::notify_panner_changed (bool force_update)
}
}
-bool
-Strip::handle_button (SurfacePort & port, Control & control, ButtonState bs)
+void
+Strip::handle_button (Button& button, ButtonState bs)
{
- Button* button = dynamic_cast<Button*>(&control);
-
- if (!button) {
- return false;
- }
+ button.set_in_use (bs == press);
if (!_route) {
// no route so always switch the light off
// because no signals will be emitted by a non-route
- _surface->write (button->led().set_state (off));
- return false;
+ _surface->write (button.led().set_state (off));
}
- bool state = false;
-
if (bs == press) {
- if (control.name() == "recenable") {
- state = !_route->record_enabled();
- _route->set_record_enabled (state, this);
- } else if (control.name() == "mute") {
- state = !_route->muted();
- _route->set_mute (state, this);
- } else if (control.name() == "solo") {
- state = !_route->soloed();
- _route->set_solo (state, this);
- } else if (control.name() == "select") {
+ if (button.name() == "recenable") {
+ _route->set_record_enabled (!_route->record_enabled(), this);
+ } else if (button.name() == "mute") {
+ _route->set_mute (!_route->muted(), this);
+ } else if (button.name() == "solo") {
+ _route->set_solo (!_route->soloed(), this);
+ } else if (button.name() == "select") {
_surface->mcp().select_track (_route);
- } else if (control.name() == "vselect") {
+ } else if (button.name() == "vselect") {
// TODO could be used to select different things to apply the pot to?
//state = default_button_press (dynamic_cast<Button&> (control));
}
}
- if (control.name() == "fader_touch") {
+ if (button.name() == "fader_touch") {
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("fader touch, press ? %1\n", (bs == press)));
- state = (bs == press);
+ bool state = (bs == press);
- gain().set_in_use (state);
+ _gain->set_in_use (state);
if (ARDOUR::Config->get_mackie_emulation() == "bcf" && state) {
@@ -456,8 +447,48 @@ Strip::handle_button (SurfacePort & port, Control & control, ButtonState bs)
_surface->mcp().add_in_use_timeout (*_surface, gain(), &fader_touch());
}
}
+}
+
+void
+Strip::handle_fader (Fader& fader, float position)
+{
+ DEBUG_TRACE (DEBUG::MackieControl, string_compose ("fader to %1\n", position));
- return state;
+ if (_route) {
+ _route->gain_control()->set_value (slider_position_to_gain (position));
+ }
+
+ if (ARDOUR::Config->get_mackie_emulation() == "bcf") {
+ /* reset the timeout while we're still moving the fader */
+ _surface->mcp().add_in_use_timeout (*_surface, fader, fader.in_use_touch_control);
+ }
+
+ // must echo bytes back to slider now, because
+ // the notifier only works if the fader is not being
+ // touched. Which it is if we're getting input.
+
+ _surface->write (fader.set_position (position));
+}
+
+void
+Strip::handle_pot (Pot& pot, ControlState& state)
+{
+ if (!_route) {
+ _surface->write (pot.set_onoff (false));
+ return;
+ }
+
+ boost::shared_ptr<Panner> panner = _route->panner_shell()->panner();
+ // pan for mono input routes, or stereo linked panners
+ if (panner) {
+ double p = panner->position ();
+
+ // calculate new value, and adjust
+ p += state.delta * state.sign;
+ p = min (1.0, p);
+ p = max (0.0, p);
+ panner->set_position (p);
+ }
}
void
diff --git a/libs/surfaces/mackie/strip.h b/libs/surfaces/mackie/strip.h
index cfca9c166e..4a96fdcf39 100644
--- a/libs/surfaces/mackie/strip.h
+++ b/libs/surfaces/mackie/strip.h
@@ -77,7 +77,9 @@ public:
// call all signal handlers manually
void notify_all();
- bool handle_button (SurfacePort & port, Control & control, ButtonState bs);
+ void handle_button (Button&, ButtonState bs);
+ void handle_fader (Fader&, float position);
+ void handle_pot (Pot&, ControlState&);
void periodic ();
diff --git a/libs/surfaces/mackie/surface.cc b/libs/surfaces/mackie/surface.cc
index ebe626d425..4e4e42ef55 100644
--- a/libs/surfaces/mackie/surface.cc
+++ b/libs/surfaces/mackie/surface.cc
@@ -329,18 +329,22 @@ Surface::connect_to_signals ()
}
}
-
void
Surface::handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t pb, uint32_t fader_id)
{
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("handle_midi pitchbend on port %3, fader = %1 value = %2\n",
fader_id, pb, _number));
- Control* control = faders[fader_id];
+ Fader* fader = faders[fader_id];
- if (control) {
- float midi_pos = pb >> 4; // only the top 10 bytes are used
- handle_control_event (*control, midi_pos / 1023.0);
+ if (fader) {
+ Strip* strip = dynamic_cast<Strip*> (&fader->group());
+ if (strip) {
+ float midi_pos = pb >> 4; // only the top 10 bytes are used
+ strip->handle_fader (*fader, midi_pos/1023.0);
+ } else {
+ /* master fader */
+ }
} else {
DEBUG_TRACE (DEBUG::MackieControl, "fader not found\n");
}
@@ -351,15 +355,19 @@ Surface::handle_midi_note_on_message (MIDI::Parser &, MIDI::EventTwoBytes* ev)
{
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("SurfacePort::handle_note_on %1 = %2\n", ev->note_number, ev->velocity));
- Control* control = buttons[ev->note_number];
+ Button* button = buttons[ev->note_number];
- if (control) {
- ControlState control_state (ev->velocity == 0x7f ? press : release);
- control->set_in_use (control_state.button_state == press);
- handle_control_event (*control, control_state);
- } else {
- DEBUG_TRACE (DEBUG::MackieControl, "button not found\n");
- }
+ if (button) {
+ Strip* strip = dynamic_cast<Strip*> (&button->group());
+
+ if (strip) {
+ strip->handle_button (*button, ev->velocity == 0x7f ? press : release);
+ } else {
+ /* global button */
+ DEBUG_TRACE (DEBUG::MackieControl, string_compose ("global button %1\n", button->raw_id()));
+ _mcp.handle_button_event (*this, *button, ev->velocity == 0x7f ? press : release);
+ }
+ }
}
void
@@ -367,13 +375,13 @@ Surface::handle_midi_controller_message (MIDI::Parser &, MIDI::EventTwoBytes* ev
{
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("SurfacePort::handle_midi_controller %1 = %2\n", ev->controller_number, ev->value));
- Control* control = pots[ev->controller_number];
+ Pot* pot = pots[ev->controller_number];
- if (!control && ev->controller_number == Control::jog_base_id) {
- control = controls_by_name["jog"];
+ if (!pot && ev->controller_number == Control::jog_base_id) {
+ pot = dynamic_cast<Pot*> (controls_by_name["jog"]);
}
- if (control) {
+ if (pot) {
ControlState state;
// bytes[2] & 0b01000000 (0x40) give sign
@@ -391,100 +399,24 @@ Surface::handle_midi_controller_message (MIDI::Parser &, MIDI::EventTwoBytes* ev
/* Pots only emit events when they move, not when they
stop moving. So to get a stop event, we need to use a timeout.
*/
-
- control->set_in_use (true);
- _mcp.add_in_use_timeout (*this, *control, control);
-
- handle_control_event (*control, state);
- } else {
- DEBUG_TRACE (DEBUG::MackieControl, "pot not found\n");
- }
-}
-void
-Surface::handle_control_event (Control & control, const ControlState & state)
-{
- // find the route for the control, if there is one
- boost::shared_ptr<Route> route;
- Strip* strip;
-
- if ((strip = dynamic_cast<Strip*> (&control.group())) != 0) {
- route = strip->route ();
- }
-
- // This handles control element events from the surface
- // the state of the controls on the surface is usually updated
- // from UI events.
-
- Fader* fader = dynamic_cast<Fader*> (&control);
- Button* button = dynamic_cast<Button*> (&control);
- Pot* pot = dynamic_cast<Pot*> (&control);
-
- if (fader) {
- // find the route in the route table for the id
- // if the route isn't available, skip it
- // at which point the fader should just reset itself
- if (route != 0) {
- DEBUG_TRACE (DEBUG::MackieControl, string_compose ("fader to %1\n", state.pos));
-
- route->gain_control()->set_value (slider_position_to_gain (state.pos));
-
- if (ARDOUR::Config->get_mackie_emulation() == "bcf") {
- /* reset the timeout while we're still moving the fader */
- _mcp.add_in_use_timeout (*this, control, control.in_use_touch_control);
- }
-
- // must echo bytes back to slider now, because
- // the notifier only works if the fader is not being
- // touched. Which it is if we're getting input.
- _port->write (fader->set_position (state.pos));
- }
- }
+ _mcp.add_in_use_timeout (*this, *pot, pot);
- if (button) {
+ Strip* strip = dynamic_cast<Strip*> (&pot->group());
if (strip) {
- strip->handle_button (*_port, control, state.button_state);
- } else {
- // handle all non-strip buttons
- DEBUG_TRACE (DEBUG::MackieControl, string_compose ("global button %1\n", control.raw_id()));
- _mcp.handle_button_event (*this, dynamic_cast<Button&>(control), state.button_state);
-
- }
- }
- // pot (jog wheel, external control)
-
- if (pot) {
- if (strip) {
- DEBUG_TRACE (DEBUG::MackieControl, string_compose ("strip pot %1\n", control.raw_id()));
- if (route) {
- boost::shared_ptr<Panner> panner = route->panner_shell()->panner();
- // pan for mono input routes, or stereo linked panners
- if (panner) {
- double p = panner->position ();
-
- // calculate new value, and adjust
- p += state.delta * state.sign;
- p = min (1.0, p);
- p = max (0.0, p);
- panner->set_position (p);
- }
- } else {
- // it's a pot for an umnapped route, so turn all the lights off
- Pot* pot = dynamic_cast<Pot*> (&control);
- if (pot) {
- _port->write (pot->set_onoff (false));
- }
- }
+ strip->handle_pot (*pot, state);
} else {
JogWheel* wheel = dynamic_cast<JogWheel*> (pot);
if (wheel) {
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Jog wheel moved %1\n", state.ticks));
- wheel->jog_event (*_port, control, state);
+ wheel->jog_event (*_port, *pot, state);
} else {
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("External controller moved %1\n", state.ticks));
cout << "external controller" << state.ticks * state.sign << endl;
}
}
+ } else {
+ DEBUG_TRACE (DEBUG::MackieControl, "pot not found\n");
}
}
diff --git a/libs/surfaces/mackie/surface.h b/libs/surfaces/mackie/surface.h
index dbc4f2530b..186f600d9f 100644
--- a/libs/surfaces/mackie/surface.h
+++ b/libs/surfaces/mackie/surface.h
@@ -128,8 +128,6 @@ public:
*/
float scaled_delta (const ControlState & state, float current_speed);
- void handle_control_event (Mackie::Control & control, const Mackie::ControlState & state);
-
// display the first 2 chars of the msg in the 2 char display
// . is appended to the previous character, so A.B. would
// be two characters