Skip to content

Commit

Permalink
Documenting UGens
Browse files Browse the repository at this point in the history
  • Loading branch information
josephine-wolf-oberholtzer committed May 1, 2024
1 parent 541bd82 commit 1cabed9
Showing 1 changed file with 211 additions and 0 deletions.
211 changes: 211 additions & 0 deletions supriya/ugens/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4520,6 +4520,10 @@ def wrap2(self, expr: "UGenRecursiveInput") -> "UGenOperable":


class UGenScalar(UGenOperable):
"""
A UGen scalar.
"""

pass


Expand Down Expand Up @@ -4618,16 +4622,223 @@ def __repr__(self) -> str:
return f"<{type(self).__name__}([{', '.join(repr(x) for x in self)}])>"

def flatten(self) -> UGenOperable:
"""
Flatten UGen vector.
::
>>> from supriya.ugens import Pan2, SinOsc
>>> vector = Pan2.ar(source=Pan2.ar(source=SinOsc.ar(frequency=[440, 443])))
>>> supriya.graph(vector) # doctest: +SKIP
>>> print(repr(vector))
<UGenVector([<UGenVector([<Pan2.ar()>, <Pan2.ar()>])>, <UGenVector([<Pan2.ar()>, <Pan2.ar()>])>])>
::
>>> result = vector.flatten()
>>> print(repr(result))
<UGenVector([<Pan2.ar()[0]>, <Pan2.ar()[1]>, <Pan2.ar()[0]>, <Pan2.ar()[1]>, <Pan2.ar()[0]>, <Pan2.ar()[1]>, <Pan2.ar()[0]>, <Pan2.ar()[1]>])>
"""
if len(vector := UGenVector(*flatten(self))) == 1:
return vector[0]
return vector

def mix(self, channel_count: int = 1) -> UGenOperable:
"""
Mix UGen vector down to ``channel_count`` outputs.
::
>>> from supriya.ugens import Pan2, SinOsc
>>> vector = Pan2.ar(source=Pan2.ar(source=SinOsc.ar(frequency=[440, 443])))
>>> supriya.graph(vector) # doctest: +SKIP
>>> print(vector)
synthdef:
name: ...
ugens:
- SinOsc.ar/0:
frequency: 440.0
phase: 0.0
- Pan2.ar/0:
source: SinOsc.ar/0[0]
position: 0.0
level: 1.0
- Pan2.ar/1:
source: Pan2.ar/0[0]
position: 0.0
level: 1.0
- Pan2.ar/2:
source: Pan2.ar/0[1]
position: 0.0
level: 1.0
- SinOsc.ar/1:
frequency: 443.0
phase: 0.0
- Pan2.ar/3:
source: SinOsc.ar/1[0]
position: 0.0
level: 1.0
- Pan2.ar/4:
source: Pan2.ar/3[0]
position: 0.0
level: 1.0
- Pan2.ar/5:
source: Pan2.ar/3[1]
position: 0.0
level: 1.0
::
>>> result = vector.mix(2)
>>> supriya.graph(result) # doctest: +SKIP
>>> print(result)
synthdef:
name: ...
ugens:
- SinOsc.ar/0:
frequency: 440.0
phase: 0.0
- Pan2.ar/0:
source: SinOsc.ar/0[0]
position: 0.0
level: 1.0
- Pan2.ar/1:
source: Pan2.ar/0[0]
position: 0.0
level: 1.0
- Pan2.ar/2:
source: Pan2.ar/0[1]
position: 0.0
level: 1.0
- SinOsc.ar/1:
frequency: 443.0
phase: 0.0
- Pan2.ar/3:
source: SinOsc.ar/1[0]
position: 0.0
level: 1.0
- Pan2.ar/4:
source: Pan2.ar/3[0]
position: 0.0
level: 1.0
- Pan2.ar/5:
source: Pan2.ar/3[1]
position: 0.0
level: 1.0
- Sum4.ar/0:
input_one: Pan2.ar/1[0]
input_two: Pan2.ar/2[0]
input_three: Pan2.ar/4[0]
input_four: Pan2.ar/5[0]
- Sum4.ar/1:
input_one: Pan2.ar/1[1]
input_two: Pan2.ar/2[1]
input_three: Pan2.ar/4[1]
input_four: Pan2.ar/5[1]
"""
from . import Mix

return Mix.multichannel(self, channel_count=channel_count)

def sum(self) -> UGenOperable:
"""
Sum UGen vector down to a single output.
::
>>> from supriya.ugens import Pan2, SinOsc
>>> vector = Pan2.ar(source=Pan2.ar(source=SinOsc.ar(frequency=[440, 443])))
>>> supriya.graph(vector) # doctest: +SKIP
>>> print(vector)
synthdef:
name: ...
ugens:
- SinOsc.ar/0:
frequency: 440.0
phase: 0.0
- Pan2.ar/0:
source: SinOsc.ar/0[0]
position: 0.0
level: 1.0
- Pan2.ar/1:
source: Pan2.ar/0[0]
position: 0.0
level: 1.0
- Pan2.ar/2:
source: Pan2.ar/0[1]
position: 0.0
level: 1.0
- SinOsc.ar/1:
frequency: 443.0
phase: 0.0
- Pan2.ar/3:
source: SinOsc.ar/1[0]
position: 0.0
level: 1.0
- Pan2.ar/4:
source: Pan2.ar/3[0]
position: 0.0
level: 1.0
- Pan2.ar/5:
source: Pan2.ar/3[1]
position: 0.0
level: 1.0
::
>>> result = vector.sum()
>>> supriya.graph(result) # doctest: +SKIP
>>> print(result)
synthdef:
name: ...
ugens:
- SinOsc.ar/0:
frequency: 440.0
phase: 0.0
- Pan2.ar/0:
source: SinOsc.ar/0[0]
position: 0.0
level: 1.0
- Pan2.ar/1:
source: Pan2.ar/0[0]
position: 0.0
level: 1.0
- Pan2.ar/2:
source: Pan2.ar/0[1]
position: 0.0
level: 1.0
- Sum4.ar/0:
input_one: Pan2.ar/1[0]
input_two: Pan2.ar/1[1]
input_three: Pan2.ar/2[0]
input_four: Pan2.ar/2[1]
- SinOsc.ar/1:
frequency: 443.0
phase: 0.0
- Pan2.ar/3:
source: SinOsc.ar/1[0]
position: 0.0
level: 1.0
- Pan2.ar/4:
source: Pan2.ar/3[0]
position: 0.0
level: 1.0
- Pan2.ar/5:
source: Pan2.ar/3[1]
position: 0.0
level: 1.0
- Sum4.ar/1:
input_one: Pan2.ar/4[0]
input_two: Pan2.ar/4[1]
input_three: Pan2.ar/5[0]
input_four: Pan2.ar/5[1]
- BinaryOpUGen(ADDITION).ar:
left: Sum4.ar/0[0]
right: Sum4.ar/1[0]
"""
from . import Mix

return Mix.new(self)
Expand Down

0 comments on commit 1cabed9

Please sign in to comment.