import java.io.*; import java.util.*; class MusicEdit { public static PrintStream out; private static ArrayList song; private static int offset=0; private static ListIterator i; static void main (String[] args) throws IOException { boolean power = true; out = new PrintStream(new FileOutputStream("/dev/tty2"), true); song = new ArrayList(); offset = 0; // ADD A FEW NOTES TO THE SONG ARRAYLIST song.add(new Note(24,256)); song.add(new Note(36,256)); song.add(new Note(26,256)); song.add(new Note(28,256)); song.add(new Note(36,256)); song.add(new Note(28,256)); song.add(new Note(26,256)); song.add(new Note(24,256)); song.add(new Note(36,256)); while (power) { if (System.in.available()>0) { switch (System.in.read()) { case 'l' : if (++offset == song.size()) { offset--; System.out.print("]"); } else { ((Note)(song.get(offset))).play(); } break; case 'h' : if (--offset < 0) { offset++; System.out.print("["); } else { ((Note)(song.get(offset))).play(); } break; case 'k' : ((Note)(song.get(offset))).higher(); ((Note)(song.get(offset))).play(); break; case 'j' : ((Note)(song.get(offset))).lower(); ((Note)(song.get(offset))).play(); break; case 'K' : ((Note)(song.get(offset))).longer(); ((Note)(song.get(offset))).play(); break; case 'J' : ((Note)(song.get(offset))).shorter(); ((Note)(song.get(offset))).play(); break; case ' ' : playSong(); break; case 'Q' : power = false; break; } } else { try { Thread.sleep(100); } catch (InterruptedException e) {} } } } // PLAY THE ENTIRE SONG IN THE ARRYLIST static void playSong () { i=song.listIterator(); while(i.hasNext()) { ((Note)i.next()).play(); } } } class Note { int note, duration; final int BASE = 20; Note (int note, int duration) { this.note = note; this.duration = duration; } public void play () { if (note > 0) { MusicEdit.out.print("\033[10;" + Math.round(BASE * Math.pow(2.0,note / 12.0)) + "]\033[11;" + duration + "]"); } try { Thread.sleep(duration); } catch (InterruptedException e) {} } public Note higher () { note++; return this;} public Note lower () { note--; return this;} public Note longer () { duration *= 2; return this;} public Note shorter () { duration /= 2; return this;} }