Core¶
core ¶
Foundation re-exports + small utility helpers.
The Core namespace re-exports the lowest-level building blocks: pitch
arithmetic, the note and interval parsers, and the transposition/distance
functions. Most users won't touch Core directly — the high-level
namespaces (Note, Interval, Chord, ...) wrap these.
Two convenience helpers live here:
fill_str— repeat a stringabs(n)times.deprecate— wrap a function so calls emit aDeprecationWarning.
Example
from tonal_py.core import note, transpose, distance note("C4").midi 60 transpose("C4", "M3") 'E4' distance("C4", "G4") '5P'
Source parity: @tonaljs/core
fill_str ¶
Repeat string s abs(n) times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
String to repeat. |
required |
n
|
int
|
Repeat count (sign ignored). |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Example
from tonal_py.core import fill_str fill_str("a", 3) 'aaa' fill_str("ab", 2) 'abab' fill_str("a", -3) # sign ignored 'aaa'
Source code in src/tonal_py/core.py
deprecate ¶
Wrap fn so calls emit a DeprecationWarning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
str
|
The deprecated name (used in the warning message). |
required |
alternative
|
str
|
The recommended replacement name. |
required |
fn
|
F
|
The function to wrap. |
required |
Returns:
| Type | Description |
|---|---|
F
|
A wrapped function with the same signature. |
Example
import warnings from tonal_py.core import deprecate def add(a, b): return a + b deprecated_add = deprecate("add", "newAdd", add) with warnings.catch_warnings(record=True) as w: ... warnings.simplefilter("always") ... deprecated_add(2, 3) ... issubclass(w[0].category, DeprecationWarning) 5 True