Class: Ruck::MIDI::MIDIShreduler
- Inherits:
-
Shreduler
- Object
- Shreduler
- Ruck::MIDI::MIDIShreduler
- Defined in:
- lib/ruck/midi/midi.rb
Instance Attribute Summary collapse
-
#midi ⇒ Object
readonly
Returns the value of attribute midi.
Instance Method Summary collapse
-
#initialize(midi, real_time) ⇒ MIDIShreduler
constructor
A new instance of MIDIShreduler.
- #run ⇒ Object
- #sim_to(new_now) ⇒ Object
Constructor Details
#initialize(midi, real_time) ⇒ MIDIShreduler
Returns a new instance of MIDIShreduler.
11 12 13 14 15 |
# File 'lib/ruck/midi/midi.rb', line 11 def initialize(midi, real_time) super() @midi = midi @real_time = real_time end |
Instance Attribute Details
#midi ⇒ Object (readonly)
Returns the value of attribute midi.
9 10 11 |
# File 'lib/ruck/midi/midi.rb', line 9 def midi @midi end |
Instance Method Details
#run ⇒ Object
17 18 19 20 |
# File 'lib/ruck/midi/midi.rb', line 17 def run @start_time = Time.now super end |
#sim_to(new_now) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruck/midi/midi.rb', line 22 def sim_to(new_now) d = new_now - @now @midi.tick(d) # sync with wall clock if @real_time actual_now = Time.now simulated_now = @start_time + (new_now.to_f / @midi.ppqn / @midi.bpm * 60.0) if simulated_now > actual_now sleep(simulated_now - actual_now) end end @now = new_now end |