Message Boards Message Boards

Import and process MIDI data?

Posted 7 years ago

I'm trying to import MIDI data. As far as I can see, the import function is capable of importing a list of SoundNote[] functions.

sn = Import["Sing-joy.mid", "SoundNotes"]

The file I'm using as a sample at the moment is attached.

When you import the SoundNote list the time information part of each note is formatted as such: {starttime, endtime}

Here is an example of one of the SoundNotes:

SoundNote["E4", {0., 0.6}, "Piccolo", SoundVolume -> 0.862745]

My end goal format is { Time , ListOfNotes } with each note expressed as a number with 0 as middle c paired with a volume.

To make it fit properly I was planning to round all time values to multiples of 0.15

However I'm lost as to an efficient way of doing all this.

Attachments:
POSTED BY: Jeffery Cole
Posted 7 years ago

Hello Jeffery, this code should do approximately what you described.

toHalfTones[ note_] := 
 Module[{octave = ToExpression[StringTake[note, -1]], 
   pitch = StringDrop[note, -1], 
   lst1 = {"C" -> 0, "C#" -> 1, "D" -> 2, "D#" -> 3, "E" -> 4, 
     "E#" -> 5, "F" -> 5, "F#" -> 6, "G" -> 7, "G#" -> 8, "A" -> 9, 
     "A#" -> 10, "B" -> 11, "B#" -> 12}},
  12 (octave - 4) + (pitch /. lst1)]

sn10 = Map[{Round[#[[2]], 0.15], {toHalfTones[#[[1]]], #[[4, 2]]}} &, 
  sn[[2]]]

Please check, I am not an expert on the proper notation of music

POSTED BY: Michael Helmle
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract