2 Copyright (C) 2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "boost/lambda/lambda.hpp"
22 #include "pbd/control_math.h"
24 #include "ardour/track.h"
25 #include "ardour/dB.h"
26 #include "ardour/meter.h"
29 #include "osc_cue_observer.h"
35 using namespace ARDOUR;
36 using namespace ArdourSurface;
38 OSCCueObserver::OSCCueObserver (OSC& o, ArdourSurface::OSC::OSCSurface* su)
43 addr = lo_address_new_from_url (sur->remote_url.c_str());
44 uint32_t sid = sur->aux - 1;
45 if (sid >= sur->strips.size ()) {
49 _strip = sur->strips[sid];
51 refresh_strip (_strip, sends, true);
54 OSCCueObserver::~OSCCueObserver ()
58 lo_address_free (addr);
62 OSCCueObserver::clear_observer ()
66 strip_connections.drop_connections ();
68 // all strip buttons should be off and faders 0 and etc.
69 _osc.text_message_with_id ("/cue/name", 0, " ", true, addr);
70 _osc.float_message ("/cue/mute", 0, addr);
71 _osc.float_message ("/cue/fader", 0, addr);
72 _osc.float_message ("/cue/signal", 0, addr);
77 OSCCueObserver::refresh_strip (boost::shared_ptr<ARDOUR::Stripable> new_strip, Sorted new_sends, bool force)
81 strip_connections.drop_connections ();
83 send_end (new_sends.size ());
85 _strip->DropReferences.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::clear_observer, this), OSC::instance());
88 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::name_changed, this, boost::lambda::_1, 0), OSC::instance());
89 name_changed (ARDOUR::Properties::name, 0);
91 _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_change_message, this, X_("/cue/mute"), 0, _strip->mute_control()), OSC::instance());
92 send_change_message ("/cue/mute", 0, _strip->mute_control());
94 gain_timeout.push_back (0);
95 _last_gain.push_back (-1.0);
96 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_gain_message, this, 0, _strip->gain_control(), false), OSC::instance());
97 send_gain_message (0, _strip->gain_control(), true);
106 OSCCueObserver::tick ()
112 if (_strip->peak_meter()) {
113 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
117 if (now_meter < -120) now_meter = -193;
118 if (_last_meter != now_meter) {
120 if (now_meter < -40) {
125 _osc.float_message ("/cue/signal", signal, addr);
127 _last_meter = now_meter;
129 for (uint32_t i = 0; i < gain_timeout.size(); i++) {
130 if (gain_timeout[i]) {
131 if (gain_timeout[i] == 1) {
132 name_changed (ARDOUR::Properties::name, i);
141 OSCCueObserver::send_init()
143 for (uint32_t i = 0; i < sends.size(); i++) {
144 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (sends[i]);
145 boost::shared_ptr<Send> send = r->internal_send_for (boost::dynamic_pointer_cast<Route> (_strip));
147 r->processors_changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_restart, this), OSC::instance());
153 sends[i]->PropertyChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::name_changed, this, boost::lambda::_1, i + 1), OSC::instance());
154 name_changed (ARDOUR::Properties::name, i + 1);
158 if (send->gain_control()) {
159 gain_timeout.push_back (0);
160 _last_gain.push_back (-1.0);
161 send->gain_control()->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_gain_message, this, i + 1, send->gain_control(), false), OSC::instance());
162 send_gain_message (i + 1, send->gain_control(), true);
165 boost::shared_ptr<Processor> proc = boost::dynamic_pointer_cast<Processor> (send);
166 proc->ActiveChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_enabled_message, this, X_("/cue/send/enable"), i + 1, proc), OSC::instance());
167 send_enabled_message (X_("/cue/send/enable"), i + 1, proc);
174 OSCCueObserver::send_end (uint32_t new_size)
176 send_connections.drop_connections ();
177 if (new_size < sends.size()) {
178 for (uint32_t i = new_size; i <= sends.size(); i++) {
179 _osc.float_message (string_compose ("/cue/send/fader/%1", i), 0, addr);
180 _osc.float_message (string_compose ("/cue/send/enable/%1", i), 0, addr);
181 _osc.text_message_with_id ("/cue/send/name", i, " ", true, addr);
184 gain_timeout.clear ();
190 OSCCueObserver::send_restart ()
193 send_end(sends.size());
199 OSCCueObserver::name_changed (const PBD::PropertyChange& what_changed, uint32_t id)
201 if (!what_changed.contains (ARDOUR::Properties::name)) {
209 _osc.text_message_with_id ("/cue/send/name", id, sends[id - 1]->name(), true, addr);
211 _osc.text_message ("/cue/name", _strip->name(), addr);
216 OSCCueObserver::send_change_message (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
219 path = string_compose("%1/%2", path, id);
221 float val = controllable->get_value();
222 _osc.float_message (path, (float) controllable->internal_to_interface (val), addr);
226 OSCCueObserver::send_gain_message (uint32_t id, boost::shared_ptr<Controllable> controllable, bool force)
228 if (_last_gain[id] != controllable->get_value()) {
229 _last_gain[id] = controllable->get_value();
234 _osc.text_message_with_id ("/cue/send/name", id, string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (controllable->get_value())), true, addr);
235 _osc.float_message_with_id ("/cue/send/fader", id, controllable->internal_to_interface (controllable->get_value()), true, addr);
237 _osc.text_message ("/cue/name", string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (controllable->get_value())), addr);
238 _osc.float_message ("/cue/fader", controllable->internal_to_interface (controllable->get_value()), addr);
241 gain_timeout[id] = 8;
245 OSCCueObserver::send_enabled_message (std::string path, uint32_t id, boost::shared_ptr<ARDOUR::Processor> proc)
248 _osc.float_message_with_id (path, id, (float) proc->enabled(), true, addr);
250 _osc.float_message (path, (float) proc->enabled(), addr);