From 8a11296652c15bfa951d904d650237b085841270 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 5 May 2017 00:07:52 +0200 Subject: classes/ZZZ.sc: Adding functions to convert from midi to amplitude and back. Removing obsolete comment. --- classes/ZZZ.sc | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/ZZZ.sc b/classes/ZZZ.sc index 662da36..a9f89f7 100644 --- a/classes/ZZZ.sc +++ b/classes/ZZZ.sc @@ -134,11 +134,39 @@ ZZZ{ /** * Calculates frequency for supplied amplitude. - * Wraps call to ampToVAC -> vacToHz * @return frequency for corresponding amplitude */ *ampcps{ arg amplitude; ^this.voltagecps(this.amplitudevoltage(amplitude)); } + + /** + * Calculates amplitude for supplied midi note. + * @return amplitude for corresponding midi note, nil if < 0 or > 127 + */ + *midiamp{ + arg midi; + if((midi < 0 ) || (midi >127), { + ^nil; + },{ + ^this.voltageamplitude(this.cpsvoltage(midi.midicps)); + }); + } + + /** + * Calculates midi note for supplied amplitude. + * @return midi note for corresponding amplitude, nil if amplitude is not + * within the allowed octave range + */ + *ampmidi{ + arg amplitude; + if((amplitude <= ((noteVoltageRangeMin+1)/10)) || (amplitude > (((noteVoltageRangeMax-1)+(1/12*7))/10)), { + ^nil; + },{ + ^this.voltagecps(this.amplitudevoltage(amplitude)).cpsmidi; + }); + } + + } -- cgit v1.2.3-70-g09d2