By default connect to existing MIDI port in repl
This commit is contained in:
parent
e101d362b9
commit
de210b571d
@ -178,9 +178,13 @@ struct Runner
|
||||
std::cout << "Connected MIDI output to port " << *output_port << ". Ready to play!" << std::endl;
|
||||
}
|
||||
} else {
|
||||
midi.connect_output();
|
||||
bool connected_to_existing_port = midi.connect_or_create_output();
|
||||
if (!quiet_mode) {
|
||||
std::cout << "Created new MIDI output port 'Musique'. Ready to play!" << std::endl;
|
||||
if (connected_to_existing_port) {
|
||||
std::cout << "Connected MIDI output to port " << midi.output->getPortName(0) << std::endl;
|
||||
} else {
|
||||
std::cout << "Created new MIDI output port 'Musique'. Ready to play!" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,8 @@ namespace midi
|
||||
{
|
||||
~Rt_Midi() override = default;
|
||||
|
||||
bool connect_or_create_output();
|
||||
|
||||
/// Connect with MIDI virtual port
|
||||
void connect_output();
|
||||
|
||||
@ -35,6 +37,7 @@ namespace midi
|
||||
/// List available ports
|
||||
void list_ports(std::ostream &out) const;
|
||||
|
||||
|
||||
bool supports_output() const override;
|
||||
|
||||
void send_note_on (uint8_t channel, uint8_t note_number, uint8_t velocity) override;
|
||||
|
@ -34,6 +34,22 @@ try {
|
||||
std::exit(33);
|
||||
}
|
||||
|
||||
bool midi::Rt_Midi::connect_or_create_output()
|
||||
try {
|
||||
output.emplace();
|
||||
if (auto pc = output->getPortCount()) {
|
||||
output->openPort(0);
|
||||
return true;
|
||||
}
|
||||
output->openVirtualPort("Musique");
|
||||
return false;
|
||||
}
|
||||
catch (RtMidiError &error) {
|
||||
// TODO(error)
|
||||
std::cerr << "Failed to use MIDI connection: " << error.getMessage() << std::endl;
|
||||
std::exit(33);
|
||||
}
|
||||
|
||||
void midi::Rt_Midi::connect_output()
|
||||
try {
|
||||
ensure(not output.has_value(), "Reconeccting is not supported yet");
|
||||
|
Loading…
Reference in New Issue
Block a user