Class: MIDIEvents::Constant::MessageBuilder Private

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

Overview

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

Helper class for building messages with pre-bound constants

This class is returned when you call a message class's bracket method with a constant name (e.g., NoteOn["C4"]). It stores the constant and message class so that when you call #new, it creates the message with the constant value already filled in.

Examples:

builder = MIDIEvents::NoteOn["C4"]
note = builder.new(0, 100)  # channel 0, velocity 100
# The note value (60 for C4) is automatically filled in

Instance Method Summary collapse

Constructor Details

#initialize(klass, const) ⇒ MessageBuilder

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.

Create a new message builder

Parameters:

  • klass (Class)

    The message class to build (e.g., NoteOn)

  • const (MIDIEvents::Constant::Map)

    The constant to build with



224
225
226
227
# File 'lib/midi-events/constant.rb', line 224

def initialize(klass, const)
  @klass = klass
  @const = const
end

Instance Method Details

#new(*args) ⇒ MIDIEvents::Message

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.

Create a message instance with the bound constant

Parameters:

  • args (Array)

    The remaining arguments for the message constructor

Returns:



233
234
235
236
237
# File 'lib/midi-events/constant.rb', line 233

def new(*args)
  args = args.dup
  args.last.is_a?(Hash) ? args.last[:const] = @const : args.push(const: @const)
  @klass.new(*args)
end