Blame view

VRGNYMusicLights/Sources/ApplicationJava/MusicPath.java 6.07 KB
742429d1   pfrison   VRGNYMusicLight b...
1
2
  
  public class MusicPath {
a89c030d   pfrison   VRGNYMusicLights ...
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
  	public static final double[][] LIGHT_COORDS = new double[][] {
  		// Planche 1
  		{0.0383, 0}, {0.0766, 0}, {0.115, 0}, {0.1533, 0}, {0.1916, 0}, {0.23, 0}, //M1L1
  		{0.2683, 0}, {0.306, 0}, {0.345, 0}, {0.383, 0}, {0.4216, 0}, {0.46, 0}, {0.4983, 0}, //M1L2
  		{0.0333, 0.25}, {0.0666, 0.25}, {0.0999, 0.25}, {0.1333, 0.25}, //P1-1
  		{0.3016, 0.25}, {0.3366, 0.25}, {0.3733, 0.25}, {0.4099, 0.25}, {0.4466, 0.25}, {0.4833, 0.25}, {0.5199, 0.25}, //P1-2
  		{0.3366, 0.3}, {0.3366, 0.35}, //P1-3
  		{0, 0.3075}, {0, 0.365}, {0, 0.4225}, //M1l1
  
  		// Planche 2
  		{0.5366, 0}, {0.575, 0}, {0.6133, 0}, {0.6516, 0}, {0.69, 0}, {0.7283, 0}, {0.7666, 0}, //M2L1
  		{0.805, 0}, {0.8433, 0}, {0.8816, 0}, {0.92, 0}, {0.9583, 0}, //M2L2
  		{0.5566, 0.25}, {0.5933, 0.25}, {0.6299, 0.25}, {0.6666, 0.25}, //P2-1
  		{0.8366, 0.25}, {0.8699, 0.25}, {0.9032, 0.25}, {0.9366, 0.25}, {0.9699, 0.25}, //P2-2
  		{1, 0.06}, {1, 0.115}, {1, 0.17}, {1, 0.225}, {1, 0.28}, {1, 0.335}, {1, 0.39}, //M2l1
  		
  		// Planche 3
  		{0.3366, 0.4}, {0.3366, 0.45}, {0.3366, 0.5}, //P3-1
  		{0.3366, 0.75}, {0.3366, 0.8}, //P3-2
  		{0, 0.48}, {0, 0.5375}, {0, 0.595}, {0, 0.6525}, {0, 0.71}, {0, 0.7675}, //M3l1
  		
  		// Planche 4
  		{1, 0.445}, {1, 0.5}, {1, 0.555}, {1, 0.61}, {1, 0.665}, {1, 0.72}, {1, 0.775}, //M4l1
  		
  		// Planche 5
  		{0.0383, 1}, {0.0766, 1}, {0.115, 1}, {0.1533, 1}, {0.1916, 1}, {0.23, 1}, //M5L1
  		{0.2683, 1}, {0.306, 1}, {0.345, 1}, {0.383, 1}, {0.4216, 1}, {0.46, 1}, {0.4983, 1}, //M5L2
  		{0.3366, 0.85}, {0.3366, 0.9}, {0.3366, 0.95}, //P5-1
  		{0, 0.8255}, {0, 0.8835}, {0, 0.9415}, //M5l1
  		
  		// Planche 6
  		{0.5366, 1}, {0.575, 1}, {0.6133, 1}, {0.6516, 1}, {0.69, 1}, {0.7283, 1}, {0.7666, 1}, //M6L1
  		{0.805, 1}, {0.8433, 1}, {0.8816, 1}, {0.92, 1}, {0.9583, 1}, //M6L2
  		{1, 0.83}, {1, 0.885}, {1, 0.94} //M6l1
  	};
  	
d175ba55   pfrison   VRGNYMusicLight a...
39
40
41
42
43
44
45
46
47
48
49
50
51
  	public static final String[] pathNames = new String[] {
  			"Vertical down",
  			"Vertical up",
  			"Horizontal right to left",
  			"Horizontal left to right",
  			"Diagonal up right to down left",
  			"Diagonal down left to up right",
  			"Diagonal up left to down right",
  			"Diagonal down right to up left",
  			"Center out",
  			"Center in",
  			"Flashing",
  	};
a89c030d   pfrison   VRGNYMusicLights ...
52
53
54
55
56
57
58
59
60
61
62
  	public static final int VERTICAL_DOWN = 0;
  	public static final int VERTICAL_UP = 1;
  	public static final int HORIZONTAL_TO_LEFT = 2;
  	public static final int HORIZONTAL_TO_RIGHT = 3;
  	public static final int DIAGONAL_TOP_RIGHT_DOWN_LEFT = 4;
  	public static final int DIAGONAL_DOWN_LEFT_TOP_RIGHT = 5;
  	public static final int DIAGONAL_TOP_LEFT_DOWN_RIGHT = 6;
  	public static final int DIAGONAL_DOWN_RIGHT_TOP_LEFT = 7;
  	public static final int CENTER_OUT = 8;
  	public static final int CENTER_IN = 9;
  	public static final int ALL = 10;
742429d1   pfrison   VRGNYMusicLight b...
63
64
  	
  	private int animation;
a89c030d   pfrison   VRGNYMusicLights ...
65
66
  	private int effectDuration;
  	private double[][] lightsCoords;
742429d1   pfrison   VRGNYMusicLight b...
67
  	
a89c030d   pfrison   VRGNYMusicLights ...
68
69
  	public MusicPath(int animation, int effectDuration) { this(animation, effectDuration, LIGHT_COORDS); }
  	public MusicPath(int animation, int effectDuration, double[][] lightsCoords) {
742429d1   pfrison   VRGNYMusicLight b...
70
  		this.animation = animation;
a89c030d   pfrison   VRGNYMusicLights ...
71
72
  		this.effectDuration = effectDuration;
  		this.lightsCoords = lightsCoords;
742429d1   pfrison   VRGNYMusicLight b...
73
  	}
d175ba55   pfrison   VRGNYMusicLight a...
74
75
76
  
  	public int getAnimation() { return animation; }
  	public int getEffectDuration() { return effectDuration; }
742429d1   pfrison   VRGNYMusicLight b...
77
  	
a89c030d   pfrison   VRGNYMusicLights ...
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  	public int[] calculateTickDelais() { // tick in ms
  		int[] ticksDelais = new int[lightsCoords.length];
  		for(int i=0; i<ticksDelais.length; i++) {
  			ticksDelais[i] = 0;
  			if(animation == VERTICAL_DOWN
  					|| animation == VERTICAL_UP
  					|| animation == HORIZONTAL_TO_LEFT
  					|| animation == HORIZONTAL_TO_RIGHT
  					|| animation == DIAGONAL_TOP_RIGHT_DOWN_LEFT
  					|| animation == DIAGONAL_DOWN_LEFT_TOP_RIGHT
  					|| animation == DIAGONAL_TOP_LEFT_DOWN_RIGHT
  					|| animation == DIAGONAL_DOWN_RIGHT_TOP_LEFT
  					|| animation == CENTER_OUT
  					|| animation == CENTER_IN) {
  				switch (animation) {
  				case VERTICAL_DOWN:
278cdee0   pfrison   VRGNYMusicLights ...
94
  					ticksDelais[i] -= tickLateVerticalDown(LIGHT_COORDS[i][1]);
a89c030d   pfrison   VRGNYMusicLights ...
95
96
  					break;
  				case VERTICAL_UP:
278cdee0   pfrison   VRGNYMusicLights ...
97
  					ticksDelais[i] -= tickLateVerticalUp(LIGHT_COORDS[i][1]);
a89c030d   pfrison   VRGNYMusicLights ...
98
99
  					break;
  				case HORIZONTAL_TO_LEFT:
278cdee0   pfrison   VRGNYMusicLights ...
100
  					ticksDelais[i] -= tickLateHorizontalToLeft(LIGHT_COORDS[i][0]);
a89c030d   pfrison   VRGNYMusicLights ...
101
102
  					break;
  				case HORIZONTAL_TO_RIGHT:
278cdee0   pfrison   VRGNYMusicLights ...
103
  					ticksDelais[i] -= tickLateHorizontalToRight(LIGHT_COORDS[i][0]);
a89c030d   pfrison   VRGNYMusicLights ...
104
105
  					break;
  				case DIAGONAL_TOP_RIGHT_DOWN_LEFT:
278cdee0   pfrison   VRGNYMusicLights ...
106
  					ticksDelais[i] -= tickLateDiagTRDL(LIGHT_COORDS[i][0], LIGHT_COORDS[i][1]);
a89c030d   pfrison   VRGNYMusicLights ...
107
108
  					break;
  				case DIAGONAL_DOWN_LEFT_TOP_RIGHT:
278cdee0   pfrison   VRGNYMusicLights ...
109
  					ticksDelais[i] -= tickLateDiagDLTR(LIGHT_COORDS[i][0], LIGHT_COORDS[i][1]);
a89c030d   pfrison   VRGNYMusicLights ...
110
111
  					break;
  				case DIAGONAL_TOP_LEFT_DOWN_RIGHT:
278cdee0   pfrison   VRGNYMusicLights ...
112
  					ticksDelais[i] -= tickLateDiagTLDR(LIGHT_COORDS[i][0], LIGHT_COORDS[i][1]);
a89c030d   pfrison   VRGNYMusicLights ...
113
114
  					break;
  				case DIAGONAL_DOWN_RIGHT_TOP_LEFT:
278cdee0   pfrison   VRGNYMusicLights ...
115
  					ticksDelais[i] -= tickLateDiagDRTL(LIGHT_COORDS[i][0], LIGHT_COORDS[i][1]);
a89c030d   pfrison   VRGNYMusicLights ...
116
117
  					break;
  				case CENTER_OUT:
278cdee0   pfrison   VRGNYMusicLights ...
118
  					ticksDelais[i] -= tickLateCenterOut(LIGHT_COORDS[i][0], LIGHT_COORDS[i][1]);
a89c030d   pfrison   VRGNYMusicLights ...
119
120
  					break;
  				case CENTER_IN:
278cdee0   pfrison   VRGNYMusicLights ...
121
  					ticksDelais[i] -= tickLateCenterIn(LIGHT_COORDS[i][0], LIGHT_COORDS[i][1]);
a89c030d   pfrison   VRGNYMusicLights ...
122
123
124
125
126
127
128
129
  					break;
  				}
  			}
  			else if(animation == ALL);
  		}
  		return ticksDelais;
  	}
  
278cdee0   pfrison   VRGNYMusicLights ...
130
131
132
133
134
135
136
137
138
139
  	private int tickLateVerticalDown(double y) {return (int) (y * effectDuration);}
  	private int tickLateVerticalUp(double y) {return (int) ((1-y) * effectDuration);}
  	private int tickLateHorizontalToRight(double x) {return (int) (x * effectDuration);}
  	private int tickLateHorizontalToLeft(double x) {return (int) ((1 - x) * effectDuration);}
  	private int tickLateDiagTRDL(double x, double y) {return (int) ((1 - x + y) / 2d * (double) effectDuration);}
  	private int tickLateDiagDLTR(double x, double y) {return (int) ((1 + x - y) / 2d * (double) effectDuration);}
  	private int tickLateDiagTLDR(double x, double y) {return (int) ((x + y) / 2d * (double) effectDuration);}
  	private int tickLateDiagDRTL(double x, double y) {return (int) ((2 - x - y) / 2d * (double) effectDuration);}
  	private int tickLateCenterOut(double x, double y) {return (int) (((x-0.5)*(x-0.5) + (y-0.5)*(y-0.5)) * 2 * (double) effectDuration);}
  	private int tickLateCenterIn(double x, double y) {return (int) ((0.5d - (x-0.5)*(x-0.5) - (y-0.5)*(y-0.5)) * 2 * (double) effectDuration);}
a89c030d   pfrison   VRGNYMusicLights ...
140
141
142
143
  
  	public int getNumberOfLights() {
  		return this.lightsCoords.length;
  	}
742429d1   pfrison   VRGNYMusicLight b...
144
  }