Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Understanding API's -- full text

 
John Held
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ambitious I know, but I the problem I'm having
illustrates the difference between book-learning and writing real Java programs
According to the Sequence API, I can create a
new MIDI (music) sequence, add a track to it, and
then add midi events to it.
1--in spite of the right import statement, I seem
to have to add "javax.sound.midi.MidiEvent" for
the t.add statement to find the "setTick" midi function.
2--Even though Midi2 is not static, I get the message "non-static method set.Tick(l) cannot
be referenced from a static context"
Help -- code below!

public class Midi2 {
Midi2() {
Sequence seq = null;
try {seq = new Sequence(0.0f, 500);} catch (InvalidMidiDataException e)
{System.exit(0);}
Track t = null;
t = seq.createTrack();
long l = 500;

t.add(javax.sound.midi.MidiEvent.setTick(l));
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't Certification related, moving to Other Java API's. Please continue the discussion there.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Held:

1--in spite of the right import statement, I seem
to have to add "javax.sound.midi.MidiEvent" for
the t.add statement to find the "setTick" midi function.
2--Even though Midi2 is not static, I get the message "non-static method set.Tick(l) cannot
be referenced from a static context"
...
t.add(javax.sound.midi.MidiEvent.setTick(l));

1) Not seeing the import statement, it's hard to say if it's "right" or not. What exactly are you using as the import statement that you say is not working?
2) I don't have this MIDI API installed so I can't check it, but just going by what the compiler is telling you, I don't think that setTick() in class MidiEvent is a static method, and you are referring to it as if it were. You might want to double-check this.
 
John Held
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob,
The import statement is as follows:
importjavax.sound.midi.MidiEvent;
Any ideas on the correct way to add the
event?
--John
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John, do you understand the difference between a static method and an instance method? If not, you should ask about them in the Java In General (Beginner) forum here:
http://www.coderanch.com/forums/f-33/java
To answer your question, you probably need to have an instance of a MidiEvent object. Instances are created via the instance-creation statement "new MidiEvent()", passing whatever parameters may be required, as described in the JavaDocs for your MIDI API.
[ June 28, 2002: Message edited by: Rob Ross ]
 
John Held
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I was able to create a sequence with midi events. If anyone knows of better descriptions of the values which need to go in various midi events (the API seems pretty dry for this information and the midi site reference is pretty feeble) let me know.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic