Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MIDI port listing #97

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,7 @@ int main(int argc, char *argv[])
int pageNum = 32;
bool autodetect = true;
ResetType resetType = ResetType::NONE;
bool listMidi = false;

romset = ROM_SET_MK2;

Expand Down Expand Up @@ -1453,6 +1454,10 @@ int main(int argc, char *argv[])
{
resetType = ResetType::GM_RESET;
}
else if (!strcmp(argv[i], "-pl"))
{
listMidi = true;
}
else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-help") || !strcmp(argv[i], "--help"))
{
// TODO: Might want to try to find a way to print out the executable's actual name (without any full paths).
Expand All @@ -1474,6 +1479,8 @@ int main(int argc, char *argv[])
printf("\n");
printf(" -gs Reset system in GS mode.\n");
printf(" -gm Reset system in GM mode.\n");
printf("\n");
printf(" -pl List all MIDI ports.\n");
return 0;
}
else if (!strcmp(argv[i], "-sc155"))
Expand Down Expand Up @@ -1749,7 +1756,7 @@ int main(int argc, char *argv[])
return 2;
}

if(!MIDI_Init(port))
if(!MIDI_Init(port, listMidi))
{
fprintf(stderr, "ERROR: Failed to initialize the MIDI Input.\nWARNING: Continuing without MIDI Input...\n");
fflush(stderr);
Expand Down
2 changes: 1 addition & 1 deletion src/midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
*/
#pragma once

int MIDI_Init(int port);
int MIDI_Init(int port, bool listMidi);
void MIDI_Quit(void);

8 changes: 7 additions & 1 deletion src/midi_rtmidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void MidiOnError(RtMidiError::Type, const std::string &errorText, void *)
fflush(stderr);
}

int MIDI_Init(int port)
int MIDI_Init(int port, bool listMidi)
{
if (s_midi_in)
{
Expand All @@ -36,6 +36,12 @@ int MIDI_Init(int port)

unsigned count = s_midi_in->getPortCount();

if (listMidi) {
for (unsigned i = 0; i < count; i++) {
printf("Port[%u]: %s\n", i, s_midi_in->getPortName(i).c_str());
}
}

if (count == 0)
{
printf("No midi input\n");
Expand Down
10 changes: 9 additions & 1 deletion src/midi_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void CALLBACK MIDI_Callback(
}
}

int MIDI_Init(int port)
int MIDI_Init(int port, bool listMidi)
{
int num = midiInGetNumDevs();

Expand All @@ -111,6 +111,14 @@ int MIDI_Init(int port)
return 0;
}

if (listMidi) {
for (int i = 0; i < num; i++) {
MIDIINCAPSA caps;
midiInGetDevCapsA(i, &caps, sizeof(MIDIINCAPSA));
printf("Port[%d]: %s\n", i, caps.szPname);
}
}

if (port < 0 || port >= num)
{
printf("Out of range midi port is requested. Defaulting to port 0\n");
Expand Down