Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ariautils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p align="center">
<pre>
█████╗ ██████╗ ██╗ █████╗ ██╗ ██╗████████╗██╗██╗ ███████╗
██╔══██╗██╔══██╗██║██╔══██╗ ██║ ██║╚══██╔══╝██║██║ ██╔════╝
███████║██████╔╝██║███████║ ██║ ██║ ██║ ██║██║ ███████╗
██╔══██║██╔══██╗██║██╔══██║ ██║ ██║ ██║ ██║██║ ╚════██║
██║ ██║██║ ██║██║██║ ██║ ╚██████╔╝ ██║ ██║███████╗███████║
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝
</pre>
</p>

An extremely lightweight and simple library for pre-processing and tokenizing MIDI files.


11 changes: 7 additions & 4 deletions ariautils/midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
Literal,
TypedDict,
cast,
ParamSpec
)

P = ParamSpec("P")

from ariautils.utils import (
load_maestro_metadata_json,
load_aria_midi_metadata_json,
Expand Down Expand Up @@ -1092,10 +1095,10 @@ def meta_aria_midi_json(midi_dict: MidiDict) -> dict[str, str]:

def get_metadata_fn(
metadata_process_name: str,
) -> Callable[Concatenate[MidiDict, ...], dict[str, str]]:
) -> Callable[Concatenate[MidiDict, P], dict[str, str]]:
name_to_fn: dict[
str,
Callable[Concatenate[MidiDict, ...], dict[str, str]],
Callable[Concatenate[MidiDict, P], dict[str, str]],
] = {
"composer_filename": meta_composer_filename,
"composer_metamsg": meta_composer_metamsg,
Expand Down Expand Up @@ -1836,9 +1839,9 @@ def test_repetitive_content(
# TODO: Refactor tests into a new module
def get_test_fn(
test_name: str,
) -> Callable[Concatenate[MidiDict, ...], tuple[bool, Any]]:
) -> Callable[Concatenate[MidiDict, P], tuple[bool, Any]]:
name_to_fn: dict[
str, Callable[Concatenate[MidiDict, ...], tuple[bool, Any]]
str, Callable[Concatenate[MidiDict, P], tuple[bool, Any]]
] = {
"max_programs": test_max_programs,
"max_instruments": test_max_instruments,
Expand Down
12 changes: 7 additions & 5 deletions ariautils/tokenizer/absolute.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

from pathlib import Path
from collections import defaultdict
from typing import Final, Callable, Any, Concatenate
from typing import Final, Callable, Any, Concatenate, ParamSpec

P = ParamSpec("P")

from ariautils.midi import (
MidiDict,
Expand Down Expand Up @@ -693,7 +695,7 @@ def detokenize(self, tokenized_seq: list[Token], **kwargs: Any) -> MidiDict:

def export_pitch_aug(
self, max_pitch_aug: int
) -> Callable[Concatenate[list[Token], ...], list[Token]]:
) -> Callable[Concatenate[list[Token], P], list[Token]]:
"""Exports a function that augments the pitch of all note tokens.

Notes which fall out of the range (0, 127) will be replaced
Expand Down Expand Up @@ -762,7 +764,7 @@ def pitch_aug_tok(tok: Token, _pitch_aug: int) -> Token:

def export_velocity_aug(
self, max_num_aug_steps: int
) -> Callable[Concatenate[list[Token], ...], list[Token]]:
) -> Callable[Concatenate[list[Token], P], list[Token]]:
"""Exports a function which augments the velocity of all pitch tokens.

Velocity values are clipped so that they don't fall outside of the
Expand Down Expand Up @@ -834,7 +836,7 @@ def velocity_aug_tok(tok: Token, _velocity_aug: int) -> Token:

def export_tempo_aug(
self, max_tempo_aug: float, mixup: bool
) -> Callable[Concatenate[list[Token], ...], list[Token]]:
) -> Callable[Concatenate[list[Token], P], list[Token]]:
"""Exports a function which augments the tempo of a sequence of tokens.

Additionally this function performs note-mixup: randomly re-ordering
Expand Down Expand Up @@ -882,7 +884,7 @@ def _quantize_time(_n: int | float) -> int:
)

# Buffer to hold all events, grouped by time
# buffer[time_tok_count][onset_ms] = [ event_1, event_2, ... ]
# buffer[time_tok_count][onset_ms] = [ event_1, event_2, P ]
# where event is a list of tokens, e.g. [note, onset, dur]
buffer: defaultdict[int, defaultdict[int, list[list[Token]]]] = (
defaultdict(lambda: defaultdict(list))
Expand Down
12 changes: 7 additions & 5 deletions ariautils/tokenizer/relative.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import random

from pathlib import Path
from typing import Final, Callable, Any, Concatenate
from typing import Final, Callable, Any, Concatenate, ParamSpec

P = ParamSpec("P")

from ariautils.midi import (
MidiDict,
Expand Down Expand Up @@ -501,7 +503,7 @@ def detokenize(self, tokenized_seq: list[Token], **kwargs: Any) -> MidiDict:

def export_pitch_aug(
self, max_pitch_aug: int
) -> Callable[Concatenate[list[Token], ...], list[Token]]:
) -> Callable[Concatenate[list[Token], P], list[Token]]:
"""Exports a function that augments the pitch of all note tokens.

Note that notes which fall out of the range (0, 127) will be replaced
Expand Down Expand Up @@ -560,7 +562,7 @@ def pitch_aug_tok(tok: Token, _pitch_aug: int) -> Token:

def export_velocity_aug(
self, max_num_aug_steps: int
) -> Callable[Concatenate[list[Token], ...], list[Token]]:
) -> Callable[Concatenate[list[Token], P], list[Token]]:
"""Exports a function which augments the velocity of all pitch tokens.

Velocity values are clipped so that they don't fall outside of the
Expand Down Expand Up @@ -634,7 +636,7 @@ def velocity_aug_tok(tok: Token, _velocity_aug: int) -> Token:
# TODO: Needs unit test
def export_tempo_aug(
self, max_tempo_aug: float
) -> Callable[Concatenate[list[Token], ...], list[Token]]:
) -> Callable[Concatenate[list[Token], P], list[Token]]:
"""Exports a function which augments the tempo of a sequence of tokens.

