add new sigc++2 directory
[ardour.git] / libs / surfaces / mackie / scripts / surface-cc-template.erb
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         Generated by scripts/generate-surface.rb
20 */
21
22 #include "<%= sf.name.downcase %>_surface.h"
23
24 #include "controls.h"
25 #include "mackie_button_handler.h"
26
27 using namespace Mackie;
28
29 void Mackie::<%= sf.name %>Surface::init_controls()
30 {
31         // intialise groups and strips
32         Group * group = 0;
33         
34         // make sure there are enough strips
35         strips.resize( <%= sf.groups.values.find_all{|x| x.name =~ /strip/}.size %> );
36         
37 % sf.groups.values.each do |group|
38         <%- if group.class == Strip -%>
39                 <%- if group.name == 'master' -%>
40         group = new MasterStrip ( "<%=group.name%>", 0 );
41                 <%- else -%>
42         group = new <%= group.class.name %> ( "<%=group.name%>", <%=group.ordinal - 1%> );
43                 <%- end -%>
44         <%- else -%>
45         group = new <%= group.class.name %> ( "<%=group.name%>" );
46         <%- end -%>
47         groups["<%=group.name%>"] = group;
48         <%- if group.class == Strip -%>
49         strips[<%=group.ordinal - 1%>] = dynamic_cast<Strip*>( group );
50         <%- end -%>
51         
52 % end
53
54         // initialise controls
55         Control * control = 0;
56
57 % sf.controls.each do |control|
58         group = groups["<%=control.group.name%>"];
59         control = new <%= control.class.name %> ( <%= control.id %>, <%= control.ordinal %>, "<%=control.name%>", *group );
60         <%=control.class.name.downcase%>s[0x<%=control.id.to_hex %>] = control;
61         controls.push_back( control );
62         <%- if control.group.class != Strip -%>
63         controls_by_name["<%= control.name %>"] = control;
64         <%- end -%>
65         group->add( *control );
66
67 % end
68 }
69
70 void Mackie::<%= sf.name %>Surface::handle_button( MackieButtonHandler & mbh, ButtonState bs, Button & button )
71 {
72         if ( bs != press && bs != release )
73         {
74                 mbh.update_led( button, none );
75                 return;
76         }
77         
78         LedState ls;
79         switch ( button.id() )
80         {
81 <%-
82 buttons = sf.controls.find_all{|x| x.class == Button && x.group.class != Strip}
83 buttons.each do |button|
84 %>
85                 case 0x<%= button.id.to_hex %>: // <%= button.name %>
86                         switch ( bs ) {
87                                 case press: ls = mbh.<%= button.name %>_press( button ); break;
88                                 case release: ls = mbh.<%= button.name %>_release( button ); break;
89                                 case neither: break;
90                         }
91                         break;
92 <% end %>
93         }
94         mbh.update_led( button, ls );
95 }