824251fe7317effc0a45e6c91e2d2d6afb243dd8
[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 #include "route_signal.h"
19
20 #include <ardour/route.h>
21 #include <ardour/track.h>
22 #include <ardour/panner.h>
23
24 #include "mackie_control_protocol.h"
25
26 #include <stdexcept>
27
28 using namespace Mackie;
29
30 void RouteSignal::connect()
31 {
32         if ( _strip.has_solo() )
33                 _solo_changed_connection = _route.solo_control().Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_solo_changed ), &_route, &_port ) );
34         
35         if ( _strip.has_mute() )
36                 _mute_changed_connection = _route.mute_control().Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_mute_changed ), &_route, &_port ) );
37         
38         if ( _strip.has_gain() )
39                 _gain_changed_connection = _route.gain_control().Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_gain_changed ), &_route, &_port ) );
40                 
41         _name_changed_connection = _route.name_changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_name_changed ), &_route, &_port ) );
42         
43         if ( _route.panner().size() == 1 )
44         {
45                 _panner_changed_connection = _route.panner()[0]->Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_panner_changed ), &_route, &_port ) );
46         }
47         
48         try
49         {
50                 _record_enable_changed_connection =
51                         dynamic_cast<ARDOUR::Track&>( _route ).rec_enable_control().Changed
52                                 .connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_record_enable_changed ), &_route, &_port ) )
53                 ;
54         }
55         catch ( std::bad_cast & )
56         {
57                 // this should catch the dynamic_cast to Track, if what we're working
58                 // with can't be record-enabled
59         }
60
61         // TODO
62         // active_changed
63         // SelectedChanged
64         // RemoteControlIDChanged
65 }
66
67 void RouteSignal::disconnect()
68 {
69         _solo_changed_connection.disconnect();
70         _mute_changed_connection.disconnect();
71         _gain_changed_connection.disconnect();
72         _name_changed_connection.disconnect();
73         _panner_changed_connection.disconnect();
74         _record_enable_changed_connection.disconnect();
75 }
76
77 void RouteSignal::notify_all()
78 {
79         void * src = &_route;
80         
81         if ( _strip.has_solo() )
82                 _mcp.notify_solo_changed( &_route, &_port );
83         
84         if ( _strip.has_mute() )
85                 _mcp.notify_mute_changed( &_route, &_port );
86         
87         if ( _strip.has_gain() )
88                 _mcp.notify_gain_changed( &_route, &_port );
89         
90         _mcp.notify_name_changed( src, &_route, &_port );
91         
92         if ( _strip.has_vpot() )
93                 _mcp.notify_panner_changed( &_route, &_port );
94         
95         if ( _strip.has_recenable() )
96                 _mcp.notify_record_enable_changed( &_route, &_port );
97 }