User:Natasa Siencnik/prototyping/markov: Difference between revisions
Line 64: | Line 64: | ||
=====Python : Script 2011-05-24===== | =====Python : Script 2011-05-24===== | ||
<source lang=" | <source lang="python"> | ||
#!/usr/bin/env python | |||
import random | |||
fugue = {} | |||
fugue = { | |||
"/l2/d4":["/l2/a4", "/l2/c+4"], | |||
"/l2/a4": ["/l2/f4"], | |||
"/l2/f4": ["/l2/d4", "/l8/f4"], | |||
"/l2/c+4": ["/l4/d4"], | |||
"/l4/d4": ["/l4/e4"], | |||
"/l4/e4": ["/l2/f4"], | |||
"/l8/f4": ["/l8/g4","/l8/e4"], | |||
"/l8/g4": ["/l8/f4"], | |||
"/l8/e4": ["/l2/d4"] | |||
} | |||
print """ | |||
@head { | |||
$time_sig 4/4 | |||
$tempo 220 | |||
} | |||
@body { | |||
@channel 1 { | |||
$patch 1 | |||
$octave 4 | |||
$length 16 | |||
""" | |||
tone = "/l2/d4" | |||
for x in range(64): | |||
print tone | |||
#this new variable tone is overwriting the old tone! => variable as empty bowl symbolism | |||
tone = random.choice(fugue[tone]) | |||
print """ | |||
} | |||
} | |||
""" | |||
</source> | </source> | ||
natasa@natasa-linux:~/pzi/3_TRIMESTER/PROTOTYPING/20110524_fugue$ python fugue.py | midge | |||
found 1 music tracks | |||
midi output written to a.out.mid | |||
natasa@natasa-linux:~/pzi/3_TRIMESTER/PROTOTYPING/20110524_fugue$ timidity a.out.mid | |||
===Useful Links=== | ===Useful Links=== | ||
<span style="font-size:7.5pt"> | <span style="font-size:7.5pt"> |
Revision as of 15:27, 24 May 2011
The Art of the Fugue
MARKOV CHAIN WITH J.S. BACH
Concept
Scripting Progress
Python : Script 2011-05-23
#!/usr/bin/env python
import random
fugue = {}
fugue = {
"l2/d3":["l2/a3", "l2/c+3"],
"l2/a3": ["l2/f3"],
"l2/f3": ["l2/d3", "l8/f3"],
"l2/c+3": ["l4/d3"],
"l4/d3": ["l4/e3"],
"l4/e3": ["l2/f3"],
"l8/f3": ["l8/g3","l8/e3"],
"l8/g3": ["l8/f3"],
"l8/e3": ["l2/d3"]
}
# start with first / one tone (KEY) in the dictionary
# look in the list of the KEY to find next possibilities
# pick a random VALUE from the list that belongs to the key
# asign this next tone to start this loop again
# variable tones
for t in enumerate(tones):
print t, tones[i+1]
random.choice()
#MIDGE
@head {
$time_sig 2/2
$tempo 120
}
@body {
@channel1 {
$patch 1
$octave 4
$length 16
# tones here
}
}
#MIDI FILE
#play with timidity
Python : Script 2011-05-24
#!/usr/bin/env python
import random
fugue = {}
fugue = {
"/l2/d4":["/l2/a4", "/l2/c+4"],
"/l2/a4": ["/l2/f4"],
"/l2/f4": ["/l2/d4", "/l8/f4"],
"/l2/c+4": ["/l4/d4"],
"/l4/d4": ["/l4/e4"],
"/l4/e4": ["/l2/f4"],
"/l8/f4": ["/l8/g4","/l8/e4"],
"/l8/g4": ["/l8/f4"],
"/l8/e4": ["/l2/d4"]
}
print """
@head {
$time_sig 4/4
$tempo 220
}
@body {
@channel 1 {
$patch 1
$octave 4
$length 16
"""
tone = "/l2/d4"
for x in range(64):
print tone
#this new variable tone is overwriting the old tone! => variable as empty bowl symbolism
tone = random.choice(fugue[tone])
print """
}
}
"""
natasa@natasa-linux:~/pzi/3_TRIMESTER/PROTOTYPING/20110524_fugue$ python fugue.py | midge found 1 music tracks midi output written to a.out.mid natasa@natasa-linux:~/pzi/3_TRIMESTER/PROTOTYPING/20110524_fugue$ timidity a.out.mid
Useful Links
http://en.wikipedia.org/wiki/The_Art_of_Fugue
http://pzwart3.wdka.hro.nl/wiki/Poetry_generators
http://pzwart3.wdka.hro.nl/wiki/Sedsongs#midge