lib/xi/clock.rb in xi-lang-0.1.5 vs lib/xi/clock.rb in xi-lang-0.1.6
- old
+ new
@@ -13,11 +13,11 @@
def initialize(cps: DEFAULT_CPS)
@mutex = Mutex.new
@cps = cps
@playing = true
@streams = [].to_set
- @init_ts = Time.now.to_f
+ @init_ts = Time.now.to_i.to_f
@latency = 0.0
@play_thread = Thread.new { thread_routine }
end
def subscribe(stream)
@@ -32,9 +32,25 @@
@mutex.synchronize { @cps }
end
def cps=(new_cps)
@mutex.synchronize { @cps = new_cps.to_f }
+ end
+
+ def bps
+ @mutex.synchronize { @cps * 2 }
+ end
+
+ def bps=(new_bps)
+ @mutex.synchronize { @cps = new_bps / 2.0 }
+ end
+
+ def bpm
+ @mutex.synchronize { @cps * 120 }
+ end
+
+ def bpm=(new_bpm)
+ @mutex.synchronize { @cps = new_bpm / 120.0 }
end
def latency=(new_latency)
@latency = new_latency.to_f
end