MCP: some debug tracing for meters
[ardour.git] / libs / surfaces / mackie / route_signal.cc
1 /*
2         Copyright (C) 2006,2007 John Anderson
3
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.
8
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.
13
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.
17 */
18
19 #include <stdexcept>
20
21 #include "ardour/route.h"
22 #include "ardour/track.h"
23 #include "ardour/midi_ui.h"
24 #include "ardour/pannable.h"
25 #include "ardour/session_object.h" // for Properties::name 
26
27 #include "mackie_control_protocol.h"
28 #include "route_signal.h"
29 #include "strip.h"
30
31 using namespace ARDOUR;
32 using namespace Mackie;
33 using namespace std;
34
35 #define midi_ui_context() MidiControlUI::instance() /* a UICallback-derived object that specifies the event loop for signal handling */
36 #define ui_bind(f, ...) boost::protect (boost::bind (f, __VA_ARGS__))
37
38 void RouteSignal::connect()
39 {
40         if (_strip.has_solo()) {
41                 _route->solo_control()->Changed.connect(connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_solo_changed, &_mcp, this), midi_ui_context());
42         }
43
44         if (_strip.has_mute()) {
45                 _route->mute_control()->Changed.connect(connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_mute_changed, &_mcp, this), midi_ui_context());
46         }
47
48         if (_strip.has_gain()) {
49                 _route->gain_control()->Changed.connect(connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_gain_changed, &_mcp, this, false), midi_ui_context());
50         }
51
52         _route->PropertyChanged.connect (connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_property_changed, &_mcp, _1, this), midi_ui_context());
53         
54         if (_route->pannable()) {
55                 _route->pannable()->pan_azimuth_control->Changed.connect(connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_panner_changed, &_mcp, this, false), midi_ui_context());
56                 _route->pannable()->pan_width_control->Changed.connect(connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_panner_changed, &_mcp, this, false), midi_ui_context());
57         }
58         
59         boost::shared_ptr<Track> trk = boost::dynamic_pointer_cast<ARDOUR::Track>(_route);
60         if (trk) {
61                 trk->rec_enable_control()->Changed .connect(connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_record_enable_changed, &_mcp, this), midi_ui_context());
62         }
63         
64         // TODO this works when a currently-banked route is made inactive, but not
65         // when a route is activated which should be currently banked.
66         _route->active_changed.connect (connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_active_changed, &_mcp, this), midi_ui_context());
67
68         _route->DropReferences.connect (connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::refresh_current_bank, &_mcp), midi_ui_context());
69         
70         // TODO
71         // SelectedChanged
72         // RemoteControlIDChanged. Better handled at Session level.
73 }
74
75 void 
76 RouteSignal::disconnect()
77 {
78         connections.drop_connections ();
79 }
80
81 void 
82 RouteSignal::notify_all()
83 {
84         if  (_strip.has_solo()) {
85                 _mcp.notify_solo_changed (this);
86         }
87         
88         if  (_strip.has_mute()) {
89                 _mcp.notify_mute_changed (this);
90         }
91         
92         if  (_strip.has_gain()) {
93                 _mcp.notify_gain_changed (this);
94         }
95         
96         _mcp.notify_property_changed (PBD::PropertyChange (ARDOUR::Properties::name), this);
97         
98         if  (_strip.has_vpot()) {
99                 _mcp.notify_panner_changed (this);
100         }
101         
102         if  (_strip.has_recenable()) {
103                 _mcp.notify_record_enable_changed (this);
104         }
105 }