MCPcopy Create free account
hub / github.com/bspaans/python-mingus / add_notes

Method add_notes

mingus/containers/track.py:55–85  ·  view source on GitHub ↗

Add a Note, note as string or NoteContainer to the last Bar. If the Bar is full, a new one will automatically be created. If the Bar is not full but the note can't fit in, this method will return False. True otherwise. An InstrumentRangeError exception will be rais

(self, note, duration=None)

Source from the content-addressed store, hash-verified

53 return self
54
55 def add_notes(self, note, duration=None):
56 """Add a Note, note as string or NoteContainer to the last Bar.
57
58 If the Bar is full, a new one will automatically be created.
59
60 If the Bar is not full but the note can't fit in, this method will
61 return False. True otherwise.
62
63 An InstrumentRangeError exception will be raised if an Instrument is
64 attached to the Track, but the note turns out not to be within the
65 range of the Instrument.
66 """
67 if self.instrument != None:
68 if not self.instrument.can_play_notes(note):
69 raise InstrumentRangeError(
70 "Note '%s' is not in range of the instrument (%s)"
71 % (note, self.instrument)
72 )
73 if duration == None:
74 duration = 4
75
76 # Check whether the last bar is full, if so create a new bar and add the
77 # note there
78 if len(self.bars) == 0:
79 self.bars.append(Bar())
80 last_bar = self.bars[-1]
81 if last_bar.is_full():
82 self.bars.append(Bar(last_bar.key, last_bar.meter))
83 # warning should hold note if it doesn't fit
84
85 return self.bars[-1].place_notes(note, duration)
86
87 def get_notes(self):
88 """Return an iterator that iterates through every bar in the this

Callers 4

add_chordMethod · 0.95
from_chordsMethod · 0.95
__add__Method · 0.95
test_add_notesMethod · 0.45

Calls 5

BarClass · 0.90
is_fullMethod · 0.80
place_notesMethod · 0.80
can_play_notesMethod · 0.45

Tested by 1

test_add_notesMethod · 0.36