def add_note(self, note, octave=None, dynamics=None): """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. """ if dynamics is None: dynamics = {} if isinstance(note, six.string_types): if octave is not None: note = Note(note, octave, dynamics) elif len(self.notes) == 0: note = Note(note, 4, dynamics) else: if Note(note, self.notes[-1].octave) < self.notes[-1]: note = Note(note, self.notes[-1].octave + 1, dynamics) else: 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 ) if note not in self.notes: self.notes.append(note) self.notes.sort() return self.notes
def __setitem__(self, index, value): """Enable the '[] =' notation.""" if not hasattr(value, 'tracks'): raise UnexpectedObjectError( "Object '%s' is not expected. " "Expecting a " "mingus.containers.Composition object." % value) self.compositions[index] = value
def __setitem__(self, index, value): """Enable the '[] =' notation for Tracks. Throw an UnexpectedObjectError if the value being set is not a mingus.containers.Bar object. """ if not hasattr(value, "bar"): raise UnexpectedObjectError( "Unexpected object '%s', " "expecting a mingus.containers.Barobject" % value) self.bars[index] = value
def add_track(self, track): """Add a track to the composition. Raise an UnexpectedObjectError if the argument is not a mingus.containers.Track object. """ if not hasattr(track, 'bars'): raise UnexpectedObjectError("Unexpected object '%s', " "expecting a mingus.containers.Track object" % track) self.tracks.append(track) self.selected_tracks = [len(self.tracks) - 1]
def add_composition(self, composition): """Add a composition to the suite. Raise an UnexpectedObjectError when the supplied argument is not a Composition object. """ if not hasattr(composition, 'tracks'): raise UnexpectedObjectError( "Object '%s' not expected. Expecting " "a mingus.containers.Composition object." % composition) self.compositions.append(composition) return self
def set_range(self, range): """Set the range of the instrument. A range is a tuple of two Notes or note strings. """ if isinstance(range[0], six.string_types): range[0] = Note(range[0]) range[1] = Note(range[1]) if not hasattr(range[0], "name"): raise UnexpectedObjectError( "Unexpected object '%s'. " "Expecting a mingus.containers.Note object" % range[0] ) self.range = range
def note_in_range(self, note): """Test whether note is in the range of this Instrument. Return True if so, False otherwise. """ if isinstance(note, six.string_types): note = Note(note) if not hasattr(note, "name"): raise UnexpectedObjectError( "Unexpected object '%s'. " "Expecting a mingus.containers.Note object" % note ) if note >= self.range[0] and note <= self.range[1]: return True return False