From What I understand midi format is a digital format computers can read and reproduce.

Is there a way to assign shapes and colors to certain frequencies and durations to visualize the music encoded in the midi files? If so how do I begin?

I uploaded a midi file here i made called c scale.


What I would like to see is shapes and colors change as the scale progresses, maybe scroll left to right which is natural progression from playing music standpoint.

Any help and insights would be appreciated.

  • $\begingroup$ For starters, try something like mf = Import["C:\Users\W10\Downloads\c scale.mid"] to get this. And see ref/format/MIDI $\endgroup$
    – kglr
    Mar 10 '17 at 23:21



Then run


i = 1
freq = ConstantArray[0, Length[mf[[1]]]];
duration = ConstantArray[{0, 0}, Length[mf[[1]]]];

For[i, i <=  Length[mf[[1]]], i++, 

 timehold = mf[[1]][[i]][[2]][[2]] - mf[[1]][[i]][[2]][[1]];

 duration =  ReplacePart[duration, timehold, i];
 freq = ReplacePart[freq, {{i, mf[[1]][[i]][[1]]}}, i];]

freq = ToExpression[freq];

ListPlot[freq, PlotStyle -> (PointSize /@ (duration/3)), 
 PlotRange -> {{-3, 33}, {100, 600}}]

There might be a better way to do it than that, but I'm relatively new to mathematica and this works. Anyway, this then gives you a plot where the radius of the point corresponds to the duration the note is played and y axis corresponds to the pitch and the x axis in what order the notes are played.

enter image description here


To include animation

 ListPlot[freq[[1 ;; j]], PlotStyle -> (PointSize /@ (duration/3)), 
  PlotRange -> {{-3, 33}, {100, 600}}], {j, 1, Length[mf[[1]]], 1}]

enter image description here

  • $\begingroup$ Wow that's beautiful! But It doesn't animate. Like as the the midi plays i wanted the shapes and colors to move across the screen like I've seen some mathematica demo's have shown. Or maybe it was some other platform, I don't remember exactly. $\endgroup$
    – bo reddude
    Mar 11 '17 at 3:14
  • $\begingroup$ @bo reddude Added an animation. $\endgroup$
    – Tomi
    Mar 11 '17 at 11:55
  • $\begingroup$ This is fantastic, and also quite fun! @Tomi $\endgroup$ Mar 11 '17 at 17:17
  • $\begingroup$ All these [[]] is so confusing. Would you mind terribly giving me a line by line explanation of what you're doing. I'm guessing it's because you just want the relevant part of the midi file, right? I guess I have to figure out what midi file actually looks like in Mathematica, too... $\endgroup$
    – bo reddude
    Mar 11 '17 at 20:41
  • $\begingroup$ Its to get the relevant part of the file. If you just take them away in stages you can see whats in the file. $\endgroup$
    – Tomi
    Mar 12 '17 at 0:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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