Routes made inactive will be bank-switched out. Add remove last capture and save...
[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 using namespace std;
30
31 void RouteSignal::connect()
32 {
33         back_insert_iterator<Connections> cins = back_inserter( _connections );
34         
35         if ( _strip.has_solo() )
36                 cins = _route.solo_control().Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_solo_changed ), this ) );
37         
38         if ( _strip.has_mute() )
39                 cins = _route.mute_control().Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_mute_changed ), this ) );
40         
41         if ( _strip.has_gain() )
42                 cins = _route.gain_control().Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_gain_changed ), this, true ) );
43                 
44         cins = _route.name_changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_name_changed ), this ) );
45         
46         cins = _route.panner().Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_panner_changed ), this, true ) );
47         for ( unsigned int i = 0; i < _route.panner().size(); ++i )
48         {
49                 cins = _route.panner()[i]->Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_panner_changed ), this, true ) );
50         }
51         
52         try
53         {
54                 cins = dynamic_cast<ARDOUR::Track&>( _route )
55                         .rec_enable_control()
56                         .Changed
57                         .connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_record_enable_changed ), this ) )
58                 ;
59         }
60         catch ( std::bad_cast & )
61         {
62                 // this should catch the dynamic_cast to Track, if what we're working
63                 // with can't be record-enabled
64         }
65
66         // TODO this works when a currently-banked route is made inactive, but not
67         // when a route is activated which should be currently banked.
68         cins = _route.active_changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_active_changed ), this ) );
69         
70         // TODO
71         // SelectedChanged
72         // RemoteControlIDChanged. Better handled at Session level.
73 }
74
75 void RouteSignal::disconnect()
76 {
77         for ( Connections::iterator it = _connections.begin(); it != _connections.end(); ++it )
78         {
79                 it->disconnect();
80         }
81 }
82
83 void RouteSignal::notify_all()
84 {
85 #ifdef DEBUG
86         cout << "RouteSignal::notify_all for " << _strip << endl;
87 #endif
88         if ( _strip.has_solo() )
89                 _mcp.notify_solo_changed( this );
90         
91         if ( _strip.has_mute() )
92                 _mcp.notify_mute_changed( this );
93         
94         if ( _strip.has_gain() )
95                 _mcp.notify_gain_changed( this );
96         
97         _mcp.notify_name_changed( &_route, this );
98         
99         if ( _strip.has_vpot() )
100                 _mcp.notify_panner_changed( this );
101         
102         if ( _strip.has_recenable() )
103                 _mcp.notify_record_enable_changed( this );
104 #ifdef DEBUG
105         cout << "RouteSignal::notify_all finish" << endl;
106 #endif
107 }