| 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::ConfigureVOAAC::ConfigID = "VOAACEnc"; |
| 17 | |
| 18 | BoCA::ConfigureVOAAC::ConfigureVOAAC() |
| 19 | { |
| 20 | const Config *config = Config::Get(); |
| 21 | |
| 22 | bitrate = config->GetIntValue(ConfigID, "Bitrate", 96); |
| 23 | allowID3 = config->GetIntValue(ConfigID, "AllowID3v2", False); |
| 24 | fileFormat = config->GetIntValue(ConfigID, "MP4Container", True); |
| 25 | fileExtension = config->GetIntValue(ConfigID, "MP4FileExtension", 0); |
| 26 | |
| 27 | I18n *i18n = I18n::Get(); |
| 28 | |
| 29 | i18n->SetContext("Encoders::AAC::Format"); |
| 30 | |
| 31 | group_id3v2 = new GroupBox(i18n->TranslateString("Tags"), Point(7, 143), Size(281, 90)); |
| 32 | |
| 33 | check_id3v2 = new CheckBox(i18n->TranslateString("Allow ID3v2 tags in AAC files"), Point(10, 13), Size(200, 0), &allowID3); |
| 34 | check_id3v2->SetWidth(check_id3v2->GetUnscaledTextWidth() + 20); |
| 35 | |
| 36 | text_note = new Text(i18n->AddColon(i18n->TranslateString("Note")), Point(10, 38)); |
| 37 | 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)); |
| 38 | |
| 39 | group_id3v2->SetSize(Size(Math::Max(240, text_note->GetUnscaledTextWidth() + text_id3v2->GetUnscaledTextWidth() + 22), Math::Max(text_note->GetUnscaledTextHeight(), text_id3v2->GetUnscaledTextHeight()) + 48)); |
| 40 | |
| 41 | group_id3v2->Add(check_id3v2); |
| 42 | group_id3v2->Add(text_note); |
| 43 | group_id3v2->Add(text_id3v2); |
| 44 | |
| 45 | i18n->SetContext("Encoders::AAC::Quality"); |
| 46 | |
| 47 | group_bitrate = new GroupBox(i18n->TranslateString("Bitrate"), Point(7, 11), Size(group_id3v2->GetWidth(), 43)); |
| 48 | |
| 49 | text_bitrate = new Text(i18n->AddColon(i18n->TranslateString("Bitrate per channel")), Point(10, 15)); |
| 50 | |
| 51 | text_bitrate_kbps = new Text(i18n->TranslateString("%1 kbps", "Technical").Replace("%1", NIL).Trim(), Point(35, 15)); |
| 52 | text_bitrate_kbps->SetX(text_bitrate_kbps->GetUnscaledTextWidth() + 10); |
| 53 | text_bitrate_kbps->SetOrientation(OR_UPPERRIGHT); |
| 54 | |
| 55 | edit_bitrate = new EditBox(Point(text_bitrate_kbps->GetX() + 32, 12), Size(25, 0), 3); |
| 56 | edit_bitrate->SetFlags(EDB_NUMERIC); |
| 57 | edit_bitrate->SetOrientation(OR_UPPERRIGHT); |
| 58 | edit_bitrate->onInput.Connect(&ConfigureVOAAC::SetBitrateByEditBox, this); |
| 59 | |
| 60 | slider_bitrate = new Slider(Point(text_bitrate->GetUnscaledTextSize().cx + 17, 13), Size(group_bitrate->GetWidth() - edit_bitrate->GetX() - 25 - text_bitrate->GetUnscaledTextSize().cx, 0), OR_HORZ, &bitrate, 8, 128); |
| 61 | slider_bitrate->onValueChange.Connect(&ConfigureVOAAC::SetBitrate, this); |
| 62 | |
| 63 | group_bitrate->Add(text_bitrate); |
| 64 | group_bitrate->Add(slider_bitrate); |
| 65 | group_bitrate->Add(edit_bitrate); |
| 66 | group_bitrate->Add(text_bitrate_kbps); |
| 67 | |
| 68 | i18n->SetContext("Encoders::AAC::Format"); |
| 69 | |
| 70 | group_mp4 = new GroupBox(i18n->TranslateString("File format"), Point(7, 66), Size(group_id3v2->GetWidth() / 2 - 4, 65)); |
| 71 | |
| 72 | option_mp4 = new OptionBox("MP4", Point(10, 13), Size(group_mp4->GetWidth() - 21, 0), &fileFormat, 1); |
| 73 | option_mp4->onAction.Connect(&ConfigureVOAAC::SetFileFormat, this); |
| 74 | |
| 75 | if (mp4v2dll == NIL) |
| 76 | { |
| 77 | option_mp4->Deactivate(); |
| 78 | |
| 79 | fileFormat = 0; |
| 80 | } |
| 81 | |
| 82 | option_aac = new OptionBox("AAC", Point(10, 38), Size(group_mp4->GetWidth() - 21, 0), &fileFormat, 0); |
| 83 | option_aac->onAction.Connect(&ConfigureVOAAC::SetFileFormat, this); |
| 84 | |
| 85 | group_mp4->Add(option_mp4); |
| 86 | group_mp4->Add(option_aac); |
| 87 | |
| 88 | group_extension = new GroupBox(i18n->TranslateString("File extension"), Point(group_mp4->GetWidth() + 15 + (group_id3v2->GetWidth() % 2), 66), Size(group_id3v2->GetWidth() / 2 - 4, 65)); |
| 89 | |
| 90 | option_extension_m4a = new OptionBox(".m4a", Point(10, 13), Size(group_extension->GetWidth() / 2 - 14, 0), &fileExtension, 0); |
| 91 | option_extension_m4b = new OptionBox(".m4b", Point(10, 38), Size(group_extension->GetWidth() / 2 - 14, 0), &fileExtension, 1); |
| 92 | option_extension_m4r = new OptionBox(".m4r", Point(group_extension->GetWidth() / 2 + 4, 13), Size(group_extension->GetWidth() / 2 - 14, 0), &fileExtension, 2); |
| 93 | option_extension_mp4 = new OptionBox(".mp4", Point(group_extension->GetWidth() / 2 + 4, 38), Size(group_extension->GetWidth() / 2 - 14, 0), &fileExtension, 3); |
| 94 | |
| 95 | group_extension->Add(option_extension_m4a); |
| 96 | group_extension->Add(option_extension_m4b); |
| 97 | group_extension->Add(option_extension_m4r); |
| 98 | group_extension->Add(option_extension_mp4); |
| 99 | |
| 100 | SetBitrate(); |
| 101 | SetFileFormat(); |
| 102 | |
| 103 | Add(group_bitrate); |
| 104 | Add(group_mp4); |
| 105 | Add(group_extension); |
| 106 | Add(group_id3v2); |
| 107 | |
| 108 | SetSize(group_id3v2->GetSize() + Size(14, 150)); |
| 109 | } |
| 110 | |
| 111 | BoCA::ConfigureVOAAC::~ConfigureVOAAC() |
| 112 | { |
| 113 | DeleteObject(group_bitrate); |
| 114 | DeleteObject(text_bitrate); |
| 115 | DeleteObject(slider_bitrate); |
| 116 | DeleteObject(edit_bitrate); |
| 117 | DeleteObject(text_bitrate_kbps); |
| 118 | DeleteObject(group_mp4); |
| 119 | DeleteObject(option_mp4); |
| 120 | DeleteObject(option_aac); |
| 121 | DeleteObject(group_extension); |
| 122 | DeleteObject(option_extension_m4a); |
| 123 | DeleteObject(option_extension_m4b); |
| 124 | DeleteObject(option_extension_m4r); |
| 125 | DeleteObject(option_extension_mp4); |
| 126 | DeleteObject(group_id3v2); |
| 127 | DeleteObject(check_id3v2); |
| 128 | DeleteObject(text_note); |
| 129 | DeleteObject(text_id3v2); |
| 130 | } |
| 131 | |
| 132 | Int BoCA::ConfigureVOAAC::SaveSettings() |
| 133 | { |
| 134 | Config *config = Config::Get(); |
| 135 | |
| 136 | if (bitrate < 8) bitrate = 8; |
| 137 | if (bitrate > 128) bitrate = 128; |
| 138 | |
| 139 | config->SetIntValue(ConfigID, "Bitrate", bitrate); |
| 140 | config->SetIntValue(ConfigID, "AllowID3v2", allowID3); |
| 141 | config->SetIntValue(ConfigID, "MP4Container", fileFormat); |
| 142 | config->SetIntValue(ConfigID, "MP4FileExtension", fileExtension); |
| 143 | |
| 144 | return Success(); |
| 145 | } |
| 146 | |
| 147 | Void BoCA::ConfigureVOAAC::SetBitrate() |
| 148 | { |
| 149 | if (!edit_bitrate->IsFocussed()) edit_bitrate->SetText(String::FromInt(bitrate)); |
| 150 | } |
| 151 | |
| 152 | Void BoCA::ConfigureVOAAC::SetBitrateByEditBox() |
| 153 | { |
| 154 | slider_bitrate->SetValue(edit_bitrate->GetText().ToInt()); |
| 155 | } |
| 156 | |
| 157 | Void BoCA::ConfigureVOAAC::SetFileFormat() |
| 158 | { |
| 159 | if (fileFormat == 1) // MP4 container |
| 160 | { |
| 161 | group_id3v2->Deactivate(); |
| 162 | |
| 163 | group_extension->Activate(); |
| 164 | } |
| 165 | else // raw AAC file format |
| 166 | { |
| 167 | group_id3v2->Activate(); |
| 168 | |
| 169 | group_extension->Deactivate(); |
| 170 | } |
| 171 | } |