Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create_duration_tuples can create overlapping tuples #144

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"] # tensorflow not supported with 3.12
os: [ ubuntu-latest, windows-latest ]
#include: # TODO uncomment when multithreading pytest-xdist is fixed (PR #142)
# - python-version: "3.11"
# os: macos-latest
include:
- python-version: "3.11"
os: macos-latest

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
project = "MidiTok"
copyright = "2023, Nathan Fradet" # noqa: A001
author = "Nathan Fradet"
release = "3.0.1"
release = "3.0.2"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
21 changes: 18 additions & 3 deletions miditok/midi_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1952,15 +1952,30 @@ def __create_durations_tuples(self) -> list[tuple[int, int, int]]:
(beat, pos, beat_res)
for beat in range(*beat_range)
for pos in range(beat_res)
if not (beat == 0 and pos == 0)
]
durations += [
durations.append(
(
max(max(self.config.beat_res)),
0,
self.config.beat_res[max(self.config.beat_res)],
)
] # the last one
del durations[0] # removes duration of 0
) # adds the last one

# Sort them
durations.sort(key=lambda dt: dt[0] + dt[1] / dt[2])

# Deduplicate identical values
# For two identical values, we only keep the tuple having the lowest res
i = 0
while i < len(durations) - 1:
dur_i_b, dur_i_p, dur_i_r = durations[i]
dur_ip_b, dur_ip_p, dur_ip_r = durations[i + 1]
if (dur_i_b + dur_i_p / dur_i_r) == (dur_ip_b + dur_ip_p / dur_ip_r):
del durations[i if dur_i_r > dur_ip_r else i + 1]
else:
i += 1

return durations

def __create_tpb_per_ts(self) -> dict[int, int]:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "miditok"
version = "3.0.1"
version = "3.0.2"
description = "MIDI / symbolic music tokenizers for Deep Learning models."
readme = "README.md"
license = "MIT"
Expand Down
Loading