MCP: correctly link routes and strips; correctly set up timeouts using event loop of MCP, not GUI

git-svn-id: svn://localhost/ardour2/branches/3.0@11827 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2012-04-08 15:10:46 +00:00
parent 6e13711361
commit 733a2b1820
5 changed files with 48 additions and 47 deletions

View File

@ -298,7 +298,7 @@ MackieControlProtocol::switch_banks (int initial)
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("remote id %1 connecting %2 to %3 with port %4\n",
route->remote_control_id(), route->name(), strip.name(), port_for_id(i)));
set_route_table (1, route);
set_route_table (i, route);
RouteSignal * rs = new RouteSignal (route, *this, strip, port_for_id(i));
route_signals.push_back (rs);
// update strip from route
@ -438,7 +438,7 @@ MackieControlProtocol::handle_strip_button (SurfacePort & port, Control & contro
/* BCF faders don't support touch, so add a timeout to reset
their `in_use' state.
*/
port.add_in_use_timeout (control.strip().gain(), &control.strip().fader_touch());
add_in_use_timeout (port, control.strip().gain(), &control.strip().fader_touch());
}
}
@ -800,7 +800,7 @@ MackieControlProtocol::handle_control_event (SurfacePort & port, Control & contr
if (ARDOUR::Config->get_mackie_emulation() == "bcf") {
/* reset the timeout while we're still moving the fader */
port.add_in_use_timeout (control, control.in_use_touch_control);
add_in_use_timeout (port, control, control.in_use_touch_control);
}
// must echo bytes back to slider now, because
@ -1741,3 +1741,41 @@ MackieControlProtocol::stop ()
return 0;
}
/** Add a timeout so that a control's in_use flag will be reset some time in the future.
* @param in_use_control the control whose in_use flag to reset.
* @param touch_control a touch control to emit an event for, or 0.
*/
void
MackieControlProtocol::add_in_use_timeout (SurfacePort& port, Control& in_use_control, Control* touch_control)
{
Glib::RefPtr<Glib::TimeoutSource> timeout (Glib::TimeoutSource::create (250)); // milliseconds
in_use_control.in_use_connection.disconnect ();
in_use_control.in_use_connection = timeout->connect (
sigc::bind (sigc::mem_fun (*this, &MackieControlProtocol::control_in_use_timeout), &port, &in_use_control, touch_control));
in_use_control.in_use_touch_control = touch_control;
timeout->attach (main_loop()->get_context());
}
/** Handle timeouts to reset in_use for controls that can't
* do this by themselves (e.g. pots, and faders without touch support).
* @param in_use_control the control whose in_use flag to reset.
* @param touch_control a touch control to emit an event for, or 0.
*/
bool
MackieControlProtocol::control_in_use_timeout (SurfacePort* port, Control* in_use_control, Control* touch_control)
{
in_use_control->set_in_use (false);
if (touch_control) {
// empty control_state
ControlState control_state;
handle_control_event (*port, *touch_control, control_state);
}
// only call this method once from the timer
return false;
}

View File

@ -48,6 +48,8 @@ namespace MIDI {
namespace Mackie {
class Surface;
class Control;
class SurfacePort;
}
/**
@ -220,6 +222,8 @@ class MackieControlProtocol
Mackie::SurfacePort & mcu_port();
ARDOUR::Session & get_session() { return *session; }
void add_in_use_timeout (Mackie::SurfacePort& port, Mackie::Control& in_use_control, Mackie::Control* touch_control);
protected:
// create instances of MackiePort, depending on what's found in ardour.rc
void create_ports();
@ -307,10 +311,11 @@ class MackieControlProtocol
void do_request (MackieControlUIRequest*);
int stop ();
private:
void port_connected_or_disconnected (std::string, std::string, bool);
bool control_in_use_timeout (Mackie::SurfacePort*, Mackie::Control *, Mackie::Control *);
boost::shared_ptr<Mackie::RouteSignal> master_route_signal;

View File

@ -383,8 +383,7 @@ MackiePort::handle_midi_controller_message (MIDI::Parser &, MIDI::EventTwoBytes*
*/
control->set_in_use (true);
add_in_use_timeout (*control, control);
_mcp.add_in_use_timeout (*this, *control, control);
control_event (*this, *control, state);
}
break;

View File

@ -198,42 +198,3 @@ ostream & Mackie::operator << (ostream & os, const SurfacePort & port)
return os;
}
/** Handle timeouts to reset in_use for controls that can't
* do this by themselves (e.g. pots, and faders without touch support).
* @param in_use_control the control whose in_use flag to reset.
* @param touch_control a touch control to emit an event for, or 0.
*/
bool
SurfacePort::control_in_use_timeout (Control* in_use_control, Control* touch_control)
{
in_use_control->set_in_use (false);
if (touch_control) {
// empty control_state
ControlState control_state;
control_event (*this, *touch_control, control_state);
}
// only call this method once from the timer
return false;
}
/** Add a timeout so that a control's in_use flag will be reset some time in the future.
* @param in_use_control the control whose in_use flag to reset.
* @param touch_control a touch control to emit an event for, or 0.
*/
void
SurfacePort::add_in_use_timeout (Control& in_use_control, Control* touch_control)
{
in_use_control.in_use_connection.disconnect ();
Glib::RefPtr<Glib::TimeoutSource> timeout (Glib::TimeoutSource::create (250));
/* timeout after 250ms */
in_use_control.in_use_connection = timeout->connect (
sigc::bind (sigc::mem_fun (*this, &SurfacePort::control_in_use_timeout), &in_use_control, touch_control));
/* XXX need to access main event loop of MackieControlProtocol */
in_use_control.in_use_touch_control = touch_control;
}

View File

@ -93,8 +93,6 @@ protected:
virtual void control_event (SurfacePort &, Control &, const ControlState &) {}
private:
bool control_in_use_timeout (Control *, Control *);
MIDI::Port * _input_port;
MIDI::Port * _output_port;
int _number;