2012-04-09 09:59:35 -04:00
|
|
|
/*
|
2019-08-03 08:34:29 -04:00
|
|
|
* Copyright (C) 2006-2007 John Anderson
|
|
|
|
* Copyright (C) 2012-2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2012-04-09 09:59:35 -04:00
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
2012-04-09 11:35:20 -04:00
|
|
|
#include "pbd/compose.h"
|
|
|
|
#include "ardour/debug.h"
|
|
|
|
|
2012-04-09 09:59:35 -04:00
|
|
|
#include "meter.h"
|
|
|
|
#include "surface.h"
|
|
|
|
#include "surface_port.h"
|
|
|
|
#include "control_group.h"
|
2016-01-30 10:46:37 -05:00
|
|
|
#include "mackie_control_protocol.h"
|
2012-04-09 09:59:35 -04:00
|
|
|
|
2012-04-09 11:35:20 -04:00
|
|
|
using namespace PBD;
|
2015-04-15 20:37:20 -04:00
|
|
|
using namespace ArdourSurface;
|
|
|
|
using namespace Mackie;
|
2012-04-09 09:59:35 -04:00
|
|
|
|
|
|
|
Control*
|
2012-04-10 10:27:44 -04:00
|
|
|
Meter::factory (Surface& surface, int id, const char* name, Group& group)
|
2012-04-09 09:59:35 -04:00
|
|
|
{
|
2012-04-10 10:27:44 -04:00
|
|
|
Meter* m = new Meter (id, name, group);
|
2012-04-09 09:59:35 -04:00
|
|
|
surface.meters[id] = m;
|
|
|
|
surface.controls.push_back (m);
|
|
|
|
group.add (*m);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
void
|
2012-06-01 08:56:20 -04:00
|
|
|
Meter::notify_metering_state_changed(Surface& surface, bool transport_is_rolling, bool metering_active)
|
2015-10-05 10:17:49 -04:00
|
|
|
{
|
2012-06-01 08:56:20 -04:00
|
|
|
MidiByteArray msg;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-06-01 08:56:20 -04:00
|
|
|
// sysex header
|
|
|
|
msg << surface.sysex_hdr();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-06-01 08:56:20 -04:00
|
|
|
// code for Channel Meter Enable Message
|
|
|
|
msg << 0x20;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-06-01 08:56:20 -04:00
|
|
|
// Channel identification
|
|
|
|
msg << id();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-06-01 08:56:20 -04:00
|
|
|
// Enable (0x07) / Disable (0x00) level meter on LCD, peak hold display on horizontal meter and signal LED
|
2016-01-30 10:46:37 -05:00
|
|
|
_enabled = ((surface.mcp().device_info().has_separate_meters() || transport_is_rolling) && metering_active);
|
2016-01-29 12:26:41 -05:00
|
|
|
msg << (_enabled ? 0x07 : 0x00);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-06-01 08:56:20 -04:00
|
|
|
// sysex trailer
|
|
|
|
msg << MIDI::eox;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-06-01 08:56:20 -04:00
|
|
|
surface.write (msg);
|
2012-05-30 10:32:27 -04:00
|
|
|
}
|
|
|
|
|
2012-05-21 15:02:44 -04:00
|
|
|
void
|
|
|
|
Meter::send_update (Surface& surface, float dB)
|
2012-04-09 09:59:35 -04:00
|
|
|
{
|
2021-07-02 16:56:11 -04:00
|
|
|
std::pair<bool,float> result = calculate_meter_over_and_deflection(dB);
|
|
|
|
|
|
|
|
MidiByteArray msg;
|
|
|
|
|
|
|
|
if (result.first) {
|
|
|
|
if (!overload_on) {
|
|
|
|
overload_on = true;
|
|
|
|
surface.write (MidiByteArray (2, 0xd0, (id() << 4) | 0xe));
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (overload_on) {
|
|
|
|
overload_on = false;
|
|
|
|
surface.write (MidiByteArray (2, 0xd0, (id() << 4) | 0xf));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we can use up to 13 segments */
|
|
|
|
|
|
|
|
int segment = lrintf ((result.second/115.0) * 13.0);
|
|
|
|
|
|
|
|
surface.write (MidiByteArray (2, 0xd0, (id()<<4) | segment));
|
|
|
|
}
|
|
|
|
|
|
|
|
MidiByteArray
|
|
|
|
Meter::zero ()
|
|
|
|
{
|
|
|
|
return MidiByteArray (2, 0xD0, (id()<<4 | 0));
|
|
|
|
}
|
2012-04-09 12:15:55 -04:00
|
|
|
|
2021-07-02 16:56:11 -04:00
|
|
|
std::pair<bool, float>
|
|
|
|
Meter::calculate_meter_over_and_deflection (float dB)
|
|
|
|
{
|
|
|
|
float def = 0.0f; /* Meter deflection %age */
|
|
|
|
bool over = false;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-04-09 09:59:35 -04:00
|
|
|
if (dB < -70.0f) {
|
|
|
|
def = 0.0f;
|
|
|
|
} else if (dB < -60.0f) {
|
|
|
|
def = (dB + 70.0f) * 0.25f;
|
|
|
|
} else if (dB < -50.0f) {
|
|
|
|
def = (dB + 60.0f) * 0.5f + 2.5f;
|
|
|
|
} else if (dB < -40.0f) {
|
|
|
|
def = (dB + 50.0f) * 0.75f + 7.5f;
|
|
|
|
} else if (dB < -30.0f) {
|
|
|
|
def = (dB + 40.0f) * 1.5f + 15.0f;
|
|
|
|
} else if (dB < -20.0f) {
|
|
|
|
def = (dB + 30.0f) * 2.0f + 30.0f;
|
|
|
|
} else if (dB < 6.0f) {
|
|
|
|
def = (dB + 20.0f) * 2.5f + 50.0f;
|
|
|
|
} else {
|
|
|
|
def = 115.0f;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-04-09 09:59:35 -04:00
|
|
|
/* 115 is the deflection %age that would be
|
|
|
|
when dB=6.0. this is an arbitrary
|
|
|
|
endpoint for our scaling.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (def > 100.0f) {
|
2021-07-02 16:56:11 -04:00
|
|
|
over = true;
|
2012-04-09 09:59:35 -04:00
|
|
|
}
|
2021-07-02 16:56:11 -04:00
|
|
|
return std::make_pair (over, def);
|
2012-05-21 15:02:44 -04:00
|
|
|
}
|