| 1 | /* BoCA - BonkEnc Component Architecture |
| 2 | * Copyright (C) 2007-2020 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 | #include "dllinterface.h" |
| 15 | |
| 16 | const String BoCA::ConfigureFAAC::ConfigID = "FAAC"; |
| 17 | |
| 18 | BoCA::ConfigureFAAC::ConfigureFAAC() |
| 19 | { |
| 20 | const Config *config = Config::Get(); |
| 21 | |
| 22 | mpegVersion = config->GetIntValue(ConfigID, "MPEGVersion", 0); |
| 23 | bitrate = config->GetIntValue(ConfigID, "Bitrate", 96); |
| 24 | allowjs = config->GetIntValue(ConfigID, "AllowJS", True); |
| 25 | usetns = config->GetIntValue(ConfigID, "UseTNS", False); |
| 26 | setQuality = config->GetIntValue(ConfigID, "SetQuality", True); |
| 27 | aacQuality = config->GetIntValue(ConfigID, "AACQuality", 150); |
| 28 | allowID3 = config->GetIntValue(ConfigID, "AllowID3v2", False); |
| 29 | fileFormat = config->GetIntValue(ConfigID, "MP4Container", True); |
| 30 | fileExtension = config->GetIntValue(ConfigID, "MP4FileExtension", 0); |
| 31 | |
| 32 | I18n *i18n = I18n::Get(); |
| 33 | |
| 34 | tabwidget = new TabWidget(Point(7, 7), Size(525, 208)); |
| 35 | |
| 36 | i18n->SetContext("Encoders::AAC::Format"); |
| 37 | |
| 38 | layer_format = new Layer(i18n->TranslateString("Format")); |
| 39 | |
| 40 | group_mp4 = new GroupBox(i18n->TranslateString("File format"), Point(7, 11), Size(120, 65)); |
| 41 | |
| 42 | option_mp4 = new OptionBox("MP4", Point(10, 13), Size(99, 0), &fileFormat, 1); |
| 43 | option_mp4->onAction.Connect(&ConfigureFAAC::SetFileFormat, this); |
| 44 | |
| 45 | if (mp4v2dll == NIL) |
| 46 | { |
| 47 | option_mp4->Deactivate(); |
| 48 | |
| 49 | fileFormat = 0; |
| 50 | } |
| 51 | |
| 52 | option_aac = new OptionBox("AAC", Point(10, 38), Size(99, 0), &fileFormat, 0); |
| 53 | option_aac->onAction.Connect(&ConfigureFAAC::SetFileFormat, this); |
| 54 | |
| 55 | group_mp4->Add(option_mp4); |
| 56 | group_mp4->Add(option_aac); |
| 57 | |
| 58 | group_id3v2 = new GroupBox(i18n->TranslateString("Tags"), Point(7, 88), Size(279, 90)); |
| 59 | |
| 60 | check_id3v2 = new CheckBox(i18n->TranslateString("Allow ID3v2 tags in AAC files"), Point(10, 13), Size(200, 0), &allowID3); |
| 61 | check_id3v2->SetWidth(check_id3v2->GetUnscaledTextWidth() + 20); |
| 62 | |
| 63 | text_note = new Text(i18n->AddColon(i18n->TranslateString("Note")), Point(10, 38)); |
| 64 | text_id3v2 = new Text(i18n->TranslateString("Some players may have problems playing AAC\nfiles with ID3 tags attached. Please use this option only\nif you are sure that your player can handle these tags."), Point(text_note->GetUnscaledTextWidth() + 12, 38)); |
| 65 | |
| 66 | group_id3v2->SetSize(Size(Math::Max(368, text_note->GetUnscaledTextWidth() + text_id3v2->GetUnscaledTextWidth() + 22), Math::Max(text_note->GetUnscaledTextHeight(), text_id3v2->GetUnscaledTextHeight()) + 48)); |
| 67 | |
| 68 | group_id3v2->Add(check_id3v2); |
| 69 | group_id3v2->Add(text_note); |
| 70 | group_id3v2->Add(text_id3v2); |
| 71 | |
| 72 | group_version = new GroupBox(i18n->TranslateString("MPEG version"), Point(135, 11), Size(group_id3v2->GetWidth() / 2 - 68, 65)); |
| 73 | |
| 74 | option_version_mpeg2 = new OptionBox("MPEG 2", Point(10, 13), Size(group_version->GetWidth() - 21, 0), &mpegVersion, 1); |
| 75 | option_version_mpeg4 = new OptionBox("MPEG 4", Point(10, 38), Size(group_version->GetWidth() - 21, 0), &mpegVersion, 0); |
| 76 | |
| 77 | group_version->Add(option_version_mpeg2); |
| 78 | group_version->Add(option_version_mpeg4); |
| 79 | |
| 80 | group_extension = new GroupBox(i18n->TranslateString("File extension"), Point(group_version->GetWidth() + 143 + (group_id3v2->GetWidth() % 2), 11), Size(group_id3v2->GetWidth() / 2 - 68, 65)); |
| 81 | |
| 82 | option_extension_m4a = new OptionBox(".m4a", Point(10, 13), Size(group_extension->GetWidth() / 2 - 14, 0), &fileExtension, 0); |
| 83 | option_extension_m4b = new OptionBox(".m4b", Point(10, 38), Size(group_extension->GetWidth() / 2 - 14, 0), &fileExtension, 1); |
| 84 | option_extension_m4r = new OptionBox(".m4r", Point(group_extension->GetWidth() / 2 + 4, 13), Size(group_extension->GetWidth() / 2 - 14, 0), &fileExtension, 2); |
| 85 | option_extension_mp4 = new OptionBox(".mp4", Point(group_extension->GetWidth() / 2 + 4, 38), Size(group_extension->GetWidth() / 2 - 14, 0), &fileExtension, 3); |
| 86 | |
| 87 | group_extension->Add(option_extension_m4a); |
| 88 | group_extension->Add(option_extension_m4b); |
| 89 | group_extension->Add(option_extension_m4r); |
| 90 | group_extension->Add(option_extension_mp4); |
| 91 | |
| 92 | i18n->SetContext("Encoders::AAC::Quality"); |
| 93 | |
| 94 | layer_quality = new Layer(i18n->TranslateString("Quality")); |
| 95 | |
| 96 | group_bitrate = new GroupBox(i18n->TranslateString("Bitrate / Quality"), Point(7, 11), Size(320, 65)); |
| 97 | |
| 98 | option_bitrate = new OptionBox(i18n->AddColon(i18n->TranslateString("Bitrate per channel")), Point(10, 13), Size(150, 0), &setQuality, 0); |
| 99 | option_bitrate->onAction.Connect(&ConfigureFAAC::ToggleBitrateQuality, this); |
| 100 | option_bitrate->SetWidth(option_bitrate->GetUnscaledTextWidth() + 19); |
| 101 | |
| 102 | text_bitrate_kbps = new Text(i18n->TranslateString("%1 kbps", "Technical").Replace("%1", NIL).Trim(), Point(35, 15)); |
| 103 | text_bitrate_kbps->SetX(text_bitrate_kbps->GetUnscaledTextWidth() + 10); |
| 104 | text_bitrate_kbps->SetOrientation(OR_UPPERRIGHT); |
| 105 | |
| 106 | edit_bitrate = new EditBox(Point(text_bitrate_kbps->GetX() + 32, 12), Size(25, 0), 3); |
| 107 | edit_bitrate->SetFlags(EDB_NUMERIC); |
| 108 | edit_bitrate->SetOrientation(OR_UPPERRIGHT); |
| 109 | edit_bitrate->onInput.Connect(&ConfigureFAAC::SetBitrateByEditBox, this); |
| 110 | |
| 111 | slider_bitrate = new Slider(Point(option_bitrate->GetWidth() + 18, 13), Size(group_bitrate->GetWidth() - edit_bitrate->GetX() - 26 - option_bitrate->GetWidth(), 0), OR_HORZ, &bitrate, 8, 256); |
| 112 | slider_bitrate->onValueChange.Connect(&ConfigureFAAC::SetBitrate, this); |
| 113 | |
| 114 | option_quality = new OptionBox(i18n->AddColon(i18n->TranslateString("Set quality")), Point(10, 38), Size(150, 0), &setQuality, 1); |
| 115 | option_quality->onAction.Connect(&ConfigureFAAC::ToggleBitrateQuality, this); |
| 116 | option_quality->SetWidth(option_bitrate->GetWidth()); |
| 117 | |
| 118 | slider_quality = new Slider(Point(option_quality->GetWidth() + 18, 38), Size(slider_bitrate->GetWidth(), 0), OR_HORZ, &aacQuality, 10, 500); |
| 119 | slider_quality->onValueChange.Connect(&ConfigureFAAC::SetQuality, this); |
| 120 | |
| 121 | edit_quality = new EditBox(Point(edit_bitrate->GetX(), 37), Size(25, 0), 3); |
| 122 | edit_quality->SetFlags(EDB_NUMERIC); |
| 123 | edit_quality->SetOrientation(OR_UPPERRIGHT); |
| 124 | edit_quality->onInput.Connect(&ConfigureFAAC::SetQualityByEditBox, this); |
| 125 | |
| 126 | text_quality_percent = new Text(i18n->TranslateString("%1%", "Technical").Replace("%1", NIL).Trim(), Point(text_bitrate_kbps->GetX(), 40)); |
| 127 | text_quality_percent->SetOrientation(OR_UPPERRIGHT); |
| 128 | |
| 129 | group_bitrate->Add(option_bitrate); |
| 130 | group_bitrate->Add(slider_bitrate); |
| 131 | group_bitrate->Add(edit_bitrate); |
| 132 | group_bitrate->Add(text_bitrate_kbps); |
| 133 | group_bitrate->Add(option_quality); |
| 134 | group_bitrate->Add(slider_quality); |
| 135 | group_bitrate->Add(edit_quality); |
| 136 | group_bitrate->Add(text_quality_percent); |
| 137 | |
| 138 | group_js = new GroupBox(i18n->TranslateString("Stereo mode"), Point(335, 11), Size(189, 42)); |
| 139 | |
| 140 | check_js = new CheckBox(i18n->TranslateString("Allow Joint Stereo"), Point(10, 13), Size(168, 0), &allowjs); |
| 141 | |
| 142 | group_js->Add(check_js); |
| 143 | |
| 144 | group_tns = new GroupBox(i18n->TranslateString("Temporal Noise Shaping"), Point(335, 65), Size(189, 42)); |
| 145 | |
| 146 | check_tns = new CheckBox(i18n->TranslateString("Use Temporal Noise Shaping"), Point(10, 13), Size(168, 0), &usetns); |
| 147 | |
| 148 | group_tns->Add(check_tns); |
| 149 | |
| 150 | group_bandwidth = new GroupBox(i18n->TranslateString("Maximum bandwidth"), Point(7, 88), Size(320, 43)); |
| 151 | |
| 152 | text_bandwidth = new Text(i18n->AddColon(i18n->TranslateString("Maximum AAC frequency bandwidth to use (Hz)")), Point(11, 15)); |
| 153 | |
| 154 | edit_bandwidth = new EditBox(String::FromInt(config->GetIntValue(ConfigID, "BandWidth", 18500)), Point(text_bandwidth->GetUnscaledTextWidth() + 19, 12), Size(291 - text_bandwidth->GetUnscaledTextWidth(), 0), 5); |
| 155 | edit_bandwidth->SetFlags(EDB_NUMERIC); |
| 156 | |
| 157 | group_bandwidth->Add(text_bandwidth); |
| 158 | group_bandwidth->Add(edit_bandwidth); |
| 159 | |
| 160 | SetBitrate(); |
| 161 | SetQuality(); |
| 162 | SetFileFormat(); |
| 163 | |
| 164 | ToggleBitrateQuality(); |
| 165 | |
| 166 | tabwidget->SetSize(Size(Math::Max(535, group_id3v2->GetWidth() + 18), Math::Max(193, group_id3v2->GetHeight() + 118))); |
| 167 | |
| 168 | Add(tabwidget); |
| 169 | |
| 170 | tabwidget->Add(layer_quality); |
| 171 | tabwidget->Add(layer_format); |
| 172 | |
| 173 | layer_format->Add(group_version); |
| 174 | layer_format->Add(group_mp4); |
| 175 | layer_format->Add(group_extension); |
| 176 | layer_format->Add(group_id3v2); |
| 177 | |
| 178 | layer_quality->Add(group_bitrate); |
| 179 | layer_quality->Add(group_js); |
| 180 | layer_quality->Add(group_tns); |
| 181 | layer_quality->Add(group_bandwidth); |
| 182 | |
| 183 | SetSize(tabwidget->GetSize() + Size(14, 14)); |
| 184 | } |
| 185 | |
| 186 | BoCA::ConfigureFAAC::~ConfigureFAAC() |
| 187 | { |
| 188 | DeleteObject(tabwidget); |
| 189 | DeleteObject(layer_format); |
| 190 | DeleteObject(layer_quality); |
| 191 | |
| 192 | DeleteObject(group_version); |
| 193 | DeleteObject(option_version_mpeg2); |
| 194 | DeleteObject(option_version_mpeg4); |
| 195 | DeleteObject(group_mp4); |
| 196 | DeleteObject(option_mp4); |
| 197 | DeleteObject(option_aac); |
| 198 | DeleteObject(group_extension); |
| 199 | DeleteObject(option_extension_m4a); |
| 200 | DeleteObject(option_extension_m4b); |
| 201 | DeleteObject(option_extension_m4r); |
| 202 | DeleteObject(option_extension_mp4); |
| 203 | DeleteObject(group_id3v2); |
| 204 | DeleteObject(check_id3v2); |
| 205 | DeleteObject(text_note); |
| 206 | DeleteObject(text_id3v2); |
| 207 | |
| 208 | DeleteObject(group_bitrate); |
| 209 | DeleteObject(option_bitrate); |
| 210 | DeleteObject(slider_bitrate); |
| 211 | DeleteObject(edit_bitrate); |
| 212 | DeleteObject(text_bitrate_kbps); |
| 213 | DeleteObject(option_quality); |
| 214 | DeleteObject(slider_quality); |
| 215 | DeleteObject(edit_quality); |
| 216 | DeleteObject(text_quality_percent); |
| 217 | DeleteObject(group_js); |
| 218 | DeleteObject(check_js); |
| 219 | DeleteObject(group_tns); |
| 220 | DeleteObject(check_tns); |
| 221 | DeleteObject(group_bandwidth); |
| 222 | DeleteObject(text_bandwidth); |
| 223 | DeleteObject(edit_bandwidth); |
| 224 | } |
| 225 | |
| 226 | Int BoCA::ConfigureFAAC::SaveSettings() |
| 227 | { |
| 228 | Config *config = Config::Get(); |
| 229 | |
| 230 | if (bitrate < 8) bitrate = 8; |
| 231 | if (bitrate > 256) bitrate = 256; |
| 232 | |
| 233 | if (aacQuality < 10) aacQuality = 10; |
| 234 | if (aacQuality > 500) aacQuality = 500; |
| 235 | |
| 236 | config->SetIntValue(ConfigID, "MPEGVersion", mpegVersion); |
| 237 | config->SetIntValue(ConfigID, "Bitrate", bitrate); |
| 238 | config->SetIntValue(ConfigID, "AllowJS", allowjs); |
| 239 | config->SetIntValue(ConfigID, "UseTNS", usetns); |
| 240 | config->SetIntValue(ConfigID, "BandWidth", edit_bandwidth->GetText().ToInt()); |
| 241 | config->SetIntValue(ConfigID, "SetQuality", setQuality); |
| 242 | config->SetIntValue(ConfigID, "AACQuality", aacQuality); |
| 243 | config->SetIntValue(ConfigID, "AllowID3v2", allowID3); |
| 244 | config->SetIntValue(ConfigID, "MP4Container", fileFormat); |
| 245 | config->SetIntValue(ConfigID, "MP4FileExtension", fileExtension); |
| 246 | |
| 247 | return Success(); |
| 248 | } |
| 249 | |
| 250 | Void BoCA::ConfigureFAAC::SetBitrate() |
| 251 | { |
| 252 | if (!edit_bitrate->IsFocussed()) edit_bitrate->SetText(String::FromInt(bitrate)); |
| 253 | } |
| 254 | |
| 255 | Void BoCA::ConfigureFAAC::SetBitrateByEditBox() |
| 256 | { |
| 257 | slider_bitrate->SetValue(edit_bitrate->GetText().ToInt()); |
| 258 | } |
| 259 | |
| 260 | Void BoCA::ConfigureFAAC::SetQuality() |
| 261 | { |
| 262 | if (!edit_quality->IsFocussed()) edit_quality->SetText(String::FromInt(aacQuality)); |
| 263 | } |
| 264 | |
| 265 | Void BoCA::ConfigureFAAC::SetQualityByEditBox() |
| 266 | { |
| 267 | slider_quality->SetValue(edit_quality->GetText().ToInt()); |
| 268 | } |
| 269 | |
| 270 | Void BoCA::ConfigureFAAC::SetFileFormat() |
| 271 | { |
| 272 | if (fileFormat == 1) // MP4 container |
| 273 | { |
| 274 | group_version->Deactivate(); |
| 275 | group_id3v2->Deactivate(); |
| 276 | |
| 277 | group_extension->Activate(); |
| 278 | |
| 279 | if (mpegVersion == 1) // MPEG2 |
| 280 | { |
| 281 | mpegVersion = 0; |
| 282 | |
| 283 | OptionBox::internalCheckValues.Emit(); |
| 284 | } |
| 285 | } |
| 286 | else // raw AAC file format |
| 287 | { |
| 288 | group_version->Activate(); |
| 289 | group_id3v2->Activate(); |
| 290 | |
| 291 | group_extension->Deactivate(); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | Void BoCA::ConfigureFAAC::ToggleBitrateQuality() |
| 296 | { |
| 297 | if (setQuality) |
| 298 | { |
| 299 | slider_bitrate->Deactivate(); |
| 300 | edit_bitrate->Deactivate(); |
| 301 | |
| 302 | slider_quality->Activate(); |
| 303 | edit_quality->Activate(); |
| 304 | } |
| 305 | else |
| 306 | { |
| 307 | slider_quality->Deactivate(); |
| 308 | edit_quality->Deactivate(); |
| 309 | |
| 310 | slider_bitrate->Activate(); |
| 311 | edit_bitrate->Activate(); |
| 312 | } |
| 313 | } |