Transforming Midi Files

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.

Comments:

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

Posted by Jenn on November 18, 2007 at 07:48 PM PST #

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/

Posted by Geertjan on November 18, 2007 at 08:02 PM PST #

This code generates an error for me:

returnPattern has private access in org.JFugue.PatternTransformer

Posted by Ralph Martin on August 27, 2008 at 07:59 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
19
21
22
23
24
25
26
27
28
29
30
   
       
Today