-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginEditor.cpp
More file actions
110 lines (91 loc) · 4.29 KB
/
PluginEditor.cpp
File metadata and controls
110 lines (91 loc) · 4.29 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <numeric>
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include "MovementIn.h"
//==============================================================================
EnvironmentalInstrumentsAudioProcessorEditor::EnvironmentalInstrumentsAudioProcessorEditor (EnvironmentalInstrumentsAudioProcessor& p)
: AudioProcessorEditor (&p),
processorRef (p),
lMovementIndicator([&]() { return processorRef.movementIn->getLeftJoyConData(); }),
rMovementIndicator([&]() { return processorRef.movementIn->getRightJoyConData(); })
{
// Set properties of the TextEditor
logDisplay.setMultiLine(true); // Allow multiple lines
logDisplay.setReadOnly(true); // Make it read-only so users cannot edit the log
logDisplay.setScrollbarsShown(true); // Show scrollbars if needed
logDisplay.setCaretVisible(false); // Hide the caret since it's read-only
logDisplay.setPopupMenuEnabled(false); // Disable the context menu
EnvironmentalInstrumentsAudioProcessor::UIState uiState = processorRef.getLockUiState();
// Set log display text
logDisplay.setText(uiState.logText);
addAndMakeVisible(logDisplay); // Add the TextEditor to the component hierarchy
leftJCIndicator.setText("L", juce::dontSendNotification);
leftJCIndicator.setJustificationType(juce::Justification::centred);
rightJCIndicator.setText("R", juce::dontSendNotification);
rightJCIndicator.setJustificationType(juce::Justification::centred);
// Set L and R connection indicators' colours
leftJCIndicator.setColour(
juce::Label::backgroundColourId,
uiState.lConnected ? juce::Colours::green : juce::Colours::red
);
rightJCIndicator.setColour(
juce::Label::backgroundColourId,
uiState.rConnected ? juce::Colours::green : juce::Colours::red
);
addAndMakeVisible(leftJCIndicator);
addAndMakeVisible(rightJCIndicator);
addAndMakeVisible(lMovementIndicator);
addAndMakeVisible(rMovementIndicator);
setSize (400, 300);
// Tell the Processor that I exist and release lock
processorRef.setEditor(this);
}
EnvironmentalInstrumentsAudioProcessorEditor::~EnvironmentalInstrumentsAudioProcessorEditor()
{
processorRef.destroyEditor();
}
void EnvironmentalInstrumentsAudioProcessorEditor::showJCConnectionStatus()
{
SafePointer<EnvironmentalInstrumentsAudioProcessorEditor> safeThis(this);
// Do all this in async call to make thread deferential
juce::MessageManager::callAsync([safeThis]() {
if (safeThis != nullptr) // Check if the editor still exists
{
auto& e = *safeThis;
EnvironmentalInstrumentsAudioProcessor::UIState uiState = e.processorRef.getUiState();
// Set L and R connection indicators' colours
e.leftJCIndicator.setColour(
juce::Label::backgroundColourId,
uiState.lConnected ? juce::Colours::green : juce::Colours::red
);
e.rightJCIndicator.setColour(
juce::Label::backgroundColourId,
uiState.rConnected ? juce::Colours::green : juce::Colours::red
);
e.leftJCIndicator.repaint();
e.rightJCIndicator.repaint();
}
});
}
void EnvironmentalInstrumentsAudioProcessorEditor::logMessage(const juce::String& message)
{
// Append the message to the TextEditor
logDisplay.moveCaretToEnd();
logDisplay.insertTextAtCaret(message + "\n");
}
//==============================================================================
void EnvironmentalInstrumentsAudioProcessorEditor::paint (juce::Graphics& g)
{
// (Our component is opaque, so we must completely fill the background with a solid colour)
g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId));
g.setColour (juce::Colours::white);
g.setFont (15.0f);
}
void EnvironmentalInstrumentsAudioProcessorEditor::resized()
{
logDisplay.setBounds(10, 40, getWidth() - 20, getHeight() - 50);
leftJCIndicator.setBounds(10, 10, 20, 20);
lMovementIndicator.setBounds(40, 10, 20, 20);
rightJCIndicator.setBounds(getWidth() - 30, 10, 20, 20);
rMovementIndicator.setBounds(getWidth() - 60, 10, 20, 20);
}