Permalink
Browse files

sliders is almost interesting

  • Loading branch information...
1 parent 76a0eb7 commit 37762fcf2d085d60d3ed5ce268db059f891e8fc5 @jacobjoaquin committed Aug 12, 2010
Showing with 48 additions and 19 deletions.
  1. +25 −8 examples/sliders/data/synth.csd
  2. +23 −11 examples/sliders/sliders.pde
@@ -6,25 +6,42 @@ ksmps = 30
nchnls = 1
0dbfs = 1
+; Create sine table
gi_sin ftgen 1, 0, 8192, 10, 1
-chn_k "slider_1", 1
-chn_k "slider_2", 1
+; Define chn busses
+chn_k "amp", 1 ; Amplitude
+chn_k "freq", 1 ; Frequency
+chn_k "c", 1 ; Carrier amount
+chn_k "m", 1 ; Modulation amount
+chn_k "index", 1 ; FM Index
+chn_k "lfo_amp", 1 ; LFO amplitude
+chn_k "lfo_rate", 1 ; LFO rate
instr 1
- idur = p3
- iamp = p4
+ idur = p3 ; Duration
+ iamp = p4 ; Amplitude
- k1 chnget "slider_1"
- k2 chnget "slider_2"
+ ; Read values from chn busses
+ kamp chnget "amp"
+ kfreq chnget "freq"
+ kc chnget "c"
+ km chnget "m"
+ kindex chnget "index"
+ klfo_amp chnget "lfo_amp"
+ klfo_rate chnget "lfo_rate"
- a1 foscil iamp, 440, 1, k1, k2, gi_sin
+ ; FM Synthesizer
+ klfo oscil 0.5, klfo_rate, gi_sin, 0.75
+ klfo = (klfo + 0.5) * klfo_amp
+ a1 foscil iamp * kamp, kfreq + kfreq * klfo, kc, km, kindex, gi_sin
+ ; Output
out a1
endin
</CsInstruments>
<CsScore>
-i 1 0 [60 * 60 * 24] 0.707
+i 1 0 [60 * 60 * 24] 0.707 ; Turn on instrument 1
</CsScore>
</CsoundSynthesizer>
@@ -4,27 +4,39 @@ import csoundo.*;
ControlP5 controlP5;
Csoundo cs;
-float mod = 1;
-float index = 1;
-
void setup() {
- size(180, 180);
+ size(550, 220);
frameRate(30);
smooth();
controlP5 = new ControlP5(this);
cs = new Csoundo(this, sketchPath("data/synth.csd"));
cs.run();
- cs.setChn("slider_1", mod);
- cs.setChn("slider_2", index);
-
- controlP5.addSlider("mod", 1, 4, mod, 30, 40, 40, 100);
- controlP5.addSlider("index", 0, 3, index, 110, 40, 40, 100);
+
+ // Set default values in Csound chn bus memory
+ cs.setChn("amp", 0.707);
+ cs.setChn("freq", 100);
+ cs.setChn("c", 1.0);
+ cs.setChn("m", 1.0);
+ cs.setChn("index", 1.0);
+ cs.setChn("lfo_amp", 0.0);
+ cs.setChn("lfo_rate", 0.0);
+
+ // Create sliders
+ controlP5.addSlider("amp", 0, 1, 0.707, 40, 40, 40, 120);
+ controlP5.addSlider("freq", 100, 200, 100, 110, 40, 40, 120);
+ controlP5.addSlider("c", 0, 8, 1.0, 180, 40, 40, 120);
+ controlP5.addSlider("m", 0, 8, 1.0, 250, 40, 40, 120);
+ controlP5.addSlider("index", 0, 8, 1.0, 320, 40, 40, 120);
+ controlP5.addSlider("lfo_amp", 0, 1, 0.0, 390, 40, 40, 120);
+ controlP5.addSlider("lfo_rate", 0, 20, 0.0, 470, 40, 40, 120);
}
void draw() {
background(0);
+}
- cs.setChn("slider_1", mod);
- cs.setChn("slider_2", index);
+void controlEvent(ControlEvent e) {
+ // Update chn bus related to ControlEvent
+ cs.setChn(e.controller().name(), e.controller().value());
}

0 comments on commit 37762fc

Please sign in to comment.