2 Copyright (C) 2006,2007 John Anderson
3 Copyright (C) 2012 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "surface_port.h"
25 #include "control_group.h"
27 using namespace Mackie;
30 Meter::factory (Surface& surface, int id, int ordinal, const char* name, Group& group)
32 Meter* m = new Meter (id, ordinal, name, group);
33 surface.meters[id] = m;
34 surface.controls.push_back (m);
40 Meter::update_message (float dB)
42 float def = 0.0f; /* Meter deflection %age */
46 } else if (dB < -60.0f) {
47 def = (dB + 70.0f) * 0.25f;
48 } else if (dB < -50.0f) {
49 def = (dB + 60.0f) * 0.5f + 2.5f;
50 } else if (dB < -40.0f) {
51 def = (dB + 50.0f) * 0.75f + 7.5f;
52 } else if (dB < -30.0f) {
53 def = (dB + 40.0f) * 1.5f + 15.0f;
54 } else if (dB < -20.0f) {
55 def = (dB + 30.0f) * 2.0f + 30.0f;
56 } else if (dB < 6.0f) {
57 def = (dB + 20.0f) * 2.5f + 50.0f;
62 /* 115 is the deflection %age that would be
63 when dB=6.0. this is an arbitrary
64 endpoint for our scaling.
72 msg << MidiByteArray (2, 0xd0, (raw_id() << 4) | 0xe);
77 msg << MidiByteArray (2, 0xd0, (raw_id() << 4) | 0xf);
81 /* we can use up to 13 segments */
83 int segment = lrintf ((def/115.0) * 13.0);
85 if (last_segment_value_sent != segment) {
86 last_segment_value_sent = segment;
87 std::cerr << "Meter ID " << raw_id() << " as byte " << (((int) raw_id() << 4) | segment) << std::endl;
88 msg << MidiByteArray (2, 0xD0, (raw_id()<<4) | segment);