Skip to content

Commit

Permalink
adopt C++20 std::ssize to avoid some signed/unsigned mismatches
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiapoirier committed Apr 2, 2023
1 parent e79e54f commit 6cb3e4d
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 41 deletions.
3 changes: 1 addition & 2 deletions bufferoverride/gui/bufferoverrideeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,8 @@ void BufferOverrideEditor::OpenEditor()
pos.set(0, GetHeight() - 64, GetWidth(), 64);
emplaceControl<DGNullControl>(this, pos)->setBackgroundColor(backgroundColor);

auto const appendixY = kHelpDisplayY + (kHelpDisplayHeight * mHelpDisplays.size()) + kHelpDisplayLineSpacing;
auto const appendixY = kHelpDisplayY + (kHelpDisplayHeight * std::ssize(mHelpDisplays)) + kHelpDisplayLineSpacing;
constexpr int spacingX = 16;
auto const valueFont = CreateVstGuiFont(kValueDisplayFontSize, kValueDisplayFont);

pos.set(spacingX, appendixY, kDryWetSliderWidth, kSliderHeight);
auto const minibufferPortionSlider = emplaceControl<DGRangeSlider>(this, kMinibufferPortionRandomMin, kMinibufferPortion, pos, sliderHandleImage, sliderHandleImage, GetBackgroundImage(), DGRangeSlider::PushStyle::Upper);
Expand Down
2 changes: 1 addition & 1 deletion dfx-library/dfxplugin-audiounit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ OSStatus DfxPlugin::SaveState(CFPropertyListRef* outData)
// create a CF data storage thingy filled with our special data
auto const cfData = dfx::MakeUniqueCFType(CFDataCreate(kCFAllocatorDefault,
reinterpret_cast<const UInt8*>(dfxData.data()),
static_cast<CFIndex>(dfxData.size())));
std::ssize(dfxData)));
if (cfData)
{
// put the CF data storage thingy into the dfx-data section of the CF dictionary
Expand Down
4 changes: 2 additions & 2 deletions dfx-library/dfxplugin-vst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ void DfxPlugin::processReplacing(float** inputs, float** outputs, VstInt32 sampl
}
else
{
assert(mInputOutOfPlaceAudioBuffers.front().size() >= static_cast<size_t>(sampleFrames));
assert(std::ssize(mInputOutOfPlaceAudioBuffers.front()) >= sampleFrames);
std::copy_n(inputs[ch], dfx::math::ToUnsigned(sampleFrames), mInputOutOfPlaceAudioBuffers[ch].data());
}
}
Expand All @@ -548,7 +548,7 @@ void DfxPlugin::processReplacing(float** inputs, float** outputs, VstInt32 sampl
{
if (ch == 0)
{
assert(mAsymmetricalInputAudioBuffer.size() >= static_cast<size_t>(sampleFrames));
assert(std::ssize(mAsymmetricalInputAudioBuffer) >= sampleFrames);
std::copy_n(mInputAudioStreams[ch], dfx::math::ToUnsigned(sampleFrames), mAsymmetricalInputAudioBuffer.data());
}
inputAudio = std::span(mAsymmetricalInputAudioBuffer).subspan(0, dfx::math::ToUnsigned(sampleFrames));
Expand Down
12 changes: 6 additions & 6 deletions exemplar/exemplar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ DFX_CORE_ENTRY(ExemplarDSP);
PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)
: DfxPlugin(inInstance, NUM_PARAMS, NUM_PRESETS) {

initparameter_indexed(P_BUFSIZE, {"wsize"}, 9, 9, BUFFERSIZESSIZE, kDfxParamUnit_samples);
initparameter_indexed(P_BUFSIZE, {"wsize"}, 9, 9, std::ssize(buffersizes), kDfxParamUnit_samples);
initparameter_indexed(P_SHAPE, {"wshape"}, WINDOW_TRIANGLE, WINDOW_TRIANGLE, MAX_WINDOWSHAPES);

initparameter_indexed(P_MODE, {"mode"}, MODE_CAPTURE, MODE_CAPTURE, NUM_MODES);
Expand All @@ -65,12 +65,12 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)

/* set up values for windowing */
std::array<char, 64> bufstr {};
for (long i=0; i < BUFFERSIZESSIZE; i++) {
for (size_t i=0; i < buffersizes.size(); i++) {
if (buffersizes[i] > 1000)
std::snprintf(bufstr.data(), bufstr.size(), "%ld,%03ld", buffersizes[i]/1000, buffersizes[i]%1000);
else
std::snprintf(bufstr.data(), bufstr.size(), "%ld", buffersizes[i]);
setparametervaluestring(P_BUFSIZE, i, bufstr.data());
setparametervaluestring(P_BUFSIZE, static_cast<long>(i), bufstr.data());
}

setparametervaluestring(P_SHAPE, WINDOW_TRIANGLE, "linear");
Expand All @@ -80,7 +80,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)
for (int i=NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++)
setparametervaluestring(P_SHAPE, i, "???");

auto const delay_samples = dfx::math::ToUnsigned(buffersizes[getparameter_i(P_BUFSIZE)]);
auto const delay_samples = dfx::math::ToUnsigned(buffersizes.at(getparameter_i(P_BUFSIZE)));
setlatency_samples(delay_samples);
settailsize_samples(delay_samples);

Expand All @@ -99,7 +99,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)
PLUGINCORE::PLUGINCORE(DfxPlugin& inInstance)
: DfxPluginCore(inInstance) {
/* determine the size of the largest window size */
constexpr auto maxframe = *std::max_element(std::cbegin(buffersizes), std::cend(buffersizes));
constexpr auto maxframe = *std::max_element(buffersizes.cbegin(), buffersizes.cend());

/* add some leeway? */
in0.assign(maxframe, 0.f);
Expand All @@ -117,7 +117,7 @@ PLUGINCORE::PLUGINCORE(DfxPlugin& inInstance)

void PLUGINCORE::reset() {

framesize = buffersizes[getparameter_i(P_BUFSIZE)];
framesize = buffersizes.at(getparameter_i(P_BUFSIZE));
third = framesize / 2;
bufsize = third * 3;

Expand Down
8 changes: 4 additions & 4 deletions exemplar/exemplar.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*------------------------------------------------------------------------
Copyright (C) 2006-2022 Tom Murphy 7
Copyright (C) 2006-2023 Tom Murphy 7
This file is part of Exemplar.
Expand All @@ -24,6 +24,7 @@ DFX Exemplar, starring the Super Destroy FX Windowing System!
#pragma once

#include <algorithm>
#include <array>
#include <memory>
#include <vector>

Expand All @@ -35,11 +36,10 @@ DFX Exemplar, starring the Super Destroy FX Windowing System!
/* change these for your plugins */
#define PLUGIN Exemplar

static constexpr long buffersizes[] = {
static constexpr std::array buffersizes {
4, 8, 16, 32, 64, 128, 256, 512,
1024, 2048, 4096, 8192, 16384, 32768,
};
static constexpr long BUFFERSIZESSIZE = std::size(buffersizes);


// PLUGIN ## DSP
Expand Down Expand Up @@ -159,6 +159,6 @@ class PLUGINCORE final : public DfxPluginCore {
dfx::UniqueOpaqueType<rfftw_plan, rfftw_destroy_plan> plan, rplan;

/* result of ffts ( */
float fftr[*std::max_element(std::cbegin(buffersizes), std::cend(buffersizes))] {};
float fftr[*std::max_element(buffersizes.cbegin(), buffersizes.cend())] {};

};
2 changes: 1 addition & 1 deletion geometer/geometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DFX_CORE_ENTRY(PLUGINCORE)
PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)
: DfxPlugin(inInstance, NUM_PARAMS, NUM_PRESETS) {

initparameter_list(P_BUFSIZE, {"wsize", "WSiz"}, 9, 9, BUFFERSIZESSIZE, DfxParam::Unit::Samples);
initparameter_list(P_BUFSIZE, {"wsize", "WSiz"}, 9, 9, std::ssize(buffersizes), DfxParam::Unit::Samples);
initparameter_list(P_SHAPE, {"wshape", "WShp"}, WINDOW_TRIANGLE, WINDOW_TRIANGLE, MAX_WINDOWSHAPES);

initparameter_list(P_POINTSTYLE, {"points where", "PntWher", "PWhere", "PWhr"}, POINT_EXTNCROSS, POINT_EXTNCROSS, MAX_POINTSTYLES);
Expand Down
8 changes: 3 additions & 5 deletions geometer/geometer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*------------------------------------------------------------------------
Copyright (C) 2002-2022 Tom Murphy 7 and Sophia Poirier
Copyright (C) 2002-2023 Tom Murphy 7 and Sophia Poirier
This file is part of Geometer.
Expand Down Expand Up @@ -39,12 +39,10 @@ Geometer, starring the Super Destroy FX Windowing System!

class PLUGIN final : public DfxPlugin {
public:
static constexpr long BUFFERSIZESSIZE = 14;

static constexpr std::array<int, BUFFERSIZESSIZE> buffersizes {{
static constexpr std::array buffersizes {
4, 8, 16, 32, 64, 128, 256, 512,
1024, 2048, 4096, 8192, 16384, 32768,
}};
};

explicit PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance);

Expand Down
2 changes: 1 addition & 1 deletion rmsbuddy/rmsbuddy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ OSStatus RMSBuddy::GetProperty(AudioUnitPropertyID inPropertyID, AudioUnitScope
if (parameterValue <= mMinMeterValueDb)
{
constexpr UniChar minusInfinity[] = { '-', 0x221E };
return CFStringCreateWithCharacters(kCFAllocatorDefault, minusInfinity, std::size(minusInfinity));
return CFStringCreateWithCharacters(kCFAllocatorDefault, minusInfinity, std::ssize(minusInfinity));
}
return nullptr;
}();
Expand Down
12 changes: 6 additions & 6 deletions slowft/slowft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ DFX_CORE_ENTRY(SlowftDSP);
PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)
: DfxPlugin(inInstance, NUM_PARAMS, NUM_PRESETS) {

initparameter_indexed(P_BUFSIZE, {"wsize"}, 9, 9, BUFFERSIZESSIZE, kDfxParamUnit_samples);
initparameter_indexed(P_BUFSIZE, {"wsize"}, 9, 9, std::ssize(buffersizes), kDfxParamUnit_samples);
initparameter_indexed(P_SHAPE, {"wshape"}, WINDOW_TRIANGLE, WINDOW_TRIANGLE, MAX_WINDOWSHAPES);

/* set up values for windowing */
std::array<char, 64> bufstr {};
for (long i = 0; i < BUFFERSIZESSIZE; i++) {
for (size_t i = 0; i < buffersizes.size(); i++) {
if (buffersizes[i] > 1000)
std::snprintf(bufstr.data(), bufstr.size(), "%ld,%03ld", buffersizes[i]/1000, buffersizes[i]%1000);
else
std::snprintf(bufstr.data(), bufstr.size(), "%ld", buffersizes[i]);
setparametervaluestring(P_BUFSIZE, i, bufstr.data());
setparametervaluestring(P_BUFSIZE, static_cast<long>(i), bufstr.data());
}

setparametervaluestring(P_SHAPE, WINDOW_TRIANGLE, "linear");
Expand All @@ -57,7 +57,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)
for (int i = NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++)
setparametervaluestring(P_SHAPE, i, "???");

auto const delay_samples = dfx::math::ToUnsigned(buffersizes[getparameter_i(P_BUFSIZE)]);
auto const delay_samples = dfx::math::ToUnsigned(buffersizes.at(getparameter_i(P_BUFSIZE)));
setlatency_samples(delay_samples);
settailsize_samples(delay_samples);

Expand All @@ -76,7 +76,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)
PLUGINCORE::PLUGINCORE(DfxPlugin& inInstance)
: DfxPluginCore(inInstance) {
/* determine the size of the largest window size */
constexpr auto maxframe = *std::max_element(std::cbegin(buffersizes), std::cend(buffersizes));
constexpr auto maxframe = *std::max_element(buffersizes.cbegin(), buffersizes.cend());

/* add some leeway? */
in0.assign(maxframe, 0.f);
Expand All @@ -89,7 +89,7 @@ PLUGINCORE::PLUGINCORE(DfxPlugin& inInstance)

void PLUGINCORE::reset() {

framesize = buffersizes[getparameter_i(P_BUFSIZE)];
framesize = buffersizes.at(getparameter_i(P_BUFSIZE));
third = framesize / 2;
bufsize = third * 3;

Expand Down
6 changes: 3 additions & 3 deletions slowft/slowft.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*------------------------------------------------------------------------
Copyright (C) 2005-2022 Tom Murphy 7
Copyright (C) 2005-2023 Tom Murphy 7
This file is part of Slowft.
Expand All @@ -23,6 +23,7 @@ Slowft, starring the Super Destroy FX Windowing System!

#pragma once

#include <array>
#include <numbers>
#include <vector>

Expand All @@ -31,11 +32,10 @@ Slowft, starring the Super Destroy FX Windowing System!
/* change these for your plugins */
#define PLUGIN Slowft

static constexpr long buffersizes[] = {
static constexpr std::array buffersizes {
4, 8, 16, 32, 64, 128, 256, 512,
1024, 2048, 4096, 8192, 16384, 32768,
};
static constexpr long BUFFERSIZESSIZE = std::size(buffersizes);


#define PLUGINCORE SlowftDSP
Expand Down
2 changes: 1 addition & 1 deletion turntablist/turntablisteditor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ static auto DFX_CopyFileNameString(FSRef const& inFileRef)
if (inValue <= 0.0f)
{
constexpr UniChar minusInfinity[] = { '-', 0x221E, ' ', ' ', 'd', 'B' };
universalDisplayText.reset(CFStringCreateWithCharacters(cfAllocator, minusInfinity, std::size(minusInfinity)));
universalDisplayText.reset(CFStringCreateWithCharacters(cfAllocator, minusInfinity, std::ssize(minusInfinity)));
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions windowingstub/windowingstub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ DFX_CORE_ENTRY(WindowingstubDSP);
PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)
: DfxPlugin(inInstance, NUM_PARAMS, NUM_PRESETS) {

initparameter_indexed(P_BUFSIZE, {"wsize"}, 9, 9, BUFFERSIZESSIZE, kDfxParamUnit_samples);
initparameter_indexed(P_BUFSIZE, {"wsize"}, 9, 9, std::ssize(buffersizes), kDfxParamUnit_samples);
initparameter_indexed(P_SHAPE, {"wshape"}, WINDOW_TRIANGLE, WINDOW_TRIANGLE, MAX_WINDOWSHAPES);

/* set up values for windowing */
for (long i = 0; i < BUFFERSIZESSIZE; i++) {
for (size_t i = 0; i < buffersizes.size(); i++) {
std::array<char, 64> bufstr {};
if (buffersizes[i] > 1000)
std::snprintf(bufstr.data(), bufstr.size(), "%ld,%03ld", buffersizes[i] / 1000, buffersizes[i] % 1000);
else
std::snprintf(bufstr.data(), bufstr.size(), "%ld", buffersizes[i]);
setparametervaluestring(P_BUFSIZE, i, bufstr.data());
setparametervaluestring(P_BUFSIZE, static_cast<long>(i), bufstr.data());
}

setparametervaluestring(P_SHAPE, WINDOW_TRIANGLE, "linear");
Expand All @@ -60,7 +60,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)
for (int i = NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++)
setparametervaluestring(P_SHAPE, i, "???");

auto const delay_samples = dfx::math::ToUnsigned(buffersizes[getparameter_i(P_BUFSIZE)]);
auto const delay_samples = dfx::math::ToUnsigned(buffersizes.at(getparameter_i(P_BUFSIZE)));
setlatency_samples(delay_samples);
settailsize_samples(delay_samples);

Expand All @@ -79,7 +79,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)
PLUGINCORE::PLUGINCORE(DfxPlugin& inInstance)
: DfxPluginCore(inInstance) {
/* determine the size of the largest window size */
constexpr auto maxframe = *std::max_element(std::cbegin(buffersizes), std::cend(buffersizes));
constexpr auto maxframe = *std::max_element(buffersizes.cbegin(), buffersizes.cend());

/* add some leeway? */
in0.assign(maxframe, 0.f);
Expand All @@ -91,7 +91,7 @@ PLUGINCORE::PLUGINCORE(DfxPlugin& inInstance)

void PLUGINCORE::reset() {

framesize = buffersizes[getparameter_i(P_BUFSIZE)];
framesize = buffersizes.at(getparameter_i(P_BUFSIZE));
third = framesize / 2;
bufsize = third * 3;

Expand Down
6 changes: 3 additions & 3 deletions windowingstub/windowingstub.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*------------------------------------------------------------------------
Copyright (C) 2002-2022 Tom Murphy 7
Copyright (C) 2002-2023 Tom Murphy 7
This file is part of Windowingstub.
Expand All @@ -25,18 +25,18 @@ Windowingstub, starring the Super Destroy FX Windowing System!

#include "dfxplugin.h"

#include <array>
#include <vector>

/* change these for your plugins */
#define PLUGIN Windowingstub
#define PLUGINCORE WindowingstubDSP


static constexpr long buffersizes[] = {
static constexpr std::array buffersizes {
4, 8, 16, 32, 64, 128, 256, 512,
1024, 2048, 4096, 8192, 16384, 32768,
};
static constexpr long BUFFERSIZESSIZE = std::size(buffersizes);

/* the types of window shapes available for smoothity */
enum { WINDOW_TRIANGLE,
Expand Down

0 comments on commit 6cb3e4d

Please sign in to comment.