World Library  
Flag as Inappropriate
Email this Article


Article Id: WHEBN0017436179
Reproduction Date:

Title: JFugue  
Author: World Heritage Encyclopedia
Language: English
Subject: Comparison of MIDI editors and sequencers
Publisher: World Heritage Encyclopedia


JFugue is an open source programming library that allows one to program music in the Java programming language without the complexities of MIDI. It was first released in 2002 by David Koelle. The current version, JFugue 5.0, was released in March 2015. Brian Eubanks has described JFugue as "useful for applications that need a quick and easy way to play music or to generate MIDI files."[1] JFugue is free software released under the Apache License.[2]


Here's an example Java program that will play the C-major scale in JFugue.

import org.jfugue.player.Player;

public class HelloWorld {
  public static void main(String[] args) {
    Player player = new Player();"C D E F G A B");

The string passed to JFugue contains a series of musical instructions that JFugue parses and turns into musical events, which by default are rendered in MIDI. This format, called "Staccato," can represent all of the musical features of MIDI [3] and is specifically designed to be easy for people to read and write.[4] While the default use case for JFugue is to convert Staccato to MIDI, the architecture allows it to read and write musical information from and to a variety of formats (e.g., MIDI to MusicXML,[5] Staccato to LilyPond). Below is an example converting a MIDI file to the Staccato format.

MidiParser parser = new MidiParser();
StaccatoParserListener listener = new StaccatoParserListener();
parser.parse(MidiSystem.getSequence(new File("YourMidiFile.mid"))); // Change to the name of a MIDI file that you own the rights to
Pattern staccatoPattern = listener.getPattern();

JFugue 5.0 contains a set of classes that represent ideas in music theory, including intervals, scales, chords, and chord progressions.

The notion of Patterns is integral to JFugue. Patterns are used to represent phrases of music that can be combined, repeated, and altered using tools that are aware of the musical content of the pattern.

Pattern pattern1 = new Pattern("A B C");
Pattern pattern2 = new Pattern("G F E");
Player player = new Player();;

JFugue 5.0 makes extensive use of fluent interfaces, also known as method chaining, which lets developers write short, expressive pieces of code like the following:

Chord[] chords = new ChordProgression("I IV V").setRoot("C").getChords();

Advanced Features

JFugue is capable of producing microtonal music by using a Staccato element consisting of the letter 'm' followed by the frequency in Hertz of the desired tone. Like other notes in JFugue, this tone may be followed by a duration (such as 'w' for a whole note or 'q' for a quarter note) and note dynamics (e.g., "note on" and "note off" velocities). JFugue converts the microtone frequency to a sequence of MIDI Pitch Wheel and Note events to achieve the desired tone.

Player player = new Player();"m440.0q A4q"); // These sound the same"m568.7w");     // Whole duration note at 568.7 Hertz

JFugue provides an intuitive programming interface for creating beats and rhythms. The characters in the strings below each correspond to a percussion note that is played on the percussive MIDI Channel (the tenth channel); default settings are provided for common sounds (e.g., "O" for "[BASS_DRUM]q"), although any Java Map or Character to String may be passed to the Rhythm constructor.

Rhythm rhythm = new Rhythm()
new Player().play(rhythm.getPattern().repeat(2));

In addition to allowing music to be converted from one music format to another, the architecture of JFugue can be used to create programmatic tools that are capable of both performing computations on incoming music (from any format) and changing incoming music. The example below is a simple tool that keeps track of all instruments used in a musical piece.

public class InstrumentToolDemo {
    public static void main(String[] args) throws InvalidMidiDataException, IOException {
        MidiParser parser = new MidiParser(); // Remember, you can use any Parser!
        InstrumentTool instrumentTool = new InstrumentTool();
        parser.parse(MidiSystem.getSequence(new File("YourMidiFile.mid"))); // Change to a real filename
        List instrumentNames = instrumentTool.getInstrumentNames();
        for (String name : instrumentNames) {

class InstrumentTool extends ParserListenerAdapter {
    private List instrumentNames;
    public InstrumentTool() {
        instrumentNames = new ArrayList();
    public void onInstrumentParsed(byte instrument) {
        String instrumentName = MidiDictionary.INSTRUMENT_BYTE_TO_STRING.get(instrument);
        if (!instrumentNames.contains(instrumentName)) {
    public List getInstrumentNames() {
        return this.instrumentNames;

JFugue provides functionality on top of Java's MIDI Transmitter and Receiver classes to reduce the amount of code that a developer would need to write to connect to external MIDI devices.

Uses in Other Applications

JFugue has been used in a number of applications, including software projects and artistic installations.

  • TransProse, which turns classic novels into music, uses JFugue[6]
  • The JFugue Music NotePad provides a user interface for composing music[7]
  • JFrets is an application for teaching and training guitar tablature[8]
  • Log4JFugue is a utility for converting log files created by log4j into musical patterns; this allows one to listen for changes in a log file, which provides a much different experience than reading through the file line-by-line.[9][10]

JFugue has been used to play music when a software build fails or succeeds.

JFugue is one of the few Java libraries that lets one do something interesting in as little as one or two lines of code. This distinction earned JFugue a place in the book "Groovy in Action"[11]


  1. ^ Eubanks, Brian D. (2005), "Wicked Cool Java". pp. 154–156.
  2. ^
  3. ^ "The Complete Guide to JFugue," Chapter 2, ""
  4. ^ ""
  5. ^ Recordare LLC, "
  6. ^ About TransProse, ""
  7. ^ JFugue Music NotePad project, ""
  8. ^ JFrets project, ""
  9. ^ Log4JFugue, ""
  10. ^ PragPub Magazine, Issue 3, September 2009, ""
  11. ^ Koenig, Dierk, et al. (2007)

External links

  •—Official JFugue website
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.