Skip to content

Commit

Permalink
PDict: Add __getattr__ syntactical sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Sep 15, 2024
1 parent 453aa28 commit 79718e5
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion isobar/pattern/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import annotations
import copy
import inspect
from typing import Iterable, Callable, TYPE_CHECKING
from typing import Iterable, Callable, Any, TYPE_CHECKING
from ..timelines.lfo import LFO

import isobar
Expand Down Expand Up @@ -417,6 +417,22 @@ def __init__(self, value: dict = None):
except IndexError:
pass

def __getattr__(self, key: str):
"""
Implemented for syntactical sugar, so that a track's params property
can be modified by doing (e.g.) track.params.cutoff = 200
"""
if key == "dict":
return super().__getattr__(key)
else:
return self.dict[key]

def __setattr__(self, key: str, value: Any):
if key == "dict":
return super().__setattr__(key, value)
else:
self.dict[key] = value

def __repr__(self):
return ("PDict(%s)" % repr(self.dict))

Expand Down

0 comments on commit 79718e5

Please sign in to comment.