#include <glibmm/convert.h>
+#include "pbd/stacktrace.h"
+
#include "midi++/port.h"
#include "ardour/audioengine.h"
#include "ardour/route.h"
#include "ardour/panner.h"
#include "ardour/panner_shell.h"
+#include "ardour/profile.h"
#include "ardour/rc_configuration.h"
#include "ardour/session.h"
#include "ardour/utils.h"
+#include <gtkmm2ext/gui_thread.h>
+
#include "control_group.h"
#include "surface_port.h"
#include "surface.h"
using namespace PBD;
using ARDOUR::Route;
using ARDOUR::Panner;
-using ARDOUR::Pannable;
+using ARDOUR::Profile;
using ARDOUR::AutomationControl;
using namespace ArdourSurface;
using namespace Mackie;
, _master_fader (0)
, _last_master_gain_written (-0.0f)
, connection_state (0)
+ , input_source (0)
{
DEBUG_TRACE (DEBUG::MackieControl, "Surface::Surface init\n");
DEBUG_TRACE (DEBUG::MackieControl, "init_strips done\n");
}
- /*
- */
+ if (_mcp.device_info().uses_ipmidi()) {
+ /* ipMIDI port already exists, we can just assume that we're
+ * connected.
+ *
+ * If the user still hasn't connected the ipMIDI surface and/or
+ * turned it on, then they have to press "Discover Mackie
+ * Devices" in the GUI at the right time.
+ */
- ARDOUR::AudioEngine::instance()->PortConnectedOrDisconnected.connect (port_connection, MISSING_INVALIDATOR, boost::bind (&Surface::connection_handler, this, _1, _2, _3, _4, _5), &_mcp);
+ connection_state |= (InputConnected|OutputConnected);
+ connected ();
+ }
connect_to_signals ();
{
DEBUG_TRACE (DEBUG::MackieControl, "Surface::~Surface init\n");
- // zero_all ();
+ if (input_source) {
+ g_source_destroy (input_source);
+ input_source = 0;
+ }
- // delete groups
+ // delete groups (strips)
for (Groups::iterator it = groups.begin(); it != groups.end(); ++it) {
delete it->second;
}
- // delete controls
+ // delete controls (global buttons, master fader etc)
for (Controls::iterator it = controls.begin(); it != controls.end(); ++it) {
delete *it;
}
- port_connection.disconnect ();
-
delete _jog_wheel;
delete _port;
-
+ // the ports take time to release and we may be rebuilding right away
+ // in the case of changing devices.
+ g_usleep (10000);
DEBUG_TRACE (DEBUG::MackieControl, "Surface::~Surface done\n");
}
-void
+bool
Surface::connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn)
{
if (!_port) {
- return;
+ return false;
}
string ni = ARDOUR::AudioEngine::instance()->make_port_name_non_relative (_port->input_name());
} else {
connection_state &= ~OutputConnected;
}
+ } else {
+ /* not our ports */
+ return false;
}
if ((connection_state & (InputConnected|OutputConnected)) == (InputConnected|OutputConnected)) {
to queue it with the MCP event loop.
*/
+ /* XXX this is a horrible hack. Without a short sleep here,
+ something prevents the device wakeup messages from being
+ sent and/or the responses from being received.
+ */
+
+ g_usleep (100000);
connected ();
} else {
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Surface %1 disconnected (input or output or both)\n", _name));
_active = false;
}
+
+ return true; /* connection status changed */
}
XMLNode&
Surface::get_state()
{
- char buf[64];
- snprintf (buf, sizeof (buf), X_("surface-%u"), _number);
- XMLNode* node = new XMLNode (buf);
-
+ XMLNode* node = new XMLNode (X_("Surface"));
+ node->add_property (X_("name"), _name);
node->add_child_nocopy (_port->get_state());
-
return *node;
}
int
Surface::set_state (const XMLNode& node, int version)
{
- char buf[64];
- snprintf (buf, sizeof (buf), X_("surface-%u"), _number);
- XMLNode* mynode = node.child (buf);
+ /* Look for a node named after the device we're part of */
+
+ XMLNodeList const& children = node.children();
+ XMLNode* mynode = 0;
+
+ for (XMLNodeList::const_iterator c = children.begin(); c != children.end(); ++c) {
+ XMLProperty const* prop = (*c)->property (X_("name"));
+ if (prop) {
+ if (prop->value() == _name) {
+ mynode = *c;
+ break;
+ }
+ }
+ }
if (!mynode) {
return 0;
}
}
+void
+Surface::master_monitor_may_have_changed ()
+{
+ if (_number == _mcp.device_info().master_position()) {
+ setup_master ();
+ }
+}
+
void
Surface::setup_master ()
{
}
if (!m) {
+ _master_fader->set_control (boost::shared_ptr<AutomationControl>());
+ master_connection.disconnect ();
return;
}
- _master_fader = dynamic_cast<Fader*> (Fader::factory (*this, _mcp.device_info().strip_cnt(), "master", *groups["master"]));
+ if (!_master_fader) {
+ _master_fader = dynamic_cast<Fader*> (Fader::factory (*this, _mcp.device_info().strip_cnt(), "master", *groups["master"]));
+
+ Groups::iterator group_it;
+ group_it = groups.find("master");
+
+ DeviceInfo device_info = _mcp.device_info();
+ GlobalButtonInfo master_button = device_info.get_global_button(Button::MasterFaderTouch);
+ Button* bb = dynamic_cast<Button*> (Button::factory (
+ *this,
+ Button::MasterFaderTouch,
+ master_button.id,
+ master_button.label,
+ *(group_it->second)
+ ));
+
+ DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface %1 Master Fader new button BID %2 id %3\n",
+ number(), Button::MasterFaderTouch, bb->id()));
+ } else {
+ master_connection.disconnect ();
+ }
_master_fader->set_control (m->gain_control());
- m->gain_control()->Changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&Surface::master_gain_changed, this), ui_context());
-
- Groups::iterator group_it;
- group_it = groups.find("master");
-
- DeviceInfo device_info = _mcp.device_info();
- GlobalButtonInfo master_button = device_info.get_global_button(Button::MasterFaderTouch);
- Button* bb = dynamic_cast<Button*> (Button::factory (
- *this,
- Button::MasterFaderTouch,
- master_button.id,
- master_button.label,
- *(group_it->second)
-));
- DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface %1 Master Fader new button BID %2 id %3\n",
- number(), Button::MasterFaderTouch, bb->id()));
+ m->gain_control()->Changed.connect (master_connection, MISSING_INVALIDATOR, boost::bind (&Surface::master_gain_changed, this), ui_context());
+ _last_master_gain_written = FLT_MAX; /* some essentially impossible value */
+ master_gain_changed ();
}
void
turn_it_on ();
}
- if (_mcp.main_modifier_state() & MackieControlProtocol::MODIFIER_SHIFT) {
- /* user is doing a reset to unity gain but device sends a PB
- * message in the middle of the touch on/off messages. Ignore
- * it.
- */
- return;
- }
-
Fader* fader = faders[fader_id];
if (fader) {
write_sysex (host_connection_query (bytes));
} else {
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Mackie Control Device ready, current status = %1\n", _active));
- if (!_active) {
- turn_it_on ();
- }
+ turn_it_on ();
}
break;
DEBUG_TRACE (DEBUG::MackieControl, "Logic Control Device confirms connection, ardour replies\n");
if (bytes[4] == 0x10 || bytes[4] == 0x11) {
write_sysex (host_connection_confirmation (bytes));
- _active = true;
+ turn_it_on ();
}
break;
(*s)->notify_all ();
}
- update_view_mode_display ();
+ update_view_mode_display (false);
if (_mcp.device_info ().has_global_controls ()) {
_mcp.update_global_button (Button::Read, _mcp.metering_active ());
for (; s != strips.end(); ++s) {
(*s)->set_route (boost::shared_ptr<Route>());
}
-
-
}
static char
Surface::update_flip_mode_display ()
{
for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) {
- (*s)->flip_mode_changed (true);
+ (*s)->potmode_changed (true);
}
}
- void
+void
Surface::update_potmode ()
{
for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) {
}
void
-Surface::update_view_mode_display ()
+Surface::subview_mode_changed ()
+{
+ for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) {
+ (*s)->subview_mode_changed ();
+ }
+}
+
+void
+Surface::update_view_mode_display (bool with_helpful_text)
{
string text;
int id = -1;
switch (_mcp.view_mode()) {
case MackieControlProtocol::Mixer:
show_two_char_display ("Mx");
- //id = Button::Pan;
- break;
- case MackieControlProtocol::Loop:
- show_two_char_display ("LP");
- id = Button::Loop;
+ id = Button::View;
+ text = _("Mixer View");
break;
case MackieControlProtocol::AudioTracks:
show_two_char_display ("AT");
+ id = Button::AudioTracks;
+ text = _("Audio Tracks");
break;
case MackieControlProtocol::MidiTracks:
show_two_char_display ("MT");
+ id = Button::MidiTracks;
+ text = _("MIDI Tracks");
+ break;
+ case MackieControlProtocol::Plugins:
+ show_two_char_display ("PL");
+ id = Button::Plugin;
+ text = _("Plugins");
+ break;
+ case MackieControlProtocol::Busses:
+ show_two_char_display ("BS");
+ id = Button::Busses;
+ if (Profile->get_mixbus()) {
+ text = _("Mixbusses");
+ } else {
+ text = _("Busses");
+ }
+ break;
+ case MackieControlProtocol::Auxes:
+ show_two_char_display ("Au");
+ id = Button::Aux;
+ text = _("Auxes");
+ break;
+ case MackieControlProtocol::Hidden:
+ show_two_char_display ("HI");
+ id = Button::Outputs;
+ text = _("Hidden Tracks");
+ break;
+ case MackieControlProtocol::Selected:
+ show_two_char_display ("SE");
+ id = Button::User;
+ text = _("Selected Tracks");
break;
default:
break;
}
+ vector<int> view_mode_buttons;
+ view_mode_buttons.push_back (Button::View);
+ view_mode_buttons.push_back (Button::Busses);
+ view_mode_buttons.push_back (Button::Plugin);
+ view_mode_buttons.push_back (Button::AudioTracks);
+ view_mode_buttons.push_back (Button::MidiTracks);
+ view_mode_buttons.push_back (Button::Aux);
+ view_mode_buttons.push_back (Button::Outputs);
+ view_mode_buttons.push_back (Button::User);
+
if (id >= 0) {
- /* we are attempting to turn a global button/LED on */
+ for (vector<int>::iterator i = view_mode_buttons.begin(); i != view_mode_buttons.end(); ++i) {
+ map<int,Control*>::iterator x = controls_by_device_independent_id.find (id);
- map<int,Control*>::iterator x = controls_by_device_independent_id.find (id);
+ if (x != controls_by_device_independent_id.end()) {
+ Button* button = dynamic_cast<Button*> (x->second);
+ if (button) {
+ bool onoff;
+ onoff = (*i) == id;
- if (x != controls_by_device_independent_id.end()) {
- Button* button = dynamic_cast<Button*> (x->second);
- if (button) {
- _port->write (button->set_state (on));
+ _port->write (button->set_state (onoff));
+ }
}
}
}
- if (!text.empty()) {
- for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) {
- _port->write ((*s)->display (1, text));
- }
+ if (with_helpful_text && !text.empty()) {
+ display_message_for (text, 1000);
}
}
return false;
}
+bool
+Surface::route_is_mapped (boost::shared_ptr<Route> r) const
+{
+ for (Strips::const_iterator s = strips.begin(); s != strips.end(); ++s) {
+ if ((*s)->route() == r) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
void
Surface::notify_metering_state_changed()
{