aboutsummaryrefslogtreecommitdiff
path: root/samples/SuperCollider/BCR2000.sc
blob: f8f96a709e55f9bf4ca713b4acc00480435cba17 (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
BCR2000 {
  var controls,
      controlBuses,
      rangedControlBuses,
      responders
  ;

  *new {
    ^super.new.init;
  }
    
  init {
    controls = Dictionary.new(108);
    controlBuses = Dictionary.new(108);
    rangedControlBuses = Dictionary.new(108);

    this.createCCResponders;
  }

  createCCResponders {
    responders = Array.fill(108, {|i|
      CCResponder({|src, chan, num, val|
        [src, chan, num, val].postln;

        // Write to controls 
        controls.put(i + 1, val);

        // Write to bus (converted to scalar 0..1)
        controlBuses.put(i + 1, Bus.control(Server.default));
        controlBuses.at(i + 1).value = val / 127;
      },
        // Adjust values as/if needed
        nil, // src
        nil, // chan
        nil, // num
        nil  // value    
      )
    });
  }

  // Value from BCR
  at {arg controlNum;
    ^controls.at(controlNum)
  }

  // Convert to 0..1
  scalarAt {arg controlNum; 
    ^controls.at(controlNum) / 127
  }

  // Get a bus
  busAt {arg controlNum;
    ^controlBuses.at(controlNum)
  }

  /*
  busRangeAt(arg controlNum, lo, hi;
    if (rangedControlBuses.at(controlNum).isNil, {
      rangedControlBuses.put(controlNum, Bus.control(Server.default))
    }); 
   
    // Left to right order of operations
    //rangedControlBuses.put(
    bus.value = hi - lo * controls.at(controlNum) + lo;

    ^bus
  }
  */
}

/* Scratch
Dictionary
b = BCR2000();
b.at(4);
b.scalarAt(4);
b.controls[5].get;
throw
z = Dictionary.new(2);
z.at(\1);
Array.fill(10, {|i| i.postln;})
(2 + 3).asSymbol;


SynthDef(\x, {
  arg amp = 0.01,
      freq = 1200,
      modDepth = 0.7,
      modFreq = 2
  ;

  var
    carrier,
    modulator   
  ;

  modulator = SinOsc.ar(modFreq, mul: modDepth);
  carrier = Saw.ar(freq, add: modulator, mul: amp);

  Out.ar([0,1], carrier)
}).store; 


x = Synth(\x);
x.set(\modDepth, 1);
x.set(\modFreq, 64); 

x.map(\modFreq, b.busAt(       



ControlSpec
*/