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 115 116 117 118 119 120 121 122 123
|
/*
* BELAUGens to access the analog and digital I/O
* created by nescivi, (c) 2016
* https://www.nescivi.eu
*/
/* input: id of analog pin to read; can be modulated at audiorate
* output: value of analog analogPin
*/
MultiplexAnalogIn : UGen {
signalRange { ^\unipolar }
*ar { arg analogPin = 0, muxChannel = 0, mul = 1.0, add = 0.0;
^this.multiNew('audio', analogPin, muxChannel).madd(mul,add)
}
*kr { arg analogPin = 0, muxChannel = 0, mul = 1.0, add = 0.0;
^this.multiNew('control', analogPin, muxChannel).madd(mul,add)
}
}
/* input: id of analog pin to read; can be modulated at audiorate
* output: value of analog analogPin
*/
AnalogIn : UGen {
signalRange { ^\unipolar }
*ar { arg analogPin = 0, mul = 1.0, add = 0.0;
^this.multiNew('audio', analogPin).madd(mul,add)
}
*kr { arg analogPin = 0, mul = 1.0, add = 0.0;
^this.multiNew('control', analogPin).madd(mul,add)
}
}
/* input 1: id of analog pin to read; can be modulated at audiorate
* input 2: value to write out
* output: none
*/
AnalogOut : UGen {
*ar { arg analogPin = 0, output = 0, mul = 1.0, add = 0.0;
this.multiNew('audio', analogPin, output).madd(mul,add);
^0.0;
}
*kr { arg analogPin = 0, output = 0, mul = 1.0, add = 0.0;
this.multiNew('control', analogPin, output).madd(mul,add);
^0.0;
}
numOutputs { ^0 }
writeOutputSpecs {}
}
/* input: id of digital pin to read; cannot be modulated
* output: value of digital pin
*/
DigitalIn : UGen {
signalRange { ^\unipolar }
*ar { arg digitalPin = 0, mul = 1.0, add = 0.0;
^this.multiNew('audio', digitalPin).madd(mul,add)
}
*kr { arg digitalPin = 0, mul = 1.0, add = 0.0;
^this.multiNew('control', digitalPin).madd(mul,add)
}
}
/* input 1: id of digital pin to read; cannot be modulated
* input 2: value to write out
* output: none
*/
DigitalOut : UGen {
*ar { arg digitalPin = 0, output = 0, mul = 1.0, add = 0.0;
this.multiNew('audio', digitalPin, output).madd(mul,add);
^0.0;
}
*kr { arg digitalPin = 0, output = 0, mul = 1.0, add = 0.0;
this.multiNew('control', digitalPin, output).madd(mul,add);
^0.0;
}
numOutputs { ^0 }
writeOutputSpecs {}
}
/* input 1: id of digital pin to read; cannot be modulated
* input 2: value to write out
* input 3: pin mode ( < 0.5 = input, otherwise output)
* output: value of digital pin (last read value)
*/
DigitalIO : UGen {
signalRange { ^\unipolar }
*ar { arg digitalPin = 0, output = 0, pinMode = 0, mul = 1.0, add = 0.0;
^this.multiNew('audio', digitalPin, output, pinMode).madd(mul,add)
}
*kr { arg digitalPin = 0, output = 0, pinMode = 0, mul = 1.0, add = 0.0;
^this.multiNew('control', digitalPin, output, pinMode).madd(mul,add)
}
}
/* input 1: channel offset
* input 2: array of signals to scope
*/
BelaScopeOut : AbstractOut {
*ar {
arg offset = 0, channelsArray;
channelsArray = this.replaceZeroesWithSilence(channelsArray.asUGenInput(this).asArray);
this.multiNewList(['audio', offset] ++ channelsArray)
^0.0
}
*numFixedArgs { ^1 }
writesToBus { ^false }
checkValidInputs {
var valid = super.checkValidInputs;
var channelOffset = inputs.first;
valid !? { ^valid };
if(channelOffset.isNumber and: { channelOffset >= 0 }) {
^nil;
};
^"arg: channelOffset must be a positive number, but % is provided.".format(channelOffset);
}
}
|