-
Notifications
You must be signed in to change notification settings - Fork 266
Passthrough everything but NoteOn and NoteOff #314
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
Comments
The upcoming filter/map API would be perfect for that, see #40 (comment). Unfortunately it's not publicly available, but you can use it by downloading the library code from the master branch here on GitHub. |
Thank you very much. I am glad there is a solution for my problem. I know it is asking for too much but if someone can provide me the sample code for both map and filter methods, I would really appreciate that. Thanks in advance. |
If understand your use-case correctly, you'd like to:
Based on these assumptions, it means that:
The code would look like this: #include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
bool thruFilter(const midi::Message& incoming)
{
return true;
}
midi::Message thruMap(const midi::Message& incoming)
{
if (incoming.type != midi::NoteOn && incoming.type != midi::NoteOff)
{
// Forward everything else as-is
return incoming;
}
midi::Message transformed = incoming;
// Example: set velocity to maximum
transformed.data2 = 127;
return transformed;
}
void setup()
{
MIDI.setThuFilter(thruFilter);
MIDI.setThruMap(thruMap);
MIDI.begin();
}
void loop()
{
MIDI.read();
} |
That was very kind of you. The only goal of my project is to intercept the incoming NoteOn or NoteOff command, modify the pitch and send them out. Before I come to the main issue, I have another doubt. Refer to this part This is the code I tried to compile. // copied these lines from my working program //MIDI_CREATE_DEFAULT_INSTANCE(); // commented this assuming the line above takes care of this. bool thruFilter(const midi::Message& incoming) midi::Message thruMap(const midi::Message& incoming) // change pitch void setup() void loop() exit status 1 Compilation error: invalid use of template-name 'midi::Message' without an argument listI have no clue how to sort this out. Regards |
Ok, so it's going to be much more complicated. My proposition involved using an unreleased feature, using MIDI library code from GitHub, rather than the Arduino Library Manager. It's not going to work here since you're using an additional layer (a midi host library) that internally seems to use this MIDI library (at a version where the map/filter feature doesn't exist). Your hunch was correct, it would be data1 that represents pitch in the case of note events. This encoding is found online in the MIDI specification, usually with callbacks it's not necessary to know what goes where, since the callback arguments are named after what they mean, but a generic MIDI message object has only those two generically-named bytes. That being said, if you're using the Arduino as a MIDI USB host, I'm not sure I follow what you want to do with thru, as this concept only exists for hardware serial connections, where it's possible to place the Arduino in the middle of a DIN chain to process the MIDI stream. |
Thank you for taking all that trouble. I will close this issue with this. |
I am using 5.0.2
I would like to intercept and modify only the NoteOn and NoteOff Midi commands. The rest I want to passthrough. I successfuly used the Callback functions of NoteOn and NoteOff to do that. But now I find that except those two commands no other messages are getting through.
For example, in order to allow the pitchbend information to go through, I had to use the callback for pitchbend and send it again.
How do I allow all commands to get through without writing individual callback functions for each of them?
Finally, a big thank you for this wonderful library. I could realize a long term dream of mine.
The text was updated successfully, but these errors were encountered: