Skip to content

Commit

Permalink
Tinkering
Browse files Browse the repository at this point in the history
  • Loading branch information
josephine-wolf-oberholtzer committed Apr 30, 2024
1 parent a756bea commit 541bd82
Showing 1 changed file with 49 additions and 45 deletions.
94 changes: 49 additions & 45 deletions supriya/ugens/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2459,6 +2459,48 @@ def distort(self) -> "UGenOperable":
float_operator=lambda x: x / (1 + abs(x)),
)

def exceeds(self, expr: "UGenRecursiveInput") -> "UGenOperable":
"""
Threshold UGen graph by ``expr``.
- 0 when a < b, otherwise a
Equivalent to sclang's ``threshold`` method, but renamed due to name
conflicts with many UGen parameters.
::
>>> from supriya.ugens import SinOsc, WhiteNoise
>>> ugen_graph = SinOsc.ar(frequency=[440, 443])
>>> expr = WhiteNoise.kr()
>>> result = ugen_graph.exceeds(expr)
>>> supriya.graph(result) # doctest: +SKIP
>>> print(result)
synthdef:
name: ...
ugens:
- SinOsc.ar/0:
frequency: 440.0
phase: 0.0
- WhiteNoise.kr: null
- BinaryOpUGen(THRESHOLD).ar/0:
left: SinOsc.ar/0[0]
right: WhiteNoise.kr[0]
- SinOsc.ar/1:
frequency: 443.0
phase: 0.0
- BinaryOpUGen(THRESHOLD).ar/1:
left: SinOsc.ar/1[0]
right: WhiteNoise.kr[0]
"""
return _compute_binary_op(
left=self,
right=expr,
special_index=BinaryOperator.THRESHOLD,
float_operator=lambda a, b: 0.0 if a < b else a,
)

def exponential_rand_range(self, expr: "UGenRecursiveInput") -> "UGenOperable":
"""
Compute an exponentially-distributed random number in the interval of UGen graph to ``expr``.
Expand Down Expand Up @@ -4074,7 +4116,7 @@ def square_of_sum(self, expr: "UGenRecursiveInput") -> "UGenOperable":
>>> from supriya.ugens import SinOsc, WhiteNoise
>>> ugen_graph = SinOsc.ar(frequency=[440, 443])
>>> expr = WhiteNoise.kr()
>>> result = ugen_graph.sum_of_squares(expr)
>>> result = ugen_graph.square_of_sum(expr)
>>> supriya.graph(result) # doctest: +SKIP
>>> print(result)
synthdef:
Expand All @@ -4084,13 +4126,13 @@ def square_of_sum(self, expr: "UGenRecursiveInput") -> "UGenOperable":
frequency: 440.0
phase: 0.0
- WhiteNoise.kr: null
- BinaryOpUGen(SUM_OF_SQUARES).ar/0:
- BinaryOpUGen(SQUARE_OF_SUM).ar/0:
left: SinOsc.ar/0[0]
right: WhiteNoise.kr[0]
- SinOsc.ar/1:
frequency: 443.0
phase: 0.0
- BinaryOpUGen(SUM_OF_SQUARES).ar/1:
- BinaryOpUGen(SQUARE_OF_SUM).ar/1:
left: SinOsc.ar/1[0]
right: WhiteNoise.kr[0]
Expand Down Expand Up @@ -4212,7 +4254,7 @@ def tanh(self) -> "UGenOperable":
>>> from supriya.ugens import SinOsc
>>> ugen_graph = SinOsc.ar(frequency=[440, 443])
>>> result = ugen_graph.tan()
>>> result = ugen_graph.tanh()
>>> supriya.graph(result) # doctest: +SKIP
>>> print(result)
synthdef:
Expand All @@ -4221,12 +4263,12 @@ def tanh(self) -> "UGenOperable":
- SinOsc.ar/0:
frequency: 440.0
phase: 0.0
- UnaryOpUGen(TAN).ar/0:
- UnaryOpUGen(TANH).ar/0:
source: SinOsc.ar/0[0]
- SinOsc.ar/1:
frequency: 443.0
phase: 0.0
- UnaryOpUGen(TAN).ar/1:
- UnaryOpUGen(TANH).ar/1:
source: SinOsc.ar/1[0]
"""
Expand All @@ -4236,44 +4278,6 @@ def tanh(self) -> "UGenOperable":
float_operator=math.tanh,
)

def threshold(self, expr: "UGenRecursiveInput") -> "UGenOperable":
"""
Threshold UGen graph by ``expr``.
- 0 when a < b, otherwise a
::
>>> from supriya.ugens import SinOsc, WhiteNoise
>>> ugen_graph = SinOsc.ar(frequency=[440, 443])
>>> expr = WhiteNoise.kr()
>>> result = ugen_graph.threshold(expr)
>>> supriya.graph(result) # doctest: +SKIP
>>> print(result)
synthdef:
name: ...
ugens:
- SinOsc.ar/0:
frequency: 440.0
phase: 0.0
- WhiteNoise.kr: null
- BinaryOpUGen(THRESHOLD).ar/0:
left: SinOsc.ar/0[0]
right: WhiteNoise.kr[0]
- SinOsc.ar/1:
frequency: 443.0
phase: 0.0
- BinaryOpUGen(THRESHOLD).ar/1:
left: SinOsc.ar/1[0]
right: WhiteNoise.kr[0]
"""
return _compute_binary_op(
left=self,
right=expr,
special_index=BinaryOperator.THRESHOLD,
)

def through(self) -> "UGenOperable":
"""
Pass through UGen graph.
Expand Down Expand Up @@ -4636,7 +4640,7 @@ class UGenSerializable(Protocol):
"""

def serialize(self, **kwargs) -> UGenVector:
pass
raise NotImplementedError


class UGen(UGenOperable, Sequence):
Expand Down

0 comments on commit 541bd82

Please sign in to comment.