The JMelodyMaker

The JMelodyMaker is a graphical user interface application written in Java using the Java Development Kit 1.3.1. Through the use of the JMusic API developed by Andrew Brown and Andrew Sorenson, the application generates a unique, 16 measure musical melody in the form of a midi file based on a set of rules taken from music theory. The topic of computer music composition was chosen as the focus for this project because of my own knowledge and past experience with music. Due to the mathematical nature of music theory, I found that expressing musical concepts through algorithms and functions would be a challenging, yet attainable task.

The Java Swing package was used to build the graphical interface that allows the end-user to supply inputs and parameters that affect various characteristics of the melody generation process. A JMenuBar is used to give the application a sense of sequential order. An integer variable named "state" is updated dependant on the user's interactions with the GUI. This variable determines which JMenuBar options and JPanels are visible to the user. When the "New" option is selected from the initial start-up screen, a JDialog Panel becomes visible that prompts the user to enter a filename for the future midi file. Next, a JTabbedPane appears with three JPanel objects, Key/Tempo(AudioPanel), Form(FormPanel), and Voice(VoicePanel). Each panel contains Swing components that hold user inputs that form the final melody. When the "Create File" option is selected from the File menu, the input data is sent to the constructor of the Melody class, where the musical data is generated and passed through the JMusic interface which creates the midi file. An enabled play JButton in the bottom right-hand corner of the GUI allows for real-time playback of the file through the use of the javax.sound package.

Java's object-oriented paradigm allowed for the encapsulation of the music rules and concepts necessary for creating the run-time melody. Two classes specifically deal with this task: Melody.java and HarmonicRhythm.java. The HarmonicRhythm class is responsible for randomly determining which chords are to be in the piece and how long each chord is to last. The Melody class takes these values, which are stored in two public arrays and generates duration values for the melody based on the length of each chord. These values are stored in an array called DurationHolder. Next, a function called NotePitch() is called that attaches a pitch to every duration value that was generated in the previous step. In this function, a switch statement is present that contains a function call for each one of its cases. These function calls correspond to melodic motive standards of music theory that encapsulate patterns for melodic composition: appogiatura, escape tone, change tone, neighbor tone, and passing tone. Each case is activated randomly, the function is called, and pitch values are generated until each duration value has a corresponding pitch value, stored in an array named PitchHolder. The resulting data is used in the JMusic interface to create the midi file.

The JMelodyMaker has many practical uses: as a teaching tool for music theory instructors who would like to outline various music theory concepts, for application developers who aren't musicians but would like to add a musical composition to their software, or for musicians who are involved in computer music. Because the JMelodyMaker was created in Java, future improvements and expansions on the project can be done easily.