af99e5d91bbf0924974c925fcbc88aaa5060f90f
[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 ARDOUR;
29 using namespace Mackie;
30 using namespace std;
31
32 void RouteSignal::connect()
33 {
34         back_insert_iterator<Connections> cins = back_inserter( _connections );
35
36         if ( _strip.has_solo() )
37                 cins = _route->solo_control()->Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_solo_changed ), this ) );
38         
39         if ( _strip.has_mute() )
40                 cins = _route->mute_control()->Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_mute_changed ), this ) );
41         
42         if ( _strip.has_gain() )
43                 cins = _route->gain_control()->Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_gain_changed ), this, true ) );
44                 
45         cins = _route->NameChanged.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_name_changed ), this ) );
46         
47         if (_route->panner()) {
48                 cins = _route->panner()->Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_panner_changed ), this, true ) );
49                 for ( unsigned int i = 0; i < _route->panner()->npanners(); ++i ) {
50                         cins = _route->panner()->streampanner (i).Changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_panner_changed ), this, true ) );
51                 }
52         }
53         
54         boost::shared_ptr<Track> trk = boost::dynamic_pointer_cast<ARDOUR::Track>(_route);
55         if (trk) {
56                 cins = trk->rec_enable_control()->Changed .connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_record_enable_changed ), this));
57         }
58         
59         // TODO this works when a currently-banked route is made inactive, but not
60         // when a route is activated which should be currently banked.
61         cins = _route->active_changed.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_active_changed ), this ) );
62
63         // TODO
64         // SelectedChanged
65         // RemoteControlIDChanged. Better handled at Session level.
66 }
67
68 void RouteSignal::disconnect()
69 {
70         for ( Connections::iterator it = _connections.begin(); it != _connections.end(); ++it )
71         {
72                 it->disconnect();
73         }
74 }
75
76 void RouteSignal::notify_all()
77 {
78 #ifdef DEBUG
79         cout << "RouteSignal::notify_all for " << _strip << endl;
80 #endif
81         if ( _strip.has_solo() )
82                 _mcp.notify_solo_changed( this );
83         
84         if ( _strip.has_mute() )
85                 _mcp.notify_mute_changed( this );
86         
87         if ( _strip.has_gain() )
88                 _mcp.notify_gain_changed( this );
89         
90         _mcp.notify_name_changed( this );
91         
92         if ( _strip.has_vpot() )
93                 _mcp.notify_panner_changed( this );
94         
95         if ( _strip.has_recenable() )
96                 _mcp.notify_record_enable_changed( this );
97 #ifdef DEBUG
98         cout << "RouteSignal::notify_all finish" << endl;
99 #endif
100 }