Class: CircuitPatchTools::Commands::Split

Inherits:
Object
  • Object
show all
Defined in:
lib/circuit_patch_tools/commands/split.rb

Constant Summary collapse

FIELDS =
%i[ name command location genre category polyphony ]
DEFAULT_OPTIONS =
{
  filename: '%<location>02d - %<name>s.sysex'
}
PATCH_REGEXP =
/\xF0\x00\x20\x29\x01\x60[\x00-\xFF]{343}\xF7/n

Instance Method Summary collapse

Instance Method Details

#descriptionObject



19
20
21
# File 'lib/circuit_patch_tools/commands/split.rb', line 19

def description
  'extract patches from a single sysex file into one file per patch'
end

#nameObject



15
16
17
# File 'lib/circuit_patch_tools/commands/split.rb', line 15

def name
  'split'
end

#run(args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/circuit_patch_tools/commands/split.rb', line 23

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('-fPATTERN', '--filename=PATTERN',
            'Pattern for filenames',
            "Default: #{DEFAULT_OPTIONS[:filename].inspect}",
            String) do |v|
      options[:filename] = v
    end
    opts.on('-h', '--help', 'Print this help') do
      puts opts
      return
    end
  end.parse!(args)

  extract_all options, args
end