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 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_gain_message, this, 0, _strip->gain_control()), OSC::instance());
53 send_gain_message (0, _strip->gain_control());
61 OSCCueObserver::~OSCCueObserver ()
64 strip_connections.drop_connections ();
66 // all strip buttons should be off and faders 0 and etc.
67 text_with_id ("/cue/name", 0, " ");
68 clear_strip ("/cue/mute", 0);
69 clear_strip ("/cue/fader", 0);
70 clear_strip ("/cue/signal", 0);
72 lo_address_free (addr);
76 OSCCueObserver::tick ()
82 if (_strip->peak_meter()) {
83 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
87 if (now_meter < -120) now_meter = -193;
88 if (_last_meter != now_meter) {
89 string path = "/cue/signal";
90 lo_message msg = lo_message_new ();
92 if (now_meter < -40) {
97 lo_message_add_float (msg, signal);
98 lo_send_message (addr, path.c_str(), msg);
99 lo_message_free (msg);
101 _last_meter = now_meter;
103 for (uint32_t i = 0; i < gain_timeout.size(); i++) {
104 if (gain_timeout[i]) {
105 if (gain_timeout[i] == 1) {
106 name_changed (ARDOUR::Properties::name, i);
115 OSCCueObserver::send_init()
117 for (uint32_t i = 0; i < sends.size(); i++) {
118 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (sends[i]);
119 boost::shared_ptr<Send> send = r->internal_send_for (boost::dynamic_pointer_cast<Route> (_strip));
121 r->processors_changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_restart, this), OSC::instance());
127 sends[i]->PropertyChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::name_changed, this, boost::lambda::_1, i + 1), OSC::instance());
128 name_changed (ARDOUR::Properties::name, i + 1);
132 if (send->gain_control()) {
133 gain_timeout.push_back (0);
134 send->gain_control()->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_gain_message, this, i + 1, send->gain_control()), OSC::instance());
135 send_gain_message (i + 1, send->gain_control());
138 boost::shared_ptr<Processor> proc = boost::dynamic_pointer_cast<Processor> (send);
139 proc->ActiveChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_enabled_message, this, X_("/cue/send_enable"), i + 1, proc->enabled()), OSC::instance());
140 send_enabled_message (X_("/cue/send/enable"), i + 1, proc->enabled());
147 OSCCueObserver::send_end ()
149 send_connections.drop_connections ();
150 for (uint32_t i = 1; i <= sends.size(); i++) {
151 clear_strip (string_compose ("/cue/send/fader/%1", i), 0);
152 clear_strip (string_compose ("/cue/send/enable/%1", i), 0);
153 text_with_id ("/cue/send/name", i, " ");
158 OSCCueObserver::send_restart ()
167 OSCCueObserver::name_changed (const PBD::PropertyChange& what_changed, uint32_t id)
169 if (!what_changed.contains (ARDOUR::Properties::name)) {
177 text_with_id ("/cue/send/name", id, sends[id - 1]->name());
179 text_with_id ("/cue/name", 0, _strip->name());
184 OSCCueObserver::send_change_message (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
186 lo_message msg = lo_message_new ();
189 path = string_compose("%1/%2", path, id);
191 float val = controllable->get_value();
192 lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
194 lo_send_message (addr, path.c_str(), msg);
195 lo_message_free (msg);
199 OSCCueObserver::text_with_id (string path, uint32_t id, string val)
201 lo_message msg = lo_message_new ();
203 path = string_compose("%1/%2", path, id);
206 lo_message_add_string (msg, val.c_str());
208 lo_send_message (addr, path.c_str(), msg);
209 lo_message_free (msg);
213 OSCCueObserver::send_gain_message (uint32_t id, boost::shared_ptr<Controllable> controllable)
215 string path = "/cue";
220 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())));
221 path = string_compose ("%1/fader", path);
223 path = string_compose ("%1/%2", path, id);
225 lo_message msg = lo_message_new ();
226 lo_message_add_float (msg, controllable->internal_to_interface (controllable->get_value()));
227 gain_timeout[id] = 8;
229 lo_send_message (addr, path.c_str(), msg);
230 lo_message_free (msg);
234 OSCCueObserver::send_enabled_message (std::string path, uint32_t id, bool enabled)
236 lo_message msg = lo_message_new ();
239 path = string_compose("%1/%2", path, id);
241 lo_message_add_float (msg, (float) enabled);
243 lo_send_message (addr, path.c_str(), msg);
244 lo_message_free (msg);
249 OSCCueObserver::clear_strip (string path, float val)
251 lo_message msg = lo_message_new ();
252 lo_message_add_float (msg, val);
254 lo_send_message (addr, path.c_str(), msg);
255 lo_message_free (msg);