Class: CircuitPatchTools::Patch

Inherits:
Object
  • Object
show all
Extended by:
AttrLookup
Defined in:
lib/circuit_patch_tools/patch.rb

Direct Known Subclasses

Commands::Info::Patch

Constant Summary collapse

SYSEX =
[
  ['C',    :sysex,                0xF0],
  ['C',    :manufacturer_1,       0x00],
  ['C',    :manufacturer_2,       0x20],
  ['C',    :manufacturer_3,       0x29],
  ['C',    :product_type,         0x01],
  ['C',    :product_number,       0x60],
  ['C',    :command,              0..1],
  ['C',    :location,             0..63],
  ['C',    :reserved,             Any],
  ['A16',  :patch_name,           Any],
  ['C',    :patch_category,       0..14],
  ['C',    :patch_genre,          0..9],
  ['a14',  :patch_reserved,       Any],
  ['C',    :voice_polyphony_mode, 0..2],
  ['a307', :patch_settings,       Any],
  ['C',    :eox,                  0xF7]
]
PATTERN =
SYSEX.map { |a, _, _| a }.join('')
FIELDS =
SYSEX.map { |_, a, _| a }
POLYPHONY =
%i[ mono mono_ag poly ]
GENRES =
%i[
  none classic drumbass house industrial jazz randb rock techno dubstep
]
CATEGORIES =
%i[
  none arp bass bell classic drum keyboard lead movement pad poly sfx
  string user voc
]
COMMANDS =
%i[ replace_current_patch replace_patch ]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AttrLookup

attr_lookup

Constructor Details

#initialize(parameter_hash) ⇒ Patch

Returns a new instance of Patch.



52
53
54
# File 'lib/circuit_patch_tools/patch.rb', line 52

def initialize(parameter_hash)
  @parameters = parameter_hash
end

Class Method Details

.unpack(raw) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/circuit_patch_tools/patch.rb', line 40

def self.unpack(raw)
  values = raw.unpack(PATTERN)

  values.zip(SYSEX).each do |v, (_, name, validator)|
    unless validator === v
      raise "#{name}: #{v.inspect} does not satisfy #{validator.inspect}"
    end
  end

  new(FIELDS.zip(values).to_h)
end

Instance Method Details

#packObject



56
57
58
# File 'lib/circuit_patch_tools/patch.rb', line 56

def pack
  FIELDS.map { |f| @parameters[f] }.pack(PATTERN)
end