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 (boost::shared_ptr<Stripable> s, std::vector<boost::shared_ptr<ARDOUR::Stripable> >& snds, lo_address a)
43 addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
45 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::name_changed, this, boost::lambda::_1, 0), OSC::instance());
46 name_changed (ARDOUR::Properties::name, 0);
48 _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());
49 send_change_message ("/cue/mute", 0, _strip->mute_control());
51 gain_timeout.push_back (0);
52 _last_gain.push_back (0.0);
53 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_gain_message, this, 0, _strip->gain_control()), OSC::instance());
54 send_gain_message (0, _strip->gain_control());
62 OSCCueObserver::~OSCCueObserver ()
66 strip_connections.drop_connections ();
68 // all strip buttons should be off and faders 0 and etc.
69 text_with_id ("/cue/name", 0, " ");
70 clear_strip ("/cue/mute", 0);
71 clear_strip ("/cue/fader", 0);
72 clear_strip ("/cue/signal", 0);
74 lo_address_free (addr);
78 OSCCueObserver::tick ()
84 if (_strip->peak_meter()) {
85 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
89 if (now_meter < -120) now_meter = -193;
90 if (_last_meter != now_meter) {
91 string path = "/cue/signal";
92 lo_message msg = lo_message_new ();
94 if (now_meter < -40) {
99 lo_message_add_float (msg, signal);
100 lo_send_message (addr, path.c_str(), msg);
101 lo_message_free (msg);
103 _last_meter = now_meter;
105 for (uint32_t i = 0; i < gain_timeout.size(); i++) {
106 if (gain_timeout[i]) {
107 if (gain_timeout[i] == 1) {
108 name_changed (ARDOUR::Properties::name, i);
117 OSCCueObserver::send_init()
119 for (uint32_t i = 0; i < sends.size(); i++) {
120 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (sends[i]);
121 boost::shared_ptr<Send> send = r->internal_send_for (boost::dynamic_pointer_cast<Route> (_strip));
123 r->processors_changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_restart, this), OSC::instance());
129 sends[i]->PropertyChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::name_changed, this, boost::lambda::_1, i + 1), OSC::instance());
130 name_changed (ARDOUR::Properties::name, i + 1);
134 if (send->gain_control()) {
135 gain_timeout.push_back (0);
136 _last_gain.push_back (0.0);
137 send->gain_control()->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_gain_message, this, i + 1, send->gain_control()), OSC::instance());
138 send_gain_message (i + 1, send->gain_control());
141 boost::shared_ptr<Processor> proc = boost::dynamic_pointer_cast<Processor> (send);
142 proc->ActiveChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_enabled_message, this, X_("/cue/send_enable"), i + 1, proc->enabled()), OSC::instance());
143 send_enabled_message (X_("/cue/send/enable"), i + 1, proc->enabled());
150 OSCCueObserver::send_end ()
152 send_connections.drop_connections ();
153 for (uint32_t i = 1; i <= sends.size(); i++) {
154 clear_strip (string_compose ("/cue/send/fader/%1", i), 0);
155 clear_strip (string_compose ("/cue/send/enable/%1", i), 0);
156 text_with_id ("/cue/send/name", i, " ");
161 OSCCueObserver::send_restart ()
170 OSCCueObserver::name_changed (const PBD::PropertyChange& what_changed, uint32_t id)
172 if (!what_changed.contains (ARDOUR::Properties::name)) {
180 text_with_id ("/cue/send/name", id, sends[id - 1]->name());
182 text_with_id ("/cue/name", 0, _strip->name());
187 OSCCueObserver::send_change_message (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
189 lo_message msg = lo_message_new ();
192 path = string_compose("%1/%2", path, id);
194 float val = controllable->get_value();
195 lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
197 lo_send_message (addr, path.c_str(), msg);
198 lo_message_free (msg);
202 OSCCueObserver::text_with_id (string path, uint32_t id, string val)
204 lo_message msg = lo_message_new ();
206 path = string_compose("%1/%2", path, id);
209 lo_message_add_string (msg, val.c_str());
211 lo_send_message (addr, path.c_str(), msg);
212 lo_message_free (msg);
216 OSCCueObserver::send_gain_message (uint32_t id, boost::shared_ptr<Controllable> controllable)
218 if (_last_gain[id] != controllable->get_value()) {
219 _last_gain[id] = controllable->get_value();
223 string path = "/cue";
228 text_with_id (string_compose ("%1/name", path), id, string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (controllable->get_value())));
229 path = string_compose ("%1/fader", path);
231 path = string_compose ("%1/%2", path, id);
233 lo_message msg = lo_message_new ();
234 lo_message_add_float (msg, controllable->internal_to_interface (controllable->get_value()));
235 gain_timeout[id] = 8;
237 lo_send_message (addr, path.c_str(), msg);
238 lo_message_free (msg);
242 OSCCueObserver::send_enabled_message (std::string path, uint32_t id, bool enabled)
244 lo_message msg = lo_message_new ();
247 path = string_compose("%1/%2", path, id);
249 lo_message_add_float (msg, (float) enabled);
251 lo_send_message (addr, path.c_str(), msg);
252 lo_message_free (msg);
257 OSCCueObserver::clear_strip (string path, float val)
259 lo_message msg = lo_message_new ();
260 lo_message_add_float (msg, val);
262 lo_send_message (addr, path.c_str(), msg);
263 lo_message_free (msg);