Skip to content

Commit

Permalink
Cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Nov 28, 2024
1 parent d0f5160 commit 4bdda3a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
42 changes: 25 additions & 17 deletions Source/Pd/MessageListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ class ReuseAllocator {
for (auto it = freeList.begin(); it != freeList.end(); ++it) {
if (it->size >= bytes) {
T* result = static_cast<T*>(it->ptr);
freeList.erase(it);

it->size -= bytes;
if(it->size <= 0) {
freeList.erase(it);
}
else {
it->ptr = static_cast<char*>(it->ptr) + bytes;
}
return result;
}
}
Expand All @@ -59,18 +66,17 @@ 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 {
size_t bytes = n * sizeof(T);

// 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 <typename U>
Expand Down Expand Up @@ -101,7 +107,6 @@ class MessageDispatcher {
PointerIntPair<t_symbol*, 2, uint8_t> symbolAndSize;
};

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

Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 7 additions & 9 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand All @@ -122,7 +120,7 @@ PluginEditor::PluginEditor(PluginProcessor& p)
}

if (welcomePanelSearchInput.getText().isEmpty()) {
isSearchToggledOn = false;
welcomePanelSearchButton.setToggleState(false, dontSendNotification);
welcomePanelSearchInput.setVisible(false);
}
};
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 4bdda3a

Please sign in to comment.