-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsPanel.cpp
More file actions
174 lines (147 loc) · 7.38 KB
/
SettingsPanel.cpp
File metadata and controls
174 lines (147 loc) · 7.38 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "SettingsPanel.h"
SettingsPanel::SettingsPanel(WaveformRendering& waveformRenderingArg) : wf(waveformRenderingArg) {
addAndMakeVisible(appName);
addAndMakeVisible(closeButton);
addAndMakeVisible(setRecordingsLocationButton);
addAndMakeVisible(recordingsButtonAssistLabel);
addAndMakeVisible(themeComboBox);
addAndMakeVisible(zoomComboBox);
addAndMakeVisible(durationComboBox);
addAndMakeVisible(formatComboBox);
addAndMakeVisible(sampleRateComboBox);
appState = ServiceLocator::getService<AppState>();
// Add ComboBox change listeners
durationComboBox.onChange = [this]() {
int selectedId = durationComboBox.getSelectedId();
appState->setDuration(selectedId);
// Get the BigBuffer from ServiceLocator and resize it
auto bigBuffer = ServiceLocator::getService<BigBuffer>();
if (bigBuffer != nullptr) {
// Map combo box IDs to BufferSizesSeconds enum values
BufferSizesSeconds seconds;
switch (selectedId) {
case 1: seconds = BufferSizesSeconds::tenSeconds; break;
case 2: seconds = BufferSizesSeconds::thirtySeconds; break;
case 3: seconds = BufferSizesSeconds::oneMinute; break;
case 4: seconds = BufferSizesSeconds::fiveMinutes; break;
case 5: seconds = BufferSizesSeconds::tenMinutes; break;
case 6: seconds = BufferSizesSeconds::thirtyMinutes; break;
case 7: seconds = BufferSizesSeconds::oneHour; break;
default: seconds = BufferSizesSeconds::tenSeconds; break;
}
std::cout << "Resizing BigBuffer to " << (int)seconds << " seconds" << std::endl;
bigBuffer->resizeSeconds(seconds);
}
this->wf.deleteButtonClicked();
};
formatComboBox.onChange = [this]() {
int selectedId = formatComboBox.getSelectedId();
int formatValue = selectedId - 1; // Convert from 1-based ID to 0-based enum
std::cout << "Format ComboBox changed to ID: " << selectedId <<
" (format value: " << formatValue << ")" << std::endl;
appState->setFormat(formatValue);
};
sampleRateComboBox.onChange = [this]() {
int sampleRate = 44100; // Default
switch (sampleRateComboBox.getSelectedId()) {
case 1: sampleRate = 44100; break;
case 2: sampleRate = 48000; break;
case 3: sampleRate = 96000; break;
}
appState->setSampleRate(sampleRate);
};
// Initialize ComboBoxes with proper values from AppState
durationComboBox.addItem("10s", 1);
durationComboBox.addItem("30s", 2);
durationComboBox.addItem("1m", 3);
durationComboBox.addItem("5m", 4);
durationComboBox.addItem("10m", 5);
durationComboBox.addItem("30m", 6);
durationComboBox.addItem("1h", 7);
int savedDuration = appState->getDuration();
durationComboBox.setSelectedId(savedDuration);
// Also set the BigBuffer size on initialization
auto bigBuffer = ServiceLocator::getService<BigBuffer>();
if (bigBuffer != nullptr) {
BufferSizesSeconds seconds;
switch (savedDuration) {
case 1: seconds = BufferSizesSeconds::tenSeconds; break;
case 2: seconds = BufferSizesSeconds::thirtySeconds; break;
case 3: seconds = BufferSizesSeconds::oneMinute; break;
case 4: seconds = BufferSizesSeconds::fiveMinutes; break;
case 5: seconds = BufferSizesSeconds::tenMinutes; break;
case 6: seconds = BufferSizesSeconds::thirtyMinutes; break;
case 7: seconds = BufferSizesSeconds::oneHour; break;
default: seconds = BufferSizesSeconds::tenSeconds; break;
}
std::cout << "Initializing BigBuffer to " << (int)seconds << " seconds" << std::endl;
bigBuffer->resizeSeconds(seconds);
}
// Add format options - make sure IDs match enum values + 1
formatComboBox.addItem("WAV", Format::WAV + 1);
formatComboBox.addItem("MP3", Format::MP3 + 1);
formatComboBox.addItem("FLAC", Format::FLAC + 1);
formatComboBox.addItem("OGG", Format::OGG + 1);
// Set format selection based on the current state, with clearer debugging
int savedFormat = appState->getFormat();
int comboBoxId = savedFormat + 1; // ComboBox IDs are 1-based, our enum is 0-based
std::cout << "Setting format ComboBox to ID: " << comboBoxId << " (format value: " << savedFormat << ")" << std::endl;
formatComboBox.setSelectedItemIndex(savedFormat, juce::sendNotificationSync);
sampleRateComboBox.addItem("44.1 kHz", 1);
sampleRateComboBox.addItem("48 kHz", 2);
sampleRateComboBox.addItem("96 kHz", 3);
sampleRateComboBox.setSelectedItemIndex(0); // Default to 44.1kHz
addAndMakeVisible(themeLabel);
addAndMakeVisible(zoomLabel);
addAndMakeVisible(durationLabel);
addAndMakeVisible(formatLabel);
addAndMakeVisible(sampleRateLabel);
closeButton.setLookAndFeel(&snagLAF);
setRecordingsLocationButton.setLookAndFeel(&snagLAF);
themeComboBox.setLookAndFeel(&snagLAF);
zoomComboBox.setLookAndFeel(&snagLAF);
durationComboBox.setLookAndFeel(&snagLAF);
formatComboBox.setLookAndFeel(&snagLAF);
sampleRateComboBox.setLookAndFeel(&snagLAF);
// Add close button callback
closeButton.onClick = [this]() {
if (onClose != nullptr) {
onClose();
}
};
// Add callback for the recordings location button
setRecordingsLocationButton.onClick = [this]() {
// Create a directory chooser dialog
this->chooser = std::make_unique<juce::FileChooser>("Select a directory for recordings",
juce::File::getSpecialLocation(juce::File::userHomeDirectory),
"",
true);
std::cout << "Launching file chooser for recordings location..." << std::endl;
// Use the correct method to browse for directories
// The true parameter in the options enables directory selection
auto chooserFlags = juce::FileBrowserComponent::openMode |
juce::FileBrowserComponent::canSelectDirectories;
this->chooser->launchAsync(chooserFlags, [this](const juce::FileChooser& fc) {
if (fc.getResult().exists() && fc.getResult().isDirectory()) {
juce::String newLocation = fc.getResult().getFullPathName();
appState->setRecordingsLocation(newLocation);
updateRecordingsLocationLabel();
}
});
};
auto baseTextFont = snagLAF.dmSansFont->withHeight(20.0f);
auto headerFont = snagLAF.staatlichesFont->withHeight(20.0f);
appName.setFont(snagLAF.staatlichesFont->withHeight(70.0f));
appName.setJustificationType(juce::Justification::topLeft);
themeLabel.setFont(headerFont);
zoomLabel.setFont(headerFont);
durationLabel.setFont(headerFont);
formatLabel.setFont(headerFont);
sampleRateLabel.setFont(headerFont);
recordingsButtonAssistLabel.setFont(snagLAF.dmSansFont->withHeight(16.0f));
recordingsButtonAssistLabel.setMultiLine(true);
recordingsButtonAssistLabel.setReadOnly(true);
recordingsButtonAssistLabel.setLookAndFeel(&snagLAF);
// Update label with current location
updateRecordingsLocationLabel();
}