-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiniMusicPlayer1.java
More file actions
36 lines (31 loc) · 948 Bytes
/
Copy pathMiniMusicPlayer1.java
File metadata and controls
36 lines (31 loc) · 948 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
import javax.sound.midi.*;
public class MiniMusicPlayer1{
public static void main(String[] args){
try{
//Create the Sequencer and Open it
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
//Create a Object of Sequencer and track
Sequence seq = new Sequence(Sequence.PPQ,4);
Track track = seq.createTrack();
//Create a queue of note
for(int i = 5; i < 61; i += 4){
track.add(makeEvent(144,1,i,100,i));
track.add(makeEvent(128,1,i,100,i + 2));
}
//Play the queue of note
sequencer.setSequence(seq);
sequencer.setTempoInBPM(220);
sequencer.start();
}catch (Exception ex){ex.printStackTrace();}
}
public static MidiEvent makeEvent(int comd, int chan, int one, int two, int tick){
MidiEvent event = null;
try{
ShortMessage a = new ShortMessage();
a.setMessage(comd,chan,one,two);
event = new MidiEvent(a, tick);
}catch (Exception e){}
return event;
}
}