2

I'm using "music21" library to process MIDI files. Unfortunately, the provided documentation is not so clear for ones who don't understand much about how music is composed. What is the difference between "duration" and "offset"? For what I understand, the first note/chord have offset 0.0, and let's suppose, its has duration 1.0. Then, the following note/chord have offset 1.0 and duration 0.5. Then, offset 1.5 and duration 2 and so on. But sometimes it has the same value. I'm confused. Code:

s2 = instrument.partitionByInstrument(midi)
duration = s2._elemets[0]._elements[9].duration
"<music21.duration.Duration 12.0>"
offset = s2._elemets[0]._elements[9].offset
"12.0"
demo
  • 421
  • 5
  • 22

1 Answers1

4

Offset is (roughly) the length of time from the start of the piece. Duration is the time the note is held. The offset of a note will only be the sum of the previous durations if there are no rests (silences) in the piece and there are no cases where two notes sound together.

BoarGules
  • 16,440
  • 2
  • 27
  • 44
  • So imagine that I want to extract the "rhythm" of the song and suppose it's only piano. The rhythm of the song is given by duration of each note? Or is considered part of the rhythm too ? – demo Mar 29 '19 at 15:27
  • 1
    Umm, that is a big question, and *hard*. I think you would have to first deduce the time signature, and identify the first beat of every bar. Those would be the notes with offsets that are integer multiples of some common factor. For example, in 4/4 time the first beat of every bar would fall at offset 0x, 4x, 8x etc. Naturally with some exceptions for suspensions. (I know this is possible because notation programs can do it.) After that, rhythm would be indicated by the offsets and/or durations of the notes in each bar, or maybe group of bars. – BoarGules Mar 29 '19 at 15:46