FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programming-Exercises/MiniMusicPlayer3.java at master · RoyTien/Java-Programming-Exercises · GitHub
RoyTien
/
Java-Programming-Exercises
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Programming-Exercises
/
MiniMusicPlayer3.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
87 lines (69 loc) · 1.98 KB
Breadcrumbs
Java-Programming-Exercises
/
MiniMusicPlayer3.java
Copy path
File metadata and controls
87 lines (69 loc) · 1.98 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import
javax
.
sound
.
midi
.*;
import
java
.
io
.*;
import
javax
.
swing
.*;
import
java
.
awt
.*;
public
class
MiniMusicPlayer3
{
static
JFrame
f
=
new
JFrame
(
"My First Music Video"
);
static
MyDrawPanel
ml
;
public
static
void
main
(
String
[]
args
){
MiniMusicPlayer3
mini
=
new
MiniMusicPlayer3
();
mini
.
go
();
}
public
void
setUpGui
(){
ml
=
new
MyDrawPanel
();
f
.
setContentPane
(
ml
);
f
.
setBounds
(
30
,
30
,
300
,
300
);
f
.
setVisible
(
true
);
}
public
void
go
(){
setUpGui
();
try
{
Sequencer
sequencer
=
MidiSystem
.
getSequencer
();
sequencer
.
open
();
sequencer
.
addControllerEventListener
(
ml
,
new
int
[] {
127
});
Sequence
seq
=
new
Sequence
(
Sequence
.
PPQ
,
4
);
Track
track
=
seq
.
createTrack
();
int
r
=
0
;
for
(
int
i
=
5
;
i
<
60
;
i
+=
4
){
r
= (
int
) ((
Math
.
random
() *
50
) +
1
);
track
.
add
(
makeEvent
(
144
,
1
,
r
,
100
,
i
));
track
.
add
(
makeEvent
(
1176
,
1
,
127
,
0
,
i
));
track
.
add
(
makeEvent
(
128
,
1
,
r
,
100
,
i
+
2
));
}
sequencer
.
setSequence
(
seq
);
sequencer
.
setTempoInBPM
(
120
);
sequencer
.
start
();
}
catch
(
Exception
ex
){
ex
.
printStackTrace
();}
}
public
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
;
}
class
MyDrawPanel
extends
JPanel
implements
ControllerEventListener
{
boolean
mag
=
false
;
public
void
controlChange
(
ShortMessage
event
){
mag
=
true
;
repaint
();
}
public
void
paintComponent
(
Graphics
g
){
if
(
mag
){
Graphics2D
g2
= (
Graphics2D
)
g
;
int
r
= (
int
) (
Math
.
random
() *
250
);
int
gr
= (
int
) (
Math
.
random
() *
250
);
int
b
= (
int
) (
Math
.
random
() *
250
);
g
.
setColor
(
new
Color
(
r
,
gr
,
b
));
int
ht
= (
int
) (
Math
.
random
() *
120
+
10
);
int
width
= (
int
) (
Math
.
random
() *
120
+
10
);
int
x
= (
int
) (
Math
.
random
() *
40
+
10
);
int
y
= (
int
) (
Math
.
random
() *
40
+
10
);
g
.
fillRect
(
x
,
y
,
ht
,
width
);
mag
=
false
;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL