Skip to content

Commit

Permalink
style: Reformat code using Black
Browse files Browse the repository at this point in the history
  • Loading branch information
edudobay committed Nov 15, 2021
1 parent 2217897 commit 89d5d11
Show file tree
Hide file tree
Showing 31 changed files with 169 additions and 400 deletions.
5 changes: 2 additions & 3 deletions mingus/containers/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from mingus.core import progressions, keys
from typing import Optional


class Bar(object):
"""A bar object.
Expand Down Expand Up @@ -208,9 +209,7 @@ def determine_progression(self, shorthand=False):
res.append(
[
x[0],
progressions.determine(
x[2].get_note_names(), self.key.key, shorthand
),
progressions.determine(x[2].get_note_names(), self.key.key, shorthand),
]
)
return res
Expand Down
3 changes: 1 addition & 2 deletions mingus/containers/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def add_track(self, track):
"""
if not hasattr(track, "bars"):
raise UnexpectedObjectError(
"Unexpected object '%s', "
"expecting a mingus.containers.Track object" % track
"Unexpected object '%s', " "expecting a mingus.containers.Track object" % track
)
self.tracks.append(track)
self.selected_tracks = [len(self.tracks) - 1]
Expand Down
6 changes: 2 additions & 4 deletions mingus/containers/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def set_range(self, range):
range[1] = Note(range[1])
if not hasattr(range[0], "name"):
raise UnexpectedObjectError(
"Unexpected object '%s'. "
"Expecting a mingus.containers.Note object" % range[0]
"Unexpected object '%s'. " "Expecting a mingus.containers.Note object" % range[0]
)
self.range = range

Expand All @@ -68,8 +67,7 @@ def note_in_range(self, note):
note = Note(note)
if not hasattr(note, "name"):
raise UnexpectedObjectError(
"Unexpected object '%s'. "
"Expecting a mingus.containers.Note object" % note
"Unexpected object '%s'. " "Expecting a mingus.containers.Note object" % note
)
if note >= self.range[0] and note <= self.range[1]:
return True
Expand Down
2 changes: 1 addition & 1 deletion mingus/containers/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def from_shorthand(self, shorthand):
def __int__(self):
"""Return the current octave multiplied by twelve and add
notes.note_to_int to it.
This means a C-0 returns 0, C-1 returns 12, etc. This method allows
you to use int() on Notes.
"""
Expand Down
3 changes: 1 addition & 2 deletions mingus/containers/note_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def add_note(self, note, octave=None, dynamics=None):
note = Note(note, self.notes[-1].octave, dynamics)
if not hasattr(note, "name"):
raise UnexpectedObjectError(
"Object '%s' was not expected. "
"Expecting a mingus.containers.Note object." % note
"Object '%s' was not expected. " "Expecting a mingus.containers.Note object." % note
)
if note not in self.notes:
self.notes.append(note)
Expand Down
10 changes: 3 additions & 7 deletions mingus/containers/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def add_notes(self, note, duration=None):
if self.instrument != None:
if not self.instrument.can_play_notes(note):
raise InstrumentRangeError(
"Note '%s' is not in range of the instrument (%s)"
% (note, self.instrument)
"Note '%s' is not in range of the instrument (%s)" % (note, self.instrument)
)
if duration == None:
duration = 4
Expand Down Expand Up @@ -114,9 +113,7 @@ def add_chord(chord, duration):
else:
chord = NoteContainer().from_chord(chord)
if tun:
chord = tun.find_chord_fingering(
chord, return_best_as_NoteContainer=True
)
chord = tun.find_chord_fingering(chord, return_best_as_NoteContainer=True)
if not self.add_notes(chord, duration):
# This should be the standard behaviour of add_notes
dur = self.bars[-1].value_left()
Expand Down Expand Up @@ -210,8 +207,7 @@ def __setitem__(self, index, value):
"""
if not hasattr(value, "bar"):
raise UnexpectedObjectError(
"Unexpected object '%s', "
"expecting a mingus.containers.Barobject" % value
"Unexpected object '%s', " "expecting a mingus.containers.Barobject" % value
)
self.bars[index] = value

Expand Down
37 changes: 14 additions & 23 deletions mingus/core/chords.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ def from_shorthand(shorthand_string, slash=None):
Recognised abbreviations: the letters "m" and "M" in the following
abbreviations can always be substituted by respectively "min", "mi" or
"-" and "maj" or "ma".
Example:
>>> from_shorthand('Amin7') == from_shorthand('Am7')
True
Expand Down Expand Up @@ -854,8 +854,7 @@ def from_shorthand(shorthand_string, slash=None):
# Get the note name
if not notes.is_valid_note(shorthand_string[0]):
raise NoteFormatError(
"Unrecognised note '%s' in chord '%s'"
% (shorthand_string[0], shorthand_string)
"Unrecognised note '%s' in chord '%s'" % (shorthand_string[0], shorthand_string)
)
name = shorthand_string[0]

Expand Down Expand Up @@ -1003,9 +1002,7 @@ def add_result(short):
elif intval == "57":
add_result("M7")
if tries != 3 and not no_inversions:
return inversion_exhauster(
[triad[-1]] + triad[:-1], shorthand, tries + 1, result
)
return inversion_exhauster([triad[-1]] + triad[:-1], shorthand, tries + 1, result)
else:
res = []
for r in result:
Expand All @@ -1018,9 +1015,7 @@ def add_result(short):
return inversion_exhauster(triad, shorthand, 1, [])


def determine_seventh(
seventh, shorthand=False, no_inversion=False, no_polychords=False
):
def determine_seventh(seventh, shorthand=False, no_inversion=False, no_polychords=False):
"""Determine the type of seventh chord; return the results in a list,
ordered on inversions.
Expand Down Expand Up @@ -1115,9 +1110,7 @@ def add_result(short, poly=False):
return inversion_exhauster(seventh, shorthand, 1, [], [])


