Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy readability-implicit-bool-conversion #3150

Open
wants to merge 5 commits into
base: community
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/deluge/deluge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ uint16_t batteryMV;
bool batteryLEDState = false;

void batteryLEDBlink() {
setOutputState(BATTERY_LED.port, BATTERY_LED.pin, batteryLEDState);
setOutputState(BATTERY_LED.port, BATTERY_LED.pin, static_cast<uint16_t>(batteryLEDState));
int32_t blinkPeriod = ((int32_t)batteryMV - 2630) * 3;
blinkPeriod = std::min(blinkPeriod, 500_i32);
blinkPeriod = std::max(blinkPeriod, 60_i32);
Expand Down Expand Up @@ -140,7 +140,7 @@ void inputRoutine() {

if (!ALLOW_SPAM_MODE) {
bool speakerOn = (!AudioEngine::headphonesPluggedIn && !outputPluggedInL && !outputPluggedInR);
setOutputState(SPEAKER_ENABLE.port, SPEAKER_ENABLE.pin, speakerOn);
setOutputState(SPEAKER_ENABLE.port, SPEAKER_ENABLE.pin, static_cast<uint16_t>(speakerOn));
}

AudioEngine::renderInStereo =
Expand Down Expand Up @@ -174,7 +174,7 @@ void inputRoutine() {
if (batteryMV > 2950) {
makeBattLEDSolid:
batteryCurrentRegion = 1;
setOutputState(BATTERY_LED.port, BATTERY_LED.pin, false);
setOutputState(BATTERY_LED.port, BATTERY_LED.pin, 0u);
uiTimerManager.unsetTimer(TimerName::BATT_LED_BLINK);
}
}
Expand All @@ -186,7 +186,7 @@ void inputRoutine() {

else if (batteryMV > 3300) {
batteryCurrentRegion = 2;
setOutputState(BATTERY_LED.port, BATTERY_LED.pin, true);
setOutputState(BATTERY_LED.port, BATTERY_LED.pin, 1u);
uiTimerManager.unsetTimer(TimerName::BATT_LED_BLINK);
}
}
Expand Down Expand Up @@ -238,7 +238,8 @@ bool isShortPress(uint32_t pressTime) {

bool readButtonsAndPads() {

if (!usbInitializationPeriodComplete && (int32_t)(AudioEngine::audioSampleTimer - timeUSBInitializationEnds) >= 0) {
if ((usbInitializationPeriodComplete == 0u)
&& (int32_t)(AudioEngine::audioSampleTimer - timeUSBInitializationEnds) >= 0) {
usbInitializationPeriodComplete = 1;
}

Expand Down Expand Up @@ -289,7 +290,7 @@ bool readButtonsAndPads() {
#endif

PIC::Response value{0};
bool anything = uartGetChar(UART_ITEM_PIC, (char*)&value);
bool anything = uartGetChar(UART_ITEM_PIC, (char*)&value) != 0u;
if (anything) {

if (value < PIC::kPadAndButtonMessagesEnd) {
Expand All @@ -304,13 +305,13 @@ bool readButtonsAndPads() {
* function that it should use the default velocity for the instrument
*/
result = matrixDriver.padAction(p.x, p.y, thisPadPressIsOn);
if (thisPadPressIsOn) {
if (thisPadPressIsOn != 0) {
Buttons::ignoreCurrentShiftForSticky();
}
}
else {
auto b = deluge::hid::Button(value);
result = Buttons::buttonAction(b, thisPadPressIsOn, sdRoutineLock);
result = Buttons::buttonAction(b, thisPadPressIsOn != 0, sdRoutineLock);
}

if (result == ActionResult::REMIND_ME_OUTSIDE_CARD_ROUTINE) {
Expand All @@ -322,7 +323,7 @@ bool readButtonsAndPads() {
}
}
else if (value == PIC::Response::NEXT_PAD_OFF) {
nextPadPressIsOn = false;
nextPadPressIsOn = 0;
}

// "No presses happening" message
Expand Down Expand Up @@ -408,7 +409,7 @@ void setUIForLoadedSong(Song* song) {
UI* newUI;
Clip* currentClip = song->getCurrentClip();
// If in a Clip-minder view
if (currentClip && song->inClipMinderViewOnLoad) {
if ((currentClip != nullptr) && song->inClipMinderViewOnLoad) {
if (currentClip->onAutomationClipView) {
newUI = &automationView;
}
Expand Down Expand Up @@ -619,7 +620,7 @@ void registerTasks() {
// true); addRepeatingTask(&(AudioEngine::routine), 0, 16 / 44100., 64 / 44100., true);
}
void mainLoop() {
while (1) {
while (true) {

uiTimerManager.routine();

Expand All @@ -633,7 +634,7 @@ void mainLoop() {

int32_t count = 0;
while (readButtonsAndPads() && count < 16) {
if (!(count & 3)) {
if ((count & 3) == 0) {
AudioEngine::routineWithClusterLoading(true); // -----------------------------------
}
count++;
Expand Down Expand Up @@ -727,7 +728,7 @@ extern "C" int32_t deluge_main(void) {

if (have_oled) {
// If OLED sharing SPI channel, have to manually control SSL pin.
setOutputState(SPI_SSL.port, SPI_SSL.pin, true);
setOutputState(SPI_SSL.port, SPI_SSL.pin, 1u);
setPinAsOutput(SPI_SSL.port, SPI_SSL.pin);

setupSPIInterrupts();
Expand Down Expand Up @@ -850,7 +851,7 @@ extern "C" int32_t deluge_main(void) {
// Ideally I'd like to repeatedly switch between host and peripheral mode anytime there's no USB connection.
// To do that, I'd really need to know at any point in time whether the user had just made a connection, just then,
// that hadn't fully initialized yet. I think I sorta have that for host, but not for peripheral yet.
if (!anythingInitiallyAttachedAsUSBHost) {
if (anythingInitiallyAttachedAsUSBHost == 0u) {
D_PRINTLN("switching from host to peripheral");
closeUSBHost();
openUSBPeripheral();
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/dsp/delay/delay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void Delay::setupWorkingState(Delay::State& workingState, uint32_t timePerIntern
// Set some stuff up that we need before we make some decisions
// BUG: we want to be able to reduce the 256 to 1, but for some reason, the
// patching engine spits out 112 even when this should be 0...
bool mightDoDelay = (workingState.delayFeedbackAmount >= 256 && (anySoundComingIn || repeatsUntilAbandon));
bool mightDoDelay = (workingState.delayFeedbackAmount >= 256 && (anySoundComingIn || (repeatsUntilAbandon != 0u)));

if (mightDoDelay) {

Expand Down Expand Up @@ -188,7 +188,7 @@ void Delay::hasWrapped() {
}

repeatsUntilAbandon--;
if (!repeatsUntilAbandon) {
if (repeatsUntilAbandon == 0u) {
// D_PRINTLN("discarding");
discardBuffers();
}
Expand Down
2 changes: 1 addition & 1 deletion src/deluge/dsp/dx/EngineMkI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ inline int32_t mkiSin(int32_t phase, uint16_t env) {
uint16_t expVal = sinLog(phase >> (22 - SINLOG_BITDEPTH)) + (env);
// int16_t expValShow = expVal;

const bool isSigned = expVal & NEGATIVE_BIT;
const bool isSigned = (expVal & NEGATIVE_BIT) != 0;
expVal &= ~NEGATIVE_BIT;

const uint16_t SINEXP_FILTER = 0x3FF;
Expand Down
8 changes: 4 additions & 4 deletions src/deluge/dsp/dx/dx7note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int32_t DxVoice::osc_freq(int logFreq_for_detune, int mode, int coarse, int fine
logfreq += detuneRatio * logFreq_for_detune * (detune - 7 + random_scaled);

logfreq += coarsemul[coarse & 31];
if (fine) {
if (fine != 0) {
// (1 << 24) / log(2)
logfreq += (int32_t)floor(24204406.323123 * log(1 + 0.01 * fine) + 0.5);
}
Expand Down Expand Up @@ -263,11 +263,11 @@ void DxVoice::init(DxPatch& newp, int midinote, int velocity) {
pitchenv_.set(pitchenv_p());

// TODO: in LFO sync mode it would be best with LFO per voice
if (patch[141]) {
if (patch[141] != 0u) {
newp.lfo_phase = (1U << 31) - 1;
}

if (patch[136]) {
if (patch[136] != 0u) {
oscSync();
}
else {
Expand Down Expand Up @@ -354,7 +354,7 @@ bool DxVoice::compute(int32_t* buf, int n, int base_pitch, const DxPatch* ctrls,
// int32_t gain = pow(2, 10 + level * (1.0 / (1 << 24)));

int mode = patch[off + 17];
if (mode)
if (mode != 0)
params[op].freq = Freqlut::lookup(basepitch_[op]);
else
params[op].freq = Freqlut::lookup(basepitch_[op] + pitch_mod);
Expand Down
2 changes: 1 addition & 1 deletion src/deluge/dsp/dx/dx7note.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DxPatch {

uint8_t params[156];
FmCore* core;
bool opSwitch(int op) const { return (params[155] >> op) & 1; }
bool opSwitch(int op) const { return ((((params[155] >> op) & 1) != 0) != 0) != 0; }
stellar-aria marked this conversation as resolved.
Show resolved Hide resolved
void setOpSwitch(int op, bool on) { params[155] = (params[155] & ~(1 << op)) | (on ? 1 : 0) * (1 << op); }
uint8_t engineMode;

Expand Down
2 changes: 1 addition & 1 deletion src/deluge/dsp/dx/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ DxVoice* DxEngine::solicitDxVoice() {
}
#endif
void* memory = allocMaxSpeed(sizeof(DxVoice));
if (!memory)
if (memory == nullptr)
return nullptr;

return new (memory) DxVoice();
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/dsp/dx/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void Env::init(const EnvParams& p, int ol, int rate_scaling) {

int32_t Env::getsample(const EnvParams& p, int n, int extra_rate) {
#ifdef ACCURATE_ENVELOPE
if (staticcount_) {
if (staticcount_ != 0) {
staticcount_ -= n;
if (staticcount_ <= 0) {
staticcount_ = 0;
Expand All @@ -61,7 +61,7 @@ int32_t Env::getsample(const EnvParams& p, int n, int extra_rate) {
#endif

if (ix_ < 3 || ((ix_ < 4) && !down_)) {
if (staticcount_) {
if (staticcount_ != 0) {
;
}
else if (rising_) {
Expand Down
2 changes: 1 addition & 1 deletion src/deluge/dsp/fft/fft_config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ne10_fft_r2c_cfg_int32_t getConfig(int32_t magnitude) {
if (magnitude > FFT_CONFIG_MAX_MAGNITUDE)
return NULL;

if (!configs[magnitude]) {
if (configs[magnitude] == nullptr) {
stellar-aria marked this conversation as resolved.
Show resolved Hide resolved
// Allocates and sets up. And we'll just never deallocate.
configs[magnitude] = ne10_fft_alloc_r2c_int32(1 << magnitude);
}
Expand Down
6 changes: 3 additions & 3 deletions src/deluge/dsp/granular/GranularProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ StereoSample GranularProcessor::processOneGrainSample(StereoSample* currentSampl
grains[i].counter <= (grains[i].length >> 1)
? grains[i].counter * grains[i].volScale
: grains[i].volScaleMax - (grains[i].counter - (grains[i].length >> 1)) * grains[i].volScale;
int32_t delta = grains[i].counter * (grains[i].rev == 1 ? -1 : 1);
int32_t delta = grains[i].counter * (static_cast<int>(grains[i].rev) == 1 ? -1 : 1);
if (grains[i].pitch != 1024) {
delta = ((delta * grains[i].pitch) >> 10);
}
Expand Down Expand Up @@ -303,7 +303,7 @@ GranularProcessor::GranularProcessor() {
void GranularProcessor::getBuffer() {
if (grainBuffer == nullptr) {
void* grainBufferMemory = GeneralMemoryAllocator::get().allocStealable(sizeof(GrainBuffer));
if (grainBufferMemory) {
if (grainBufferMemory != nullptr) {
grainBuffer = new (grainBufferMemory) GrainBuffer(this);
}
else {}
Expand Down Expand Up @@ -336,7 +336,7 @@ GranularProcessor::GranularProcessor(const GranularProcessor& other) {
getBuffer();
}
void GranularProcessor::startSkippingRendering() {
if (grainBuffer) {
if (grainBuffer != nullptr) {
grainBuffer->inUse = false;
}
}
Loading
Loading