Processing/Getting Info on a MIDI File Before Saving #278
-
I’m currently working on debugging a MIDI file before saving it. I was unsuccessful getting notes to quantize so I started experimenting and I can’t even get a note count. All the values in the output debug are zeros. Here's the output I'm getting:
I’m able to import the MIDI file into my DAW and it works fine. The notes are on channel 11. In the debug I expected to at least see the count of notes. Can you suggest why I'm only getting zeros in the debug output and what I might be doing wrong with quantizing? I’ve set the quantizing class up the same as your ’Soft Quantizer’ example:
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
Hi, Well, as a first step please write this code: var recordedFile = recording.ToFile();
var notes = recordedFile.GetNotes();
Debug.Log($"Recorded notes count: {notes.Count}"); below that line: IReadOnlyList<TimedEvent> recordedEvents = recording.GetEvents(); What number does the "Recorded notes count" line show? What about this? var recordedFile2 = recording.GetEvents().ToFile();
var notes2 = recordedFile2.GetNotes();
Debug.Log($"Recorded notes count 2: {notes2.Count}"); Do you see the correct number again? |
Beta Was this translation helpful? Give feedback.
-
Thanks for your response! I followed your suggestions to debug it. Here's the relevant part of the code:
After adding these lines to my SaveRecording method, I found that both recordedFile.GetNotes() and recordedFile2.GetNotes() returned a count of zero. Considering that the MIDI files contain notes when loaded into Ableton Live, I'm puzzled by GetNotes() returning zero. |
Beta Was this translation helpful? Give feedback.
-
Ok on stepping through with the debugger! In the meantime here's some example output from the GetEvents debug log. That seems to be working and accurate.
|
Beta Was this translation helpful? Give feedback.
-
Well, now I see the problem. Your device sends Note Off messages as Note On ones with zero velocity. It's a common practice. But DryWetMIDI receives events as is by default. But you can change this behavior. Somewhere in your code you get inputDevice.SilentNoteOnPolicy = SilentNoteOnPolicy.NoteOff; That should fix your problem. |
Beta Was this translation helpful? Give feedback.
-
Ah yes! Indeed that fixed it! Thanks so much for your assistance in this. I’ll probably implement a method to ensure uniform handling of note-off events, whether they are explicitly sent as note-offs or as note-ons with zero velocity, assuming the performance hit is negligible. I’m curious how common it is for devices to send zero velocity note-offs vs explicit. I have a lot of vintage gear and have noticed the zero velocity version. So glad this is solved, it had me stumped. Thank you! |
Beta Was this translation helpful? Give feedback.
Well, now I see the problem. Your device sends Note Off messages as Note On ones with zero velocity. It's a common practice. But DryWetMIDI receives events as is by default. But you can change this behavior.
Somewhere in your code you get
InputDevice
that is passed to the constructor of theRecording
class. Just setSilentNoteOnPolicy
property of the device toSilentNoteOnPolicy.NoteOff
before recording started:That should fix your problem.