Chapter 22 Java Media (Cpanel web hosting) Framework and Java Sound

Chapter 22 Java Media Framework and Java Sound (on CD) 1295 Method initialize(lines 35 77) of class MidiRecordsets up the sequencer for recording. Line 41 of method initialize instantiates an empty sequence. Midi- Record will record data to the empty sequence once the transmitter is connected to the receiver. Line 48 obtains the recording sequencer s receiver and line 57 specifies that transmitterwill send its messages to receiver. MIDI messages must be placed in a track, so method initializeinvokes method makeTrack (lines 80 88) to delete the previous existing track (line 84) and to create an empty Track(line 87). Method makeTrackcan also be called from an external class to record a new sequence without instantiating new sequencers and a new sequence. After setting up a sequencer and an empty sequence, calling MidiRecord method startRecord (lines 97 115) starts the recording process. Line 101 loads an empty sequence into the sequencer. Sequencermethod recordEnableis called and passed the trackobject and a channel number as arguments (line 104), which enables recording on that track. Line 106 invokes Sequencer s startRecordingmethod to start the recording of MIDI events sent from the transmitter. Sequencer s stopRecording method stops recording and is called in MidiRecord s stopRecordmethod (lines 118 121). Class MidiRecordcan also supports save a recorded sequence to a MIDI file using its saveSequencemethod (lines 124 144). Although most MIDI sequences can support MIDI type 0 files (the most common type of MIDI file), the sequence should be checked for other supported file types. Line 127 obtains an array of MIDI file types supported by the system for writing a sequence to a file. The MIDI file types are represented by integer values of 0, 1 or 2. Using the first supported file type, the MidiSystem writes the sequence to a specified File(line 136) passed into method saveSequenceas an argument. MidiRecord s play method (lines 91 94) enables the program to play back the newly recorded sequence. 22.7.3 MIDI Synthesis This MidiDemo program provides an interactive piano that generates notes according to the keys pressed by the user. Class MidiSynthesizer(Fig. 22.9) generates these notes directly, and sends them to another device. Specifically, it sends the notes to a sequencer s receiver through a transmitter to record the MIDI sequence. Class MidiSynthesizer uses an object that implements interface Synthesizer (a sub-interface of MidiDevice) to access the default synthesizer s sound generation, instruments, channel resources and sound banks. A SoundBank is the container for various Instruments, which instructs the computer on how to make the sound of a specific note. Different notes made by various instruments are played through a MidiChannel on different tracks simultaneously to produce symphonic melodies. 1 // Fig. 22.9: MidiSynthesizer.java 2 // Accessing synthesizer resources 3 4 // Java extension package 5 import javax.sound.midi.*; 6 Fig. 22.9 MidiSynthesizercan generate notes and send them to another MIDI device (part 1 of 4).
We recommend high quality webhost to host and run your jsp application: christian web host services.

Leave a Reply