Skip to content

Commit b64bcc9

Browse files
committed
Simplify and improve mechanism for recalling last plugin mode scale
1 parent 020089c commit b64bcc9

File tree

3 files changed

+31
-35
lines changed

3 files changed

+31
-35
lines changed

Source/Pd/Patch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class Patch final : public ReferenceCountedObject {
129129
bool closePatchOnDelete;
130130

131131
bool openInPluginMode = false;
132+
int pluginModeScale = 100;
132133
int splitViewIndex = 0;
133134
int windowIndex = 0;
134135

Source/PluginMode.h

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,15 @@ class PluginMode final : public Component
9191
scaleComboBox.setColour(ComboBox::backgroundColourId, findColour(PlugDataColour::toolbarHoverColourId).withAlpha(0.8f));
9292
scaleComboBox.onChange = [this] {
9393
auto const itemId = scaleComboBox.getSelectedId();
94+
if (itemId == 0) return;
9495
if (itemId == 8) {
9596
setKioskMode(true);
9697
return;
9798
}
9899
if (selectedItemId != itemId) {
99100
selectedItemId = itemId;
100101
setWidthAndHeight(pluginScales[itemId - 1].floatScale);
101-
pluginPreviousScale = pluginScales[itemId - 1].intScale;
102+
patchPtr->pluginModeScale = pluginScales[itemId - 1].intScale;
102103
}
103104
};
104105

@@ -112,8 +113,6 @@ class PluginMode final : public Component
112113

113114
~PluginMode() override
114115
{
115-
pluginModeScaleMap[patchPtr->getPointer().get()] = pluginPreviousScale;
116-
117116
if (pluginModeLnf) {
118117
editor->setLookAndFeel(editor->pd->lnf);
119118
editor->pd->lnf->setTheme(SettingsFile::getInstance()->getTheme(lastTheme));
@@ -131,15 +130,9 @@ class PluginMode final : public Component
131130
return;
132131
#endif
133132
// set scale to the last scale that was set for this patches plugin mode
134-
// if none was set, use 100% scale
135-
if (pluginModeScaleMap.contains(patchPtr->getPointer().get())) {
136-
int const previousScale = pluginModeScaleMap[patchPtr->getPointer().get()];
137-
scaleComboBox.setText(String(previousScale) + String("%"), dontSendNotification);
138-
setWidthAndHeight(previousScale * 0.01f);
139-
} else {
140-
scaleComboBox.setText(String(static_cast<int>(editor->pd->pluginModeScale * 100)) + String("%"), dontSendNotification);
141-
setWidthAndHeight(editor->pd->pluginModeScale);
142-
}
133+
int const previousScale = patchPtr->pluginModeScale;
134+
scaleComboBox.setText(String(previousScale) + String("%"), dontSendNotification);
135+
setWidthAndHeight(previousScale * 0.01f);
143136
}
144137

145138
void setWidthAndHeight(float const scale)
@@ -186,11 +179,11 @@ class PluginMode final : public Component
186179
}
187180
});
188181
}
189-
182+
190183
void render(NVGcontext* nvg, Rectangle<int> area)
191184
{
192185
NVGScopedState scopedState(nvg);
193-
float scale = editor->pd->pluginModeScale;
186+
auto const scale = pluginModeScale;
194187
#if !JUCE_IOS
195188
if(isWindowFullscreen())
196189
#endif
@@ -207,6 +200,8 @@ class PluginMode final : public Component
207200

208201
void closePluginMode()
209202
{
203+
isClosing = true;
204+
210205
auto const constrainedNewBounds = windowBounds.withWidth(std::max(windowBounds.getWidth(), 890)).withHeight(std::max(windowBounds.getHeight(), 650));
211206
if (auto* mainWindow = dynamic_cast<PlugDataWindow*>(editor->getTopLevelComponent())) {
212207
editor->constrainer.setSizeLimits(890, 650, 99000, 99000);
@@ -226,6 +221,7 @@ class PluginMode final : public Component
226221

227222
cnv->patch.openInPluginMode = false;
228223
editor->getTabComponent().updateNow();
224+
isClosing = false;
229225
}
230226

231227
bool isWindowFullscreen() const
@@ -271,6 +267,8 @@ class PluginMode final : public Component
271267

272268
void resized() override
273269
{
270+
if(isClosing) return;
271+
274272
// Detect if the user exited fullscreen with the macOS's fullscreen button
275273
#if JUCE_MAC
276274
if (ProjectInfo::isStandalone && isWindowFullscreen() && !desktopWindow->isFullScreen()) {
@@ -285,7 +283,7 @@ class PluginMode final : public Component
285283
float const scaleY = static_cast<float>(getHeight()) / height;
286284
float scale = jmin(scaleX, scaleY);
287285

288-
editor->pd->pluginModeScale = scale;
286+
pluginModeScale = scale;
289287
scaleComboBox.setVisible(false);
290288
editorButton->setVisible(true);
291289

@@ -318,7 +316,7 @@ class PluginMode final : public Component
318316
int const x = (getWidth() - scaledWidth) / 2;
319317
int const y = (getHeight() - scaledHeight) / 2;
320318

321-
editor->pd->pluginModeScale = scale;
319+
pluginModeScale = scale;
322320

323321
// Hide titlebar
324322
titleBar.setBounds(0, 0, 0, 0);
@@ -332,7 +330,7 @@ class PluginMode final : public Component
332330
cnv->setBounds(-b.getX() + x / scale, -b.getY() + y / scale, b.getWidth() + b.getX(), b.getHeight() + b.getY());
333331
} else {
334332
float scale = getWidth() / width;
335-
editor->pd->pluginModeScale = scale;
333+
pluginModeScale = scale;
336334
scaleComboBox.setVisible(true);
337335
editorButton->setVisible(true);
338336

@@ -473,23 +471,22 @@ class PluginMode final : public Component
473471
int selectedItemId = 3; // default is 100% for now
474472

475473
WindowDragger windowDragger;
476-
bool isDraggingWindow = false;
477-
478-
bool isFullScreenKioskMode = false;
474+
bool isDraggingWindow:1 = false;
475+
bool isClosing:1 = false;
476+
bool isFullScreenKioskMode:1 = false;
479477

480478
Rectangle<int> originalPluginWindowBounds;
481479

482480
Rectangle<int> windowBounds;
483481
float const width = static_cast<float>(cnv->patchWidth.getValue()) + 1.0f;
484482
float const height = static_cast<float>(cnv->patchHeight.getValue()) + 1.0f;
485-
int pluginPreviousScale = 100;
483+
484+
float pluginModeScale = 1.0f;
486485

487486
String lastTheme;
488487

489488
std::unique_ptr<PlugDataLook> pluginModeLnf;
490489

491-
static inline UnorderedMap<t_canvas*, int> pluginModeScaleMap;
492-
493490
struct Scale {
494491
float floatScale;
495492
int intScale;

Source/PluginProcessor.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,9 +1036,10 @@ void PluginProcessor::getStateInformation(MemoryBlock& destData)
10361036
// Write new format
10371037
patchTree->setAttribute("Content", content);
10381038
patchTree->setAttribute("Location", patchFile);
1039-
patchTree->setAttribute("PluginMode", patch->openInPluginMode);
10401039
patchTree->setAttribute("SplitIndex", patch->splitViewIndex);
1041-
1040+
patchTree->setAttribute("PluginMode", patch->openInPluginMode);
1041+
patchTree->setAttribute("PluginModeScale", patch->pluginModeScale);
1042+
10421043
patchesTree->addChildElement(patchTree);
10431044
}
10441045
unlockAudioThread();
@@ -1056,8 +1057,7 @@ void PluginProcessor::getStateInformation(MemoryBlock& destData)
10561057
xml.setAttribute("Latency", getLatencySamples() - Instance::getBlockSize());
10571058
xml.setAttribute("TailLength", getValue<float>(tailLength));
10581059
xml.setAttribute("Legacy", false);
1059-
xml.setAttribute("PluginScale", pluginModeScale);
1060-
1060+
10611061
// TODO: make multi-window friendly
10621062
if (auto const* editor = getActiveEditor()) {
10631063
xml.setAttribute("Width", editor->getWidth());
@@ -1143,7 +1143,7 @@ void PluginProcessor::setStateInformation(void const* data, int const sizeInByte
11431143

11441144
std::unique_ptr<XmlElement> const xmlState(getXmlFromBinary(xmlData, xmlSize));
11451145

1146-
auto openPatch = [this](String const& content, File const& location, bool const pluginMode = false, int const splitIndex = 0) {
1146+
auto openPatch = [this](String const& content, File const& location, bool const pluginMode = false, int pluginModeScale = 100, int const splitIndex = 0) {
11471147
// CHANGED IN v0.9.0:
11481148
// We now prefer loading the patch content over the patch file, if possible
11491149
if (content.isNotEmpty()) {
@@ -1157,6 +1157,7 @@ void PluginProcessor::setStateInformation(void const* data, int const sizeInByte
11571157
auto const patchPtr = loadPatch(content);
11581158
patchPtr->splitViewIndex = splitIndex;
11591159
patchPtr->openInPluginMode = pluginMode;
1160+
patchPtr->pluginModeScale = pluginModeScale;
11601161
if (!locationIsValid || location.getParentDirectory() == File::getSpecialLocation(File::tempDirectory)) {
11611162
patchPtr->setUntitled();
11621163
} else {
@@ -1167,6 +1168,7 @@ void PluginProcessor::setStateInformation(void const* data, int const sizeInByte
11671168
auto const patchPtr = loadPatch(URL(location));
11681169
patchPtr->splitViewIndex = splitIndex;
11691170
patchPtr->openInPluginMode = pluginMode;
1171+
patchPtr->pluginModeScale = pluginModeScale;
11701172
}
11711173
};
11721174

@@ -1177,6 +1179,7 @@ void PluginProcessor::setStateInformation(void const* data, int const sizeInByte
11771179
auto content = p->getStringAttribute("Content");
11781180
auto location = p->getStringAttribute("Location");
11791181
auto const pluginMode = p->getBoolAttribute("PluginMode");
1182+
auto const pluginModeScale = p->getIntAttribute("PluginModeScale", 100);
11801183

11811184
int splitIndex = 0;
11821185
if (p->hasAttribute("SplitIndex")) {
@@ -1189,7 +1192,8 @@ void PluginProcessor::setStateInformation(void const* data, int const sizeInByte
11891192
auto patchesDir = ProjectInfo::appDataDir.getChildFile("Patches");
11901193
location = location.replace("${PATCHES_DIR}", patchesDir.getFullPathName());
11911194

1192-
openPatch(content, location, pluginMode, splitIndex);
1195+
openPatch(content, location, pluginMode, pluginModeScale, splitIndex);
1196+
11931197
}
11941198
}
11951199
// Otherwise, load from legacy format
@@ -1214,12 +1218,6 @@ void PluginProcessor::setStateInformation(void const* data, int const sizeInByte
12141218
setOversampling(xmlState->getDoubleAttribute("Oversampling"));
12151219
setLatencySamples(xmlState->getDoubleAttribute("Latency") + Instance::getBlockSize());
12161220
tailLength = xmlState->getDoubleAttribute("TailLength");
1217-
#if !JUCE_IOS
1218-
if(!ProjectInfo::isStandalone && xmlState->hasAttribute("PluginScale"))
1219-
{
1220-
pluginModeScale = std::clamp(xmlState->getDoubleAttribute("PluginScale"), 0.5, 2.0);
1221-
}
1222-
#endif
12231221
}
12241222

12251223
if (xmlState->hasAttribute("Version")) {

0 commit comments

Comments
 (0)