• 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

Using the MidiDevice interface (Java Sound API)

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That does make sense, I'll give that a try. Cheers!
 
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