| 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::ConfigureBonk::ConfigID = "Bonk"; |
| 16 | |
| 17 | BoCA::ConfigureBonk::ConfigureBonk() |
| 18 | { |
| 19 | const Config *config = Config::Get(); |
| 20 | |
| 21 | quant = config->GetIntValue(ConfigID, "Quantization", 8); |
| 22 | predictor = config->GetIntValue(ConfigID, "Predictor", 32); |
| 23 | downsampling = config->GetIntValue(ConfigID, "Downsampling", 2); |
| 24 | jstereo = config->GetIntValue(ConfigID, "JointStereo", 0); |
| 25 | lossless = config->GetIntValue(ConfigID, "Lossless", 0); |
| 26 | |
| 27 | I18n *i18n = I18n::Get(); |
| 28 | |
| 29 | i18n->SetContext("Encoders::Bonk"); |
| 30 | |
| 31 | group_mode = new GroupBox(i18n->TranslateString("Encoder mode"), Point(7, 11), Size(179, 43)); |
| 32 | |
| 33 | check_lossless = new CheckBox(i18n->TranslateString("Enable lossless encoding"), Point(10, 13), Size(158, 0), &lossless); |
| 34 | check_lossless->onAction.Connect(&ConfigureBonk::SetEncoderMode, this); |
| 35 | |
| 36 | group_mode->Add(check_lossless); |
| 37 | |
| 38 | group_stereo = new GroupBox(i18n->TranslateString("Stereo mode"), Point(194, 11), Size(179, 43)); |
| 39 | |
| 40 | check_joint = new CheckBox(i18n->TranslateString("Enable Joint Stereo"), Point(10, 13), Size(158, 0), &jstereo); |
| 41 | |
| 42 | group_stereo->Add(check_joint); |
| 43 | |
| 44 | Int maxTextSize = Math::Max(check_lossless->GetUnscaledTextWidth(), check_joint->GetUnscaledTextWidth()); |
| 45 | |
| 46 | check_lossless->SetWidth(Math::Max(158, maxTextSize + 21)); |
| 47 | check_joint->SetWidth(check_lossless->GetWidth()); |
| 48 | |
| 49 | group_mode->SetWidth(check_lossless->GetWidth() + 20); |
| 50 | |
| 51 | group_stereo->SetX(group_mode->GetWidth() + 15); |
| 52 | group_stereo->SetWidth(group_mode->GetWidth()); |
| 53 | |
| 54 | group_quant = new GroupBox(i18n->TranslateString("Quantization"), Point(7, 66), Size(group_mode->GetWidth(), 43)); |
| 55 | |
| 56 | slider_quant = new Slider(Point(10, 13), Size(group_quant->GetWidth() - 48, 0), OR_HORZ, &quant, 0, 40); |
| 57 | slider_quant->onValueChange.Connect(&ConfigureBonk::SetQuantization, this); |
| 58 | |
| 59 | text_quant = new Text("0.00", Point(slider_quant->GetWidth() + 17, 15)); |
| 60 | |
| 61 | text_quant->SetX(group_quant->GetWidth() - 10 - text_quant->GetUnscaledTextWidth()); |
| 62 | slider_quant->SetWidth(group_quant->GetWidth() - 28 - text_quant->GetUnscaledTextWidth()); |
| 63 | |
| 64 | group_quant->Add(slider_quant); |
| 65 | group_quant->Add(text_quant); |
| 66 | |
| 67 | SetQuantization(); |
| 68 | |
| 69 | group_downsampling = new GroupBox(i18n->TranslateString("Downsampling ratio"), Point(group_stereo->GetX(), 66), Size(group_stereo->GetWidth(), 43)); |
| 70 | |
| 71 | slider_downsampling = new Slider(Point(10, 13), Size(group_downsampling->GetWidth() - 48, 0), OR_HORZ, &downsampling, 1, 10); |
| 72 | slider_downsampling->onValueChange.Connect(&ConfigureBonk::SetDownsamplingRatio, this); |
| 73 | |
| 74 | text_downsampling = new Text("00:0", Point(slider_downsampling->GetWidth() + 17, 15)); |
| 75 | |
| 76 | text_downsampling->SetX(group_downsampling->GetWidth() - 10 - text_downsampling->GetUnscaledTextWidth()); |
| 77 | slider_downsampling->SetWidth(group_downsampling->GetWidth() - 28 - text_downsampling->GetUnscaledTextWidth()); |
| 78 | |
| 79 | group_downsampling->Add(slider_downsampling); |
| 80 | group_downsampling->Add(text_downsampling); |
| 81 | |
| 82 | SetDownsamplingRatio(); |
| 83 | |
| 84 | group_predictor = new GroupBox(i18n->TranslateString("Predictor size"), Point(7, 121), Size(2 * group_mode->GetWidth() + 8, 43)); |
| 85 | |
| 86 | slider_predictor = new Slider(Point(10, 13), Size(group_predictor->GetWidth() - 48, 0), OR_HORZ, &predictor, 0, 512); |
| 87 | slider_predictor->onValueChange.Connect(&ConfigureBonk::SetPredictorSize, this); |
| 88 | |
| 89 | text_predictor = new Text("00:0", Point(slider_predictor->GetWidth() + 17, 15)); |
| 90 | |
| 91 | text_predictor->SetX(group_predictor->GetWidth() - 10 - text_predictor->GetUnscaledTextWidth()); |
| 92 | slider_predictor->SetWidth(group_predictor->GetWidth() - 28 - text_predictor->GetUnscaledTextWidth()); |
| 93 | |
| 94 | group_predictor->Add(slider_predictor); |
| 95 | group_predictor->Add(text_predictor); |
| 96 | |
| 97 | SetPredictorSize(); |
| 98 | SetEncoderMode(); |
| 99 | |
| 100 | Add(group_quant); |
| 101 | Add(group_stereo); |
| 102 | Add(group_mode); |
| 103 | Add(group_downsampling); |
| 104 | Add(group_predictor); |
| 105 | |
| 106 | SetSize(Size(group_predictor->GetWidth() + 14, 171)); |
| 107 | } |
| 108 | |
| 109 | BoCA::ConfigureBonk::~ConfigureBonk() |
| 110 | { |
| 111 | DeleteObject(group_quant); |
| 112 | DeleteObject(slider_quant); |
| 113 | DeleteObject(text_quant); |
| 114 | DeleteObject(group_stereo); |
| 115 | DeleteObject(check_joint); |
| 116 | DeleteObject(group_mode); |
| 117 | DeleteObject(check_lossless); |
| 118 | DeleteObject(group_downsampling); |
| 119 | DeleteObject(slider_downsampling); |
| 120 | DeleteObject(text_downsampling); |
| 121 | DeleteObject(group_predictor); |
| 122 | DeleteObject(slider_predictor); |
| 123 | DeleteObject(text_predictor); |
| 124 | } |
| 125 | |
| 126 | Int BoCA::ConfigureBonk::SaveSettings() |
| 127 | { |
| 128 | Config *config = Config::Get(); |
| 129 | |
| 130 | config->SetIntValue(ConfigID, "Quantization", quant); |
| 131 | config->SetIntValue(ConfigID, "Predictor", predictor); |
| 132 | config->SetIntValue(ConfigID, "Downsampling", downsampling); |
| 133 | config->SetIntValue(ConfigID, "JointStereo", jstereo); |
| 134 | config->SetIntValue(ConfigID, "Lossless", lossless); |
| 135 | |
| 136 | return Success(); |
| 137 | } |
| 138 | |
| 139 | Void BoCA::ConfigureBonk::SetQuantization() |
| 140 | { |
| 141 | String val = String::FromFloat(0.05 * (double) quant); |
| 142 | |
| 143 | switch (val.Length()) |
| 144 | { |
| 145 | case 1: |
| 146 | val.Append(".00"); |
| 147 | break; |
| 148 | case 3: |
| 149 | val.Append("0"); |
| 150 | break; |
| 151 | } |
| 152 | |
| 153 | text_quant->SetText(val); |
| 154 | } |
| 155 | |
| 156 | Void BoCA::ConfigureBonk::SetPredictorSize() |
| 157 | { |
| 158 | text_predictor->SetText(String::FromInt(predictor)); |
| 159 | } |
| 160 | |
| 161 | Void BoCA::ConfigureBonk::SetDownsamplingRatio() |
| 162 | { |
| 163 | text_downsampling->SetText(String::FromInt(downsampling).Append(":1")); |
| 164 | } |
| 165 | |
| 166 | Void BoCA::ConfigureBonk::SetEncoderMode() |
| 167 | { |
| 168 | if (lossless) |
| 169 | { |
| 170 | group_quant->Deactivate(); |
| 171 | slider_quant->Deactivate(); |
| 172 | text_quant->Deactivate(); |
| 173 | |
| 174 | group_downsampling->Deactivate(); |
| 175 | slider_downsampling->Deactivate(); |
| 176 | text_downsampling->Deactivate(); |
| 177 | } |
| 178 | else |
| 179 | { |
| 180 | group_quant->Activate(); |
| 181 | slider_quant->Activate(); |
| 182 | text_quant->Activate(); |
| 183 | |
| 184 | group_downsampling->Activate(); |
| 185 | slider_downsampling->Activate(); |
| 186 | text_downsampling->Activate(); |
| 187 | } |
| 188 | } |