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.
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 115 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.
105 106 107 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 105 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).
145 146 147 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 145 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.
153 154 155 156 157 158 159 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 153 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.
130 131 132 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 130 def reset @voices = @channels.collect { |channel| MIDIVoice.new(sequencer: @sequencer, output: @output, channel: channel, do_log: @do_log) }.freeze end |