Debian Codegraph @

components/encoder/bladeenc/config.cpp

raw symbols SCIP
1 /* BoCA - BonkEnc Component Architecture
2 * Copyright (C) 2007-2018 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 "config.h"
14
15 const String BoCA::ConfigureBlade::ConfigID = "BladeEnc";
16
17 BoCA::ConfigureBlade::ConfigureBlade()
18 {
19 const Config *config = Config::Get();
20
21 bitrate = GetSliderValue();
22 crc = config->GetIntValue(ConfigID, "CRC", 0);
23 copyright = config->GetIntValue(ConfigID, "Copyright", 0);
24 original = config->GetIntValue(ConfigID, "Original", 1);
25 priv = config->GetIntValue(ConfigID, "Private", 0);
26 dualchannel = config->GetIntValue(ConfigID, "DualChannel", 0);
27
28 I18n *i18n = I18n::Get();
29
30 i18n->SetContext("Encoders::BladeEnc");
31
32 group_bit = new GroupBox(i18n->TranslateString("Bitrate"), Point(7, 11), Size(179, 43));
33
34 slider_bit = new Slider(Point(10, 13), Size(114, 0), OR_HORZ, &bitrate, 0, 13);
35 slider_bit->onValueChange.Connect(&ConfigureBlade::SetBitrate, this);
36
37 text_bit = new Text("320 kbit", Point(131, 15));
38
39 group_bit->Add(slider_bit);
40 group_bit->Add(text_bit);
41
42 group_copyright = new GroupBox(i18n->TranslateString("Copyright bit"), Point(194, 11), Size(179, 43));
43 check_copyright = new CheckBox(i18n->TranslateString("Set Copyright bit"), Point(10, 13), Size(158, 0), &copyright);
44 group_copyright->Add(check_copyright);
45
46 group_crc = new GroupBox(i18n->TranslateString("CRC"), Point(7, 66), Size(179, 43));
47 check_crc = new CheckBox(i18n->TranslateString("Enable CRC"), Point(10, 13), Size(158, 0), &crc);
48 group_crc->Add(check_crc);
49
50 group_original = new GroupBox(i18n->TranslateString("Original bit"), Point(194, 66), Size(179, 43));
51 check_original = new CheckBox(i18n->TranslateString("Set Original bit"), Point(10, 13), Size(158, 0), &original);
52 group_original->Add(check_original);
53
54 group_dualchannel = new GroupBox(i18n->TranslateString("Channels"), Point(7, 121), Size(179, 43));
55 check_dualchannel = new CheckBox(i18n->TranslateString("Dual channel encoding"), Point(10, 13), Size(158, 0), &dualchannel);
56 group_dualchannel->Add(check_dualchannel);
57
58 group_private = new GroupBox(i18n->TranslateString("Private bit"), Point(194, 121), Size(179, 43));
59 check_private = new CheckBox(i18n->TranslateString("Set Private bit"), Point(10, 13), Size(158, 0), &priv);
60 group_private->Add(check_private);
61
62 Int maxTextSize = Math::Max(Math::Max(Math::Max(check_copyright->GetUnscaledTextWidth(), check_private->GetUnscaledTextWidth()), check_crc->GetUnscaledTextWidth()), Math::Max(check_original->GetUnscaledTextWidth(), check_dualchannel->GetUnscaledTextWidth()));
63
64 check_copyright->SetWidth(Math::Max(158, maxTextSize + 21));
65 check_original->SetWidth(check_copyright->GetWidth());
66 check_private->SetWidth(check_copyright->GetWidth());
67 check_crc->SetWidth(check_copyright->GetWidth());
68 check_dualchannel->SetWidth(check_copyright->GetWidth());
69
70 group_bit->SetWidth(check_copyright->GetWidth() + 20);
71 group_copyright->SetWidth(group_bit->GetWidth());
72 group_original->SetWidth(group_bit->GetWidth());
73 group_private->SetWidth(group_bit->GetWidth());
74 group_crc->SetWidth(group_bit->GetWidth());
75 group_dualchannel->SetWidth(group_bit->GetWidth());
76
77 group_copyright->SetX(group_bit->GetWidth() + 15);
78 group_original->SetX(group_bit->GetWidth() + 15);
79 group_private->SetX(group_bit->GetWidth() + 15);
80
81 text_bit->SetX(group_bit->GetWidth() - 10 - text_bit->GetUnscaledTextWidth());
82 slider_bit->SetWidth(group_bit->GetWidth() - 28 - text_bit->GetUnscaledTextWidth());
83
84 SetBitrate();
85
86 Add(group_bit);
87 Add(group_crc);
88 Add(group_copyright);
89 Add(group_original);
90 Add(group_private);
91 Add(group_dualchannel);
92
93 SetSize(Size(2 * group_bit->GetWidth() + 22, 171));
94 }
95
96 BoCA::ConfigureBlade::~ConfigureBlade()
97 {
98 DeleteObject(group_bit);
99 DeleteObject(slider_bit);
100 DeleteObject(text_bit);
101 DeleteObject(group_crc);
102 DeleteObject(check_crc);
103 DeleteObject(group_copyright);
104 DeleteObject(check_copyright);
105 DeleteObject(group_original);
106 DeleteObject(check_original);
107 DeleteObject(group_private);
108 DeleteObject(check_private);
109 DeleteObject(group_dualchannel);
110 DeleteObject(check_dualchannel);
111 }
112
113 Int BoCA::ConfigureBlade::SaveSettings()
114 {
115 Config *config = Config::Get();
116
117 config->SetIntValue(ConfigID, "Bitrate", GetBitrate());
118 config->SetIntValue(ConfigID, "CRC", crc);
119 config->SetIntValue(ConfigID, "Copyright", copyright);
120 config->SetIntValue(ConfigID, "Original", original);
121 config->SetIntValue(ConfigID, "Private", priv);
122 config->SetIntValue(ConfigID, "DualChannel", dualchannel);
123
124 return Success();
125 }
126
127 Void BoCA::ConfigureBlade::SetBitrate()
128 {
129 text_bit->SetText(String::FromInt(GetBitrate()).Append(" kbit"));
130 }
131
132 Int BoCA::ConfigureBlade::GetBitrate()
133 {
134 switch (bitrate)
135 {
136 case 0: return 32;
137 case 1: return 40;
138 case 2: return 48;
139 case 3: return 56;
140 case 4: return 64;
141 case 5: return 80;
142 case 6: return 96;
143 case 7: return 112;
144 case 8: return 128;
145 case 9: return 160;
146 case 10: return 192;
147 case 11: return 224;
148 case 12: return 256;
149 case 13: return 320;
150 default: return 128;
151 }
152 }
153
154 Int BoCA::ConfigureBlade::GetSliderValue()
155 {
156 switch (Config::Get()->GetIntValue("BladeEnc", "Bitrate", 192))
157 {
158 case 32: return 0;
159 case 40: return 1;
160 case 48: return 2;
161 case 56: return 3;
162 case 64: return 4;
163 case 80: return 5;
164 case 96: return 6;
165 case 112: return 7;
166 case 128: return 8;
167 case 160: return 9;
168 case 192: return 10;
169 case 224: return 11;
170 case 256: return 12;
171 case 320: return 13;
172 default: return 8;
173 }
174 }