aboutsummaryrefslogblamecommitdiffstats
path: root/plugins/LV2/makeplugin
blob: de6aaebe968c06181a3730a0cf3d7003578c396e (plain) (tree)
1
2
3
4
5
6
7
8
9
                   


                   
                                                             
                                             
 

                                  
                                                            


                   





                                                                             
 
                  
       

   










                         
 





                             



                                                

                                             
                                                  

 
                                    
                                        
                                          


                   




              
                                                                               

                       


                                                                          

                                             
                                
                                
                                                 
                                                                
                                                  
                                                  
 
                                    










                                                       
#!/usr/bin/env ruby

require 'fileutils'

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