Debian Codegraph @

components/decoder/cdrip/config.cpp

raw symbols SCIP
1 /* BoCA - BonkEnc Component Architecture
2 * Copyright (C) 2007-2024 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 <windows.h>
14
15 #include "config.h"
16
17 const String BoCA::ConfigureCDRip::ConfigID = "Ripper";
18
19 BoCA::ConfigureCDRip::ConfigureCDRip()
20 {
21 const Config *config = Config::Get();
22
23 Bool notificationAvailable = config->GetIntValue("Internal", "NotificationAvailable", False);
24
25 autoRead = notificationAvailable && config->GetIntValue(ConfigID, "AutoReadContents", True);
26 autoRip = notificationAvailable && config->GetIntValue(ConfigID, "AutoRip", False);
27
28 jitter = config->GetIntValue(ConfigID, "JitterCorrection", False);
29 swapchannels = config->GetIntValue(ConfigID, "SwapChannels", False);
30
31 autoEject = config->GetIntValue(ConfigID, "EjectAfterRipping", False);
32
33 readCDText = config->GetIntValue(ConfigID, "ReadCDText", True);
34 readCDPlayerIni = config->GetIntValue(ConfigID, "ReadCDPlayerIni", True);
35 readISRC = config->GetIntValue(ConfigID, "ReadISRC", False);
36
37 cdparanoia = config->GetIntValue(ConfigID, "CDParanoia", False);
38
39 I18n *i18n = I18n::Get();
40
41 i18n->SetContext("Ripper");
42
43 group_drive = new GroupBox(i18n->TranslateString("Active CD-ROM drive"), Point(7, 11), Size(354, 121));
44
45 combo_drive = new ComboBox(Point(10, 12), Size(334, 0));
46
47 AS::Registry &boca = AS::Registry::Get();
48 AS::DeviceInfoComponent *info = (AS::DeviceInfoComponent *) boca.CreateComponentByID("cdrip-info");
49
50 if (info != NIL)
51 {
52 if (info->GetNumberOfDevices() == 0) group_drive->Deactivate();
53
54 for (Int i = 0; i < info->GetNumberOfDevices(); i++)
55 {
56 const Device &device = info->GetNthDeviceInfo(i);
57 String deviceID = device.GetID();
58
59 combo_drive->AddEntry(device.GetName());
60
61 driveOffsetUsed.Add(config->GetIntValue(ConfigID, String("UseOffsetDrive-").Append(deviceID), 0));
62 driveOffsets.Add(config->GetIntValue(ConfigID, String("ReadOffsetDrive-").Append(deviceID), 0));
63 driveSpeeds.Add(config->GetIntValue(ConfigID, String("RippingSpeedDrive-").Append(deviceID), 0));
64 driveSpinUpTimes.Add(config->GetIntValue(ConfigID, String("SpinUpTimeDrive-").Append(deviceID), -5));
65 }
66
67 boca.DeleteComponent(info);
68 }
69
70 combo_drive->SelectNthEntry(config->GetIntValue(ConfigID, "ActiveDrive", 0));
71 combo_drive->onSelectEntry.Connect(&ConfigureCDRip::SelectDrive, this);
72
73 useoffset = driveOffsetUsed.GetNth(config->GetIntValue(ConfigID, "ActiveDrive", 0));
74 spinup = driveSpinUpTimes.GetNth(config->GetIntValue(ConfigID, "ActiveDrive", 0)) > 0;
75 setspeed = driveSpeeds.GetNth(config->GetIntValue(ConfigID, "ActiveDrive", 0));
76
77 check_speed = new CheckBox(i18n->AddColon(i18n->TranslateString("Set drive speed limit")), Point(10, 40), Size(162, 0), &setspeed);
78 check_speed->onAction.Connect(&ConfigureCDRip::ToggleSetSpeed, this);
79
80 check_spinup = new CheckBox(i18n->AddColon(i18n->TranslateString("Spin up before ripping")), Point(10, 67), Size(162, 0), &spinup);
81 check_spinup->onAction.Connect(&ConfigureCDRip::ToggleSpinUp, this);
82
83 check_offset = new CheckBox(i18n->AddColon(i18n->TranslateString("Use read offset")), Point(10, 94), Size(162, 0), &useoffset);
84 check_offset->onAction.Connect(&ConfigureCDRip::ToggleUseOffset, this);
85
86 Int maxTextSize = Math::Max(Math::Max(check_speed->GetUnscaledTextWidth(), check_spinup->GetUnscaledTextWidth()), check_offset->GetUnscaledTextWidth());
87
88 check_speed->SetWidth(maxTextSize + 21);
89 check_spinup->SetWidth(maxTextSize + 21);
90 check_offset->SetWidth(maxTextSize + 21);
91
92 combo_speed = new ComboBox(Point(39 + maxTextSize, 39), Size(305 - maxTextSize, 0));
93 combo_speed->onSelectEntry.Connect(&ConfigureCDRip::SelectSpeed, this);
94
95 for (Int i = 48; i > 0; i -= 4) combo_speed->AddEntry(String::FromInt(i).Append("x"));
96
97 text_spinup_seconds = new Text(i18n->TranslateString("%1 seconds").Replace("%1", "00"), Point(275, 69));
98 text_spinup_seconds->SetX(343 - text_spinup_seconds->GetUnscaledTextWidth());
99
100 slider_spinup = new Slider(Point(39 + maxTextSize, 67), Size(86, 0), OR_HORZ, NIL, 1, 30);
101 slider_spinup->SetWidth(335 - slider_spinup->GetX() - text_spinup_seconds->GetUnscaledTextWidth());
102 slider_spinup->onValueChange.Connect(&ConfigureCDRip::ChangeSpinUpTime, this);
103
104 edit_offset = new EditBox(Point(39 + maxTextSize, 93), Size(36, 0), 5);
105 edit_offset->SetFlags(EDB_NUMERIC);
106 edit_offset->onInput.Connect(&ConfigureCDRip::ChangeOffset, this);
107
108 text_offset_samples = new Text(i18n->TranslateString("samples"), Point(edit_offset->GetX() + edit_offset->GetWidth() + 8, 96));
109
110 SelectDrive();
111
112 group_drive->Add(combo_drive);
113 group_drive->Add(check_speed);
114 group_drive->Add(combo_speed);
115 group_drive->Add(check_spinup);
116 group_drive->Add(slider_spinup);
117 group_drive->Add(text_spinup_seconds);
118 group_drive->Add(check_offset);
119 group_drive->Add(edit_offset);
120 group_drive->Add(text_offset_samples);
121
122 group_cdinfo = new GroupBox(i18n->TranslateString("CD information"), Point(7, 144), Size(354, 65));
123
124 check_readCDText = new CheckBox(i18n->TranslateString("Read CD-Text"), Point(10, 11), Size(162, 0), &readCDText);
125 check_readCDPlayerIni = new CheckBox(i18n->TranslateString("Read cdplayer.ini"), Point(181, 11), Size(162, 0), &readCDPlayerIni);
126 check_readISRC = new CheckBox(i18n->TranslateString("Read ISRC when adding tracks to joblist"), Point(10, 37), Size(333, 0), &readISRC);
127
128 check_readCDText->SetWidth(Math::Max(162, check_readCDText->GetUnscaledTextWidth() + 21));
129 check_readCDPlayerIni->SetX(check_readCDText->GetWidth() + 19);
130 check_readCDPlayerIni->SetWidth(Math::Max(162, check_readCDPlayerIni->GetUnscaledTextWidth() + 21));
131 check_readISRC->SetWidth(Math::Max(333, check_readISRC->GetUnscaledTextWidth() + 21));
132
133 group_cdinfo->SetWidth(Math::Max(check_readCDText->GetWidth() + check_readCDPlayerIni->GetWidth() + 9, check_readISRC->GetWidth()) + 20);
134
135 group_cdinfo->Add(check_readCDText);
136 group_cdinfo->Add(check_readCDPlayerIni);
137 group_cdinfo->Add(check_readISRC);
138
139 group_ripping = new GroupBox(i18n->TranslateString("Ripper settings"), Point(7, 221), Size(354, 68));
140
141 check_paranoia = new CheckBox(i18n->AddColon(i18n->TranslateString("Activate cdparanoia mode")), Point(10, 14), Size(162, 0), &cdparanoia);
142 check_paranoia->onAction.Connect(&ConfigureCDRip::ToggleParanoia, this);
143
144 combo_paranoia_mode = new ComboBox(Point(181, 13), Size(162, 0));
145 combo_paranoia_mode->AddEntry(i18n->TranslateString("Overlap only"));
146 combo_paranoia_mode->AddEntry(i18n->TranslateString("No verify"));
147 combo_paranoia_mode->AddEntry(i18n->TranslateString("No scratch repair"));
148 combo_paranoia_mode->AddEntry(i18n->TranslateString("Full cdparanoia mode"));
149 combo_paranoia_mode->SelectNthEntry(config->GetIntValue(ConfigID, "CDParanoiaMode", 3));
150
151 ToggleParanoia();
152
153 check_jitter = new CheckBox(i18n->TranslateString("Activate jitter correction"), Point(10, 40), Size(162, 0), &jitter);
154 check_swapchannels = new CheckBox(i18n->TranslateString("Switch stereo channels"), Point(181, 40), Size(162, 0), &swapchannels);
155
156 maxTextSize = Math::Max(check_paranoia->GetUnscaledTextWidth(), check_jitter->GetUnscaledTextWidth());
157
158 check_paranoia->SetWidth(Math::Max(162, maxTextSize + 21));
159 check_jitter->SetWidth(check_paranoia->GetWidth());
160 combo_paranoia_mode->SetX(check_paranoia->GetWidth() + 19);
161 check_swapchannels->SetX(combo_paranoia_mode->GetX());
162 check_swapchannels->SetWidth(Math::Max(162, check_swapchannels->GetUnscaledTextWidth() + 21));
163
164 group_ripping->SetWidth(check_paranoia->GetWidth() + check_swapchannels->GetWidth() + 29);
165
166 group_ripping->Add(check_paranoia);
167 group_ripping->Add(combo_paranoia_mode);
168 group_ripping->Add(check_jitter);
169 group_ripping->Add(check_swapchannels);
170
171 group_drive->SetWidth(Math::Max(group_cdinfo->GetWidth(), group_ripping->GetWidth()));
172 group_cdinfo->SetWidth(group_drive->GetWidth());
173 group_ripping->SetWidth(group_drive->GetWidth());
174
175 combo_drive->SetWidth(group_drive->GetWidth() - 20);
176 combo_speed->SetWidth(group_drive->GetWidth() - check_speed->GetWidth() - 28);
177 slider_spinup->SetWidth(group_drive->GetWidth() - 24 - slider_spinup->GetX() - text_spinup_seconds->GetUnscaledTextWidth());
178 text_spinup_seconds->SetX(group_drive->GetWidth() - 16 - text_spinup_seconds->GetUnscaledTextWidth());
179
180 check_readCDPlayerIni->SetWidth(group_cdinfo->GetWidth() - check_readCDText->GetWidth() - 29);
181 check_readISRC->SetWidth(group_cdinfo->GetWidth() - 20);
182
183 check_swapchannels->SetWidth(group_ripping->GetWidth() - check_paranoia->GetWidth() - 29);
184 combo_paranoia_mode->SetWidth(check_swapchannels->GetWidth());
185
186 group_automatization = new GroupBox(i18n->TranslateString("Automatization"), Point(group_drive->GetWidth() + 15, 11), Size(190, 94));
187
188 check_autoRead = new CheckBox(i18n->TranslateString("Read CD contents on insert"), Point(10, 14), Size(170, 0), &autoRead);
189 check_autoRead->onAction.Connect(&ConfigureCDRip::ToggleAutoRead, this);
190
191 if (!notificationAvailable) check_autoRead->Deactivate();
192
193 check_autoRip = new CheckBox(i18n->TranslateString("Start ripping automatically"), check_autoRead->GetPosition() + Point(0, 26), Size(170, 0), &autoRip);
194 check_autoEject = new CheckBox(i18n->TranslateString("Eject disc after ripping"), check_autoRip->GetPosition() + Point(0, 26), Size(170, 0), &autoEject);
195
196 group_automatization->Add(check_autoRead);
197 group_automatization->Add(check_autoRip);
198 group_automatization->Add(check_autoEject);
199
200 maxTextSize = Math::Max(Math::Max(check_autoRead->GetUnscaledTextWidth(), check_autoRip->GetUnscaledTextWidth()), check_autoEject->GetUnscaledTextWidth());
201
202 check_autoRead->SetWidth(Math::Max(149, maxTextSize + 21));
203 check_autoRip->SetWidth(check_autoRead->GetWidth());
204 check_autoEject->SetWidth(check_autoRead->GetWidth());
205
206 group_automatization->SetWidth(check_autoRead->GetWidth() + 20);
207
208 ToggleAutoRead();
209
210 Add(group_drive);
211 Add(group_ripping);
212 Add(group_automatization);
213 Add(group_cdinfo);
214
215 SetSize(Size(group_drive->GetWidth() + group_automatization->GetWidth() + 22, 296));
216 }
217
218 BoCA::ConfigureCDRip::~ConfigureCDRip()
219 {
220 DeleteObject(group_drive);
221 DeleteObject(combo_drive);
222 DeleteObject(check_speed);
223 DeleteObject(combo_speed);
224 DeleteObject(check_spinup);
225 DeleteObject(slider_spinup);
226 DeleteObject(text_spinup_seconds);
227 DeleteObject(check_offset);
228 DeleteObject(edit_offset);
229 DeleteObject(text_offset_samples);
230
231 DeleteObject(group_ripping);
232 DeleteObject(check_paranoia);
233 DeleteObject(combo_paranoia_mode);
234 DeleteObject(check_jitter);
235 DeleteObject(check_swapchannels);
236
237 DeleteObject(group_automatization);
238 DeleteObject(check_autoRead);
239 DeleteObject(check_autoRip);
240 DeleteObject(check_autoEject);
241
242 DeleteObject(group_cdinfo);
243 DeleteObject(check_readCDText);
244 DeleteObject(check_readCDPlayerIni);
245 DeleteObject(check_readISRC);
246 }
247
248 Void BoCA::ConfigureCDRip::SelectDrive()
249 {
250 edit_offset->SetText(String::FromInt(driveOffsets.GetNth(combo_drive->GetSelectedEntryNumber())));
251 combo_speed->SelectNthEntry((48 - driveSpeeds.GetNth(combo_drive->GetSelectedEntryNumber())) / 4);
252
253 check_offset->SetChecked(driveOffsetUsed.GetNth(combo_drive->GetSelectedEntryNumber()));
254 check_speed->SetChecked(driveSpeeds.GetNth(combo_drive->GetSelectedEntryNumber()));
255 check_spinup->SetChecked(driveSpinUpTimes.GetNth(combo_drive->GetSelectedEntryNumber()) > 0);
256
257 slider_spinup->SetValue(Math::Abs(driveSpinUpTimes.GetNth(combo_drive->GetSelectedEntryNumber())));
258
259 ToggleUseOffset();
260 ToggleSetSpeed();
261 ToggleSpinUp();
262 }
263
264 Void BoCA::ConfigureCDRip::ToggleUseOffset()
265 {
266 driveOffsetUsed.SetNth(combo_drive->GetSelectedEntryNumber(), useoffset);
267
268 if (useoffset)
269 {
270 edit_offset->Activate();
271 text_offset_samples->Activate();
272 }
273 else
274 {
275 edit_offset->Deactivate();
276 text_offset_samples->Deactivate();
277 }
278 }
279
280 Void BoCA::ConfigureCDRip::ChangeOffset()
281 {
282 if (!useoffset) return;
283
284 driveOffsets.SetNth(combo_drive->GetSelectedEntryNumber(), edit_offset->GetText().ToInt());
285 }
286
287 Void BoCA::ConfigureCDRip::ToggleSpinUp()
288 {
289 driveSpinUpTimes.SetNth(combo_drive->GetSelectedEntryNumber(), slider_spinup->GetValue() * (spinup ? 1 : -1));
290
291 if (spinup)
292 {
293 slider_spinup->Activate();
294 text_spinup_seconds->Activate();
295 }
296 else
297 {
298 slider_spinup->Deactivate();
299 text_spinup_seconds->Deactivate();
300 }
301 }
302
303 Void BoCA::ConfigureCDRip::ChangeSpinUpTime()
304 {
305 I18n *i18n = I18n::Get();
306
307 i18n->SetContext("Ripper");
308
309 text_spinup_seconds->SetText(i18n->TranslateString("%1 seconds").Replace("%1", String::FromInt(slider_spinup->GetValue())));
310
311 driveSpinUpTimes.SetNth(combo_drive->GetSelectedEntryNumber(), slider_spinup->GetValue() * (spinup ? 1 : -1));
312 }
313
314 Void BoCA::ConfigureCDRip::ToggleSetSpeed()
315 {
316 if (setspeed)
317 {
318 combo_speed->Activate();
319
320 driveSpeeds.SetNth(combo_drive->GetSelectedEntryNumber(), 48 - (combo_speed->GetSelectedEntryNumber() * 4));
321 }
322 else
323 {
324 combo_speed->Deactivate();
325
326 driveSpeeds.SetNth(combo_drive->GetSelectedEntryNumber(), 0);
327 }
328 }
329
330 Void BoCA::ConfigureCDRip::SelectSpeed()
331 {
332 if (!setspeed) return;
333
334 driveSpeeds.SetNth(combo_drive->GetSelectedEntryNumber(), 48 - (combo_speed->GetSelectedEntryNumber() * 4));
335 }
336
337 Void BoCA::ConfigureCDRip::ToggleParanoia()
338 {
339 if (cdparanoia) combo_paranoia_mode->Activate();
340 else combo_paranoia_mode->Deactivate();
341 }
342
343 Void BoCA::ConfigureCDRip::ToggleAutoRead()
344 {
345 if (autoRead) check_autoRip->Activate();
346 else check_autoRip->Deactivate();
347 }
348
349 Int BoCA::ConfigureCDRip::SaveSettings()
350 {
351 Config *config = Config::Get();
352
353 if (driveSpeeds.Length() >= 1) config->SetIntValue(ConfigID, "ActiveDrive", combo_drive->GetSelectedEntryNumber());
354
355 AS::Registry &boca = AS::Registry::Get();
356 AS::DeviceInfoComponent *info = (AS::DeviceInfoComponent *) boca.CreateComponentByID("cdrip-info");
357
358 if (info != NIL)
359 {
360 for (Int i = 0; i < info->GetNumberOfDevices(); i++)
361 {
362 const Device &device = info->GetNthDeviceInfo(i);
363 String deviceID = device.GetID();
364
365 config->SetIntValue(ConfigID, String("UseOffsetDrive-").Append(deviceID), driveOffsetUsed.GetNth(i));
366 config->SetIntValue(ConfigID, String("ReadOffsetDrive-").Append(deviceID), driveOffsets.GetNth(i));
367 config->SetIntValue(ConfigID, String("RippingSpeedDrive-").Append(deviceID), driveSpeeds.GetNth(i));
368 config->SetIntValue(ConfigID, String("SpinUpTimeDrive-").Append(deviceID), driveSpinUpTimes.GetNth(i));
369 }
370
371 boca.DeleteComponent(info);
372 }
373
374 if (config->GetIntValue("Internal", "NotificationAvailable", False))
375 {
376 config->SetIntValue(ConfigID, "AutoReadContents", autoRead);
377 config->SetIntValue(ConfigID, "AutoRip", autoRip);
378 }
379
380 config->SetIntValue(ConfigID, "JitterCorrection", jitter);
381 config->SetIntValue(ConfigID, "SwapChannels", swapchannels);
382
383 config->SetIntValue(ConfigID, "EjectAfterRipping", autoEject);
384
385 config->SetIntValue(ConfigID, "ReadCDText", readCDText);
386 config->SetIntValue(ConfigID, "ReadCDPlayerIni", readCDPlayerIni);
387 config->SetIntValue(ConfigID, "ReadISRC", readISRC);
388
389 config->SetIntValue(ConfigID, "CDParanoia", cdparanoia);
390 config->SetIntValue(ConfigID, "CDParanoiaMode", combo_paranoia_mode->GetSelectedEntryNumber());
391
392 return Success();
393 }