742429d1
pfrison
VRGNYMusicLight b...
|
1
2
3
4
5
6
7
8
9
|
public class MusicPattern {
/* Pattern definition :
* 0 : low time
* 1 : rise time
* 2 : high time
* 3 : fall time
*/
private int[] pattern; // in ms
|
a89c030d
pfrison
VRGNYMusicLights ...
|
10
11
12
13
|
private int totalLentgh;
private int[] patternTiming = new int[4]; // in ms
private long begin; // in ms
private long stop; // in ms
|
742429d1
pfrison
VRGNYMusicLight b...
|
14
|
|
a89c030d
pfrison
VRGNYMusicLights ...
|
15
|
public MusicPattern(int[] pattern, int repeat, long begin) {
|
742429d1
pfrison
VRGNYMusicLight b...
|
16
17
18
|
if(pattern.length != 4)
throw new InvalidPatternException();
this.pattern = pattern;
|
a89c030d
pfrison
VRGNYMusicLights ...
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
this.totalLentgh = pattern[0] + pattern[1] + pattern[2] + pattern[3];
this.patternTiming[0] = pattern[0];
for(int i=1; i<4; i++)
this.patternTiming[i] = this.patternTiming[i-1] + pattern[i];
this.begin = begin;
this.stop = repeat * totalLentgh;
}
public double render(long tick) { // tick in ms
if(tick <= begin)
return 0;
if(tick >= stop)
return 0;
int tickMod = (int) (tick % totalLentgh);
if(tickMod < patternTiming[0])
return 0;
if(tickMod < patternTiming[1])
return (double) (tickMod - patternTiming[0]) / (double) (pattern[1]);
if(tickMod < patternTiming[2])
return 1;
return 1 - ((double) (tickMod - patternTiming[2]) / (double) (pattern[3]));
|
742429d1
pfrison
VRGNYMusicLight b...
|
40
41
|
}
}
|