Skip to content

Commit 4bdda3a

Browse files
committed
Cleaned up
1 parent d0f5160 commit 4bdda3a

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

Source/Pd/MessageListener.h

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ class ReuseAllocator {
4343
for (auto it = freeList.begin(); it != freeList.end(); ++it) {
4444
if (it->size >= bytes) {
4545
T* result = static_cast<T*>(it->ptr);
46-
freeList.erase(it);
46+
47+
it->size -= bytes;
48+
if(it->size <= 0) {
49+
freeList.erase(it);
50+
}
51+
else {
52+
it->ptr = static_cast<char*>(it->ptr) + bytes;
53+
}
4754
return result;
4855
}
4956
}
@@ -59,18 +66,17 @@ class ReuseAllocator {
5966

6067
void reserve(size_t n)
6168
{
62-
for(int i = 0; i < n; i++)
63-
{
64-
// populate the freeList with n addresses
65-
deallocate(allocate(1), 1);
66-
}
69+
deallocate(allocate(n), n);
6770
}
6871

6972
void deallocate(T* p, size_t n) noexcept {
7073
size_t bytes = n * sizeof(T);
7174

7275
// Push the memory back into the free list
7376
freeList.push_back({p, bytes});
77+
freedSize += bytes;
78+
79+
// TODO: we need to actually free sometimes it, if we've allocated a lot
7480
}
7581

7682
template <typename U>
@@ -101,7 +107,6 @@ class MessageDispatcher {
101107
PointerIntPair<t_symbol*, 2, uint8_t> symbolAndSize;
102108
};
103109

104-
static constexpr int StackSize = 1 << 20;
105110
using MessageStack = plf::stack<Message, ReuseAllocator<Message>>;
106111
using AtomStack = plf::stack<t_atom, ReuseAllocator<t_atom>>;
107112

@@ -117,11 +122,18 @@ class MessageDispatcher {
117122
public:
118123
MessageDispatcher()
119124
{
120-
usedHashes.reserve(StackSize);
121-
nullListeners.reserve(StackSize);
125+
usedHashes.reserve(128);
126+
nullListeners.reserve(128);
127+
128+
messageAllocator.reserve(1<<19);
129+
atomAllocator.reserve(1<<19);
130+
131+
for(auto& buffer : buffers)
132+
{
133+
buffer.messages.reserve(1<<17);
134+
buffer.atoms.reserve(1<<17);
135+
}
122136

123-
messageAllocator.reserve(StackSize);
124-
atomAllocator.reserve(StackSize);
125137
}
126138

127139
static void enqueueMessage(void* instance, void* target, t_symbol* symbol, int argc, t_atom* argv) noexcept
@@ -250,12 +262,8 @@ class MessageDispatcher {
250262
}),
251263
nullListeners.end());
252264

253-
// Make sure they don't grow excessively large
254-
if(frontBuffer.messages.capacity() > StackSize*2)
255-
{
256-
frontBuffer.messages.trim();
257-
frontBuffer.atoms.trim();
258-
}
265+
frontBuffer.messages.trim();
266+
frontBuffer.atoms.trim();
259267
}
260268

261269
MessageBuffer& getBackBuffer()

Source/PluginEditor.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@ PluginEditor::PluginEditor(PluginProcessor& p)
100100

101101
welcomePanelSearchButton.setClickingTogglesState(false);
102102
welcomePanelSearchButton.onClick = [this]() {
103-
if (isSearchToggledOn) {
104-
isSearchToggledOn = false;
103+
if (!welcomePanelSearchButton.getToggleState()) {
105104
welcomePanelSearchInput.setVisible(false);
106105
} else {
107-
isSearchToggledOn = true;
108106
welcomePanelSearchInput.setVisible(true);
109107
welcomePanelSearchInput.grabKeyboardFocus();
110108
welcomePanel->setSearchQuery("");
@@ -122,7 +120,7 @@ PluginEditor::PluginEditor(PluginProcessor& p)
122120
}
123121

124122
if (welcomePanelSearchInput.getText().isEmpty()) {
125-
isSearchToggledOn = false;
123+
welcomePanelSearchButton.setToggleState(false, dontSendNotification);
126124
welcomePanelSearchInput.setVisible(false);
127125
}
128126
};
@@ -428,7 +426,7 @@ void PluginEditor::paint(Graphics& g)
428426
// This is easier than having to replicate the DnD highlight at the edge of the NVG window.
429427
if (welcomePanel->isVisible()) {
430428
g.setColour(findColour(PlugDataColour::panelBackgroundColourId));
431-
g.fillRect(workArea.withTrimmedTop(4));
429+
g.fillRect(workArea.withTrimmedTop(5).withTrimmedBottom(50));
432430
}
433431
}
434432

@@ -446,15 +444,15 @@ void PluginEditor::paintOverChildren(Graphics& g)
446444

447445
auto welcomePanelVisible = !getCurrentCanvas();
448446
auto tabbarDepth = welcomePanelVisible ? toolbarHeight + 5.5f : toolbarHeight + 30.0f;
447+
auto paletteRight = palettes->isVisible() ? (palettes->isExpanded() ? palettes->getRight() : 29.0f) : 0;
448+
auto sidebarLeft = sidebar->isVisible() ? sidebar->getX() + 1.0f : getWidth();
449449
g.setColour(findColour(PlugDataColour::toolbarOutlineColourId));
450-
if (palettes->isVisible())
451-
g.drawLine(palettes->isExpanded() ? palettes->getRight() : 29.0f, tabbarDepth, sidebar->getX() + 1.0f, tabbarDepth);
450+
g.drawLine(paletteRight, tabbarDepth, sidebarLeft, tabbarDepth);
452451

453452
// Draw extra lines in case tabbar is not visible. Otherwise some outlines will stop too soon
454453
if (!getCurrentCanvas()) {
455454
auto toolbarDepth = welcomePanelVisible ? toolbarHeight + 6 : toolbarHeight;
456-
if (palettes->isVisible())
457-
g.drawLine(palettes->isExpanded() ? palettes->getRight() : 29.5f, toolbarDepth, palettes->isExpanded() ? palettes->getRight() : 29.5f, toolbarDepth + 30);
455+
g.drawLine(paletteRight, toolbarDepth, paletteRight, toolbarDepth + 30);
458456
if (sidebar->isVisible())
459457
g.drawLine(sidebar->getX() + 0.5f, toolbarDepth, sidebar->getX() + 0.5f, toolbarHeight + 30);
460458
}

Source/PluginEditor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ class PluginEditor final : public AudioProcessorEditor
201201
MainToolbarButton mainMenuButton, undoButton, redoButton, addObjectMenuButton, pluginModeButton, welcomePanelSearchButton;
202202
SettingsToolbarButton recentlyOpenedPanelSelector, libraryPanelSelector;
203203
ToolbarRadioButton editButton, runButton, presentButton;
204-
205-
bool isSearchToggledOn = false;
206204

207205
SearchEditor welcomePanelSearchInput;
208206

0 commit comments

Comments
 (0)