-
Notifications
You must be signed in to change notification settings - Fork 0
/
trancegate
140 lines (115 loc) · 5.69 KB
/
trancegate
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
desc:Cyclic Trance Gate
slider1:slider_stepsPerBeat=4<1,128,1>Steps Per Beat
slider2:slider_patternLength=16<3,64,1>Pattern Length (steps)
slider3:slider_adsrAttack=3<1.0,5000,1>Attack (ms)
slider4:slider_adsrDecay=1000<1,15000,1>Decay (ms)
slider5:slider_adsrSustain=-12.0<-120.0,24.0,1.0>Sustain (dB)
slider6:slider_adsrRelease=500<1.0,5000,1>Release (ms)
import adsr.jsfx-inc
in_pin:left input
in_pin:right input
out_pin:left output
out_pin:right output
@init
temp_lastSubbeatPosition = -1;
temp_lastInteractedPatternPosition = -1;
temp_lastPatternValue = -1;
temp_spinStartAngle = -999999;
@slider
// slider section simply feeds the Tale ADSR params
adsr.adsr_seta(slider_adsrAttack * 0.001);
adsr.adsr_setd(slider_adsrDecay * 0.001);
adsr.adsr_sets(exp(log(10)/20 * slider_adsrSustain));
adsr.adsr_setr(slider_adsrRelease * 0.001);
@serialize
// store the pattern content directly using file_var for each of the 64 slots
i=0;
while(
file_var(0,patternContent[i]);
i+=1;
i<64;
);
// also store the offset
file_var(0,patternOffset);
@sample
singleBeatDuration = 60.0/tempo;
subBeatDuration = singleBeatDuration / slider_stepsPerBeat;
subbeatPosition = floor(play_position / subBeatDuration) % slider_patternLength;
temp_lastSubbeatPosition != subbeatPosition ? (
patternValue = patternContent[(subbeatPosition+patternOffset)%slider_patternLength];
patternValue != temp_lastPatternValue ? ( patternValue == 1 ? adsr.adsr_a(1.0) : adsr.adsr_r(); );
temp_lastPatternValue = patternValue;
temp_lastSubbeatPosition = subbeatPosition;
);
// apply actual stereo audio processing from Tale ADSR
adsr.adsr_process() ?
(
spl0 *= adsr.env;
spl1 *= adsr.env;
) : spl0 = spl1 = 0;
@gfx
gfx_a = 1.0;
_uiDiameter = min(gfx_w, gfx_h);
// draw background and purple circle
gfx_clear = 0xEEEEEE;
// draw the cursor for the current beat position around the wheel
cursorLength = _uiDiameter / 2 - 5;
pi = $pi;
stepSizeSingleBeat = (2*pi)/slider_patternLength;
// Draw the ith polygonal segment of the cycle given the radial distance offset and the angular offset to use
function drawSegment(i, radiusOffset, angleOffset)
(
coord_a_x = gfx_w/2 + cos(i*stepSizeSingleBeat-pi/2-stepSizeSingleBeat/2+angleOffset) * (_uiDiameter / 2 - 5 + radiusOffset);
coord_a_y = gfx_h/2 + sin(i*stepSizeSingleBeat-pi/2-stepSizeSingleBeat/2+angleOffset) * (_uiDiameter / 2 - 5 + radiusOffset);
coord_b_x = gfx_w/2 + cos(i*stepSizeSingleBeat-pi/2-stepSizeSingleBeat/2+angleOffset) * (_uiDiameter / 2 - 5 - _uiDiameter * 0.12 - radiusOffset);
coord_b_y = gfx_h/2 + sin(i*stepSizeSingleBeat-pi/2-stepSizeSingleBeat/2+angleOffset) * (_uiDiameter / 2 - 5 - _uiDiameter * 0.12 - radiusOffset);
coord_c_x = gfx_w/2 + cos(i*stepSizeSingleBeat+stepSizeSingleBeat-pi/2-stepSizeSingleBeat/2-angleOffset) * (_uiDiameter / 2 - 5 + radiusOffset);
coord_c_y = gfx_h/2 + sin(i*stepSizeSingleBeat+stepSizeSingleBeat-pi/2-stepSizeSingleBeat/2-angleOffset) * (_uiDiameter / 2 - 5 + radiusOffset);
coord_d_x = gfx_w/2 + cos(i*stepSizeSingleBeat+stepSizeSingleBeat-pi/2-stepSizeSingleBeat/2-angleOffset) * (_uiDiameter / 2 - 5 - _uiDiameter * 0.12 - radiusOffset);
coord_d_y = gfx_h/2 + sin(i*stepSizeSingleBeat+stepSizeSingleBeat-pi/2-stepSizeSingleBeat/2-angleOffset) * (_uiDiameter / 2 - 5 - _uiDiameter * 0.12 - radiusOffset);
gfx_triangle(coord_a_x, coord_a_y, coord_b_x, coord_b_y, coord_c_x, coord_c_y, coord_d_x, coord_d_y);
);
// draw the "beat present" indicators
i=0;
while(
gfx_set(0.5, 0, 0.7);
drawSegment(i, 0, 0);
patternContent[(i+patternOffset)%slider_patternLength] == 1 ? gfx_set(0.93,0.9,0.93) : gfx_set(0.1, 0, 0.3);
drawSegment(i, -_uiDiameter*0.1, -0.005);
// indicate current with white half alpha overlay
subbeatPosition % slider_patternLength == i ? ( gfx_set(1,1,1,0.5); drawSegment(i, 0, 0); );
i+=1;
i<slider_patternLength;
);
// handle left mouse clicks by toggling positions on and off
mouse_cap & 1 == 1 ? (
relativeClickPositionX = mouse_x - gfx_w / 2;
relativeClickPositionY = mouse_y - gfx_h / 2;
clickPositionAngle = atan2(relativeClickPositionY, relativeClickPositionX) + $pi + stepSizeSingleBeat/2;
clickPositionInPattern = (floor(clickPositionAngle/(($pi*2)/slider_patternLength)) + slider_patternLength - (slider_patternLength/4)) % slider_patternLength;
clickPositionInPattern = (clickPositionInPattern + patternOffset) % slider_patternLength;
temp_lastInteractedPatternPosition != clickPositionInPattern ? (
patternContent[clickPositionInPattern] = patternContent[clickPositionInPattern] == 0 ? 1 : 0;
temp_lastInteractedPatternPosition = clickPositionInPattern;
);
) : temp_lastInteractedPatternPosition = -1;
// handle right mouse drags by shifting the patterns
mouse_cap & 2 == 2 ? (
relativeClickPositionX = mouse_x - gfx_w / 2;
relativeClickPositionY = mouse_y - gfx_h / 2;
clickPositionAngle = atan2(relativeClickPositionY , relativeClickPositionX) + $pi;
temp_spinStartAngle != -1 ? (
clickPositionAngleDelta = temp_spinStartAngle - clickPositionAngle;
clickPositionAngleDelta = abs(clickPositionAngleDelta) > $pi ? (temp_spinStartAngle - clickPositionAngle) - sign(clickPositionAngleDelta)*2*$pi : clickPositionAngleDelta;
spion_indicator_radius = sqrt(relativeClickPositionX*relativeClickPositionX + relativeClickPositionY*relativeClickPositionY);
gfx_set(0.5, 0, 0.7);
gfx_arc( gfx_w / 2, gfx_h / 2, spion_indicator_radius, temp_spinStartAngle - $pi/2, temp_spinStartAngle - clickPositionAngleDelta - $pi/2, 1);
abs(clickPositionAngleDelta) >= stepSizeSingleBeat ? (
temp_spinStartAngle = clickPositionAngle;
patternOffset += sign(clickPositionAngleDelta);
);
);
temp_spinStartAngle == -1 ? (
temp_spinStartAngle = clickPositionAngle;
);
) : temp_spinStartAngle = -1;