Skip to content

Commit d98fdb8

Browse files
authored
Add option to MidiDict length test (#15)
1 parent f88ed4a commit d98fdb8

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

ariautils/midi.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,30 +1140,30 @@ def test_note_frequency_per_instrument(
11401140
return is_valid, note_freq_per_instrument
11411141

11421142

1143-
def test_min_length(
1144-
midi_dict: MidiDict, min_seconds: int
1143+
def test_length(
1144+
midi_dict: MidiDict,
1145+
min_length_s: int,
1146+
max_length_s: int,
11451147
) -> tuple[bool, float]:
11461148
"""Tests the min length is above a threshold.
11471149
11481150
Args:
11491151
midi_dict (MidiDict): MidiDict to test.
1150-
min_seconds (int): Minimum length threshold in seconds.
1152+
min_length_s (int): Minimum length threshold in seconds.
1153+
max_length_s (int): Maximum length threshold in seconds.
11511154
11521155
Returns:
1153-
bool: True if longer than minimum length, else False.
1156+
bool: True if within thresholds, else False.
11541157
float: Length in seconds.
11551158
"""
11561159

11571160
if not midi_dict.note_msgs:
11581161
return False, 0.0
11591162

1160-
total_duration_ms = get_duration_ms(
1161-
start_tick=midi_dict.note_msgs[0]["data"]["start"],
1162-
end_tick=midi_dict.note_msgs[-1]["data"]["end"],
1163-
tempo_msgs=midi_dict.tempo_msgs,
1164-
ticks_per_beat=midi_dict.ticks_per_beat,
1163+
total_duration_ms = midi_dict.tick_to_ms(
1164+
midi_dict.note_msgs[-1]["data"]["end"]
11651165
)
1166-
is_valid = total_duration_ms / 1e3 >= min_seconds
1166+
is_valid = min_length_s <= total_duration_ms / 1e3 <= max_length_s
11671167

11681168
return is_valid, total_duration_ms / 1e3
11691169

@@ -1749,7 +1749,7 @@ def get_test_fn(
17491749
"max_instruments": test_max_instruments,
17501750
"total_note_frequency": test_note_frequency,
17511751
"note_frequency_per_instrument": test_note_frequency_per_instrument,
1752-
"min_length": test_min_length,
1752+
"length": test_length,
17531753
"mean_note_len": test_mean_note_len,
17541754
"mean_note_velocity": test_mean_note_velocity,
17551755
"silent_interval": test_silent_interval,

ariautils/tokenizer/absolute.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __init__(self, config_path: Path | str | None = None) -> None:
7272
self.name = "abs"
7373

7474
# Calculate time quantizations (in ms)
75+
# TODO: abs_time_step_ms isn't very descriptive
7576
self.abs_time_step_ms: int = self.config["abs_time_step_ms"]
7677
self.max_dur_ms: int = self.config["max_dur_ms"]
7778
self.time_step_ms: int = self.config["time_step_ms"]

0 commit comments

Comments
 (0)