-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginEditor.cpp
More file actions
94 lines (79 loc) · 3.46 KB
/
Copy pathPluginEditor.cpp
File metadata and controls
94 lines (79 loc) · 3.46 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "PluginEditor.h"
#include "PluginProcessor.h"
#include "AboutComponent.h"
// =============================================================================
PluginEditor::PluginEditor (PluginProcessor& p) : AudioProcessorEditor (&p), processor (p)
{
// ---- Waterfall ----------------------------------------------------------
addAndMakeVisible (waterfall);
// ---- Toolbar buttons ----------------------------------------------------
addAndMakeVisible (liveButton);
addAndMakeVisible (fileButton);
addAndMakeVisible (aboutButton);
liveButton.setClickingTogglesState (false);
fileButton.setClickingTogglesState (false);
aboutButton.setClickingTogglesState (false);
liveButton.onClick = [this] { onLiveClicked (); };
fileButton.onClick = [this] { onFileClicked (); };
aboutButton.onClick = [] { AboutComponent::show (); };
// ---- Initial size -------------------------------------------------------
setSize (1024, 512 + kToolbarH);
setResizable (true, true);
setResizeLimits (512, 256 + kToolbarH, 2560, 1440 + kToolbarH);
// ---- Forward sample rate ------------------------------------------------
const double sr = p.getSampleRate ();
if (sr > 0.0)
waterfall.setSampleRate (sr);
}
PluginEditor::~PluginEditor ()
{
processor.unregisterEditor (this);
}
// =============================================================================
void PluginEditor::paint (juce::Graphics& g)
{
// The waterfall owns its own OpenGL surface and fills its bounds entirely.
// We only need to paint the toolbar strip.
g.fillAll (juce::Colour (0xff0a0a14)); // near-black navy, matches fog colour
}
void PluginEditor::resized ()
{
auto area = getLocalBounds ();
auto toolbar = area.removeFromTop (kToolbarH);
liveButton.setBounds (toolbar.removeFromLeft (80).reduced (4));
fileButton.setBounds (toolbar.removeFromLeft (120).reduced (4));
aboutButton.setBounds (toolbar.removeFromRight (36).reduced (4));
waterfall.setBounds (area);
}
// ---------------------------------------------------------------------------
void PluginEditor::parentHierarchyChanged ()
{
AudioProcessorEditor::parentHierarchyChanged ();
// Set the window icon once the component has a native peer.
// Works in standalone mode; most plugin hosts ignore setIcon().
if (auto* peer = getPeer ())
peer->setIcon (AboutComponent::createIcon (256));
}
// =============================================================================
void PluginEditor::onLiveClicked ()
{
waterfall.switchToLiveStream ();
liveButton.setEnabled (false);
fileButton.setEnabled (true);
}
void PluginEditor::onFileClicked ()
{
// Launch async so we never block the message thread waiting on the OS
// file dialog — JUCE requires the async overload in plugin contexts.
fileChooser.launchAsync (juce::FileBrowserComponent::openMode |
juce::FileBrowserComponent::canSelectFiles,
[this] (const juce::FileChooser& fc)
{
auto result = fc.getResult ();
if (result == juce::File{})
return; // user cancelled
waterfall.loadStaticFile (result);
liveButton.setEnabled (true);
fileButton.setEnabled (false);
});
}