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 Using the MidiDevice interface (Java Sound API) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using the MidiDevice interface (Java Sound API)" Watch "Using the MidiDevice interface (Java Sound API)" New topic
Author

Using the MidiDevice interface (Java Sound API)

Ravaa Bal
Ranch Hand

Joined: Apr 15, 2009
Posts: 31
Hi all, I'm trying to understand interfaces in Java so hope someone can help.

I have a class which is implementing the MidiDevice interface (http://java.sun.com/j2se/1.5.0/docs/api/javax/sound/midi/MidiDevice.html).

There is a method in there that I need to declare called isOpen(). The thing is I'm not sure how I would check if the device 'is open'. These are the lines I'm thinking along:



Is this correct? If not, what kind of thing would I need to do for this method?

Thank you.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

If you check the API, there is a link at the top called "Use". If you follow this link you get an overview of all classes, methods and fields that use that specific class or interface.

After having a quick look, you can choose one of the following:
- MidiSystem.getSequencer(), since Sequencer is a sub interface of MidiDevice
- MidiSystem.getSynthesizer(), since Synthesizer is a sub interface of MidiDevice
- a combination of MidiSystem.getMidiDeviceInfo() to retrieve an array of MidiDevice.Info, then MidiSystem.getMidiDevice(MidiDevice.Info) using one of the array values

You'll have to investigate yourself which of these is best.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ravaa Bal
Ranch Hand

Joined: Apr 15, 2009
Posts: 31
Ah I see, thank you for pointing that out.
Ravaa Bal
Ranch Hand

Joined: Apr 15, 2009
Posts: 31
I was gonna post another topic for this but hopefully someone will see this instead...

If I needed to use the method getTickPosition() from Sequencer (http://java.sun.com/j2se/1.4.2/docs/api/javax/sound/midi/Sequencer.html), I assume I'll need to have my class implement the Sequencer interface?

If so, is there any way around having to declare each and every method for this Sequencer interface? Apparently I also have to declare methods from the MidiDevice interface too since it extends it...there must be a better way.

Or maybe I'm kidding myself haha!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

Can't you just call getTickPosition() on the result of MidiSystem.getSequencer()?

Although this method appears to return an instance of an interface, it actually returns an instance of an unknown class that implements Sequencer.
Ravaa Bal
Ranch Hand

Joined: Apr 15, 2009
Posts: 31
That does make sense, I'll give that a try. Cheers!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Using the MidiDevice interface (Java Sound API)
 
Similar Threads
Java Sound API Problems
Using the MidiDevice interface (Java Sound API)
Multiple Midi Channels Problem
Static methods and nullpointerexceptions
I didn't think you could instantiate an Interface