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 "ardour/track.h"
23 #include "ardour/dB.h"
24 #include "ardour/meter.h"
27 #include "osc_cue_observer.h"
33 using namespace ARDOUR;
34 using namespace ArdourSurface;
36 OSCCueObserver::OSCCueObserver (boost::shared_ptr<Stripable> s, std::vector<boost::shared_ptr<ARDOUR::Stripable> >& snds, lo_address a)
41 addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
43 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::name_changed, this, boost::lambda::_1, 0), OSC::instance());
44 name_changed (ARDOUR::Properties::name, 0);
46 _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCCueObserver::send_change_message, this, X_("/cue/mute"), 0, _strip->mute_control()), OSC::instance());
47 send_change_message ("/cue/mute", 0, _strip->mute_control());
49 gain_timeout.push_back (0);
50 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCCueObserver::send_gain_message, this, 0, _strip->gain_control()), OSC::instance());
51 send_gain_message (0, _strip->gain_control());
59 OSCCueObserver::~OSCCueObserver ()
62 strip_connections.drop_connections ();
64 // all strip buttons should be off and faders 0 and etc.
65 text_with_id ("/cue/name", 0, " ");
66 clear_strip ("/cue/mute", 0);
67 clear_strip ("/cue/fader", 0);
68 clear_strip ("/cue/signal", 0);
70 lo_address_free (addr);
74 OSCCueObserver::tick ()
80 if (_strip->peak_meter()) {
81 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
85 if (now_meter < -120) now_meter = -193;
86 if (_last_meter != now_meter) {
87 string path = "/cue/signal";
88 lo_message msg = lo_message_new ();
90 if (now_meter < -40) {
95 lo_message_add_float (msg, signal);
96 lo_send_message (addr, path.c_str(), msg);
97 lo_message_free (msg);
99 _last_meter = now_meter;
101 for (uint32_t i = 0; i < gain_timeout.size(); i++) {
102 if (gain_timeout[i]) {
103 if (gain_timeout[i] == 1) {
104 name_changed (ARDOUR::Properties::name, i);
113 OSCCueObserver::send_init()
115 for (uint32_t i = 0; i < sends.size(); i++) {
116 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (sends[i]);
117 boost::shared_ptr<Send> send = r->internal_send_for (boost::dynamic_pointer_cast<Route> (_strip));
119 r->processors_changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_restart, this), OSC::instance());
125 sends[i]->PropertyChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::name_changed, this, boost::lambda::_1, i + 1), OSC::instance());
126 name_changed (ARDOUR::Properties::name, i + 1);
130 if (send->gain_control()) {
131 gain_timeout.push_back (0);
132 send->gain_control()->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_gain_message, this, i + 1, send->gain_control()), OSC::instance());
133 send_gain_message (i + 1, send->gain_control());
136 boost::shared_ptr<Processor> proc = boost::dynamic_pointer_cast<Processor> (send);
137 proc->ActiveChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_enabled_message, this, X_("/cue/send_enable"), i + 1, proc->enabled()), OSC::instance());
138 send_enabled_message (X_("/cue/send/enable"), i + 1, proc->enabled());
145 OSCCueObserver::send_end ()
147 send_connections.drop_connections ();
148 for (uint32_t i = 1; i <= sends.size(); i++) {
149 clear_strip (string_compose ("/cue/send/fader/%1", i), 0);
150 clear_strip (string_compose ("/cue/send/enable/%1", i), 0);
151 text_with_id ("/cue/send/name", i, " ");
156 OSCCueObserver::send_restart ()
165 OSCCueObserver::name_changed (const PBD::PropertyChange& what_changed, uint32_t id)
167 if (!what_changed.contains (ARDOUR::Properties::name)) {
175 text_with_id ("/cue/send/name", id, sends[id - 1]->name());
177 text_with_id ("/cue/name", 0, _strip->name());
182 OSCCueObserver::send_change_message (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
184 lo_message msg = lo_message_new ();
187 path = string_compose("%1/%2", path, id);
189 float val = controllable->get_value();
190 lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
192 lo_send_message (addr, path.c_str(), msg);
193 lo_message_free (msg);
197 OSCCueObserver::text_with_id (string path, uint32_t id, string val)
199 lo_message msg = lo_message_new ();
201 path = string_compose("%1/%2", path, id);
204 lo_message_add_string (msg, val.c_str());
206 lo_send_message (addr, path.c_str(), msg);
207 lo_message_free (msg);
211 OSCCueObserver::send_gain_message (uint32_t id, boost::shared_ptr<Controllable> controllable)
213 string path = "/cue";
218 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())));
219 path = string_compose ("%1/fader", path);
221 path = string_compose ("%1/%2", path, id);
223 lo_message msg = lo_message_new ();
224 lo_message_add_float (msg, gain_to_slider_position (controllable->get_value()));
225 gain_timeout[id] = 8;
227 lo_send_message (addr, path.c_str(), msg);
228 lo_message_free (msg);
232 OSCCueObserver::send_enabled_message (std::string path, uint32_t id, bool enabled)
234 lo_message msg = lo_message_new ();
237 path = string_compose("%1/%2", path, id);
239 lo_message_add_float (msg, (float) enabled);
241 lo_send_message (addr, path.c_str(), msg);
242 lo_message_free (msg);
247 OSCCueObserver::clear_strip (string path, float val)
249 lo_message msg = lo_message_new ();
250 lo_message_add_float (msg, val);
252 lo_send_message (addr, path.c_str(), msg);
253 lo_message_free (msg);