Skip to content

Commit f3cc6f5

Browse files
committed
Core - new fn - current_bpm_mode
Add new fn current_bpm_mode which works similarly to current_bpm except when in :link bpm mode returns :link rather than Link's current bpm.
1 parent c399db7 commit f3cc6f5

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

app/server/ruby/lib/sonicpi/lang/core.rb

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3898,22 +3898,51 @@ def current_random_source
38983898
puts rand # => 0.10821533203125
38993899
puts rand # => 0.54010009765625
39003900
"]
3901+
def current_bpm_mode
3902+
__get_spider_bpm_mode
3903+
end
3904+
doc name: :current_bpm_mode,
3905+
introduced: Version.new(4,0,0),
3906+
summary: "Get current tempo mode",
3907+
doc: "Returns the current tempo mode - either a bpm value or :link.
39013908
3909+
To know the current BPM value when this thread is in :link mode see `current_bpm`.
39023910
3903-
def current_bpm
3911+
This can be set via the fns `use_bpm`, `with_bpm`, `use_sample_bpm` and `with_sample_bpm`.",
3912+
args: [],
3913+
opts: nil,
3914+
accepts_block: false,
3915+
examples: ["
3916+
use_bpm 60
3917+
puts current_bpm_mode # => 60
3918+
use_bpm 70
3919+
puts current_bpm_mode # => 70
3920+
use_bpm :link
3921+
puts current_bpm_mode # => :link"]
3922+
3923+
3924+
3925+
def current_bpm
39043926
__get_spider_bpm
39053927
end
39063928
doc name: :current_bpm,
39073929
introduced: Version.new(2,0,0),
39083930
summary: "Get current tempo",
3909-
doc: "Returns the current tempo as a bpm value.
3931+
doc: "Returns the current tempo as a bpm value. If the thread is in :link bpm mode, this will return the latest bpm value of the shared Link network metronome (note that this value may change after reading if the Link bpm isn't static).
3932+
3933+
To know if this thread is in :link or standard bpm mode see `current_bpm_mode`.
39103934
39113935
This can be set via the fns `use_bpm`, `with_bpm`, `use_sample_bpm` and `with_sample_bpm`.",
39123936
args: [],
39133937
opts: nil,
39143938
accepts_block: false,
39153939
examples: ["
3916-
puts current_bpm # Print out the current bpm"]
3940+
use_bpm 60
3941+
puts current_bpm_mode # => 60
3942+
use_bpm 70
3943+
puts current_bpm_mode # => 70
3944+
use_bpm :link
3945+
puts current_bpm_mode # => 120 (or whatever the current Link BPM value is)"]
39173946

39183947

39193948

app/server/ruby/lib/sonicpi/runtime.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ def __get_spider_bpm
206206
end
207207
end
208208

209+
def __get_spider_bpm_mode
210+
if __in_link_bpm_mode
211+
:link
212+
else
213+
__get_spider_bpm
214+
end
215+
end
216+
209217
def __get_spider_beat
210218
__system_thread_locals.get :sonic_pi_spider_beat
211219
end

0 commit comments

Comments
 (0)