Module: MIDIEvents::Constant

Defined in:
lib/midi-events/constant.rb

Overview

MIDI constant lookups and mappings

Provides a flexible system for referring to MIDI messages by their human-readable names instead of numeric values. For example, "C4" for MIDI note 60, or "Bank Select" for MIDI control change 0.

Constants are loaded from a YAML dictionary (midi.yml) and organized into groups (Notes, Control Changes, Status bytes, etc.).

Examples:

Looking up note values

MIDIEvents::Constant.find('Note', 'C4')
# => #<MIDIEvents::Constant::Map @key="C4", @value=60>

Getting constant value directly

MIDIEvents::Constant.value('Note', 'E4')
# => 64

Using constants in message creation

MIDIEvents::NoteOn["C4"].new(0, 100)
# Creates a NoteOn message for C4 (MIDI note 60)

Defined Under Namespace

Modules: Loader, Name, Status Classes: Group, Map, MessageBuilder

Class Method Summary collapse

Class Method Details

.find(group_name, const_name) ⇒ MIDIEvents::Constant::Map?

Get a Mapping object for the specified constant

Parameters:

  • group_name (Symbol, String)
  • const_name (String)

Returns:



29
30
31
32
# File 'lib/midi-events/constant.rb', line 29

def self.find(group_name, const_name)
  group = Group[group_name]
  group.find(const_name)
end

.value(group_name, const_name) ⇒ Object

Get the value of the specified constant

Parameters:

  • group_name (Symbol, String)
  • const_name (String)

Returns:

  • (Object)


38
39
40
41
# File 'lib/midi-events/constant.rb', line 38

def self.value(group_name, const_name)
  map = find(group_name, const_name)
  map.value
end