class CircuitPatchTools::Commands::Portable

Constants

DEFAULT_OPTIONS

Public Instance Methods

description() click to toggle source
# File lib/circuit_patch_tools/commands/portable.rb, line 15
def description
  'make patches portable'
end
name() click to toggle source
# File lib/circuit_patch_tools/commands/portable.rb, line 11
def name
  'portable'
end
run(args) click to toggle source
# File lib/circuit_patch_tools/commands/portable.rb, line 19
      def run(args)
        options = DEFAULT_OPTIONS.dup

        OptionParser.new do |opts|
          opts.banner = <<~END
            #{name}: #{description}

            Usage: circuit-patch #{name} [options] patch1.sysex [patch2.sysex ...]

            Options:
          END
          opts.on('-sSYNTH', '--synth=SYNTH',
                  'Synth for the patch',
                  "Default: #{DEFAULT_OPTIONS[:synth]}",
                  Integer) do |v|
            options[:synth] = v
          end
          opts.on('-h', '--help', 'Print this help') do
            puts opts
            return
          end
        end.parse!(args)

        args.each do |path|
          make_portable options, path
        end
      end

Private Instance Methods

make_portable(options, path) click to toggle source
# File lib/circuit_patch_tools/commands/portable.rb, line 48
def make_portable(options, path)
  raw = File.open(path, 'rb', encoding: Encoding::ASCII_8BIT).read
  patch = Patch.unpack(raw)
  patch.command = :replace_current_patch
  patch.location = options.fetch(:synth) - 1
  File.open(path, 'wb', encoding: Encoding::ASCII_8BIT) do |f|
    f << patch.pack
  end
end