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/session.h"
25 #include "ardour/dB.h"
26 #include "ardour/meter.h"
27 #include "ardour/monitor_processor.h"
30 #include "osc_global_observer.h"
36 using namespace ARDOUR;
37 using namespace ArdourSurface;
39 OSCGlobalObserver::OSCGlobalObserver (OSC& o, Session& s, ArdourSurface::OSC::OSCSurface* su)
43 ,_last_master_gain (0.0)
44 ,_last_master_trim (0.0)
45 ,_last_monitor_gain (0.0)
47 addr = lo_address_new_from_url (sur->remote_url.c_str());
48 //addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
50 gainmode = sur->gainmode;
51 feedback = sur->feedback;
55 // connect to all the things we want to send feed back from
62 // Master channel first
63 _osc.text_message (X_("/master/name"), "Master", addr);
64 boost::shared_ptr<Stripable> strip = session->master_out();
66 boost::shared_ptr<Controllable> mute_controllable = boost::dynamic_pointer_cast<Controllable>(strip->mute_control());
67 mute_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_change_message, this, X_("/master/mute"), strip->mute_control()), OSC::instance());
68 send_change_message ("/master/mute", strip->mute_control());
70 boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(strip->trim_control());
71 trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_trim_message, this, X_("/master/trimdB"), strip->trim_control()), OSC::instance());
72 send_trim_message ("/master/trimdB", strip->trim_control());
74 boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(strip->pan_azimuth_control());
75 if (pan_controllable) {
76 pan_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_change_message, this, X_("/master/pan_stereo_position"), strip->pan_azimuth_control()), OSC::instance());
77 send_change_message ("/master/pan_stereo_position", strip->pan_azimuth_control());
80 boost::shared_ptr<Controllable> gain_controllable = boost::dynamic_pointer_cast<Controllable>(strip->gain_control());
81 gain_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_gain_message, this, X_("/master/"), strip->gain_control()), OSC::instance());
82 send_gain_message ("/master/", strip->gain_control());
85 strip = session->monitor_out();
87 _osc.text_message (X_("/monitor/name"), "Monitor", addr);
89 boost::shared_ptr<Controllable> mon_mute_cont = strip->monitor_control()->cut_control();
90 mon_mute_cont->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_change_message, this, X_("/monitor/mute"), mon_mute_cont), OSC::instance());
91 send_change_message ("/monitor/mute", mon_mute_cont);
93 boost::shared_ptr<Controllable> mon_dim_cont = strip->monitor_control()->dim_control();
94 mon_dim_cont->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_change_message, this, X_("/monitor/dim"), mon_dim_cont), OSC::instance());
95 send_change_message ("/monitor/dim", mon_dim_cont);
97 boost::shared_ptr<Controllable> mon_mono_cont = strip->monitor_control()->mono_control();
98 mon_mono_cont->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_change_message, this, X_("/monitor/mono"), mon_mono_cont), OSC::instance());
99 send_change_message ("/monitor/mono", mon_mono_cont);
101 gain_controllable = boost::dynamic_pointer_cast<Controllable>(strip->gain_control());
102 gain_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_gain_message, this, X_("/monitor/"), strip->gain_control()), OSC::instance());
103 send_gain_message ("/monitor/", strip->gain_control());
111 session->TransportStateChange.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_transport_state_changed, this), OSC::instance());
112 send_transport_state_changed ();
113 session->TransportLooped.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_transport_state_changed, this), OSC::instance());
114 session->RecordStateChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_record_state_changed, this), OSC::instance());
115 send_record_state_changed ();
118 session->StateSaved.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::session_name, this, X_("/session_name"), _1), OSC::instance());
119 session_name (X_("/session_name"), session->snap_name());
120 session->SoloActive.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::solo_active, this, _1), OSC::instance());
121 solo_active (session->soloing() || session->listening());
130 OSCGlobalObserver::~OSCGlobalObserver ()
134 // need to add general zero everything messages
135 strip_connections.drop_connections ();
136 session_connections.drop_connections ();
138 lo_address_free (addr);
142 OSCGlobalObserver::clear_observer ()
144 strip_connections.drop_connections ();
145 session_connections.drop_connections ();
146 _osc.text_message (X_("/master/name"), " ", addr);
147 _osc.text_message (X_("/monitor/name"), " ", addr);
148 _osc.text_message (X_("/session_name"), " ", addr);
149 if (feedback[6]) { // timecode enabled
150 _osc.text_message (X_("/position/smpte"), " ", addr);
152 if (feedback[5]) { // Bar beat enabled
153 _osc.text_message (X_("/position/bbt"), " ", addr);
155 if (feedback[11]) { // minutes/seconds enabled
156 _osc.text_message (X_("/position/time"), " ", addr);
158 if (feedback[10]) { // samples
159 _osc.text_message (X_("/position/samples"), " ", addr);
161 if (feedback[3]) { //heart beat enabled
162 _osc.float_message (X_("/heartbeat"), 0.0, addr);
164 if (feedback[7] || feedback[8]) { // meters enabled
166 if (feedback[7] && !gainmode) {
169 _osc.float_message (X_("/master/meter"), meter, addr);
172 _osc.float_message (X_("/master/signal"), 0, addr);
174 _osc.float_message ("/master/fader", 0, addr);
175 _osc.float_message ("/monitor/fader", 0, addr);
176 _osc.float_message ("/master/gain", -193, addr);
177 _osc.float_message ("/monitor/gain", -193, addr);
178 _osc.float_message (X_("/master/trimdB"), 0, addr);
179 _osc.float_message ("/master/mute", 0, addr);
180 _osc.float_message ("/master/pan_stereo_position", 0.5, addr);
181 _osc.float_message ("/monitor/mute", 0, addr);
182 _osc.float_message ("/monitor/dim", 0, addr);
183 _osc.float_message ("/monitor/mono", 0, addr);
184 _osc.float_message (X_("/loop_toggle"), 0, addr);
185 _osc.float_message (X_("/transport_play"), 0, addr);
186 _osc.float_message (X_("/transport_stop"), 0, addr);
187 _osc.float_message (X_("/rewind"), 0, addr);
188 _osc.float_message (X_("/ffwd"), 0, addr);
189 _osc.float_message (X_("/record_tally"), 0, addr);
190 _osc.float_message (X_("/rec_enable_toggle"), 0, addr);
191 _osc.float_message (X_("/cancel_all_solos"), 0, addr);
197 OSCGlobalObserver::tick ()
202 samplepos_t now_sample = session->transport_sample();
203 if (now_sample != _last_sample) {
204 if (feedback[6]) { // timecode enabled
205 Timecode::Time timecode;
206 session->timecode_time (now_sample, timecode);
208 // Timecode mode: Hours/Minutes/Seconds/Samples
210 os << setw(2) << setfill('0') << timecode.hours;
212 os << setw(2) << setfill('0') << timecode.minutes;
214 os << setw(2) << setfill('0') << timecode.seconds;
216 os << setw(2) << setfill('0') << timecode.frames;
218 _osc.text_message ("/position/smpte", os.str(), addr);
220 if (feedback[5]) { // Bar beat enabled
221 Timecode::BBT_Time bbt_time;
223 session->bbt_time (now_sample, bbt_time);
225 // semantics: BBB/bb/tttt
228 os << setw(3) << setfill('0') << bbt_time.bars;
230 os << setw(2) << setfill('0') << bbt_time.beats;
232 os << setw(4) << setfill('0') << bbt_time.ticks;
234 _osc.text_message ("/position/bbt", os.str(), addr);
236 if (feedback[11]) { // minutes/seconds enabled
237 samplepos_t left = now_sample;
238 int hrs = (int) floor (left / (session->sample_rate() * 60.0f * 60.0f));
239 left -= (samplecnt_t) floor (hrs * session->sample_rate() * 60.0f * 60.0f);
240 int mins = (int) floor (left / (session->sample_rate() * 60.0f));
241 left -= (samplecnt_t) floor (mins * session->sample_rate() * 60.0f);
242 int secs = (int) floor (left / (float) session->sample_rate());
243 left -= (samplecnt_t) floor ((double)(secs * session->sample_rate()));
244 int millisecs = floor (left * 1000.0 / (float) session->sample_rate());
246 // Min/sec mode: Hours/Minutes/Seconds/msec
248 os << setw(2) << setfill('0') << hrs;
250 os << setw(2) << setfill('0') << mins;
252 os << setw(2) << setfill('0') << secs;
254 os << setw(3) << setfill('0') << millisecs;
256 _osc.text_message ("/position/time", os.str(), addr);
258 if (feedback[10]) { // samples
261 _osc.text_message ("/position/samples", os.str(), addr);
263 _last_sample = now_sample;
265 if (feedback[3]) { //heart beat enabled
266 if (_heartbeat == 10) {
267 _osc.float_message (X_("/heartbeat"), 1.0, addr);
270 _osc.float_message (X_("/heartbeat"), 0.0, addr);
273 if (_heartbeat > 20) _heartbeat = 0;
275 if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
276 // the only meter here is master
277 float now_meter = session->master_out()->peak_meter()->meter_level(0, MeterMCP);
278 if (now_meter < -94) now_meter = -193;
279 if (_last_meter != now_meter) {
280 if (feedback[7] || feedback[8]) {
281 if (gainmode && feedback[7]) {
282 // change from db to 0-1
283 _osc.float_message (X_("/master/meter"), ((now_meter + 94) / 100), addr);
284 } else if ((!gainmode) && feedback[7]) {
285 _osc.float_message (X_("/master/meter"), now_meter, addr);
286 } else if (feedback[8]) {
287 uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
288 uint32_t ledbits = ~(0xfff<<ledlvl);
289 _osc.float_message (X_("/master/meter"), ledbits, addr);
294 if (now_meter < -40) {
299 _osc.float_message (X_("/master/signal"), signal, addr);
302 _last_meter = now_meter;
306 if (master_timeout) {
307 if (master_timeout == 1) {
308 _osc.text_message (X_("/master/name"), "Master", addr);
312 if (monitor_timeout) {
313 if (monitor_timeout == 1) {
314 _osc.text_message (X_("/monitor/name"), "Monitor", addr);
322 OSCGlobalObserver::send_change_message (string path, boost::shared_ptr<Controllable> controllable)
324 _osc.float_message (path, (float) controllable->get_value(), addr);
328 OSCGlobalObserver::session_name (string path, string name)
330 _osc.text_message (path, name, addr);
334 OSCGlobalObserver::send_gain_message (string path, boost::shared_ptr<Controllable> controllable)
336 bool ismaster = false;
337 if (path.find("master") != std::string::npos) {
339 if (_last_master_gain != controllable->get_value()) {
340 _last_master_gain = controllable->get_value();
345 if (_last_monitor_gain != controllable->get_value()) {
346 _last_monitor_gain = controllable->get_value();
352 _osc.float_message (string_compose ("%1fader", path), controllable->internal_to_interface (controllable->get_value()), addr);
353 _osc.text_message (string_compose ("%1name", path), string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (controllable->get_value())), addr);
361 if (controllable->get_value() < 1e-15) {
362 _osc.float_message (string_compose ("%1gain",path), -200, addr);
364 _osc.float_message (string_compose ("%1gain",path), accurate_coefficient_to_dB (controllable->get_value()), addr);
370 OSCGlobalObserver::send_trim_message (string path, boost::shared_ptr<Controllable> controllable)
372 if (_last_master_trim != controllable->get_value()) {
373 _last_master_trim = controllable->get_value();
377 _osc.float_message (X_("/master/trimdB"), (float) accurate_coefficient_to_dB (controllable->get_value()), addr);
382 OSCGlobalObserver::send_transport_state_changed()
384 _osc.float_message (X_("/loop_toggle"), session->get_play_loop(), addr);
385 _osc.float_message (X_("/transport_play"), session->transport_speed() == 1.0, addr);
386 _osc.float_message (X_("/transport_stop"), session->transport_stopped(), addr);
387 _osc.float_message (X_("/rewind"), session->transport_speed() < 0.0, addr);
388 _osc.float_message (X_("/ffwd"), (session->transport_speed() != 1.0 && session->transport_speed() > 0.0), addr);
392 OSCGlobalObserver::send_record_state_changed ()
394 _osc.float_message (X_("/rec_enable_toggle"), (int)session->get_record_enabled (), addr);
396 if (session->have_rec_enabled_track ()) {
397 _osc.float_message (X_("/record_tally"), 1, addr);
399 _osc.float_message (X_("/record_tally"), 0, addr);
404 OSCGlobalObserver::solo_active (bool active)
406 _osc.float_message (X_("/cancel_all_solos"), (float) active, addr);