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/session.h"
23 #include "ardour/track.h"
24 #include "ardour/monitor_control.h"
25 #include "ardour/dB.h"
26 #include "ardour/meter.h"
29 #include "osc_select_observer.h"
35 using namespace ARDOUR;
36 using namespace ArdourSurface;
38 OSCSelectObserver::OSCSelectObserver (boost::shared_ptr<Stripable> s, lo_address a, uint32_t ss, uint32_t gm, std::bitset<32> fb)
44 addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
46 if (feedback[0]) { // buttons are separate feedback
47 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::name_changed, this, boost::lambda::_1), OSC::instance());
48 name_changed (ARDOUR::Properties::name);
50 _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_change_message, this, X_("/select/mute"), _strip->mute_control()), OSC::instance());
51 send_change_message ("/select/mute", _strip->mute_control());
53 _strip->solo_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_change_message, this, X_("/select/solo"), _strip->solo_control()), OSC::instance());
54 send_change_message ("/select/solo", _strip->solo_control());
56 boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
58 track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_monitor_status, this, track->monitoring_control()), OSC::instance());
59 send_monitor_status (track->monitoring_control());
62 boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
63 if (rec_controllable) {
64 rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_change_message, this, X_("/select/recenable"), _strip->rec_enable_control()), OSC::instance());
65 send_change_message ("/select/recenable", _strip->rec_enable_control());
67 boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
68 if (rec_controllable) {
69 recsafe_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_change_message, this, X_("/select/record_safe"), _strip->rec_safe_control()), OSC::instance());
70 send_change_message ("/select/record_safe", _strip->rec_safe_control());
74 if (feedback[1]) { // level controls
76 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_gain_message, this, X_("/select/fader"), _strip->gain_control()), OSC::instance());
77 send_gain_message ("/select/fader", _strip->gain_control());
79 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_gain_message, this, X_("/select/gain"), _strip->gain_control()), OSC::instance());
80 send_gain_message ("/select/gain", _strip->gain_control());
83 boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
84 if (trim_controllable) {
85 trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_trim_message, this, X_("/select/trimdB"), _strip->trim_control()), OSC::instance());
86 send_trim_message ("/select/trimdB", _strip->trim_control());
89 boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
90 if (pan_controllable) {
91 pan_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_change_message, this, X_("/select/pan_stereo_position"), _strip->pan_azimuth_control()), OSC::instance());
92 send_change_message ("/select/pan_stereo_position", _strip->pan_azimuth_control());
98 OSCSelectObserver::~OSCSelectObserver ()
101 strip_connections.drop_connections ();
102 // all strip buttons should be off and faders 0 and etc.
103 if (feedback[0]) { // buttons are separate feedback
104 lo_message msg = lo_message_new ();
105 // name is a string do it first
106 string path = "/select/name";
107 lo_message_add_string (msg, " ");
108 lo_send_message (addr, path.c_str(), msg);
109 lo_message_free (msg);
110 clear_strip ("/select/mute", 0);
111 clear_strip ("/select/solo", 0);
112 clear_strip ("/select/recenable", 0);
113 clear_strip ("/select/record_safe", 0);
114 clear_strip ("/select/monitor_input", 0);
115 clear_strip ("/select/monitor_disk", 0);
117 if (feedback[1]) { // level controls
119 clear_strip ("/select/fader", 0);
121 clear_strip ("/select/gain", -193);
123 clear_strip ("/select/trimdB", 0);
124 clear_strip ("/select/pan_stereo_position", 0.5);
127 clear_strip ("/select/signal", 0);
131 clear_strip ("/select/meter", 0);
133 clear_strip ("/select/meter", -193);
135 }else if (feedback[8]) {
136 clear_strip ("/select/meter", 0);
139 lo_address_free (addr);
143 OSCSelectObserver::tick ()
145 if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
147 float now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
148 if (now_meter < -193) now_meter = -193;
149 if (_last_meter != now_meter) {
150 if (feedback[7] || feedback[8]) {
151 string path = "/select/meter";
152 lo_message msg = lo_message_new ();
153 if (gainmode && feedback[7]) {
154 uint32_t lev1023 = (uint32_t)((now_meter + 54) * 17.05);
155 lo_message_add_int32 (msg, lev1023);
156 lo_send_message (addr, path.c_str(), msg);
157 } else if ((!gainmode) && feedback[7]) {
158 lo_message_add_float (msg, now_meter);
159 lo_send_message (addr, path.c_str(), msg);
160 } else if (feedback[8]) {
161 uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
162 uint16_t ledbits = ~(0xfff<<ledlvl);
163 lo_message_add_int32 (msg, ledbits);
164 lo_send_message (addr, path.c_str(), msg);
166 lo_message_free (msg);
169 string path = "/select/signal";
170 lo_message msg = lo_message_new ();
172 if (now_meter < -40) {
177 lo_message_add_float (msg, signal);
178 lo_send_message (addr, path.c_str(), msg);
179 lo_message_free (msg);
182 _last_meter = now_meter;
189 OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
191 if (!what_changed.contains (ARDOUR::Properties::name)) {
199 lo_message msg = lo_message_new ();
201 // ssid is the strip on the surface this observer refers to
202 // not part of the internal ordering.
203 string path = "/select/name";
205 path = set_path (path);
207 lo_message_add_int32 (msg, ssid);
209 lo_message_add_string (msg, _strip->name().c_str());
211 lo_send_message (addr, path.c_str(), msg);
212 lo_message_free (msg);
216 OSCSelectObserver::send_change_message (string path, boost::shared_ptr<Controllable> controllable)
218 lo_message msg = lo_message_new ();
220 lo_message_add_float (msg, (float) controllable->get_value());
222 lo_send_message (addr, path.c_str(), msg);
223 lo_message_free (msg);
227 OSCSelectObserver::send_monitor_status (boost::shared_ptr<Controllable> controllable)
230 float val = controllable->get_value();
245 lo_message msg = lo_message_new ();
246 string path = "/select/monitor_input";
247 lo_message_add_int32 (msg, (float) input);
248 lo_send_message (addr, path.c_str(), msg);
249 lo_message_free (msg);
251 msg = lo_message_new ();
252 path = "/select/monitor_disk";
253 lo_message_add_int32 (msg, (float) disk);
254 lo_send_message (addr, path.c_str(), msg);
255 lo_message_free (msg);
260 OSCSelectObserver::send_trim_message (string path, boost::shared_ptr<Controllable> controllable)
262 lo_message msg = lo_message_new ();
264 lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
266 lo_send_message (addr, path.c_str(), msg);
267 lo_message_free (msg);
271 OSCSelectObserver::send_gain_message (string path, boost::shared_ptr<Controllable> controllable)
273 lo_message msg = lo_message_new ();
276 if (controllable->get_value() == 1) {
277 lo_message_add_int32 (msg, 800);
279 lo_message_add_int32 (msg, gain_to_slider_position (controllable->get_value()) * 1023);
282 if (controllable->get_value() < 1e-15) {
283 lo_message_add_float (msg, -200);
285 lo_message_add_float (msg, accurate_coefficient_to_dB (controllable->get_value()));
289 lo_send_message (addr, path.c_str(), msg);
290 lo_message_free (msg);
294 OSCSelectObserver::set_path (string path)
298 os << path << "/" << ssid;
305 OSCSelectObserver::clear_strip (string path, float val)
307 lo_message msg = lo_message_new ();
308 lo_message_add_float (msg, val);
310 lo_send_message (addr, path.c_str(), msg);
311 lo_message_free (msg);