diff options
author | David Runge <dave@sleepmap.de> | 2017-05-05 00:07:52 +0200 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2017-05-05 00:07:52 +0200 |
commit | 8a11296652c15bfa951d904d650237b085841270 (patch) | |
tree | fc565895b7a60aa2466e48935ce833173bcd34f2 | |
parent | 86ad8e493d6c4ca8dbcdd93407686118e4f109e8 (diff) | |
download | zzz-8a11296652c15bfa951d904d650237b085841270.tar.gz zzz-8a11296652c15bfa951d904d650237b085841270.tar.bz2 zzz-8a11296652c15bfa951d904d650237b085841270.tar.xz zzz-8a11296652c15bfa951d904d650237b085841270.zip |
classes/ZZZ.sc: Adding functions to convert from midi to amplitude and back. Removing obsolete comment.
-rw-r--r-- | classes/ZZZ.sc | 30 |
1 files changed, 29 insertions, 1 deletions
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; + }); + } + + } |