Skip to content

Commit e518b69

Browse files
committed
Apply C++ best practices
1 parent fd88a9c commit e518b69

File tree

143 files changed

+878
-950
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+878
-950
lines changed

Source/Canvas.cpp

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ class ObjectsResizer final : public Component
9292
addAndMakeVisible(border);
9393

9494
setBounds(selectedObjectBounds.expanded(tabMargin));
95-
};
95+
}
9696

97-
~ObjectsResizer()
97+
~ObjectsResizer() override
9898
{
9999
for (auto* obj : cnv->getSelectionOfType<Object>()) {
100100
obj->hideHandles(false);
@@ -567,6 +567,7 @@ void Canvas::updateFramebuffers(NVGcontext* nvg)
567567
if (zoom < 0.5f)
568568
decim = 12;
569569
break;
570+
default: break;
570571
}
571572

572573
auto const majorDotColour = canvasMarkingsColJuce.withAlpha(std::min(zoom * 0.8f, 1.0f));
@@ -892,6 +893,7 @@ void Canvas::settingsChanged(String const& name, var const& value)
892893
updateOverlays();
893894
break;
894895
}
896+
default: break;
895897
}
896898
}
897899

@@ -1111,7 +1113,7 @@ void Canvas::synchroniseSplitCanvas()
11111113
void Canvas::performSynchronise()
11121114
{
11131115
static bool alreadyFlushed = false;
1114-
bool needsFlush = !alreadyFlushed;
1116+
bool const needsFlush = !alreadyFlushed;
11151117
ScopedValueSetter<bool> flushGuard(alreadyFlushed, true);
11161118
// By flushing twice, we can make sure that any message sent before this point will be dequeued
11171119
if (needsFlush && !isGraph)
@@ -1126,10 +1128,8 @@ void Canvas::performSynchronise()
11261128

11271129
// Remove deleted objects
11281130
for (int n = objects.size() - 1; n >= 0; n--) {
1129-
auto* object = objects[n];
1130-
11311131
// If the object is showing it's initial editor, meaning no object was assigned yet, allow it to exist without pointing to an object
1132-
if (!object->getPointer() && !object->isInitialEditorShown()) {
1132+
if (auto* object = objects[n]; !object->getPointer() && !object->isInitialEditorShown()) {
11331133
setSelected(object, false, false);
11341134
objects.remove_at(n);
11351135
}
@@ -1173,7 +1173,7 @@ void Canvas::performSynchronise()
11731173

11741174
// Make sure objects have the same order
11751175
std::ranges::sort(objects,
1176-
[&pdObjects](Object* first, Object* second) mutable {
1176+
[&pdObjects](Object const* first, Object const* second) mutable {
11771177
return pdObjects.index_of(first->getPointer()) < pdObjects.index_of(second->getPointer());
11781178
});
11791179

@@ -1221,11 +1221,9 @@ void Canvas::performSynchronise()
12211221
if (it == connections.end()) {
12221222
connections.add(this, inlet, outlet, ptr);
12231223
} else {
1224-
auto& c = **it;
1225-
12261224
// This is necessary to make resorting a subpatchers iolets work
12271225
// And it can't hurt to check if the connection is valid anyway
1228-
if (c.inlet != inlet || c.outlet != outlet) {
1226+
if (auto& c = **it; c.inlet != inlet || c.outlet != outlet) {
12291227
int const idx = connections.index_of(*it);
12301228
connections.remove_one(*it);
12311229
connections.insert(idx, this, inlet, outlet, ptr);
@@ -1306,8 +1304,7 @@ void Canvas::shiftKeyChanged(bool const isHeld)
13061304
return;
13071305

13081306
t_outconnect* connection = nullptr;
1309-
auto selectedConnections = getSelectionOfType<Connection>();
1310-
if (selectedConnections.size() == 1) {
1307+
if (auto selectedConnections = getSelectionOfType<Connection>(); selectedConnections.size() == 1) {
13111308
connection = selectedConnections[0]->getPointer();
13121309
}
13131310

@@ -1428,10 +1425,8 @@ void Canvas::mouseDrag(MouseEvent const& e)
14281425
}
14291426
}
14301427

1431-
bool const objectIsBeingEdited = ObjectBase::isBeingEdited();
1432-
14331428
// Ignore on graphs or when locked
1434-
if ((isGraph || locked == var(true) || commandLocked == var(true)) && !objectIsBeingEdited) {
1429+
if ((isGraph || locked == var(true) || commandLocked == var(true)) && !ObjectBase::isBeingEdited()) {
14351430
bool hasToggled = false;
14361431

14371432
// Behaviour for dragging over toggles, bang and radiogroup to toggle them
@@ -1733,7 +1728,7 @@ void Canvas::focusLost(FocusChangeType cause)
17331728
});
17341729
}
17351730

1736-
void Canvas::dragAndDropPaste(String const& patchString, Point<int> mousePos, int const patchWidth, int const patchHeight, String const& name)
1731+
void Canvas::dragAndDropPaste(String const& patchString, Point<int> const mousePos, int const patchWidth, int const patchHeight, String const& name)
17371732
{
17381733
locked = false;
17391734
presentationMode = false;
@@ -2017,9 +2012,7 @@ void Canvas::cycleSelection()
20172012
return;
20182013
}
20192014
// Get the selected objects
2020-
auto selectedObjects = getSelectionOfType<Object>();
2021-
2022-
if (selectedObjects.size() == 1) {
2015+
if (auto selectedObjects = getSelectionOfType<Object>(); selectedObjects.size() == 1) {
20232016
// Find the index of the currently selected object
20242017
auto const currentIdx = objects.index_of(selectedObjects[0]);
20252018
setSelected(selectedObjects[0], false);
@@ -2032,9 +2025,7 @@ void Canvas::cycleSelection()
20322025
}
20332026

20342027
// Get the selected connections if no objects are selected
2035-
auto selectedConnections = getSelectionOfType<Connection>();
2036-
2037-
if (selectedConnections.size() == 1) {
2028+
if (auto selectedConnections = getSelectionOfType<Connection>(); selectedConnections.size() == 1) {
20382029
// Find the index of the currently selected connection
20392030
auto const currentIdx = connections.index_of(selectedConnections[0]);
20402031
setSelected(selectedConnections[0], false);
@@ -2237,8 +2228,7 @@ void Canvas::connectSelection()
22372228
}
22382229

22392230
t_outconnect* connection = nullptr;
2240-
auto selectedConnections = getSelectionOfType<Connection>();
2241-
if (selectedConnections.size() == 1) {
2231+
if (auto selectedConnections = getSelectionOfType<Connection>(); selectedConnections.size() == 1) {
22422232
connection = selectedConnections[0]->getPointer();
22432233
}
22442234

@@ -2316,7 +2306,7 @@ void Canvas::alignObjects(Align const alignment)
23162306
// get the bounding box of all selected objects
23172307
auto const selectedBounds = getBoundingBox(selectedObjects);
23182308

2319-
auto onMove = [this, selectedObjects](Point<int> position) {
2309+
auto onMove = [this, selectedObjects](Point<int> const position) {
23202310
// Calculate the bounding box of all selected objects
23212311
Rectangle<int> totalSize;
23222312

@@ -2389,7 +2379,7 @@ void Canvas::alignObjects(Align const alignment)
23892379
case Align::HDistribute: {
23902380
sortByXPos(selectedObjects);
23912381

2392-
auto onResize = [this, selectedObjects](Rectangle<int> newBounds) {
2382+
auto onResize = [this, selectedObjects](Rectangle<int> const newBounds) {
23932383
int totalObjectsWidth = 0;
23942384
for (auto const* obj : selectedObjects) {
23952385
totalObjectsWidth += obj->getBounds().getWidth() - Object::doubleMargin;
@@ -2419,7 +2409,7 @@ void Canvas::alignObjects(Align const alignment)
24192409
case Align::VDistribute: {
24202410
sortByYPos(selectedObjects);
24212411

2422-
auto onResize = [this, selectedObjects](Rectangle<int> newBounds) {
2412+
auto onResize = [this, selectedObjects](Rectangle<int> const newBounds) {
24232413
int totalObjectsHeight = 0;
24242414
for (auto const* obj : selectedObjects) {
24252415
totalObjectsHeight += obj->getBounds().getHeight() - Object::doubleMargin;
@@ -2516,7 +2506,7 @@ void Canvas::valueChanged(Value& v)
25162506
auto y2 = static_cast<float>(cnv->gl_screeny2);
25172507

25182508
char buf[MAXPDSTRING];
2519-
snprintf(buf, MAXPDSTRING - 1, ".x%lx", (unsigned long)cnv.get());
2509+
snprintf(buf, MAXPDSTRING - 1, ".x%lx", reinterpret_cast<unsigned long>(cnv.get()));
25202510
pd->sendMessage(buf, "setbounds", { x1, y1, x2, y2 });
25212511
}
25222512
repaint();
@@ -2529,7 +2519,7 @@ void Canvas::valueChanged(Value& v)
25292519
auto y2 = static_cast<float>(getValue<int>(patchHeight) + y1);
25302520

25312521
char buf[MAXPDSTRING];
2532-
snprintf(buf, MAXPDSTRING - 1, ".x%lx", (unsigned long)cnv.get());
2522+
snprintf(buf, MAXPDSTRING - 1, ".x%lx", reinterpret_cast<unsigned long>(cnv.get()));
25332523
pd->sendMessage(buf, "setbounds", { x1, y1, x2, y2 });
25342524
}
25352525
repaint();
@@ -2676,7 +2666,7 @@ bool Canvas::setPanDragMode(bool const shouldPan)
26762666
return false;
26772667
}
26782668

2679-
bool Canvas::isPointOutsidePluginArea(Point<int> point) const
2669+
bool Canvas::isPointOutsidePluginArea(Point<int> const point) const
26802670
{
26812671
auto const borderWidth = getValue<float>(patchWidth);
26822672
auto const borderHeight = getValue<float>(patchHeight);
@@ -2786,8 +2776,7 @@ void Canvas::receiveMessage(t_symbol* symbol, SmallArray<pd::Atom> const& atoms)
27862776
return;
27872777

27882778
if (atoms.size() >= 1) {
2789-
int const flag = atoms[0].getFloat();
2790-
if (flag % 2 == 0) {
2779+
if (int const flag = atoms[0].getFloat(); flag % 2 == 0) {
27912780
locked = true;
27922781
} else {
27932782
locked = false;
@@ -2812,6 +2801,7 @@ void Canvas::receiveMessage(t_symbol* symbol, SmallArray<pd::Atom> const& atoms)
28122801
synchroniseSplitCanvas();
28132802
break;
28142803
}
2804+
default: break;
28152805
}
28162806
}
28172807

Source/CanvasViewport.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@ using namespace gl;
2222

2323
#include "Utility/SettingsFile.h"
2424

25-
class Minimap : public Component
25+
class Minimap final : public Component
2626
, public Timer
2727
, public AsyncUpdater {
2828
public:
29-
Minimap(Canvas* canvas)
29+
explicit Minimap(Canvas* canvas)
3030
: cnv(canvas)
3131
{
3232
}
3333

3434
void handleAsyncUpdate() override
3535
{
36-
auto area = visibleArea / getValue<float>(cnv->zoomScale);
36+
auto const area = visibleArea / getValue<float>(cnv->zoomScale);
3737
bool renderMinimap = cnv->objects.not_empty();
38-
for (auto* obj : cnv->objects) {
38+
for (auto const* obj : cnv->objects) {
3939
if (obj->getBounds().intersects(area)) {
4040
renderMinimap = false;
4141
break;
4242
}
4343
}
4444

45-
auto showMinimap = SettingsFile::getInstance()->getProperty<int>("show_minimap");
45+
auto const showMinimap = SettingsFile::getInstance()->getProperty<int>("show_minimap");
4646
float fadedIn = 0.0f;
4747
float fadedOut = 0.0f;
4848
if (showMinimap == 1) {
@@ -71,7 +71,7 @@ class Minimap : public Component
7171
}
7272
}
7373

74-
void updateMinimap(Rectangle<int> area)
74+
void updateMinimap(Rectangle<int> const area)
7575
{
7676
if (isMouseDown || area.isEmpty())
7777
return;
@@ -91,8 +91,8 @@ class Minimap : public Component
9191

9292
auto const zoom = getValue<float>(cnv->zoomScale);
9393
b.viewBounds = cnv->viewport->getViewArea() / zoom;
94-
Rectangle<int> allObjectBounds = Rectangle<int>(cnv->canvasOrigin.x, cnv->canvasOrigin.y, b.viewBounds.getWidth(), b.viewBounds.getHeight());
95-
for (auto* object : cnv->objects) {
94+
auto allObjectBounds = Rectangle<int>(cnv->canvasOrigin.x, cnv->canvasOrigin.y, b.viewBounds.getWidth(), b.viewBounds.getHeight());
95+
for (auto const* object : cnv->objects) {
9696
allObjectBounds = allObjectBounds.getUnion(object->getBounds());
9797
}
9898

@@ -118,8 +118,8 @@ class Minimap : public Component
118118
float const x = cnv->viewport->getViewWidth() - (width + 10);
119119
float const y = cnv->viewport->getViewHeight() - (height + 10);
120120

121-
auto canvasBackground = cnv->findColour(PlugDataColour::canvasBackgroundColourId);
122-
auto mapBackground = canvasBackground.contrasting(0.5f);
121+
auto const canvasBackground = cnv->findColour(PlugDataColour::canvasBackgroundColourId);
122+
auto const mapBackground = canvasBackground.contrasting(0.5f);
123123

124124
// draw background
125125
nvgFillColor(nvg, NVGComponent::convertColour(mapBackground.withAlpha(0.4f)));
@@ -155,13 +155,13 @@ class Minimap : public Component
155155
downPosition = cnv->viewport->getViewPosition();
156156

157157
auto map = getMapBounds();
158-
auto realViewBounds = Rectangle<int>((map.offsetX + map.viewBounds.getX() - cnv->canvasOrigin.x) * map.scale, (map.offsetY + map.viewBounds.getY() - cnv->canvasOrigin.y) * map.scale, map.viewBounds.getWidth() * map.scale, map.viewBounds.getHeight() * map.scale);
158+
auto const realViewBounds = Rectangle<int>((map.offsetX + map.viewBounds.getX() - cnv->canvasOrigin.x) * map.scale, (map.offsetY + map.viewBounds.getY() - cnv->canvasOrigin.y) * map.scale, map.viewBounds.getWidth() * map.scale, map.viewBounds.getHeight() * map.scale);
159159
isMouseDown = realViewBounds.contains(e.getMouseDownPosition());
160160
}
161161

162162
void mouseUp(MouseEvent const& e) override
163163
{
164-
auto viewBounds = cnv->viewport->getViewArea();
164+
auto const viewBounds = cnv->viewport->getViewArea();
165165
downPosition = viewBounds.getPosition();
166166
isMouseDown = false;
167167
updateMinimap(viewBounds);
@@ -173,7 +173,7 @@ class Minimap : public Component
173173
auto map = getMapBounds();
174174

175175
if (isMouseDown) {
176-
cnv->viewport->setViewPosition(downPosition + (e.getOffsetFromDragStart() / map.scale));
176+
cnv->viewport->setViewPosition(downPosition + e.getOffsetFromDragStart() / map.scale);
177177
}
178178
}
179179

@@ -488,7 +488,7 @@ class CanvasViewport final : public Viewport
488488
addAndMakeVisible(vbar);
489489
addAndMakeVisible(hbar);
490490

491-
setCachedComponentImage(new NVGSurface::InvalidationListener(editor->nvgSurface, this, [this](){
491+
setCachedComponentImage(new NVGSurface::InvalidationListener(editor->nvgSurface, this, [this]{
492492
return editor->getTabComponent().getVisibleCanvases().contains(this->cnv);
493493
}));
494494

@@ -547,6 +547,7 @@ class CanvasViewport final : public Viewport
547547
lerpAnimation += animationSpeed;
548548
break;
549549
}
550+
default: break;
550551
}
551552
}
552553

Source/Components/Buttons.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void ToolbarRadioButton::mouseExit(MouseEvent const& e)
140140

141141

142142

143-
bool SmallIconButton::hitTest(int x, int y)
143+
bool SmallIconButton::hitTest(int const x, int const y)
144144
{
145145
if (getLocalBounds().reduced(2).contains(x, y))
146146
return true;
@@ -176,7 +176,7 @@ void SmallIconButton::paint(Graphics& g)
176176

177177
WidePanelButton::WidePanelButton(String const& icon, int const iconSize)
178178
: icon(icon)
179-
, iconSize(iconSize) { };
179+
, iconSize(iconSize) { }
180180

181181
void WidePanelButton::mouseEnter(MouseEvent const& e)
182182
{

Source/Components/Buttons.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MainToolbarButton final : public TextButton {
2222

2323
// On macOS, we need to make sure that dragging any of these buttons doesn't drag the whole titlebar
2424
#if JUCE_MAC
25-
~MainToolbarButton();
25+
~MainToolbarButton() override;
2626
void mouseEnter(MouseEvent const& e) override;
2727
void mouseExit(MouseEvent const& e) override;
2828
#endif
@@ -57,7 +57,7 @@ class WidePanelButton final : public TextButton {
5757
int iconSize;
5858

5959
public:
60-
explicit WidePanelButton(String const& icon, int const iconSize = 13);
60+
explicit WidePanelButton(String const& icon, int iconSize = 13);
6161

6262
void mouseEnter(MouseEvent const& e) override;
6363

Source/Components/ColourPicker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Eyedropper final : public Timer
5151
return false;
5252
}
5353

54-
void setROI(Image& image, Point<int> position)
54+
void setROI(Image const& image, Point<int> const position)
5555
{
5656
pixelImage = image.getClippedImage(Rectangle<int>(0, 0, 11, 11).withCentre(position)).rescaled(getWidth() - 8 * 2, getHeight() - 8 * 2, Graphics::ResamplingQuality::lowResamplingQuality);
5757
colour = image.getPixelAt(position.x, position.y);
@@ -212,7 +212,7 @@ class ColourPicker final : public Component {
212212
};
213213

214214
public:
215-
void show(PluginEditor* editorComponent, Component* topLevelComponent, bool const onlySendCallbackOnClose, Colour const currentColour, Rectangle<int> bounds, std::function<void(Colour)> const& colourCallback)
215+
void show(PluginEditor* editorComponent, Component* topLevelComponent, bool const onlySendCallbackOnClose, Colour const currentColour, Rectangle<int> const bounds, std::function<void(Colour)> const& colourCallback)
216216
{
217217
callback = colourCallback;
218218
onlyCallBackOnClose = onlySendCallbackOnClose;

Source/Components/ConnectionMessageDisplay.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ConnectionMessageDisplay final
4545
}
4646

4747
// Activate the current connection info display overlay, to hide give it a nullptr
48-
void setConnection(Connection* connection, Point<int> screenPosition = { 0, 0 })
48+
void setConnection(Connection* connection, Point<int> const screenPosition = { 0, 0 })
4949
{
5050
// multiple events can hide the display, so we don't need to do anything
5151
// if this object has already been set to null
@@ -123,7 +123,7 @@ class ConnectionMessageDisplay final
123123
for(int ch = 0; ch < numChannels; ch++)
124124
{
125125
auto* start = samples + (ch * numSamples + block * blockSize);
126-
auto* destination = output.data() + (ch * blockSize);
126+
auto* destination = output.data() + ch * blockSize;
127127
std::copy_n(start, blockSize, destination);
128128
}
129129
sampleQueue.try_enqueue(SignalBlock(std::move(output), numChannels, blockSize));

0 commit comments

Comments
 (0)