• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

sugar needed for Java! help me, please.

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a good place to start looking for code examples...

http://www.softsynth.com/links/java_music.html
 
parthiban rajendran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Posts: 11343
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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)
    Posts: 8791
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic