I've written a program using the Java MIDI system that attempts to analyse the contents of a music track and interpret it into notes played. The one technical part of this is understanding the concept of PPQN and how it relates to MIDI ticks.
A tick in a MIDI file is a time-marker which is independent of actual time. All you can say is that tick 0 is at the start of the piece and that tick 1 comes after tick 0 and before tick 2. And so on.
So how do you know when to play a note?
This is related to the PPQN value which specifies, for the piece, how many pulses (known interchangably as ticks) make up one quarter note. So a PPQN value of 4 mean that 4 ticks make a quarter note.
MIDI uses a system of events to specify how the music is played so that there is a NOTE_ON event which specifies on which tick a specific note is to begin playing and a NOTE_OFF event which specifies when it should stop, except when it doesn't. This is where things get grisly.
A NOTE_ON event specifies which note is to be played along with something called a velocity. The velocity is a measure of how hard the note is struck (MIDI has a bit of a keyboard which I guess is reflected in that most synthesizers were keyboards). Velocity is certainly related to the amplitude (loudness) of the sound but also to the sound envelope.
Anyway suffice to say I have discovered that instead of a NOTE_OFF event it is possible to receive a NOTE_ON event with a velocity of 0 instead.
Okay so at a certain tick value we get a NOTE_ON with a velocity greater than zero, then at another tick value we either get a NOTE_OFF or a NOTE_ON with a velocity of zero. This means that we know the note lasts for a certain number of ticks.
Using the formula:
- tick_duration / ( 4 * PPQN )
we can work out the length, in whole notes, of the specified note.
I think....
The reason for my lack of confidence is that the sites I have been reading have confidently predicted that most music is played in whole-note, half-note, quarter-note and so on. Yet just analysing three classical pieces:
- A section of Beethovens pastoral symphony
- Philip Glass - Metamorphosis#1
- Philip Glass - Mad Rush
As well as the regular whole notes (1.0), quarter notes (0.25), and, eighth notes (0.125) I have also come across 0.15364583333333334 notes, 0.20833333333333334 notes, and 0.08333333333333333 notes!
Guess I have more learning to do.