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) ⇒ Object
sequencer = Musa::Sequencer::BaseSequencer.new(4, 24) voices = Musa::MIDIVoices::MIDIVoices.new(sequencer: sequencer, output: output, channels: [0]) voice = voices.voices.first.
-
#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.
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 137 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.
127 128 129 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 127 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).
167 168 169 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 167 def fast_forward=(enabled) @voices.each { |voice| voice.fast_forward = enabled } end |
#panic(reset: nil) ⇒ Object
sequencer = Musa::Sequencer::BaseSequencer.new(4, 24) voices = Musa::MIDIVoices::MIDIVoices.new(sequencer: sequencer, output: output, channels: [0]) voice = voices.voices.first
voices.panic
output.sent # => [[176, 123, 0]]
# CC 123 -- all notes off -- once per channel. With `reset: true` an
# FF system-reset follows it:
voices.panic(reset: true)
output.sent # => [[176, 123, 0], [176, 123, 0], [255]]
195 196 197 198 199 200 201 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 195 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.
152 153 154 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 152 def reset @voices = @channels.collect { |channel| MIDIVoice.new(sequencer: @sequencer, output: @output, channel: channel, do_log: @do_log) }.freeze end |