/
11_ServerSideMethods.scd
90 lines (50 loc) · 3.73 KB
/
11_ServerSideMethods.scd
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
/// Methods for mapping on the server:
MIDIIn.connectAll;
s.boot;
// we use Ndef in this example, to allow for a flexible redefining of the sound on the server
Ndef( \testSynth, { arg freq=440, amp=0.1, t_trig=1, dur=1; SinOsc.ar( freq, 0, amp ) * EnvGen.kr( Env.perc, t_trig, timeScale: dur ) } );
Ndef( \testSynth ).play;
MIDIdef.noteOn( \akaiPad1On, { arg val; Ndef( \testSynth ).set( \t_trig, 1, \amp, val/127 ) }, 36, 0, 1310720 ); // listen to note on
//// mapping ranges:
/// linlin:
Ndef( \testSynth, { arg freq=440, ampin=64, t_trig=1, dur=1; SinOsc.ar( freq, 0, ampin.linlin( 0, 127, 0, 0.2 ) ) * EnvGen.kr( Env.perc, t_trig, timeScale: dur ) } );
MIDIdef.noteOn( \akaiPad1On, { arg val; Ndef( \testSynth ).set( \t_trig, 1, \ampin, val ) }, 36, 0, 1310720 ); // listen to note on
// linexp
Ndef( \testSynth, { arg freq=440, ampin=64, t_trig=1, dur=1; SinOsc.ar( freq, 0, ampin.linexp( 0, 127, 0.0001, 0.2 ) ) * EnvGen.kr( Env.perc, t_trig, timeScale: dur ) } );
// explin
Ndef( \testSynth, { arg freq=440, ampin=64, t_trig=1, dur=1; SinOsc.ar( freq, 0, ampin.explin( 1, 127, 0.0001, 0.2 ) ) * EnvGen.kr( Env.perc, t_trig, timeScale: dur ) } );
// expexp
Ndef( \testSynth, { arg freq=440, ampin=64, t_trig=1, dur=1; SinOsc.ar( freq, 0, ampin.expexp( 1, 127, 0.0001, 0.2 ) ) * EnvGen.kr( Env.perc, t_trig, timeScale: dur ) } );
// lincurve
Ndef( \testSynth, { arg freq=440, ampin=64, t_trig=1, dur=1; SinOsc.ar( freq, 0, ampin.lincurve( 0, 127, 0, 0.2, -4 ) ) * EnvGen.kr( Env.perc, t_trig, timeScale: dur ) } );
// curvelin
Ndef( \testSynth, { arg freq=440, ampin=64, t_trig=1, dur=1; SinOsc.ar( freq, 0, ampin.curvelin( 0, 127, 0, 0.2, -4 ) ) * EnvGen.kr( Env.perc, t_trig, timeScale: dur ) } );
/// range:
Ndef( \testSynth, { arg freq=440, ampin=64, t_trig=1, dur=1; SinOsc.ar( freq, 0, (ampin/127).range( 0, 0.2 ) ) * EnvGen.kr( Env.perc, t_trig, timeScale: dur ) } );
/// exprange:
Ndef( \testSynth, { arg freq=440, ampin=64, t_trig=1, dur=1; SinOsc.ar( freq, 0, (ampin/127).range( 0.001, 0.2 ) ) * EnvGen.kr( Env.perc, t_trig, timeScale: dur ) } );
/// clipping, folding, wrapping
Ndef( \testSynth, { arg freq=440, ampin=64, t_trig=1, dur=1; SinOsc.ar( freq, 0, (ampin/127).clip( 0, 0.06 ) ) * EnvGen.kr( Env.perc, t_trig, timeScale: dur ) } );
Ndef( \testSynth, { arg freq=440, ampin=64, t_trig=1, dur=1; SinOsc.ar( freq, 0, (ampin/127).fold( 0, 0.1 ) ) * EnvGen.kr( Env.perc, t_trig, timeScale: dur ) } );
Ndef( \testSynth, { arg freq=440, ampin=64, t_trig=1, dur=1; SinOsc.ar( freq, 0, (ampin/127).wrap( 0, 0.1 ) ) * EnvGen.kr( Env.perc, t_trig, timeScale: dur ) } );
/// these are all direct... more interesting is also the behaviour over time:
MIDIdef.noteOn( \akaiPad1On, { arg val; Ndef( \testSynth ).set( \amp, val/255 ) }, 36, 0, 1310720 ); // listen to note on
MIDIdef.noteOff( \akaiPad1Off, { arg val; Ndef( \testSynth ).set( \amp, 0 ) }, 36, 0, 1310720 ); // listen to note on
// lag
Ndef( \testSynth, { arg freq=440, amp=0, t_trig=1, dur=1; SinOsc.ar( freq, 0, amp.lag( 0.5 ) ) } );
// lag up down
Ndef( \testSynth, { arg freq=440, amp=0, t_trig=1, dur=1; SinOsc.ar( freq, 0, amp.lag( 0.1, 2 ) ) } );
// different curve
Ndef( \testSynth, { arg freq=440, amp=0, t_trig=1, dur=1; SinOsc.ar( freq, 0, amp.lag2( 0.1, 2 ) ) } );
// different curve...
Ndef( \testSynth, { arg freq=440, amp=0, t_trig=1, dur=1; SinOsc.ar( freq, 0, amp.lag3( 0.1, 2 ) ) } );
// variable curve
Ndef( \testSynth, { arg freq=440, amp=0, t_trig=1, dur=1; SinOsc.ar( freq, 0, amp.varlag( 0.1, -4, 4 ) ) } ); // [VarLag] ugen
// limit the slope
Ndef( \testSynth, { arg freq=440, amp=0, t_trig=1, dur=1; SinOsc.ar( freq, 0, amp.slew( 0.1, 0.2 ) ) } ); // [Slew] ugen
// Also: [Ramp]
// useful conversions for frequencies:
// midicps
// cpsmidi
Ndef( \testSynth ).clear;
MIDIdef.freeAll;