From edcadc2599216491a85e19994bbb0c95ce501540 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 14 Mar 2021 10:42:47 +0100 Subject: LV2/makeplugin: Refactor makeplugin script. Instantiate PluginInfo object instead of using a class method returning a hash. --- plugins/LV2/lib/makeplugin/plugin_info.rb | 38 ++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'plugins/LV2/lib/makeplugin/plugin_info.rb') diff --git a/plugins/LV2/lib/makeplugin/plugin_info.rb b/plugins/LV2/lib/makeplugin/plugin_info.rb index c6f4adb..b9cae0d 100644 --- a/plugins/LV2/lib/makeplugin/plugin_info.rb +++ b/plugins/LV2/lib/makeplugin/plugin_info.rb @@ -21,8 +21,26 @@ module MakePlugin class PluginInfo PLUGIN_FIELDS = %w{Type Use Description Comment} - def self.find_plugin_info(root, plugin_name) - pi = { name: plugin_name } + attr_reader :name + attr_reader :n_ctrl_ports + attr_reader :ctrl_ports + attr_reader :type + attr_reader :use + attr_reader :desc + attr_reader :comment + + def initialize(root, name) + @name = name + @ctrl_ports = [] + self.find_plugin_info(root) + if @n_ctrl_ports != @ctrl_ports.length + raise "Expected #{@n_ctrl_ports} but found #{@ctrl_ports.length}" + end + end + + private + + def find_plugin_info(root) found = false db = File.join(root, '../../cheatsheet/src/database.js') @@ -32,39 +50,37 @@ module MakePlugin break if found && line =~ /^\s*\},$/ pat.match(line) do |m| - if m[1] == 'Name' && m[2] == plugin_name + if m[1] == 'Name' && m[2] == @name found = true elsif found && PLUGIN_FIELDS.include?(m[1]) - pi[m[1].downcase.to_sym] = m[2] + eval(%Q{@#{m[1].downcase.to_sym} = "#{m[2]}"}) end end end end - header_file = File.join(root, '../WinVST', plugin_name, "#{plugin_name}.h") + header_file = File.join(root, '../WinVST', @name, "#{@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 + @n_ctrl_ports = $1.to_i end end end - class_file = File.join(root, '../WinVST', plugin_name, "#{plugin_name}.cpp") + class_file = File.join(root, '../WinVST', @name, "#{@name}.cpp") fun = "" File.open(class_file) do |f| f.each_line do |line| - if line =~ /void #{plugin_name}::(\w+)/ + if line =~ /void #{@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 + @ctrl_ports << $2 end end end - - return pi end end end -- cgit v1.2.3