This is Example 14 from JFugue website (JFugue Examples) in Jython.
# JFugue 14. Play Music in Realtime
'''
Create interactive musical programs using the RealtimePlayer.
'''
import sys
sys.path.append("C:/jfugue-5.0.7.jar")
import random
from org.jfugue.pattern import Pattern
from org.jfugue.realtime import RealtimePlayer
from org.jfugue.theory import Note
player = RealtimePlayer()
quit = False
s = [None]*3
s[0]="Enter a '+C' to start a note,"
s[1]="'-C' to stop a note, 'i' for a random instrument,"
s[2]="'p' for a pattern, or 'q' to quit\n"
info = " ".join(s)
PATTERNS = [Pattern("Cmajq Dmajq Emajq"),
Pattern("V0 Ei Gi Di Ci V1 Gi Ci Fi Ei"),
Pattern("V0 Cmajq V1 Gmajq")]
while quit == False:
entry = raw_input(info)
if entry.startswith("+"):
player.startNote(Note(entry[1:]))
elif entry.startswith("-"):
player.stopNote(Note(entry[1:]))
elif entry.lower()=="i":
player.changeInstrument(random.randint(0,127))
elif entry.lower()=="p":
player.play(random.choice(PATTERNS))
elif entry.lower()=="q":
quit = True
player.close()
No comments:
Post a Comment