Debian Codegraph @

BambooTracker/gui/vgm_export_settings_dialog.cpp

raw
1 /*
2 * Copyright (C) 2018-2022 Rerrah
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "vgm_export_settings_dialog.hpp"
27 #include "ui_vgm_export_settings_dialog.h"
28 #include <QTextCodec>
29 #include "io/export_io.hpp"
30
31 VgmExportSettingsDialog::VgmExportSettingsDialog(QWidget *parent)
32 : QDialog(parent),
33 ui(new Ui::VgmExportSettingsDialog)
34 {
35 ui->setupUi(this);
36
37 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
38
39 for (QRadioButton *button : {
40 ui->ym2608RadioButton, ui->ym2612RadioButton, ui->ym2203RadioButton, ui->noneFmRadioButton,
41 ui->internalSsgRadioButton, ui->ay8910PsgRadioButton })
42 connect(button, &QAbstractButton::toggled,
43 this, &VgmExportSettingsDialog::updateSupportInformation);
44
45 updateSupportInformation();
46 }
47
48 VgmExportSettingsDialog::~VgmExportSettingsDialog()
49 {
50 delete ui;
51 }
52
53 bool VgmExportSettingsDialog::enabledGD3() const
54 {
55 return ui->gd3GroupBox->isChecked();
56 }
57
58 QString VgmExportSettingsDialog::getTrackNameEnglish() const
59 {
60 return ui->titleEnLineEdit->text();
61 }
62
63 QString VgmExportSettingsDialog::getTrackNameJapanese() const
64 {
65 return ui->titleJpLineEdit->text();
66 }
67
68 QString VgmExportSettingsDialog::getGameNameEnglish() const
69 {
70 return ui->nameEnLineEdit->text();
71 }
72
73 QString VgmExportSettingsDialog::getGameNameJapanese() const
74 {
75 return ui->nameJpLineEdit->text();
76 }
77
78 QString VgmExportSettingsDialog::getSystemNameEnglish() const
79 {
80 return ui->systemEnLineEdit->text();
81 }
82
83 QString VgmExportSettingsDialog::getSystemNameJapanese() const
84 {
85 return ui->systemJpLineEdit->text();
86 }
87
88 QString VgmExportSettingsDialog::getTrackAuthorEnglish() const
89 {
90 return ui->authorEnLineEdit->text();
91 }
92
93 QString VgmExportSettingsDialog::getTrackAuthorJapanese() const
94 {
95 return ui->authorJpLineEdit->text();
96 }
97
98 QString VgmExportSettingsDialog::getReleaseDate() const
99 {
100 return ui->releaseDateLineEdit->text();
101 }
102
103 QString VgmExportSettingsDialog::getVgmCreator() const
104 {
105 return ui->creatorLineEdit->text();
106 }
107
108 QString VgmExportSettingsDialog::getNotes() const
109 {
110 return ui->notesPlainTextEdit->toPlainText();
111 }
112
113 io::GD3Tag VgmExportSettingsDialog::getGD3Tag() const
114 {
115 io::GD3Tag tag;
116 QTextCodec* sjis = QTextCodec::codecForName("Shift-JIS");
117 std::string endNull = "";
118 endNull += '\0';
119 endNull += '\0';
120
121 const QByteArray trackNameEn = getTrackNameEnglish().toLatin1();
122 tag.trackNameEn = "";
123 for (const auto& c : trackNameEn) {
124 tag.trackNameEn += c;
125 tag.trackNameEn += '\0';
126 }
127 tag.trackNameEn += endNull;
128
129 const QByteArray trackNameJp = sjis->fromUnicode(getTrackNameJapanese());
130 tag.trackNameJp = "";
131 for (const auto& c : trackNameJp) {
132 tag.trackNameJp += c;
133 }
134 tag.trackNameJp += endNull;
135
136 const QByteArray gameNameEn = getGameNameEnglish().toLatin1();
137 tag.gameNameEn = "";
138 for (const auto& c : gameNameEn) {
139 tag.gameNameEn += c;
140 tag.gameNameEn += '\0';
141 }
142 tag.gameNameEn += endNull;
143
144 const QByteArray gameNameJp = sjis->fromUnicode(getGameNameJapanese());
145 tag.gameNameJp = "";
146 for (const auto& c : gameNameJp) {
147 tag.gameNameJp += c;
148 }
149 tag.gameNameJp += endNull;
150
151 const QByteArray systemNameEn = getSystemNameEnglish().toLatin1();
152 tag.systemNameEn = "";
153 for (const auto& c : systemNameEn) {
154 tag.systemNameEn += c;
155 tag.systemNameEn += '\0';
156 }
157 tag.systemNameEn += endNull;
158
159 const QByteArray systemNameJp = sjis->fromUnicode(getSystemNameJapanese());
160 tag.systemNameJp = "";
161 for (const auto& c : systemNameJp) {
162 tag.systemNameJp += c;
163 }
164 tag.systemNameJp += endNull;
165
166 const QByteArray authorEn = getTrackAuthorEnglish().toLatin1();
167 tag.authorEn = "";
168 for (const auto& c : authorEn) {
169 tag.authorEn += c;
170 tag.authorEn += '\0';
171 }
172 tag.authorEn += endNull;
173
174 const QByteArray authorJp = sjis->fromUnicode(getTrackAuthorJapanese());
175 tag.authorJp = "";
176 for (const auto& c : authorJp) {
177 tag.authorJp += c;
178 }
179 tag.authorJp += endNull;
180
181 const QByteArray releaseDate = getReleaseDate().toLatin1();
182 tag.releaseDate = "";
183 for (const auto& c : releaseDate) {
184 tag.releaseDate += c;
185 tag.releaseDate += '\0';
186 }
187 tag.releaseDate += endNull;
188
189 const QByteArray vgmCreator = getVgmCreator().toLatin1();
190 tag.vgmCreator = "";
191 for (const auto& c : vgmCreator) {
192 tag.vgmCreator += c;
193 tag.vgmCreator += '\0';
194 }
195 tag.vgmCreator += endNull;
196
197 const QByteArray notes = getNotes().toLatin1();
198 tag.notes = "";
199 for (const auto& c : notes) {
200 tag.notes += c;
201 tag.notes += '\0';
202 }
203 tag.notes += endNull;
204
205 return tag;
206 }
207
208 int VgmExportSettingsDialog::getExportTarget() const
209 {
210 int target = 0;
211
212 if (ui->ym2608RadioButton->isChecked())
213 target |= io::Export_YM2608;
214 else if (ui->ym2612RadioButton->isChecked())
215 target |= io::Export_YM2612;
216 else if (ui->ym2203RadioButton->isChecked())
217 target |= io::Export_YM2203;
218 else if (ui->ym2610bRadioButton->isChecked())
219 target |= io::Export_YM2610B;
220
221 if (ui->ay8910PsgRadioButton->isChecked())
222 target |= io::Export_AY8910Psg;
223 else if (ui->ym2149PsgRadioButton->isChecked())
224 target |= io::Export_YM2149Psg;
225
226 return target;
227 }
228
229 bool VgmExportSettingsDialog::isEnabledMix() const
230 {
231 return ui->mixGroupBox->isChecked();
232 }
233
234 double VgmExportSettingsDialog::getGain() const
235 {
236 return ui->gainDoubleSpinBox->value();
237 }
238
239 void VgmExportSettingsDialog::updateSupportInformation()
240 {
241 int target = getExportTarget();
242 int channels;
243
244 int fm = target & io::Export_FmMask;
245 int ssg = target & io::Export_SsgMask;
246
247 switch (fm) {
248 default:
249 channels = 6;
250 break;
251 case io::Export_YM2203:
252 channels = 3;
253 break;
254 case io::Export_NoneFm:
255 channels = 0;
256 break;
257 }
258
259 bool haveSsg = fm == io::Export_YM2608 || fm == io::Export_YM2203 || fm == io::Export_YM2610B || ssg != io::Export_InternalSsg;
260 bool haveRhythm = fm == io::Export_YM2608;
261 bool haveAdpcm = fm == io::Export_YM2608;
262
263 ui->supportFmChannelsLabel->setText(QString::number(channels));
264 ui->supportSsgLabel->setText(haveSsg ? tr("Yes") : tr("No"));
265 ui->supportRhythmLabel->setText(haveRhythm ? tr("Yes") : tr("No"));
266 ui->supportAdpcmLabel->setText(haveAdpcm ? tr("Yes") : tr("No"));
267
268 QPalette normalPalette = palette();
269 QPalette warnPalette = normalPalette;
270 warnPalette.setColor(QPalette::WindowText, QColor(0xef2929));
271
272 ui->supportFmChannelsLabel->setPalette((channels == 6) ? normalPalette : warnPalette);
273 ui->supportSsgLabel->setPalette(haveSsg ? normalPalette : warnPalette);
274 ui->supportRhythmLabel->setPalette(haveRhythm ? normalPalette : warnPalette);
275 ui->supportAdpcmLabel->setPalette(haveAdpcm ? normalPalette : warnPalette);
276 }