File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes sugar needed for Java! help me, please. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sugar needed for Java! help me, please. " Watch "sugar needed for Java! help me, please. " New topic
Author

sugar needed for Java! help me, please.

parthiban rajendran
Greenhorn

Joined: Oct 05, 2005
Posts: 8
hello friends,
i am now studying the "head first java" book and i am now at the end of the 12th chapter "A very Graphic story". at this stage, i understand something of how to create a midi file and now i want to build a midi song instead of some random tunes getting generated. but i do not know any ABCD of music notes or the relation of parameters with real world music notes.
so i would like you people to suggest some source where i can get the values of parameters needed (not even the source code to generate the song. just java-ised (a new techni-word by me!) musical note needed) to generated a song.
any song. i prefer english. if indians read this, i request them for hindi(which i don know) or tamil(which i know very well) songs. please help me friends. please send the reply as soon as possible.

[Please use the forum, not email. Removed the email address. - Ilja]

[ October 14, 2005: Message edited by: parthiban rajendran ]
[ October 15, 2005: Message edited by: Ilja Preuss ]

i love 'drinking' java
Michael Lloyd Lee
Greenhorn

Joined: Sep 07, 2005
Posts: 22
I'm sorry, but I really do not understand your question.

Are you after sheet music? (If so your'll also need to learn the basics on how to read sheet music, not a quick task).


Please please please use code tags!<br /> <br /><a href="http://java.sun.com/j2se/1.5.0/docs/api/" target="_blank" rel="nofollow">Java API</a> - <a href="http://java.sun.com/docs/books/tutorial/index.html" target="_blank" rel="nofollow">Java Tutorials</a>
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
If you're looking for music theory, I was a music major and could give you a ton but just google for music theory tutorials and find better teachers than me.

There are bazillions of MIDI files on the web (by actual count!) Google for MIDI files and see what you find. Studying exsting files may give you a good idea of what is going on.

I haven't looked at the Java classes ... is there one that can read a MIDI file and produce a collection of MIDI messages? If not, that would be a very cool exercise. You can study the messages one at a time and see what effect they are having. Note messages are easy - they send note numbers 0..127 to some instrument. Pitched instruments convert these to notes on the scale. In General Midi note 69 is A-440. The Velocity parameter is like how hard you hit a piano key. There is no note duration parameter; you send a note off or velocity zero to end the sound.

Controller messages do bends and volume changes and such. SysEx messages give hardware-specific custom instructions.

Is that the kind of info you were after?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I'm have only looked at the Java MIDI libraries briefly. Perhaps the OP is asking a question I have, but have never found an answer to:

How do you make Java play a given note? Say I have a sheet of music, how do I reproduce it in Java with the same notes and rhythms (or at least close enough to be recognizable). For now, I would start by hardcoding values for a specific song, but then I would go on to make it more general.

Is this what you are asking, parthiban?

Layne


Java API Documentation
The Java Tutorial
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Here's a good place to start looking for code examples...

http://www.softsynth.com/links/java_music.html


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
parthiban rajendran
Greenhorn

Joined: Oct 05, 2005
Posts: 8
friends,
i observe that some do not understand my question. actually it is very easy to create MIDI files using java. but to create "a good music", does, ofcourse need a good musical background too (like where to put a high C and bla-bla-bla) i would like to present a small simple file which can show you how easy it is to create a music note in java. the program is shown below.

import javax.sound.midi.*;

public class testMusic1
{

public static void main(String args[])
{
testMusic1 mini = new testMusic1();
mini.play();
}



public void play()
{

try{


//GET THE CD PLAYER and SWITCH IT ON
Sequencer player = MidiSystem.getSequencer();
player.open();



//GET THE CD
Sequence seq = new Sequence(Sequence.PPQ, 4);




//CREATE A SINGLE TRACK IN THE CD
Track track = seq.createTrack();





//--------- creating the SONG ---------------------
/*
CREATE EACH MESSAGE AND MIDIEVENT
AND AS AND WHEN CREATED, ADD THEM TO TRACK
*/

ShortMessage a = new ShortMessage();
a.setMessage(144,1,44,100);
MidiEvent noteOn = new MidiEvent(a,1);
track.add(noteOn);

ShortMessage b = new ShortMessage();
b.setMessage(128,1,44,25);
MidiEvent noteOff = new MidiEvent(b,10);
track.add(noteOff);
//--------- end of the SONG -----------------------




//NOW CD HAS THE SONG. PUT THE CD IN THE CD PLAYER
player.setSequence(seq);



//PUSH THE PLAY BUTTON OF THE PLAYER
player.start();

}

catch(Exception ex){
ex.printStackTrace();
}

}


}

note: just change the 3rd argument of setMessage function and music at different "pitch" will be played.
i have compared creating the music in java, with playing a CD in CD player (the typical kathy's style of explanation). the parameters of the following lines will say "how" and "when" the note should be played.

ShortMessage a = new ShortMessage();
a.setMessage(144,1,44,100);
MidiEvent noteOn = new MidiEvent(a,1);
track.add(noteOn);

the above 4 lines are for a "note on" (musicians can understand it, better?!) i know where to put the arguments to create music but do not know, how to compose notes and put the corresponding parameters to get some music I WANT. i need to be a musician for that.
INSTEAD , i thought of getting some actual "ready made arguments" (that is numbers to put as arguments) from some source (and definitely not a actual sheet music of 4-lines-pages, that an actual musician will use) and put it as my arguments and play it so that my program can replay atleast some MUSIC rather than playing some junk notes, i put!
this is where, exactly i need your help friends! please suggest some sites which can help me create a MUSIC using java.
yours sincerely

R.Parthiban
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Here is a table of MIDI note values...

http://www.harmony-central.com/MIDI/Doc/table2.html

from http://www.harmony-central.com/MIDI/

So the "44" you are using in your example represents a G# in the second octave.

This is very interesting. I've never worked directly with MIDI. I see that your ShortMessage constructor is taking 4 arguments:
  • Command (NOTE_ON or NOTE_OFF)
  • Channel (1)
  • Data1 (note value)
  • Data2 (100 or 25)
  • But I can't figure out the last argument. What does the 100 or 25 represent?
    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    Hmmm... So using note values from the table I linked to above, here is a C major scale (beginning on middle C)...
    Stan James
    (instanceof Sidekick)
    Ranch Hand

    Joined: Jan 29, 2003
    Posts: 8791
    Here's some info on the note on message: http://tonalsoft.com/pub/pitch-bend/pitch.2005-08-31.17-00.aspx. The last parameter is "velocity" originating with how hard a key was hit on a synthesizer keyboard.

    It might be fun to build a program that reads a text file and plays notes. I did this back in MS-DOS when I had a BEEP program that took pitch and duration arguments, say in beats.

    Early versions of the Cakewalk sequencer program workedin character mode like a spreadsheet. The new versions still have this view. Note timestamps are measure:beat:fraction. You'd wind up with a spreadsheet like:

    This is far more flexible than the first format. You can play harmony and multiple channels. But it's lots more work to put together, too.
     
    wood burning stoves
     
    subject: sugar needed for Java! help me, please.
     
    Similar Threads
    Fable translated from sheet music to midi
    Java Midi Synthesizer API
    GUI Inner Frame
    SCJP 1.6
    problem in MIDI music file