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)
| 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 |