Sinewave Melodic ContourThis tutorial shows how mathematical functions can be used to create melodies. Want to hear it go faster? with more range? Well
you should be able to work out how to do it pretty easily. The GUI will look similar to this (uncanny isn't it!): Let's have a closer look at how its done.
This section covers the importing of the
usual jMusic classes. The show() method that is responsible for the picture above is found
within jm.util.View class.
This section creates the SineMelody class, and
starts off its main method by creating an empty Score, Part and Phrase.
The density variable is also set to define the resolution of notes.
OK, so here is the fun maths bit that does all the
hard work. Look complicated? Not if you paid attention in high school
maths! Remember, the formula for the circumference of a circle is
2*pi*r (pronounced "two pie arrrr" :-). Taking the density variable as
r (the circle's radius), this formula is entered into the for()
statement. Then, a pitch is calculated using Java's inbuilt Math.sin()
method, and a new note is created using this pitch and added into the
phrase.
The end of the SineMelody class should look very familiar. Here, we finish up by adding the new phrase containing our Sine Melody into a Part, and added this to the Score. Show is used to pop up a GUI so we can see the fruits of our efforts, playQT is called to pup up a player to hear the music, and the MIDI file "SineMelody.mid" is created. Now imagine what a tan wave would sound like! |