Skip to content

Commit 9c1f211

Browse files
committed
Core - work with current_bpm_mode where necessary
Previously we we just using current_bpm which worked fine prior to the new :link mode. To maintain compatibility, within :link mode current_bpm returns Link's current bpm as a number. However, this function was also being used in places where the mode was important rather than the current value. This fixes issues when syncing within :link bpm mode observed on the forums: https://in-thread.sonic-pi.net/t/demo-of-experimental-ableton-link-with-sonic-pi/5869/5?u=samaaron
1 parent f3cc6f5 commit 9c1f211

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def initialize(time, priority, thread_id, delta, beat, bpm, path, val, meta={})
3030
@thread_id = thread_id
3131
@delta = delta.to_i
3232
@beat = beat.to_f
33-
@bpm = bpm.to_f
33+
@bpm = bpm
3434

3535
if path.is_a?(Symbol)
3636
@path = @@path_cache[path] || @@path_cache[path] = "/cue/#{path}".strip.freeze

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __cueset(k, val, prefix)
108108
d = __system_thread_locals.get(:sonic_pi_spider_thread_delta)
109109
__system_thread_locals.set_local(:sonic_pi_spider_thread_delta, d + 1)
110110
p = __system_thread_locals.get(:sonic_pi_spider_thread_priority, 0)
111-
m = current_bpm
111+
m = current_bpm_mode
112112

113113
ce = CueEvent.new(t, p, i, d, b, m, cue_path, val)
114114

@@ -316,7 +316,7 @@ def get_event(*args)
316316
i = __current_thread_id
317317
d = __system_thread_locals.get(:sonic_pi_spider_thread_delta)
318318
p = __system_thread_locals.get(:sonic_pi_spider_thread_priority, 1001)
319-
m = current_bpm
319+
m = current_bpm_mode
320320

321321
@event_history.get(t, p, i, d, b, m, k)
322322
end
@@ -2153,6 +2153,9 @@ def live_loop(name=nil, *args, &block)
21532153

21542154
sync_sym = args_h[:sync]
21552155
sync_bpm_sym = args_h[:sync_bpm]
2156+
2157+
#handle case where user passes both :sync and :sync_bpm opts.
2158+
# --> sync_bpm overrides sync
21562159
sync_sym = nil if sync_bpm_sym
21572160

21582161
raise LiveLockError, "livelock detection - live_loop cannot sync with itself - please choose another sync name for live_loop #{name.inspect}" if name == sync_sym || name == sync_bpm_sym
@@ -3649,7 +3652,7 @@ def use_bpm(bpm, &block)
36493652
def with_bpm(bpm, &block)
36503653
raise ArgumentError, "with_bpm must be called with a do/end block. Perhaps you meant use_bpm" unless block
36513654
raise ArgumentError, "with_bpm's BPM should be a positive value. You tried to use: #{bpm}" unless bpm > 0
3652-
current_bpm = __get_spider_bpm
3655+
current_bpm = __get_spider_bpm_mode
36533656
use_bpm bpm
36543657
res = block.call
36553658
use_bpm current_bpm
@@ -4035,7 +4038,7 @@ def set_sched_ahead_time!(sat)
40354038
t = __get_spider_time
40364039
b = __get_spider_beat_
40374040
i = __current_thread_id
4038-
m = current_bpm
4041+
m = current_bpm_mode
40394042
@system_state.set(t, 0, i, 0, b, m, :sched_ahead_time, sat)
40404043
__info "Schedule ahead time set to #{sat}"
40414044
end
@@ -4299,7 +4302,7 @@ def __live_loop_cue(id)
42994302
d = __system_thread_locals.get(:sonic_pi_spider_thread_delta)
43004303
__system_thread_locals.set_local(:sonic_pi_spider_thread_delta, d + 1)
43014304
cue_path = "/live_loop/#{id}"
4302-
@register_cue_event_lambda.call(t, p, __current_thread_id, d, current_beat, current_bpm, cue_path, [], __current_sched_ahead_time)
4305+
@register_cue_event_lambda.call(t, p, __current_thread_id, d, current_beat, current_bpm_mode, cue_path, [], __current_sched_ahead_time)
43034306
end
43044307

43054308

@@ -4368,7 +4371,7 @@ def sync_event(*args)
43684371
raise StandardError, "Incorrect bpm value. Expecting either :link or a number such as 120" unless ((se.bpm == :link) || se.bpm.is_a?(Numeric))
43694372
__change_spider_bpm_time_and_beat!(se.bpm, se.time, se.beat)
43704373
else
4371-
__change_spider_bpm_time_and_beat!(current_bpm, se.time, se.beat)
4374+
__change_spider_bpm_time_and_beat!(current_bpm_mode, se.time, se.beat)
43724375
end
43734376

43744377
run_info = ""

0 commit comments

Comments
 (0)