Debian Codegraph @

Resources/modules/Pitch/LooperMod.c5

raw
1 import random
2 class Module(BaseModule):
3 """
4 "Looper module with optional amplitude and frequency modulation"
5
6 Description
7
8 A simple soundfile looper with optional amplitude and frequency modulations
9 of variable shapes.
10
11 Sliders
12
13 # AM Range :
14 Minimum and maximum amplitude of the Amplitude Modulation LFO
15 # AM Speed :
16 Frequency of the Amplitude Modulation LFO
17 # FM Range :
18 Minimum and maximum amplitude of the Frequency Modulation LFO
19 # FM Speed :
20 Frequency of the Frequency Modulation LFO
21 # Dry / Wet :
22 Mix between the original signal and the processed signal
23
24 Graph Only
25
26 # Overall Amplitude :
27 The amplitude curve applied on the total duration of the performance
28
29 Popups & Toggles
30
31 # AM LFO Type :
32 Shape of the amplitude modulation waveform
33 # AM On/Off :
34 Activate or deactivate the amplitude modulation
35 # FM LFO Type :
36 Shape of the frequency modulation waveform
37 # FM On/Off :
38 Activate or deactivate frequency modulation
39 # Polyphony Voices :
40 Number of voices played simultaneously (polyphony),
41 only available at initialization time
42 # Polyphony Spread :
43 Pitch variation between voices (chorus),
44 only available at initialization time
45
46 """
47 def __init__(self):
48 BaseModule.__init__(self)
49 self.snd = self.addFilein("snd")
50 if type(self.snd.getRate()) == type([]):
51 rate = self.snd.getRate()[0]
52 else:
53 rate = self.snd.getRate()
54 self.lfoam = LFO(freq=self.amspeed, sharp=1, type=self.ampwave_index, mul=0.37, add=0.6)
55 self.lfoamrange = Randi(min=self.amrange[0], max=self.amrange[1], freq=self.amspeed, mul=self.lfoam)
56 self.lfofm = LFO(freq=self.fmspeed, sharp=1, type=self.freqwave_index, mul=0.05, add=1)
57 self.sig1 = Sig(self.fmrange[0])
58 self.sig2 = Sig(self.fmrange[1])
59 self.lfofmrange = Randi(min=1-self.sig1, max=1+self.sig2, freq=self.fmspeed, mul=self.lfofm)
60 self.pitrnds = [x*rate for x in self.polyphony_spread for j in range(self.nchnls)]
61 self.ply = [i*self.lfofmrange for i in self.pitrnds]
62 self.index = Phasor(freq=self.pitrnds)
63 self.pointer = Pointer(self.snd, self.index)
64 self.index2 = Phasor(freq=self.pitrnds)
65 self.pointer2 = Pointer(self.snd, self.index2)
66 self.out = Interp(self.pointer2.mix(self.nchnls), self.pointer.mix(self.nchnls), self.drywet, mul=self.polyphony_scaling*0.5*self.env)
67
68 #INIT
69 self.onoffam(self.onoffam_value)
70 self.onofffm(self.onofffm_value)
71
72 def ampwave(self, index, value):
73 if index == 0:
74 self.lfoam.sharp = 0.0
75 else:
76 self.lfoam.sharp = 1.0
77 self.lfoam.type = (index - 1) % 8
78
79 def freqwave(self, index, value):
80 if index == 0:
81 self.lfofm.sharp = 0.0
82 else:
83 self.lfofm.sharp = 1.0
84 self.lfofm.type = (index - 1) % 8
85
86 def onoffam(self, value):
87 if value == 0:
88 self.pointer.mul = 1
89 else:
90 self.pointer.mul = self.lfoamrange
91
92 def onofffm(self, value):
93 if value == 0:
94 self.index.freq = self.pitrnds
95 else:
96 self.index.freq = self.ply
97
98 Interface = [ cfilein(name="snd"),
99 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue1"),
100 crange(name="amrange", label="AM Range", min=0.001, max=1, init=[0.3,0.5], rel="lin", unit="x", col="green1"),
101 cslider(name="amspeed", label="AM Speed", min=0.001, max=2000, init=8, rel="log", unit="Hz", col="green2"),
102 crange(name="fmrange", label="FM Range", min=0.001, max=0.2, init=[0.01,0.05], rel="lin", unit="x", col="red1"),
103 cslider(name="fmspeed", label="FM Speed", min=0.001, max=2000, init=200, rel="log", unit="Hz", col="red2"),
104 cslider(name="drywet", label="Dry / Wet", min=0, max=1, init=1, rel="lin", unit="x", col="blue1"),
105 cpopup(name="ampwave", label="AM LFO Type", init="Sine", col="green1", value=["Sine", "Saw Up", "Saw Down", "Square",
106 "Triangle", "Pulse", "Bipolar Pulse", "SAH"]),
107 ctoggle(name="onoffam", label="AM On/Off", init=1, col="green2"),
108 cpopup(name="freqwave", label="FM LFO Type", init="Sine", col="red1", value=["Sine", "Saw Up", "Saw Down", "Square",
109 "Triangle", "Pulse", "Bipolar Pulse", "SAH"]),
110 ctoggle(name="onofffm", label="FM On/Off", init=1, col="red2"),
111 cpoly()
112 ]