Make external MIDI options actually appear in Settings

This commit is contained in:
Cacodemon345
2021-12-03 02:12:35 +06:00
parent f7aec4cfcf
commit e021b3460a
3 changed files with 77 additions and 11 deletions

View File

@@ -11,6 +11,7 @@ extern "C" {
#include <86box/86box.h>
#include <86box/config.h>
#include <86box/device.h>
#include <86box/plat_midi.h>
}
#include "qt_filefield.hpp"
@@ -58,19 +59,50 @@ void DeviceConfig::ConfigureDevice(const _device_* device) {
int currentIndex = -1;
int selected = config_get_int(device_context.name, const_cast<char*>(config->name), config->default_int);
for (auto* sel = config->selection; (sel->description != nullptr) && (strlen(sel->description) > 0); ++sel) {
int rows = model->rowCount();
model->insertRow(rows);
auto idx = model->index(rows, 0);
if (config->type == CONFIG_MIDI) {
for (int i = 0; i < plat_midi_get_num_devs(); i++) {
char midiName[512] = { 0 };
plat_midi_get_dev_name(i, midiName);
model->setData(idx, sel->description, Qt::DisplayRole);
model->setData(idx, sel->value, Qt::UserRole);
int rows = model->rowCount();
model->insertRow(rows);
auto idx = model->index(rows, 0);
if (selected == sel->value) {
currentIndex = idx.row();
model->setData(idx, midiName, Qt::DisplayRole);
model->setData(idx, i, Qt::UserRole);
if (selected == i) {
currentIndex = idx.row();
}
}
} else if (config->type == CONFIG_MIDI_IN) {
for (int i = 0; i < plat_midi_in_get_num_devs(); i++) {
char midiName[512] = { 0 };
plat_midi_in_get_dev_name(i, midiName);
int rows = model->rowCount();
model->insertRow(rows);
auto idx = model->index(rows, 0);
model->setData(idx, midiName, Qt::DisplayRole);
model->setData(idx, i, Qt::UserRole);
if (selected == i) {
currentIndex = idx.row();
}
}
} else {
for (auto* sel = config->selection; (sel->description != nullptr) && (strlen(sel->description) > 0); ++sel) {
int rows = model->rowCount();
model->insertRow(rows);
auto idx = model->index(rows, 0);
model->setData(idx, sel->description, Qt::DisplayRole);
model->setData(idx, sel->value, Qt::UserRole);
if (selected == sel->value) {
currentIndex = idx.row();
}
}
}
dc.ui->formLayout->addRow(config->description, cbox);
cbox->setCurrentIndex(currentIndex);
break;

View File

@@ -29,4 +29,16 @@ int plat_midi_get_num_devs()
int plat_midi_in_get_num_devs(void)
{ return 0; }
void plat_midi_get_dev_name(int num, char *s)
{
s[0] = ' ';
s[1] = 0;
}
void plat_midi_in_get_dev_name(int num, char *s)
{
s[0] = ' ';
s[1] = 0;
}
}

View File

@@ -24,7 +24,7 @@ void plat_midi_init()
{
try
{
midiout = new RtMidiOut;
if (!midiout) midiout = new RtMidiOut;
}
catch (RtMidiError& error)
{
@@ -63,6 +63,17 @@ void plat_midi_close()
int plat_midi_get_num_devs()
{
if (!midiout)
{
try
{
midiout = new RtMidiOut;
}
catch (RtMidiError& error)
{
pclog("Failed to initialize MIDI output: %s\n", error.getMessage().c_str());
}
}
return midiout ? midiout->getPortCount() : 0;
}
@@ -91,7 +102,7 @@ void plat_midi_input_init(void)
{
try
{
midiin = new RtMidiIn;
if (!midiin) midiin = new RtMidiIn;
}
catch (RtMidiError& error)
{
@@ -132,6 +143,17 @@ void plat_midi_input_close(void)
int plat_midi_in_get_num_devs(void)
{
if (!midiin)
{
try
{
midiin = new RtMidiIn;
}
catch (RtMidiError& error)
{
pclog("Failed to initialize MIDI input: %s\n", error.getMessage().c_str());
}
}
return midiin ? midiin->getPortCount() : 0;
}