Class: Zgomot::Midi::Dispatcher
Class Attribute Summary collapse
-
.clock ⇒ Object
readonly
Returns the value of attribute clock.
-
.last_time ⇒ Object
readonly
Returns the value of attribute last_time.
-
.playing ⇒ Object
readonly
Returns the value of attribute playing.
-
.qdispatch ⇒ Object
readonly
Returns the value of attribute qdispatch.
-
.qmutex ⇒ Object
readonly
Returns the value of attribute qmutex.
-
.queue ⇒ Object
readonly
Returns the value of attribute queue.
-
.resolution ⇒ Object
readonly
Returns the value of attribute resolution.
-
.thread ⇒ Object
readonly
Returns the value of attribute thread.
-
.tick ⇒ Object
readonly
Returns the value of attribute tick.
Class Method Summary collapse
- .clk ⇒ Object
- .dequeue(time) ⇒ Object
- .dispatch(now) ⇒ Object
- .done? ⇒ Boolean
- .enqueue(ch) ⇒ Object
- .flush ⇒ Object
- .notes_off(time) ⇒ Object
- .notes_on(notes) ⇒ Object
Class Attribute Details
.clock ⇒ Object (readonly)
Returns the value of attribute clock.
13 14 15 |
# File 'lib/zgomot/midi/dispatcher.rb', line 13 def clock @clock end |
.last_time ⇒ Object (readonly)
Returns the value of attribute last_time.
13 14 15 |
# File 'lib/zgomot/midi/dispatcher.rb', line 13 def last_time @last_time end |
.playing ⇒ Object (readonly)
Returns the value of attribute playing.
13 14 15 |
# File 'lib/zgomot/midi/dispatcher.rb', line 13 def @playing end |
.qdispatch ⇒ Object (readonly)
Returns the value of attribute qdispatch.
13 14 15 |
# File 'lib/zgomot/midi/dispatcher.rb', line 13 def qdispatch @qdispatch end |
.qmutex ⇒ Object (readonly)
Returns the value of attribute qmutex.
13 14 15 |
# File 'lib/zgomot/midi/dispatcher.rb', line 13 def qmutex @qmutex end |
.queue ⇒ Object (readonly)
Returns the value of attribute queue.
13 14 15 |
# File 'lib/zgomot/midi/dispatcher.rb', line 13 def queue @queue end |
.resolution ⇒ Object (readonly)
Returns the value of attribute resolution.
13 14 15 |
# File 'lib/zgomot/midi/dispatcher.rb', line 13 def resolution @resolution end |
.thread ⇒ Object (readonly)
Returns the value of attribute thread.
13 14 15 |
# File 'lib/zgomot/midi/dispatcher.rb', line 13 def thread @thread end |
.tick ⇒ Object (readonly)
Returns the value of attribute tick.
13 14 15 |
# File 'lib/zgomot/midi/dispatcher.rb', line 13 def tick @tick end |
Class Method Details
.clk ⇒ Object
15 16 17 |
# File 'lib/zgomot/midi/dispatcher.rb', line 15 def clk clock.to_s end |
.dequeue(time) ⇒ Object
33 34 35 36 37 |
# File 'lib/zgomot/midi/dispatcher.rb', line 33 def dequeue(time) qmutex.synchronize do queue.partition{|n| n.play_at <= time} end end |
.dispatch(now) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/zgomot/midi/dispatcher.rb', line 39 def dispatch(now) qdispatch.synchronize do ready, @queue = dequeue(now) notes_off(now) notes_on(ready) end end |
.done? ⇒ Boolean
23 24 25 |
# File 'lib/zgomot/midi/dispatcher.rb', line 23 def done? qdispatch.synchronize{queue.empty? and .empty?} end |
.enqueue(ch) ⇒ Object
27 28 29 30 31 |
# File 'lib/zgomot/midi/dispatcher.rb', line 27 def enqueue(ch) qmutex.synchronize do @queue += ch.pattern.map{|p| p.to_midi}.flatten.compact.select{|n| not n.pitch_class.eql?(:R)} end end |
.flush ⇒ Object
19 20 21 |
# File 'lib/zgomot/midi/dispatcher.rb', line 19 def flush @queue.clear end |
.notes_off(time) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/zgomot/midi/dispatcher.rb', line 55 def notes_off(time) turn_off, @playing = .partition{|n| (n.play_at+n.length_to_sec) <= time} turn_off.each do |n| Zgomot.logger.info "NOTE OFF:#{n.channel} : #{n.to_s} : #{n.time.to_s} : #{clock.current_time.to_s}" Zgomot::Drivers::Mgr.note_off(n.midi, n.channel, (127*n.velocity).to_i) end end |
.notes_on(notes) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/zgomot/midi/dispatcher.rb', line 47 def notes_on(notes) notes.each do |n| Zgomot.logger.info "NOTE ON: #{n.channel} : #{n.to_s} : #{n.time.to_s} : #{clock.current_time.to_s}" Zgomot::Drivers::Mgr.note_on(n.midi, n.channel, (127*n.velocity).to_i) end @playing += notes end |