Merged with trunk R1705.
[ardour.git] / libs / surfaces / mackie / scripts / signals.rb
1 #~ /usr/bin/ruby
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 require 'erb'
19
20 signals = %w{
21 solo_changed
22 mute_changed
23 record_enable_changed
24 gain_changed
25 name_changed
26 panner_changed
27 }
28
29 @signal_calls = { 'panner_changed' => 'panner()[0]->Changed' }
30
31 def connection_call( x )
32   if @signal_calls.include? x
33     @signal_calls[x]
34   else
35     x
36   end
37 end
38
39 signals.each do |x|
40         puts <<EOF
41 void MackieControlProtocol::notify_#{x}( void *, ARDOUR::Route * route )
42 {
43         try
44         {
45                 strip_from_route( route ).#{x.gsub( /_changed/, '' )}();
46         }
47         catch( exception & e )
48         {
49                 cout << e.what() << endl;
50         }
51 }
52
53 EOF
54 end
55
56 class_def = <<EOF
57 #ifndef route_signal_h
58 #define route_signal_h
59
60 #include <sigc++/sigc++.h>
61
62 class MackieControlProtocol;
63
64 namespace ARDOUR {
65         class Route;
66 }
67         
68 namespace Mackie
69 {
70
71 class Strip;
72
73 /**
74   This class is intended to easily create and destroy the set of
75   connections from a route to a control surface strip. Instanting
76   it will connect the signals, and destructing it will disconnect
77   the signals.
78 */
79 class RouteSignal
80 {
81 public:
82         RouteSignal( ARDOUR::Route & route, MackieControlProtocol & mcp, Strip & strip )
83         : _route( route ), _mcp( mcp ), _strip( strip )
84         {
85                 connect();
86         }
87         
88         ~RouteSignal()
89         {
90                 disconnect();
91         }
92         
93 private:
94         ARDOUR::Route & _route;
95         MackieControlProtocol & _mcp;
96         Strip & _strip;
97         
98 <% signals.each do |x| -%>
99         sigc::connection _<%= x %>_connection;
100 <% end -%>
101 };
102
103 }
104
105 #endif
106 EOF
107
108 erb = ERB.new( class_def, 0, ">-" )
109 erb.run
110
111 impl_def = <<EOF
112 #include "route_signal.h"
113
114 #include <ardour/route.h>
115 #include <ardour/panner.h>
116
117 #include "mackie_control_protocol.h"
118
119 using namespace Mackie;
120
121 void RouteSignal::connect()
122 {
123 <% signals.each do |x| -%>
124         _<%=x%>_connection = _route.<%=connection_call(x)%>.connect( sigc::bind ( mem_fun ( _mcp, &MackieControlProtocol::notify_<%=x%> ), &_route ) );
125 <% end -%>
126 }
127
128 void RouteSignal::disconnect()
129 {
130 <% signals.each do |x| -%>
131   _<%= x %>_connection.disconnect();
132 <% end -%>
133 }
134 EOF
135
136 erb = ERB.new( impl_def, 0, ">-" )
137 erb.run