• 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

a reference from a method?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone explain what exactly is going on in this statement?

Sequencer sequencer = MidiSystem.getSequencer();

Am I thinking correctly about this statement? You are creating a reference variable called "sequencer" to the Sequencer Interface, yet its calling a method?

I am understanding of object creation and polymorphism such as: Sequencer sequencer = new Sequencer(); or Animal a = new lizard(); But here I am a bit confused to what is going on.

 
Rancher
Posts: 5035
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

what exactly is going on in this statement?

Sequencer sequencer = MidiSystem.getSequencer();


Start by reading the API doc for the MidiSystem class.

My guess on what that statement does is:
calls the static method: getSequence() in the MidiSystem class,
that method returns a reference to a Sequencer object
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't read the API but from the line given by you

a static method getSequencer() is declared in MidiSystem class whose return type is Sequencer. So, when you call getSequencer() method, it returns Sequencer class's object. Thus, you have to hold that object in a reference. That's why you are taking "Sequencer sequencer" to hold the returned Sequencer object in a reference variable called "sequencer"
 
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, cameron. Here's what the Javadoc says:

public static Sequencer getSequencer() throws MidiUnavailableException

Obtains the default Sequencer, connected to a default device. The returned Sequencer instance is connected to the default Synthesizer, as returned by getSynthesizer(). If there is no Synthesizer available, or the default Synthesizer cannot be opened, the sequencer is connected to the default Receiver, as returned by getReceiver(). The connection is made by retrieving a Transmitter instance from the Sequencer and setting its Receiver. Closing and re-opening the sequencer will restore the connection to the default device.

This method is equivalent to calling getSequencer(true).

If the system property javax.sound.midi.Sequencer is defined or it is defined in the file "sound.properties", it is used to identify the default sequencer. For details, refer to the class description.

Returns:
the default sequencer, connected to a default Receiver


Does that make sense to you, or do you need some help in understanding it?
 
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
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