#include <sys/time.h>
+#include <glibmm/convert.h>
+
#include "midi++/port.h"
#include "pbd/compose.h"
#include "jog.h"
#include "meter.h"
-using namespace Mackie;
using namespace std;
using namespace ARDOUR;
using namespace PBD;
+using namespace ArdourSurface;
+using namespace Mackie;
+
+#ifndef timeradd /// only avail with __USE_BSD
+#define timeradd(a,b,result) \
+ do { \
+ (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
+ (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
+ if ((result)->tv_usec >= 1000000) \
+ { \
+ ++(result)->tv_sec; \
+ (result)->tv_usec -= 1000000; \
+ } \
+ } while (0)
+#endif
#define ui_context() MackieControlProtocol::instance() /* a UICallback-derived object that specifies the event loop for signal handling */
, _fader_touch (0)
, _vpot (0)
, _fader (0)
+ , _meter (0)
, _index (index)
, _surface (&s)
, _controls_locked (false)
, _last_gain_position_written (-1.0)
, _last_pan_azi_position_written (-1.0)
, _last_pan_width_position_written (-1.0)
+ , redisplay_requests (256)
{
_fader = dynamic_cast<Fader*> (Fader::factory (*_surface, index, "fader", *this));
_vpot = dynamic_cast<Pot*> (Pot::factory (*_surface, Pot::ID + index, "vpot", *this));
for (map<Button::ID,StripButtonInfo>::const_iterator b = strip_buttons.begin(); b != strip_buttons.end(); ++b) {
Button* bb = dynamic_cast<Button*> (Button::factory (*_surface, b->first, b->second.base_id + index, b->second.name, *this));
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface %1 strip %2 new button BID %3 id %4 from base %5\n",
- _surface->number(), index, Button::id_to_name (bb->bid()),
+ _surface->number(), index, Button::id_to_name (bb->bid()),
bb->id(), b->second.base_id));
}
}
/* surface is responsible for deleting all controls */
}
-void
+void
Strip::add (Control & control)
{
Button* button;
break;
case Button::FaderTouch:
_fader_touch = button;
+ break;
default:
break;
}
boost::shared_ptr<Pannable> pannable = _route->pannable();
- if (pannable && pannable->panner()) {
+ if (pannable && _route->panner()) {
pannable->pan_azimuth_control->Changed.connect(route_connections, MISSING_INVALIDATOR, boost::bind (&Strip::notify_panner_azi_changed, this, false), ui_context());
pannable->pan_width_control->Changed.connect(route_connections, MISSING_INVALIDATOR, boost::bind (&Strip::notify_panner_width_changed, this, false), ui_context());
}
possible_pot_parameters.clear();
if (pannable) {
- boost::shared_ptr<Panner> panner = pannable->panner();
+ boost::shared_ptr<Panner> panner = _route->panner();
if (panner) {
set<Evoral::Parameter> automatable = panner->what_can_be_automated ();
set<Evoral::Parameter>::iterator a;
}
}
-void
+void
Strip::notify_all()
{
if (!_route) {
notify_record_enable_changed ();
}
-void
+void
Strip::notify_solo_changed ()
{
if (_route && _solo) {
}
}
-void
+void
Strip::notify_mute_changed ()
{
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Strip %1 mute changed\n", _index));
}
}
-void
+void
Strip::notify_record_enable_changed ()
{
if (_route && _recenable) {
}
}
-void
+void
Strip::notify_active_changed ()
{
_surface->mcp().refresh_current_bank();
}
-void
+void
Strip::notify_route_deleted ()
{
_surface->mcp().refresh_current_bank();
}
-void
+void
Strip::notify_gain_changed (bool force_update)
{
if (_route) {
Control* control;
- if (_surface->mcp().flip_mode()) {
+ if (_surface->mcp().flip_mode() != MackieControlProtocol::Normal) {
control = _vpot;
} else {
control = _fader;
}
-
boost::shared_ptr<AutomationControl> ac = _route->gain_control();
float gain_coefficient = ac->get_value();
float normalized_position = ac->internal_to_interface (gain_coefficient);
-
+
+
if (force_update || normalized_position != _last_gain_position_written) {
- if (_surface->mcp().flip_mode()) {
+ if (_surface->mcp().flip_mode() != MackieControlProtocol::Normal) {
if (!control->in_use()) {
_surface->write (_vpot->set (normalized_position, true, Pot::wrap));
}
- do_parameter_display (GainAutomation, gain_coefficient);
+ queue_parameter_display (GainAutomation, gain_coefficient);
} else {
if (!control->in_use()) {
_surface->write (_fader->set_position (normalized_position));
}
- do_parameter_display (GainAutomation, gain_coefficient);
+ queue_parameter_display (GainAutomation, gain_coefficient);
}
queue_display_reset (2000);
}
}
-void
+void
Strip::notify_property_changed (const PropertyChange& what_changed)
{
if (!what_changed.contains (ARDOUR::Properties::name)) {
} else {
line1 = PBD::short_version (fullname, 6);
}
-
+
_surface->write (display (0, line1));
}
}
-void
+void
Strip::notify_panner_azi_changed (bool force_update)
{
if (_route) {
boost::shared_ptr<Pannable> pannable = _route->pannable();
- if (!pannable || !pannable->panner()) {
+ if (!pannable || !_route->panner()) {
_surface->write (_vpot->zero());
return;
}
_surface->write (_vpot->set (pos, true, Pot::dot));
}
- do_parameter_display (PanAzimuthAutomation, pos);
+ queue_parameter_display (PanAzimuthAutomation, pos);
queue_display_reset (2000);
_last_pan_azi_position_written = pos;
}
}
}
-void
+void
Strip::notify_panner_width_changed (bool force_update)
{
if (_route) {
boost::shared_ptr<Pannable> pannable = _route->pannable();
- if (!pannable || !pannable->panner()) {
+ if (!pannable || !_route->panner()) {
_surface->write (_vpot->zero());
return;
}
if (force_update || pos != _last_pan_azi_position_written) {
- if (_surface->mcp().flip_mode()) {
+ if (_surface->mcp().flip_mode() != MackieControlProtocol::Normal) {
if (control == _fader) {
if (!control->in_use()) {
_surface->write (_vpot->set (pos, true, Pot::spread));
}
- do_parameter_display (PanWidthAutomation, pos);
+ queue_parameter_display (PanWidthAutomation, pos);
queue_display_reset (2000);
_last_pan_azi_position_written = pos;
}
if (bs == press) {
- int ms = _surface->mcp().modifier_state();
+ int ms = _surface->mcp().main_modifier_state();
if (ms & MackieControlProtocol::MODIFIER_CMDALT) {
_controls_locked = !_controls_locked;
{
if (bs == press) {
- int ms = _surface->mcp().modifier_state();
+ int ms = _surface->mcp().main_modifier_state();
if (ms & MackieControlProtocol::MODIFIER_SHIFT) {
boost::shared_ptr<AutomationControl> ac = _fader->control ();
- if (_surface->mcp().modifier_state() == MackieControlProtocol::MODIFIER_SHIFT) {
+ if (_surface->mcp().main_modifier_state() & MackieControlProtocol::MODIFIER_SHIFT) {
if (ac) {
ac->set_value (ac->normal());
}
} else {
-
+
_fader->set_in_use (true);
_fader->start_touch (_surface->mcp().transport_frame());
if (ac) {
- do_parameter_display ((AutomationType) ac->parameter().type(), ac->internal_to_interface (ac->get_value()));
+ queue_parameter_display ((AutomationType) ac->parameter().type(), ac->internal_to_interface (ac->get_value()));
queue_display_reset (2000);
}
}
_surface->mcp().add_down_button ((AutomationType) control->parameter().type(), _surface->number(), _index);
float new_value;
- int ms = _surface->mcp().modifier_state();
+ int ms = _surface->mcp().main_modifier_state();
if (ms & MackieControlProtocol::MODIFIER_SHIFT) {
/* reset to default/normal value */
}
}
+void
+Strip::queue_parameter_display (AutomationType type, float val)
+{
+ RedisplayRequest req;
+
+ req.type = type;
+ req.val = val;
+
+ redisplay_requests.write (&req, 1);
+}
+
void
Strip::do_parameter_display (AutomationType type, float val)
{
case PanAzimuthAutomation:
if (_route) {
boost::shared_ptr<Pannable> p = _route->pannable();
- if (p && p->panner()) {
- string str = p->panner()->value_as_string (p->pan_azimuth_control);
+ if (p && _route->panner()) {
+ string str =_route->panner()->value_as_string (p->pan_azimuth_control);
_surface->write (display (1, str));
}
}
case PanWidthAutomation:
if (_route) {
char buf[16];
- snprintf (buf, sizeof (buf), "%5ld%%", lrintf (val * 100.0));
+ snprintf (buf, sizeof (buf), "%5ld%%", lrintf ((val * 200.0)-100));
_surface->write (display (1, buf));
}
break;
}
}
+void
+Strip::handle_fader_touch (Fader& fader, bool touch_on)
+{
+ if (touch_on) {
+ fader.start_touch (_surface->mcp().transport_frame());
+ } else {
+ fader.stop_touch (_surface->mcp().transport_frame(), false);
+ }
+}
+
void
Strip::handle_fader (Fader& fader, float position)
{
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("fader to %1\n", position));
fader.set_value (position);
- fader.start_touch (_surface->mcp().transport_frame());
- queue_display_reset (2000);
- // must echo bytes back to slider now, because
- // the notifier only works if the fader is not being
- // touched. Which it is if we're getting input.
+ /* From the Mackie Control MIDI implementation docs:
+
+ In order to ensure absolute synchronization with the host software,
+ Mackie Control uses a closed-loop servo system for the faders,
+ meaning the faders will always move to their last received position.
+ When a host receives a Fader Position Message, it must then
+ re-transmit that message to the Mackie Control or else the faders
+ will return to their last position.
+ */
_surface->write (fader.set_position (position));
}
}
}
-void
+void
+Strip::redisplay ()
+{
+ RedisplayRequest req;
+ bool have_request = false;
+
+ while (redisplay_requests.read (&req, 1) == 1) {
+ /* read them all */
+ have_request = true;
+ }
+
+ if (have_request) {
+ do_parameter_display (req.type, req.val);
+ }
+}
+
+void
Strip::update_automation ()
{
ARDOUR::AutoState gain_state = _route->gain_control()->automation_state();
Strip::update_meter ()
{
if (_meter && _transport_is_rolling && _metering_active) {
- float dB = const_cast<PeakMeter&> (_route->peak_meter()).peak_power (0);
+ float dB = const_cast<PeakMeter&> (_route->peak_meter()).meter_level (0, MeterMCP);
_meter->send_update (*_surface, dB);
}
}
// offset (0 to 0x37 first line, 0x38 to 0x6f for second line)
retval << (_index * 7 + (line_number * 0x38));
- // ascii data to display
- retval << line;
+ // ascii data to display. @param line is UTF-8
+ string ascii = Glib::convert_with_fallback (line, "UTF-8", "ISO-8859-1", "_");
+ string::size_type len = ascii.length();
+ if (len > 6) {
+ ascii = ascii.substr (0, 6);
+ len = 6;
+ }
+ retval << ascii;
// pad with " " out to 6 chars
- for (int i = line.length(); i < 6; ++i) {
+ for (int i = len; i < 6; ++i) {
retval << ' ';
}
clear_display_reset ();
}
-
+
struct RouteCompareByName {
bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
return a->name().compare (b->name()) < 0;
{
vector<Evoral::Parameter>::iterator i;
- if (_surface->mcp().flip_mode()) {
+ if (_surface->mcp().flip_mode() != MackieControlProtocol::Normal) {
/* do not change vpot mode while in flipped mode */
DEBUG_TRACE (DEBUG::MackieControl, "not stepping pot mode - in flip mode\n");
_surface->write (display (1, "Flip"));
case PanAzimuthAutomation:
pannable = _route->pannable ();
if (pannable) {
- if (_surface->mcp().flip_mode()) {
+ if (_surface->mcp().flip_mode() != MackieControlProtocol::Normal) {
/* gain to vpot, pan azi to fader */
_vpot->set_control (_route->gain_control());
control_by_parameter[GainAutomation] = _vpot;
case PanWidthAutomation:
pannable = _route->pannable ();
if (pannable) {
- if (_surface->mcp().flip_mode()) {
+ if (_surface->mcp().flip_mode() != MackieControlProtocol::Normal) {
/* gain to vpot, pan width to fader */
_vpot->set_control (_route->gain_control());
control_by_parameter[GainAutomation] = _vpot;
}
-void
+void
Strip::notify_metering_state_changed()
{
if (!_route || !_meter) {