From 4bdda3a50c332b1d1107758a5ac916f751ce9b3a Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Thu, 28 Nov 2024 18:29:34 +0100 Subject: [PATCH] Cleaned up --- Source/Pd/MessageListener.h | 42 ++++++++++++++++++++++--------------- Source/PluginEditor.cpp | 16 +++++++------- Source/PluginEditor.h | 2 -- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/Source/Pd/MessageListener.h b/Source/Pd/MessageListener.h index 083317576..6a2b0b4fa 100644 --- a/Source/Pd/MessageListener.h +++ b/Source/Pd/MessageListener.h @@ -43,7 +43,14 @@ class ReuseAllocator { for (auto it = freeList.begin(); it != freeList.end(); ++it) { if (it->size >= bytes) { T* result = static_cast(it->ptr); - freeList.erase(it); + + it->size -= bytes; + if(it->size <= 0) { + freeList.erase(it); + } + else { + it->ptr = static_cast(it->ptr) + bytes; + } return result; } } @@ -59,11 +66,7 @@ class ReuseAllocator { void reserve(size_t n) { - for(int i = 0; i < n; i++) - { - // populate the freeList with n addresses - deallocate(allocate(1), 1); - } + deallocate(allocate(n), n); } void deallocate(T* p, size_t n) noexcept { @@ -71,6 +74,9 @@ class ReuseAllocator { // Push the memory back into the free list freeList.push_back({p, bytes}); + freedSize += bytes; + + // TODO: we need to actually free sometimes it, if we've allocated a lot } template @@ -101,7 +107,6 @@ class MessageDispatcher { PointerIntPair symbolAndSize; }; - static constexpr int StackSize = 1 << 20; using MessageStack = plf::stack>; using AtomStack = plf::stack>; @@ -117,11 +122,18 @@ class MessageDispatcher { public: MessageDispatcher() { - usedHashes.reserve(StackSize); - nullListeners.reserve(StackSize); + usedHashes.reserve(128); + nullListeners.reserve(128); + + messageAllocator.reserve(1<<19); + atomAllocator.reserve(1<<19); + + for(auto& buffer : buffers) + { + buffer.messages.reserve(1<<17); + buffer.atoms.reserve(1<<17); + } - messageAllocator.reserve(StackSize); - atomAllocator.reserve(StackSize); } static void enqueueMessage(void* instance, void* target, t_symbol* symbol, int argc, t_atom* argv) noexcept @@ -250,12 +262,8 @@ class MessageDispatcher { }), nullListeners.end()); - // Make sure they don't grow excessively large - if(frontBuffer.messages.capacity() > StackSize*2) - { - frontBuffer.messages.trim(); - frontBuffer.atoms.trim(); - } + frontBuffer.messages.trim(); + frontBuffer.atoms.trim(); } MessageBuffer& getBackBuffer() diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index c3b8a52ed..55b60a18a 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -100,11 +100,9 @@ PluginEditor::PluginEditor(PluginProcessor& p) welcomePanelSearchButton.setClickingTogglesState(false); welcomePanelSearchButton.onClick = [this]() { - if (isSearchToggledOn) { - isSearchToggledOn = false; + if (!welcomePanelSearchButton.getToggleState()) { welcomePanelSearchInput.setVisible(false); } else { - isSearchToggledOn = true; welcomePanelSearchInput.setVisible(true); welcomePanelSearchInput.grabKeyboardFocus(); welcomePanel->setSearchQuery(""); @@ -122,7 +120,7 @@ PluginEditor::PluginEditor(PluginProcessor& p) } if (welcomePanelSearchInput.getText().isEmpty()) { - isSearchToggledOn = false; + welcomePanelSearchButton.setToggleState(false, dontSendNotification); welcomePanelSearchInput.setVisible(false); } }; @@ -428,7 +426,7 @@ void PluginEditor::paint(Graphics& g) // This is easier than having to replicate the DnD highlight at the edge of the NVG window. if (welcomePanel->isVisible()) { g.setColour(findColour(PlugDataColour::panelBackgroundColourId)); - g.fillRect(workArea.withTrimmedTop(4)); + g.fillRect(workArea.withTrimmedTop(5).withTrimmedBottom(50)); } } @@ -446,15 +444,15 @@ void PluginEditor::paintOverChildren(Graphics& g) auto welcomePanelVisible = !getCurrentCanvas(); auto tabbarDepth = welcomePanelVisible ? toolbarHeight + 5.5f : toolbarHeight + 30.0f; + auto paletteRight = palettes->isVisible() ? (palettes->isExpanded() ? palettes->getRight() : 29.0f) : 0; + auto sidebarLeft = sidebar->isVisible() ? sidebar->getX() + 1.0f : getWidth(); g.setColour(findColour(PlugDataColour::toolbarOutlineColourId)); - if (palettes->isVisible()) - g.drawLine(palettes->isExpanded() ? palettes->getRight() : 29.0f, tabbarDepth, sidebar->getX() + 1.0f, tabbarDepth); + g.drawLine(paletteRight, tabbarDepth, sidebarLeft, tabbarDepth); // Draw extra lines in case tabbar is not visible. Otherwise some outlines will stop too soon if (!getCurrentCanvas()) { auto toolbarDepth = welcomePanelVisible ? toolbarHeight + 6 : toolbarHeight; - if (palettes->isVisible()) - g.drawLine(palettes->isExpanded() ? palettes->getRight() : 29.5f, toolbarDepth, palettes->isExpanded() ? palettes->getRight() : 29.5f, toolbarDepth + 30); + g.drawLine(paletteRight, toolbarDepth, paletteRight, toolbarDepth + 30); if (sidebar->isVisible()) g.drawLine(sidebar->getX() + 0.5f, toolbarDepth, sidebar->getX() + 0.5f, toolbarHeight + 30); } diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index fe6c087d2..08bf9218f 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -201,8 +201,6 @@ class PluginEditor final : public AudioProcessorEditor MainToolbarButton mainMenuButton, undoButton, redoButton, addObjectMenuButton, pluginModeButton, welcomePanelSearchButton; SettingsToolbarButton recentlyOpenedPanelSelector, libraryPanelSelector; ToolbarRadioButton editButton, runButton, presentButton; - - bool isSearchToggledOn = false; SearchEditor welcomePanelSearchInput;