Args:
Expand Down Expand Up @@ -720,7 +722,7 @@ def _append_wait_tokens(

def export_chord_mixup(
self,
) -> Callable[Concatenate[list[Token], ...], list[Token]]:
) -> Callable[Concatenate[list[Token], P], list[Token]]:
"""Exports a function which augments order of concurrent note tokens.

Concurrent note tokens are those which are not separated by a wait
Expand Down
19 changes: 12 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
[build-system]
requires = ["setuptools>=61.0"]
requires = ["setuptools>=80.0.0"]
build-backend = "setuptools.build_meta"

[project]
name = "ariautils"
version = "0.0.1"
description = ""
description = "MIDI tokenizers and pre-processing utils"
authors = [{name = "Louis Bradshaw", email = "[email protected]"}]
requires-python = ">=3.11"
license = {text = "Apache-2.0"}
requires-python = ">=3.10"
license = "Apache-2.0"
license-files = ["LICENSE"]
dependencies = [
"mido",
]
readme = "README.md"

[project.readme]
file = "ariautils/README.md"
content-type = "text/markdown"

keywords = []
classifiers = [
"Programming Language :: Python :: 3",
Expand Down Expand Up @@ -40,11 +45,11 @@ ariautils = ["config/*.json"]

[tool.black]
line-length = 80
target-version = ["py311"]
target-version = ["py310"]
include = '\.pyi?$'

[tool.mypy]
python_version = "3.11"
python_version = "3.10"
packages = ["ariautils", "tests"]
warn_return_any = true
warn_unused_configs = true
Expand Down