Wednesday, January 25, 2017

JFugue Jython Example 8. Introduction to Rhythms

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



# JFugue 8. Introduction to Rhythms

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

'''
One of my favorite parts of the JFugue API is the ability
to create rhythms in a fun and easily understandable way.
The letters are mapped to percussive instrument sounds,
like "Acoustic Snare" and "Closed Hi Hat". JFugue comes
with a default "rhythm set", which is a Map
with entries like this: put('O', "[BASS_DRUM]i").
'''

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

def getRhythm():
    r = Rhythm()
    r = r.addLayer("O..oO...O..oOO..")
    r = r.addLayer("..S...S...S...S.")
    r = r.addLayer("````````````````")
    r = r.addLayer("...............+")
    return r
    

rhythm = getRhythm()
Player().play(rhythm.getPattern().repeat(2))

It is best to use simple variables, like r, in local scope, and longer and more descriptive variables in global namespace.


No comments:

Post a Comment