1
$\begingroup$

I have observed when importing midi files with more than one track, the times for every track except for the first one are sped up.

for example,

Import[file, "SoundNotes"][[4, -10]]
Import[file, {"SoundNotes", 4}][[-10]]

returns

SoundNote["F5", {404., 404.569}, "Oboe", SoundVolume -> 0.752941]
SoundNote["F5", {408.062, 408.659}, "Oboe", SoundVolume -> 0.752941]

As you can see, by the end of playing this file, the fourth track is over 4 seconds off!

On the other hand, the first track shows no time difference at all between the two import methods:

Import[file, "SoundNotes"][[1, -10]]
Import[file, {"SoundNotes", 1}][[-10]]

returns

SoundNote["F6", {408.062, 408.629}, "Flute", SoundVolume -> 0.752941]
SoundNote["F6", {408.062, 408.629}, "Flute", SoundVolume -> 0.752941]

You can definitely hear this offset by the end of the piece, especially if it is a two-track piano midi roll.

How can I properly import the midi without messing up the timestamps for the lower tracks? This bug is present in Mathematica 12.3.0 on Windows 10.

$\endgroup$
1

1 Answer 1

1
$\begingroup$

Since the timing bug is only present in the default mode of importing all tracks at the same time and is absent when importing tracks one-at-a-time, you can resolve the issue by importing each track's notes separately and storing the notes from each track into a list.

Sound[Flatten[
  ParallelMap[Import[file, {"SoundNotes", #}] &, 
    Range[Import[file, "TrackCount"]]]
]]

Since we are not writing to the file, we can use ParallelMap.

Hopefully this bug can be fixed in the future...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.