aboutsummaryrefslogtreecommitdiffstats
path: root/classes/ZZZ.sc
blob: 3f39357d2e70cc77a37cbc978e4863e693512ddd (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
ZZZ{

  classvar <cvMinLFO = -2.5,
  < cvMaxLFO = 2.5,
  < cvMinADSR = 0.0,
  < cvMaxADSR = 8.0,
  < cvMinTriggerGateClock = 0.0,
  < cvMaxTriggerGateClock = 5.0,
  < ampToVACConst = 6.8925;
  var <channels;

  *new{
    arg channels;
    ^super.newCopyArgs(channels).init;
  }

  init{
    ("Using the following channels:").postln;
    channels.postln;
  }

  *initClass{
    StartUp.add{
      //adding synth for percussive environments (trigger, gate, clock)
      SynthDef(\ZZZPerc, { |out = 0, freq = 20000, amp = 0.0, attack = 0.001, release = 1, time = 1, curve = -4|
        var signal, envelope;
        envelope = EnvGen.kr(Env.perc(attack, release, amp, curve),  doneAction: 2);
        signal = SinOsc.ar(freq, 0, envelope);
        Out.ar(out, signal);
      }).add;
      // adding synth for note environments (adsr, v/o)
      SynthDef(\ZZZHold, { |out = 0, freq = 20000, amp = 0.0|
        var signal;
        signal = SinOsc.ar(freq, 0, amp);
        Out.ar(out, signal);
      }).add;
    }
  }

  /**
   * Calculates voltage for supplied amplitude.
   * Linear until ampToVACConst, exponential above.
   * Maximum voltage: 7.68096 VAC
   * @return voltage that corresponds to the amplitude supplied.
   */
  *ampToVAC{
    arg amplitude;
    var voltage;
    if((amplitude <= 1.0), {
      voltage = amplitude * ampToVACConst;
    },{
      voltage = amplitude.lincurve(1.0, 2.5, ampToVACConst, 7.7, -4, nil);
    });
    voltage.postln;
    ^voltage;
  }

  /**
   * Calculates amplitude for supplied voltage.
   * Linear until ampToVACConst.
   * Maximum amplitude output: 2.2
   * @return amplitude needed to achieve the voltage supplied.
   */
  *vacToAmp{
    arg voltage;
    var amplitude;
    if((voltage <= ampToVACConst), {
      amplitude = voltage/ampToVACConst;
    },{
      amplitude = voltage.curvelin(ampToVACConst, 7.7, 1.0, 2.5, -4, \max);
    });
    amplitude.postln;
    ^amplitude;
  }

  /**
   * Calculates voltage for supplied frequency.
   * Frequencies below 27.5Hz will return 0.
   * @return voltage for corresponding frequency
   */
  *hzToVAC{
    arg frequency;
    var voltage;
    if(frequency < 27.5, {
      voltage = 0;
    },{
      voltage = frequency.explin(55, 880, 1.0, 5.0, nil);
    });
    voltage.postln;
    ^voltage;
  }

  /**
   * Calculates frequency for supplied voltage.
   * Voltages below 0 will return 27.5Hz
   * @return frequency for corresponding voltage
   */
  *vacToHz{
    arg voltage;
    var frequency;
    if(voltage < 0, {
      frequency = 27.5;
    },{
      frequency = voltage.linexp(1.0, 5.0, 55, 880, nil);
    });
    frequency.postln;
    ^frequency;
  }

}