BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

commit db2786ccf2e6d7878e1bfa9ce4c2500792264be1
parent 339a141774bb9e53bf2e7381d031eed4b846d43f
Author: Matt Demanett <matt@demanett.net>
Date:   Sun, 18 Feb 2018 13:45:56 -0500

Fix svg_widgets.rb for new module structure; add make_stub.sh.

Diffstat:
Ascripts/make_stub.sh | 43+++++++++++++++++++++++++++++++++++++++++++
Mscripts/svg_widgets.rb | 85+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Msrc/bogaudio.cpp | 4++++
3 files changed, 95 insertions(+), 37 deletions(-)

diff --git a/scripts/make_stub.sh b/scripts/make_stub.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +MODULE=$1 +HP=$2 +CLASS=$3 + +if [ "x$MODULE" == "x" ] || [ "x$HP" == "x" ] +then + echo "Usage: $0 <module name> <width in HP> [param class]" 1>&2 + exit 1 +fi +if [ "x$CLASS" == "x" ] +then + CLASS=Knob26 +fi + +WIDGETS="./scripts/svg_widgets.rb" +HPP_OUT="./src/$MODULE.hpp" +CPP_OUT="./src/$MODULE.cpp" + +($WIDGETS ./res-src/$MODULE-src.svg --stub-hpp --module=$MODULE --plugin=Bogaudio --manufacturer=Bogaudio --hp=$HP --param-class=$CLASS | ruby -e 's = STDIN.read; s.sub!(/\/\* For.*?\*\/\s*/m, ""); puts s' > $HPP_OUT) || exit 1 +echo "Wrote: $HPP_OUT" + +($WIDGETS ./res-src/$MODULE-src.svg --stub-cpp --module=$MODULE --plugin=Bogaudio --manufacturer=Bogaudio --hp=$HP --param-class=$CLASS > $CPP_OUT) || exit 1 +echo "Wrote: $CPP_OUT" + +PLUGIN="./src/bogaudio.cpp" +if [ -e $PLUGIN ] +then + if [ "x$(grep NEW_INCLUDES_HERE $PLUGIN)" != "x" ] + then + INCLUDE="#include \"$MODULE.hpp\"" + echo Patching $PLUGIN with: $INCLUDE + ruby -e "s = File.read('$PLUGIN'); s.sub!(/\/\/NEW_INCLUDES_HERE/, %Q{$INCLUDE\n//NEW_INCLUDES_HERE}); File.write('$PLUGIN', s)" + fi + + if [ "x$(grep NEW_MODELS_HERE $PLUGIN)" != "x" ] + then + MODEL="p->addModel(model$MODULE);" + echo Patching $PLUGIN with: $MODEL + ruby -e "s = File.read('$PLUGIN'); s.sub!(/\/\/NEW_MODELS_HERE/, %Q{$MODEL\n\t//NEW_MODELS_HERE}); File.write('$PLUGIN', s)" + fi +fi diff --git a/scripts/svg_widgets.rb b/scripts/svg_widgets.rb @@ -3,17 +3,20 @@ INKSCAPE = '/Applications/Inkscape.app/Contents/Resources/bin/inkscape' OUTPUT_DECIMAL_PLACES=2 -class_template = <<TEMPLATE -/* -// For %PLUGIN%.hpp: -extern Model* model%MODULE%; - -// For %PLUGIN%.cpp: +hpp_template = <<HPP_TEMPLATE +/* For %PLUGIN%.cpp: +#include "%MODULE%.hpp" p->addModel(model%MODULE%); */ +#pragma once + #include "%HEADER%.hpp" +extern Model* model%MODULE%; + +namespace %HEADER% { + struct %MODULE% : Module { %ENUMS% @@ -25,37 +28,40 @@ struct %MODULE% : Module { virtual void step() override; }; +} // namespace %HEADER% +HPP_TEMPLATE + +cpp_template = <<CPP_TEMPLATE + +#include "%MODULE%.hpp" + void %MODULE%::onReset() { } void %MODULE%::step() { } - struct %MODULE%Widget : ModuleWidget { - %MODULE%Widget(%MODULE%* module); -}; + %MODULE%Widget(%MODULE%* module) : ModuleWidget(module) { + box.size = Vec(RACK_GRID_WIDTH * %HP%, RACK_GRID_HEIGHT); -%MODULE%Widget::%MODULE%Widget(%MODULE%* module) : ModuleWidget(module) { - box.size = Vec(RACK_GRID_WIDTH * %HP%, RACK_GRID_HEIGHT); - - { - SVGPanel *panel = new SVGPanel(); - panel->box.size = box.size; - panel->setBackground(SVG::load(assetPlugin(plugin, "res/%MODULE%.svg"))); - addChild(panel); - } + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/%MODULE%.svg"))); + addChild(panel); + } %SCREWS% %POSITIONS% %CREATES% -} - + } +}; Model* model%MODULE% = Model::create<%MODULE%, %MODULE%Widget>("%MANUFACTURER%", "%MANUFACTURER%-%MODULE%", "%MODULE%"); -TEMPLATE +CPP_TEMPLATE require 'optparse' options = { @@ -90,31 +96,34 @@ option_parser = OptionParser.new do |opts| opts.on('--enums', 'Output param/input/output/light ID enums') do options[:output] = 'enums' end - opts.on('--stub', 'Output a module class stub') do - options[:output] = 'class' + opts.on('--stub-hpp', 'Output a module class stub header (.hpp)') do + options[:output] = 'hpp' + end + opts.on('--stub-cpp', 'Output a module class stub implementation (.cpp)') do + options[:output] = 'cpp' end - opts.on('--module=MODULE', "Name of the module class (with --creates, --stub; default: #{options[:module]})") do |v| + opts.on('--module=MODULE', "Name of the module class (with --creates, --stub-*; default: #{options[:module]})") do |v| options[:module] = v end - opts.on('--plugin=PLUGIN', "Name of the plugin (with ----stub; default: #{options[:plugin]})") do |v| + opts.on('--plugin=PLUGIN', "Name of the plugin (with --stub-*; default: #{options[:plugin]})") do |v| options[:plugin] = v end - opts.on('--manufacturer=MANUFACTURER', "Name of the manufacturer (with ----stub; default: #{options[:manufacturer]})") do |v| + opts.on('--manufacturer=MANUFACTURER', "Name of the manufacturer (with ---stub-*; default: #{options[:manufacturer]})") do |v| options[:manufacturer] = v end - opts.on('--hp=HP', "Module width in multiples of RACK_GRID_WIDTH (with ----stub; default: #{options[:hp]})") do |v| + opts.on('--hp=HP', "Module width in multiples of RACK_GRID_WIDTH (with --stub-*; default: #{options[:hp]})") do |v| options[:hp] = v if v.to_i > 0 end - opts.on('--param-class=CLASS', "Widget type for params (with --creates, --stub; default: #{options[:param_class]})") do |v| + opts.on('--param-class=CLASS', "Widget type for params (with --creates, --stub-*; default: #{options[:param_class]})") do |v| options[:param_class] = v end - opts.on('--input-class=CLASS', "Widget type for inputs (with --creates, --stub; default: #{options[:input_class]})") do |v| + opts.on('--input-class=CLASS', "Widget type for inputs (with --creates, --stub-*; default: #{options[:input_class]})") do |v| options[:input_class] = v end - opts.on('--output-class=CLASS', "Widget type for outputs (with --creates, --stub; default: #{options[:output_class]})") do |v| + opts.on('--output-class=CLASS', "Widget type for outputs (with --creates, --stub-*; default: #{options[:output_class]})") do |v| options[:output_class] = v end - opts.on('--light-class=CLASS', "Widget type for lights (with --creates, --stub; default: #{options[:light_class]})") do |v| + opts.on('--light-class=CLASS', "Widget type for lights (with --creates, --stub-*; default: #{options[:light_class]})") do |v| options[:light_class] = v end opts.on('--comments', 'Output "generated by" comments around code') do @@ -198,12 +207,12 @@ def make_comment(prefix, indent) else "// end generated by #{File.basename($0)}" end - s = "\t#{s}" if indent + s = "\t\t#{s}" if indent s end def make_variables(widgets_by_type, style, comments, indent) - i1 = indent ? "\t" : '' + i1 = indent ? "\t\t" : '' groups = [%w(params Param), %w(inputs Input), %w(outputs Output), %w(lights Light)].map do |type| (widgets_by_type[type[0]] || []).map do |w| case style @@ -227,7 +236,7 @@ def make_variables(widgets_by_type, style, comments, indent) end def make_creates(widgets_by_type, comments, indent, options) - i1 = indent ? "\t" : '' + i1 = indent ? "\t\t" : '' groups = [] groups << (widgets_by_type['params'] || []).map do |w| "#{i1}addParam(ParamWidget::create<#{options[:param_class]}>(#{titleize(w.id)}Position, module, #{options[:module]}::#{w.id}, 0.0, 1.0, 0.0));" @@ -260,7 +269,7 @@ def make_enums(widgets_by_type, comments, indent) end def make_screws(hp, comments, indent) - i1 = indent ? "\t" : '' + i1 = indent ? "\t\t" : '' ss = [] if hp <= 6 ss << 'addChild(Widget::create<ScrewSilver>(Vec(0, 0)));' @@ -316,8 +325,10 @@ when 'creates' puts make_creates(widgets_by_type, options[:comments], false, options) when 'enums' puts make_enums(widgets_by_type, options[:comments], false) -when 'class' - puts make_stub(widgets_by_type, class_template, options) +when 'hpp' + puts make_stub(widgets_by_type, hpp_template, options) +when 'cpp' + puts make_stub(widgets_by_type, cpp_template, options) else puts "Params:" puts widgets_by_type['params'] diff --git a/src/bogaudio.cpp b/src/bogaudio.cpp @@ -22,6 +22,8 @@ #include "Test.hpp" #include "template_panels.hpp" +//NEW_INCLUDES_HERE + Plugin *plugin; void init(rack::Plugin *p) { @@ -65,4 +67,6 @@ void init(rack::Plugin *p) { p->addModel(modelTwentyFiveHP); p->addModel(modelThirtyHP); #endif + + //NEW_MODELS_HERE }