Skip to content

Commit

Permalink
Renaming use_drums_pitch_tokens to use_pitchdrum_tokens (#143)
Browse files Browse the repository at this point in the history
* renaming `use_drums_pitch_tokens` to `use_pitchdrum_tokens`

* lint fix
  • Loading branch information
Natooz committed Feb 2, 2024
1 parent 9c71b15 commit 37e28ed
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions miditok/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
TEMPO_RANGE,
TIME_SIGNATURE_RANGE,
USE_CHORDS,
USE_DRUMS_PITCH_TOKENS,
USE_PITCH_BENDS,
USE_PITCH_INTERVALS,
USE_PITCHDRUM_TOKENS,
USE_PROGRAMS,
USE_RESTS,
USE_SUSTAIN_PEDALS,
Expand Down Expand Up @@ -276,7 +276,7 @@ class TokenizerConfig:
``Pitch``, ``Velocity`` and ``Duration`` tokens. The :ref:`Octuple`, :ref:`MMM`
and :ref:`MuMIDI` tokenizers use natively ``Program`` tokens, this option is
always enabled. (default: ``False``)
:param use_drums_pitch_tokens: will use dedicated ``PitchDrum`` tokens for pitches
:param use_pitchdrum_tokens: will use dedicated ``PitchDrum`` tokens for pitches
of drums tracks. In the MIDI norm, the pitches of drums tracks corresponds to
discrete drum elements (bass drum, high tom, cymbals...) which are unrelated to
the pitch value of other instruments/programs. Using dedicated tokens for drums
Expand Down Expand Up @@ -388,7 +388,7 @@ def __init__(
use_pitch_bends: bool = USE_PITCH_BENDS,
use_programs: bool = USE_PROGRAMS,
use_pitch_intervals: bool = USE_PITCH_INTERVALS,
use_drums_pitch_tokens: bool = USE_DRUMS_PITCH_TOKENS,
use_pitchdrum_tokens: bool = USE_PITCHDRUM_TOKENS,
beat_res_rest: dict[tuple[int, int], int] = BEAT_RES_REST,
chord_maps: dict[str, tuple] = CHORD_MAPS,
chord_tokens_with_root_note: bool = CHORD_TOKENS_WITH_ROOT_NOTE,
Expand Down Expand Up @@ -474,7 +474,7 @@ def __init__(
self.use_pitch_bends: bool = use_pitch_bends
self.use_programs: bool = use_programs
self.use_pitch_intervals = use_pitch_intervals
self.use_drums_pitch_tokens = use_drums_pitch_tokens
self.use_pitchdrum_tokens = use_pitchdrum_tokens

# Rest params
self.beat_res_rest: dict[tuple[int, int], int] = beat_res_rest
Expand Down
2 changes: 1 addition & 1 deletion miditok/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
USE_SUSTAIN_PEDALS = False
USE_PITCH_BENDS = False
USE_PROGRAMS = False
USE_DRUMS_PITCH_TOKENS = True
USE_PITCHDRUM_TOKENS = True

# Pitch as intervals
USE_PITCH_INTERVALS = False
Expand Down
8 changes: 4 additions & 4 deletions miditok/midi_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def _preprocess_notes(
# Delete notes outside of pitch range
pitch_range = (
self.config.drums_pitch_range
if is_drums and self.config.use_drums_pitch_tokens
if is_drums and self.config.use_pitchdrum_tokens
else self.config.pitch_range
)
idx_out_of_pitch_range = np.where(
Expand Down Expand Up @@ -1163,7 +1163,7 @@ def _create_track_events(

# Pitch / NoteOn
if add_absolute_pitch_token:
if self.config.use_drums_pitch_tokens and track.is_drum:
if self.config.use_pitchdrum_tokens and track.is_drum:
note_token_name = "DrumOn" if self._note_on_off else "PitchDrum"
else:
note_token_name = "NoteOn" if self._note_on_off else "Pitch"
Expand Down Expand Up @@ -1203,7 +1203,7 @@ def _create_track_events(
events.append(
Event(
type_="DrumOff"
if self.config.use_drums_pitch_tokens and track.is_drum
if self.config.use_pitchdrum_tokens and track.is_drum
else "NoteOff",
value=note.pitch,
time=note.end,
Expand Down Expand Up @@ -1720,7 +1720,7 @@ def _add_additional_tokens_to_vocab_list(self, vocab: list[str]) -> None:
]

# PitchDrum
if self.config.use_drums_pitch_tokens:
if self.config.use_pitchdrum_tokens:
pitch_token_name = "DrumOn" if self._note_on_off else "PitchDrum"
vocab += [
f"{pitch_token_name}_{pitch_bend}"
Expand Down
4 changes: 2 additions & 2 deletions miditok/tokenizations/cp_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def _create_base_vocabulary(self) -> list[list[str]]:
# PITCH
vocab[2].append("Ignore_None")
vocab[2] += [f"Pitch_{i}" for i in range(*self.config.pitch_range)]
if self.config.use_drums_pitch_tokens:
if self.config.use_pitchdrum_tokens:
vocab[2] += [
f"PitchDrum_{i}" for i in range(*self.config.drums_pitch_range)
]
Expand Down Expand Up @@ -704,7 +704,7 @@ def _create_token_types_graph(self) -> dict[str, list[str]]:
dic[key].append("Ignore")
dic["Ignore"] = list(dic.keys())

if self.config.use_drums_pitch_tokens:
if self.config.use_pitchdrum_tokens:
dic["PitchDrum"] = dic["Pitch"]
for key, values in dic.items():
if "Pitch" in values:
Expand Down
2 changes: 1 addition & 1 deletion miditok/tokenizations/midi_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def _create_token_types_graph(self) -> dict[str, list[str]]:
dic["Program"].append(token_type)
dic[token_type].append("Program")

if self.config.use_drums_pitch_tokens:
if self.config.use_pitchdrum_tokens:
for tok1, tok2 in {("DrumOn", "NoteOn"), ("DrumOff", "NoteOff")}:
dic[tok1] = dic[tok2]
for key, values in dic.items():
Expand Down
2 changes: 1 addition & 1 deletion miditok/tokenizations/mmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def _create_token_types_graph(self) -> dict[str, list[str]]:

dic["Fill"] = list(dic.keys())

if self.config.use_drums_pitch_tokens:
if self.config.use_pitchdrum_tokens:
dic["PitchDrum"] = dic["Pitch"]
for key, values in dic.items():
if "Pitch" in values:
Expand Down
2 changes: 1 addition & 1 deletion miditok/tokenizations/octuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def _create_base_vocabulary(self) -> list[list[str]]:

# PITCH
vocab[0] += [f"Pitch_{i}" for i in range(*self.config.pitch_range)]
if self.config.use_drums_pitch_tokens:
if self.config.use_pitchdrum_tokens:
vocab[0] += [
f"PitchDrum_{i}" for i in range(*self.config.drums_pitch_range)
]
Expand Down
2 changes: 1 addition & 1 deletion miditok/tokenizations/remi.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ def _create_token_types_graph(self) -> dict[str, list[str]]:
dic["Program"].append(token_type)
dic[token_type].append("Program")

if self.config.use_drums_pitch_tokens:
if self.config.use_pitchdrum_tokens:
dic["PitchDrum"] = dic["Pitch"]
for key, values in dic.items():
if "Pitch" in values:
Expand Down
2 changes: 1 addition & 1 deletion miditok/tokenizations/structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _create_track_events(self, track: Track, _: None = None) -> list[Event]:
)
pitch_token_name = (
"PitchDrum"
if track.is_drum and self.config.use_drums_pitch_tokens
if track.is_drum and self.config.use_pitchdrum_tokens
else "Pitch"
)
events.append(
Expand Down
2 changes: 1 addition & 1 deletion miditok/tokenizations/tsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def _create_token_types_graph(self) -> dict[str, list[str]]:
dic["Program"].append(token_type)
dic[token_type].append("Program")

if self.config.use_drums_pitch_tokens:
if self.config.use_pitchdrum_tokens:
dic["PitchDrum"] = dic["Pitch"]
for key, values in dic.items():
if "Pitch" in values:
Expand Down

0 comments on commit 37e28ed

Please sign in to comment.