| 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 "ssg_instrument_editor.hpp" |
| 27 |
#include "ui_ssg_instrument_editor.h" |
| 28 |
#include <vector> |
| 29 |
#include <set> |
| 30 |
#include <utility> |
| 31 |
#include <stdexcept> |
| 32 |
#include "gui/event_guard.hpp" |
| 33 |
#include "note.hpp" |
| 34 |
#include "sequence_property.hpp" |
| 35 |
#include "gui/jam_layout.hpp" |
| 36 |
#include "gui/instrument_editor/instrument_editor_utils.hpp" |
| 37 |
|
| 38 |
namespace |
| 39 |
{ |
| 40 |
bool isModulatedWaveformSSG(int type) |
| 41 |
{ |
| 42 |
switch (type) { |
| 43 |
case SSGWaveformType::SQUARE: |
| 44 |
case SSGWaveformType::TRIANGLE: |
| 45 |
case SSGWaveformType::SAW: |
| 46 |
case SSGWaveformType::INVSAW: |
| 47 |
return false; |
| 48 |
case SSGWaveformType::SQM_TRIANGLE: |
| 49 |
case SSGWaveformType::SQM_SAW: |
| 50 |
case SSGWaveformType::SQM_INVSAW: |
| 51 |
return true; |
| 52 |
default: |
| 53 |
throw std::invalid_argument("Invalid SSGWaveformType"); |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
SsgInstrumentEditor::SsgInstrumentEditor(int num, QWidget* parent) |
| 59 |
: InstrumentEditor(num, parent), |
| 60 |
ui(new Ui::SsgInstrumentEditor) |
| 61 |
{ |
| 62 |
ui->setupUi(this); |
| 63 |
|
| 64 |
//========== Waveform ==========// |
| 65 |
ui->waveEditor->setMaximumDisplayedRowCount(7); |
| 66 |
ui->waveEditor->setDefaultRow(0); |
| 67 |
ui->waveEditor->AddRow(tr("Sq"), false); |
| 68 |
ui->waveEditor->AddRow(tr("Tri"), false); |
| 69 |
ui->waveEditor->AddRow(tr("Saw"), false); |
| 70 |
ui->waveEditor->AddRow(tr("InvSaw"), false); |
| 71 |
ui->waveEditor->AddRow(tr("SMTri"), false); |
| 72 |
ui->waveEditor->AddRow(tr("SMSaw"), false); |
| 73 |
ui->waveEditor->AddRow(tr("SMInvSaw"), false); |
| 74 |
ui->waveEditor->autoFitLabelWidth(); |
| 75 |
|
| 76 |
QObject::connect(ui->waveEditor, &VisualizedInstrumentMacroEditor::sequenceDataAdded, |
| 77 |
this, [&](int row, int col) { |
| 78 |
if (!isIgnoreEvent_) { |
| 79 |
if (isModulatedWaveformSSG(row)) { |
| 80 |
SSGWaveformUnit data = setWaveformSequenceColumn(col, row); // Set square-mask frequency |
| 81 |
bt_.lock()->addWaveformSSGSequenceData(ui->waveNumSpinBox->value(), data); |
| 82 |
} |
| 83 |
else { |
| 84 |
bt_.lock()->addWaveformSSGSequenceData(ui->waveNumSpinBox->value(), SSGWaveformUnit::makeOnlyDataUnit(row)); |
| 85 |
} |
| 86 |
emit waveformParameterChanged(ui->waveNumSpinBox->value(), instNum_); |
| 87 |
emit modified(); |
| 88 |
} |
| 89 |
}); |
| 90 |
QObject::connect(ui->waveEditor, &VisualizedInstrumentMacroEditor::sequenceDataRemoved, |
| 91 |
this, [&] { |
| 92 |
if (!isIgnoreEvent_) { |
| 93 |
bt_.lock()->removeWaveformSSGSequenceData(ui->waveNumSpinBox->value()); |
| 94 |
emit waveformParameterChanged(ui->waveNumSpinBox->value(), instNum_); |
| 95 |
emit modified(); |
| 96 |
} |
| 97 |
}); |
| 98 |
QObject::connect(ui->waveEditor, &VisualizedInstrumentMacroEditor::sequenceDataChanged, |
| 99 |
this, [&](int row, int col) { |
| 100 |
if (!isIgnoreEvent_) { |
| 101 |
if (isModulatedWaveformSSG(row)) { |
| 102 |
SSGWaveformUnit data = setWaveformSequenceColumn(col, row); // Set square-mask frequency |
| 103 |
bt_.lock()->setWaveformSSGSequenceData(ui->waveNumSpinBox->value(), col, data); |
| 104 |
} |
| 105 |
else { |
| 106 |
bt_.lock()->setWaveformSSGSequenceData(ui->waveNumSpinBox->value(), col, SSGWaveformUnit::makeOnlyDataUnit(row)); |
| 107 |
} |
| 108 |
emit waveformParameterChanged(ui->waveNumSpinBox->value(), instNum_); |
| 109 |
emit modified(); |
| 110 |
} |
| 111 |
}); |
| 112 |
QObject::connect(ui->waveEditor, &VisualizedInstrumentMacroEditor::loopAdded, |
| 113 |
this, [&](InstrumentSequenceLoop loop) { |
| 114 |
if (!isIgnoreEvent_) { |
| 115 |
bt_.lock()->addWaveformSSGLoop(ui->waveNumSpinBox->value(), loop); |
| 116 |
emit waveformParameterChanged(ui->waveNumSpinBox->value(), instNum_); |
| 117 |
emit modified(); |
| 118 |
} |
| 119 |
}); |
| 120 |
QObject::connect(ui->waveEditor, &VisualizedInstrumentMacroEditor::loopRemoved, |
| 121 |
this, [&](int begin, int end) { |
| 122 |
if (!isIgnoreEvent_) { |
| 123 |
bt_.lock()->removeWaveformSSGLoop(ui->waveNumSpinBox->value(), begin, end); |
| 124 |
emit waveformParameterChanged(ui->waveNumSpinBox->value(), instNum_); |
| 125 |
emit modified(); |
| 126 |
} |
| 127 |
}); |
| 128 |
QObject::connect(ui->waveEditor, &VisualizedInstrumentMacroEditor::loopCleared, |
| 129 |
this, [&] { |
| 130 |
if (!isIgnoreEvent_) { |
| 131 |
bt_.lock()->clearWaveformSSGLoops(ui->waveNumSpinBox->value()); |
| 132 |
emit waveformParameterChanged(ui->waveNumSpinBox->value(), instNum_); |
| 133 |
emit modified(); |
| 134 |
} |
| 135 |
}); |
| 136 |
QObject::connect(ui->waveEditor, &VisualizedInstrumentMacroEditor::loopChanged, |
| 137 |
this, [&](int prevBegin, int prevEnd, InstrumentSequenceLoop loop) { |
| 138 |
if (!isIgnoreEvent_) { |
| 139 |
bt_.lock()->changeWaveformSSGLoop(ui->waveNumSpinBox->value(), prevBegin, prevEnd, loop); |
| 140 |
emit waveformParameterChanged(ui->waveNumSpinBox->value(), instNum_); |
| 141 |
emit modified(); |
| 142 |
} |
| 143 |
}); |
| 144 |
QObject::connect(ui->waveEditor, &VisualizedInstrumentMacroEditor::releaseChanged, |
| 145 |
this, [&](InstrumentSequenceRelease release) { |
| 146 |
if (!isIgnoreEvent_) { |
| 147 |
bt_.lock()->setWaveformSSGRelease(ui->waveNumSpinBox->value(), release); |
| 148 |
emit waveformParameterChanged(ui->waveNumSpinBox->value(), instNum_); |
| 149 |
emit modified(); |
| 150 |
} |
| 151 |
}); |
| 152 |
|
| 153 |
//========== Tone/Noise ==========// |
| 154 |
QObject::connect(ui->tnEditor, &VisualizedInstrumentMacroEditor::sequenceDataAdded, |
| 155 |
this, [&](int row, int) { |
| 156 |
if (!isIgnoreEvent_) { |
| 157 |
bt_.lock()->addToneNoiseSSGSequenceData(ui->tnNumSpinBox->value(), row); |
| 158 |
emit toneNoiseParameterChanged(ui->tnNumSpinBox->value(), instNum_); |
| 159 |
emit modified(); |
| 160 |
} |
| 161 |
}); |
| 162 |
QObject::connect(ui->tnEditor, &VisualizedInstrumentMacroEditor::sequenceDataRemoved, |
| 163 |
this, [&] { |
| 164 |
if (!isIgnoreEvent_) { |
| 165 |
bt_.lock()->removeToneNoiseSSGSequenceData(ui->tnNumSpinBox->value()); |
| 166 |
emit toneNoiseParameterChanged(ui->tnNumSpinBox->value(), instNum_); |
| 167 |
emit modified(); |
| 168 |
} |
| 169 |
}); |
| 170 |
QObject::connect(ui->tnEditor, &VisualizedInstrumentMacroEditor::sequenceDataChanged, |
| 171 |
this, [&](int row, int col) { |
| 172 |
if (!isIgnoreEvent_) { |
| 173 |
bt_.lock()->setToneNoiseSSGSequenceData(ui->tnNumSpinBox->value(), col, row); |
| 174 |
emit toneNoiseParameterChanged(ui->tnNumSpinBox->value(), instNum_); |
| 175 |
emit modified(); |
| 176 |
} |
| 177 |
}); |
| 178 |
QObject::connect(ui->tnEditor, &VisualizedInstrumentMacroEditor::loopAdded, |
| 179 |
this, [&](InstrumentSequenceLoop loop) { |
| 180 |
if (!isIgnoreEvent_) { |
| 181 |
bt_.lock()->addToneNoiseSSGLoop(ui->tnNumSpinBox->value(), loop); |
| 182 |
emit toneNoiseParameterChanged(ui->tnNumSpinBox->value(), instNum_); |
| 183 |
emit modified(); |
| 184 |
} |
| 185 |
}); |
| 186 |
QObject::connect(ui->tnEditor, &VisualizedInstrumentMacroEditor::loopRemoved, |
| 187 |
this, [&](int begin, int end) { |
| 188 |
if (!isIgnoreEvent_) { |
| 189 |
bt_.lock()->removeToneNoiseSSGLoop(ui->tnNumSpinBox->value(), begin, end); |
| 190 |
emit toneNoiseParameterChanged(ui->tnNumSpinBox->value(), instNum_); |
| 191 |
emit modified(); |
| 192 |
} |
| 193 |
}); |
| 194 |
QObject::connect(ui->tnEditor, &VisualizedInstrumentMacroEditor::loopCleared, |
| 195 |
this, [&] { |
| 196 |
if (!isIgnoreEvent_) { |
| 197 |
bt_.lock()->clearToneNoiseSSGLoops(ui->tnNumSpinBox->value()); |
| 198 |
emit toneNoiseParameterChanged(ui->tnNumSpinBox->value(), instNum_); |
| 199 |
emit modified(); |
| 200 |
} |
| 201 |
}); |
| 202 |
QObject::connect(ui->tnEditor, &VisualizedInstrumentMacroEditor::loopChanged, |
| 203 |
this, [&](int prevBegin, int prevEnd, InstrumentSequenceLoop loop) { |
| 204 |
if (!isIgnoreEvent_) { |
| 205 |
bt_.lock()->changeToneNoiseSSGLoop(ui->tnNumSpinBox->value(), prevBegin, prevEnd, loop); |
| 206 |
emit toneNoiseParameterChanged(ui->tnNumSpinBox->value(), instNum_); |
| 207 |
emit modified(); |
| 208 |
} |
| 209 |
}); |
| 210 |
QObject::connect(ui->tnEditor, &VisualizedInstrumentMacroEditor::releaseChanged, |
| 211 |
this, [&](InstrumentSequenceRelease release) { |
| 212 |
if (!isIgnoreEvent_) { |
| 213 |
bt_.lock()->setToneNoiseSSGRelease(ui->tnNumSpinBox->value(), release); |
| 214 |
emit toneNoiseParameterChanged(ui->tnNumSpinBox->value(), instNum_); |
| 215 |
emit modified(); |
| 216 |
} |
| 217 |
}); |
| 218 |
|
| 219 |
//========== Envelope ==========// |
| 220 |
ui->envEditor->setMaximumDisplayedRowCount(16); |
| 221 |
ui->envEditor->setDefaultRow(15); |
| 222 |
for (int i = 0; i < 16; ++i) { |
| 223 |
ui->envEditor->AddRow(QString::number(i), false); |
| 224 |
} |
| 225 |
for (int i = 0; i < 8; ++i) { |
| 226 |
ui->envEditor->AddRow(tr("HEnv %1").arg(i), false); |
| 227 |
} |
| 228 |
ui->envEditor->autoFitLabelWidth(); |
| 229 |
ui->envEditor->setMultipleReleaseState(true); |
| 230 |
ui->envEditor->setPermittedReleaseTypes( |
| 231 |
VisualizedInstrumentMacroEditor::PermittedReleaseFlag::ABSOLUTE_RELEASE |
| 232 |
| VisualizedInstrumentMacroEditor::PermittedReleaseFlag::RELATIVE_RELEASE |
| 233 |
| VisualizedInstrumentMacroEditor::PermittedReleaseFlag::FIXED_RELEASE); |
| 234 |
|
| 235 |
QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::sequenceDataAdded, |
| 236 |
this, [&](int row, int col) { |
| 237 |
if (!isIgnoreEvent_) { |
| 238 |
if (row >= 16) { |
| 239 |
SSGEnvelopeUnit data = setEnvelopeSequenceColumn(col, row); // Set hard frequency |
| 240 |
bt_.lock()->addEnvelopeSSGSequenceData(ui->envNumSpinBox->value(), data); |
| 241 |
} |
| 242 |
else { |
| 243 |
bt_.lock()->addEnvelopeSSGSequenceData(ui->envNumSpinBox->value(), SSGEnvelopeUnit::makeOnlyDataUnit(row)); |
| 244 |
} |
| 245 |
emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_); |
| 246 |
emit modified(); |
| 247 |
} |
| 248 |
}); |
| 249 |
QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::sequenceDataRemoved, |
| 250 |
this, [&] { |
| 251 |
if (!isIgnoreEvent_) { |
| 252 |
bt_.lock()->removeEnvelopeSSGSequenceData(ui->envNumSpinBox->value()); |
| 253 |
emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_); |
| 254 |
emit modified(); |
| 255 |
} |
| 256 |
}); |
| 257 |
QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::sequenceDataChanged, |
| 258 |
this, [&](int row, int col) { |
| 259 |
if (!isIgnoreEvent_) { |
| 260 |
if (row >= 16) { |
| 261 |
SSGEnvelopeUnit data = setEnvelopeSequenceColumn(col, row); // Set hard frequency |
| 262 |
bt_.lock()->setEnvelopeSSGSequenceData(ui->envNumSpinBox->value(), col, data); |
| 263 |
} |
| 264 |
else { |
| 265 |
bt_.lock()->setEnvelopeSSGSequenceData(ui->envNumSpinBox->value(), col, SSGEnvelopeUnit::makeOnlyDataUnit(row)); |
| 266 |
} |
| 267 |
emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_); |
| 268 |
emit modified(); |
| 269 |
} |
| 270 |
}); |
| 271 |
QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::loopAdded, |
| 272 |
this, [&](InstrumentSequenceLoop loop) { |
| 273 |
if (!isIgnoreEvent_) { |
| 274 |
bt_.lock()->addEnvelopeSSGLoop(ui->envNumSpinBox->value(), loop); |
| 275 |
emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_); |
| 276 |
emit modified(); |
| 277 |
} |
| 278 |
}); |
| 279 |
QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::loopRemoved, |
| 280 |
this, [&](int begin, int end) { |
| 281 |
if (!isIgnoreEvent_) { |
| 282 |
bt_.lock()->removeEnvelopeSSGLoop(ui->envNumSpinBox->value(), begin, end); |
| 283 |
emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_); |
| 284 |
emit modified(); |
| 285 |
} |
| 286 |
}); |
| 287 |
QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::loopCleared, |
| 288 |
this, [&] { |
| 289 |
if (!isIgnoreEvent_) { |
| 290 |
bt_.lock()->clearEnvelopeSSGLoops(ui->envNumSpinBox->value()); |
| 291 |
emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_); |
| 292 |
emit modified(); |
| 293 |
} |
| 294 |
}); |
| 295 |
QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::loopChanged, |
| 296 |
this, [&](int prevBegin, int prevEnd, InstrumentSequenceLoop loop) { |
| 297 |
if (!isIgnoreEvent_) { |
| 298 |
bt_.lock()->changeEnvelopeSSGLoop(ui->envNumSpinBox->value(), prevBegin, prevEnd, loop); |
| 299 |
emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_); |
| 300 |
emit modified(); |
| 301 |
} |
| 302 |
}); |
| 303 |
QObject::connect(ui->envEditor, &VisualizedInstrumentMacroEditor::releaseChanged, |
| 304 |
this, [&](InstrumentSequenceRelease release) { |
| 305 |
if (!isIgnoreEvent_) { |
| 306 |
bt_.lock()->setEnvelopeSSGRelease(ui->envNumSpinBox->value(), release); |
| 307 |
emit envelopeParameterChanged(ui->envNumSpinBox->value(), instNum_); |
| 308 |
emit modified(); |
| 309 |
} |
| 310 |
}); |
| 311 |
|
| 312 |
//========== Arpeggio ==========// |
| 313 |
ui->arpTypeComboBox->addItem(tr("Absolute"), static_cast<int>(SequenceType::AbsoluteSequence)); |
| 314 |
ui->arpTypeComboBox->addItem(tr("Fixed"), static_cast<int>(SequenceType::FixedSequence)); |
| 315 |
ui->arpTypeComboBox->addItem(tr("Relative"), static_cast<int>(SequenceType::RelativeSequence)); |
| 316 |
|
| 317 |
QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::sequenceDataAdded, |
| 318 |
this, [&](int row, int) { |
| 319 |
if (!isIgnoreEvent_) { |
| 320 |
bt_.lock()->addArpeggioSSGSequenceData(ui->arpNumSpinBox->value(), row); |
| 321 |
emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_); |
| 322 |
emit modified(); |
| 323 |
} |
| 324 |
}); |
| 325 |
QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::sequenceDataRemoved, |
| 326 |
this, [&] { |
| 327 |
if (!isIgnoreEvent_) { |
| 328 |
bt_.lock()->removeArpeggioSSGSequenceData(ui->arpNumSpinBox->value()); |
| 329 |
emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_); |
| 330 |
emit modified(); |
| 331 |
} |
| 332 |
}); |
| 333 |
QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::sequenceDataChanged, |
| 334 |
this, [&](int row, int col) { |
| 335 |
if (!isIgnoreEvent_) { |
| 336 |
bt_.lock()->setArpeggioSSGSequenceData(ui->arpNumSpinBox->value(), col, row); |
| 337 |
emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_); |
| 338 |
emit modified(); |
| 339 |
} |
| 340 |
}); |
| 341 |
QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::loopAdded, |
| 342 |
this, [&](InstrumentSequenceLoop loop) { |
| 343 |
if (!isIgnoreEvent_) { |
| 344 |
bt_.lock()->addArpeggioSSGLoop(ui->arpNumSpinBox->value(), loop); |
| 345 |
emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_); |
| 346 |
emit modified(); |
| 347 |
} |
| 348 |
}); |
| 349 |
QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::loopRemoved, |
| 350 |
this, [&](int begin, int end) { |
| 351 |
if (!isIgnoreEvent_) { |
| 352 |
bt_.lock()->removeArpeggioSSGLoop(ui->arpNumSpinBox->value(), begin, end); |
| 353 |
emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_); |
| 354 |
emit modified(); |
| 355 |
} |
| 356 |
}); |
| 357 |
QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::loopCleared, |
| 358 |
this, [&] { |
| 359 |
if (!isIgnoreEvent_) { |
| 360 |
bt_.lock()->clearArpeggioSSGLoops(ui->arpNumSpinBox->value()); |
| 361 |
emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_); |
| 362 |
emit modified(); |
| 363 |
} |
| 364 |
}); |
| 365 |
QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::loopChanged, |
| 366 |
this, [&](int prevBegin, int prevEnd, InstrumentSequenceLoop loop) { |
| 367 |
if (!isIgnoreEvent_) { |
| 368 |
bt_.lock()->changeArpeggioSSGLoop(ui->arpNumSpinBox->value(), prevBegin, prevEnd, loop); |
| 369 |
emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_); |
| 370 |
emit modified(); |
| 371 |
} |
| 372 |
}); |
| 373 |
QObject::connect(ui->arpEditor, &VisualizedInstrumentMacroEditor::releaseChanged, |
| 374 |
this, [&](InstrumentSequenceRelease release) { |
| 375 |
if (!isIgnoreEvent_) { |
| 376 |
bt_.lock()->setArpeggioSSGRelease(ui->arpNumSpinBox->value(), release); |
| 377 |
emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_); |
| 378 |
emit modified(); |
| 379 |
} |
| 380 |
}); |
| 381 |
// Leave Before Qt5.7.0 style due to windows xp |
| 382 |
QObject::connect(ui->arpTypeComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), |
| 383 |
this, &SsgInstrumentEditor::onArpeggioTypeChanged); |
| 384 |
|
| 385 |
//========== Pitch ==========// |
| 386 |
ui->ptEditor->setMaximumDisplayedRowCount(15); |
| 387 |
ui->ptEditor->setDefaultRow(127); |
| 388 |
ui->ptEditor->setLabelDiaplayMode(true); |
| 389 |
for (int i = 0; i < 255; ++i) { |
| 390 |
ui->ptEditor->AddRow(QString::asprintf("%+d", i - 127), false); |
| 391 |
} |
| 392 |
ui->ptEditor->autoFitLabelWidth(); |
| 393 |
ui->ptEditor->setUpperRow(134); |
| 394 |
ui->ptEditor->setMMLDisplay0As(-127); |
| 395 |
|
| 396 |
ui->ptTypeComboBox->addItem(tr("Absolute"), static_cast<int>(SequenceType::AbsoluteSequence)); |
| 397 |
ui->ptTypeComboBox->addItem(tr("Relative"), static_cast<int>(SequenceType::RelativeSequence)); |
| 398 |
|
| 399 |
QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::sequenceDataAdded, |
| 400 |
this, [&](int row, int) { |
| 401 |
if (!isIgnoreEvent_) { |
| 402 |
bt_.lock()->addPitchSSGSequenceData(ui->ptNumSpinBox->value(), row); |
| 403 |
emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_); |
| 404 |
emit modified(); |
| 405 |
} |
| 406 |
}); |
| 407 |
QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::sequenceDataRemoved, |
| 408 |
this, [&] { |
| 409 |
if (!isIgnoreEvent_) { |
| 410 |
bt_.lock()->removePitchSSGSequenceData(ui->ptNumSpinBox->value()); |
| 411 |
emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_); |
| 412 |
emit modified(); |
| 413 |
} |
| 414 |
}); |
| 415 |
QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::sequenceDataChanged, |
| 416 |
this, [&](int row, int col) { |
| 417 |
if (!isIgnoreEvent_) { |
| 418 |
bt_.lock()->setPitchSSGSequenceData(ui->ptNumSpinBox->value(), col, row); |
| 419 |
emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_); |
| 420 |
emit modified(); |
| 421 |
} |
| 422 |
}); |
| 423 |
QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::loopAdded, |
| 424 |
this, [&](InstrumentSequenceLoop loop) { |
| 425 |
if (!isIgnoreEvent_) { |
| 426 |
bt_.lock()->addPitchSSGLoop(ui->ptNumSpinBox->value(), loop); |
| 427 |
emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_); |
| 428 |
emit modified(); |
| 429 |
} |
| 430 |
}); |
| 431 |
QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::loopRemoved, |
| 432 |
this, [&](int begin, int end) { |
| 433 |
if (!isIgnoreEvent_) { |
| 434 |
bt_.lock()->removePitchSSGLoop(ui->ptNumSpinBox->value(), begin, end); |
| 435 |
emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_); |
| 436 |
emit modified(); |
| 437 |
} |
| 438 |
}); |
| 439 |
QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::loopCleared, |
| 440 |
this, [&] { |
| 441 |
if (!isIgnoreEvent_) { |
| 442 |
bt_.lock()->clearPitchSSGLoops(ui->ptNumSpinBox->value()); |
| 443 |
emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_); |
| 444 |
emit modified(); |
| 445 |
} |
| 446 |
}); |
| 447 |
QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::loopChanged, |
| 448 |
this, [&](int prevBegin, int prevEnd, InstrumentSequenceLoop loop) { |
| 449 |
if (!isIgnoreEvent_) { |
| 450 |
bt_.lock()->changePitchSSGLoop(ui->ptNumSpinBox->value(), prevBegin, prevEnd, loop); |
| 451 |
emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_); |
| 452 |
emit modified(); |
| 453 |
} |
| 454 |
}); |
| 455 |
QObject::connect(ui->ptEditor, &VisualizedInstrumentMacroEditor::releaseChanged, |
| 456 |
this, [&](InstrumentSequenceRelease release) { |
| 457 |
if (!isIgnoreEvent_) { |
| 458 |
bt_.lock()->setPitchSSGRelease(ui->ptNumSpinBox->value(), release); |
| 459 |
emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_); |
| 460 |
emit modified(); |
| 461 |
} |
| 462 |
}); |
| 463 |
// Leave Before Qt5.7.0 style due to windows xp |
| 464 |
QObject::connect(ui->ptTypeComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), |
| 465 |
this, &SsgInstrumentEditor::onPitchTypeChanged); |
| 466 |
} |
| 467 |
|
| 468 |
SsgInstrumentEditor::~SsgInstrumentEditor() |
| 469 |
{ |
| 470 |
delete ui; |
| 471 |
} |
| 472 |
|
| 473 |
SoundSource SsgInstrumentEditor::getSoundSource() const |
| 474 |
{ |
| 475 |
return SoundSource::SSG; |
| 476 |
} |
| 477 |
|
| 478 |
InstrumentType SsgInstrumentEditor::getInstrumentType() const |
| 479 |
{ |
| 480 |
return InstrumentType::SSG; |
| 481 |
} |
| 482 |
|
| 483 |
void SsgInstrumentEditor::updateByConfigurationChange() |
| 484 |
{ |
| 485 |
ui->arpEditor->onNoteNamesUpdated(); |
| 486 |
} |
| 487 |
|
| 488 |
void SsgInstrumentEditor::updateBySettingCore() |
| 489 |
{ |
| 490 |
updateInstrumentParameters(); |
| 491 |
} |
| 492 |
|
| 493 |
void SsgInstrumentEditor::updateBySettingColorPalette() |
| 494 |
{ |
| 495 |
ui->waveEditor->setColorPalette(palette_); |
| 496 |
ui->tnEditor->setColorPalette(palette_); |
| 497 |
ui->envEditor->setColorPalette(palette_); |
| 498 |
ui->arpEditor->setColorPalette(palette_); |
| 499 |
ui->ptEditor->setColorPalette(palette_); |
| 500 |
} |
| 501 |
|
| 502 |
void SsgInstrumentEditor::updateInstrumentParameters() |
| 503 |
{ |
| 504 |
Ui::EventGuard eg(isIgnoreEvent_); |
| 505 |
|
| 506 |
updateWindowTitle(); |
| 507 |
|
| 508 |
setInstrumentWaveformParameters(); |
| 509 |
setInstrumentToneNoiseParameters(); |
| 510 |
setInstrumentEnvelopeParameters(); |
| 511 |
setInstrumentArpeggioParameters(); |
| 512 |
setInstrumentPitchParameters(); |
| 513 |
} |
| 514 |
|
| 515 |
/********** Events **********/ |
| 516 |
// MUST DIRECT CONNECTION |
| 517 |
void SsgInstrumentEditor::keyPressEvent(QKeyEvent *event) |
| 518 |
{ |
| 519 |
// General keys |
| 520 |
switch (event->key()) { |
| 521 |
case Qt::Key_Escape: |
| 522 |
close(); |
| 523 |
break; |
| 524 |
default: |
| 525 |
// For jam key on |
| 526 |
if (!event->isAutoRepeat()) { |
| 527 |
// Musical keyboard |
| 528 |
Qt::Key qtKey = static_cast<Qt::Key>(event->key()); |
| 529 |
try { |
| 530 |
JamKey jk = getJamKeyFromLayoutMapping(qtKey, config_); |
| 531 |
emit jamKeyOnEvent(jk); |
| 532 |
} catch (std::invalid_argument&) {} |
| 533 |
} |
| 534 |
break; |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
// MUST DIRECT CONNECTION |
| 539 |
void SsgInstrumentEditor::keyReleaseEvent(QKeyEvent *event) |
| 540 |
{ |
| 541 |
// For jam key off |
| 542 |
if (!event->isAutoRepeat()) { |
| 543 |
Qt::Key qtKey = static_cast<Qt::Key>(event->key()); |
| 544 |
try { |
| 545 |
JamKey jk = getJamKeyFromLayoutMapping(qtKey, config_); |
| 546 |
emit jamKeyOffEvent(jk); |
| 547 |
} catch (std::invalid_argument&) {} |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
//--- Waveform |
| 552 |
void SsgInstrumentEditor::setInstrumentWaveformParameters() |
| 553 |
{ |
| 554 |
Ui::EventGuard ev(isIgnoreEvent_); |
| 555 |
|
| 556 |
std::unique_ptr<AbstractInstrument> inst = bt_.lock()->getInstrument(instNum_); |
| 557 |
auto instSSG = dynamic_cast<InstrumentSSG*>(inst.get()); |
| 558 |
|
| 559 |
ui->waveNumSpinBox->setValue(instSSG->getWaveformNumber()); |
| 560 |
ui->waveEditor->clearData(); |
| 561 |
for (auto& unit : instSSG->getWaveformSequence()) { |
| 562 |
QString str(""); |
| 563 |
if (isModulatedWaveformSSG(unit.data)) { |
| 564 |
if (unit.type == SSGWaveformUnit::RatioSubdata) { |
| 565 |
int r1, r2; |
| 566 |
unit.getSubdataAsRatio(r1, r2); |
| 567 |
str = QString("%1/%2").arg(r1).arg(r2); |
| 568 |
} |
| 569 |
else { |
| 570 |
str = QString::number(unit.subdata); |
| 571 |
} |
| 572 |
} |
| 573 |
ui->waveEditor->addSequenceData(unit.data, str, unit.subdata); |
| 574 |
} |
| 575 |
for (auto& loop : instSSG->getWaveformLoopRoot().getAllLoops()) { |
| 576 |
ui->waveEditor->addLoop(loop.getBeginPos(), loop.getEndPos(), loop.getTimes()); |
| 577 |
} |
| 578 |
ui->waveEditor->setRelease(instSSG->getWaveformRelease()); |
| 579 |
if (instSSG->getWaveformEnabled()) { |
| 580 |
ui->waveEditGroupBox->setChecked(true); |
| 581 |
onWaveformNumberChanged(); |
| 582 |
} |
| 583 |
else { |
| 584 |
ui->waveEditGroupBox->setChecked(false); |
| 585 |
} |
| 586 |
} |
| 587 |
|
| 588 |
SSGWaveformUnit SsgInstrumentEditor::setWaveformSequenceColumn(int col, int wfRow) |
| 589 |
{ |
| 590 |
auto button = ui->squareMaskButtonGroup->checkedButton(); |
| 591 |
if (button == ui->squareMaskRawRadioButton) { |
| 592 |
SSGWaveformUnit unit = SSGWaveformUnit::makeRawUnit(wfRow, ui->squareMaskRawSpinBox->value()); |
| 593 |
ui->waveEditor->setText(col, QString::number(unit.subdata)); |
| 594 |
ui->waveEditor->setSubdata(col, unit.subdata); |
| 595 |
return unit; |
| 596 |
} |
| 597 |
else { |
| 598 |
SSGWaveformUnit unit = SSGWaveformUnit::makeRatioUnit(wfRow, ui->squareMaskToneSpinBox->value(), |
| 599 |
ui->squareMaskMaskSpinBox->value()); |
| 600 |
ui->waveEditor->setText(col, QString::number(ui->squareMaskToneSpinBox->value()) + "/" |
| 601 |
+ QString::number(ui->squareMaskMaskSpinBox->value())); |
| 602 |
ui->waveEditor->setSubdata(col, unit.subdata); |
| 603 |
return unit; |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
/********** Slots **********/ |
| 608 |
void SsgInstrumentEditor::onWaveformNumberChanged() |
| 609 |
{ |
| 610 |
// Change users view |
| 611 |
std::multiset<int> users = bt_.lock()->getWaveformSSGUsers(ui->waveNumSpinBox->value()); |
| 612 |
ui->waveUsersLineEdit->setText(inst_edit_utils::generateUsersString(users)); |
| 613 |
} |
| 614 |
|
| 615 |
void SsgInstrumentEditor::onWaveformParameterChanged(int wfNum) |
| 616 |
{ |
| 617 |
if (ui->waveNumSpinBox->value() == wfNum) { |
| 618 |
Ui::EventGuard eg(isIgnoreEvent_); |
| 619 |
setInstrumentWaveformParameters(); |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
void SsgInstrumentEditor::on_waveEditGroupBox_toggled(bool arg1) |
| 624 |
{ |
| 625 |
if (!isIgnoreEvent_) { |
| 626 |
bt_.lock()->setInstrumentSSGWaveformEnabled(instNum_, arg1); |
| 627 |
setInstrumentWaveformParameters(); |
| 628 |
emit waveformNumberChanged(); |
| 629 |
emit modified(); |
| 630 |
} |
| 631 |
|
| 632 |
onWaveformNumberChanged(); |
| 633 |
} |
| 634 |
|
| 635 |
void SsgInstrumentEditor::on_waveNumSpinBox_valueChanged(int arg1) |
| 636 |
{ |
| 637 |
if (!isIgnoreEvent_) { |
| 638 |
bt_.lock()->setInstrumentSSGWaveform(instNum_, arg1); |
| 639 |
setInstrumentWaveformParameters(); |
| 640 |
emit waveformNumberChanged(); |
| 641 |
emit modified(); |
| 642 |
} |
| 643 |
|
| 644 |
onWaveformNumberChanged(); |
| 645 |
} |
| 646 |
|
| 647 |
void SsgInstrumentEditor::on_squareMaskRawSpinBox_valueChanged(int arg1) |
| 648 |
{ |
| 649 |
ui->squareMaskRawSpinBox->setSuffix( |
| 650 |
QString(" (0x") + QString("%1 | ").arg(arg1, 3, 16, QChar('0')).toUpper() |
| 651 |
+ QString("%1Hz)").arg(arg1 ? QString::number(124800.0 / arg1, 'f', 4) : "-") |
| 652 |
); |
| 653 |
} |
| 654 |
|
| 655 |
//--- Tone/Noise |
| 656 |
void SsgInstrumentEditor::setInstrumentToneNoiseParameters() |
| 657 |
{ |
| 658 |
Ui::EventGuard ev(isIgnoreEvent_); |
| 659 |
|
| 660 |
std::unique_ptr<AbstractInstrument> inst = bt_.lock()->getInstrument(instNum_); |
| 661 |
auto instSSG = dynamic_cast<InstrumentSSG*>(inst.get()); |
| 662 |
|
| 663 |
ui->tnNumSpinBox->setValue(instSSG->getToneNoiseNumber()); |
| 664 |
ui->tnEditor->clearData(); |
| 665 |
for (auto& unit : instSSG->getToneNoiseSequence()) { |
| 666 |
ui->tnEditor->addSequenceData(unit.data); |
| 667 |
} |
| 668 |
for (auto& loop : instSSG->getToneNoiseLoopRoot().getAllLoops()) { |
| 669 |
ui->tnEditor->addLoop(loop.getBeginPos(), loop.getEndPos(), loop.getTimes()); |
| 670 |
} |
| 671 |
ui->tnEditor->setRelease(instSSG->getToneNoiseRelease()); |
| 672 |
if (instSSG->getToneNoiseEnabled()) { |
| 673 |
ui->tnEditGroupBox->setChecked(true); |
| 674 |
onToneNoiseNumberChanged(); |
| 675 |
} |
| 676 |
else { |
| 677 |
ui->tnEditGroupBox->setChecked(false); |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
/********** Slots **********/ |
| 682 |
void SsgInstrumentEditor::onToneNoiseNumberChanged() |
| 683 |
{ |
| 684 |
// Change users view |
| 685 |
std::multiset<int> users = bt_.lock()->getToneNoiseSSGUsers(ui->tnNumSpinBox->value()); |
| 686 |
ui->tnUsersLineEdit->setText(inst_edit_utils::generateUsersString(users)); |
| 687 |
} |
| 688 |
|
| 689 |
void SsgInstrumentEditor::onToneNoiseParameterChanged(int tnNum) |
| 690 |
{ |
| 691 |
if (ui->tnNumSpinBox->value() == tnNum) { |
| 692 |
Ui::EventGuard eg(isIgnoreEvent_); |
| 693 |
setInstrumentToneNoiseParameters(); |
| 694 |
} |
| 695 |
} |
| 696 |
|
| 697 |
void SsgInstrumentEditor::on_tnEditGroupBox_toggled(bool arg1) |
| 698 |
{ |
| 699 |
if (!isIgnoreEvent_) { |
| 700 |
bt_.lock()->setInstrumentSSGToneNoiseEnabled(instNum_, arg1); |
| 701 |
setInstrumentToneNoiseParameters(); |
| 702 |
emit toneNoiseNumberChanged(); |
| 703 |
emit modified(); |
| 704 |
} |
| 705 |
|
| 706 |
onToneNoiseNumberChanged(); |
| 707 |
} |
| 708 |
|
| 709 |
void SsgInstrumentEditor::on_tnNumSpinBox_valueChanged(int arg1) |
| 710 |
{ |
| 711 |
if (!isIgnoreEvent_) { |
| 712 |
bt_.lock()->setInstrumentSSGToneNoise(instNum_, arg1); |
| 713 |
setInstrumentToneNoiseParameters(); |
| 714 |
emit toneNoiseNumberChanged(); |
| 715 |
emit modified(); |
| 716 |
} |
| 717 |
|
| 718 |
onToneNoiseNumberChanged(); |
| 719 |
} |
| 720 |
|
| 721 |
//--- Envelope |
| 722 |
void SsgInstrumentEditor::setInstrumentEnvelopeParameters() |
| 723 |
{ |
| 724 |
Ui::EventGuard ev(isIgnoreEvent_); |
| 725 |
|
| 726 |
std::unique_ptr<AbstractInstrument> inst = bt_.lock()->getInstrument(instNum_); |
| 727 |
auto instSSG = dynamic_cast<InstrumentSSG*>(inst.get()); |
| 728 |
|
| 729 |
ui->envNumSpinBox->setValue(instSSG->getEnvelopeNumber()); |
| 730 |
ui->envEditor->clearData(); |
| 731 |
for (auto& unit : instSSG->getEnvelopeSequence()) { |
| 732 |
QString str(""); |
| 733 |
if (unit.data >= 16) { |
| 734 |
if (unit.type == SSGEnvelopeUnit::RatioSubdata) { |
| 735 |
int r1, r2; |
| 736 |
unit.getSubdataAsRatio(r1, r2); |
| 737 |
str = QString("%1/%2").arg(r1).arg(r2); |
| 738 |
} |
| 739 |
else { |
| 740 |
str = QString::number(unit.subdata); |
| 741 |
} |
| 742 |
} |
| 743 |
ui->envEditor->addSequenceData(unit.data, str, unit.subdata); |
| 744 |
} |
| 745 |
for (auto& loop : instSSG->getEnvelopeLoopRoot().getAllLoops()) { |
| 746 |
ui->envEditor->addLoop(loop.getBeginPos(), loop.getEndPos(), loop.getTimes()); |
| 747 |
} |
| 748 |
ui->envEditor->setRelease(instSSG->getEnvelopeRelease()); |
| 749 |
if (instSSG->getEnvelopeEnabled()) { |
| 750 |
ui->envEditGroupBox->setChecked(true); |
| 751 |
onEnvelopeNumberChanged(); |
| 752 |
} |
| 753 |
else { |
| 754 |
ui->envEditGroupBox->setChecked(false); |
| 755 |
} |
| 756 |
} |
| 757 |
|
| 758 |
SSGEnvelopeUnit SsgInstrumentEditor::setEnvelopeSequenceColumn(int col, int envRow) |
| 759 |
{ |
| 760 |
if (ui->hardFreqButtonGroup->checkedButton() == ui->hardFreqRawRadioButton) { |
| 761 |
SSGEnvelopeUnit unit = SSGEnvelopeUnit::makeRawUnit(envRow, ui->hardFreqRawSpinBox->value()); |
| 762 |
ui->envEditor->setText(col, QString::number(unit.subdata)); |
| 763 |
ui->envEditor->setSubdata(col, unit.subdata); |
| 764 |
return unit; |
| 765 |
} |
| 766 |
else { |
| 767 |
SSGEnvelopeUnit unit = SSGEnvelopeUnit::makeRatioUnit(envRow, ui->hardFreqToneSpinBox->value(), |
| 768 |
ui->hardFreqHardSpinBox->value()); |
| 769 |
ui->envEditor->setText(col, QString::number(ui->hardFreqToneSpinBox->value()) + "/" |
| 770 |
+ QString::number(ui->hardFreqHardSpinBox->value())); |
| 771 |
ui->envEditor->setSubdata(col, unit.subdata); |
| 772 |
return unit; |
| 773 |
} |
| 774 |
} |
| 775 |
|
| 776 |
/********** Slots **********/ |
| 777 |
void SsgInstrumentEditor::onEnvelopeNumberChanged() |
| 778 |
{ |
| 779 |
// Change users view |
| 780 |
std::multiset<int> users = bt_.lock()->getEnvelopeSSGUsers(ui->envNumSpinBox->value()); |
| 781 |
ui->envUsersLineEdit->setText(inst_edit_utils::generateUsersString(users)); |
| 782 |
} |
| 783 |
|
| 784 |
void SsgInstrumentEditor::onEnvelopeParameterChanged(int envNum) |
| 785 |
{ |
| 786 |
if (ui->envNumSpinBox->value() == envNum) { |
| 787 |
Ui::EventGuard eg(isIgnoreEvent_); |
| 788 |
setInstrumentEnvelopeParameters(); |
| 789 |
} |
| 790 |
} |
| 791 |
|
| 792 |
void SsgInstrumentEditor::on_envEditGroupBox_toggled(bool arg1) |
| 793 |
{ |
| 794 |
if (!isIgnoreEvent_) { |
| 795 |
bt_.lock()->setInstrumentSSGEnvelopeEnabled(instNum_, arg1); |
| 796 |
setInstrumentEnvelopeParameters(); |
| 797 |
emit envelopeNumberChanged(); |
| 798 |
emit modified(); |
| 799 |
} |
| 800 |
|
| 801 |
onEnvelopeNumberChanged(); |
| 802 |
} |
| 803 |
|
| 804 |
void SsgInstrumentEditor::on_envNumSpinBox_valueChanged(int arg1) |
| 805 |
{ |
| 806 |
if (!isIgnoreEvent_) { |
| 807 |
bt_.lock()->setInstrumentSSGEnvelope(instNum_, arg1); |
| 808 |
setInstrumentEnvelopeParameters(); |
| 809 |
emit envelopeNumberChanged(); |
| 810 |
emit modified(); |
| 811 |
} |
| 812 |
|
| 813 |
onEnvelopeNumberChanged(); |
| 814 |
} |
| 815 |
|
| 816 |
void SsgInstrumentEditor::on_hardFreqRawSpinBox_valueChanged(int arg1) |
| 817 |
{ |
| 818 |
ui->hardFreqRawSpinBox->setSuffix( |
| 819 |
QString(" (0x") + QString("%1 | ").arg(arg1, 4, 16, QChar('0')).toUpper() |
| 820 |
+ QString("%1Hz").arg(arg1 ? QString::number(7800.0 / arg1, 'f', 4) : "-")); |
| 821 |
} |
| 822 |
|
| 823 |
//--- Arpeggio |
| 824 |
void SsgInstrumentEditor::setInstrumentArpeggioParameters() |
| 825 |
{ |
| 826 |
Ui::EventGuard ev(isIgnoreEvent_); |
| 827 |
|
| 828 |
std::unique_ptr<AbstractInstrument> inst = bt_.lock()->getInstrument(instNum_); |
| 829 |
auto instSSG = dynamic_cast<InstrumentSSG*>(inst.get()); |
| 830 |
|
| 831 |
ui->arpNumSpinBox->setValue(instSSG->getArpeggioNumber()); |
| 832 |
ui->arpEditor->clearData(); |
| 833 |
for (auto& unit : instSSG->getArpeggioSequence()) { |
| 834 |
ui->arpEditor->addSequenceData(unit.data); |
| 835 |
} |
| 836 |
for (auto& loop : instSSG->getArpeggioLoopRoot().getAllLoops()) { |
| 837 |
ui->arpEditor->addLoop(loop.getBeginPos(), loop.getEndPos(), loop.getTimes()); |
| 838 |
} |
| 839 |
ui->arpEditor->setRelease(instSSG->getArpeggioRelease()); |
| 840 |
for (int i = 0; i < ui->arpTypeComboBox->count(); ++i) { |
| 841 |
if (instSSG->getArpeggioType() == static_cast<SequenceType>(ui->arpTypeComboBox->itemData(i).toInt())) { |
| 842 |
ui->arpTypeComboBox->setCurrentIndex(i); |
| 843 |
break; |
| 844 |
} |
| 845 |
} |
| 846 |
if (instSSG->getArpeggioEnabled()) { |
| 847 |
ui->arpEditGroupBox->setChecked(true); |
| 848 |
onArpeggioNumberChanged(); |
| 849 |
} |
| 850 |
else { |
| 851 |
ui->arpEditGroupBox->setChecked(false); |
| 852 |
} |
| 853 |
} |
| 854 |
|
| 855 |
/********** Slots **********/ |
| 856 |
void SsgInstrumentEditor::onArpeggioNumberChanged() |
| 857 |
{ |
| 858 |
// Change users view |
| 859 |
std::multiset<int> users = bt_.lock()->getArpeggioSSGUsers(ui->arpNumSpinBox->value()); |
| 860 |
ui->arpUsersLineEdit->setText(inst_edit_utils::generateUsersString(users)); |
| 861 |
} |
| 862 |
|
| 863 |
void SsgInstrumentEditor::onArpeggioParameterChanged(int tnNum) |
| 864 |
{ |
| 865 |
if (ui->arpNumSpinBox->value() == tnNum) { |
| 866 |
Ui::EventGuard eg(isIgnoreEvent_); |
| 867 |
setInstrumentArpeggioParameters(); |
| 868 |
} |
| 869 |
} |
| 870 |
|
| 871 |
void SsgInstrumentEditor::onArpeggioTypeChanged(int) |
| 872 |
{ |
| 873 |
auto type = static_cast<SequenceType>(ui->arpTypeComboBox->currentData(Qt::UserRole).toInt()); |
| 874 |
if (!isIgnoreEvent_) { |
| 875 |
bt_.lock()->setArpeggioSSGType(ui->arpNumSpinBox->value(), type); |
| 876 |
emit arpeggioParameterChanged(ui->arpNumSpinBox->value(), instNum_); |
| 877 |
emit modified(); |
| 878 |
} |
| 879 |
|
| 880 |
ui->arpEditor->setSequenceType(type); |
| 881 |
} |
| 882 |
|
| 883 |
void SsgInstrumentEditor::on_arpEditGroupBox_toggled(bool arg1) |
| 884 |
{ |
| 885 |
if (!isIgnoreEvent_) { |
| 886 |
bt_.lock()->setInstrumentSSGArpeggioEnabled(instNum_, arg1); |
| 887 |
setInstrumentArpeggioParameters(); |
| 888 |
emit arpeggioNumberChanged(); |
| 889 |
emit modified(); |
| 890 |
} |
| 891 |
|
| 892 |
onArpeggioNumberChanged(); |
| 893 |
} |
| 894 |
|
| 895 |
void SsgInstrumentEditor::on_arpNumSpinBox_valueChanged(int arg1) |
| 896 |
{ |
| 897 |
if (!isIgnoreEvent_) { |
| 898 |
bt_.lock()->setInstrumentSSGArpeggio(instNum_, arg1); |
| 899 |
setInstrumentArpeggioParameters(); |
| 900 |
emit arpeggioNumberChanged(); |
| 901 |
emit modified(); |
| 902 |
} |
| 903 |
|
| 904 |
onArpeggioNumberChanged(); |
| 905 |
} |
| 906 |
|
| 907 |
//--- Pitch |
| 908 |
void SsgInstrumentEditor::setInstrumentPitchParameters() |
| 909 |
{ |
| 910 |
Ui::EventGuard ev(isIgnoreEvent_); |
| 911 |
|
| 912 |
std::unique_ptr<AbstractInstrument> inst = bt_.lock()->getInstrument(instNum_); |
| 913 |
auto instSSG = dynamic_cast<InstrumentSSG*>(inst.get()); |
| 914 |
|
| 915 |
ui->ptNumSpinBox->setValue(instSSG->getPitchNumber()); |
| 916 |
ui->ptEditor->clearData(); |
| 917 |
for (auto& unit : instSSG->getPitchSequence()) { |
| 918 |
ui->ptEditor->addSequenceData(unit.data); |
| 919 |
} |
| 920 |
for (auto& loop : instSSG->getPitchLoopRoot().getAllLoops()) { |
| 921 |
ui->ptEditor->addLoop(loop.getBeginPos(), loop.getEndPos(), loop.getTimes()); |
| 922 |
} |
| 923 |
ui->ptEditor->setRelease(instSSG->getPitchRelease()); |
| 924 |
for (int i = 0; i < ui->ptTypeComboBox->count(); ++i) { |
| 925 |
if (instSSG->getPitchType() == static_cast<SequenceType>(ui->ptTypeComboBox->itemData(i).toInt())) { |
| 926 |
ui->ptTypeComboBox->setCurrentIndex(i); |
| 927 |
break; |
| 928 |
} |
| 929 |
} |
| 930 |
if (instSSG->getPitchEnabled()) { |
| 931 |
ui->ptEditGroupBox->setChecked(true); |
| 932 |
onPitchNumberChanged(); |
| 933 |
} |
| 934 |
else { |
| 935 |
ui->ptEditGroupBox->setChecked(false); |
| 936 |
} |
| 937 |
} |
| 938 |
|
| 939 |
/********** Slots **********/ |
| 940 |
void SsgInstrumentEditor::onPitchNumberChanged() |
| 941 |
{ |
| 942 |
// Change users view |
| 943 |
std::multiset<int> users = bt_.lock()->getPitchSSGUsers(ui->ptNumSpinBox->value()); |
| 944 |
ui->ptUsersLineEdit->setText(inst_edit_utils::generateUsersString(users)); |
| 945 |
} |
| 946 |
|
| 947 |
void SsgInstrumentEditor::onPitchParameterChanged(int ptNum) |
| 948 |
{ |
| 949 |
if (ui->ptNumSpinBox->value() == ptNum) { |
| 950 |
Ui::EventGuard eg(isIgnoreEvent_); |
| 951 |
setInstrumentPitchParameters(); |
| 952 |
} |
| 953 |
} |
| 954 |
|
| 955 |
void SsgInstrumentEditor::onPitchTypeChanged(int) |
| 956 |
{ |
| 957 |
auto type = static_cast<SequenceType>(ui->ptTypeComboBox->currentData(Qt::UserRole).toInt()); |
| 958 |
if (!isIgnoreEvent_) { |
| 959 |
bt_.lock()->setPitchSSGType(ui->ptNumSpinBox->value(), type); |
| 960 |
emit pitchParameterChanged(ui->ptNumSpinBox->value(), instNum_); |
| 961 |
emit modified(); |
| 962 |
} |
| 963 |
|
| 964 |
ui->ptEditor->setSequenceType(type); |
| 965 |
} |
| 966 |
|
| 967 |
void SsgInstrumentEditor::on_ptEditGroupBox_toggled(bool arg1) |
| 968 |
{ |
| 969 |
if (!isIgnoreEvent_) { |
| 970 |
bt_.lock()->setInstrumentSSGPitchEnabled(instNum_, arg1); |
| 971 |
setInstrumentPitchParameters(); |
| 972 |
emit pitchNumberChanged(); |
| 973 |
emit modified(); |
| 974 |
} |
| 975 |
|
| 976 |
onPitchNumberChanged(); |
| 977 |
} |
| 978 |
|
| 979 |
void SsgInstrumentEditor::on_ptNumSpinBox_valueChanged(int arg1) |
| 980 |
{ |
| 981 |
if (!isIgnoreEvent_) { |
| 982 |
bt_.lock()->setInstrumentSSGPitch(instNum_, arg1); |
| 983 |
setInstrumentPitchParameters(); |
| 984 |
emit pitchNumberChanged(); |
| 985 |
emit modified(); |
| 986 |
} |
| 987 |
|
| 988 |
onPitchNumberChanged(); |
| 989 |
} |