import josx.platform.rcx.*; public class Song { Note[] notes; Song(String code) { char[] chars = code.toCharArray(); notes = new Note[chars.length/4]; for (int i = 0 ; i < notes.length ; i ++) { int pauseB4 = chars[4*i] - '0'; char letter = chars[4*i+1]; int length = chars[4*i+3] - '0'; int octave = chars[4*i+2] - '0'; notes[i] = new Note(letter, octave, length, pauseB4); } } void play(Keyboard kbrd, int msecs) { for (int i = 0 ; i < notes.length ; i ++) { if (notes[i] != null) notes[i].play(kbrd, msecs); } } void combineNotes() { //find notes with no pauseB4 and combine them with their neighbors for (int i = 1 ; i < notes.length ; i ++) { if (notes[i].pauseB4 == 0) { notes[i].combine(notes[i-1]); notes[i-1] = null; } } } }