Debian Codegraph @

BambooTracker/gui/instrument_editor/adpcm_instrument_editor.cpp

raw
1 /*
2 * Copyright (C) 2020-2023 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 "adpcm_instrument_editor.hpp"
27 #include "ui_adpcm_instrument_editor.h"
28 #include <set>
29 #include "instrument.hpp"
30 #include "gui/event_guard.hpp"
31 #include "gui/jam_layout.hpp"
32 #include "gui/instrument_editor/instrument_editor_utils.hpp"
33
34 AdpcmInstrumentEditor::AdpcmInstrumentEditor(int num, QWidget* parent)
35 : InstrumentEditor(num, parent),
36 ui(new Ui::AdpcmInstrumentEditor),
37 isIgnoreEvent_(false)
38 {
39 ui->setupUi(this);
40
41 //========== Sample ==========//
42 QObject::connect(ui->sampleEditor, &ADPCMSampleEditor::modified, this, [&] { emit modified(); });
43 QObject::connect(ui->sampleEditor, &ADPCMSampleEditor::sampleNumberChanged,
44 this, [&](int n) {
45 bt_.lock()->setInstrumentADPCMSample(instNum_, n);
46 setInstrumentSampleParameters();
47 emit sampleNumberChanged();
48 emit modified();
49
50 if (config_.lock()->getWriteOnlyUsedSamples()) {
51 emit sampleAssignRequested();
52 }
53 }, Qt::DirectConnection);
54 QObject::connect(ui->sampleEditor, &ADPCMSampleEditor::sampleParameterChanged,
55 this, [&](int sampNum) {
56 emit sampleParameterChanged(sampNum, instNum_);
57 });
58 QObject::connect(ui->sampleEditor, &ADPCMSampleEditor::sampleAssignRequested,
59 this, [&] { emit sampleAssignRequested(); });
60 QObject::connect(ui->sampleEditor, &ADPCMSampleEditor::sampleMemoryChanged,
61 this, [&] { emit sampleMemoryChanged(); });
62
63 //========== Envelope ==========//
64 ui->envEditor->setMaximumDisplayedRowCount(64);
65 ui->envEditor->setDefaultRow(255);
66 ui->envEditor->setLabelDiaplayMode(true);
67 for (int i = 0; i < 256; ++i) {
68 ui->envEditor->AddRow(QString::number(i), false);
69 }
70 ui->envEditor->autoFitLabelWidth();
71 ui->envEditor->setUpperRow(255);
72 ui->envEditor->setMultipleReleaseState(true);
73 ui->envEditor->setPermittedReleaseTypes(
74 VisualizedInstrumentMacroEditor::PermittedReleaseFlag::ABSOLUTE_RELEASE
75 | VisualizedInstrumentMacroEditor::PermittedReleaseFlag::RELATIVE_RELEASE
76 | VisualizedInstrumentMacroEditor::PermittedReleaseFlag::FIXED_RELEASE);
77
78 QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::sequenceDataAdded,
79 this, [&](int row, int) {
80 if (!isIgnoreEvent_) {
81 bt_.lock()->addEnvelopeADPCMSequenceData(ui->envNumSpinBox->value(), row);
82 emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_);
83 emit modified();
84 }
85 });
86 QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::sequenceDataRemoved,
87 this, [&] {
88 if (!isIgnoreEvent_) {
89 bt_.lock()->removeEnvelopeADPCMSequenceData(ui->envNumSpinBox->value());
90 emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_);
91 emit modified();
92 }
93 });
94 QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::sequenceDataChanged,
95 this, [&](int row, int col) {
96 if (!isIgnoreEvent_) {
97 bt_.lock()->setEnvelopeADPCMSequenceData(ui->envNumSpinBox->value(), col, row);
98 emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_);
99 emit modified();
100 }
101 });
102 QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::loopAdded,
103 this, [&](InstrumentSequenceLoop loop) {
104 if (!isIgnoreEvent_) {
105 bt_.lock()->addEnvelopeADPCMLoop(ui->envNumSpinBox->value(), loop);
106 emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_);
107 emit modified();
108 }
109 });
110 QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::loopRemoved,
111 this, [&](int begin, int end) {
112 if (!isIgnoreEvent_) {
113 bt_.lock()->removeEnvelopeADPCMLoop(ui->envNumSpinBox->value(), begin, end);
114 emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_);
115 emit modified();
116 }
117 });
118 QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::loopCleared,
119 this, [&] {
120 if (!isIgnoreEvent_) {
121 bt_.lock()->clearEnvelopeADPCMLoops(ui->envNumSpinBox->value());
122 emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_);
123 emit modified();
124 }
125 });
126 QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::loopChanged,
127 this, [&](int prevBegin, int prevEnd, InstrumentSequenceLoop loop) {
128 if (!isIgnoreEvent_) {
129 bt_.lock()->changeEnvelopeADPCMLoop(ui->envNumSpinBox->value(), prevBegin, prevEnd, loop);
130 emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_);
131 emit modified();
132 }
133 });
134 QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::releaseChanged,
135 this, [&](InstrumentSequenceRelease release) {
136 if (!isIgnoreEvent_) {
137 bt_.lock()->setEnvelopeADPCMRelease(ui->envNumSpinBox->value(), release);
138 emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_);
139 emit modified();
140 }
141 });
142
143 //========== Arpeggio ==========//
144 ui->arpTypeComboBox->addItem(tr("Absolute"), static_cast<int>(SequenceType::AbsoluteSequence));
145 ui->arpTypeComboBox->addItem(tr("Fixed"), static_cast<int>(SequenceType::FixedSequence));
146 ui->arpTypeComboBox->addItem(tr("Relative"), static_cast<int>(SequenceType::RelativeSequence));
147
148 QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::sequenceDataAdded,
149 this, [&](int row, int) {
150 if (!isIgnoreEvent_) {
151 bt_.lock()->addArpeggioADPCMSequenceData(ui->arpNumSpinBox->value(), row);
152 emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_);
153 emit modified();
154 }
155 });
156 QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::sequenceDataRemoved,
157 this, [&] {
158 if (!isIgnoreEvent_) {
159 bt_.lock()->removeArpeggioADPCMSequenceData(ui->arpNumSpinBox->value());
160 emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_);
161 emit modified();
162 }
163 });
164 QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::sequenceDataChanged,
165 this, [&](int row, int col) {
166 if (!isIgnoreEvent_) {
167 bt_.lock()->setArpeggioADPCMSequenceData(ui->arpNumSpinBox->value(), col, row);
168 emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_);
169 emit modified();
170 }
171 });
172 QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::loopAdded,
173 this, [&](InstrumentSequenceLoop loop) {
174 if (!isIgnoreEvent_) {
175 bt_.lock()->addArpeggioADPCMLoop(ui->arpNumSpinBox->value(), loop);
176 emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_);
177 emit modified();
178 }
179 });
180 QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::loopRemoved,
181 this, [&](int begin, int end) {
182 if (!isIgnoreEvent_) {
183 bt_.lock()->removeArpeggioADPCMLoop(ui->arpNumSpinBox->value(), begin, end);
184 emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_);
185 emit modified();
186 }
187 });
188 QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::loopCleared,
189 this, [&] {
190 if (!isIgnoreEvent_) {
191 bt_.lock()->clearArpeggioADPCMLoops(ui->arpNumSpinBox->value());
192 emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_);
193 emit modified();
194 }
195 });
196 QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::loopChanged,
197 this, [&](int prevBegin, int prevEnd, InstrumentSequenceLoop loop) {
198 if (!isIgnoreEvent_) {
199 bt_.lock()->changeArpeggioADPCMLoop(ui->arpNumSpinBox->value(), prevBegin, prevEnd, loop);
200 emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_);
201 emit modified();
202 }
203 });
204 QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::releaseChanged,
205 this, [&](InstrumentSequenceRelease release) {
206 if (!isIgnoreEvent_) {
207 bt_.lock()->setArpeggioADPCMRelease(ui->arpNumSpinBox->value(), release);
208 emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_);
209 emit modified();
210 }
211 });
212 // Leave Before Qt5.7.0 style due to windows xp
213 QObject::connect(ui->arpTypeComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
214 this, &AdpcmInstrumentEditor::onArpeggioTypeChanged);
215
216 //========== Pitch ==========//
217 ui->ptEditor->setMaximumDisplayedRowCount(15);
218 ui->ptEditor->setDefaultRow(127);
219 ui->ptEditor->setLabelDiaplayMode(true);
220 for (int i = 0; i < 255; ++i) {
221 ui->ptEditor->AddRow(QString::asprintf("%+d", i - 127), false);
222 }
223 ui->ptEditor->autoFitLabelWidth();
224 ui->ptEditor->setUpperRow(134);
225 ui->ptEditor->setMMLDisplay0As(-127);
226
227 ui->ptTypeComboBox->addItem(tr("Absolute"), static_cast<int>(SequenceType::AbsoluteSequence));
228 ui->ptTypeComboBox->addItem(tr("Relative"), static_cast<int>(SequenceType::RelativeSequence));
229
230 QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::sequenceDataAdded,
231 this, [&](int row, int) {
232 if (!isIgnoreEvent_) {
233 bt_.lock()->addPitchADPCMSequenceData(ui->ptNumSpinBox->value(), row);
234 emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_);
235 emit modified();
236 }
237 });
238 QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::sequenceDataRemoved,
239 this, [&] {
240 if (!isIgnoreEvent_) {
241 bt_.lock()->removePitchADPCMSequenceData(ui->ptNumSpinBox->value());
242 emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_);
243 emit modified();
244 }
245 });
246 QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::sequenceDataChanged,
247 this, [&](int row, int col) {
248 if (!isIgnoreEvent_) {
249 bt_.lock()->setPitchADPCMSequenceData(ui->ptNumSpinBox->value(), col, row);
250 emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_);
251 emit modified();
252 }
253 });
254 QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::loopAdded,
255 this, [&](InstrumentSequenceLoop loop) {
256 if (!isIgnoreEvent_) {
257 bt_.lock()->addPitchADPCMLoop(ui->ptNumSpinBox->value(), loop);
258 emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_);
259 emit modified();
260 }
261 });
262 QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::loopRemoved,
263 this, [&](int begin, int end) {
264 if (!isIgnoreEvent_) {
265 bt_.lock()->removePitchADPCMLoop(ui->ptNumSpinBox->value(), begin, end);
266 emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_);
267 emit modified();
268 }
269 });
270 QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::loopCleared,
271 this, [&] {
272 if (!isIgnoreEvent_) {
273 bt_.lock()->clearPitchADPCMLoops(ui->ptNumSpinBox->value());
274 emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_);
275 emit modified();
276 }
277 });
278 QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::loopChanged,
279 this, [&](int prevBegin, int prevEnd, InstrumentSequenceLoop loop) {
280 if (!isIgnoreEvent_) {
281 bt_.lock()->changePitchADPCMLoop(ui->ptNumSpinBox->value(), prevBegin, prevEnd, loop);
282 emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_);
283 emit modified();
284 }
285 });
286 QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::releaseChanged,
287 this, [&](InstrumentSequenceRelease release) {
288 if (!isIgnoreEvent_) {
289 bt_.lock()->setPitchADPCMRelease(ui->ptNumSpinBox->value(), release);
290 emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_);
291 emit modified();
292 }
293 });
294 // Leave Before Qt5.7.0 style due to windows xp
295 QObject::connect(ui->ptTypeComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
296 this, &AdpcmInstrumentEditor::onPitchTypeChanged);
297
298 //========== Pan ==========//
299 QObject::connect(ui->panEditor, &VisualizedInstrumentMacroEditor::sequenceDataAdded,
300 this, [&](int row, int) {
301 if (!isIgnoreEvent_) {
302 bt_.lock()->addPanADPCMSequenceData(ui->panNumSpinBox->value(), row);
303 emit panParameterChanged(ui->panNumSpinBox->value(), instNum_);
304 emit modified();
305 }
306 });
307 QObject::connect(ui->panEditor, &VisualizedInstrumentMacroEditor::sequenceDataRemoved,
308 this, [&] {
309 if (!isIgnoreEvent_) {
310 bt_.lock()->removePanADPCMSequenceData(ui->panNumSpinBox->value());
311 emit panParameterChanged(ui->panNumSpinBox->value(), instNum_);
312 emit modified();
313 }
314 });
315 QObject::connect(ui->panEditor, &VisualizedInstrumentMacroEditor::sequenceDataChanged,
316 this, [&](int row, int col) {
317 if (!isIgnoreEvent_) {
318 bt_.lock()->setPanADPCMSequenceData(ui->panNumSpinBox->value(), col, row);
319 emit panParameterChanged(ui->panNumSpinBox->value(), instNum_);
320 emit modified();
321 }
322 });
323 QObject::connect(ui->panEditor, &VisualizedInstrumentMacroEditor::loopAdded,
324 this, [&](InstrumentSequenceLoop loop) {
325 if (!isIgnoreEvent_) {
326 bt_.lock()->addPanADPCMLoop(ui->panNumSpinBox->value(), loop);
327 emit panParameterChanged(ui->panNumSpinBox->value(), instNum_);
328 emit modified();
329 }
330 });
331 QObject::connect(ui->panEditor, &VisualizedInstrumentMacroEditor::loopRemoved,
332 this, [&](int begin, int end) {
333 if (!isIgnoreEvent_) {
334 bt_.lock()->removePanADPCMLoop(ui->panNumSpinBox->value(), begin, end);
335 emit panParameterChanged(ui->panNumSpinBox->value(), instNum_);
336 emit modified();
337 }
338 });
339 QObject::connect(ui->panEditor, &VisualizedInstrumentMacroEditor::loopCleared,
340 this, [&] {
341 if (!isIgnoreEvent_) {
342 bt_.lock()->clearPanADPCMLoops(ui->panNumSpinBox->value());
343 emit panParameterChanged(ui->panNumSpinBox->value(), instNum_);
344 emit modified();
345 }
346 });
347 QObject::connect(ui->panEditor, &VisualizedInstrumentMacroEditor::loopChanged,
348 this, [&](int prevBegin, int prevEnd, InstrumentSequenceLoop loop) {
349 if (!isIgnoreEvent_) {
350 bt_.lock()->changePanADPCMLoop(ui->panNumSpinBox->value(), prevBegin, prevEnd, loop);
351 emit panParameterChanged(ui->panNumSpinBox->value(), instNum_);
352 emit modified();
353 }
354 });
355 QObject::connect(ui->panEditor, &VisualizedInstrumentMacroEditor::releaseChanged,
356 this, [&](InstrumentSequenceRelease release) {
357 if (!isIgnoreEvent_) {
358 bt_.lock()->setPanADPCMRelease(ui->panNumSpinBox->value(), release);
359 emit panParameterChanged(ui->panNumSpinBox->value(), instNum_);
360 emit modified();
361 }
362 });
363 }
364
365 AdpcmInstrumentEditor::~AdpcmInstrumentEditor()
366 {
367 delete ui;
368 }
369
370 SoundSource AdpcmInstrumentEditor::getSoundSource() const
371 {
372 return SoundSource::ADPCM;
373 }
374
375 InstrumentType AdpcmInstrumentEditor::getInstrumentType() const
376 {
377 return InstrumentType::ADPCM;
378 }
379
380 void AdpcmInstrumentEditor::updateByConfigurationChange()
381 {
382 ui->sampleEditor->onNoteNamesUpdated();
383 ui->arpEditor->onNoteNamesUpdated();
384 }
385
386 void AdpcmInstrumentEditor::updateBySettingCore()
387 {
388 ui->sampleEditor->setCore(bt_);
389 updateInstrumentParameters();
390 }
391
392 void AdpcmInstrumentEditor::updateBySettingConfiguration()
393 {
394 ui->sampleEditor->setConfiguration(config_);
395 }
396
397 void AdpcmInstrumentEditor::updateBySettingColorPalette()
398 {
399 ui->sampleEditor->setColorPalette(palette_);
400 ui->envEditor->setColorPalette(palette_);
401 ui->arpEditor->setColorPalette(palette_);
402 ui->ptEditor->setColorPalette(palette_);
403 ui->panEditor->setColorPalette(palette_);
404 }
405
406 void AdpcmInstrumentEditor::updateInstrumentParameters()
407 {
408 Ui::EventGuard eg(isIgnoreEvent_);
409
410 updateWindowTitle();
411
412 setInstrumentSampleParameters();
413 setInstrumentEnvelopeParameters();
414 setInstrumentArpeggioParameters();
415 setInstrumentPitchParameters();
416 setInstrumentPanParameters();
417 }
418
419 /********** Events **********/
420 // MUST DIRECT CONNECTION
421 void AdpcmInstrumentEditor::keyPressEvent(QKeyEvent *event)
422 {
423 // General keys
424 switch (event->key()) {
425 case Qt::Key_Escape:
426 close();
427 break;
428 default:
429 // For jam key on
430 if (!event->isAutoRepeat()) {
431 // Musical keyboard
432 Qt::Key qtKey = static_cast<Qt::Key>(event->key());
433 try {
434 JamKey jk = getJamKeyFromLayoutMapping(qtKey, config_);
435 emit jamKeyOnEvent(jk);
436 } catch (std::invalid_argument&) {}
437 }
438 break;
439 }
440 }
441
442 // MUST DIRECT CONNECTION
443 void AdpcmInstrumentEditor::keyReleaseEvent(QKeyEvent *event)
444 {
445 // For jam key off
446 if (!event->isAutoRepeat()) {
447 Qt::Key qtKey = static_cast<Qt::Key>(event->key());
448 try {
449 JamKey jk = getJamKeyFromLayoutMapping(qtKey, config_);
450 emit jamKeyOffEvent(jk);
451 } catch (std::invalid_argument&) {}
452 }
453 }
454
455 //--- Sample
456 void AdpcmInstrumentEditor::setInstrumentSampleParameters()
457 {
458 std::unique_ptr<AbstractInstrument> inst = bt_.lock()->getInstrument(instNum_);
459 auto instADPCM = dynamic_cast<InstrumentADPCM*>(inst.get());
460
461 ui->sampleEditor->setInstrumentSampleParameters(
462 instADPCM->getSampleNumber(),
463 instADPCM->isSampleRepeatable(),
464 instADPCM->getSampleRepeatRange(),
465 instADPCM->getSampleRootKeyNumber(),
466 instADPCM->getSampleRootDeltaN(),
467 instADPCM->getSampleStartAddress(),
468 instADPCM->getSampleStopAddress(),
469 instADPCM->getRawSample());
470 }
471
472 /********** Slots **********/
473 void AdpcmInstrumentEditor::onSampleNumberChanged()
474 {
475 ui->sampleEditor->onSampleNumberChanged();
476 }
477
478 void AdpcmInstrumentEditor::onSampleParameterChanged(int sampNum)
479 {
480 if (ui->sampleEditor->getSampleNumber() == sampNum) {
481 setInstrumentSampleParameters();
482 }
483 }
484
485 void AdpcmInstrumentEditor::onSampleMemoryUpdated()
486 {
487 std::unique_ptr<AbstractInstrument> inst = bt_.lock()->getInstrument(instNum_);
488 auto instADPCM = dynamic_cast<InstrumentADPCM*>(inst.get());
489
490 ui->sampleEditor->onSampleMemoryUpdated(instADPCM->getSampleStartAddress(), instADPCM->getSampleStopAddress());
491 }
492
493 //--- Envelope
494 void AdpcmInstrumentEditor::setInstrumentEnvelopeParameters()
495 {
496 Ui::EventGuard ev(isIgnoreEvent_);
497
498 std::unique_ptr<AbstractInstrument> inst = bt_.lock()->getInstrument(instNum_);
499 auto instADPCM = dynamic_cast<InstrumentADPCM*>(inst.get());
500
501 ui->envNumSpinBox->setValue(instADPCM->getEnvelopeNumber());
502 ui->envEditor->clearData();
503 for (auto& unit : instADPCM->getEnvelopeSequence()) {
504 ui->envEditor->addSequenceData(unit.data);
505 }
506 for (auto& loop : instADPCM->getEnvelopeLoopRoot().getAllLoops()) {
507 ui->envEditor->addLoop(loop.getBeginPos(), loop.getEndPos(), loop.getTimes());
508 }
509 ui->envEditor->setRelease(instADPCM->getEnvelopeRelease());
510 if (instADPCM->getEnvelopeEnabled()) {
511 ui->envEditGroupBox->setChecked(true);
512 onEnvelopeNumberChanged();
513 }
514 else {
515 ui->envEditGroupBox->setChecked(false);
516 }
517 }
518
519 /********** Slots **********/
520 void AdpcmInstrumentEditor::onEnvelopeNumberChanged()
521 {
522 // Change users view
523 std::multiset<int> users = bt_.lock()->getEnvelopeADPCMUsers(ui->envNumSpinBox->value());
524 ui->envUsersLineEdit->setText(inst_edit_utils::generateUsersString(users));
525 }
526
527 void AdpcmInstrumentEditor::onEnvelopeParameterChanged(int envNum)
528 {
529 if (ui->envNumSpinBox->value() == envNum) {
530 Ui::EventGuard eg(isIgnoreEvent_);
531 setInstrumentEnvelopeParameters();
532 }
533 }
534
535 void AdpcmInstrumentEditor::on_envEditGroupBox_toggled(bool arg1)
536 {
537 if (!isIgnoreEvent_) {
538 bt_.lock()->setInstrumentADPCMEnvelopeEnabled(instNum_, arg1);
539 setInstrumentEnvelopeParameters();
540 emit envelopeNumberChanged();
541 emit modified();
542 }
543
544 onEnvelopeNumberChanged();
545 }
546
547 void AdpcmInstrumentEditor::on_envNumSpinBox_valueChanged(int arg1)
548 {
549 if (!isIgnoreEvent_) {
550 bt_.lock()->setInstrumentADPCMEnvelope(instNum_, arg1);
551 setInstrumentEnvelopeParameters();
552 emit envelopeNumberChanged();
553 emit modified();
554 }
555
556 onEnvelopeNumberChanged();
557 }
558
559 //--- Arpeggio
560 void AdpcmInstrumentEditor::setInstrumentArpeggioParameters()
561 {
562 Ui::EventGuard ev(isIgnoreEvent_);
563
564 std::unique_ptr<AbstractInstrument> inst = bt_.lock()->getInstrument(instNum_);
565 auto instADPCM = dynamic_cast<InstrumentADPCM*>(inst.get());
566
567 ui->arpNumSpinBox->setValue(instADPCM->getArpeggioNumber());
568 ui->arpEditor->clearData();
569 for (auto& unit : instADPCM->getArpeggioSequence()) {
570 ui->arpEditor->addSequenceData(unit.data);
571 }
572 for (auto& loop : instADPCM->getArpeggioLoopRoot().getAllLoops()) {
573 ui->arpEditor->addLoop(loop.getBeginPos(), loop.getEndPos(), loop.getTimes());
574 }
575 ui->arpEditor->setRelease(instADPCM->getArpeggioRelease());
576 for (int i = 0; i < ui->arpTypeComboBox->count(); ++i) {
577 if (instADPCM->getArpeggioType() == static_cast<SequenceType>(ui->arpTypeComboBox->itemData(i).toInt())) {
578 ui->arpTypeComboBox->setCurrentIndex(i);
579 break;
580 }
581 }
582 if (instADPCM->getArpeggioEnabled()) {
583 ui->arpEditGroupBox->setChecked(true);
584 onArpeggioNumberChanged();
585 }
586 else {
587 ui->arpEditGroupBox->setChecked(false);
588 }
589 }
590
591 /********** Slots **********/
592 void AdpcmInstrumentEditor::onArpeggioNumberChanged()
593 {
594 // Change users view
595 std::multiset<int> users = bt_.lock()->getArpeggioADPCMUsers(ui->arpNumSpinBox->value());
596 ui->arpUsersLineEdit->setText(inst_edit_utils::generateUsersString(users));
597 }
598
599 void AdpcmInstrumentEditor::onArpeggioParameterChanged(int tnNum)
600 {
601 if (ui->arpNumSpinBox->value() == tnNum) {
602 Ui::EventGuard eg(isIgnoreEvent_);
603 setInstrumentArpeggioParameters();
604 }
605 }
606
607 void AdpcmInstrumentEditor::onArpeggioTypeChanged(int)
608 {
609 auto type = static_cast<SequenceType>(ui->arpTypeComboBox->currentData(Qt::UserRole).toInt());
610 if (!isIgnoreEvent_) {
611 bt_.lock()->setArpeggioADPCMType(ui->arpNumSpinBox->value(), type);
612 emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_);
613 emit modified();
614 }
615
616 ui->arpEditor->setSequenceType(type);
617 }
618
619 void AdpcmInstrumentEditor::on_arpEditGroupBox_toggled(bool arg1)
620 {
621 if (!isIgnoreEvent_) {
622 bt_.lock()->setInstrumentADPCMArpeggioEnabled(instNum_, arg1);
623 setInstrumentArpeggioParameters();
624 emit arpeggioNumberChanged();
625 emit modified();
626 }
627
628 onArpeggioNumberChanged();
629 }
630
631 void AdpcmInstrumentEditor::on_arpNumSpinBox_valueChanged(int arg1)
632 {
633 if (!isIgnoreEvent_) {
634 bt_.lock()->setInstrumentADPCMArpeggio(instNum_, arg1);
635 setInstrumentArpeggioParameters();
636 emit arpeggioNumberChanged();
637 emit modified();
638 }
639
640 onArpeggioNumberChanged();
641 }
642
643 //--- Pitch
644 void AdpcmInstrumentEditor::setInstrumentPitchParameters()
645 {
646 Ui::EventGuard ev(isIgnoreEvent_);
647
648 std::unique_ptr<AbstractInstrument> inst = bt_.lock()->getInstrument(instNum_);
649 auto instADPCM = dynamic_cast<InstrumentADPCM*>(inst.get());
650
651 ui->ptNumSpinBox->setValue(instADPCM->getPitchNumber());
652 ui->ptEditor->clearData();
653 for (auto& unit : instADPCM->getPitchSequence()) {
654 ui->ptEditor->addSequenceData(unit.data);
655 }
656 for (auto& loop : instADPCM->getPitchLoopRoot().getAllLoops()) {
657 ui->ptEditor->addLoop(loop.getBeginPos(), loop.getEndPos(), loop.getTimes());
658 }
659 ui->ptEditor->setRelease(instADPCM->getPitchRelease());
660 for (int i = 0; i < ui->ptTypeComboBox->count(); ++i) {
661 if (instADPCM->getPitchType() == static_cast<SequenceType>(ui->ptTypeComboBox->itemData(i).toInt())) {
662 ui->ptTypeComboBox->setCurrentIndex(i);
663 break;
664 }
665 }
666 if (instADPCM->getPitchEnabled()) {
667 ui->ptEditGroupBox->setChecked(true);
668 onPitchNumberChanged();
669 }
670 else {
671 ui->ptEditGroupBox->setChecked(false);
672 }
673 }
674
675 /********** Slots **********/
676 void AdpcmInstrumentEditor::onPitchNumberChanged()
677 {
678 // Change users view
679 std::multiset<int> users = bt_.lock()->getPitchADPCMUsers(ui->ptNumSpinBox->value());
680 ui->ptUsersLineEdit->setText(inst_edit_utils::generateUsersString(users));
681 }
682
683 void AdpcmInstrumentEditor::onPitchParameterChanged(int ptNum)
684 {
685 if (ui->ptNumSpinBox->value() == ptNum) {
686 Ui::EventGuard eg(isIgnoreEvent_);
687 setInstrumentPitchParameters();
688 }
689 }
690
691 void AdpcmInstrumentEditor::onPitchTypeChanged(int)
692 {
693 auto type = static_cast<SequenceType>(ui->ptTypeComboBox->currentData(Qt::UserRole).toInt());
694 if (!isIgnoreEvent_) {
695 bt_.lock()->setPitchADPCMType(ui->ptNumSpinBox->value(), type);
696 emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_);
697 emit modified();
698 }
699
700 ui->ptEditor->setSequenceType(type);
701 }
702
703 void AdpcmInstrumentEditor::on_ptEditGroupBox_toggled(bool arg1)
704 {
705 if (!isIgnoreEvent_) {
706 bt_.lock()->setInstrumentADPCMPitchEnabled(instNum_, arg1);
707 setInstrumentPitchParameters();
708 emit pitchNumberChanged();
709 emit modified();
710 }
711
712 onPitchNumberChanged();
713 }
714
715 void AdpcmInstrumentEditor::on_ptNumSpinBox_valueChanged(int arg1)
716 {
717 if (!isIgnoreEvent_) {
718 bt_.lock()->setInstrumentADPCMPitch(instNum_, arg1);
719 setInstrumentPitchParameters();
720 emit pitchNumberChanged();
721 emit modified();
722 }
723
724 onPitchNumberChanged();
725 }
726
727 //--- Pan
728 void AdpcmInstrumentEditor::setInstrumentPanParameters()
729 {
730 Ui::EventGuard ev(isIgnoreEvent_);
731
732 std::unique_ptr<AbstractInstrument> inst = bt_.lock()->getInstrument(instNum_);
733 auto instADPCM = dynamic_cast<InstrumentADPCM*>(inst.get());
734
735 ui->panNumSpinBox->setValue(instADPCM->getPanNumber());
736 ui->panEditor->clearData();
737 for (auto& unit : instADPCM->getPanSequence()) {
738 ui->panEditor->addSequenceData(unit.data);
739 }
740 for (auto& loop : instADPCM->getPanLoopRoot().getAllLoops()) {
741 ui->panEditor->addLoop(loop.getBeginPos(), loop.getEndPos(), loop.getTimes());
742 }
743 ui->panEditor->setRelease(instADPCM->getPanRelease());
744
745 if (instADPCM->getPanEnabled()) {
746 ui->panEditGroupBox->setChecked(true);
747 onPanNumberChanged();
748 }
749 else {
750 ui->panEditGroupBox->setChecked(false);
751 }
752 }
753
754 /********** Slots **********/
755 void AdpcmInstrumentEditor::onPanNumberChanged()
756 {
757 // Change users view
758 std::multiset<int> users = bt_.lock()->getPanADPCMUsers(ui->panNumSpinBox->value());
759 ui->panUsersLineEdit->setText(inst_edit_utils::generateUsersString(users));
760 }
761
762 void AdpcmInstrumentEditor::onPanParameterChanged(int panNum)
763 {
764 if (ui->panNumSpinBox->value() == panNum) {
765 Ui::EventGuard eg(isIgnoreEvent_);
766 setInstrumentPanParameters();
767 }
768 }
769
770 void AdpcmInstrumentEditor::on_panEditGroupBox_toggled(bool arg1)
771 {
772 if (!isIgnoreEvent_) {
773 bt_.lock()->setInstrumentADPCMPanEnabled(instNum_, arg1);
774 setInstrumentPanParameters();
775 emit panNumberChanged();
776 emit modified();
777 }
778
779 onPanNumberChanged();
780 }
781
782 void AdpcmInstrumentEditor::on_panNumSpinBox_valueChanged(int arg1)
783 {
784 if (!isIgnoreEvent_) {
785 bt_.lock()->setInstrumentADPCMPan(instNum_, arg1);
786 setInstrumentPanParameters();
787 emit panNumberChanged();
788 emit modified();
789 }
790
791 onPanNumberChanged();
792 }