|
17 | 17 | #include <QTreeView> |
18 | 18 | #include <QVBoxLayout> |
19 | 19 |
|
| 20 | +#include <SVSCraftCore/MusicModeInfo.h> |
| 21 | + |
20 | 22 | #include <midiformatconverter/internal/MIDITextCodecConverter.h> |
21 | 23 |
|
22 | 24 | namespace MIDIFormatConverter::Internal { |
@@ -91,6 +93,27 @@ namespace MIDIFormatConverter::Internal { |
91 | 93 | importTimeSignatureCheckBox->setChecked(importTimeSignature); |
92 | 94 | optionsLayout->addWidget(importTimeSignatureCheckBox); |
93 | 95 |
|
| 96 | + auto *keySignatureLayout = new QHBoxLayout; |
| 97 | + autoDetectKeySignatureCheckBox = new QCheckBox(MIDIFormatConverter::Internal::MIDITrackSelectorDialog::tr("Automatically detect key signature"), optionsGroup); |
| 98 | + autoDetectKeySignatureCheckBox->setChecked(autoDetectKeySignature); |
| 99 | + keySignatureLayout->addWidget(autoDetectKeySignatureCheckBox); |
| 100 | + |
| 101 | + musicModeComboBox = new QComboBox(optionsGroup); |
| 102 | + for (const auto &[mode, name] : SVS::MusicModeInfo::getBuiltInMusicModeInfoList()) { |
| 103 | + musicModeComboBox->addItem(name, mode.mask()); |
| 104 | + } |
| 105 | + musicModeComboBox->setCurrentIndex(musicModeComboBox->findData(musicMode)); |
| 106 | + musicModeComboBox->setEnabled(autoDetectKeySignature); |
| 107 | + keySignatureLayout->addWidget(musicModeComboBox, 1); |
| 108 | + |
| 109 | + accidentalTypeComboBox = new QComboBox(optionsGroup); |
| 110 | + accidentalTypeComboBox->addItem(MIDIFormatConverter::Internal::MIDITrackSelectorDialog::tr("Flat"), 0); |
| 111 | + accidentalTypeComboBox->addItem(MIDIFormatConverter::Internal::MIDITrackSelectorDialog::tr("Sharp"), 1); |
| 112 | + accidentalTypeComboBox->setCurrentIndex(accidentalTypeComboBox->findData(accidentalType)); |
| 113 | + accidentalTypeComboBox->setEnabled(autoDetectKeySignature); |
| 114 | + keySignatureLayout->addWidget(accidentalTypeComboBox); |
| 115 | + optionsLayout->addLayout(keySignatureLayout); |
| 116 | + |
94 | 117 | mainLayout->addWidget(optionsGroup); |
95 | 118 |
|
96 | 119 | auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, q); |
@@ -132,6 +155,25 @@ namespace MIDIFormatConverter::Internal { |
132 | 155 | Q_Q(MIDITrackSelectorDialog); |
133 | 156 | q->setImportTimeSignature(checked); |
134 | 157 | }); |
| 158 | + |
| 159 | + QObject::connect(autoDetectKeySignatureCheckBox, &QCheckBox::toggled, q, [this](bool checked) { |
| 160 | + Q_Q(MIDITrackSelectorDialog); |
| 161 | + q->setAutoDetectKeySignature(checked); |
| 162 | + }); |
| 163 | + |
| 164 | + QObject::connect(musicModeComboBox, &QComboBox::currentIndexChanged, q, [this](int index) { |
| 165 | + if (index < 0) |
| 166 | + return; |
| 167 | + Q_Q(MIDITrackSelectorDialog); |
| 168 | + q->setMusicMode(musicModeComboBox->itemData(index).toInt()); |
| 169 | + }); |
| 170 | + |
| 171 | + QObject::connect(accidentalTypeComboBox, &QComboBox::currentIndexChanged, q, [this](int index) { |
| 172 | + if (index < 0) |
| 173 | + return; |
| 174 | + Q_Q(MIDITrackSelectorDialog); |
| 175 | + q->setAccidentalType(accidentalTypeComboBox->itemData(index).toInt()); |
| 176 | + }); |
135 | 177 | q->resize(640, 480); |
136 | 178 | } |
137 | 179 |
|
@@ -431,6 +473,61 @@ namespace MIDIFormatConverter::Internal { |
431 | 473 | emit importTimeSignatureChanged(enabled); |
432 | 474 | } |
433 | 475 |
|
| 476 | + bool MIDITrackSelectorDialog::autoDetectKeySignature() const { |
| 477 | + Q_D(const MIDITrackSelectorDialog); |
| 478 | + return d->autoDetectKeySignature; |
| 479 | + } |
| 480 | + |
| 481 | + void MIDITrackSelectorDialog::setAutoDetectKeySignature(bool enabled) { |
| 482 | + Q_D(MIDITrackSelectorDialog); |
| 483 | + if (d->autoDetectKeySignature == enabled) |
| 484 | + return; |
| 485 | + d->autoDetectKeySignature = enabled; |
| 486 | + if (d->autoDetectKeySignatureCheckBox) { |
| 487 | + QSignalBlocker blocker(d->autoDetectKeySignatureCheckBox); |
| 488 | + d->autoDetectKeySignatureCheckBox->setChecked(enabled); |
| 489 | + } |
| 490 | + if (d->musicModeComboBox) |
| 491 | + d->musicModeComboBox->setEnabled(enabled); |
| 492 | + if (d->accidentalTypeComboBox) |
| 493 | + d->accidentalTypeComboBox->setEnabled(enabled); |
| 494 | + emit autoDetectKeySignatureChanged(enabled); |
| 495 | + } |
| 496 | + |
| 497 | + int MIDITrackSelectorDialog::musicMode() const { |
| 498 | + Q_D(const MIDITrackSelectorDialog); |
| 499 | + return d->musicMode; |
| 500 | + } |
| 501 | + |
| 502 | + void MIDITrackSelectorDialog::setMusicMode(int mode) { |
| 503 | + Q_D(MIDITrackSelectorDialog); |
| 504 | + if (d->musicMode == mode) |
| 505 | + return; |
| 506 | + d->musicMode = mode; |
| 507 | + if (d->musicModeComboBox) { |
| 508 | + QSignalBlocker blocker(d->musicModeComboBox); |
| 509 | + d->musicModeComboBox->setCurrentIndex(d->musicModeComboBox->findData(mode)); |
| 510 | + } |
| 511 | + emit musicModeChanged(mode); |
| 512 | + } |
| 513 | + |
| 514 | + int MIDITrackSelectorDialog::accidentalType() const { |
| 515 | + Q_D(const MIDITrackSelectorDialog); |
| 516 | + return d->accidentalType; |
| 517 | + } |
| 518 | + |
| 519 | + void MIDITrackSelectorDialog::setAccidentalType(int accidentalType) { |
| 520 | + Q_D(MIDITrackSelectorDialog); |
| 521 | + if (d->accidentalType == accidentalType) |
| 522 | + return; |
| 523 | + d->accidentalType = accidentalType; |
| 524 | + if (d->accidentalTypeComboBox) { |
| 525 | + QSignalBlocker blocker(d->accidentalTypeComboBox); |
| 526 | + d->accidentalTypeComboBox->setCurrentIndex(d->accidentalTypeComboBox->findData(accidentalType)); |
| 527 | + } |
| 528 | + emit accidentalTypeChanged(accidentalType); |
| 529 | + } |
| 530 | + |
434 | 531 | void MIDITrackSelectorDialog::detectCodec() { |
435 | 532 | Q_D(MIDITrackSelectorDialog); |
436 | 533 | const QByteArray combined = d->aggregateLyricsForDetection(); |
|
0 commit comments