#include "pbd/memento_command.h"
#include "pbd/convert.h"
+#include "ardour/audio_track.h"
#include "ardour/automation_control.h"
#include "ardour/async_midi_port.h"
#include "ardour/dB.h"
#include "ardour/debug.h"
#include "ardour/location.h"
#include "ardour/meter.h"
+#include "ardour/midi_track.h"
#include "ardour/panner.h"
#include "ardour/panner_shell.h"
#include "ardour/route.h"
, needs_ipmidi_restart (false)
, _metering_active (true)
, _initialized (false)
- , _surfaces_state (0)
- , _surfaces_version (0)
- , _session_load (true)
+ , configuration_state (0)
+ , state_version (0)
{
DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::MackieControlProtocol\n");
DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol tear_down_gui ()\n");
tear_down_gui ();
- delete _surfaces_state;
+ delete configuration_state;
/* stop event loop */
DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol BaseUI::quit ()\n");
if (route_is_locked_to_strip(route)) {
continue;
}
- /* This next section which is not used yet, looks wrong to me
- The first four belong here but the bottom five are not a selection
- of routes and belong elsewhere as they are v-pot modes.
- */
+
switch (_view_mode) {
case Mixer:
+ sorted.push_back (*it);
+ remote_ids.insert (route->remote_control_id());
break;
case AudioTracks:
+ if (is_audio_track(*it)) {
+ sorted.push_back (*it);
+ remote_ids.insert (route->remote_control_id());
+ }
break;
case Busses:
+ if (!is_track(*it)) {
+ sorted.push_back (*it);
+ remote_ids.insert (route->remote_control_id());
+ }
break;
case MidiTracks:
+ if (is_midi_track(*it)) {
+ sorted.push_back (*it);
+ remote_ids.insert (route->remote_control_id());
+ }
+ break;
+ case Plugins:
break;
- case Loop:
+ case Auxes:
break;
}
- sorted.push_back (*it);
- remote_ids.insert (route->remote_control_id());
}
sort (sorted.begin(), sorted.end(), RouteByRemoteId());
*/
return;
}
-
_current_initial_bank = initial;
_current_selected_track = -1;
void
MackieControlProtocol::update_global_button (int id, LedState ls)
{
- Glib::Threads::Mutex::Lock lm (surfaces_lock);
+ boost::shared_ptr<Surface> surface;
- if (surfaces.empty()) {
- return;
- }
+ {
+ Glib::Threads::Mutex::Lock lm (surfaces_lock);
- if (!_device_info.has_global_controls()) {
- return;
+ if (surfaces.empty()) {
+ return;
+ }
+
+ if (!_device_info.has_global_controls()) {
+ return;
+ }
+ // surface needs to be master surface
+ surface = _master_surface;
}
- // surface needs to be master surface
- boost::shared_ptr<Surface> surface = _master_surface;
map<int,Control*>::iterator x = surface->controls_by_device_independent_id.find (id);
if (x != surface->controls_by_device_independent_id.end()) {
int
MackieControlProtocol::set_device (const string& device_name, bool force)
{
- cerr << "Set Device\n\n\n\n\n\n";
-
if (device_name == device_info().name() && !force) {
/* already using that device, nothing to do */
return 0;
}
+ /* get state from the current setup, and make sure it is stored in
+ the configuration_states node so that if we switch back to this device,
+ we will have its state available.
+ */
+
+ {
+ Glib::Threads::Mutex::Lock lm (surfaces_lock);
+ if (!surfaces.empty()) {
+ update_configuration_state ();
+ }
+ }
if (set_device_info (device_name)) {
- cerr << "Unknown device name\n";
return -1;
}
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Create %1 surfaces for %2\n", 1 + _device_info.extenders(), _device_info.name()));
+ if (!_device_info.uses_ipmidi()) {
+ _input_bundle.reset (new ARDOUR::Bundle (_("Mackie Control In"), true));
+ _output_bundle.reset (new ARDOUR::Bundle (_("Mackie Control Out"), false));
+ } else {
+ _input_bundle.reset ();
+ _output_bundle.reset ();
+
+ }
for (uint32_t n = 0; n < 1 + _device_info.extenders(); ++n) {
+ bool is_master = false;
+
+ if (n == _device_info.master_position()) {
+ is_master = true;
+ if (_device_info.extenders() == 0) {
+ device_name = _device_info.name();
+ } else {
+ device_name = X_("mackie control");
+ }
- if (n == 0) {
- device_name = _device_info.name();
- } else {
- device_name = string_compose ("%1 #%2", _device_info.name(), n+1);
}
+ if (!is_master) {
+ device_name = string_compose (X_("mackie control ext %1"), n+1);
+ }
+
+ DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Port Name for surface %1 is %2\n", n, device_name));
+
boost::shared_ptr<Surface> surface;
- if (n == _device_info.master_position()) {
+ if (is_master) {
stype = mcu;
} else {
stype = ext;
return -1;
}
- if (n == _device_info.master_position()) {
+ if (is_master) {
_master_surface = surface;
}
- if (_surfaces_state) {
- cerr << "Resetting surface state\n";
- surface->set_state (*_surfaces_state, _surfaces_version);
+ if (configuration_state) {
+ XMLNode* this_device = 0;
+ XMLNodeList const& devices = configuration_state->children();
+ for (XMLNodeList::const_iterator d = devices.begin(); d != devices.end(); ++d) {
+ XMLProperty* prop = (*d)->property (X_("name"));
+ if (prop && prop->value() == _device_info.name()) {
+ this_device = *d;
+ break;
+ }
+ }
+ if (this_device) {
+ XMLNode* snode = this_device->child (X_("Surfaces"));
+ if (snode) {
+ surface->set_state (*snode, state_version);
+ }
+ }
}
{
if (!_device_info.uses_ipmidi()) {
- _input_bundle.reset (new ARDOUR::Bundle (_("Mackie Control In"), true));
- _output_bundle.reset (new ARDOUR::Bundle (_("Mackie Control Out"), false));
-
_input_bundle->add_channel (
surface->port().input_port().name(),
ARDOUR::DataType::MIDI,
ARDOUR::DataType::MIDI,
session->engine().make_port_name_non_relative (surface->port().output_port().name())
);
-
- session->BundleAddedOrRemoved ();
-
- } else {
- _input_bundle.reset ((ARDOUR::Bundle*) 0);
- _output_bundle.reset ((ARDOUR::Bundle*) 0);
-
- session->BundleAddedOrRemoved ();
}
MIDI::Port& input_port (surface->port().input_port());
}
}
+ if (!_device_info.uses_ipmidi()) {
+ Glib::Threads::Mutex::Lock lm (surfaces_lock);
+ for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
+ (*s)->port().reconnect ();
+ }
+ }
+
+ session->BundleAddedOrRemoved ();
+
+ assert (_master_surface);
+
return 0;
}
clear_surfaces();
}
+/** Ensure that the configuration_state XML node contains an up-to-date
+ * copy of the state node the current device. If configuration_state already
+ * contains a state node for the device, it will deleted and replaced.
+ */
+void
+MackieControlProtocol::update_configuration_state ()
+{
+ /* CALLER MUST HOLD SURFACES LOCK */
+
+ if (!configuration_state) {
+ configuration_state = new XMLNode (X_("Configurations"));
+ }
+
+ XMLNode* devnode = new XMLNode (X_("Configuration"));
+ devnode->add_property (X_("name"), _device_info.name());
+
+ configuration_state->remove_nodes_and_delete (X_("name"), _device_info.name());
+ configuration_state->add_child_nocopy (*devnode);
+
+ XMLNode* snode = new XMLNode (X_("Surfaces"));
+
+ for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
+ snode->add_child_nocopy ((*s)->get_state());
+ }
+
+ devnode->add_child_nocopy (*snode);
+}
+
XMLNode&
MackieControlProtocol::get_state()
{
node.add_property (X_("device-profile"), _device_profile.name());
node.add_property (X_("device-name"), _device_info.name());
- XMLNode* snode = new XMLNode (X_("Surfaces"));
- for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
- snode->add_child_nocopy ((*s)->get_state());
+ {
+ Glib::Threads::Mutex::Lock lm (surfaces_lock);
+ update_configuration_state ();
}
- node.add_child_nocopy (*snode);
+ /* force a copy of the _surfaces_state node, because we want to retain ownership */
+ node.add_child_copy (*configuration_state);
DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::get_state done\n");
set_profile (prop->value());
}
- XMLNode* snode = node.child (X_("Surfaces"));
+ XMLNode* dnode = node.child (X_("Configurations"));
- delete _surfaces_state;
- _surfaces_state = 0;
+ delete configuration_state;
+ configuration_state = 0;
- if (snode) {
- _surfaces_state = new XMLNode (*snode);
- _surfaces_version = version;
+ if (dnode) {
+ configuration_state = new XMLNode (*dnode);
+ state_version = version;
}
switch_banks (bank, true);
void
MackieControlProtocol::set_flip_mode (FlipMode fm)
{
- Glib::Threads::Mutex::Lock lm (surfaces_lock);
+ if (_flip_mode != fm) {
+ if (fm == Normal) {
+ update_global_button (Button::Flip, off);
+ } else {
+ update_global_button (Button::Flip, on);
+ }
- _flip_mode = fm;
+ Glib::Threads::Mutex::Lock lm (surfaces_lock);
- for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
- (*s)->update_flip_mode_display ();
+ _flip_mode = fm;
+
+ for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
+ (*s)->update_flip_mode_display ();
+ }
}
}
void
MackieControlProtocol::set_pot_mode (PotMode m)
{
- Glib::Threads::Mutex::Lock lm (surfaces_lock);
-
+ // maybe not in flip mode.
+ if (flip_mode()) {
+ return;
+ }
_pot_mode = m;
- for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
- (*s)->update_potmode ();
+ {
+ Glib::Threads::Mutex::Lock lm (surfaces_lock);
+ for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
+ (*s)->update_potmode ();
+
+ }
}
+ switch (_pot_mode) {
+ case Trim:
+ update_global_button (Button::Track, on);
+ update_global_button (Button::Send, off);
+ update_global_button (Button::Pan, off);
+ break;
+ case Send:
+ update_global_button (Button::Track, off);
+ update_global_button (Button::Send, on);
+ update_global_button (Button::Pan, off);
+ break;
+ case Pan:
+ update_global_button (Button::Track, off);
+ update_global_button (Button::Send, off);
+ update_global_button (Button::Pan, on);
+ };
}
void
}
}
}
+
+bool
+MackieControlProtocol::is_track (boost::shared_ptr<Route> r) const
+{
+ return boost::dynamic_pointer_cast<Track>(r) != 0;
+}
+
+bool
+MackieControlProtocol::is_audio_track (boost::shared_ptr<Route> r) const
+{
+ return boost::dynamic_pointer_cast<AudioTrack>(r) != 0;
+}
+
+bool
+MackieControlProtocol::is_midi_track (boost::shared_ptr<Route> r) const
+{
+ return boost::dynamic_pointer_cast<MidiTrack>(r) != 0;
+}