Archive for September, 2007

1304 Java Media Framework and Java (Geocities web hosting) Sound (on

Sunday, September 30th, 2007

1304 Java Media Framework and Java Sound (on CD) Chapter 22 209 210 configurePanel.add( volumeSlider ); 211 212 JLabel tempLabel = new JLabel( “tempo” ); 213 configurePanel.add( tempLabel ); 214 215 resolutionSlider = new JSlider( 216 SwingConstants.HORIZONTAL, 1, 10, 1 ); 217 218 // register a ChangeListener slider for change events 219 resolutionSlider.addChangeListener( 220 221 // anonymous inner class to handle tempo slider events 222 new ChangeListener() { 223 224 // change resolution if value changed 225 public void stateChanged( ChangeEvent changeEvent ) 226 { 227 resolution = resolutionSlider.getValue(); 228 } 229 230 } // end ChangeListener 231 232 ); // end call to method addChangeListener 233 234 resolutionSlider.setEnabled( false ); 235 configurePanel.add( resolutionSlider ); 236 237 } // end method makeConfigureControls 238 239 // set up play and save buttons 240 private void makePlaySaveButtons() 241 { 242 playButton = new JButton( “Playback” ); 243 244 // register an ActionListener for playButton events 245 playButton.addActionListener( 246 247 // anonymous inner class to handle playButton event 248 new ActionListener() { 249 250 // playback last recorded MIDI 251 public void actionPerformed( ActionEvent event ) 252 { 253 if ( midiRecord != null ) 254 midiRecord.play(); 255 } 256 257 } // end ActionListener 258 259 ); // end call to method addActionListener 260 Fig. 22.10 MidiDemoprovides the GUI than enables users to interact with the application (part 5 of 14).
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

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

Sunday, September 30th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1303 157 // set up configuration controls 158 private void makeConfigureControls() 159 { 160 JPanel configurePanel = 161 new JPanel( new GridLayout( 5, 1 ) ); 162 163 controlPanel.add( configurePanel, BorderLayout.WEST ); 164 165 instrumentBox = new JComboBox( 166 midiSynthesizer.getInstruments() ); 167 168 configurePanel.add( instrumentBox ); 169 170 // register an ActionListener for instrumentBox events 171 instrumentBox.addActionListener( 172 173 // anonymous inner class to handle instrument selector 174 new ActionListener() { 175 176 // change current instrument program 177 public void actionPerformed( ActionEvent event ) 178 { 179 // change instrument in synthesizer 180 midiSynthesizer.changeInstrument( 181 instrumentBox.getSelectedIndex() ); 182 } 183 184 } // end ActionListener 185 186 ); // end call to method addActionListener 187 188 JLabel volumeLabel = new JLabel( “volume” ); 189 configurePanel.add( volumeLabel ); 190 191 volumeSlider = new JSlider( 192 SwingConstants.HORIZONTAL, 5, 80, 30 ); 193 194 // register a ChangeListener for slider change events 195 volumeSlider.addChangeListener( 196 197 // anonymous inner class to handle volume slider events 198 new ChangeListener() { 199 200 // change volume 201 public void stateChanged( ChangeEvent changeEvent ) 202 { 203 midiVolume = volumeSlider.getValue(); 204 } 205 206 } // end class ChangeListener 207 208 ); // end call to method addChangeListener Fig. 22.10 MidiDemoprovides the GUI than enables users to interact with the application (part 4 of 14).
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

1302 Java Media (Affordable web design) Framework and Java Sound (on

Saturday, September 29th, 2007

1302 Java Media Framework and Java Sound (on CD) Chapter 22 105 // set correct spacing for buttons 106 noteButton[ i ].setBounds( ( i * 11 ), 1, 11, 40 ); 107 keyPanel.add( noteButton[ i ] ); 108 109 // register a mouse listener for mouse events 110 noteButton[ i ].addMouseListener( 111 112 // anonymous inner class to handle mouse events 113 new MouseAdapter() { 114 115 // invoke key note when mouse touches key 116 public void mouseEntered( MouseEvent mouseEvent ) 117 { 118 // if recording, send message to receiver 119 if ( recording ) 120 midiSynthesizer.sendMessage( 121 ShortMessage.NOTE_ON, 122 note + FIRST_NOTE, midiVolume ); 123 124 // else just sound the note 125 else 126 midiSynthesizer.midiNoteOn( 127 note + FIRST_NOTE, midiVolume ); 128 129 // turn key color to blue 130 noteButton[ note ].setBackground( 131 Color.blue ); 132 } 133 134 // turn key note off when mouse leaves key 135 public void mouseExited( MouseEvent mouseEvent ) 136 { 137 if ( recording ) 138 midiSynthesizer.sendMessage( 139 ShortMessage.NOTE_OFF, 140 note + FIRST_NOTE, midiVolume ); 141 else 142 midiSynthesizer.midiNoteOff( 143 note + FIRST_NOTE ); 144 145 noteButton[ note ].setBackground( 146 Color.white ); 147 } 148 149 } // end MouseAdapter 150 151 ); // end call to addMouseListener 152 153 } // end for loop 154 155 } // end method makeKeys 156 Fig. 22.10 MidiDemoprovides the GUI than enables users to interact with the application (part 3 of 14).
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Web server info - Chapter 22 Java Media Framework and Java Sound

Saturday, September 29th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1301 53 54 // constructor for MidiDemo 55 public MidiDemo() 56 { 57 super( “MIDI Demo” ); 58 59 container = getContentPane(); 60 container.setLayout( new BorderLayout() ); 61 62 // synthesizer must be instantiated to enable synthesis 63 midiSynthesizer = new MidiSynthesizer(); 64 65 // make piano keys 66 makeKeys(); 67 68 // add control panel to frame 69 controlPanel = new JPanel( new BorderLayout() ); 70 container.add( controlPanel, BorderLayout.NORTH ); 71 72 makeConfigureControls(); 73 74 // add button panel to frame 75 buttonPanel = new JPanel( new GridLayout( 5, 1 ) ); 76 controlPanel.add( buttonPanel, BorderLayout.EAST ); 77 78 // make GUI 79 makePlaySaveButtons(); 80 makeRecordButton(); 81 makePianoPlayerButton(); 82 83 } // end constructor 84 85 // utility method making piano keys 86 private void makeKeys() 87 { 88 // panel containing keys 89 JPanel keyPanel = new JPanel( null ); 90 container.add( keyPanel, BorderLayout.CENTER ); 91 92 // piano keys 93 noteButton = new JButton[ MAX_KEYS ]; 94 95 // add MAX_KEYS buttons and what note they sound 96 for ( int i = 0; i < MAX_KEYS; i++ ) { 97 98 final int note = i; 99 100 noteButton[ i ] = new JButton(); 101 102 // setting white keys 103 noteButton[ i ].setBackground( Color.white ); 104 Fig. 22.10 MidiDemoprovides the GUI than enables users to interact with the application (part 2 of 14).
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

1300 Java Media Framework and Java Sound (on (Web site counters)

Friday, September 28th, 2007

1300 Java Media Framework and Java Sound (on CD) Chapter 22 // Fig. 22.10: MidiDemo.java // Simulates a musical keyboard with various // instruments to play, also featuring recording, MIDI file // playback and simulating MIDI playback with the keyboard // Java core packages import java.awt.*; import java.awt.event.*; import java.io.*; // Java extension packages import javax.swing.*; import javax.swing.event.*; import javax.sound.midi.*; public class MidiDemo extends JFrame { // recording MIDI data private MidiRecord midiRecord; // synthesize MIDI functioning private MidiSynthesizer midiSynthesizer; // MIDI data in MIDI file private MidiData midiData; // timer for simulating MIDI on piano private Timer pianoTimer; // piano keys private JButton noteButton[]; // volume, tempo sliders private JSlider volumeSlider, resolutionSlider; // containers and panels holding GUI private Container container; private JPanel controlPanel, buttonPanel; // instrument selector and buttons GUI private JComboBox instrumentBox; private JButton playButton, recordButton, saveButton, pianoPlayerButton, listenButton; // tempo, last piano key invoked, volume of MIDI private int resolution, lastKeyOn = -1, midiVolume = 40; // boolean value indicating if program is in recording mode private boolean recording = false; // first note number of first piano key, max number of keys private static int FIRST_NOTE = 32, MAX_KEYS = 64; Fig. 22.10 MidiDemoprovides the GUI than enables users to interact with the application (part 1 of 14).
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

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

Friday, September 28th, 2007

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.

Web hosting isp - 1298 Java Media Framework and Java Sound (on

Thursday, September 27th, 2007

1298 Java Media Framework and Java Sound (on CD) Chapter 22 110 // send a MIDI ShortMessage using this method’s parameters 111 try { 112 message = new ShortMessage(); 113 114 // set new message of command (NOTE_ON, NOTE_OFF), 115 // note number, volume 116 message.setMessage( command, note, volume ); 117 118 // send message through receiver 119 receiver.send( message, -1 ); 120 } 121 122 // invalid message values set 123 catch ( InvalidMidiDataException badMidiException ) { 124 badMidiException.printStackTrace(); 125 } 126 127 } // end method sendMessage 128 129 } // end class MidiSynthesizer Fig. 22.9 MidiSynthesizercan generate notes and send them to another MIDI device (part 4 of 4). MidiSynthesizer s constructor (lines 29 72) acquires the synthesizer and initializes related resources. Line 34 obtains a Synthesizer object from the MidiSystem and line 38 opens the Synthesizer. To enable sounds to be played and recorded at the same time, lines 41 47 obtain the Transmitterand Receiverof the Synthesizer. When a MIDI message is sent to the synthesizer s receiver, the synthesizer executes the message s instruction, generating notes, and the transmitter sends that message to designated Receivers of other MidiDevices. Common Programming Error 22.3 A MidiUnavailableExceptionoccurs when a program attempts to acquire unavailable MidiDeviceresources such as synthesizers and transmitters. MIDI messages are sent to the MidiSynthesizer from MidiDemo as a result of either pressing a piano key or a MidiEventin the preloaded track of MidiData. A note can be generated by accessing the channels of the synthesizer directly. For simplicity, MidiSynthesizer uses only the first channel (out of a possible 16) to sound notes. Line 57 invokes Synthesizermethod getChannelsto obtain all 16 channels from synthesizer, and line 60 sets the default channel to the first channel. A MidiChannel sounds a note by calling its noteOn method with the note number (0 127) and a volume number as arguments. MidiChannel s noteOffmethod turns off a note with just the note number as an argument. MidiSynthesizer accesses these Midi- Channel methods through method midiNoteOn (lines 87 90) and method midiNoteOff(lines 93 96), respectively. A synthesizer can use its default instruments to sound notes. Line 54 obtains the default instrument available through the synthesizer or through a default sound bank by invoking Synthesizermethod getAvailableInstruments. A sound bank usually has 128 instruments. The instrument in use can be changed by invoking MidiSynthesizer
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Web design templates - Chapter 22 Java Media Framework and Java Sound

Thursday, September 27th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1297 59 // assign first channel as default channel 60 channel = channels[ 0 ]; 61 } 62 63 else 64 System.err.println( “No Synthesizer” ); 65 } 66 67 // synthesizer, receiver or transmitter unavailable 68 catch ( MidiUnavailableException noMidiException ) { 69 noMidiException.printStackTrace(); 70 } 71 72 } // end constructor 73 74 // return available instruments 75 public Instrument[] getInstruments() 76 { 77 return instruments; 78 } 79 80 // return synthesizer’s transmitter 81 public Transmitter getTransmitter() 82 { 83 return transmitter; 84 } 85 86 // sound note on through channel 87 public void midiNoteOn( int note, int volume ) 88 { 89 channel.noteOn( note, volume ); 90 } 91 92 // sound note off through channel 93 public void midiNoteOff( int note ) 94 { 95 channel.noteOff( note ); 96 } 97 98 // change to selected instrument 99 public void changeInstrument( int index ) 100 { 101 Patch patch = instruments[ index ].getPatch(); 102 103 channel.programChange( patch.getBank(), 104 patch.getProgram() ); 105 } 106 107 // send custom MIDI messages through transmitter 108 public void sendMessage( int command, int note, int volume ) 109 { Fig. 22.9 MidiSynthesizercan generate notes and send them to another MIDI device (part 3 of 4).
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

1296 Java Media Framework and Java Sound (on (Web hosting ratings)

Wednesday, September 26th, 2007

1296 Java Media Framework and Java Sound (on CD) Chapter 22 7 public class MidiSynthesizer { 8 9 // main synthesizer accesses resources 10 private Synthesizer synthesizer; 11 12 // available instruments for synthesis use 13 private Instrument instruments[]; 14 15 // channels through which notes sound 16 private MidiChannel channels[]; 17 private MidiChannel channel; // current channel 18 19 // transmitter for transmitting messages 20 private Transmitter transmitter; 21 22 // receiver end of messages 23 private Receiver receiver; 24 25 // short message containing sound commands, note, volume 26 private ShortMessage message; 27 28 // constructor for MidiSynthesizer 29 public MidiSynthesizer() 30 { 31 // open synthesizer, set receiver, 32 // obtain channels and instruments 33 try { 34 synthesizer = MidiSystem.getSynthesizer(); 35 36 if ( synthesizer != null ) { 37 38 synthesizer.open(); 39 40 // get transmitter of synthesizer 41 transmitter = synthesizer.getTransmitter(); 42 43 if ( transmitter == null ) 44 System.err.println( “Transmitter unavailable” ); 45 46 // get receiver of synthesizer 47 receiver = synthesizer.getReceiver(); 48 49 if ( receiver == null ) 50 System.out.println( “Receiver unavailable” ); 51 52 // get all available instruments in default 53 // soundbank or synthesizer 54 instruments = synthesizer.getAvailableInstruments(); 55 56 // get all 16 channels from synthesizer 57 channels = synthesizer.getChannels(); 58 Fig. 22.9 MidiSynthesizercan generate notes and send them to another MIDI device (part 2 of 4).
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

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

Wednesday, September 26th, 2007

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.