From 0e3a8a91a22b718c25342e000c623b0594faa538 Mon Sep 17 00:00:00 2001 From: dndrks Date: Wed, 30 Sep 2020 10:29:55 -0400 Subject: [PATCH] quickfix don't divide by 0!! --- cheat_codes.lua | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/cheat_codes.lua b/cheat_codes.lua index 7b6f63f..0234f5c 100755 --- a/cheat_codes.lua +++ b/cheat_codes.lua @@ -1199,36 +1199,34 @@ end --- function sync_clock_to_loop(source,style) - local duration = 0 + local dur = 0 local pattern_id; if style == "audio" then - duration = source.end_point-source.start_point + dur = source.end_point-source.start_point elseif style == "pattern" then pattern_id = string.match(source.name,"%d+") if params:string("sync_clock_to_pattern_"..pattern_id) == "yes" then for i = source.start_point,source.end_point do - duration = duration + source.time[i] + dur = dur + source.time[i] end end end - local quarter = duration/4 - local derived_bpm = 60/quarter - while derived_bpm < 70 do - derived_bpm = derived_bpm * 2 - if derived_bpm > 160 then break end - end - while derived_bpm > 160 do - derived_bpm = derived_bpm/2 - if derived_bpm <= 70 then break end - end - if duration ~= 0 then + if dur > 0 then + local quarter = dur/4 + local derived_bpm = 60/quarter + while derived_bpm < 70 do + derived_bpm = derived_bpm * 2 + if derived_bpm > 160 then break end + end + while derived_bpm > 160 do + derived_bpm = derived_bpm/2 + if derived_bpm <= 70 then break end + end if params:get("clock_midi_out") ~= 1 then params:set("clock_tempo",util.round(derived_bpm)) else params:set("clock_tempo",util.round(derived_bpm,0.01)) end - else - print("won't be doing it!") end end