Skip to content

mxm, IT's mad science

Sections
Personal tools
You are here: Home » Products » Open Source » Python Midi Package » rests
Downloads
You can download mxm products here.

Due to it's technical and international nature, this section is in english.

Max M Has a blog too.

og er glad for mad

 

Comment

Above in this comment thread: Python Midi Package

rests

Posted by Anonymous User at 2008-04-18 04:15 AM
Thank you, first and foremost, for making this... I've been looking for something like this for a long time, and the "Frets on Fire" guy below got me here via Google Cache.

Anyways, to my problem: I am writing a program which reads a text file of 0's and 1's, then converts them into 16th notes in a MIDI file (1 is a note, 0 is a rest). For some reason, the output file shows the correct number of notes, but they are placed next to each other with none of the rests between. Here is a sample of the code (the list is made of the first 16 characters of each line in the text file, eliminating newlines):


for line in text:
beat = list(line)
if int(beat[0]):
midi.update_time(0)
midi.note_on(channel=0, note=0x40)
midi.update_time(24)
midi.note_off(channel=0, note=0x40)
else:
midi.update_time(24)
if int(beat[1]):
midi.note_on(channel=0, note=0x40)
midi.update_time(24)
midi.note_off(channel=0, note=0x40)
else:
midi.update_time(24)

# ... continues to "if int(beat[15]):", then goes on to


midi.update_time(0)
midi.end_of_track()

midi.eof()

I am baffled as to why the rests don't appear, but perhaps I just don't have a good enough understanding of update_time(n).

solved

Posted by Anonymous User at 2008-04-18 05:20 AM
aha, i've answered my own question. My problem was that sequential update_time(n) messages override each other, so

midi.note_on(...)
midi.update_time(24)
midi.update_time(47)
midi.update_time(30)
midi.note_off(...)

would be the same as

midi.note_on(...)
midi.update_time(30)
midi.note_off(...).

Since my program requires sequential update_time(n)s, I need to use "blank" midi messages that interrupt update_time. Therefore I could not only use rel_time() or something to that effect, as it does not actually hold a place in the midi file and ergo does not interrupt the count. I used note_off(...) when there was no note playing, which serves the purpose of the "blank" function:

...
if int(beat[2]):
midi.note_on(channel=0, note=0x40)
midi.update_time(24)
midi.note_off(channel=0, note=0x40)
midi.update_time(0)
else:
midi.note_off(channel=0, note=0x40)
midi.update_time(24)
...

Simple enough, I guess.

Thanks a lot, max, this is an amazing module. will come in handy many times