In[]:=
testMidi=Import[pathToMidiFile]
Out[]=
In[]:=
A4notes=Cases[testMidi,SoundNote["A4",___],Infinity]
Out[]=
{SoundNote[A4,{2.,2.5},Piano,SoundVolume0.996078],SoundNote[A4,{3.,4.},Piano,SoundVolume0.996078],SoundNote[A4,{10.,10.5},Piano,SoundVolume0.996078],SoundNote[A4,{11.,12.},Piano,SoundVolume0.996078],SoundNote[A4,{20.5,21.},Piano,SoundVolume0.996078],SoundNote[A4,{21.5,22.},Piano,SoundVolume0.996078],SoundNote[A4,{26.,26.5},Piano,SoundVolume0.996078],SoundNote[A4,{27.,27.75},Piano,SoundVolume0.996078],SoundNote[A4,{29.75,30.},Piano,SoundVolume0.996078]}
In[]:=
timeRanges=A4notes[[All,2]]
Out[]=
{{2.,2.5},{3.,4.},{10.,10.5},{11.,12.},{20.5,21.},{21.5,22.},{26.,26.5},{27.,27.75},{29.75,30.}}
In[]:=
noteDurations=Differences/@timeRanges
Out[]=
{{0.5},{1.},{0.5},{1.},{0.5},{0.5},{0.5},{0.75},{0.25}}
In[]:=
combinedDuration=Total[noteDurations,Infinity]
Out[]=
5.5