diff --git a/miditok/tokenizations/mmm.py b/miditok/tokenizations/mmm.py index f23ead6e..869c721f 100644 --- a/miditok/tokenizations/mmm.py +++ b/miditok/tokenizations/mmm.py @@ -72,7 +72,10 @@ def _add_time_events(self, events: List[Event]) -> List[Event]: all_events = [Event("Bar", "Start", 0)] # Time events - time_sig_change = self._current_midi_metadata["time_sig_changes"][0] + if self.config.use_time_signatures and len(self._current_midi_metadata["time_sig_changes"]) > 0: + time_sig_change = self._current_midi_metadata["time_sig_changes"][0] + else: + time_sig_change = TimeSignature(*TIME_SIGNATURE, 0) ticks_per_bar = self._compute_ticks_per_bar(time_sig_change, time_division) bar_at_last_ts_change = 0 previous_tick = 0 diff --git a/tests/One_track_MIDIs/6338816_Etude No. 4.mid b/tests/One_track_MIDIs/6338816_Etude No. 4.mid new file mode 100644 index 00000000..d3e27934 Binary files /dev/null and b/tests/One_track_MIDIs/6338816_Etude No. 4.mid differ diff --git a/tests/test_one_track.py b/tests/test_one_track.py index fdd02ee8..82a2d4a8 100644 --- a/tests/test_one_track.py +++ b/tests/test_one_track.py @@ -22,6 +22,7 @@ ) TIME_SIGNATURE_RANGE.update({2: [2, 3, 4]}) +TIME_SIGNATURE_RANGE[4].append(8) BEAT_RES_TEST = {(0, 16): 8} TOKENIZER_PARAMS = { "beat_res": BEAT_RES_TEST, @@ -66,6 +67,7 @@ def test_one_track_midi_to_tokens_to_midi( for i, file_path in enumerate(tqdm(files, desc="Testing One Track")): # Reads the midi midi = MidiFile(file_path) + # midi.instruments = [midi.instruments[0]] # Will store the tracks tokenized / detokenized, to be saved in case of errors for ti, track in enumerate(midi.instruments): track.name = f"original {ti} not quantized" @@ -105,8 +107,9 @@ def test_one_track_midi_to_tokens_to_midi( # For Octuple, as tempo is only carried at notes times, we need to adapt their times for comparison # Same for CPWord which carries tempo with Position (for notes) if tokenization in ["Octuple", "CPWord"]: + # We use the first track only, as it is the one for which tempos are decoded adapt_tempo_changes_times( - midi_to_compare.instruments, midi_to_compare.tempo_changes + [midi_to_compare.instruments[0]], midi_to_compare.tempo_changes ) # When the tokenizer only decoded tempo changes different from the last tempo val if tokenization in ["CPWord"]: