Skip to content

Commit

Permalink
Add keepdot and filtdot operators
Browse files Browse the repository at this point in the history
  • Loading branch information
ssidorenko committed Nov 3, 2023
1 parent cfbb800 commit 79923db
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

There is a group of functions used for filtering: removing events, filtering values, etc... These functions are very low-level but they can be really interesting for specific use cases.

## mask
## mask


Apply a boolean mask on values from the collection. True values will return the value itself, others will return a silence. This function is used by others for many different operations.
Expand Down Expand Up @@ -43,3 +43,33 @@ This function can be used to filter some values from a pattern. Imagine generati
# Removing 2 and 4 from the generated ramp
Pa * d('hat', p=.25, speed='(filter [0:10] [2 4])')
```


## filtdot

This function can be used to filter out some values from a pattern, replacing them with silences (.).

**Arguments:**
- **collection:** the collection you would like to filter.
- **filter:** a list containing the elements to filter

**Example:**
```python
# Replacing 2 and 4 By silences
Pa * d('hat', p=.25, speed='(filtdot [0:10] [2 4])') # Equivalent to speed='0 1 . 3 . 5 6 7 8 9 10'
```


## keepdot

This function does the opposite of filtdot: only the values that are in the given filter are kept.

**Arguments:**
- **collection:** the collection you would like to filter.
- **filter:** a list containing the elements to keep

**Example:**
```python
# Replacing 2 and 4 By silences
Pa * d('hat', p=.25, speed='(keepdot [0:10] [2 4])') # Equivalent to speed='. . 2 . 4 . . . . . .'
```
6 changes: 6 additions & 0 deletions sardine_core/sequences/sardine_parser/funclib.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ def notdot(self, collection: list) -> list:
"""Invert a rhythm pattern (1 -> ., . -> 1)"""
return [1 if x == None else None for x in collection]

def filtdot(self, collection: list, filter_: list) -> list:
return [x if x not in filter_ else None for x in collection]

def keepdot(self, collection: list, keep_: list) -> list:
return [x if x in keep_ else None for x in collection]

def clamp(
self,
collection: list,
Expand Down
2 changes: 2 additions & 0 deletions sardine_core/sequences/sardine_parser/tree_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ def function_call(self, func_name, *args):
"neu": self.library.negative_euclidian_rhythm,
"mask": self.library.mask,
"notdot": self.library.notdot,
"filtdot": self.library.filtdot,
"keepdot": self.library.keepdot,
"euclid": self.library.euclidian_to_number,
"numclid": self.library.euclidian_to_number,
"e": self.library.euclidian_to_number,
Expand Down

0 comments on commit 79923db

Please sign in to comment.