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());
47 OSCCueObserver::~OSCCueObserver ()
51 lo_address_free (addr);
55 OSCCueObserver::clear_observer ()
59 strip_connections.drop_connections ();
61 // all strip buttons should be off and faders 0 and etc.
62 _osc.text_message_with_id ("/cue/name", 0, " ", true, addr);
63 _osc.float_message ("/cue/mute", 0, addr);
64 _osc.float_message ("/cue/fader", 0, addr);
65 _osc.float_message ("/cue/signal", 0, addr);
70 OSCCueObserver::no_strip ()
72 // This gets called on drop references
75 strip_connections.drop_connections ();
77 * The strip will sit idle at this point doing nothing until
78 * the surface has recalculated it's strip list and then calls
79 * refresh_strip. Otherwise refresh strip will get a strip address
80 * that does not exist... Crash
85 OSCCueObserver::refresh_strip (bool force)
89 uint32_t sid = sur->aux - 1;
90 if (sid >= sur->strips.size ()) {
94 boost::shared_ptr<ARDOUR::Stripable> new_strip = sur->strips[sid];
95 if (_strip && (new_strip == _strip) && !force) {
99 strip_connections.drop_connections ();
103 _strip->DropReferences.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::no_strip, this), OSC::instance());
106 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::name_changed, this, boost::lambda::_1, 0), OSC::instance());
107 name_changed (ARDOUR::Properties::name, 0);
109 _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());
110 send_change_message ("/cue/mute", 0, _strip->mute_control());
112 gain_timeout.push_back (0);
113 _last_gain.push_back (-1.0);
114 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_gain_message, this, 0, _strip->gain_control(), false), OSC::instance());
115 send_gain_message (0, _strip->gain_control(), true);
124 OSCCueObserver::tick ()
130 if (_strip->peak_meter()) {
131 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
135 if (now_meter < -120) now_meter = -193;
136 if (_last_meter != now_meter) {
138 if (now_meter < -40) {
143 _osc.float_message ("/cue/signal", signal, addr);
145 _last_meter = now_meter;
147 for (uint32_t i = 0; i < gain_timeout.size(); i++) {
148 if (gain_timeout[i]) {
149 if (gain_timeout[i] == 1) {
150 name_changed (ARDOUR::Properties::name, i);
159 OSCCueObserver::send_init()
161 for (uint32_t i = 0; i < sends.size(); i++) {
162 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (sends[i]);
163 boost::shared_ptr<Send> send = r->internal_send_for (boost::dynamic_pointer_cast<Route> (_strip));
165 r->processors_changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_restart, this), OSC::instance());
171 sends[i]->PropertyChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::name_changed, this, boost::lambda::_1, i + 1), OSC::instance());
172 name_changed (ARDOUR::Properties::name, i + 1);
176 if (send->gain_control()) {
177 gain_timeout.push_back (0);
178 _last_gain.push_back (-1.0);
179 send->gain_control()->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_gain_message, this, i + 1, send->gain_control(), false), OSC::instance());
180 send_gain_message (i + 1, send->gain_control(), true);
183 boost::shared_ptr<Processor> proc = boost::dynamic_pointer_cast<Processor> (send);
184 proc->ActiveChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_enabled_message, this, X_("/cue/send/enable"), i + 1, proc), OSC::instance());
185 send_enabled_message (X_("/cue/send/enable"), i + 1, proc);
192 OSCCueObserver::send_end ()
194 send_connections.drop_connections ();
195 for (uint32_t i = 1; i <= sends.size(); i++) {
196 _osc.float_message (string_compose ("/cue/send/fader/%1", i), 0, addr);
197 _osc.float_message (string_compose ("/cue/send/enable/%1", i), 0, addr);
198 _osc.text_message_with_id ("/cue/send/name", i, " ", true, addr);
200 gain_timeout.clear ();
205 OSCCueObserver::send_restart ()
214 OSCCueObserver::name_changed (const PBD::PropertyChange& what_changed, uint32_t id)
216 if (!what_changed.contains (ARDOUR::Properties::name)) {
224 _osc.text_message_with_id ("/cue/send/name", id, sends[id - 1]->name(), true, addr);
226 _osc.text_message ("/cue/name", _strip->name(), addr);
231 OSCCueObserver::send_change_message (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
233 // maybe don't need ID only used for mute- maybe mute can use enable
235 path = string_compose("%1/%2", path, id);
237 float val = controllable->get_value();
238 _osc.float_message (path, (float) controllable->internal_to_interface (val), addr);
242 OSCCueObserver::send_gain_message (uint32_t id, boost::shared_ptr<Controllable> controllable, bool force)
244 if (_last_gain[id] != controllable->get_value()) {
245 _last_gain[id] = controllable->get_value();
250 _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);
251 _osc.float_message_with_id ("/cue/send/fader", id, controllable->internal_to_interface (controllable->get_value()), true, addr);
253 _osc.text_message ("/cue/name", string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (controllable->get_value())), addr);
254 _osc.float_message ("/cue/fader", controllable->internal_to_interface (controllable->get_value()), addr);
257 gain_timeout[id] = 8;
261 OSCCueObserver::send_enabled_message (std::string path, uint32_t id, boost::shared_ptr<ARDOUR::Processor> proc)
264 _osc.float_message_with_id (path, id, (float) proc->enabled(), true, addr);
266 _osc.float_message (path, (float) proc->enabled(), addr);