From 24377e9fb2a2777179e9078219b75beb07aa3b40 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 14 Apr 2012 20:38:42 +0000 Subject: MCP: the return of the master fader git-svn-id: svn://localhost/ardour2/branches/3.0@11973 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/surfaces/mackie/fader.cc | 6 ++++-- libs/surfaces/mackie/fader.h | 1 + libs/surfaces/mackie/surface.cc | 48 +++++++++++++++++++++++++++++++++++++---- libs/surfaces/mackie/surface.h | 14 +++++++----- 4 files changed, 58 insertions(+), 11 deletions(-) (limited to 'libs') diff --git a/libs/surfaces/mackie/fader.cc b/libs/surfaces/mackie/fader.cc index a55c23c129..4a6c81f491 100644 --- a/libs/surfaces/mackie/fader.cc +++ b/libs/surfaces/mackie/fader.cc @@ -17,6 +17,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include + #include "fader.h" #include "surface.h" #include "control_group.h" @@ -50,6 +52,6 @@ Fader::update_message () return MidiByteArray(); } - int posi = int (0x3fff * position); - return MidiByteArray (3, 0xe0 | id(), posi & 0x7f, posi >> 7); + int posi = lrintf (0x3fff * position); + return MidiByteArray (3, 0xe0 + id(), posi & 0x7f, posi >> 7); } diff --git a/libs/surfaces/mackie/fader.h b/libs/surfaces/mackie/fader.h index ed8e72eb50..42a485036e 100644 --- a/libs/surfaces/mackie/fader.h +++ b/libs/surfaces/mackie/fader.h @@ -8,6 +8,7 @@ namespace Mackie { class Fader : public Control { public: + Fader (int id, std::string name, Group & group) : Control (id, name, group) , position (0.0) diff --git a/libs/surfaces/mackie/surface.cc b/libs/surfaces/mackie/surface.cc index 6d47393f60..340e0e07dd 100644 --- a/libs/surfaces/mackie/surface.cc +++ b/libs/surfaces/mackie/surface.cc @@ -7,11 +7,13 @@ #include "midi++/port.h" #include "midi++/manager.h" +#include "ardour/automation_control.h" #include "ardour/debug.h" #include "ardour/route.h" #include "ardour/panner.h" #include "ardour/panner_shell.h" #include "ardour/rc_configuration.h" +#include "ardour/session.h" #include "control_group.h" #include "surface_port.h" @@ -36,7 +38,12 @@ using namespace Mackie; using ARDOUR::Route; using ARDOUR::Panner; using ARDOUR::Pannable; -using ARDOUR::PannerShell; +using ARDOUR::AutomationControl; + +#define ui_context() MackieControlProtocol::instance() /* a UICallback-derived object that specifies the event loop for signal handling */ +#define ui_bind(f, ...) boost::protect (boost::bind (f, __VA_ARGS__)) +extern PBD::EventLoop::InvalidationRecord* __invalidator (sigc::trackable& trackable, const char*, int); +#define invalidator() __invalidator (*(MackieControlProtocol::instance()), __FILE__, __LINE__) // The MCU sysex header.4th byte Will be overwritten // when we get an incoming sysex that identifies @@ -69,6 +76,10 @@ Surface::Surface (MackieControlProtocol& mcp, const std::string& device_name, ui if (_mcp.device_info().has_global_controls()) { init_controls (); } + + if (_mcp.device_info().has_master_fader()) { + setup_master (); + } } uint32_t n = _mcp.device_info().strip_cnt(); @@ -76,7 +87,7 @@ Surface::Surface (MackieControlProtocol& mcp, const std::string& device_name, ui if (n) { init_strips (n); } - + connect_to_signals (); /* wakey wakey */ @@ -194,6 +205,33 @@ Surface::init_strips (uint32_t n) } } +void +Surface::setup_master () +{ + _master_fader = dynamic_cast (Fader::factory (*this, 8, "master", *groups["master"])); + + boost::shared_ptr m; + + if ((m = _mcp.get_session().monitor_out()) == 0) { + m = _mcp.get_session().master_out(); + } + + if (!m) { + return; + } + + _master_fader->set_normal_control (m->gain_control()); + m->gain_control()->Changed.connect (*this, invalidator(), ui_bind (&Surface::master_gain_changed, this), ui_context()); +} + +void +Surface::master_gain_changed () +{ + boost::shared_ptr ac = _master_fader->control(false); + float pos = ac->internal_to_interface (ac->get_value()); + _port->write (_master_fader->set_position (pos)); +} + float Surface::scaled_delta (float delta, float current_speed) { @@ -289,11 +327,13 @@ Surface::handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t pb, uin if (fader) { Strip* strip = dynamic_cast (&fader->group()); + float pos = (pb >> 4)/1023.0; // only the top 10 bytes are used if (strip) { - float midi_pos = pb >> 4; // only the top 10 bytes are used - strip->handle_fader (*fader, midi_pos/1023.0); + strip->handle_fader (*fader, pos); } else { /* master fader */ + fader->set_value (pos, false); // alter master gain + _port->write (fader->set_position (pos)); // write back value (required for servo) } } else { DEBUG_TRACE (DEBUG::MackieControl, "fader not found\n"); diff --git a/libs/surfaces/mackie/surface.h b/libs/surfaces/mackie/surface.h index 5bcd9ebde9..b5a887bbc7 100644 --- a/libs/surfaces/mackie/surface.h +++ b/libs/surfaces/mackie/surface.h @@ -59,9 +59,9 @@ public: std::map controls_by_device_independent_id; Mackie::JogWheel* jog_wheel() const { return _jog_wheel; } + Fader* master_fader() const { return _master_fader; } - /// The collection of all numbered strips. No master - /// strip in here. + /// The collection of all numbered strips. typedef std::vector Strips; Strips strips; @@ -147,9 +147,7 @@ public: MackieControlProtocol& mcp() const { return _mcp; } protected: - void init_controls(); - void init_strips (uint32_t n); - + private: MackieControlProtocol& _mcp; SurfacePort* _port; @@ -159,11 +157,17 @@ public: bool _active; bool _connected; Mackie::JogWheel* _jog_wheel; + Fader* _master_fader; void jog_wheel_state_display (Mackie::JogWheel::State state); void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count); MidiByteArray host_connection_query (MidiByteArray& bytes); MidiByteArray host_connection_confirmation (const MidiByteArray& bytes); + + void init_controls(); + void init_strips (uint32_t n); + void setup_master (); + void master_gain_changed (); }; } -- cgit v1.2.3