def determine_extended_chord5(
chord, shorthand=False, no_inversions=False, no_polychords=False
):
def determine_extended_chord5(chord, shorthand=False, no_inversions=False, no_polychords=False):
"""Determine the names of an extended chord."""
if len(chord) != 5:
# warning raise exeption: not an extended chord
Expand Down Expand Up @@ -1181,16 +1174,18 @@ def add_result(short):
return inversion_exhauster(chord, shorthand, 1, [], [])


def determine_extended_chord6(
chord, shorthand=False, no_inversions=False, no_polychords=False
):
def determine_extended_chord6(chord, shorthand=False, no_inversions=False, no_polychords=False):
"""Determine the names of an 6 note chord."""
if len(chord) != 6:
# warning raise exeption: not an extended chord
return False

def inversion_exhauster(
chord, shorthand, tries, result, polychords,
chord,
shorthand,
tries,
result,
polychords,
):
"""Recursive helper function"""

Expand Down Expand Up @@ -1238,9 +1233,7 @@ def add_result(short):
return inversion_exhauster(chord, shorthand, 1, [], [])


def determine_extended_chord7(
chord, shorthand=False, no_inversions=False, no_polychords=False
):
def determine_extended_chord7(chord, shorthand=False, no_inversions=False, no_polychords=False):
"""Determine the names of an 7 note chord."""
if len(chord) != 7:
# warning raise exeption: not an extended chord
Expand Down Expand Up @@ -1298,7 +1291,7 @@ def int_desc(tries):

