Skip to content
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ To use it, simply type "sendmidi" or "sendmidi.exe" on the command line and foll
These are all the supported commands:
```
dev name Set the name of the MIDI output port
devindex index Set MIDI output port by index (see listi)
virt (name) Use virtual MIDI port with optional name (Linux/macOS)
list Lists the MIDI output ports
listi Lists the MIDI output ports with indices
panic Sends all possible Note Offs and relevant panic CCs
file path Loads commands from the specified program file
dec Interpret the next numbers as decimals by default
Expand Down Expand Up @@ -81,7 +83,7 @@ These are all the supported commands:

Alternatively, you can use the following long versions of the commands:
```
device virtual decimal hexadecimal channel octave-middle-c note-on note-off
device device-index virtual list-index decimal hexadecimal channel octave-middle-c note-on note-off
poly-pressure control-change control-change-14 program-change
channel-pressure pitch-bend midi-clock continue active-sensing reset
system-exclusive system-exclusive-file time-code song-position song-select
Expand Down
14 changes: 14 additions & 0 deletions Source/ApplicationCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,25 @@ void ApplicationCommand::execute(ApplicationState& state)
std::cout << device.name << std::endl;
}
break;
case LIST_INDEX:
{
auto devices = MidiOutput::getAvailableDevices();
for (int i = 0; i < devices.size(); ++i)
{
std::cout << i << " " << devices[i].name << std::endl;
}
break;
}
case DEVICE:
{
state.openOutputDevice(opts_[0]);
break;
}
case DEVICE_INDEX:
{
state.openOutputDeviceByIndex(opts_[0].getIntValue());
break;
}
case VIRTUAL:
{
auto name = DEFAULT_VIRTUAL_NAME;
Expand Down
2 changes: 2 additions & 0 deletions Source/ApplicationCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ enum CommandIndex
{
NONE,
LIST,
LIST_INDEX,
PANIC,
DEVICE,
DEVICE_INDEX,
VIRTUAL,
TXTFILE,
DECIMAL,
Expand Down
19 changes: 19 additions & 0 deletions Source/ApplicationState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ static const int DEFAULT_OCTAVE_MIDDLE_C = 3;
ApplicationState::ApplicationState()
{
commands_.add({"dev", "device", DEVICE, 1, {"name"}, {"Set the name of the MIDI output port"}});
commands_.add({"devindex", "device-index", DEVICE_INDEX, 1, {"index"}, {"Set MIDI output port by index (see listi)"}});
commands_.add({"virt", "virtual", VIRTUAL, -1, {"(name)"}, {"Use virtual MIDI port with optional name (Linux/macOS)"}});
commands_.add({"list", "", LIST, 0, {""}, {"Lists the MIDI output ports"}});
commands_.add({"listi", "list-index", LIST_INDEX, 0, {""}, {"Lists the MIDI output ports with indices"}});
commands_.add({"panic", "", PANIC, 0, {""}, {"Sends all possible Note Offs and relevant panic CCs"}});
commands_.add({"file", "", TXTFILE, 1, {"path"}, {"Loads commands from the specified program file"}});
commands_.add({"dec", "decimal", DECIMAL, 0, {""}, {"Interpret the next numbers as decimals by default"}});
Expand Down Expand Up @@ -226,6 +228,23 @@ void ApplicationState::openOutputDevice(const String& name)
}
}

void ApplicationState::openOutputDeviceByIndex(int index)
{
midiOut_ = nullptr;
auto devices = MidiOutput::getAvailableDevices();
if (index >= 0 && index < devices.size())
{
midiOut_ = MidiOutput::openDevice(devices[index].identifier);
if (midiOut_)
{
midiOutName_ = devices[index].name;
return;
}
}
std::cerr << "Couldn't open MIDI output port with index " << index << std::endl;
JUCEApplicationBase::getInstance()->setApplicationReturnValue(EXIT_FAILURE);
}

void ApplicationState::openInputDevice(const String& name)
{
midiIn_ = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions Source/ApplicationState.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ class ApplicationState : public MidiInputCallback, public ci::DeviceMessageHandl
public:
ApplicationState();
void initialise(JUCEApplicationBase& app);

void openOutputDevice(const String& name);
void openOutputDeviceByIndex(int index);
void openInputDevice(const String& name);
void virtualDevice(const String& name);
void parseFile(File file);
Expand Down Expand Up @@ -82,4 +83,3 @@ class ApplicationState : public MidiInputCallback, public ci::DeviceMessageHandl
uint32 lastTimeStampCounter_;
int64_t lastTimeStamp_;
};