Class: Eg::Music::Simulator
- Inherits:
-
Object
- Object
- Eg::Music::Simulator
- Defined in:
- lib/eg/music/simulator.rb
Constant Summary collapse
- @@system =
Simulator.new
- @@time =
Time.now.to_i
- @@next_search_complete =
@@next_play_started = @@next_play_complete = 0
Class Method Summary collapse
- .next_play_complete ⇒ Object
- .next_play_complete=(value) ⇒ Object
- .next_play_started=(value) ⇒ Object
- .next_search_complete=(value) ⇒ Object
- .schedule(seconds) ⇒ Object
- .system ⇒ Object
- .time ⇒ Object
Instance Method Summary collapse
- #advance(future) ⇒ Object
- #delay(seconds) ⇒ Object
- #fail_load_jam ⇒ Object
- #next_event(bound) ⇒ Object
- #perform ⇒ Object
- #reset ⇒ Object
- #sooner(soon, event) ⇒ Object
- #wait_play_complete ⇒ Object
- #wait_play_started ⇒ Object
- #wait_search_complete ⇒ Object
Class Method Details
.next_play_complete ⇒ Object
26 |
# File 'lib/eg/music/simulator.rb', line 26 def Simulator.next_play_complete; @@next_play_complete; end |
.next_play_complete=(value) ⇒ Object
23 24 25 |
# File 'lib/eg/music/simulator.rb', line 23 def Simulator.next_play_complete= value @@next_play_complete = value end |
.next_play_started=(value) ⇒ Object
20 21 22 |
# File 'lib/eg/music/simulator.rb', line 20 def Simulator.next_play_started= value @@next_play_started = value end |
.next_search_complete=(value) ⇒ Object
17 18 19 |
# File 'lib/eg/music/simulator.rb', line 17 def Simulator.next_search_complete= value @@next_search_complete = value end |
.schedule(seconds) ⇒ Object
53 54 55 |
# File 'lib/eg/music/simulator.rb', line 53 def Simulator.schedule seconds @@time + seconds end |
.system ⇒ Object
14 15 16 |
# File 'lib/eg/music/simulator.rb', line 14 def Simulator.system @@system end |
.time ⇒ Object
27 |
# File 'lib/eg/music/simulator.rb', line 27 def Simulator.time; @@time; end |
Instance Method Details
#advance(future) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/eg/music/simulator.rb', line 47 def advance future while @@time < future @@time = next_event future perform end end |
#delay(seconds) ⇒ Object
56 57 58 |
# File 'lib/eg/music/simulator.rb', line 56 def delay seconds advance(Simulator.schedule(seconds)) end |
#fail_load_jam ⇒ Object
62 63 64 |
# File 'lib/eg/music/simulator.rb', line 62 def fail_load_jam Fit::ActionFixture.actor = Dialog.new('load jamed', Fit::ActionFixture.actor) end |
#next_event(bound) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/eg/music/simulator.rb', line 32 def next_event bound result = bound result = sooner result, @@next_search_complete result = sooner result, @@next_play_started result = sooner result, @@next_play_complete result end |
#perform ⇒ Object
42 43 44 45 46 |
# File 'lib/eg/music/simulator.rb', line 42 def perform MusicLibrary.search_complete if @@time == @@next_search_complete MusicPlayer.play_started if @@time == @@next_play_started MusicPlayer.play_complete if @@time == @@next_play_complete end |
#reset ⇒ Object
28 29 30 31 |
# File 'lib/eg/music/simulator.rb', line 28 def reset @@next_search_complete = @@next_play_started = @@next_play_complete = 0 MusicPlayer.stop end |
#sooner(soon, event) ⇒ Object
39 40 41 |
# File 'lib/eg/music/simulator.rb', line 39 def sooner soon, event (event > @@time and event < soon) ? event : soon end |
#wait_play_complete ⇒ Object
61 |
# File 'lib/eg/music/simulator.rb', line 61 def wait_play_complete; advance(@@next_play_complete); end |
#wait_play_started ⇒ Object
60 |
# File 'lib/eg/music/simulator.rb', line 60 def wait_play_started; advance(@@next_play_started); end |
#wait_search_complete ⇒ Object
59 |
# File 'lib/eg/music/simulator.rb', line 59 def wait_search_complete; advance(@@next_search_complete); end |