def determine_polychords(chord, shorthand=False):
"""Determine the polychords in chord.
This function can handle anything from polychords based on two triads to
6 note extended chords.
"""
Expand Down Expand Up @@ -1326,9 +1319,7 @@ def determine_polychords(chord, shorthand=False):
# f) last notes of the chord. Then try the function_list[f2] on the
# f2 + 3 first notes of the chord. Thus, trying all possible
# combinations.
for chord1 in function_list[f](
chord[len(chord) - (3 + f) :], True, True, True
):
for chord1 in function_list[f](chord[len(chord) - (3 + f) :], True, True, True):
for chord2 in function_list[f2](chord[: f2 + 3], True, True, True):
polychords.append("%s|%s" % (chord1, chord2))
if shorthand:
Expand Down
6 changes: 3 additions & 3 deletions mingus/core/intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,9 @@ def is_consonant(note1, note2, include_fourths=True):
In classical music the fourth is considered dissonant when used
contrapuntal, which is why you can choose to exclude it.
"""
return is_perfect_consonant(
note1, note2, include_fourths
) or is_imperfect_consonant(note1, note2)
return is_perfect_consonant(note1, note2, include_fourths) or is_imperfect_consonant(
note1, note2
)


def is_perfect_consonant(note1, note2, include_fourths=True):
Expand Down
50 changes: 10 additions & 40 deletions mingus/core/progressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ def to_chords(progression, key="C"):
Any number of accidentals can be used as prefix to augment or diminish;
for example: bIV or #I.
All the chord abbreviations in the chord module can be used as suffixes;
for example: Im7, IVdim7, etc.
You can combine prefixes and suffixes to manage complex progressions:
#vii7, #iidim7, iii7, etc.
Using 7 as suffix is ambiguous, since it is classicly used to denote the
seventh chord when talking about progressions instead of just the
dominant seventh chord. We have taken the classic route; I7 will get
Expand Down Expand Up @@ -187,9 +187,7 @@ def determine(chord, key, shorthand=False):
if shorthand:
func += chord_type
else:
func = (
func_dict[func] + chords.chord_shorthand_meaning[chord_type]
)
func = func_dict[func] + chords.chord_shorthand_meaning[chord_type]

# Handle b's and #'s (for instance Dbm in key C is bII)
if shorthand:
Expand Down Expand Up @@ -308,13 +306,7 @@ def substitute_minor_for_major(progression, substitute_index, ignore_suffix=Fals
res = []

# Minor to major substitution
if (
suff == "m"
or suff == "m7"
or suff == ""
and roman in ["II", "III", "VI"]
or ignore_suffix
):
if suff == "m" or suff == "m7" or suff == "" and roman in ["II", "III", "VI"] or ignore_suffix:
n = skip(roman, 2)
a = interval_diff(roman, n, 3) + acc
if suff == "m" or ignore_suffix:
Expand Down Expand Up @@ -342,13 +334,7 @@ def substitute_major_for_minor(progression, substitute_index, ignore_suffix=Fals
res = []

# Major to minor substitution
if (
suff == "M"
or suff == "M7"
or suff == ""
and roman in ["I", "IV", "V"]
or ignore_suffix
):
if suff == "M" or suff == "M7" or suff == "" and roman in ["I", "IV", "V"] or ignore_suffix:
n = skip(roman, 5)
a = interval_diff(roman, n, 9) + acc
if suff == "M" or ignore_suffix:
Expand All @@ -360,9 +346,7 @@ def substitute_major_for_minor(progression, substitute_index, ignore_suffix=Fals
return res


def substitute_diminished_for_diminished(
progression, substitute_index, ignore_suffix=False
):
def substitute_diminished_for_diminished(progression, substitute_index, ignore_suffix=False):
"""Substitute a diminished chord for another diminished chord.
'dim' and 'dim7' suffixes recognized, and 'VI' if there is no suffix.
Expand All @@ -375,13 +359,7 @@ def substitute_diminished_for_diminished(
res = []

# Diminished progressions
if (
suff == "dim7"
or suff == "dim"
or suff == ""
and roman in ["VII"]
or ignore_suffix
):
if suff == "dim7" or suff == "dim" or suff == "" and roman in ["VII"] or ignore_suffix:
if suff == "":
suff = "dim"

Expand All @@ -395,20 +373,12 @@ def substitute_diminished_for_diminished(
return res


def substitute_diminished_for_dominant(
progression, substitute_index, ignore_suffix=False
):
def substitute_diminished_for_dominant(progression, substitute_index, ignore_suffix=False):
(roman, acc, suff) = parse_string(progression[substitute_index])
res = []

# Diminished progressions
if (
suff == "dim7"
or suff == "dim"
or suff == ""
and roman in ["VII"]
or ignore_suffix
):
if suff == "dim7" or suff == "dim" or suff == "" and roman in ["VII"] or ignore_suffix:
if suff == "":
suff = "dim"

Expand Down
10 changes: 4 additions & 6 deletions mingus/core/scales.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def determine(notes):
):
res.append(scale(key[0]).name)
elif scale.type == "minor":
if notes <= set(
scale(get_notes(key[1])[0]).ascending()
) or notes <= set(scale(get_notes(key[1])[0]).descending()):
if notes <= set(scale(get_notes(key[1])[0]).ascending()) or notes <= set(
scale(get_notes(key[1])[0]).descending()
):
res.append(scale(get_notes(key[1])[0]).name)
return res

Expand Down Expand Up @@ -606,9 +606,7 @@ def __init__(self, note, octaves=1):
def ascending(self):
notes = [self.tonic]
for i in range(3):
notes.extend(
[intervals.major_second(notes[-1]), intervals.minor_third(notes[-1])]
)
notes.extend([intervals.major_second(notes[-1]), intervals.minor_third(notes[-1])])
notes.append(intervals.major_seventh(notes[0]))
notes[-2] = intervals.major_sixth(notes[0])
return notes * self.octaves + [notes[0]]
8 changes: 2 additions & 6 deletions mingus/extra/lilypond.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,12 @@ def from_Bar(bar, showkey=True, showtime=True):
parsed_value = value.determine(bar_entry[1])
ratio = parsed_value[2:]
if ratio == latest_ratio:
result += (
from_NoteContainer(bar_entry[2], bar_entry[1], standalone=False) + " "
)
result += from_NoteContainer(bar_entry[2], bar_entry[1], standalone=False) + " "
else:
if ratio_has_changed:
result += "}"
result += "\\times %d/%d {" % (ratio[1], ratio[0])
result += (
from_NoteContainer(bar_entry[2], bar_entry[1], standalone=False) + " "
)
result += from_NoteContainer(bar_entry[2], bar_entry[1], standalone=False) + " "
latest_ratio = ratio
ratio_has_changed = True
if ratio_has_changed:
Expand Down
4 changes: 1 addition & 3 deletions mingus/extra/musicxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ def write_Composition(composition, filename, zip=False):
import zipfile
import os

zf = zipfile.ZipFile(
filename + ".mxl", mode="w", compression=zipfile.ZIP_DEFLATED
)
zf = zipfile.ZipFile(filename + ".mxl", mode="w", compression=zipfile.ZIP_DEFLATED)
zi = zipfile.ZipInfo("META-INF" + os.sep + "container.xml")
zi.external_attr = 0o660 << 16
zf.writestr(
Expand Down
Loading

0 comments on commit 89d5d11

Please sign in to comment.