aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/LV2/makeplugin
blob: 061d7123e262a5d0d64c2dcbb4d65ec44aaad37b (plain) (blame)
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
#!/usr/bin/env ruby
require_relative 'lib/makeplugin/plugin_description_template'
require_relative 'lib/makeplugin/plugin_info'

def make_param_assigns(ctrl_ports)
  ctrl_ports
    .map.with_index { |p, n| "#{p[:sym]} = *param[#{n}];" }
    .join("\n    ")
end


if ARGV.length < 1
  puts "Usage: #{__FILE__} <PluginName>"
  exit
end

root = File.dirname(__FILE__)

plugin_name = ARGV[0]

target_dir = File.join(root, 'src', plugin_name)
template_dir = File.join(root, 'Template')


puts "Reading plugin info from cheatsheet..."
pi = MakePlugin::PluginInfo.new(root, plugin_name)


puts "Creating plugin #{pi.name}..."
puts "Type: #{pi.type} (#{pi.raw_type})"
puts "CTRL ports: #{pi.ctrl_ports.length}"

Templates = %w{
    manifest.ttl.in
    Plugin.h
    Plugin.cpp
}

begin
  Dir.mkdir(target_dir)

  plugin_ttl = MakePlugin::PluginDescriptionTemplate.new(template_dir, pi)
  IO.write(File.join(target_dir, plugin_ttl.filename), plugin_ttl.render)

  Templates.each do |t|
    tpl = IO.read(File.join(template_dir, t))
      .gsub('@Plugin@', pi.name)
      .gsub('@plugin@', pi.slug)
      .gsub('@NCtrlPorts@', pi.n_ctrl_ports.to_s)
      .gsub('@AssignParams@', make_param_assigns(pi.ctrl_ports))
      .gsub('@VARDECLS@', pi.var_decls.join("\n"))

    fname = t.sub('Plugin', pi.name)

    puts " - #{fname}..."
    File.open(File.join(target_dir, fname), "w") do |f|
      f.write(tpl)
    end
  end

rescue SystemCallError => e
  puts "Could not create plugin: #{e}"
  puts "Aborting!"
end