class CircuitPatchTools::Commands::Join

Constants

DEFAULT_OPTIONS

Public Instance Methods

description() click to toggle source
# File lib/circuit_patch_tools/commands/join.rb, line 15
def description
  'join up to 64 patches into a single sysex file'
end
name() click to toggle source
# File lib/circuit_patch_tools/commands/join.rb, line 11
def name
  'join'
end
run(args) click to toggle source
# File lib/circuit_patch_tools/commands/join.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('-oFILENAME', '--output=FILENAME',
                  'Output filename',
                  "Default: #{DEFAULT_OPTIONS[:output]}",
                  String) do |v|
            options[:output] = v
          end
          opts.on('-h', '--help', 'Print this help') do
            puts opts
            return
          end
        end.parse!(args)

        join options, args
      end

Private Instance Methods

join(options, paths) click to toggle source
# File lib/circuit_patch_tools/commands/join.rb, line 46
def join(options, paths)
  output = options.fetch(:output)
  File.open(output, 'wb', encoding: Encoding::ASCII_8BIT) do |f|
    paths.each.with_index do |path, index|
      raw = File.open(path, 'rb', encoding: Encoding::ASCII_8BIT).read
      patch = Patch.unpack(raw)
      patch.command = :replace_patch
      patch.location = index
      f << patch.pack
    end
  end
end