Debian Codegraph @

BambooTracker/gui/wave_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 "wave_export_settings_dialog.hpp"
27 #include "ui_wave_export_settings_dialog.h"
28 #include <algorithm>
29 #include <QListWidgetItem>
30 #include "gui/gui_utils.hpp"
31 #include "song.hpp"
32
33 WaveExportSettingsDialog::WaveExportSettingsDialog(const std::vector<int> defUnmutes, QWidget *parent) :
34 QDialog(parent),
35 ui(new Ui::WaveExportSettingsDialog)
36 {
37 ui->setupUi(this);
38
39 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
40
41 constexpr uint32_t SAMPLE_RATES[] = { 8000, 16000, 22050, 32000, 44100, 48000, 55466, 96000, 192000, 249600 };
42 constexpr uint32_t DEFAULT_RATE = 44100;
43 for (auto rate : SAMPLE_RATES) {
44 ui->sampleRateComboBox->addItem(QString("%1Hz").arg(rate), rate);
45 if (rate == DEFAULT_RATE) {
46 ui->sampleRateComboBox->setCurrentIndex(ui->sampleRateComboBox->count() - 1);
47 }
48 }
49
50 struct Pair
51 {
52 SoundSource src;
53 int count;
54 };
55 static const QList<Pair> SRC_NUMS = {
56 { SoundSource::FM, 6 }, { SoundSource::SSG, 3 }, { SoundSource::RHYTHM, 6 }, { SoundSource::ADPCM, 1 }
57 };
58
59 int tmpT = 0;
60 for (const auto& pair : SRC_NUMS) {
61 for (int i = 0; i < pair.count; ++i, ++tmpT) {
62 auto item = new QListWidgetItem(gui_utils::getTrackName(SongType::Standard, pair.src, i), ui->tracksListWidget);
63 item->setCheckState(std::any_of(defUnmutes.begin(), defUnmutes.end(), [tmpT](const int t) { return t == tmpT; })
64 ? Qt::Checked : Qt::Unchecked);
65 }
66 }
67 }
68
69 WaveExportSettingsDialog::~WaveExportSettingsDialog()
70 {
71 delete ui;
72 }
73
74 int WaveExportSettingsDialog::getSampleRate() const
75 {
76 return ui->sampleRateComboBox->currentData().toInt();
77 }
78
79 int WaveExportSettingsDialog::getLoopCount() const
80 {
81 return ui->loopSpinBox->value();
82 }
83
84 std::vector<int> WaveExportSettingsDialog::getSoloExportTracks() const
85 {
86 if (!ui->tracksGroupBox->isChecked()) return {};
87
88 std::vector<int> tracks;
89 for (int i = 0; i < ui->tracksListWidget->count(); ++i) {
90 if (ui->tracksListWidget->item(i)->checkState() == Qt::Checked)
91 tracks.push_back(i);
92 }
93 return tracks;
94 }
95
96 void WaveExportSettingsDialog::on_reversePushButton_clicked()
97 {
98 for (int i = 0; i < ui->tracksListWidget->count(); ++i) {
99 auto item = ui->tracksListWidget->item(i);
100 item->setCheckState((item->checkState() == Qt::Checked) ? Qt::Unchecked : Qt::Checked);
101 }
102 }
103
104 void WaveExportSettingsDialog::on_allPushButton_clicked()
105 {
106 for (int i = 0; i < ui->tracksListWidget->count(); ++i) {
107 auto item = ui->tracksListWidget->item(i);
108 item->setCheckState(Qt::Checked);
109 }
110 }