Class: Musa::MIDIVoices::MIDIVoice
- Inherits:
-
Object
- Object
- Musa::MIDIVoices::MIDIVoice
- Defined in:
- lib/musa-dsl/midi/midi-voices.rb
Instance Attribute Summary collapse
-
#active_pitches ⇒ Object
readonly
Returns the value of attribute active_pitches.
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#do_log ⇒ Object
Returns the value of attribute do_log.
-
#name ⇒ Object
Returns the value of attribute name.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#sequencer ⇒ Object
readonly
Returns the value of attribute sequencer.
-
#tick_duration ⇒ Object
readonly
Returns the value of attribute tick_duration.
Instance Method Summary collapse
- #all_notes_off ⇒ Object
- #controller ⇒ Object
- #fast_forward=(enabled) ⇒ Object
- #fast_forward? ⇒ Boolean
-
#initialize(sequencer:, output:, channel:, name: nil, do_log: nil) ⇒ MIDIVoice
constructor
A new instance of MIDIVoice.
- #log(msg) ⇒ Object
- #note(pitchvalue = nil, pitch: nil, velocity: nil, duration: nil, duration_offset: nil, note_duration: nil, velocity_off: nil) ⇒ Object
- #sustain_pedal ⇒ Object
- #sustain_pedal=(value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(sequencer:, output:, channel:, name: nil, do_log: nil) ⇒ MIDIVoice
Returns a new instance of MIDIVoice.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 51 def initialize(sequencer:, output:, channel:, name: nil, do_log: nil) do_log ||= false @sequencer = sequencer @output = output @channel = channel @name = name @do_log = do_log @tick_duration = Rational(1, @sequencer.) @controllers_control = ControllersControl.new(@output, @channel) @active_pitches = [] fill_active_pitches @active_pitches @sequencer.logger.warn 'voice without output' unless @output self end |
Instance Attribute Details
#active_pitches ⇒ Object (readonly)
Returns the value of attribute active_pitches.
49 50 51 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 49 def active_pitches @active_pitches end |
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
49 50 51 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 49 def channel @channel end |
#do_log ⇒ Object
Returns the value of attribute do_log.
48 49 50 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 48 def do_log @do_log end |
#name ⇒ Object
Returns the value of attribute name.
48 49 50 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 48 def name @name end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
49 50 51 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 49 def output @output end |
#sequencer ⇒ Object (readonly)
Returns the value of attribute sequencer.
49 50 51 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 49 def sequencer @sequencer end |
#tick_duration ⇒ Object (readonly)
Returns the value of attribute tick_duration.
49 50 51 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 49 def tick_duration @tick_duration end |
Instance Method Details
#all_notes_off ⇒ Object
113 114 115 116 117 118 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 113 def all_notes_off @active_pitches.clear fill_active_pitches @active_pitches @output.puts MIDIEvents::ChannelMessage.new(0xb, @channel, 0x7b, 0) end |
#controller ⇒ Object
101 102 103 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 101 def controller @controllers_control end |
#fast_forward=(enabled) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 72 def fast_forward=(enabled) if @fast_forward && !enabled (0..127).each do |pitch| @output.puts MIDIEvents::NoteOn.new(@channel, pitch, @active_pitches[pitch][:velocity]) unless @active_pitches[pitch][:note_controls].empty? end end @fast_forward = enabled end |
#fast_forward? ⇒ Boolean
82 83 84 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 82 def fast_forward? @fast_forward end |
#log(msg) ⇒ Object
120 121 122 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 120 def log(msg) @sequencer.logger.info('MIDIVoice') { "voice #{name || @channel}: #{msg}" } if @do_log end |
#note(pitchvalue = nil, pitch: nil, velocity: nil, duration: nil, duration_offset: nil, note_duration: nil, velocity_off: nil) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 86 def note(pitchvalue = nil, pitch: nil, velocity: nil, duration: nil, duration_offset: nil, note_duration: nil, velocity_off: nil) pitch ||= pitchvalue if pitch velocity ||= 63 duration_offset ||= -@tick_duration note_duration ||= [0, duration + duration_offset].max velocity_off ||= 63 NoteControl.new(self, pitch: pitch, velocity: velocity, duration: note_duration, velocity_off: velocity_off).note_on end end |
#sustain_pedal ⇒ Object
109 110 111 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 109 def sustain_pedal @controllers_control[:sustain_pedal] end |
#sustain_pedal=(value) ⇒ Object
105 106 107 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 105 def sustain_pedal=(value) @controllers_control[:sustain_pedal] = value end |
#to_s ⇒ Object
124 125 126 |
# File 'lib/musa-dsl/midi/midi-voices.rb', line 124 def to_s "voice #{@name} output: #{@output} channel: #{@channel}" end |