Add a note to the container and sorts the notes from low to high. The note can either be a string, in which case you could also use the octave and dynamics arguments, or a Note object.
(self, note, octave=None, dynamics=None)
| 48 | self.notes = [] |
| 49 | |
| 50 | def add_note(self, note, octave=None, dynamics=None): |
| 51 | """Add a note to the container and sorts the notes from low to high. |
| 52 | |
| 53 | The note can either be a string, in which case you could also use |
| 54 | the octave and dynamics arguments, or a Note object. |
| 55 | """ |
| 56 | if dynamics is None: |
| 57 | dynamics = {} |
| 58 | if isinstance(note, six.string_types): |
| 59 | if octave is not None: |
| 60 | note = Note(note, octave, dynamics) |
| 61 | elif len(self.notes) == 0: |
| 62 | note = Note(note, 4, dynamics) |
| 63 | else: |
| 64 | if Note(note, self.notes[-1].octave) < self.notes[-1]: |
| 65 | note = Note(note, self.notes[-1].octave + 1, dynamics) |
| 66 | else: |
| 67 | note = Note(note, self.notes[-1].octave, dynamics) |
| 68 | if not hasattr(note, "name"): |
| 69 | raise UnexpectedObjectError( |
| 70 | "Object '%s' was not expected. " |
| 71 | "Expecting a mingus.containers.Note object." % note |
| 72 | ) |
| 73 | if note not in self.notes: |
| 74 | self.notes.append(note) |
| 75 | self.notes.sort() |
| 76 | return self.notes |
| 77 | |
| 78 | def add_notes(self, notes): |
| 79 | """Feed notes to self.add_note. |
no test coverage detected