MCP: the return of the master fader

git-svn-id: svn://localhost/ardour2/branches/3.0@11973 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2012-04-14 20:38:42 +00:00
parent 2ed2b61224
commit 24377e9fb2
4 changed files with 58 additions and 11 deletions

View file

@ -17,6 +17,8 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <cmath>
#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);
}

View file

@ -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)

View file

@ -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*> (Fader::factory (*this, 8, "master", *groups["master"]));
boost::shared_ptr<Route> 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<AutomationControl> 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<Strip*> (&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");

View file

@ -59,9 +59,9 @@ public:
std::map<int,Control*> 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<Strip*> 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 ();
};
}