Class: Zgomot::Midi::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/zgomot/midi/dispatcher.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.clockObject (readonly)

Returns the value of attribute clock.



13
14
15
# File 'lib/zgomot/midi/dispatcher.rb', line 13

def clock
  @clock
end

.playingObject (readonly)

Returns the value of attribute playing.



13
14
15
# File 'lib/zgomot/midi/dispatcher.rb', line 13

def playing
  @playing
end

.qdispatchObject (readonly)

Returns the value of attribute qdispatch.



13
14
15
# File 'lib/zgomot/midi/dispatcher.rb', line 13

def qdispatch
  @qdispatch
end

.qmutexObject (readonly)

Returns the value of attribute qmutex.



13
14
15
# File 'lib/zgomot/midi/dispatcher.rb', line 13

def qmutex
  @qmutex
end

.queueObject (readonly)

Returns the value of attribute queue.



13
14
15
# File 'lib/zgomot/midi/dispatcher.rb', line 13

def queue
  @queue
end

.resolutionObject (readonly)

Returns the value of attribute resolution.



13
14
15
# File 'lib/zgomot/midi/dispatcher.rb', line 13

def resolution
  @resolution
end

.threadObject (readonly)

Returns the value of attribute thread.



13
14
15
# File 'lib/zgomot/midi/dispatcher.rb', line 13

def thread
  @thread
end

.tickObject (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

.clkObject



15
16
17
# File 'lib/zgomot/midi/dispatcher.rb', line 15

def clk
  clock.to_s
end

.dequeueObject



35
36
37
38
39
# File 'lib/zgomot/midi/dispatcher.rb', line 35

def dequeue
  qmutex.synchronize do
    queue.partition{|n| n.note_on.to_f <= clock.current_time.to_f}
  end
end

.done?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/zgomot/midi/dispatcher.rb', line 23

def done?
  qmutex.synchronize{queue.empty? and playing.empty?}
end

.enqueue(ch) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/zgomot/midi/dispatcher.rb', line 27

def enqueue(ch)
  ch.offset = clock.ceil
  qmutex.synchronize do
    pattern = ch.pattern.map{|p| p.to_midi}.flatten.compact.select{|n| not n.pitch_class.eql?(:R)}
    @queue += pattern
  end
end

.flushObject



19
20
21
# File 'lib/zgomot/midi/dispatcher.rb', line 19

def flush
  @queue.clear
end