-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiniMiniMusicApp.java
More file actions
45 lines (33 loc) · 972 Bytes
/
MiniMiniMusicApp.java
File metadata and controls
45 lines (33 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package BeatBox;
import javax.sound.midi.*;
public class MiniMiniMusicApp {
public static void main(String[] args) {
MiniMiniMusicApp mini = new MiniMiniMusicApp();
mini.play();
}
public void play() {
try{
Sequencer player = MidiSystem.getSequencer();
player.open();
Sequence seq = new Sequence(Sequence.PPQ, 4);
Track track = seq.createTrack();
ShortMessage first = new ShortMessage();
first.setMessage(192,1,102,0);
MidiEvent note = new MidiEvent(first, 1);
track.add(note);
ShortMessage a = new ShortMessage();
a.setMessage(144,1,44,100);
MidiEvent noteon = new MidiEvent(a, 1);
track.add(noteon);
ShortMessage b = new ShortMessage();
b.setMessage(128,1,44,100);
MidiEvent noteoff = new MidiEvent(b, 16);
track.add(noteoff);
player.setSequence(seq);
player.start();
}
catch(Exception ex){
ex.printStackTrace();
}
}
}