Chapter 22 Java Media Framework (Web site optimization) and Java Sound

Chapter 22 Java Media Framework and Java Sound (on CD) 1299 method changeInstrument (lines 99 105). Lines 103 104 invoke MidiChannel s programChangemethod to load the desired instrument program with the bank and program number obtained from patch (line 104) as the parameters. A Patch is the location of a loaded instrument. Performance Tip 22.5 A program can import more instruments by loading a customized sound bank through Synthesizer method loadAllInstruments with a SoundBank object. By sending MidiMessages to a Synthesizer s Receiver, a program can invoke the synthesizer to sound notes without using its channels. Sending MidiMessages to a MidiDevice s Receiveralso allows the device s Transmitters to send these messages to another MidiDevice s Receiver. In MidiSynthesizer s sendMessage method (lines 108 127), lines 112 116 create a new ShortMessage from the parameters of method sendMessage and send the message to the synthesizer s receiver (line 119). Line 116 of method sendMessage invokes ShortMessage method setMessage to set the contents of the message s instructions using three intarguments: a command, the note to play and the volume of the note. Method setMessage throws an InvalidMidiDataException if the designated command and parameter values are invalid. When creating a new ShortMessage using method setMessage, the meaning of the second and third arguments vary depending on the command. Command ShortMessage.NOTE_ON designates the second parameter to be the note number and third argument to be the velocity (i.e. volume) of the note. The ShortMessage.PROGRAM_CHANGE command designates the second argument as the instrument program to use and ignores the third argument. Line 119 sends the created ShortMessage to the synthesizer s receiverby calling Receiver method sendwith the MidiMessage and a time stamp as its arguments. MidiSynthesizerdoes not deal with the complexity of MIDI synthesis timing. The receiver sends a value of -1 for the time stamp parameter to designate that the time stamp should be ignored. The sequence recorder in class MidiRecord takes care of timing issues when it receives the messages. Up to this point, we have discussed the tools needed to create our MIDI piano. In brief synopsis, class MidiDemo (Fig. 22.10) uses class MidiSynthesizer to generate sounds and to access channels and instruments. MidiDemo uses MidiData to playback MIDI files and access MIDI track information. MidiRecord provides the recording function for MidiDemo, which receives messages from MidiSynthesizer. 22.7.4 Class MidiDemo We now present class MidiDemo (Fig. 22.10), which provides the GUI for our piano as well as other GUI components to control the capabilities of this example. Using a for loop, utility method makeKeys (lines 86 155) in class MidiDemo creates 64 buttons that represent 64 different piano keys. Whenever the mouse hovers over a key, the program sounds the designated note. Method makeKeys arranges the keys at the bottom of the frame using each button s setBounds method (line 106) to designate the location and size of the buttons. The program arranges the buttons horizontally according to their index in array noteButton.
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Leave a Reply