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 std::cout << "entered observer\n";
42 addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
44 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::name_changed, this, boost::lambda::_1, 0), OSC::instance());
45 name_changed (ARDOUR::Properties::name, 0);
47 _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCCueObserver::send_change_message, this, X_("/cue/mute"), 0, _strip->mute_control()), OSC::instance());
48 send_change_message ("/cue/mute", 0, _strip->mute_control());
50 gain_timeout.push_back (0);
51 std::cout << "observer past gain timeout for aux\n";
52 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCCueObserver::send_gain_message, this, 0, _strip->gain_control()), OSC::instance());
53 send_gain_message (0, _strip->gain_control());
56 std::cout << "observer past send init\n";
62 OSCCueObserver::~OSCCueObserver ()
65 strip_connections.drop_connections ();
67 // all strip buttons should be off and faders 0 and etc.
68 text_with_id ("/cue/name", 0, " ");
69 clear_strip ("/cue/mute", 0);
70 clear_strip ("/cue/fader", 0);
71 clear_strip ("/cue/signal", 0);
73 lo_address_free (addr);
77 OSCCueObserver::tick ()
83 if (_strip->peak_meter()) {
84 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
88 if (now_meter < -120) now_meter = -193;
89 if (_last_meter != now_meter) {
90 string path = "/cue/signal";
91 lo_message msg = lo_message_new ();
93 if (now_meter < -40) {
98 lo_message_add_float (msg, signal);
99 lo_send_message (addr, path.c_str(), msg);
100 lo_message_free (msg);
102 _last_meter = now_meter;
104 for (uint32_t i = 0; i < gain_timeout.size(); i++) {
105 if (gain_timeout[i]) {
106 if (gain_timeout[i] == 1) {
107 name_changed (ARDOUR::Properties::name, i);
116 OSCCueObserver::send_init()
118 for (uint32_t i = 0; i < sends.size(); i++) {
119 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (sends[i]);
120 boost::shared_ptr<Send> send = r->internal_send_for (boost::dynamic_pointer_cast<Route> (_strip));
122 r->processors_changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_restart, this), OSC::instance());
128 sends[i]->PropertyChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::name_changed, this, boost::lambda::_1, i + 1), OSC::instance());
129 name_changed (ARDOUR::Properties::name, i + 1);
133 if (send->gain_control()) {
134 gain_timeout.push_back (0);
135 send->gain_control()->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_gain_message, this, i + 1, send->gain_control()), OSC::instance());
136 send_gain_message (i + 1, send->gain_control());
139 boost::shared_ptr<Processor> proc = boost::dynamic_pointer_cast<Processor> (send);
140 proc->ActiveChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_enabled_message, this, X_("/cue/send_enable"), i + 1, proc->enabled()), OSC::instance());
141 send_enabled_message (X_("/cue/send/enable"), i + 1, proc->enabled());
148 OSCCueObserver::send_end ()
150 send_connections.drop_connections ();
151 for (uint32_t i = 1; i <= sends.size(); i++) {
152 clear_strip (string_compose ("/cue/send/fader/%1", i), 0);
153 clear_strip (string_compose ("/cue/send/enable/%1", i), 0);
154 text_with_id ("/cue/send/name", i, " ");
159 OSCCueObserver::send_restart ()
168 OSCCueObserver::name_changed (const PBD::PropertyChange& what_changed, uint32_t id)
170 if (!what_changed.contains (ARDOUR::Properties::name)) {
178 text_with_id ("/cue/send/name", id, sends[id - 1]->name());
180 text_with_id ("/cue/name", 0, _strip->name());
185 OSCCueObserver::send_change_message (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
187 lo_message msg = lo_message_new ();
190 path = string_compose("%1/%2", path, id);
192 float val = controllable->get_value();
193 lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
195 lo_send_message (addr, path.c_str(), msg);
196 lo_message_free (msg);
200 OSCCueObserver::text_with_id (string path, uint32_t id, string val)
202 lo_message msg = lo_message_new ();
204 path = string_compose("%1/%2", path, id);
207 lo_message_add_string (msg, val.c_str());
209 lo_send_message (addr, path.c_str(), msg);
210 lo_message_free (msg);
214 OSCCueObserver::send_gain_message (uint32_t id, boost::shared_ptr<Controllable> controllable)
216 string path = "/cue";
221 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())));
222 path = string_compose ("%1/fader", path);
224 path = string_compose ("%1/%2", path, id);
226 lo_message msg = lo_message_new ();
227 lo_message_add_float (msg, gain_to_slider_position (controllable->get_value()));
228 gain_timeout[id] = 8;
230 lo_send_message (addr, path.c_str(), msg);
231 lo_message_free (msg);
235 OSCCueObserver::send_enabled_message (std::string path, uint32_t id, bool enabled)
237 lo_message msg = lo_message_new ();
240 path = string_compose("%1/%2", path, id);
242 lo_message_add_float (msg, (float) enabled);
244 lo_send_message (addr, path.c_str(), msg);
245 lo_message_free (msg);
250 OSCCueObserver::clear_strip (string path, float val)
252 lo_message msg = lo_message_new ();
253 lo_message_add_float (msg, val);
255 lo_send_message (addr, path.c_str(), msg);
256 lo_message_free (msg);