Skip to content

Commit c299f4b

Browse files
committed
More message listener improvements
1 parent 6110f6b commit c299f4b

File tree

8 files changed

+2251
-54
lines changed

8 files changed

+2251
-54
lines changed

Libraries/plf_stack

Submodule plf_stack deleted from a9cdfff

Source/NVGSurface.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ void NVGSurface::invalidateArea(Rectangle<int> area)
305305

306306
void NVGSurface::render()
307307
{
308+
// Flush message queue before rendering, to make sure all GUIs are up-to-date
309+
editor->pd->flushMessageQueue();
310+
308311
if (renderThroughImage) {
309312
auto startTime = Time::getMillisecondCounter();
310313
if (startTime - lastRenderTime < 32) {

Source/Pd/MessageListener.h

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "Instance.h"
99
#include <readerwriterqueue.h>
10-
#include <plf_stack/plf_stack.h>
10+
#include "Utility/Stack.h"
1111

1212
namespace pd {
1313

@@ -32,7 +32,7 @@ class MessageDispatcher {
3232
PointerIntPair<t_symbol*, 2, uint8_t> symbolAndSize;
3333
};
3434

35-
static constexpr int StackSize = 1 << 21;
35+
static constexpr int StackSize = 1 << 20;
3636
using MessageStack = plf::stack<Message>;
3737
using AtomStack = plf::stack<t_atom>;
3838

@@ -47,13 +47,12 @@ class MessageDispatcher {
4747
{
4848
usedHashes.reserve(StackSize);
4949
nullListeners.reserve(StackSize);
50-
51-
buffers[0].messages.reserve(StackSize);
52-
buffers[0].atoms.reserve(StackSize);
53-
buffers[1].messages.reserve(StackSize);
54-
buffers[1].atoms.reserve(StackSize);
55-
buffers[2].messages.reserve(StackSize);
56-
buffers[2].atoms.reserve(StackSize);
50+
51+
for(auto& buffer : buffers)
52+
{
53+
buffer.messages.reserve(StackSize);
54+
buffer.atoms.reserve(StackSize);
55+
}
5756
}
5857

5958
static void enqueueMessage(void* instance, void* target, t_symbol* symbol, int argc, t_atom* argv) noexcept
@@ -63,10 +62,10 @@ class MessageDispatcher {
6362
if (ProjectInfo::isStandalone || EXPECT_LIKELY(!dispatcher->block)) {
6463
auto size = std::min(argc, 15);
6564
auto& backBuffer = dispatcher->getBackBuffer();
65+
backBuffer.messages.push({ PointerIntPair<void*, 2, uint8_t>(target, (size >> 2) & 0b11), PointerIntPair<t_symbol*, 2, uint8_t>(symbol, size & 0b11) });
66+
6667
for (int i = 0; i < size; i++)
6768
backBuffer.atoms.push(argv[i]);
68-
69-
backBuffer.messages.push({ PointerIntPair<void*, 2, uint8_t>(target, (size >> 2) & 0b11), PointerIntPair<t_symbol*, 2, uint8_t>(symbol, size & 0b11) });
7069
}
7170
}
7271

@@ -78,12 +77,11 @@ class MessageDispatcher {
7877
// If we're blocking messages from now on, also clear out the queue
7978
if (blockMessages) {
8079
sys_lock();
81-
buffers[0].messages.clear();
82-
buffers[0].atoms.clear();
83-
buffers[1].messages.clear();
84-
buffers[1].atoms.clear();
85-
buffers[2].messages.clear();
86-
buffers[2].atoms.clear();
80+
for(auto& buffer : buffers)
81+
{
82+
buffer.messages.clear();
83+
buffer.atoms.clear();
84+
}
8785
sys_unlock();
8886
}
8987
}
@@ -186,21 +184,15 @@ class MessageDispatcher {
186184
// Make sure they don't grow excessively large
187185
if(frontBuffer.messages.capacity() > StackSize*2)
188186
{
189-
frontBuffer.messages.shrink_to_fit();
190-
frontBuffer.messages.reserve(StackSize);
191-
}
192-
if(frontBuffer.atoms.capacity() > StackSize*2)
193-
{
194-
frontBuffer.atoms.shrink_to_fit();
195-
frontBuffer.atoms.reserve(StackSize);
187+
frontBuffer.messages.trim();
188+
frontBuffer.atoms.trim();
196189
}
197190
}
198191

199192
MessageBuffer& getBackBuffer()
200193
{
201194
return buffers[currentBuffer.load()];
202195
}
203-
204196

205197
MessageBuffer& getFrontBuffer()
206198
{

Source/PluginEditor.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ PluginEditor::PluginEditor(PluginProcessor& p)
250250
addChildComponent(*palettes);
251251
addAndMakeVisible(*statusbar);
252252

253-
addAndMakeVisible(*sidebar);
253+
addChildComponent(*sidebar);
254254
sidebar->toBehind(statusbar.get());
255255
addAndMakeVisible(tabComponent);
256256

@@ -271,7 +271,7 @@ PluginEditor::PluginEditor(PluginProcessor& p)
271271
&pluginModeButton,
272272
#endif
273273
}) {
274-
addAndMakeVisible(button);
274+
addChildComponent(button);
275275
}
276276

277277
// Show settings
@@ -285,18 +285,18 @@ PluginEditor::PluginEditor(PluginProcessor& p)
285285
// Undo button
286286
undoButton.isUndo = true;
287287
undoButton.onClick = [this]() { getCurrentCanvas()->undo(); };
288-
addAndMakeVisible(undoButton);
288+
addChildComponent(undoButton);
289289

290290
// Redo button
291291
redoButton.isRedo = true;
292292
redoButton.onClick = [this]() { getCurrentCanvas()->redo(); };
293-
addAndMakeVisible(redoButton);
293+
addChildComponent(redoButton);
294294

295295
// New object button
296296
addObjectMenuButton.setButtonText(Icons::AddObject);
297297
addObjectMenuButton.setTooltip("Add object");
298298
addObjectMenuButton.onClick = [this]() { Dialogs::showObjectMenu(this, &addObjectMenuButton); };
299-
addAndMakeVisible(addObjectMenuButton);
299+
addChildComponent(addObjectMenuButton);
300300

301301
recentlyOpenedPanelSelector.setClickingTogglesState(true);
302302
libraryPanelSelector.setClickingTogglesState(true);
@@ -334,7 +334,7 @@ PluginEditor::PluginEditor(PluginProcessor& p)
334334

335335
button->setClickingTogglesState(true);
336336
button->setRadioGroupId(hash("edit_run_present"));
337-
addAndMakeVisible(button);
337+
addChildComponent(button);
338338
}
339339
editButton.setToggleState(true, sendNotification);
340340

@@ -357,7 +357,12 @@ PluginEditor::PluginEditor(PluginProcessor& p)
357357

358358
sidebar->setSize(250, pd->lastUIHeight - statusbar->getHeight());
359359

360-
setSize(pd->lastUIWidth, pd->lastUIHeight);
360+
if(ProjectInfo::isStandalone) {
361+
setSize(pd->lastUIWidth, pd->lastUIHeight);
362+
}
363+
else {
364+
setSize(850, 650);
365+
}
361366

362367
sidebar->toFront(false);
363368

@@ -586,6 +591,7 @@ void PluginEditor::showWelcomePanel(bool shouldShow)
586591
if(shouldShow)
587592
{
588593
welcomePanel->show();
594+
sidebar->showSidebar(true);
589595
}
590596
else {
591597
welcomePanel->hide();

Source/PluginProcessor.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ PluginProcessor::PluginProcessor()
176176
settingsFile->startChangeListener();
177177

178178
sendMessagesFromQueue();
179-
startTimerHz(60);
179+
180180
}
181181

182182
PluginProcessor::~PluginProcessor()
@@ -187,18 +187,10 @@ PluginProcessor::~PluginProcessor()
187187
patchesLock.exit();
188188
}
189189

190-
// Flushes Pd message listener messages from the queue
191-
void PluginProcessor::timerCallback()
190+
void PluginProcessor::flushMessageQueue()
192191
{
193-
if(canDequeueMessages) {
194-
canDequeueMessages = false;
195-
setThis();
196-
messageDispatcher->dequeueMessages();
197-
startTimerHz(60);
198-
}
199-
else {
200-
startTimerHz(120);
201-
}
192+
setThis();
193+
messageDispatcher->dequeueMessages();
202194
}
203195

204196
void PluginProcessor::initialiseFilesystem()
@@ -782,7 +774,6 @@ void PluginProcessor::processConstant(dsp::AudioBlock<float> buffer, MidiBuffer&
782774
// Process audio
783775
performDSP(audioVectorIn.data(), audioVectorOut.data());
784776

785-
canDequeueMessages = true;
786777
sendMessagesFromQueue();
787778

788779
if (connectionListener && plugdata_debugging_enabled())
@@ -837,7 +828,6 @@ void PluginProcessor::processVariable(dsp::AudioBlock<float> buffer, MidiBuffer&
837828
// Process audio
838829
performDSP(audioVectorIn.data(), audioVectorOut.data());
839830

840-
canDequeueMessages = true;
841831
sendMessagesFromQueue();
842832

843833
if (connectionListener && plugdata_debugging_enabled())

Source/PluginProcessor.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ class ConnectionMessageDisplay;
3333
class Object;
3434
class PluginProcessor final : public AudioProcessor
3535
, public pd::Instance
36-
, public SettingsFileListener
37-
, public Timer
38-
{
36+
, public SettingsFileListener {
3937
public:
4038
PluginProcessor();
4139

@@ -49,10 +47,10 @@ class PluginProcessor final : public AudioProcessor
4947
void prepareToPlay(double sampleRate, int samplesPerBlock) override;
5048
void numChannelsChanged() override;
5149
void releaseResources() override;
52-
50+
5351
void updateAllEditorsLNF();
5452

55-
void timerCallback() override;
53+
void flushMessageQueue();
5654

5755
#ifndef JucePlugin_PreferredChannelConfigurations
5856
bool isBusesLayoutSupported(BusesLayout const& layouts) const override;
@@ -193,8 +191,7 @@ class PluginProcessor final : public AudioProcessor
193191
SmoothedValue<float, ValueSmoothingTypes::Linear> smoothedGain;
194192

195193
AtomicValue<int> audioAdvancement = 0;
196-
AtomicValue<bool> canDequeueMessages = false;
197-
194+
198195
bool variableBlockSize = false;
199196
AudioBuffer<float> audioBufferIn;
200197
AudioBuffer<float> audioBufferOut;

Source/Statusbar.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ void Statusbar::setWelcomePanelShown(bool isShowing)
14581458
audioSettingsButton.setVisible(!isShowing);
14591459
sidebarExpandButton.setVisible(isShowing);
14601460
helpButton.setVisible(isShowing);
1461+
if(!isShowing) sidebarExpandButton.setToggleState(false, dontSendNotification);
14611462
}
14621463

14631464

0 commit comments

Comments
 (0)