Read, Write Functions

Read A MIDI File into a Score

You can read a MIDI file into your program using the Read.midi() function. This function expects an empty score and the name of a MIDI file (saved in the same folder as your program). For example,

Read.midi(score, "song.mid")

inputs the musical data from the MIDI file “song.mid”, and stores them into score. Once the file has been read in, then you can manipulate or playback the score. For example,

from music import *

score = Score()              # create an empty score
Read.midi(score, "song.mid") # read MIDI file into it

Play.midi(score)             # play it back

A Score created from an external MIDI file may not be as nicely structured (in terms of Parts, Phrases, and Notes) as a Score created manually through your program.  However, you can still use Score.getPartList(), Part.getPhraseList(), and Phrase.getNoteList() to extract its musical material, and use it as you see fit.

Function Description
Read.midi(score, file) Reads musical material from the MIDI file into the score.


Write a Score to a MIDI File

You can create a MIDI file from your program using the Write.midi() function. This function expects a Score (Part, Phrase, or Note) and a file name. For example,

Write.midi(score, "song.mid")

writes the musical data in score into the MIDI file called “song.mid”. This file is saved in the same folder as your program. If the MIDI file already exists, it will be overwritten.

Function Description
Write.midi(score, file) Writes musical material (Note, Phrase, Part, or Score) into the MIDI file. If the file exists it will be overwritten.