Debian Codegraph @

src/dialogs/config/config_dsp.cpp

raw symbols SCIP
1 /* fre:ac - free audio converter
2 * Copyright (C) 2001-2022 Robert Kausch <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation, either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
10 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
11 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
12
13 #include <dialogs/config/config_dsp.h>
14 #include <dialogs/config/configcomponent.h>
15
16 #include <config.h>
17
18 using namespace BoCA::AS;
19
20 freac::ConfigureDSP::ConfigureDSP()
21 {
22 BoCA::Config *config = BoCA::Config::Get();
23 BoCA::I18n *i18n = BoCA::I18n::Get();
24
25 i18n->SetContext("Configuration::Processing");
26
27 enableProcessing = config->GetIntValue(Config::CategoryProcessingID, Config::ProcessingEnableProcessingID, Config::ProcessingEnableProcessingDefault);
28 processPlayback = config->GetIntValue(Config::CategoryProcessingID, Config::ProcessingProcessPlaybackID, Config::ProcessingProcessPlaybackDefault);
29
30 singleFileMode = config->GetIntValue(Config::CategoryProcessingID, Config::ProcessingSingleFileModeID, Config::ProcessingSingleFileModeDefault);
31
32 group_dsp = new GroupBox(i18n->TranslateString("Signal processing"), Point(7, 11), Size(552, 65));
33
34 check_enable = new CheckBox(i18n->TranslateString("Enable signal processing"), Point(10, 14), Size(532, 0), &enableProcessing);
35 check_enable->onAction.Connect(&ConfigureDSP::OnToggleProcessing, this);
36
37 check_playback = new CheckBox(i18n->TranslateString("Enable processing during playback"), Point(27, 37), Size(515, 0), &processPlayback);
38
39 group_dsp->Add(check_enable);
40 group_dsp->Add(check_playback);
41
42 Add(group_dsp);
43
44 group_components = new GroupBox(i18n->TranslateString("Components"), Point(7, 87), Size(552, 220));
45
46 text_available = new Text(i18n->AddColon(i18n->TranslateString("Available")), Point(10, 12));
47
48 list_available = new ListBox(Point(10, 32), Size(245, 148));
49 list_available->onSelectEntry.Connect(&ConfigureDSP::OnSelectAvailable, this);
50
51 btn_add = new Button(i18n->IsActiveLanguageRightToLeft() ? "<-" : "->", Point(263, 80), Size(26, 0));
52 btn_add->onAction.Connect(&ConfigureDSP::OnAddComponent, this);
53 btn_add->Deactivate();
54
55 btn_remove = new Button(i18n->IsActiveLanguageRightToLeft() ? "->" : "<-", Point(263, 110), Size(26, 0));
56 btn_remove->onAction.Connect(&ConfigureDSP::OnRemoveComponent, this);
57 btn_remove->Deactivate();
58
59 text_selected = new Text(i18n->AddColon(i18n->TranslateString("Selected")), Point(297, 12));
60
61 list_selected = new ListBox(Point(297, 32), Size(245, 148));
62 list_selected->onSelectEntry.Connect(&ConfigureDSP::OnSelectComponent, this);
63 list_selected->SetFlags(LF_ALLOWREORDER);
64
65 btn_configure = new Button(i18n->TranslateString("Configure component"), Point(382, 188), Size(160, 0));
66 btn_configure->onAction.Connect(&ConfigureDSP::OnConfigureComponent, this);
67 btn_configure->Deactivate();
68
69 btn_configure->SetWidth(Math::Max(80, btn_configure->GetUnscaledTextWidth() + 14));
70 btn_configure->SetX(542 - btn_configure->GetWidth());
71
72 group_components->Add(text_available);
73 group_components->Add(list_available);
74
75 group_components->Add(btn_add);
76 group_components->Add(btn_remove);
77
78 group_components->Add(text_selected);
79 group_components->Add(list_selected);
80
81 group_components->Add(btn_configure);
82
83 Add(group_components);
84
85 AddComponents();
86
87 group_single_file = new GroupBox(i18n->TranslateString("Conversion to a single output file"), Point(7, 319), Size(552, 65));
88
89 option_individual = new OptionBox(i18n->TranslateString("Process each track individually"), Point(10, 14), Size(532, 0), &singleFileMode, 0);
90 option_combined = new OptionBox(i18n->TranslateString("Treat the combined tracks like a single track"), Point(10, 37), Size(532, 0), &singleFileMode, 1);
91
92 group_single_file->Add(option_individual);
93 group_single_file->Add(option_combined);
94
95 Add(group_single_file);
96
97 OnToggleProcessing();
98
99 SetSize(Size(566, 391));
100 }
101
102 freac::ConfigureDSP::~ConfigureDSP()
103 {
104 DeleteObject(group_dsp);
105
106 DeleteObject(check_enable);
107 DeleteObject(check_playback);
108
109 DeleteObject(group_components);
110
111 DeleteObject(text_available);
112 DeleteObject(list_available);
113
114 DeleteObject(btn_add);
115 DeleteObject(btn_remove);
116
117 DeleteObject(text_selected);
118 DeleteObject(list_selected);
119
120 DeleteObject(btn_configure);
121
122 DeleteObject(group_single_file);
123
124 DeleteObject(option_individual);
125 DeleteObject(option_combined);
126 }
127
128 Void freac::ConfigureDSP::AddComponents()
129 {
130 BoCA::Config *config = BoCA::Config::Get();
131
132 Registry &boca = Registry::Get();
133 const Array<String> &dspIDs = config->GetStringValue(Config::CategoryProcessingID, Config::ProcessingComponentsID, Config::ProcessingComponentsDefault).Explode(",");
134
135 for (Int i = 0; i < boca.GetNumberOfComponents(); i++)
136 {
137 if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_DSP) continue;
138
139 list_available->AddEntry(boca.GetComponentName(i));
140 }
141
142 foreach (const String &dspID, dspIDs)
143 {
144 if (!boca.ComponentExists(dspID)) continue;
145
146 Int entryNumber = -1;
147
148 for (Int i = 0; i < boca.GetNumberOfComponents(); i++)
149 {
150 if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_DSP) continue;
151
152 entryNumber++;
153
154 if (boca.GetComponentID(i) != dspID) continue;
155
156 list_available->GetNthEntry(entryNumber)->SetHeight(0);
157 list_selected->AddEntry(boca.GetComponentName(i));
158
159 break;
160 }
161 }
162 }
163
164 String freac::ConfigureDSP::GetSelectedComponent() const
165 {
166 Registry &boca = Registry::Get();
167
168 for (Int i = 0; i < boca.GetNumberOfComponents(); i++)
169 {
170 if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_DSP) continue;
171
172 if (list_selected->GetSelectedEntry()->GetText() == boca.GetComponentName(i)) return boca.GetComponentID(i);
173 }
174
175 return NIL;
176 }
177
178 Void freac::ConfigureDSP::OnToggleProcessing()
179 {
180 if (enableProcessing)
181 {
182 check_playback->Activate();
183
184 group_components->Activate();
185 group_single_file->Activate();
186 }
187 else
188 {
189 check_playback->Deactivate();
190
191 group_components->Deactivate();
192 group_single_file->Deactivate();
193 }
194 }
195
196 Void freac::ConfigureDSP::OnSelectAvailable()
197 {
198 btn_add->Activate();
199 }
200
201 Void freac::ConfigureDSP::OnSelectComponent()
202 {
203 btn_remove->Activate();
204
205 Registry &boca = Registry::Get();
206 Component *component = boca.CreateComponentByID(GetSelectedComponent());
207
208 if (component != NIL)
209 {
210 if (component->GetConfigurationLayer() != NIL) btn_configure->Activate();
211 else btn_configure->Deactivate();
212
213 boca.DeleteComponent(component);
214 }
215 }
216
217 Void freac::ConfigureDSP::OnAddComponent()
218 {
219 Surface *surface = GetDrawSurface();
220 ListEntry *entry = list_available->GetSelectedEntry();
221
222 surface->StartPaint(Rect(list_available->GetRealPosition(), list_available->GetRealSize()));
223
224 entry->Deselect();
225 entry->SetHeight(0);
226
227 list_available->Paint(SP_PAINT);
228
229 surface->EndPaint();
230
231 list_selected->AddEntry(entry->GetText());
232
233 btn_add->Deactivate();
234 }
235
236 Void freac::ConfigureDSP::OnRemoveComponent()
237 {
238 Surface *surface = GetDrawSurface();
239 ListEntry *entry = list_selected->GetSelectedEntry();
240
241 surface->StartPaint(Rect(list_available->GetRealPosition(), list_available->GetRealSize()));
242
243 for (Int i = 0; i < list_available->Length(); i++)
244 {
245 ListEntry *nthEntry = list_available->GetNthEntry(i);
246
247 if (nthEntry->GetHeight() != 0) continue;
248 if (nthEntry->GetText() != entry->GetText()) continue;
249
250 nthEntry->SetHeight(16);
251
252 list_available->Paint(SP_PAINT);
253 }
254
255 surface->EndPaint();
256
257 list_selected->Remove(entry);
258
259 btn_remove->Deactivate();
260 btn_configure->Deactivate();
261 }
262
263 Void freac::ConfigureDSP::OnConfigureComponent()
264 {
265 Registry &boca = Registry::Get();
266 Component *component = boca.CreateComponentByID(GetSelectedComponent());
267
268 if (component != NIL)
269 {
270 ConfigComponentDialog(component).ShowDialog();
271
272 boca.DeleteComponent(component);
273 }
274 }
275
276 Int freac::ConfigureDSP::SaveSettings()
277 {
278 BoCA::Config *config = BoCA::Config::Get();
279
280 /* Save component list.
281 */
282 Registry &boca = Registry::Get();
283 String components;
284
285 for (Int i = 0; i < list_selected->Length(); i++)
286 {
287 String name = list_selected->GetNthEntry(i)->GetText();
288
289 for (Int i = 0; i < boca.GetNumberOfComponents(); i++)
290 {
291 if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_DSP) continue;
292 if (boca.GetComponentName(i) != name) continue;
293
294 components.Append(components.Length() > 0 ? "," : NIL).Append(boca.GetComponentID(i));
295 }
296 }
297
298 config->SetStringValue(Config::CategoryProcessingID, Config::ProcessingComponentsID, components);
299
300 /* Save other settings.
301 */
302 config->SetIntValue(Config::CategoryProcessingID, Config::ProcessingEnableProcessingID, enableProcessing);
303 config->SetIntValue(Config::CategoryProcessingID, Config::ProcessingProcessPlaybackID, processPlayback);
304
305 config->SetIntValue(Config::CategoryProcessingID, Config::ProcessingSingleFileModeID, singleFileMode);
306
307 return Success();
308 }