Class: MIDIEvents::Constant::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/midi-events/constant.rb

Overview

Container for a group of related MIDI constants

Groups organize constants by category (e.g., "Note", "Control Change", "Status"). Each group contains multiple Map objects that pair constant names with their values.

Examples:

Accessing a constant group

group = MIDIEvents::Constant::Group['Note']
group.find('C4')  # => Map object for C4

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, constants) ⇒ Group

Create a new constant group

Parameters:

  • key (String)

    The group identifier

  • constants (Hash)

    Hash of constant names to values



100
101
102
103
# File 'lib/midi-events/constant.rb', line 100

def initialize(key, constants)
  @key = key
  @constants = constants.map { |k, v| Constant::Map.new(k, v) }
end

Instance Attribute Details

#constantsArray<MIDIEvents::Constant::Map> (readonly)

Returns The constants in this group.

Returns:



91
92
93
# File 'lib/midi-events/constant.rb', line 91

def constants
  @constants
end

#keyString (readonly)

Returns The group's key/name.

Returns:

  • (String)

    The group's key/name



94
95
96
# File 'lib/midi-events/constant.rb', line 94

def key
  @key
end

Class Method Details

.allArray<ConstantGroup>

All constant groups

Returns:

  • (Array<ConstantGroup>)


132
133
134
135
# File 'lib/midi-events/constant.rb', line 132

def all
  ensure_initialized
  @groups
end

.find(key) ⇒ ConstantGroup Also known as: []

Find a constant group by its key

Parameters:

  • key (String, Symbol)

Returns:

  • (ConstantGroup)


140
141
142
143
# File 'lib/midi-events/constant.rb', line 140

def find(key)
  ensure_initialized
  @groups.find { |group| Name.match?(group.key, key) }
end

Instance Method Details

#find(name) ⇒ MIDIEvents::Constant::Map?

Find a constant in this group by its name

Examples:

group = MIDIEvents::Constant::Group['Note']
group.find('E4')  # => Map for E4 (value 64)

Parameters:

  • name (String, Symbol)

    The constant name to find

Returns:



113
114
115
# File 'lib/midi-events/constant.rb', line 113

def find(name)
  @constants.find { |const| Name.match?(const.key, name) }
end

#find_by_value(value) ⇒ MIDIEvents::Constant::Map?

Find a constant in this group by its value (reverse lookup)

Examples:

group = MIDIEvents::Constant::Group['Note']
group.find_by_value(64)  # => Map for E4

Parameters:

  • value (Object)

    The numeric value to find

Returns:



125
126
127
# File 'lib/midi-events/constant.rb', line 125

def find_by_value(value)
  @constants.find { |const| Name.match?(const.value, value) }
end