/** * bentPlayer.java * * Implementation of abstract player class. * Plays bent pitches * * This module is part of Karl Brown's MIDI programming project. * */ package MidiApps; import java.io.*; import java.util.*; import javax.sound.midi.*; /** * * @author Karl Brown * @version 1.0 * last updated 2/16/2003 */ public class bentPlayer extends player { static byte PITCH_BEND_MSG =(byte) 0xE0; static short MIN_PITCH_BEND = (short)0xE000; static short MAX_PITCH_BEND = (short)0x1FFF; static short HALF_STEP_PITCH_BEND= (short) 0x1000; static short NO_PITCH_BEND = (short)0x0000; static short PITCH_BEND_CENTER = ( ( short)( (0x40)*(0x80) ) ); bentPitch bentPitches[] = new bentPitch[16]; public void resetBentPitches() { for (int i = 0; i < MAXNOTES; i++) { bentPitches[i] = null; } pitchCount = 0; } public void setBentPitch(bentPitch bp) { bentPitches[0] = bp; pitchCount = 1; } public void addBentPitch(bentPitch bp) { bentPitches[pitchCount] = bp; pitchCount++; } /** * * Implemented class method to play one or more notes * by generating pitch bend, note on and note off events. * */ public void play() { try { long tickOn = tickCount; incTickCount(getDuration()); long tickOff = tickCount; ShortMessage mm; MidiEvent me; for (int i = 0; i < pitchCount; i ++) { // pitch bend; mm = new ShortMessage(); mm.setMessage((byte)((byte)PITCH_BEND_MSG + (byte)channel[0]), (byte)bentPitches[i].getStatusLSB(), (byte)bentPitches[i].getStatusMSB()); me = new MidiEvent(mm,(long)tickOn); t.add(me); // tr.trace("pitch: " + bentPitches[0].getMidiPitch() // + " status LSB: " + bentPitches[0].getStatusLSB() // + " status MSB: " + bentPitches[0].getStatusMSB()); // note on; mm = new ShortMessage(); mm.setMessage((byte)(0x90 + (byte)channel[0]), (byte)bentPitches[i].getMidiPitch(),(byte)velOn); me = new MidiEvent(mm,(long)tickOn+1); t.add(me); // note off; mm = new ShortMessage(); mm.setMessage((byte)(0x80 + (byte)channel[0]), (byte)bentPitches[i].getMidiPitch(),(byte)velOff); me = new MidiEvent(mm,(long)tickOff); t.add(me); } } //try catch(Exception e) { tr.trace("bentPlayer::play: Exception caught:"); tr.trace(e.toString()); } //catch } }