40 setWindowTitle(
"ACMX2 MIDI Map Configuration");
41 setMinimumSize(820, 640);
43 auto *central =
new QWidget(
this);
44 auto *mainLayout =
new QVBoxLayout(central);
45 mainLayout->setContentsMargins(12, 12, 12, 12);
46 mainLayout->setSpacing(8);
49 auto *target_group =
new QGroupBox(
"Target Application",
this);
50 auto *target_layout =
new QHBoxLayout(target_group);
54 target_combo->setToolTip(
"Selects target-specific action names while preserving the shared "
55 ".midi_cfg file format.");
57 mainLayout->addWidget(target_group);
62 auto *deviceGroup =
new QGroupBox(
"MIDI Device",
this);
63 auto *deviceLayout =
new QHBoxLayout(deviceGroup);
65 deviceCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
69 mainLayout->addWidget(deviceGroup);
80 auto *tableGroup =
new QGroupBox(
"Action Mappings",
this);
81 auto *tableLayout =
new QVBoxLayout(tableGroup);
82 table =
new QTableWidget(
this);
83 table->setColumnCount(5);
84 table->setHorizontalHeaderLabels({
"Action",
"Description",
"Key Codes",
"MIDI Bytes",
"Status"});
85 table->horizontalHeader()->setStretchLastSection(
true);
86 table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
87 table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
88 table->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
89 table->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
90 table->setSelectionBehavior(QAbstractItemView::SelectRows);
91 table->setSelectionMode(QAbstractItemView::SingleSelection);
92 table->setEditTriggers(QAbstractItemView::NoEditTriggers);
93 table->verticalHeader()->setVisible(
false);
94 tableLayout->addWidget(
table);
95 mainLayout->addWidget(tableGroup, 1);
98 auto *btnLayout =
new QHBoxLayout();
100 clearButton =
new QPushButton(
"Clear Selected",
this);
103 btnLayout->addStretch();
104 mainLayout->addLayout(btnLayout);
110 auto *fileGroup =
new QGroupBox(
"Configuration File",
this);
111 auto *fileLayout =
new QHBoxLayout(fileGroup);
112 fileEdit =
new QLineEdit(
"midi.midi_cfg",
this);
118 mainLayout->addWidget(fileGroup);
123 setCentralWidget(central);
124 statusBar()->showMessage(
"Ready");
283 if (index < 0 || index > 1) {
302 const std::vector<MidiMapping> previous_mappings =
mappings;
308 const bool target_specific_meaning = mapping.key2 == 0 && (mapping.key1 == 53 || mapping.key1 == 70 || mapping.key1 == 91 || mapping.key1 == 93);
309 if (target_specific_meaning) {
312 const auto previous = std::find_if(previous_mappings.begin(), previous_mappings.end(), [&](
const MidiMapping &candidate) { return candidate.captured && candidate.key1 == mapping.key1 && candidate.key2 == mapping.key2; });
313 if (previous == previous_mappings.end()) {
316 mapping.captured =
true;
317 mapping.byte0 = previous->byte0;
318 mapping.byte1 = previous->byte1;
319 mapping.byte2 = previous->byte2;
327 setWindowTitle(target_name +
" MIDI Map Configuration");
329 setStatus(QString(
"%1 profile selected — %2 actions available; shared "
330 "captured mappings preserved")
337 for (
int i = 0; i < static_cast<int>(
mappings.size()); ++i) {
339 table->setItem(i, 0,
new QTableWidgetItem(QString::fromStdString(m.actionName)));
340 table->setItem(i, 1,
new QTableWidgetItem(QString::fromStdString(m.description)));
342 QString keys = (m.key2 != 0) ? QString(
"%1:%2").arg(m.key1).arg(m.key2) : QString(
"%1:0").arg(m.key1);
343 table->setItem(i, 2,
new QTableWidgetItem(keys));
348 table->setItem(i, 3,
new QTableWidgetItem(QString(
"CC %1 %2 (knob)").arg(m.byte0).arg(m.byte1)));
349 auto *statusItem =
new QTableWidgetItem(
"Knob mapped");
350 statusItem->setForeground(QBrush(QColor(
"#00ff00")));
351 table->setItem(i, 4, statusItem);
353 table->setItem(i, 3,
new QTableWidgetItem(QString(
"%1 %2 %3").arg(m.byte0).arg(m.byte1).arg(m.byte2)));
354 auto *statusItem =
new QTableWidgetItem(
"Mapped");
355 statusItem->setForeground(QBrush(QColor(
"#00ff00")));
356 table->setItem(i, 4, statusItem);
359 table->setItem(i, 3,
new QTableWidgetItem(
"—"));
360 auto *statusItem =
new QTableWidgetItem(
"Not mapped");
361 statusItem->setForeground(QBrush(QColor(
"#666666")));
362 table->setItem(i, 4, statusItem);
453 std::vector<unsigned char> message;
454 midiIn->getMessage(&message);
456 if (message.size() < 3)
459 midiMonitorLabel->setText(QString(
"Last MIDI: [%1 %2 %3] (ch %4)").arg(message[0]).arg(message[1]).arg(message[2]).arg((message[0] & 0x0F) + 1));
475 statusMsg = QString(
"Captured knob CC [%1 %2] for: %3 — value >64 = %4, <=64 = %5").arg(message[0]).arg(message[1]).arg(QString::fromStdString(
mappings[
captureRow].actionName)).arg(QString::fromStdString(
mappings[
captureRow].actionName).split(
'/').first().trimmed()).arg(QString::fromStdString(
mappings[
captureRow].actionName).split(
'/').last().trimmed());
477 statusMsg = QString(
"Captured [%1 %2 %3] for: %4").arg(message[0]).arg(message[1]).arg(message[2]).arg(QString::fromStdString(
mappings[
captureRow].actionName));
512 QString fileName = QFileDialog::getOpenFileName(
this,
"Load MIDI Config",
fileEdit->text(),
"MIDI Config (*.midi_cfg);;All Files (*)");
513 if (fileName.isEmpty())
516 std::ifstream file(fileName.toStdString());
517 if (!file.is_open()) {
518 QMessageBox::critical(
this,
"Error",
"Could not open file for reading.");
532 while (std::getline(file, line)) {
533 std::istringstream iss(line);
535 if (!(iss >> keyPair))
538 auto colonPos = keyPair.find(
':');
539 if (colonPos == std::string::npos)
542 int k1 = std::stoi(keyPair.substr(0, colonPos));
543 int k2 = std::stoi(keyPair.substr(colonPos + 1));
546 if (!(iss >> brace) || brace !=
'{')
550 if (!(iss >> b0 >> b1 >> b2))
554 if (m.key1 == k1 && m.key2 == k2) {
555 m.byte0 =
static_cast<unsigned char>(b0);
556 m.byte1 =
static_cast<unsigned char>(b1);
557 m.byte2 =
static_cast<unsigned char>(b2);
568 setStatus(QString(
"Loaded %1 mapping(s) from %2").arg(loaded).arg(fileName));