So I came across a situation where I wanted to test a class that sends MIDI to an output device. Specifically, I’m working on a class that can transpose messages before sending them off to the output. Originally I’d hoped to write a dummy class with its own sendMessageNow() implementation that I could pass in at construction, but since I cannot inherit from MidiOutput I had to find some other solution.
Using a templated member field (if someone knows the actual term for it I’d love to hear it) seems to work fine, and I think it also looks fairly clean. I was wondering however if there are any drawbacks/issues to be aware of when using this approach?
(using Catch2 as a framework btw. If there are any other tools I should be aware of that simplify these types of dependency issues, do let me know)
template<typename MO = ::juce::MidiOutput>
class Destination
{
public:
...
void handleMessage(MidiMessage& msg) const
{
msg.setChannel(channel.getValue());
mh::transposeNote(msg, transpose.getValue());
outDevice->sendMessageNow(msg);
}
private:
ValueTree state;
Value channel;
Value transpose;
MO* outDevice;
};
