toolbox
F5#
E5
D5
C5
A4#
G4#
F4#
E4
h
c
t
i
P
D4
0
1
2
3
6
7
8
4
5
Time in seconds
MATLAB Tools
for Music Research
Tuomas Eerola & Petri Toiviainen
MIDI Toolbox
MATLAB Tools
for Music Research
Tuomas Eerola & Petri Toiviainen
Music Cognition Group
Copyright ©: Tuomas Eerola & Petri Toiviainen
Cover & layout: Tuomas Eerola & Petri Toiviainen
Publisher: Department of Music, University of Jyväskylä, Finland
Printing and binding: Kopijyvä, Jyväskylä, Finland
ISBN: 951-39-1796-7 (printed version)
ISBN: 951-39-1795-9 (pdf version)
Document data:
Eerola, T. & Toiviainen, P. (2004). MIDI Toolbox: MATLAB Tools for Music
Research. University of Jyväskylä: Kopijyvä, Jyväskylä, Finland.
Electronic version available from: http://www.jyu.fi/musica/miditoolbox/
4
■ CONTENTS
CONTENTS
■ CHAPTER 1 – INTRODUCTION.................................................................................... 6
■ CHAPTER 2 – INSTALLATION..................................................................................... 8
■ CHAPTER 3 – BASIC OPERATIONS............................................................................ 9
■ CHAPTER 4 – EXAMPLES ........................................................................................... 15
■ EXAMPLE 1: VISUALIZING MIDI DATA............................................................... 15
■ EXAMPLE 2: MELODIC CONTOUR........................................................................ 21
■ EXAMPLE 3: KEY-FINDING................................................................................... 24
■ EXAMPLE 4: METER-FINDING.............................................................................. 29
■ EXAMPLE 5: MELODIC SEGMENTATION.............................................................. 32
■ EXAMPLE 6: MELODIC EXPECTATIONS............................................................... 34
■ EXAMPLE 7: MELODIC COMPLEXITY.................................................................. 37
■ EXAMPLE 8: ANALYZING MIDI COLLECTIONS .................................................. 38
■ EXAMPLE 9: MELODIC SIMILARITY..................................................................... 41
■ EXAMPLE 10: CREATING SEQUENCES ................................................................. 43
■ REFERENCES.......................................................................................................... 45
■ CHAPTER 5 – FUNCTION REFERENCE................................................................... 48
■ ALPHABETICAL INDEX OF FUNCTIONS................................................................ 96
■ MIDI Toolbox ■
■ CHAPTER 1 – INTRODUCTION
6
CHAPTER 1 – INTRODUCTION
MIDI Toolbox provides a set of Matlab functions, which together have all the
necessary machinery to analyze and visualize MIDI data. The development of the
Toolbox has been part of ongoing research involved in topics relating to musical data-
mining, modelling music perception and decomposing the data for and from
perceptual experiments. Although MIDI data is not necessarily a good representation
of music in general, it suffices for many research questions dealing with concepts
such as melodic contour, tonality and pulse finding. These concepts are intriguing
from the point of view of music perception and the chosen representation greatly
affects the way these issues can be approached. MIDI is not able to handle the timbre
of music and therefore it unsuitable representation for a number of research questions
(for summary, see Hewlett and Selfridge-Field, 1993-94, p. 11-28). All musical
signals may be processed from acoustic representation and there are suitable tools
available for these purposes (e.g. IPEM toolbox, Leman et al., 2000). However, there
is a body of essential questions of music cognition that benefit from a MIDI-based
approach. MIDI does not contain notational information, such as phrase and bar
markings, and neither is that information conveyed in explicit terms to the ears of
music listeners. Consequently, models of music cognition must infer these musical
cues from the pitch, timing and velocity information that MIDI provides. Another
advantage of the MIDI format is that it is extremely wide-spread among the research
community as well as having a wider group of users amongst the music professionals,
artists and amateur musicians. MIDI is a common file format between many notation,
sequencing and performance programs across a variety of operating systems.
Numerous pieces of hardware exist that collect data from musical performances,
either directly from the instrument (e.g. digital pianos and other MIDI instruments) or
from the movements of the artists (e.g. motion tracking of musician’s gestures, hand
movements etc.). The vast majority of this technology is based on MIDI
representation. However, the analysis of the MIDI data is often developed from
scratch for each research question. The aim of MIDI Toolbox is to provide the core
representation and functions that are needed most often. These basic tools are
designed to be modular to allow easy further development and tailoring for specific
analysis needs. Another aim is to facilitate efficient use and to lower the “threshold of
practicalities”. For example, the Toolbox can be used as teaching aid in music
cognition courses.
This documentation provides a description of the Toolbox (Chapter 1), installation
and system requirements (Chapter 2). Basic issues are explained in Chapter 3. Chapter
4 demonstrates the Toolbox functions using various examples. The User’s Guide does
not describe any of the underlying theories in detail. Chapter 5 focuses on a collection
format and Chapter 6 is the reference section, describing all functions in the Toolbox.
The online reference documentation provides direct hypertext links to specific
Toolbox functions. This is available at http://www.jyu.fi/musica/miditoolbox/
■ MIDI Toolbox ■
CHAPTER 1 – INTRODUCTION ■
7
This User’s Guide assumes that the readers are familiar with Matlab. At the moment,
the MIDI Toolbox is a collection of Matlab functions that do not require any extra
toolboxes to run. Signal processing and Statistics toolboxes – both available
separately from Mathworks – offer useful extra tools for the analysis of perceptual
experiments.
MIDI Toolbox comes with no warranty. This is free software, and you are welcome to
redistribute it under certain conditions. See License.txt for details of GNU
General Public License.
We would like to thank various people contributing to the toolbox. The conversion to
and from MIDI file is based on the C source code by Piet van Oostrum, which, in
turn, uses the midifile library written by Tim Thompson and updated by Michael
Czeiszperger. Brian Cameron found out some sneaky bugs in the aforementioned C
source code. Micah Bregman helped to check parts of the manual and wrote out some
new functions.
Comments, suggestions or questions?
Many functions are still not completely tested in MIDI Toolbox version 1.0. Check
the online forum for corrections and revisions:
http://www.jyu.fi/musica/miditoolbox/forum.html
Alternatively, you can report any bugs or problems to:
Tuomas Eerola, Petri Toiviainen
{ptee, ptoiviai}@cc.jyu.fi
Department of Music
University of Jyväskylä
P.O. BOX 35
40014 University of Jyväskylä
Finland
■ MIDI Toolbox ■
■ CHAPTER 1 – INTRODUCTION
8
CHAPTER 2 – INSTALLATION
Availability
The whole toolbox is available either as a zipped package from the internet
(http://www.jyu.fi/musica/miditoolbox/).
Installation
Unpack the MIDI Toolbox file package you have downloaded. For this, use a program
like Winzip for Windows and Stuffit Expander for Macintosh. This will create a
directory called miditoolbox. Secondly, a version of the Matlab program needs to be
installed (see www.mathworks.com). Thirdly, the Toolbox needs to be defined in
the Matlab path variable.
Windows (98, 2000, XP)
The MIDI Toolbox version 1.0 is compatible with Matlab 5.3 and Matlab 6.5.
Macintosh (OS X)
The MIDI Toolbox version 1.0 is compatible with Matlab 6.5 for Macintosh.
Linux
Currently not tested but should be compatible.
■ MIDI Toolbox ■
9
CHAPTER 3 – BASIC OPERATIONS ■
CHAPTER 3 – BASIC OPERATIONS
good
tutorials
exist
in
the
Internet,
syntax. Many
http://www.math.ufl.edu/help/matlab-tutorial/
http://www.math.mtu.edu/~msgocken/intro/intro.html
http://www.helsinki.fi/~mjlaine/matlab/index.html (in Finnish)
http://www.csc.fi/oppaat/matlab/matlabohje.pdf (in Finnish)
Basic issues
In this tutorial, we assume that the reader has basic knowledge of the Matlab
command
see:
In the following examples, the commands that are typed to Matlab command prompt
are written in monospaced font and are preceded by the » sign. Help is also
available within the Matlab session. For example, to understand what a particular
function does, type help and the name of the function at the command prompt. For
example, to obtain information about how the pitch-class distribution function works,
type:
To see a list of all available functions in the Toolbox, type:
» help miditoolbox
» help pcdist1
Reading MIDI files into Matlab
The basic functions in MIDI Toolbox read and manipulate type 0 and type 1 MIDI
files. The following command reads and parses a MIDI file called laksin.mid and
stores it as a matrix of notes called nmat in Matlab’s workspace:
This particular MIDI file contains the first two verses of a Finnish Folk song called
"Läksin minä kesäyönä" (trad.).
» nmat = readmidi('laksin.mid');
Basic terms
Notematrix (or nmat) refers to a matrix representation of note events in a MIDI file.
We can now type nmat and see what the notematrix of the folk song looks like.
■ MIDI Toolbox ■