From bf373c40eb790016f2591f95d35f3f49840a9acf Mon Sep 17 00:00:00 2001 From: taconi Date: Fri, 24 Jan 2025 13:03:47 -0300 Subject: [PATCH 1/2] Correcting examples of vortex functions --- .../src/pattern_languages/vortex/functions.md | 12 ++++++------ sardine_core/run.py | 2 +- sardine_core/sequences/tidal_parser/control.py | 10 ++++++++++ sardine_core/sequences/tidal_parser/pattern.py | 9 +++++---- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/docs/sardine_doc/src/pattern_languages/vortex/functions.md b/docs/sardine_doc/src/pattern_languages/vortex/functions.md index def14318..7db8b193 100644 --- a/docs/sardine_doc/src/pattern_languages/vortex/functions.md +++ b/docs/sardine_doc/src/pattern_languages/vortex/functions.md @@ -73,13 +73,13 @@ These functions typically take up to **n** patterns to form a single pattern tha - `layer`: Layer up multiple functions on one pattern. For example, the following will play two versions of the pattern at the same time, one reversed and one at twice the speed. ```python - d1 * s("arpy [~ arpy:4]").layer(rev, lambda p: p.fast(2)]) + d1 * s("arpy [~ arpy:4]").layer(rev, lambda p: p.fast(2)) ``` If you want to include the original version of the pattern in the layering, use the `id` function: ```python - d1 * s("arpy [~ arpy:4]").layer(id, rev, lambda p: p.fast(2)]) + d1 * s("arpy [~ arpy:4]").layer(id, rev, lambda p: p.fast(2)) ``` ## Pattern degradation @@ -118,7 +118,7 @@ The `sometimes` family of function can sometimes apply a function to a pattern.. d1 * s('drum(5,8)').n('1 2 3 4').always(fast(2)) ``` -- `almostAlways`: will apply the function 90% of the time, at random. +- `almostAlways` | `almost_always`: will apply the function 90% of the time, at random. ```python d1 * s('drum(5,8)').n('1 2 3 4').almostAlways(fast(2)) @@ -146,7 +146,7 @@ The `sometimes` family of function can sometimes apply a function to a pattern.. d1 * s('drum(5,8)').n('1 2 3 4').rarely(fast(2)) ``` -- `almostNever`: will apply the function 10% of the time, at random. +- `almostNever` | `almost_never`: will apply the function 10% of the time, at random. ```python d1 * s('drum(5,8)').n('1 2 3 4').almostNever(fast(2)) @@ -163,7 +163,7 @@ The `sometimes` family of function can sometimes apply a function to a pattern.. - `every`: allows you to apply a function based on a condition. You need a function to determine when the function should be applied (*e.g.* a number **n** to apply the function every **n** cycles). You also need a transformation such as `rev` (reverse a pattern) or `fast` (make a pattern faster). ```python - d1 * s('[bd(5,8), jvbass(3,8)]').every(3, lambda p: p.superimpose(fast 2)) + d1 * s('[bd(5,8), jvbass(3,8)]').every(3, lambda p: p.superimpose(fast(2))) ``` - `somecycles`: Apply a function on certain cycles (*e.g* on cycle `3`) ??? @@ -325,7 +325,7 @@ Signal functions are functions generating streams of values to apply to a patter - `run` - `scan` -- `choosewith` +- `choose_with` - `choose` - `choose_cycles` - `wchoose` diff --git a/sardine_core/run.py b/sardine_core/run.py index f5306d74..4fe76f74 100644 --- a/sardine_core/run.py +++ b/sardine_core/run.py @@ -105,7 +105,7 @@ player_names.remove("SC") # NOTE: used by SuperCollider command player_names.remove("PC") # NOTE: used by MIDI Program Change # player_names += [''.join(tup) for tup in list(product(ascii_lowercase, repeat=3))] -for player in player_names: +for player in filter(lambda p: p not in ['id'], player_names): p = Player(name=player) globals()[player] = p bowl.add_handler(p) diff --git a/sardine_core/sequences/tidal_parser/control.py b/sardine_core/sequences/tidal_parser/control.py index 47072f6c..b867be92 100644 --- a/sardine_core/sequences/tidal_parser/control.py +++ b/sardine_core/sequences/tidal_parser/control.py @@ -110,6 +110,11 @@ "hcutoff", "a pattern of numbers from 0 to 1. Applies the cutoff frequency of the high-pass filter. Also has alias @hpf@", ), + ( + "f", + "hpf", + "a pattern of numbers from 0 to 1. Applies the cutoff frequency of the high-pass filter.", + ), ( "f", "hold", @@ -120,6 +125,11 @@ "hresonance", "a pattern of numbers from 0 to 1. Applies the resonance of the high-pass filter. Has alias @hpq@", ), + ( + "f", + "hpq", + "a pattern of numbers from 0 to 1. Applies the resonance of the high-pass filter.", + ), ("f", "lagogo", ""), ("f", "lclap", ""), ("f", "lclaves", ""), diff --git a/sardine_core/sequences/tidal_parser/pattern.py b/sardine_core/sequences/tidal_parser/pattern.py index 08e0f60f..a822e589 100644 --- a/sardine_core/sequences/tidal_parser/pattern.py +++ b/sardine_core/sequences/tidal_parser/pattern.py @@ -810,21 +810,22 @@ def sometimes(self, func): def always(self, func): return self.sometimes_by(1.0, func) - def always(self, func): - return self.sometimes_by(1.0, func) - def almost_always(self, func): return self.sometimes_by(0.9, func) + almostAlways = almost_always + def often(self, func): return self.sometimes_by(0.75, func) def rarely(self, func): return self.sometimes_by(0.25, func) - def almostNever(self, func): + def almost_never(self, func): return self.sometimes_by(0.10, func) + almostNever = almost_never + def never(self, func): return self.sometimes_by(0.0, func) From 70670048c3628ad09b97c706df23186fdc0ebc30 Mon Sep 17 00:00:00 2001 From: taconi Date: Fri, 24 Jan 2025 20:04:48 -0300 Subject: [PATCH 2/2] Adjusting the `hush` function to work with documentation examples --- .../sequences/tidal_parser/__init__.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/sardine_core/sequences/tidal_parser/__init__.py b/sardine_core/sequences/tidal_parser/__init__.py index d4cb6dc6..bff225ea 100644 --- a/sardine_core/sequences/tidal_parser/__init__.py +++ b/sardine_core/sequences/tidal_parser/__init__.py @@ -28,12 +28,33 @@ def tidal(key, pattern=None, data_only: bool = False): def hush_factory(env, osc_client, tidal_players): - def hush(): + def _hush_all(): for stream in __streams.values(): stream.pattern = silence tidal_players.remove(stream) __streams.clear() + def _hush(pat): + streams = ( + (n, s) for n, s in __streams.items() if pat in [n, s.name] + ) + name, stream = next(streams, (None, None)) + if not stream: + raise TypeError(f'Stream "{pat}" not found') + + stream.pattern = silence + tidal_players.remove(stream) + __streams.pop(name) + + def hush(pat=None): + if pat is None: + return _hush_all() + if isinstance(pat, str): + return _hush(pat) + if not hasattr(pat, 'name') or not isinstance(pat.name, str): + raise TypeError(f'Object of type {type(pat)} is not recognized') + _hush(pat.name) + return hush