• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Understanding API's -- full text

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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));
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This isn't Certification related, moving to Other Java API's. Please continue the discussion there.
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
https://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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic