Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using the MidiDevice interface (Java Sound API)

 
Ravaa Bal
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ravaa Bal
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah I see, thank you for pointing that out.
 
Ravaa Bal
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That does make sense, I'll give that a try. Cheers!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic