Thursday, January 26, 2017

JFugue Jython Example 9. Advanced Rhythms

This is Example 9 from JFugue website (JFugue Examples) in Jython.



# JFugue 9. Advanced Rhythms

import sys
sys.path.append("C:/jfugue-5.0.7.jar")

'''
Through the Rhythm API, you can specify a variety of alternate
layers that occur once or recur regularly. You can even create
your own "RhythmAltLayerProvider" if you'd like to create a
new behavior that does not already exist in the Rhythm API.
'''

from org.jfugue.player import Player
from org.jfugue.rhythm import Rhythm

r = Rhythm()
r = r.addLayer("O..oO...O..oOO..") # This is Layer 0
r = r.addLayer("..S...S...S...S.")
r = r.addLayer("````````````````")
r = r.addLayer("...............+") # This is Layer 3
# Replace Layer 3 with this string on the 4th (count from 0) measure
r = r.addOneTimeAltLayer(3, 3, "...+...+...+...+")
r = r.setLength(4) # Set the length of the rhythm to 4 measures
# Play 2 instances of the 4-measure-long rhythm
Player().play(r.getPattern().repeat(2))

No comments:

Post a Comment