#include <errno.h>
#include <boost/shared_array.hpp>
+#include <glibmm/miscutils.h>
#include "midi++/types.h"
#include "midi++/port.h"
#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"
+#include "ardour/route_group.h"
#include "ardour/session.h"
#include "ardour/tempo.h"
#include "ardour/track.h"
: ControlProtocol (session, X_("Mackie"))
, AbstractUI<MackieControlUIRequest> ("mackie")
, _current_initial_bank (0)
+ , _frame_last (0)
, _timecode_type (ARDOUR::AnyTime::BBT)
, _gui (0)
, _scrub_mode (false)
, 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");
DeviceInfo::reload_device_info ();
DeviceProfile::reload_device_profiles ();
+ for (int i = 0; i < 9; i++) {
+ _last_bank[i] = 0;
+ }
+
+ _last_bank[Mixer] = _current_selected_track;
+
TrackSelectionChanged.connect (gui_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::gui_track_selection_changed, this, _1, true), this);
_instance = this;
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:
+ if (route->route_group()) {
+ route->route_group()->set_active (true, this);
+ }
+ sorted.push_back (route);
+ remote_ids.insert (route->remote_control_id());
break;
case AudioTracks:
+ if (is_audio_track(route)) {
+ if (route->route_group()) {
+ route->route_group()->set_active (true, this);
+ }
+ sorted.push_back (route);
+ remote_ids.insert (route->remote_control_id());
+ }
break;
case Busses:
+ if (!is_track(route)) {
+ if (route->route_group()) {
+ route->route_group()->set_active (true, this);
+ }
+ sorted.push_back (route);
+ remote_ids.insert (route->remote_control_id());
+ }
break;
case MidiTracks:
+ if (is_midi_track(route)) {
+ if (route->route_group()) {
+ route->route_group()->set_active (true, this);
+ }
+ sorted.push_back (route);
+ remote_ids.insert (route->remote_control_id());
+ }
+ break;
+ case Plugins:
+ break;
+ case Auxes: // for now aux and buss are same
+ if (!is_track(route)) {
+ if (route->route_group()) {
+ route->route_group()->set_active (true, this);
+ }
+ sorted.push_back (route);
+ remote_ids.insert (route->remote_control_id());
+ }
break;
- case Loop:
+ case Selected: // For example: a group
+ if (selected(route)) {
+ /* Selected may be a group in which case we want to
+ * control each track separately.
+ */
+ if (route->route_group()) {
+ route->route_group()->set_active (false, this);
+ }
+ sorted.push_back (route);
+ remote_ids.insert (route->remote_control_id());
+ }
break;
}
- sorted.push_back (*it);
- remote_ids.insert (route->remote_control_id());
}
sort (sorted.begin(), sorted.end(), RouteByRemoteId());
*/
return;
}
- set_flip_mode (Normal);
_current_initial_bank = initial;
_current_selected_track = -1;
}
/* reset this to get the right display of view mode after the switch */
- set_view_mode (_view_mode);
+ display_view_mode ();
/* make sure selection is correct */
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()) {
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("device ready init (active=%1)\n", active()));
update_surfaces ();
+ set_pot_mode (_pot_mode);
}
// send messages to surface to set controls to correct values
void
MackieControlProtocol::set_profile (const string& profile_name)
{
- if (profile_name == "default") {
- /* reset to default */
- _device_profile = DeviceProfile (profile_name);
- }
-
map<string,DeviceProfile>::iterator d = DeviceProfile::device_profiles.find (profile_name);
if (d == DeviceProfile::device_profiles.end()) {
+ _device_profile = DeviceProfile (profile_name);
return;
}
/* already using that device, nothing to do */
return 0;
}
-
/* get state from the current setup, and make sure it is stored in
- the _surface_states node so that if we switch back to this device,
+ the configuration_states node so that if we switch back to this device,
we will have its state available.
*/
- if (!_surfaces_state) {
- _surfaces_state = new XMLNode (X_("Surfaces"));
- }
-
{
Glib::Threads::Mutex::Lock lm (surfaces_lock);
-
- for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
- update_surface_state (*s);
+ if (!surfaces.empty()) {
+ update_configuration_state ();
}
}
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));
+
+ DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Port Name for surface %1 is %2\n", n, device_name));
boost::shared_ptr<Surface> surface;
_master_surface = surface;
}
- if (_surfaces_state) {
- 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);
+ }
+ }
}
{
clear_surfaces();
}
-/** Ensure that the _surfaces_state XML node contains an up-to-date
- * copy of the state node for @param surface. If _surfaces_state already
- * contains a state node for @param surface, it will deleted and replaced.
+/** 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_surface_state (boost::shared_ptr<Surface> surface)
+MackieControlProtocol::update_configuration_state ()
{
- assert (_surfaces_state);
- _surfaces_state->remove_nodes_and_delete (X_("name"), surface->name());
- _surfaces_state->add_child_nocopy (surface->get_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&
node.add_property (X_("device-profile"), _device_profile.name());
node.add_property (X_("device-name"), _device_info.name());
- if (!_surfaces_state) {
- _surfaces_state = new XMLNode (X_("Surfaces"));
- }
-
{
Glib::Threads::Mutex::Lock lm (surfaces_lock);
- for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
- update_surface_state (*s);
- }
+ update_configuration_state ();
}
/* force a copy of the _surfaces_state node, because we want to retain ownership */
- node.add_child_copy (*_surfaces_state);
+ node.add_child_copy (*configuration_state);
DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::get_state done\n");
}
if ((prop = node.property (X_("device-profile"))) != 0) {
- set_profile (prop->value());
+ if (prop->value().empty()) {
+ string default_profile_name;
+
+ default_profile_name = Glib::get_user_name();
+ default_profile_name += ' ';
+ default_profile_name += _device_info.name();
+
+ set_profile (default_profile_name);
+ } else {
+ 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);
// do assignment here so current_frame is fixed
framepos_t current_frame = session->transport_frame();
string timecode;
+ // For large jumps in play head possition do full reset
+ int moved = (current_frame - _frame_last) / session->frame_rate ();
+ if (moved) {
+ DEBUG_TRACE (DEBUG::MackieControl, "Timecode reset\n");
+ _timecode_last = string (10, ' ');
+ }
+ _frame_last = current_frame;
switch (_timecode_type) {
case ARDOUR::AnyTime::BBT:
void
MackieControlProtocol::set_view_mode (ViewMode m)
{
- Glib::Threads::Mutex::Lock lm (surfaces_lock);
+ _last_bank[_view_mode] = _current_initial_bank;
_view_mode = m;
+ switch_banks(_last_bank[_view_mode], true);
+}
+
+void
+MackieControlProtocol::display_view_mode ()
+{
+ Glib::Threads::Mutex::Lock lm (surfaces_lock);
+
for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
(*s)->update_view_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;
+}
+
+bool
+MackieControlProtocol::selected (boost::shared_ptr<Route> r) const
+{
+ const RouteNotificationList* rl = &_last_selected_routes;
+
+ for (ARDOUR::RouteNotificationList::const_iterator i = rl->begin(); i != rl->end(); ++i) {
+ boost::shared_ptr<ARDOUR::Route> rt = (*i).lock();
+ if (rt == r) {
+ return true;
+ }
+ }
+ return false;
+}