Archive for September, 2007

1294 Java Media Framework (Web design portfolio) and Java Sound (on

Tuesday, September 25th, 2007

1294 Java Media Framework and Java Sound (on CD) Chapter 22 102 103 // set track to recording-enabled and default channel 104 sequencer.recordEnable( track, 0 ); 105 106 sequencer.startRecording(); 107 } 108 109 // sequence contains bad MIDI data 110 catch ( InvalidMidiDataException badMidiException ) { 111 badMidiException.printStackTrace(); 112 113 } 114 115 } // end method startRecord 116 117 // stop MIDI recording 118 public void stopRecord() 119 { 120 sequencer.stopRecording(); 121 } 122 123 // save MIDI sequence to file 124 public void saveSequence( File file ) 125 { 126 // get all MIDI supported file types 127 int[] fileTypes = MidiSystem.getMidiFileTypes( sequence ); 128 129 if ( fileTypes.length == 0 ) { 130 System.err.println( “No supported MIDI file format!” ); 131 return; 132 } 133 134 // write recorded sequence into MIDI file 135 try { 136 MidiSystem.write( sequence, fileTypes[ 0 ], file ); 137 } 138 139 // error writing to file 140 catch ( IOException ioException ) { 141 ioException.printStackTrace(); 142 } 143 144 } // end method saveSequence 145 146 } // end class MidiRecord Fig. 22.8 MidiRecordenables a program to record a MIDI sequence (part 3 of 3). The first step of recording MIDI data is similar to the playback mechanism in class MidiData. In addition to obtaining an empty sequence and a sequencer, a MIDI recording program needs to connect the transmitters and receivers. After successfully wiring the sequencer s receiver as the IN PORT, the recorder loads the empty sequence into the sequencer to start recording to a new track in the sequence. The following discussion covers these steps.
We recommend high quality webhost to host and run your jsp application: christian web host services.

Web hosting e commerce - Chapter 22 Java Media Framework and Java Sound

Tuesday, September 25th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1293 49 50 if ( receiver == null ) { 51 System.err.println( 52 “Receiver unavailable for sequencer” ); 53 return false; 54 } 55 56 // set receiver for transmitter to send MidiMessages 57 transmitter.setReceiver( receiver ); 58 59 makeTrack(); 60 } 61 62 // invalid timing division specification for new sequence 63 catch ( InvalidMidiDataException invalidMidiException ) { 64 invalidMidiException.printStackTrace(); 65 return false; 66 } 67 68 // sequencer or receiver unavailable 69 catch ( MidiUnavailableException noMidiException ) { 70 noMidiException.printStackTrace(); 71 return false; 72 } 73 74 // MIDI recorder initialization successful 75 return true; 76 77 } // end method initialize 78 79 // make new empty track for sequence 80 public void makeTrack() 81 { 82 // if previous track exists, delete it first 83 if ( track != null ) 84 sequence.deleteTrack( track ); 85 86 // create track in sequence 87 track = sequence.createTrack(); 88 } 89 90 // start playback of loaded sequence 91 public void play() 92 { 93 sequencer.start(); 94 } 95 96 // start recording into sequence 97 public void startRecord() 98 { 99 // load sequence into recorder and start recording 100 try { 101 sequencer.setSequence( sequence ); Fig. 22.8 MidiRecordenables a program to record a MIDI sequence (part 2 of 3).
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Chapter 22 Java Media Framework and Java Sound (Florida web design)

Tuesday, September 18th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1289 116 // set current MIDI event to first event in track 117 currentEvent = track.get( eventIndex ); 118 119 // get MIDI message from event 120 message = currentEvent.getMessage(); 121 122 // track initialization successful 123 return true; 124 125 } // end method initializeTrack 126 127 // move to next event in track 128 public void goNextEvent() 129 { 130 eventIndex++; 131 currentEvent = track.get( eventIndex ); 132 message = currentEvent.getMessage(); 133 } 134 135 // get time interval between events 136 public int getEventDelay() 137 { 138 // first event’s time interval is its duration 139 if ( eventIndex == 0 ) 140 return ( int ) currentEvent.getTick(); 141 142 // time difference between current and next event 143 return ( int ) ( track.get( eventIndex + 1 ).getTick() 144 currentEvent.getTick() ); 145 } 146 147 // return if track has ended 148 public boolean isTrackEnd() 149 { 150 // if eventIndex is less than track’s number of events 151 if ( eventIndex + 1 < track.size() ) 152 return false; 153 154 return true; 155 } 156 157 // get current ShortMessage command from event 158 public int getEventCommand() 159 { 160 if ( message instanceof ShortMessage ) { 161 162 // obtain MidiMessage for accessing purposes 163 noteMessage = ( ShortMessage ) message; 164 return noteMessage.getCommand(); 165 } 166 167 return -1; 168 } Fig. 22.7 MidiDataloads MIDI files for playback (part 4 of 5).
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Professional web hosting - 1288 Java Media Framework and Java Sound (on

Tuesday, September 18th, 2007

1288 Java Media Framework and Java Sound (on CD) Chapter 22 64 } // end method play 65 66 // method returning adjusted tempo/resolution of MIDI 67 public int getResolution() 68 { 69 return 500 / sequence.getResolution(); 70 } 71 72 // obtain MIDI and prepare track in MIDI to be accessed 73 public boolean initialize( File file ) 74 { 75 // get valid MIDI from file into sequence 76 try { 77 sequence = MidiSystem.getSequence( file ); 78 } 79 80 // unreadable MIDI file or unsupported MIDI 81 catch ( InvalidMidiDataException badMIDI ) { 82 badMIDI.printStackTrace(); 83 return false; 84 } 85 86 // I/O error generated during file reading 87 catch ( IOException ioException ) { 88 ioException.printStackTrace(); 89 return false; 90 } 91 92 return true; 93 94 } // end method initialize 95 96 // prepare longest track to be read and get first MIDI event 97 public boolean initializeTrack() 98 { 99 // get all tracks from sequence 100 Track tracks[] = sequence.getTracks(); 101 102 if ( tracks.length == 0 ) { 103 System.err.println( “No tracks in MIDI sequence!” ); 104 105 return false; 106 } 107 108 track = tracks[ 0 ]; 109 110 // find longest track 111 for ( int i = 0; i < tracks.length; i++ ) 112 113 if ( tracks[ i ].size() > track.size() ) 114 track = tracks[ i ]; 115 Fig. 22.7 MidiDataloads MIDI files for playback (part 3 of 5).
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

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

Monday, September 17th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1287 11 public class MidiData { 12 13 // MIDI track data 14 private Track track; 15 16 // player for MIDI sequences 17 private Sequencer sequencer; 18 19 // MIDI sequence 20 private Sequence sequence; 21 22 // MIDI events containing time and MidiMessages 23 private MidiEvent currentEvent, nextEvent; 24 25 // MIDI message usually containing sounding messages 26 private ShortMessage noteMessage; 27 28 // short, meta, or sysex MIDI messages 29 private MidiMessage message; 30 31 // index of MIDI event in track, command in MIDI message 32 private int eventIndex = 0, command; 33 34 // method to play MIDI sequence via sequencer 35 public void play() 36 { 37 // initiate default sequencer 38 try { 39 40 // get sequencer from MidiSystem 41 sequencer = MidiSystem.getSequencer(); 42 43 // open sequencer resources 44 sequencer.open(); 45 46 // load MIDI into sequencer 47 sequencer.setSequence( sequence ); 48 49 // play sequence 50 sequencer.start(); 51 } 52 53 // MIDI resource availability error 54 catch ( MidiUnavailableException noMidiException ) { 55 noMidiException.printStackTrace(); 56 } 57 58 // corrupted MIDI or invalid MIDI file encountered 59 catch ( InvalidMidiDataException badMidiException ) { 60 badMidiException.printStackTrace(); 61 62 } 63 Fig. 22.7 MidiDataloads MIDI files for playback (part 2 of 5).
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Web server logs - 1286 Java Media Framework and Java Sound (on

Monday, September 17th, 2007

1286 Java Media Framework and Java Sound (on CD) Chapter 22 and transmitting them to other MIDI devices, such as recorders. Class MidiDatahandles MIDI playback, track initialization and event information. Class MidiRecord provides MIDI recording capabilities. Class MidiDemoties the other classes together with an interactive GUI that includes a simulated piano keyboard, play and record buttons, and a control panel for configuring MIDI options. Class MidiDemoalso uses MIDI event-synchronization to play a MIDI file and highlight the appropriate piano keys, simulating someone playing the keyboard. An integral part of this MIDI example is its GUI, which allows users to play musical notes on a simulated piano keyboard (see screen capture in Fig. 22.10). When the mouse hovers over a piano key, the program plays the corresponding note. In this section, we refer to this as user synthesis. The Play MIDI button in the GUI allows the user to select a MIDI file to play. The Record button records the notes played on the piano (user synthesis). Users can save the recorded MIDI to a file using the Save MIDI button and play back the recorded MIDI using the PlayBack button. Users can click the Piano Player button to open a MIDI file, then play that file back through a synthesizer. The program signifies synchronization of notes and piano keys by highlighting the key that corresponds to the note number. This playback and synchronization ability is called the piano player. While the piano player is running, users can synthesize additional notes, and record both the old audio material and the new user-synthesized notes by clicking the Record button. The JComboBox in the upper-left corner of the GUI enables users to select an instrument for synthesis. Additional GUI components include a volume control for user-synthesized notes and a tempo control for controlling the speed of the piano player. Testing and Debugging Tip 22.1 Testing the MIDI file playback functions requires a sound card and an audio file in MIDI format. 22.7.1 MIDI Playback This section discusses how to play MIDI files and how to access and interpret MIDI file contents. Class MidiData (Fig. 22.7) contains methods that load a MIDI file for playback. The class also provides the MIDI track information required by the piano player feature. A MIDI sequencer is used to play and manipulate the audio data. Often, MIDI data is referred to as a sequence, because the musical data in a MIDI file is composed of a sequence of events. The steps performed in MIDI playback are accessing a sequencer, loading a MIDI sequence or file into that sequencer and starting the sequencer. 1 // Fig. 22.7: MidiData.java 2 // Contains MIDI sequence information 3 // with accessor methods and MIDI playback methods 4 5 // Java core package 6 import java.io.*; 7 8 // Java extension package 9 import javax.sound.midi.*; 10 Fig. 22.7 MidiDataloads MIDI files for playback (part 1 of 5).
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Chapter 22 Java Media Framework and (Web design course) Java Sound

Sunday, September 16th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1285 93 } // end class ClipPlayerTest Fig. 22.6 ClipPlayerTestenables the user to specify the name and location of the audio to play with ClipPlayer(part 3 of 3). 22.7 Musical Instrument Digital Interface (MIDI) The Musical Instrument Digital Interface (MIDI) is a standard format for electronic music. MIDI music can be created through a digital instrument, such as an electronic keyboard, or through software. The MIDI interface allows musicians to create synthesized digital music that reproduces the actual music. Then they can share their musical creations with music enthusiasts around the world. A MIDI synthesizer is a device that can produce MIDI sounds and music. Programs can easily manipulate MIDI data. Like other types of audio, MIDI data has a well-defined format that MIDI players can interpret, play and use to create new MIDI data. The Complete Detailed MIDI 1.0 specification provides detailed information on MIDI files. Visit the official MIDI Web site at www.midi.org for information on MIDI and its specification. Java Sound s MIDI packages (javax.sound.midi and javax.sound.midi.spi) allow developers to access MIDI data. Interpretation of MIDI data varies between synthesizers, so a file may sound quite different when played on synthesizers other than the one on which it was created. Synthesizers support varying types and numbers of instrumental sounds and different numbers of simultaneous sounds. Usually hardware-based synthesizers are capable of producing higher- quality synthesized music than software-based synthesizers. Many Web sites and games use MIDI for music playback, as it enables developers to entertain users with lengthy, digitized music files that do not require a lot of memory. In comparison, sampled audio files can grow to be quite large. Package javax.sound.midi enables programs to manipulate, play and synthesize MIDI. Java Sound supports MIDI files with midand rmf(Rich Music Format or RMF) extensions. The example presented in Sections 22.7.1 through 22.7.4 covers MIDI synthesis, playback, recording and saving. Class MidiDemo(Fig. 22.10) is the main application class that utilizes classes MidiData (Fig. 22.7), MidiRecord (Fig. 22.8) and MidiSynthesizer(Fig. 22.9). Class MidiSynthesizerprovides resources for generating sounds
Check Tomcat Web Hosting services for best quality webspace to host your web application.

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

Sunday, September 16th, 2007

1284 Java Media Framework and Java Sound (on CD) Chapter 22 41 if ( mediaFile != null ) { 42 43 // instantiate new clip player with mediaFile 44 clipPlayer = new ClipPlayer( mediaFile ); 45 46 // if clip player opened correctly 47 if ( clipPlayer.openFile() == true ) { 48 49 // play loaded clip 50 clipPlayer.play(); 51 52 // no replay 53 clipPlayer.setReplay( false ); 54 } 55 56 } // end if mediaFile 57 58 } // end actionPerformed 59 60 } // end ActionListener 61 62 ); // end call to addActionListener 63 64 } // end constructor 65 66 // get file from computer 67 public File getFile() 68 { 69 JFileChooser fileChooser = new JFileChooser(); 70 71 fileChooser.setFileSelectionMode( 72 JFileChooser.FILES_ONLY ); 73 int result = fileChooser.showOpenDialog( this ); 74 75 if ( result == JFileChooser.CANCEL_OPTION ) 76 return null; 77 78 else 79 return fileChooser.getSelectedFile(); 80 } 81 82 // execute application 83 public static void main( String args[] ) 84 { 85 ClipPlayerTest test = new ClipPlayerTest(); 86 87 test.setSize( 150, 70 ); 88 test.setLocation( 300, 300 ); 89 test.setDefaultCloseOperation( EXIT_ON_CLOSE ); 90 test.setVisible( true ); 91 } 92 Fig. 22.6 ClipPlayerTestenables the user to specify the name and location of the audio to play with ClipPlayer(part 2 of 3).
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Free web hosting with ftp - Chapter 22 Java Media Framework and Java Sound

Sunday, September 16th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1283 a ClipPlayer for the specified audio file (line 44). Line 47 invokes ClipPlayer method openFile, which returns true if the ClipPlayer can open the audio file. If so, line 50 calls ClipPlayer method play to play the audio and line 53 calls Clip- Playermethod setReplayto indicate that the audio should not loop continuously. Performance Tip 22.4 Large audio files take a long time to load, depending on the speed of the computer. An alternative playback form is to buffer the audio by loading a portion of the data to begin playback and continuing to load the remainder as the audio plays. This is similar to the streaming capability provided by JMF. 1 // Fig. 22.6: ClipPlayerTest.java 2 // Test file for ClipPlayer 3 4 // Java core packages 5 import java.awt.*; 6 import java.awt.event.*; 7 import java.io.*; 8 9 // Java extension packages 10 import javax.swing.*; 11 12 public class ClipPlayerTest extends JFrame { 13 14 // object to play audio clips 15 private ClipPlayer clipPlayer; 16 17 // constructor for ClipPlayerTest 18 public ClipPlayerTest() 19 { 20 super( “Clip Player” ); 21 22 // panel containing buttons 23 JPanel buttonPanel = new JPanel(); 24 getContentPane().add( buttonPanel ); 25 26 // open file button 27 JButton openFile = new JButton( “Open Audio Clip” ); 28 buttonPanel.add( openFile, BorderLayout.CENTER ); 29 30 // register ActionListener for openFile events 31 openFile.addActionListener( 32 33 // inner anonymous class to handle openFile ActionEvent 34 new ActionListener() { 35 36 // try to open and play an audio clip file 37 public void actionPerformed( ActionEvent event ) 38 { 39 File mediaFile = getFile(); 40 Fig. 22.6 ClipPlayerTestenables the user to specify the name and location of the audio to play with ClipPlayer(part 1 of 3).
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Multiple domain web hosting - 1282 Java Media Framework and Java Sound (on

Saturday, September 15th, 2007

1282 Java Media Framework and Java Sound (on CD) Chapter 22 portedAudioFileException if the specified sound file is a non-audio file or if it contains a format that is not supported by Java Sound. Next the program must provide a line through which audio data can be processed. Line 52 invokes method loadClip (lines 57 106) to open a Clip line and load the audio stream for playback. Line 81 invokes AudioSystem static method getLine to obtain a Clip line for audio playback. Method getLine requires a Line.Info object as an argument, to specify the attributes of the line that the AudioSystem should return. The line must be able to process audio clips of all supported sampled audio formats, so the DataLine.Info object must specify a Clip data line and a general encoding format. A buffer range should also be specified so the program can determine the best buffer size. The DataLine.Info constructor receives four arguments. The first two are the format (of type AudioFormat.Encoding) into which the program should convert the audio data and the AudioFormat of the audio source. The AudioFormat sets the format supported by the line, according to the audio format of the stream. Line 63 obtains the Audio- Format of the AudioInputStream, which contains format specifications that the underlying system uses to translate the data into sounds. Lines 68 69 call AudioSystem method getTargetFormatsto obtain an array of the supported AudioFormats. The third argument of the DataLine.Info constructor, which specifies the minimum buffer size, is set to the number of bytes in each frame of the audio stream. Line 70 invokes AudioFormat method getFrameSize to obtain the size of each frame in the audio stream. The maximum buffer size should be equivalent to two frames of the audio stream (line 71). Using the DataLine.Info object, line 74 checks if the underlying audio system supports the specified line. If it does, line 81 obtains the line from the audio system. When an audio clip starts playing and when it finishes, the program needs to be alerted. Line 84 registers a LineListener for the Clip s LineEvents. If a LineEvent occurs, the program calls LineListener method update (lines 115 133) to process it. The four LineEvent types, as defined in class LineEvent.Type, are OPEN, CLOSE, START and STOP. When the event type is LineEvent.Type.STOP and variable replayis false, line 120 calls ClipPlayer s close method (lines 142 148) to stop audio playback and close the Clip. All audio resources obtained previously by the Clip are released when audio playback stops. When the event type is LineEvent.Type.STOP and variable replay is true, line 131 calls Clip method loop with parameter Clip.LOOP_CONTINUOUSLY, causing the Clipto loop until the user terminates the application. Invoking method stop of interface Clip stops data activity in the Line. Invoking method start resumes data activity. Once the program finishes validating the Clip, line 87 calls Clip method open with the AudioInputStreamsoundStream as an argument. The Clip obtains the system resources required for audio playback. AudioSystem method getLine and Clip method open throw LineUnavailableExceptions if another application is using the requested audio resource. Clip method open also throws an IOException if the Clip cannot read the specified AudioInputStream. When the test program (Fig. 22.6) calls ClipPlayer method play (lines 109 112), the Clip method start begins audio playback. Class ClipPlayerTest (Fig. 22.6) enables users to specify an audio file to play by clicking the Open Audio Clip button. When users click the button, method action- Performed(lines 37 58) prompts an audio file name and location (line 39) and creates
Check Tomcat Web Hosting services for best quality webspace to host your web application.