«Poussière : standalone dust generator (uncommented version of luce)» by Dindoléon

on 18 Nov'18 13:22 in guislidermodule

Dust2 synth controlled by a custom 2D slider (kind of simulates vinyl crackles). Actually an uncommented fork of the luce module. Easy to integrate and modify.

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
(
/* Poussière module for SuperCollider, licensed under GNU GPL v3 (<https://www.gnu.org/licenses/>),
Poussière means 'Dust' in French.
Written by Simon Deplat (aka Dindoleon).
See http://sccode.org/1-5aY for more informations.
*/

var synth, synth_amount_range, win, window_size, slider, margin, value, knob_size, knob_outline_size, stroke_size, frame_color, frame_border_color, gradient_color, diamond_color, diamond_outline_color;

window_size = [ 400, 300 ];
knob_size = 8;
knob_outline_size = 15;
stroke_size = 2;
margin = 3;

frame_color = Color.black;
frame_border_color = Color.white;
gradient_color = Color.white;
//Diamond Colors are disabled in order to change its color on fly
//diamond_color = Color.red;
//diamond_outline_color = Color.red;

value = [ 0, 1 ];
synth_amount_range = [ 0.5, 10000 ];

synth = SynthDef(\poussiere, {
	|out = 0, freq = 440, amp = 0, amount = 0|
	var snd;
	snd = Dust2.ar(amount, 1);
	Out.ar(out, Pan2.ar(snd, 0, amp));
}).play;

win = Window("Poussière", Rect(0, 0, window_size[0], window_size[1]), false);
win.background_( frame_color );
slider = UserView( win, Rect( margin, margin, window_size[0] - ( margin * 2 ), window_size[1] - ( margin * 2 ) ));

slider.drawFunc = {
	Pen.width = stroke_size;
	Pen.addRect( Rect(0,0, slider.bounds.width,slider.bounds.height) );
	Pen.fillAxialGradient( slider.bounds.leftBottom, slider.bounds.rightTop, Color.black, gradient_color );
	Pen.moveTo( ( slider.bounds.width * value[0] - knob_size ) @ ( slider.bounds.height * value[1] ) );
	Pen.lineTo( ( slider.bounds.width * value[0] ) @ ( slider.bounds.height * value[1] - knob_size ) );
	Pen.lineTo( ( slider.bounds.width * value[0] + knob_size ) @ (( slider.bounds.height * value[1] ) ) );
	Pen.lineTo( ( slider.bounds.width * value[0] ) @ ( slider.bounds.height * value[1] + knob_size ) );
	Pen.fillColor_( Color.new( 1-((0.5*value[0])+(0.5*(1-value[1]))), 1-((0.5*value[0])+(0.5*(1-value[1]))), 1-((0.5*value[0])+(0.5*(1-value[1]))) ) ); // Here.
	Pen.fill;
	Pen.moveTo( 0 @ ( slider.bounds.height * value[1] ) );
	Pen.lineTo( ( slider.bounds.width * value[0] - knob_outline_size ) @ ( slider.bounds.height * value[1] ) );
	Pen.moveTo( ( slider.bounds.width * value[0] ) @ 0 );
	Pen.lineTo( ( slider.bounds.width * value[0] ) @ ( slider.bounds.height * value[1] - knob_outline_size ) );
	Pen.moveTo( ( slider.bounds.width * value[0] + knob_outline_size ) @ (( slider.bounds.height * value[1] ) ) );
	Pen.lineTo( slider.bounds.width @ (( slider.bounds.height * value[1] ) ) );
	Pen.moveTo( ( slider.bounds.width * value[0] ) @ (( slider.bounds.height * value[1] + knob_outline_size ) ) );
	Pen.lineTo( ( slider.bounds.width * value[0] ) @  slider.bounds.height );
	Pen.moveTo( ( slider.bounds.width * value[0] - knob_outline_size ) @ ( slider.bounds.height * value[1] ) );
	Pen.lineTo( ( slider.bounds.width * value[0] ) @ ( slider.bounds.height * value[1] - knob_outline_size ) );
	Pen.lineTo( ( slider.bounds.width * value[0] + knob_outline_size ) @ (( slider.bounds.height * value[1] ) ) );
	Pen.lineTo( ( slider.bounds.width * value[0] ) @ (( slider.bounds.height * value[1] + knob_outline_size ) ) );
	Pen.lineTo( ( slider.bounds.width * value[0] - knob_outline_size ) @ ( slider.bounds.height * value[1] ) );
	Pen.strokeColor_( Color.new( 1-((0.5*value[0])+(0.5*(1-value[1]))), 1-((0.5*value[0])+(0.5*(1-value[1]))), 1-((0.5*value[0])+(0.5*(1-value[1]))) ) ); // And here.
	Pen.stroke;
	Pen.addRect( Rect(0,0, slider.bounds.width,slider.bounds.height) );
	Pen.strokeColor_( frame_border_color );
	Pen.stroke;
};

slider.action = {
	synth.set(\amp, 1 - value[1]);
	synth.set(\amount, linexp(value[0], 0, 1, synth_amount_range[0], synth_amount_range[1]));
	slider.refresh
};

slider.mouseDownAction = { arg slider, x = 0.5, y = 0.5, m;
	([256, 0].includes(m)).if{
		value[0] = (x).linlin(0,slider.bounds.width,0,1);
		value[1] = (y).linlin(0,slider.bounds.height,0,1);
		slider.doAction};
};
slider.mouseMoveAction = slider.mouseDownAction;
win.front;
)
raw 4071 chars (focus & ctrl+a+c to copy)
reception
comments