-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginEditor.cpp
More file actions
78 lines (66 loc) · 2.74 KB
/
Copy pathPluginEditor.cpp
File metadata and controls
78 lines (66 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "PluginEditor.h"
#include "PluginProcessor.h"
struct EmptyAudioProcessorEditor::PluginConfig {
PluginConfig() {
juce::PropertiesFile::Options options{};
options.applicationName = JucePlugin_Name;
options.filenameSuffix = ".settings";
#if defined(JUCE_LINUX) || defined(JUCE_BSD)
options.folderName = "~/.config/" JucePlugin_Name;
#elif defined(JUCE_MAC) || defined(JUCE_IOS)
options.folderName = JucePlugin_Name;
#endif
options.osxLibrarySubFolder = "Application Support";
options.storageFormat = juce::PropertiesFile::storeAsXML;
config = std::make_unique<juce::PropertiesFile>(options);
}
std::unique_ptr<juce::PropertiesFile> config;
};
// -------------------- plugin editor --------------------
static_assert(std::is_base_of_v<juce::Component, PluginUi>, "PluginUi must inherit from juce::Component");
EmptyAudioProcessorEditor::EmptyAudioProcessorEditor(EmptyAudioProcessor& p)
: AudioProcessorEditor(&p)
, ui_(p) {
auto ui_bound = ui_.getLocalBounds();
if (ui_bound.isEmpty()) {
jassert("you must set an editor size" && false);
}
ui_width_ = ui_bound.getWidth();
ui_height_ = ui_bound.getHeight();
auto* props = plugin_config_->config.get();
if (props != nullptr) {
scale_ = static_cast<float>(props->getDoubleValue("scale", scale_));
setSize(static_cast<int>(static_cast<float>(ui_width_) * scale_),
static_cast<int>(static_cast<float>(ui_height_) * scale_));
}
else {
setSize(ui_width_, ui_height_);
}
setResizable(true, true);
getConstrainer()->setFixedAspectRatio(static_cast<float>(ui_width_) / static_cast<float>(ui_height_));
setResizeLimits(ui_width_, ui_height_, 9999, 9999);
addAndMakeVisible(ui_);
}
EmptyAudioProcessorEditor::~EmptyAudioProcessorEditor() {
}
//==============================================================================
void EmptyAudioProcessorEditor::paint(juce::Graphics& g) {
g.fillAll(ui::green_bg);
}
void EmptyAudioProcessorEditor::resized() {
scale_ = static_cast<float>(getWidth()) / static_cast<float>(ui_width_);
ui_.setTransform(juce::AffineTransform::scale(scale_, scale_));
if (auto* props = plugin_config_->config.get()) {
if (getWidth() > 0 && getHeight() > 0) {
props->setValue("scale", scale_);
}
}
}
void EmptyAudioProcessorEditor::SetNewSize(int width, int height) {
ui_width_ = width;
ui_height_ = height;
ui_.setSize(width, height);
getConstrainer()->setFixedAspectRatio(static_cast<float>(ui_width_) / static_cast<float>(ui_height_));
setSize(static_cast<int>(static_cast<float>(width) * scale_),
static_cast<int>(static_cast<float>(height) * scale_));
}