Skip to content

Commit 160a9ee

Browse files
committed
Re-org and commit new stuff.
New stuff: - {Software} Structure. - Various examples from 3rd-party libraries. - kazimuth's examples, 'cause I haven't anywhere else to keep them. - A few example from the Processing Handbook.
1 parent 0554007 commit 160a9ee

File tree

163 files changed

+4259
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+4259
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from ddf.minim.ugens import Frequency, Line, Oscil
2+
from ddf.minim.ugens import Instrument, Waves, Pan
3+
4+
5+
class FlutterSaw(Instrument):
6+
def __init__(self, freq, panning, patchTo):
7+
self.saw = Oscil(freq, 1.0, Waves.SAW)
8+
self.ampMod = Oscil(2.0, 0.5, Waves.SINE)
9+
self.pan = Pan(panning)
10+
self.out = patchTo
11+
12+
def noteOn(self, dur):
13+
ampModFreqLine = Line(dur * 0.9, 0.5, Frequency.ofPitch("C3").asHz())
14+
ampModFreqLine.patch(self.ampMod.frequency).patch(self.saw.amplitude)
15+
ampModFreqLine.activate()
16+
self.saw.patch(self.pan).patch(self.out)
17+
18+
def noteOff(self):
19+
self.pan.unpatch(self.out)
20+
21+
22+
class FilterFrequency(Instrument):
23+
def __init__(self, begin, end, moog):
24+
self.filterFreqLine = Line()
25+
self.begin = begin
26+
self.end = end
27+
self.moog = moog
28+
29+
def noteOn(self, dur):
30+
self.filterFreqLine = Line(dur, self.begin, self.end)
31+
self.filterFreqLine.activate()
32+
self.filterFreqLine.patch(self.moog.frequency)
33+
34+
def noteOff(self):
35+
self.filterFreqLine.unpatch(self.moog)
36+
37+
38+
class FilterResonance(Instrument):
39+
def __init__(self, begin, end, moog):
40+
self.filterRezLine = Line()
41+
self.begin = begin
42+
self.end = end
43+
self.moog = moog
44+
45+
def noteOn(self, dur):
46+
self.filterRezLine = Line(dur, self.begin, self.end)
47+
self.filterRezLine.activate()
48+
self.filterRezLine.patch(self.moog.resonance)
49+
50+
def noteOff(self):
51+
self.filterRezLine.unpatch(self.moog)
52+
53+
54+
def PlayFlutterSaw(audiooutput, time, dur, pitch, pan, patchTo):
55+
audiooutput.playNote(time, dur,
56+
FlutterSaw(Frequency.ofPitch(pitch).asHz(),
57+
pan, patchTo))
58+
59+
60+
def PlayFrequencySweep(audiooutput, time, dur, begin, end, moog):
61+
audiooutput.playNote(time, dur, FilterFrequency(begin, end, moog))
62+
63+
64+
def PlayResonanceSweep(audiooutput, time, dur, begin, end, moog):
65+
audiooutput.playNote(time, dur, FilterResonance(begin, end, moog))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from ddf.minim import Minim
2+
from ddf.minim.ugens import Summer, MoogFilter, Frequency
3+
from Instruments import PlayFlutterSaw, PlayFrequencySweep, PlayResonanceSweep
4+
5+
minim = Minim(this)
6+
mainOut = minim.getLineOut(Minim.STEREO, 256)
7+
sawSummer = Summer()
8+
moog = MoogFilter(3000.0, 0.2)
9+
waveSize = 100.0
10+
notes = ['C2', 'G3', 'E5', 'D6', 'D6', 'C8']
11+
tempo = 130.0
12+
PAN_CENTER = 0.0
13+
PAN_LEFT = -1.0
14+
PAN_RIGHT = 1.0
15+
PAN_L_HALF = -0.5
16+
PAN_R_HALF = 0.5
17+
18+
# Gain in (presumably) dBFS
19+
mainOut.setGain(0)
20+
21+
22+
def setup():
23+
size(800, 400)
24+
colorMode(HSB, 360, 1, 1)
25+
26+
sawSummer.patch(moog).patch(mainOut)
27+
mainOut.pauseNotes()
28+
mainOut.setTempo(tempo)
29+
30+
# PlayFlutterSaw(audiooutput, time, dur, pitch, pan, patchTo)
31+
PlayFlutterSaw(mainOut, 0.0, 200.0, notes[0], PAN_CENTER, sawSummer)
32+
PlayFlutterSaw(mainOut, 8.0, 192.0, notes[1], PAN_LEFT, sawSummer)
33+
PlayFlutterSaw(mainOut, 16.0, 184.0, notes[2], PAN_RIGHT, sawSummer)
34+
PlayFlutterSaw(mainOut, 32.0, 168.0, notes[3], PAN_R_HALF, sawSummer)
35+
PlayFlutterSaw(mainOut, 32.01, 167.99, notes[3], PAN_L_HALF, sawSummer)
36+
37+
# PlayFrequencySweep(audiooutput, time, dur, begin, end, moog)
38+
PlayFrequencySweep(mainOut, 32.0, 8.0, 3000.0, 10000.0, moog)
39+
PlayFrequencySweep(mainOut, 44.0, 4.0, 10000.0, 8000.0, moog)
40+
PlayFrequencySweep(mainOut, 48.0, 8.0, 8000.0, 200.0, moog)
41+
PlayFrequencySweep(mainOut, 62.0, 4.0, 200.0, 2000.0, moog)
42+
PlayFrequencySweep(mainOut, 74.0, 12.0, 2000.0, 400.0, moog)
43+
44+
# PlayResonanceSweep(audiooutput, time, dur, begin, end, moog)
45+
PlayResonanceSweep(mainOut, 66.0, 4.0, 0.2, 0.8, moog)
46+
PlayResonanceSweep(mainOut, 74.0, 12.0, 0.8, 0.0, moog)
47+
PlayResonanceSweep(mainOut, 86.0, 2.0, 0.0, 0.2, moog)
48+
PlayResonanceSweep(mainOut, 88.0, 2.0, 0.2, 0.0, moog)
49+
PlayResonanceSweep(mainOut, 90.0, 2.0, 0.0, 0.3, moog)
50+
PlayResonanceSweep(mainOut, 92.0, 2.0, 0.3, 0.01, moog)
51+
PlayResonanceSweep(mainOut, 94.0, 3.0, 0.01, 0.9, moog)
52+
PlayResonanceSweep(mainOut, 122.0, 24.0, 0.9, 0.05, moog)
53+
54+
PlayFrequencySweep(mainOut, 98.0, 24.0, 400.0, 1000.0, moog)
55+
PlayFrequencySweep(mainOut, 122.0, 12.0, 1000.0,
56+
Frequency.ofPitch(notes[4]).asHz(), moog)
57+
58+
mainOut.resumeNotes()
59+
#
60+
#
61+
# DRAWING DOWN HERE
62+
#
63+
64+
65+
def hueForSample(sample):
66+
return map(abs(sample), 0, 1, 120, 450)
67+
68+
69+
def draw():
70+
# erase the window to black
71+
lastRez = moog.resonance.getLastValue()
72+
lastFreq = moog.frequency.getLastValue() / 22100.0
73+
background(lastFreq * 360.0, 0.5, lastRez)
74+
# draw using a white stroke
75+
stroke(255)
76+
# draw the waveforms
77+
left = mainOut.left.toArray()
78+
right = mainOut.right.toArray()
79+
for i in range(mainOut.bufferSize() - 1):
80+
# find the x position of each buffer value
81+
x1 = map(i, 0, mainOut.bufferSize(), 0, width)
82+
x2 = map(i + 1, 0, mainOut.bufferSize(), 0, width)
83+
# draw a line from one buffer position to the next for both channels
84+
stroke(hueForSample(left[i]), 1, 1)
85+
line(x1, height / 2 - waveSize + left[i] * waveSize,
86+
x2, height / 2 - waveSize + left[i + 1] * waveSize)
87+
stroke(hueForSample(right[i]), 1, 1)
88+
line(x1, height / 2 + waveSize + right[i] * waveSize,
89+
x2, height / 2 + waveSize + right[i + 1] * waveSize)
90+
91+
92+
def keyPressed():
93+
# close the AudioOutput
94+
mainOut.close()
95+
# stop the minim object
96+
minim.stop()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
add_library('minim')
2+
3+
from ddf.minim import Minim
4+
from ddf.minim.ugens import Waves, Oscil
5+
6+
minim = Minim(this)
7+
out = minim.getLineOut()
8+
wave = Oscil(440, 0.5, Waves.SINE)
9+
wave.patch(out)
10+
waveDrawMult = None
11+
12+
13+
def setup():
14+
size(512, 200, P3D)
15+
waveDrawMult = height / 2 - height * 0.49
16+
17+
18+
def draw():
19+
background(0)
20+
stroke(255)
21+
strokeWeight(1)
22+
23+
# draw the waveform of the output
24+
for i in range(out.bufferSize() - 1):
25+
line(i, 50 - out.left.get(i) * 50,
26+
i + 1, 50 - out.left.get(i + 1) * 50)
27+
line(
28+
i, 150 - out.right.get(i) * 50,
29+
i + 1, 150 - out.right.get(i + 1) * 50)
30+
31+
# draw the waveform we are using in the oscillator
32+
stroke(128, 0, 0)
33+
strokeWeight(4)
34+
for i in range(width - 1):
35+
point(i, waveDrawMult * wave.getWaveform().value(float(i) / width))
36+
37+
38+
def mouseMoved():
39+
amp = map(mouseY, 0, height, 1, 0)
40+
wave.setAmplitude(amp)
41+
42+
freq = map(mouseX, 0, width, 110, 880)
43+
wave.setFrequency(freq)
44+
45+
46+
def keyPressed():
47+
if key == '1':
48+
wave.setWaveform(Waves.SINE)
49+
elif key == '2':
50+
wave.setWaveform(Waves.TRIANGLE)
51+
elif key == '3':
52+
wave.setWaveform(Waves.SAW)
53+
elif key == '4':
54+
wave.setWaveform(Waves.SQUARE)
55+
elif key == '5':
56+
wave.setWaveform(Waves.QUARTERPULSE)
57+
else:
58+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# The BrapInstrument is intended to give a chopped up mixture of tone and noise.
2+
3+
# Every instrument must implement the Instrument interface so
4+
# playNote() can call the instrument's methods.
5+
class BrapInstrument implements Instrument
6+
7+
# create all variables that must be used throughout the class
8+
Oscil toneOsc, fmOsc
9+
ADSR adsr
10+
Noise pinkNoise
11+
Constant fmConstant
12+
Summer sum, fmSummer
13+
GranulateSteady chopper
14+
AudioOutput out
15+
16+
# the constructor for this instrument specifies the amplitude of the output,
17+
# the frequency of the tone, and the on and off time of the granulating gate
18+
BrapInstrument(amp, toneFreq, onTime, offTime, AudioOutput output)
19+
20+
# equate class variables to constructor variables as necessary
21+
out = output
22+
23+
# create instances of any UGen objects as necessary
24+
toneOsc = Oscil(toneFreq, amp, Waves.TRIANGLE)
25+
# a little frequency modulation for added harmonics never hurt anyone, right?
26+
fmOsc = Oscil(toneFreq / 2.0, toneFreq / 2.0, Waves.SAW)
27+
fmConstant = Constant(toneFreq)
28+
fmSummer = Summer()
29+
30+
pinkNoise = Noise(amp / 3.0, Noise.Tint.PINK)
31+
adsr = ADSR(1.0, 0.003, 0.003, 1.0, 0.003)
32+
chopper = GranulateSteady(onTime, offTime, 0.0025)
33+
sum = Summer()
34+
35+
# patch everything together up to the output
36+
# put some freq modulation on the tone
37+
fmOsc.patch(fmSummer)
38+
fmConstant.patch(fmSummer)
39+
fmSummer.patch(toneOsc.frequency)
40+
41+
# put both the tone and the noise into the summer
42+
toneOsc.patch(sum)
43+
pinkNoise.patch(sum)
44+
# pass the summer through a granulating gate to the adsr
45+
sum.patch(chopper).patch(adsr)
46+
47+
48+
# every instrument must have a noteOn() method
49+
def noteOn(dur):
50+
51+
# patch the adsr all the way to the output
52+
adsr.patch(out)
53+
# and turn it on
54+
adsr.noteOn()
55+
56+
57+
# every instrument must have a noteOff() method
58+
def noteOff():
59+
60+
# turn off adsr, which cause the release to begin
61+
adsr.noteOff()
62+
# after the release is over, unpatch from the ou
63+
adsr.unpatchAfterRelease(out)
64+
65+

0 commit comments

Comments
 (0)