Skip to content

Instantly share code, notes, and snippets.

@audionerd
Last active December 15, 2015 12:29
Show Gist options
  • Save audionerd/5260402 to your computer and use it in GitHub Desktop.
Save audionerd/5260402 to your computer and use it in GitHub Desktop.
SuperCollider's SequenceableCollection blend, blendAt in CoffeeScript
# SuperCollider's SequenceableCollection blend, blendAt in CoffeeScript
# SEE ALSO:
# https://github.com/supercollider/supercollider/blob/master/SCClassLibrary/Common/Core/Object.sc
# http://danielnouri.org/docs/SuperColliderHelp/Collections/SequenceableCollection.html
# http://coleingraham.com/2012/12/31/notes-between-chromatic-just-intonation/
# http://mohayonao.github.com/subcollider.js/
class ArrayUtil
# via https://github.com/supercollider/supercollider/blob/master/SCClassLibrary/Common/Core/Object.sc
@blendAt: (array, index) ->
return array[0] if index <= 0
return array[array.length - 1] if index >= array.length - 1
iMin = Math.ceil(index) - 1
return MathUtil.blend(array[iMin], array[iMin + 1], Math.abs(index - iMin))
class MathUtil
@scale: (value, lo, hi) ->
(value * (hi - lo)) + lo
@clamp: (v, min, max) ->
Math.min(Math.max(v, min), max)
# via https://github.com/supercollider/supercollider/blob/master/SCClassLibrary/Common/Core/Object.sc
@blend: (a, b, blendFrac = 0.5) ->
a + (blendFrac * (b - a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment