Play a Bar object. Return a dictionary with the bpm lemma set on success, an empty dict on some kind of failure. The tempo can be changed by setting the bpm attribute on a NoteContainer.
(self, bar, channel=1, bpm=120)
| 204 | return True |
| 205 | |
| 206 | def play_Bar(self, bar, channel=1, bpm=120): |
| 207 | """Play a Bar object. |
| 208 | |
| 209 | Return a dictionary with the bpm lemma set on success, an empty dict |
| 210 | on some kind of failure. |
| 211 | |
| 212 | The tempo can be changed by setting the bpm attribute on a |
| 213 | NoteContainer. |
| 214 | """ |
| 215 | self.notify_listeners( |
| 216 | self.MSG_PLAY_BAR, {"bar": bar, "channel": channel, "bpm": bpm} |
| 217 | ) |
| 218 | |
| 219 | # length of a quarter note |
| 220 | qn_length = 60.0 / bpm |
| 221 | for nc in bar: |
| 222 | if not self.play_NoteContainer(nc[2], channel, 100): |
| 223 | return {} |
| 224 | |
| 225 | # Change the quarter note length if the NoteContainer has a bpm |
| 226 | # attribute |
| 227 | if hasattr(nc[2], "bpm"): |
| 228 | bpm = nc[2].bpm |
| 229 | qn_length = 60.0 / bpm |
| 230 | ms = qn_length * (4.0 / nc[1]) |
| 231 | self.sleep(ms) |
| 232 | self.notify_listeners(self.MSG_SLEEP, {"s": ms}) |
| 233 | self.stop_NoteContainer(nc[2], channel) |
| 234 | return {"bpm": bpm} |
| 235 | |
| 236 | def play_Bars(self, bars, channels, bpm=120): |
| 237 | """Play several bars (a list of Bar objects) at the same time. |