Skip to content

Commit d2675a4

Browse files
committed
fix: metronome recursion
1 parent 014114d commit d2675a4

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/Features/Metronome.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ static std::thread metronomeThread;
1616
static int metronomeBeat = 0;
1717

1818
static void bpmTick() {
19-
auto interval = std::chrono::milliseconds(1000);
20-
if (sar_metronome.GetBool()) {
21-
auto isBar = metronomeBeat == 0;
22-
metronomeBeat = (metronomeBeat + 1) % sar_metronome_beats.GetInt();
23-
auto sound = isBar ? sar_metronome_sound_bar.GetString() : sar_metronome_sound.GetString();
24-
engine->ExecuteCommand(Utils::ssprintf("playvol \"%s\" %f", sound, sar_metronome_volume.GetFloat()).c_str());
25-
if (sar_metronome_bpm.GetFloat() > 0) {
26-
interval = std::chrono::milliseconds((int)(60000 / sar_metronome_bpm.GetFloat()));
19+
while (true) {
20+
while (sar_metronome.GetBool()) {
21+
auto interval = std::chrono::milliseconds(1000);
22+
auto isBar = metronomeBeat == 0;
23+
metronomeBeat = (metronomeBeat + 1) % sar_metronome_beats.GetInt();
24+
auto sound = isBar ? sar_metronome_sound_bar.GetString() : sar_metronome_sound.GetString();
25+
engine->ExecuteCommand(Utils::ssprintf("playvol \"%s\" %f", sound, sar_metronome_volume.GetFloat()).c_str());
26+
if (sar_metronome_bpm.GetFloat() > 0) {
27+
interval = std::chrono::milliseconds((int)(60000 / sar_metronome_bpm.GetFloat()));
28+
}
29+
std::this_thread::sleep_for(interval);
2730
}
31+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
2832
}
29-
std::this_thread::sleep_for(interval);
30-
bpmTick();
3133
}
3234

3335
ON_INIT {

0 commit comments

Comments
 (0)