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

Python 3 and jazz updates #63

Closed
wants to merge 3 commits 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
14 changes: 14 additions & 0 deletions mingus/containers/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,22 @@ def __init__(self, key="C", meter=(4, 4)):
self.set_meter(meter)
self.empty()

#Convenient Python operator overloading

def __iadd__(self, other):
self.temporal_notes.append(other)
return self

def empty(self):
"""Empty the Bar, remove all the NoteContainers."""
self.temporal_notes = []
self.bar = []
self.current_beat = 0.0
return self.bar

def set_chord_notes(self, chords):
self.chords = chords
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unclear to me why you added chords and temporal_notes to this class. It seems they are not used elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that I added this, maybe from a historic version of mingus? Guess it's fine to ignore


def set_meter(self, meter):
"""Set the meter of this bar.

Expand All @@ -77,6 +87,10 @@ def set_meter(self, meter):
"Expecting a tuple." % meter
)

def extend(self, temporal_notes):
for note in temporal_notes:
self.temporal_notes.append(note)

def place_notes(self, notes, duration):
"""Place the notes on the current_beat.

Expand Down
12 changes: 10 additions & 2 deletions mingus/containers/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self, name="C", octave=4, dynamics=None):
if dynamics is None:
dynamics = {}
if isinstance(name, six.string_types):

self.set_note(name, octave, dynamics)
elif hasattr(name, "name"):
# Hardcopy Note object
Expand All @@ -66,6 +67,7 @@ def __init__(self, name="C", octave=4, dynamics=None):
"Don't know what to do with name object: " "'%s'" % name
)


def set_channel(self, channel):
self.channel = channel

Expand Down Expand Up @@ -262,7 +264,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 All @@ -272,7 +274,7 @@ def __int__(self):
res += 1
elif n == "b":
res -= 1
return res
return int(res)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear why this int should be needed. Did you ever get a non-int here? If so, maybe there's another bug to uncover.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry also not sure why I added this - I'm guessing it was from a type bug but I'm afraid I can't recall


def __lt__(self, other):
"""Enable the comparing operators on Notes (>, <, \ ==, !=, >= and <=).
Expand All @@ -293,6 +295,11 @@ def __eq__(self, other):
"""Compare Notes for equality by comparing their note values."""
if other is None:
return False

# added as was getting erros from play_Bar.set_key
if type(other) == str:
other = Note(other)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to me we should not compare Notes and strings by implicit conversion, but instead raise a TypeError to uncover bugs.


return int(self) == int(other)

def __ne__(self, other):
Expand All @@ -310,3 +317,4 @@ def __ge__(self, other):
def __repr__(self):
"""Return a helpful representation for printing Note classes."""
return "'%s-%d'" % (self.name, self.octave)

1 change: 0 additions & 1 deletion mingus/containers/note_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from mingus.containers.mt_exceptions import UnexpectedObjectError
import six


class NoteContainer(object):

"""A container for notes.
Expand Down
1 change: 0 additions & 1 deletion mingus/containers/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

from mingus.containers.mt_exceptions import UnexpectedObjectError


class Suite(object):

"""A suite object.
Expand Down
1 change: 1 addition & 0 deletions mingus/containers/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def add_notes(self, note, duration=None):
"Note '%s' is not in range of the instrument (%s)"
% (note, self.instrument)
)

if duration == None:
duration = 4

Expand Down
Loading