aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/LV2/makeplugin
blob: e8ff8895e9616e7d0ae65705d1c73ffbaecff0ab (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/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]} = *params[#{n}];" }
    .join("\n    ")
end

def usage
  puts "Usage: #{__FILE__} [--pristine] <PluginName>"
  puts "\nFlags:\n"
  puts "\t--pristine\t- Make pristine plugin (deletes existing if it exists)"
  exit
end

if ARGV.length < 1
  usage
end

opt = {}
plugin_name = ''

ARGV.each do |arg|
  case arg
  when /^--pristine$/
    opt[:pristine] = true
  else
    plugin_name = arg
  end
end

if plugin_name.empty?
  puts "Missing plugin name!"
  usage
end

root = File.dirname(__FILE__)

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
  FileUtils.remove_dir(target_dir) if opt[:pristine] and Dir.exist?(target_dir)
  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"))
      .gsub('@VARINITS@', pi.var_inits.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