Module: MIDIEvents::Constant::Loader::DSL Private

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

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

DSL class methods for message classes to work with constants

These methods are extended into message classes to provide constant lookup functionality (e.g., NoteOn["C4"]).

Instance Method Summary collapse

Instance Method Details

#constant_mapHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


331
332
333
# File 'lib/midi-events/constant.rb', line 331

def constant_map
  const_get('CONSTANT') if const_defined?('CONSTANT')
end

#constant_nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


336
337
338
# File 'lib/midi-events/constant.rb', line 336

def constant_name
  constant_map&.keys&.first
end

#constant_propertySymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Symbol)


341
342
343
# File 'lib/midi-events/constant.rb', line 341

def constant_property
  constant_map[constant_name] unless constant_map.nil?
end

#display_nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


326
327
328
# File 'lib/midi-events/constant.rb', line 326

def display_name
  const_get('DISPLAY_NAME') if const_defined?('DISPLAY_NAME')
end

#find(const_name) ⇒ MIDIEvents::Constant::MessageBuilder? Also known as: []

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Find a constant and return a MessageBuilder bound to it

This enables the bracket syntax: NoteOn["C4"].new(channel, velocity)

Examples:

builder = MIDIEvents::NoteOn["C4"]
note = builder.new(0, 100)  # Creates NoteOn for C4 on channel 0

Parameters:

  • const_name (String, Symbol)

    The constant name to look up

Returns:



361
362
363
364
# File 'lib/midi-events/constant.rb', line 361

def find(const_name)
  const = get_constant(const_name.to_s)
  MessageBuilder.new(self, const) unless const.nil?
end

#get_constant(name) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Find a constant value in this class's group for the passed in key

Parameters:

  • name (String)

    The constant key

Returns:

  • (String)

    The constant value



317
318
319
320
321
322
323
# File 'lib/midi-events/constant.rb', line 317

def get_constant(name)
  key = constant_name || display_name
  return if key.nil?

  group = Group[key]
  group.find(name)
end

#type_for_statusFixnum

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the status nibble for this particular message type

Returns:

  • (Fixnum)

    The status nibble



347
348
349
# File 'lib/midi-events/constant.rb', line 347

def type_for_status
  Constant::Status[display_name]
end