diff --git a/ariautils/README.md b/ariautils/README.md new file mode 100644 index 0000000..e27fd30 --- /dev/null +++ b/ariautils/README.md @@ -0,0 +1,14 @@ +

+

+ █████╗ ██████╗ ██╗ █████╗     ██╗   ██╗████████╗██╗██╗     ███████╗
+██╔══██╗██╔══██╗██║██╔══██╗    ██║   ██║╚══██╔══╝██║██║     ██╔════╝
+███████║██████╔╝██║███████║    ██║   ██║   ██║   ██║██║     ███████╗
+██╔══██║██╔══██╗██║██╔══██║    ██║   ██║   ██║   ██║██║     ╚════██║
+██║  ██║██║  ██║██║██║  ██║    ╚██████╔╝   ██║   ██║███████╗███████║
+╚═╝  ╚═╝╚═╝  ╚═╝╚═╝╚═╝  ╚═╝     ╚═════╝    ╚═╝   ╚═╝╚══════╝╚══════╝
+
+

+ +An extremely lightweight and simple library for pre-processing and tokenizing MIDI files. + + diff --git a/ariautils/midi.py b/ariautils/midi.py index 2289304..0ee72a6 100644 --- a/ariautils/midi.py +++ b/ariautils/midi.py @@ -22,8 +22,11 @@ Literal, TypedDict, cast, + ParamSpec ) +P = ParamSpec("P") + from ariautils.utils import ( load_maestro_metadata_json, load_aria_midi_metadata_json, @@ -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, @@ -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, diff --git a/ariautils/tokenizer/absolute.py b/ariautils/tokenizer/absolute.py index 4ba4c46..08b1049 100644 --- a/ariautils/tokenizer/absolute.py +++ b/ariautils/tokenizer/absolute.py @@ -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, @@ -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 @@ -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 @@ -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 @@ -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)) diff --git a/ariautils/tokenizer/relative.py b/ariautils/tokenizer/relative.py index 946c737..1f1785d 100644 --- a/ariautils/tokenizer/relative.py +++ b/ariautils/tokenizer/relative.py @@ -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, @@ -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 @@ -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 @@ -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: @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 8ffd74c..49020e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = "loua19@outlook.com"}] -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", @@ -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