Skip to content

Commit a17b01b

Browse files
author
Matthieu Mastio
committed
round BPM values to prevent float truncation mismatch
1 parent 5b7b261 commit a17b01b

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

juce/NinjamRunThread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,15 @@ void NinjamRunThread::detectBpmBpiChanges(NJClient* client)
477477
}
478478

479479
// Detect BPM change
480-
if (prevBpm > 0.0f && static_cast<int>(prevBpm) != static_cast<int>(newBpm))
480+
if (prevBpm > 0.0f && static_cast<int>(std::round(prevBpm)) != static_cast<int>(std::round(newBpm)))
481481
{
482482
processor.evt_queue.try_push(jamwide::BpmChangedEvent{prevBpm, newBpm});
483483

484484
ChatMessage msg;
485485
msg.type = ChatMessageType::System;
486486
msg.content = "[Server] BPM changed from "
487-
+ std::to_string(static_cast<int>(prevBpm))
488-
+ " to " + std::to_string(static_cast<int>(newBpm));
487+
+ std::to_string(static_cast<int>(std::round(prevBpm)))
488+
+ " to " + std::to_string(static_cast<int>(std::round(newBpm)));
489489
msg.timestamp = currentTimeString();
490490
processor.chat_queue.try_push(std::move(msg));
491491

juce/ui/BeatBar.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void BeatBar::paint(juce::Graphics& g)
5858
auto bpmArea = labelArea.removeFromLeft(36);
5959
g.setColour(textCol);
6060
g.setFont(numberFont);
61-
g.drawText(juce::String(static_cast<int>(currentBpm_)), bpmArea,
61+
g.drawText(juce::String(static_cast<int>(std::round(currentBpm_))), bpmArea,
6262
juce::Justification::centredRight, false);
6363

6464
// Separator "/"
@@ -158,7 +158,7 @@ void BeatBar::mouseDown(const juce::MouseEvent& e)
158158
void BeatBar::createVoteEditor(bool forBpm)
159159
{
160160
editingBpm_ = forBpm;
161-
int currentVal = forBpm ? static_cast<int>(currentBpm_) : bpi_;
161+
int currentVal = forBpm ? static_cast<int>(std::round(currentBpm_)) : bpi_;
162162

163163
// Create TextEditor overlay
164164
voteEditor_ = std::make_unique<juce::TextEditor>();
@@ -188,7 +188,7 @@ void BeatBar::createVoteEditor(bool forBpm)
188188

189189
if (valid && processorRef_)
190190
{
191-
int existingVal = editingBpm_ ? static_cast<int>(currentBpm_) : bpi_;
191+
int existingVal = editingBpm_ ? static_cast<int>(std::round(currentBpm_)) : bpi_;
192192
if (newVal != existingVal)
193193
{
194194
jamwide::SendChatCommand cmd;

juce/ui/ConnectionBar.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,12 @@ void ConnectionBar::handleSyncClick()
603603
return;
604604
}
605605

606-
if (static_cast<int>(hostBpm) != static_cast<int>(serverBpm))
606+
if (static_cast<int>(std::round(hostBpm)) != static_cast<int>(std::round(serverBpm)))
607607
{
608608
// BPM mismatch -- show bubble per UI-SPEC
609-
juce::String msg = "Host tempo (" + juce::String(static_cast<int>(hostBpm))
609+
juce::String msg = "Host tempo (" + juce::String(static_cast<int>(std::round(hostBpm)))
610610
+ " BPM) does not match server ("
611-
+ juce::String(static_cast<int>(serverBpm)) + " BPM)";
611+
+ juce::String(static_cast<int>(std::round(serverBpm))) + " BPM)";
612612
syncMismatchBubble = std::make_unique<juce::BubbleMessageComponent>(3000);
613613
addChildComponent(syncMismatchBubble.get()); // MUST come before showAt (review fix)
614614
syncMismatchBubble->showAt(&syncButton,

src/build_number.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#pragma once
2-
#define JAMWIDE_BUILD_NUMBER 316
2+
#define JAMWIDE_BUILD_NUMBER 317

0 commit comments

Comments
 (0)