X

Geertjan's Blog

  • March 15, 2007

Transforming Midi Files

Geertjan Wielenga
Product Manager
I received an interesting code snippet from JFugue API's Dave Koelle yesterday. It takes any JFugue Pattern and changes all notes to be played an octave lower:

        // Lower the octaves of the pattern
PatternTransformer octaveTransformer = new PatternTransformer() {
public void noteEvent(Note note)
{
byte currentValue = note.getValue();
if (currentValue > 12) {
note.setValue((byte)(currentValue - 12));
returnPattern.addElement(note);
}
}
};

And here's how to use it:

       Pattern octaveLowerSong = octaveTransformer.transform(song);

So I built a Java desktop client around this code, using a slider to change the octave (and instrument icons to insert instruments into the opened Midi file). Therefore, note that the syntax you see below comes from an actual Midi file, converted to JFugue music strings (thanks to Player.load(file)), that I've opened in the client:

A next step is to transform the music while it is being played. That seems to be possible too. This JFugue API is pretty fun. You only need to focus on the user interface, and on the connection points between the user interface and the JFugue API, not on the underlying Midi magic. And that's the way it should be.

Join the discussion

Comments ( 3 )
  • Jenn Monday, November 19, 2007

    Cheers I tried that out myself and it's pretty good thanks...


  • Geertjan Monday, November 19, 2007

    Great! You can also have a look here for a full blown user interface on top of JFugue API, which you might like to contribute to:

    https://nbjfuguesupport.dev.java.net/


  • Ralph Martin Wednesday, August 27, 2008

    This code generates an error for me:

    returnPattern has private access in org.JFugue.PatternTransformer


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services