On Sun, 7 Feb 2010, Philippe Hezaine wrote:
I'm looking for randomize Note On from a midi file.
I have two way for sending this file, a standard file generated by
Lilypond or a text file by midicomp.
Here is an excert from midicomp file:
062:00:000 On ch=10 note=f#3 vol=105
063:-1:-576 Off ch=10 note=f#3 vol=64
063:-1:-384 On ch=10 note=f#3 vol=95
063:-1:-192 Off ch=10 note=f#3 vol=64
063:-1:000 On ch=10 note=f#3 vol=127
063:00:-576 Off ch=10 note=f#3 vol=64
068:00:000 On ch=10 note=f#3 vol=127
069:-1:-576 Off ch=10 note=f#3 vol=64
074:00:000 On ch=10 note=f#3 vol=127
074:00:192 Off ch=10 note=f#3 vol=64
074:00:384 On ch=10 note=f#3 vol=95
074:00:576 Off ch=10 note=f#3 vol=64
074:01:000 On ch=10 note=f#3 vol=105
074:01:192 Off ch=10 note=f#3 vol=64
I'm looking for randomizing the third column: 192 or -576...
between + or -3 units for instance. ( 000 is a special case)
Try the attached python filter and see how it suits you.
You can use it in a pipe like this:
$ cat that-data-quoted-above.txt | python timerander.py
However, if you're tryint to "humanize" the data, you might
consider replacing the line that has random.randint(min,
max) with something like:
c = int(c) + int(random.gauss(0.0, 1.0))
HTH,
Gabriel
#!env python
#
import sys
import random
# Config:
rand_min = -3
rand_max = 3
def main():
global rand_min, rand_max
random.seed()
for line in sys.stdin:
line = line.rstrip()
if len(line) == 0:
continue
first, second = line.split(' ', 1)
a, b, c = first.split(':')
c = int(c) + random.randint(rand_min, rand_max)
if( c >= 0 ):
out = "%s:%s:%03d" % (a, b, c)
else:
out = "%s:%s:%+04d" % (a, b, c)
out = ' '.join( (out, second) )
print out
if __name__ == "__main__":
main()
_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@xxxxxxxxxxxxxxxxxxxx
http://lists.linuxaudio.org/listinfo/linux-audio-user