-
Notifications
You must be signed in to change notification settings - Fork 258
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
thru filter overhaul #232
base: master
Are you sure you want to change the base?
thru filter overhaul #232
Conversation
* resolves FortySevenEffects#40 with franky47's proposed thru filter overhaul * removes thru filter modes * adds thru filter callback * adds thru map callback * old thru filter unit tests have been replicated with filter callbacks * does not yet include documentation changes I believe this implements the latest proposal for FortySevenEffects#40 and exercises everything necessary in the unit tests, including the immutability of `mMessage` after a thru map callback has modified the outgoing message. The thru filter callbacks in the unit tests are not suitable for copying and pasting by end-users due to the difference in the MIDI namespace when setup via the unit tests vs via `MIDI_CREATE_DEFAULT_INSTANCE()`. If the changes here are deemed suitable, I'll work on documentation.
This is ground work for the `map` Thru function in PR #232.
It just occurred to me that the other transports expect thru to be off by default, and I haven't tested any transport other than the baked-in serial. |
I've added a commit on |
Good point, Thru makes sense only for serial transports. That being said, it was initialized as active by default. Maybe we could have transports indicate whether they support Thru, and initialize the callbacks based on a static templated property. cc @lathoub |
This is ground work for the `map` Thru function in PR FortySevenEffects#232.
Cherry-picked 2ae9d9e |
I was lurking on the thread; indeed: thru filter does not make sense in point to point communication (AppleMIDI, ipMIDI, BLEMIDI, USBMIDI) and is disabled by these transports in code: // Override default thruActivated. Must be false for all packet based messages
static const bool thruActivated = false; and taken up here arduino_midi_library/src/MIDI.hpp Line 97 in 9f5317f
If this code is deleted, we need to find a why for the transports to switch off Thru |
Since each transport already defines their Thru preference as a |
|
One thing that came clear when doing the example in 2fec41e is that it's hard to reference the using Message = midi::Message<midi::DefaultSettings::SysExSize>;
// Without the typedef above, this gets overly verbose:
bool filter(const Message& message)
{
return true;
}
MIDI.setThruFilter(filter); There is some strong coupling between the Settings traits, the MidiInterface and its underlying Message type, because of this centralisation of the static SysEx array size. There are other open issues and discussion on how to reference types somewhere else in the sketch code, rather than just using the instance object, and I think it would be interesting to extend the macros to add type definitions. I'm not keen on having a default value for the |
Types have names prepended by the port name (defaults to `MIDI`), to allow multi-port applications. This allows referencing those types elsewhere in the application, without re-writing the template arguments, and simplifies referencing the underlying Message type, for SoftThru `filter`/`map`function definitions. Proposition & discussion: FortySevenEffects#232 (comment)
Exporting the message type is definitely a clean, path-of-least-surprise solution. |
The only one issue I could see is a name clash with already user-defined types with the same name, although it's very unlikely. |
Types have names prepended by the port name (defaults to `MIDI`), to allow multi-port applications. This allows referencing those types elsewhere in the application, without re-writing the template arguments, and simplifies referencing the underlying Message type, for SoftThru `filter`/`map`function definitions. Proposition & discussion: #232 (comment)
I believe this implements the latest proposal for #40 and exercises
everything necessary in the unit tests, including the immutability of
mMessage
after a thru map callback has modified the outgoing message.The thru filter callbacks in the unit tests are not suitable for copying
and pasting by end-users due to the difference in the MIDI namespace
when setup via the unit tests vs via
MIDI_CREATE_DEFAULT_INSTANCE()
.If the changes here are deemed suitable, I'll work on documentation.