Friday, January 27, 2017

JFugue Jython Example 12. Connecting Any Parser to Any ParserListener

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



# JFugue 12. Connecting Any Parser to Any ParserListener

'''
You can use JFugue to convert between music formats.
Most commonly, JFugue is used to turn Staccato music
into MIDI sound. Alternatively, you can play with the
MIDI, MusicXML, and LilyPond parsers and listeners.
Or, you can easily create your own parser or listener,
and it will instantly interoperate with the other
existing formats. (And if you convert to Staccato,
you can then play the Staccato music... and edit it!)
'''

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

from java.io import File
from javax.sound.midi import MidiSystem
from org.jfugue.midi import MidiParser
from org.jfugue.player import Player
from org.staccato import StaccatoParserListener

parser = MidiParser()
listener = StaccatoParserListener()
parser.addParserListener(listener)
parser.parse(MidiSystem.getSequence(File("RowYourBoat.mid")))
staccatoPattern = listener.getPattern()

print staccatoPattern

player = Player()
player.play(staccatoPattern)

No comments:

Post a Comment