[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-dev] proposal: curverange



i found myself using a lot of curved mappings, but the UGen-curverange
method (like range and exprange) seems to be missing, which is a bit
inconsistent ...

any objections to add them?

tim
From 6ab0fecc62435e992eb54a5e8889a62a2c9abef1 Mon Sep 17 00:00:00 2001
Message-Id: <6ab0fecc62435e992eb54a5e8889a62a2c9abef1.1357483217.git.tim@xxxxxxxxxx>
From: Tim Blechmann <tim@xxxxxxxxxx>
Date: Sun, 6 Jan 2013 13:10:50 +0100
Subject: [PATCH] class library: introduce curverange method

introduce curverange similar to range and exprange

Signed-off-by: Tim Blechmann <tim@xxxxxxxxxx>
---
 HelpSource/Classes/Env.schelp                               |  5 +++--
 HelpSource/Classes/UGen.schelp                              | 11 +++++++++++
 SCClassLibrary/Common/Audio/Env.sc                          |  4 ++++
 SCClassLibrary/Common/Audio/UGen.sc                         |  8 ++++++++
 SCClassLibrary/Common/Collections/SequenceableCollection.sc |  1 +
 5 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/HelpSource/Classes/Env.schelp b/HelpSource/Classes/Env.schelp
index 6e39714..ed69a34 100644
--- a/HelpSource/Classes/Env.schelp
+++ b/HelpSource/Classes/Env.schelp
@@ -564,14 +564,15 @@ Converts the Env to an link::Classes/Array:: in a specially ordered format, like
 method::isSustained
 Returns true if this is a sustaining envelope, false otherwise.
 
-method::range, exprange
-Returns a copy of the Env whose levels have been mapped onto the given linear or exponential range.
+method::range, exprange, curverange
+Returns a copy of the Env whose levels have been mapped onto the given linear, exponential or curve range.
 discussion::
 code::
 a = Env.adsr;
 a.levels;
 a.range(42, 45).levels;
 a.exprange(42, 45).levels;
+a.curverange(42, 45, -4).levels;
 
 (
 // Mapping an Env to an exponential frequency range:
diff --git a/HelpSource/Classes/UGen.schelp b/HelpSource/Classes/UGen.schelp
index b6aaaac..b8de240 100644
--- a/HelpSource/Classes/UGen.schelp
+++ b/HelpSource/Classes/UGen.schelp
@@ -135,6 +135,17 @@ code::
 { SinOsc.ar(SinOsc.ar(0.3).exprange(440, 6600), 0, 0.5) * 0.1 }.play;
 ::
 
+method:: curverange
+
+Scales the output of this UGen to be within the range of code::lo:: and code::hi:: using a curve factor of code::curve::.
+discussion::
+Note that code::curverange:: expects the default output range, and thus should not be used in conjunction with mul and add arguments.
+code::
+{ SinOsc.ar(SinOsc.ar(0.3).range(440, 660), 0, 0.5) * 0.1 }.play;
+::
+
+
+
 method:: unipolar
 
 Scales the output of this UGen to be between code::(0..mul):: range (default 1).
diff --git a/SCClassLibrary/Common/Audio/Env.sc b/SCClassLibrary/Common/Audio/Env.sc
index 7d13fec..49f955c 100644
--- a/SCClassLibrary/Common/Audio/Env.sc
+++ b/SCClassLibrary/Common/Audio/Env.sc
@@ -91,6 +91,10 @@ Env {
 		^this.copy.levels_(levels.linexp(levels.minItem, levels.maxItem, lo, hi))
 	}
 
+	curverange { arg lo = 0.01, hi = 1.0, curve = -4;
+		^this.copy.levels_(levels.lincurve(levels.minItem, levels.maxItem, lo, hi, curve))
+	}
+
 	// methods to make some typical shapes :
 
 	// fixed duration envelopes
diff --git a/SCClassLibrary/Common/Audio/UGen.sc b/SCClassLibrary/Common/Audio/UGen.sc
index c5217b6..92bdf61 100644
--- a/SCClassLibrary/Common/Audio/UGen.sc
+++ b/SCClassLibrary/Common/Audio/UGen.sc
@@ -127,6 +127,14 @@ UGen : AbstractFunction {
 		};
  	}
 
+	curverange { arg lo = 0.00, hi = 1.0, curve = -4;
+		^if (this.signalRange == \bipolar) {
+			this.lincurve(-1, 1, lo, hi, curve, nil)
+		} {
+			this.lincurve(0, 1, lo, hi, curve, nil)
+		};
+	}
+
  	unipolar { arg mul = 1;
  		^this.range(0, mul)
  	}
diff --git a/SCClassLibrary/Common/Collections/SequenceableCollection.sc b/SCClassLibrary/Common/Collections/SequenceableCollection.sc
index c20b805..aa57e3d 100644
--- a/SCClassLibrary/Common/Collections/SequenceableCollection.sc
+++ b/SCClassLibrary/Common/Collections/SequenceableCollection.sc
@@ -920,6 +920,7 @@ SequenceableCollection : Collection {
 	biexp { arg ... args; ^this.multiChannelPerform('biexp', *args) }
 	range { arg ... args; ^this.multiChannelPerform('range', *args) }
 	exprange { arg ... args; ^this.multiChannelPerform('exprange', *args) }
+	curverange { arg ... args; ^this.multiChannelPerform('curverange', *args) }
 	unipolar { arg ... args; ^this.multiChannelPerform('unipolar', *args) }
 	bipolar { arg ... args; ^this.multiChannelPerform('bipolar', *args) }
 	lag { arg ... args; ^this.multiChannelPerform('lag', *args) }
-- 
1.8.0.3