You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					
					
						
							26 lines
						
					
					
						
							1.1 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							26 lines
						
					
					
						
							1.1 KiB
						
					
					
				| class MidiReceiver implements Receiver { | |
|   void close() {} | |
|    | |
|   void send( MidiMessage msg, long timeStamp ) {  | |
|     // we only care about NoteOn midi messages. | |
|     // here's how you check for that | |
|     if ( msg instanceof ShortMessage ) { | |
|       ShortMessage sm = (ShortMessage)msg; | |
|       // if you want to handle messages other than NOTE_ON, you can refer to the constants defined in  | |
|       // ShortMessage: http://docs.oracle.com/javase/6/docs/api/javax/sound/midi/ShortMessage.html | |
|       // And figure out what Data1 and Data2 will be, refer to the midi spec: http://www.midi.org/techspecs/midimessages.php | |
|       if ( sm.getCommand() == ShortMessage.NOTE_ON ) { | |
|         // note number, between 1 and 127 | |
|         int note = sm.getData1(); | |
|         // velocity, between 1 and 127 | |
|         int vel  = sm.getData2(); | |
|         // we could also use sm.getChannel() to do something different depending on the channel of the message | |
|          | |
|         // see below the draw method for the definition of this sound generating Instrument | |
|          | |
|         System.out.println(note); | |
|         out.playNote( 0, 0.1f, new Synth( note, vel ) );  | |
|       } | |
|     } | |
|   } | |
| }
 |