Sunday, January 29, 2017

JFugue Jython Example 15. Anticipate Musical Events Before They Occur

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



# JFugue 15. Anticipate Musical Events Before They Occur

'''
You might imagine creating new types of ParserListeners,
like an AnimationParserListener, that depend on knowing
about the musical events before they happen. For example,
perhaps your animation is of a robot playing a drum or
strumming a guitar. Before the note makes a sound, the
animation needs to get its virtual hands in the right
place, so you might want a notice 500ms earlier that
a musical event is about to happen. To bend time with
JFugue, use a combination of the TemporalPLP class
and Player.delayPlay(). delayPlay() creates a new
thread that first waits the specified amount of
time before playing. If you do this, make sure to
call delayPlay() before plp.parse().
'''

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

from org.jfugue.player import Player
from org.jfugue.temporal import TemporalPLP
from org.staccato import StaccatoParser
from org.jfugue.devtools import DiagnosticParserListener

MUSIC = "C D E F G A B"
TEMPORAL_DELAY = 500

# Part 1. Parse the original music
parser = StaccatoParser()
plp = TemporalPLP()
parser.addParserListener(plp)
parser.parse(MUSIC)

# Part 2. Send the events from Part 1,
# and play the original music with a delay
dpl = DiagnosticParserListener()
# Or your AnimationParserListener!
plp.addParserListener(dpl)
Player().delayPlay(TEMPORAL_DELAY, MUSIC)
plp.parse()

No comments:

Post a Comment