public javax.sound.midi.Sequence createMidiSequence() {
		javax.sound.midi.Sequence s = null;
		try {
			s = new javax.sound.midi.Sequence(javax.sound.midi.Sequence.PPQ, 16);
			int channelNum = 0;
			for (Track t : tracks) {
				int tickCount = 0;
				javax.sound.midi.Track javaTrack = s.createTrack();
				javaTrack.add(new MidiEvent(sequenceTempo(), tickCount)); // set tempo
				ShortMessage setInst = new ShortMessage();
				setInst.setMessage(ShortMessage.PROGRAM_CHANGE, channelNum,
						t.getInstrument().getInstrumentNumber(), 0);
				javaTrack.add(new MidiEvent(setInst, tickCount)); // set instrument for track
				for (int i = 0; i < t.getNumElements(); i++) {
					if (t.getElement(i) instanceof Note) {
						Note currentNote = (Note) t.getElement(i);
						ShortMessage onMessage = new ShortMessage();
						onMessage.setMessage(ShortMessage.NOTE_ON, channelNum,
								currentNote.getPitch(), currentNote.getVelocity());
						javaTrack.add(new MidiEvent(onMessage, tickCount));
						tickCount += currentNote.getDuration();
						ShortMessage offMessage = new ShortMessage();
						offMessage.setMessage(ShortMessage.NOTE_OFF, channelNum,
								currentNote.getPitch(), 0);
						javaTrack.add(new MidiEvent(offMessage, tickCount));
					}
					else if (t.getElement(i) instanceof Chord) {
						Chord currentChord = (Chord) t.getElement(i);
						Note[] noteList = currentChord.getNotes();
						for (int j = 0; j < noteList.length; j++) {
							ShortMessage onMessage = new ShortMessage();
							onMessage.setMessage(ShortMessage.NOTE_ON, channelNum,
									noteList[j].getPitch(), noteList[j].getVelocity());
							javaTrack.add(new MidiEvent(onMessage, tickCount));
						}
						tickCount += currentChord.getDuration();
						for (int j = 0; j < noteList.length; j++) {
							ShortMessage offMessage = new ShortMessage();
							offMessage.setMessage(ShortMessage.NOTE_OFF, channelNum,
									noteList[j].getPitch(), 0);
							javaTrack.add(new MidiEvent(offMessage, tickCount));
						}
					}
				}
				channelNum++;
			}
		} catch (InvalidMidiDataException e) {
			System.err.println("Error: (Sequence) failure to generate Java midi sequence");
			//e.printStackTrace();
		}
		return s;
	}