summaryrefslogtreecommitdiff
path: root/libs/surfaces/mackie/scripts/surface-cc-template.erb
blob: 79cd2e4ae02cb67dfff53ea659d9c38df46fa12d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<%#
	Copyright (C) 2006,2007 John Anderson

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-%>
/*
	Generated by scripts/generate-surface.rb
*/

#include "<%= sf.name.downcase %>_surface.h"

#include "controls.h"
#include "mackie_button_handler.h"

using namespace Mackie;

void Mackie::<%= sf.name %>Surface::init_controls()
{
	// intialise groups and strips
	Group * group = 0;
	
	// make sure there are enough strips
	strips.resize( <%= sf.groups.values.find_all{|x| x.name =~ /strip/}.size %> );
	
% sf.groups.values.each do |group|
	<%- if group.class == Strip -%>
		<%- if group.name == 'master' -%>
	group = new MasterStrip ( "<%=group.name%>", 0 );
		<%- else -%>
	group = new <%= group.class.name %> ( "<%=group.name%>", <%=group.ordinal - 1%> );
		<%- end -%>
	<%- else -%>
	group = new <%= group.class.name %> ( "<%=group.name%>" );
	<%- end -%>
	groups["<%=group.name%>"] = group;
	<%- if group.class == Strip -%>
	strips[<%=group.ordinal - 1%>] = dynamic_cast<Strip*>( group );
	<%- end -%>
	
% end

	// initialise controls
	Fader * fader = 0;
	Pot * pot = 0;
	Button * button = 0;
	Led * led = 0;

% sf.controls.each do |control|
	group = groups["<%=control.group.name%>"];
	<%= control.class.name.downcase %> = new <%= control.class.name %> ( <%= control.id %>, <%= control.ordinal %>, "<%=control.name%>", *group );
	<%=control.class.name.downcase%>s[0x<%=control.id.to_hex %>] = <%= control.class.name.downcase %>;
	controls.push_back( <%= control.class.name.downcase %> );
	<%- if control.group.class != Strip -%>
	controls_by_name["<%= control.name %>"] = <%= control.class.name.downcase %>;
	<%- end -%>
	group->add( *<%= control.class.name.downcase %> );

% end
}

void Mackie::<%= sf.name %>Surface::handle_button( MackieButtonHandler & mbh, ButtonState bs, Button & button )
{
	if ( bs != press && bs != release )
	{
		mbh.update_led( button, none );
		return;
	}
	
	LedState ls;
	switch ( button.id() )
	{
<%-
buttons = sf.controls.find_all{|x| x.class == Button && x.group.class != Strip}
buttons.each do |button|
%>
		case 0x<%= ( button.class.midi_zero_byte << 8 | button.id ).to_hex %>: // <%= button.name %>
			switch ( bs ) {
				case press: ls = mbh.<%= button.name %>_press( button ); break;
				case release: ls = mbh.<%= button.name %>_release( button ); break;
				case neither: break;
			}
			break;
<% end %>
	}
	mbh.update_led( button, ls );
}