From 4c719e0eaba0e244cc5575a89b7d22d8726a860c Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 13 Mar 2021 21:15:16 +0100 Subject: Improve makeplugin script Fetch number of control ports and their labels from the WinVST source files. --- plugins/LV2/makeplugin | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/plugins/LV2/makeplugin b/plugins/LV2/makeplugin index bc28335..be152b1 100755 --- a/plugins/LV2/makeplugin +++ b/plugins/LV2/makeplugin @@ -10,19 +10,20 @@ def make_param_assigns(num) .join("\n ") end -def make_ctrl_port(n) +def make_ctrl_port(n, name) %Q{ a lv2:InputPort , lv2:ControlPort ; lv2:index #{n} ; lv2:symbol "#{param_sym(n)}" ; - lv2:name "Parameter #{param_sym(n)}" ; + lv2:name "#{name}" ; lv2:default 0.5 ; lv2:minimum 0.0 ; lv2:maximum 1.0 ;} end -def make_lv2_port_defs(num) +def make_lv2_port_defs(pi) + num = pi[:n_ctrl_ports] ctrlports = (0 ... num) - .map { |n| make_ctrl_port(n) } + .map { |n| make_ctrl_port(n, pi["ctrl_port_#{param_sym(n)}".to_sym]) } .join("\n ] , [\n") ctrlports + %Q{ @@ -49,7 +50,7 @@ def make_lv2_port_defs(num) end if ARGV.length < 1 - puts "Usage: #{__FILE__} []" + puts "Usage: #{__FILE__} " exit end @@ -58,8 +59,6 @@ root = File.dirname(__FILE__) plugin_name = ARGV[0] plugin_slug = plugin_name.downcase -n_ctrl_ports = ARGV[1] || '1' - target_dir = File.join(root, 'src', plugin_name) template_dir = File.join(root, 'Template') @@ -72,9 +71,7 @@ def find_plugin_info(db, plugin_name) File.open(db) do |f| pat = /^\s*(\w+): \"([^"]+)\",/ f.each_line do |line| - if found && line =~ /^\s*\},$/ - return pi - end + break if found && line =~ /^\s*\},$/ pat.match(line) do |m| if m[1] == 'Name' && m[2] == plugin_name @@ -86,6 +83,29 @@ def find_plugin_info(db, plugin_name) end end + header_file = File.join('../WinVST', plugin_name, "#{plugin_name}.h") + + File.open(header_file) do |f| + f.each_line do |line| + if line =~ /kNumParameters\s*=\s*(\d+)/ + pi[:n_ctrl_ports] = $1.to_i + end + end + end + + class_file = File.join('../WinVST', plugin_name, "#{plugin_name}.cpp") + fun = "" + + File.open(class_file) do |f| + f.each_line do |line| + if line =~ /void #{plugin_name}::(\w+)/ + fun = $1 + elsif fun == 'getParameterName' and line =~ /case\s+kParam([A-Z])\:\s+vst_strncpy\s*\([^,]*,\s*\"(\w+)\",/ + pi["ctrl_port_#{$1}".to_sym] = $2 + end + end + end + return pi end @@ -106,6 +126,7 @@ plugin_info = find_plugin_info(File.join(root, '../../cheatsheet/src/database.js puts "Creating plugin #{plugin_name}..." puts "Type: #{plugin_info[:type]}" +puts "CTRL ports: #{plugin_info[:n_ctrl_ports]}" Templates = %w{ manifest.ttl.in @@ -121,9 +142,9 @@ begin tpl = IO.read(File.join(template_dir, t)) .gsub('@Plugin@', plugin_name) .gsub('@plugin@', plugin_slug) - .gsub('@NCtrlPorts@', n_ctrl_ports) - .gsub('@AssignParams@', make_param_assigns(n_ctrl_ports.to_i)) - .gsub('@TTLPortDefs@', make_lv2_port_defs(n_ctrl_ports.to_i)) + .gsub('@NCtrlPorts@', plugin_info[:n_ctrl_ports].to_s) + .gsub('@AssignParams@', make_param_assigns(plugin_info[:n_ctrl_ports])) + .gsub('@TTLPortDefs@', make_lv2_port_defs(plugin_info)) .gsub('@TTLPluginType@', get_lv2_plugin_type(plugin_info)) fname = t.sub('Plugin', plugin_name) -- cgit v1.2.3