Skip to content

Instantly share code, notes, and snippets.

View arseniiv's full-sized avatar
🌜

Arsenii A. arseniiv

🌜
View GitHub Profile
@arseniiv
arseniiv / continued_fraction.py
Created March 26, 2024 22:48
Continued fractions, incl. handling quadratic surds
"""
Reference implementation of continued fraction routines
by 0.5°.
"""
from __future__ import annotations
from dataclasses import InitVar, dataclass
from itertools import pairwise
from math import floor, inf, isinf, isnan, isqrt, lcm, sqrt
from typing import Iterable, Iterator, Literal, Sequence, overload
@arseniiv
arseniiv / blackjack.py
Last active March 20, 2024 21:42
Comparing simple strategies of playing one-suit black jack with individual decks for each player
from __future__ import annotations
from collections import defaultdict
from dataclasses import dataclass
from fractions import Fraction
from typing import Callable, Final, Iterable, Iterator
@dataclass(frozen=True, slots=True)
class Prob[TDom, TProb: (float, Fraction)]:
"""Probability monad."""
@arseniiv
arseniiv / guide.md
Last active March 14, 2024 20:44
a partial tuneBfree guide

Doing stuff with tuneBfree

tuneBfree is naren’s fork of a setBfree tonewheel organ emulation that allows custom tuning using MTS-ESP. It being one of the first microtunable tonewheel organ synths, I thought it might be useful to write a quick post of what one might wish to consider or have in mind tuning it.

MTS-ESP connection basics

An MTS-ESP master plugin like MTS-ESP Mini should be present in your project somewhere. It can be in passthru mode to conserve resources; the only thing you need to be sure of is that it says that a client is connected. If tuneBfree is the sole MTS-ESP-aware plugin in there, that’s it! Load a tuning and it will apply immediately.

Note that hosts like Carla or Element, as far I was able to work them, don’t allow MTS-ESP connection. Either I didn’t do something crucial or you need another more diversely functional DAW.

@arseniiv
arseniiv / subdivide_scale_best.py
Created February 18, 2024 23:25
Sorting subdivided scales by avg variety, filtering out rotated variants
from __future__ import annotations
from collections import defaultdict
from typing import Final, Iterable, Iterator, Mapping, Sequence
import operator
from dataclasses import dataclass
from itertools import accumulate, permutations, product
from math import prod
from fractions import Fraction as F
def avg_variety(scale_steps: Sequence[F]) -> float:
@arseniiv
arseniiv / edo_confluence.py
Created December 27, 2023 18:59
List intervals in various edo/edX scales that are close to each other
from collections import defaultdict
from dataclasses import dataclass
from fractions import Fraction
from itertools import pairwise
from typing import Final, Sequence
@dataclass
class EdIntervals:
ed_fractions: list[Fraction]
sources: dict[Fraction, list[int]]
@arseniiv
arseniiv / scale_approx.py
Created December 23, 2023 19:43
Approximate a scale with a periodic scale with specific step pattern
"""
Fitting a scale to have a given pattern of steps between notes.
Install `sympy` and `more_itertools`.
"""
from typing import Sequence
from collections import defaultdict
from dataclasses import dataclass
from fractions import Fraction
@arseniiv
arseniiv / replacenotes.py
Created October 3, 2023 18:59
replacenotes.py
'''
Replaces notes with flats with enharmonic sharps in SFZ and DSPRESET files.
'''
from pathlib import Path
from typing import Final
import re
DS_EXTS: Final = frozenset(['.dspreset'])
SFZ_EXTS: Final = frozenset(['.sfz'])
"""
sfzdefiner.py
a tool to dump all contents of files linked to
specified SFZ file(s) into self-contained results;
replaces variables with values too
basic usage: (python3 | py) sfzdefiner.py (source-file-name)+
usage help: (python3 | py) sfzdefiner.py --help
@arseniiv
arseniiv / integer_fit.py
Last active November 28, 2022 16:12
Multiplying a list of floats by the best number to fit to integers
from dataclasses import dataclass
from typing import Sequence
import numpy as np
@dataclass
class Fit:
error: float
multiplier: float
result: tuple[int, ...]
@arseniiv
arseniiv / lazy_var.py
Created March 2, 2021 21:38
Lazy variables in Python 3 (static types included)
"""
Lazy wrappers: `Lazy` and `LazyMut`.
In case you have a class with many lazy fields, consider
using `functools.cached_property` for each of them implemented as methods.
That will free you from writing `val` everywhere, and make the code clearer.
"""
from __future__ import annotations
from typing import Callable, TypeVar, Generic