Class: Musa::MIDIVoices::MIDIVoices
- Defined in:
- lib/musa-dsl/midi/midi-voices.rb
Overview
All durations are expressed as Rational numbers representing bars.
MIDI channels are zero-indexed (0-15), not 1-16.
High level helpers to drive one or more MIDI channels from a Sequencer::Sequencer.
A voice represents the state of a given MIDI channel (active notes, controllers, sustain pedal, etc.). MIDIVoices ties the life‑cycle of those voices to the sequencer clock so that note durations, waits and callbacks stay in the musical timeline even when running in fast-forward or quantized sessions.
Typical usage:
Instance Attribute Summary collapse
-
#do_log ⇒ Boolean
Whether verbose logging is enabled.
-
#voices ⇒ Array<MIDIVoice>
readonly
Read-only list of per-channel voices.
Instance Method Summary collapse
-
#fast_forward=(enabled) ⇒ void
Enables or disables the fast-forward mode on every voice.
-
#initialize(sequencer:, output:, channels:, do_log: nil) ⇒ void
constructor
Builds the voice container for one or many MIDI channels.
-
#panic(reset: nil) ⇒ void
Sends all-notes-off on every channel and (optionally) a MIDI reset.
-
#reset ⇒ void
Resets the collection recreating every MIDIVoice.
Constructor Details
#initialize(sequencer:, output:, channels:, do_log: nil) ⇒ void
Builds the voice container for one or many MIDI channels.
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 102 def initialize(sequencer:, output:, channels:, do_log: nil) do_log ||= false @sequencer = sequencer @output = output @channels = channels.arrayfy.explode_ranges @do_log = do_log reset end |
Instance Attribute Details
#do_log ⇒ Boolean
Returns whether verbose logging is enabled.
92 93 94 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 92 def do_log @do_log end |
Instance Method Details
#fast_forward=(enabled) ⇒ void
This method returns an undefined value.
Enables or disables the fast-forward mode on every voice.
When enabled, notes are registered internally but their MIDI messages are not emitted, allowing the sequencer to catch up silently (e.g. when loading a snapshot).
132 133 134 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 132 def fast_forward=(enabled) @voices.each { |voice| voice.fast_forward = enabled } end |
#panic(reset: nil) ⇒ void
This method returns an undefined value.
Sends all-notes-off on every channel and (optionally) a MIDI reset.
140 141 142 143 144 145 146 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 140 def panic(reset: nil) reset ||= false @voices.each(&:all_notes_off) @output.puts MIDIEvents::SystemRealtime.new(0xff) if reset end |
#reset ⇒ void
This method returns an undefined value.
Resets the collection recreating every Musa::MIDIVoices::MIDIVoice. Useful when the MIDI output has changed or after a panic.
117 118 119 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 117 def reset @voices = @channels.collect { |channel| MIDIVoice.new(sequencer: @sequencer, output: @output, channel: channel, do_log: @do_log) }.freeze end |