I590/N560 MIDI FILE TO MELODIC INTERVALS ASSIGNMENT Donald Byrd, 6 October 2006 The musical purpose of this assignment is to calculate how many times each melodic interval, ignoring octaves and up/down direction, occurs in a melody. Not very interesting in itself, but this is a first step towards a program to create melodies that imitate a given style. http://www.informatics.indiana.edu/donbyrd/N560Site-Fall06/Dichterliebe01.mid ...is a MIDI file of the first song from Schumann's wonderful song cycle, Dichterliebe; it's for voice and piano. You can find a PDF of the notation (as well as MusicXML) at http://www.recordare.com/xml/samples.html. For this assignment, we're interested only in the voice part. The format of MIDI files is not simple at all, but you're lucky: you don't have to read the MIDI file itself, since I've already converted it to text form and saved the result at http://www.informatics.indiana.edu/donbyrd/N560Site-Fall06/Dichterliebe01PMIDI.txt But the format of the text file still isn't THAT simple. In general, each line contains five fields, separated by tabs: 1. Cumulative time (time since the beginning of the track) 2. Delta time (time since the previous event) 3. Status byte 4. Data bytes 5. Description And of course we need to ignore the piano, as well as Note Off events and everything else other than Note Ons. But you're in luck again! I removed everything but the Note Ons; Yushen removed the piano part, and figured out an easy way to read it and access what we want: the data bytes. Actually, for a Note On event, there's only one data byte, and it's the MIDI "note number". (60 = middle C, 61 = C# or Db above middle C, etc.) After setting R's working directory to whereever you put the file, use read.table to read all its data in: noteTable = read.table("Dichterliebe01PMIDI.txt", header=TRUE) Then you can access the vector that contains the MIDI note numbers with either 'noteTable$DataByte' or 'noteTable[4]'. To calculate the melodic intervals, start with the difference between each note's note number and the previous one; take its absolute value; and take that value modulo 12 (with R's %% operator). For example, the first few notes have note numbers 73, 73, 71, 71, 74, 66. The differences are 0, -2, 0, 3, -8; the absolute values of the differences are 0, 2, 0, 3, 8. So, in these notes, an interval of 0 occurs twice, and intervals of 2, 3, and 8 semitones occur once each. Have your program do this for the entire melody and then print the resulting table. E-mail the program to me.