-
Notifications
You must be signed in to change notification settings - Fork 299
Make dummy implementation always available to use as fallback #367
Description
It would be great to have the dummy API always available as a fallback option in case the primary API fails to instantiate for some reason:
try {
return std::make_unique<RtMidiIn>(RtMidi::Api::UNSPECIFIED, name);
} catch (const RtMidiError &) {
return std::make_unique<RtMidiIn>(RtMidi::Api::RTMIDI_DUMMY, name);
}Unfortunately, the dummy implementation is only available if no other API is compiled in, which seems like an obtuse design choice to me. Consider the advantages of the Null Object pattern and the fact that the dummy implementation already exists.
The only ways I could find to work around this are either to deal with a bunch of null pointers everywhere or write wrapper abstract classes around RtMidiIn/Out with two concrete implementations for each: one that forwards calls to a successful instance, and one that acts like the dummy implementation.
The cause of the error is irrelevant, but here it is anyway. ALSA fails to instantiate under WSL2 because it can't find /dev/snd/seq (and looks like it won't ever be available: microsoft/WSL#7107). I don't have JACK installed under it and don't plan to install either, leaving RtMidi with ALSA as the only API option. I'd like to have the dummy implementation available as a fallback so I can at least run the application with no MIDI support without having to do the workarounds cited above.
ALSA lib ../.././../src/v1.2.15.3-f23c25925a.clean/src/seq/seq_hw.c:540:(snd_seq_hw_open) [error.sequencer] open /dev/snd/seq failed: No such file or directory
MidiInAlsa::initialize: error creating ALSA sequencer client object.