~ubuntu-branches/ubuntu/vivid/ardour/vivid-proposed

« back to all changes in this revision

Viewing changes to libs/surfaces/mackie/scripts/generate-surfaces

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler, Jaromír Mikeš, Felipe Sateler
  • Date: 2014-05-22 14:39:25 UTC
  • mfrom: (29 sid)
  • mto: This revision was merged to the branch mainline in revision 30.
  • Revision ID: package-import@ubuntu.com-20140522143925-vwqfo9287pmkrroe
Tags: 1:2.8.16+git20131003-3
* Team upload

[ Jaromír Mikeš ]
* Add -dbg package

[ Felipe Sateler ]
* Upload to experimental

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/ruby
 
2
 
 
3
require 'getoptlong'
 
4
require 'csv'
 
5
require 'erb'
 
6
this_dir = File.dirname(__FILE__)
 
7
require this_dir + '/mackie.rb'
 
8
require this_dir + '/controls.rb'
 
9
 
 
10
read_opts = GetoptLong.new(
 
11
[ "--headers", '-e', GetoptLong::NO_ARGUMENT ],
 
12
 
 
13
[ "--version","-v", GetoptLong::NO_ARGUMENT ],
 
14
[ "--help",   "-h", "-?", GetoptLong::NO_ARGUMENT ]
 
15
)
 
16
 
 
17
# process the parsed options
 
18
read_opts.each do |opt, arg|
 
19
  case opt
 
20
    when "--headers"
 
21
      $generate_headers = true
 
22
    else
 
23
      $generate_headers = false
 
24
  end
 
25
end
 
26
 
 
27
cc_template = ''
 
28
File.open( this_dir + "/surface-cc-template.erb", "r" ) { |f| cc_template = f.read }
 
29
 
 
30
h_template = ''
 
31
File.open( this_dir + "/surface-h-template.erb", "r" ) { |f| h_template = f.read }
 
32
 
 
33
# needs to be defined outside the loop otherwise ERB can't find it
 
34
sf = nil
 
35
 
 
36
files =
 
37
if ARGV.size == 0
 
38
  Dir.glob "#{this_dir}/*csv"
 
39
else
 
40
  ARGV
 
41
end
 
42
 
 
43
files.each do |csv_file|
 
44
  csv_file =~ /(\w+)-controls.csv/
 
45
  sf = Surface.new( $1.capitalize )
 
46
  
 
47
  control_data = ''
 
48
  File.open( csv_file, "r") { |f| control_data = f.read }
 
49
  sf.parse control_data
 
50
 
 
51
  @result = ""
 
52
  
 
53
  erb = ERB.new( cc_template , 0, "%<>-", "@result" )
 
54
  erb.result
 
55
  File.open( "#{sf.name.downcase}_surface_generated.cc", "w" ) { |f| f.write @result }
 
56
 
 
57
  if $generate_headers
 
58
    erb = ERB.new( h_template , 0, "%<>-", "@result" )
 
59
    erb.result
 
60
    File.open( "#{sf.name.downcase}_surface.h", "w" ) { |f| f.write @result }
 
61
  end
 
62
  
 
63
end
 
64