Module: MIDIEvents

Included in:
ChannelMessage, SystemExclusive
Defined in:
lib/midi-events/version.rb,
lib/midi-events/context.rb,
lib/midi-events/message.rb,
lib/midi-events/constant.rb,
lib/midi-events/messages.rb,
lib/midi-events/note_message.rb,
lib/midi-events/system_message.rb,
lib/midi-events/channel_message.rb,
lib/midi-events/type_conversion.rb,
lib/midi-events/system_exclusive.rb

Overview

Note:

This library is part of the MusaDSL ecosystem

Note:

Based on Ari Russo's MIDI Message library with performance optimizations

Ruby MIDI Events library - object-oriented representation of MIDI messages

This library provides a comprehensive set of classes and modules for working with MIDI events in Ruby. It offers an intuitive API for creating and manipulating various MIDI message types including channel messages (notes, control changes, program changes), system messages, and system exclusive (SysEx) messages.

Examples:

Basic note creation

require 'midi-events'

# Create a middle C note-on message on channel 0 with velocity 64
note = MIDIEvents::NoteOn.new(0, 64, 64)
# => #<MIDIEvents::NoteOn @channel=0, @note=64, @velocity=64>

Using note names

# Create note using named constant
note = MIDIEvents::NoteOn["E4"].new(0, 100)
# => #<MIDIEvents::NoteOn @channel=0, @note=64, @velocity=100, @name="E4">

Using context for common parameters

# Set channel and velocity as context
MIDIEvents.with(channel: 0, velocity: 100) do
  note_on("E4")  # Creates note-on with channel 0, velocity 100
end

Working with control changes

# Create modulation wheel control change
cc = MIDIEvents::ControlChange["Modulation Wheel"].new(0, 64)

System exclusive messages

# Create a SysEx node representing a device
synth = MIDIEvents::SystemExclusive::Node.new(0x41, model_id: 0x42, device_id: 0x10)

# Send a command to the device
command = synth.command([0x40, 0x7F, 0x00], 0x00)

See Also:

Author:

  • (c)2021 Javier Sánchez Yeste for the modifications, licensed under LGPL 3.0 License

  • (c)2011-2015 Ari Russo for original MIDI Message library, licensed under Apache 2.0 License

Defined Under Namespace

Modules: ChannelMessage, Constant, Message, NoteMessage, SystemExclusive, SystemMessage, TypeConversion Classes: ChannelAftertouch, Context, ControlChange, NoteOff, NoteOn, PitchBend, PolyphonicAftertouch, ProgramChange, SystemCommon, SystemRealtime

Constant Summary collapse

VERSION =
'0.7.0'.freeze
ChannelPressure =
ChannelAftertouch
Controller =

shortcut

ControlChange
PolyAftertouch =
PolyphonicAftertouch
PolyPressure =
PolyphonicAftertouch
PolyphonicPressure =
PolyphonicAftertouch

Class Method Summary collapse

Class Method Details

.with_context(options = {}, &block) ⇒ Object Also known as: with

Shortcut to MIDIMessage::Context.with

Parameters:

  • options (Hash) (defaults to: {})
  • block (Proc)

Options Hash (options):

  • :channel (Fixnum)
  • :velocity (Fixnum)


183
184
185
# File 'lib/midi-events/context.rb', line 183

def self.with_context(options = {}, &block)
  Context.with(options, &block)
end