1 package sample;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
6
7 import fi.jyu.mit.Music.*;
8
9
10
14 public class PlaySample {
15 public static void main(String[] args) {
16 ukkoNoaSample();
22
23 }
24
25 public static void ukkoNoaSample() {
26 BufferedMidiPlayer2 mp = new BufferedMidiPlayer2();
27 mp.setTempo(150);
28 mp.play("CCCEDDDFEEDDC*");
29 mp.play("EEEEG*F*DDDDF*E*");
30 mp.play("CCCEDDDFEEDDC*");
31 mp.run();
32 }
33
34 public static void midiFileSample() {
35 MidiPlayer ss = new MidiPlayer();
36 ss.setVerbose(true);
37 ss.playMidiFile("ukkonooa.mid");
39 }
40
41 public static void outl(String msg) {
42 System.out.println(msg);
43 }
44
45 public static void out(String msg) {
46 System.out.print(msg + " ");
47 }
48
49 public static void concurrentSample() {
50 ThreadedMidiPlayer css = new ThreadedMidiPlayer();
51 css.setVerbose(true);
52 css.begin();
53 css.play("CEG-EBbC-AC#E", 0.25, 5);
54 css.play("-EBbC-");
55 try {
56 Thread.sleep(2500);
57 } catch (InterruptedException e) {
58 e.printStackTrace();
59 }
60 css.end();
61 }
62
63 public static void keyboardSample() {
65 MidiPlayer ss = new MidiPlayer(true);
66 ss.setVerbose(true);
67 ss.setInstrument(1);
68 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
69 String line = "";
70 try {
71 while ((line = br.readLine()) != null) {
72 ss.play(line);
73 }
74 } catch (IOException e) {
75 e.printStackTrace();
77 }
78 }
79
80 public static void ascFileSample() {
81 MidiPlayer ss = new MidiPlayer();
82 ss.setVerbose(true);
83 ss.setInstrument(1);
84 ss.playAsciiFile("testSong.asc");
85 }
97
98 public static void asyncSample() {
99 BufferedMidiPlayer ss = new BufferedMidiPlayer();
100
101 ss.setVerbose(true);
102 ss.setInstrument(1);
103 ss.play("BbADEFG");
104 ss.playSingleNote("C", 1, 5);
105 ss.play("C#C", 5);
106 ss.play("GBb");
107 ss.play("C", 5);
108 ss.play("E", 5);
109 ss.playSingleNote("G");
110 ss.playSingleNote("Bb", 1.0);
111 ss.play("Bb");
112 ss.play("CC#CC#C", 5);
113 ss.play("BG");
114 ss.playSingleNote("Bb", 1.0);
115 ss.play("Bb");
116 ss.play("C", 5);
117 ss.play("BBbAG#GF#");
118 ss.playSingleNote("F", 1.0);
119 ss.runAsync();
120 System.out.println("Asynkronista soittoa! Odotetaan kymmenen sekuntia...");
121 try {
122 Thread.sleep(10000);
123 ss.stop();
124 } catch (InterruptedException e) {
125 e.printStackTrace();
126 }
127 }
128 }
129