Play a list of Tracks. If an instance of MidiInstrument is used then the instrument will be set automatically.
(self, tracks, channels, bpm=120)
| 325 | return {"bpm": bpm} |
| 326 | |
| 327 | def play_Tracks(self, tracks, channels, bpm=120): |
| 328 | """Play a list of Tracks. |
| 329 | |
| 330 | If an instance of MidiInstrument is used then the instrument will be |
| 331 | set automatically. |
| 332 | """ |
| 333 | self.notify_listeners( |
| 334 | self.MSG_PLAY_TRACKS, {"tracks": tracks, "channels": channels, "bpm": bpm} |
| 335 | ) |
| 336 | |
| 337 | # Set the right instruments |
| 338 | for x in range(len(tracks)): |
| 339 | instr = tracks[x].instrument |
| 340 | if isinstance(instr, MidiInstrument): |
| 341 | try: |
| 342 | i = instr.names.index(instr.name) |
| 343 | except: |
| 344 | i = 1 |
| 345 | self.set_instrument(channels[x], i) |
| 346 | else: |
| 347 | self.set_instrument(channels[x], 1) |
| 348 | current_bar = 0 |
| 349 | max_bar = len(tracks[0]) |
| 350 | |
| 351 | # Play the bars |
| 352 | while current_bar < max_bar: |
| 353 | playbars = [] |
| 354 | for tr in tracks: |
| 355 | playbars.append(tr[current_bar]) |
| 356 | res = self.play_Bars(playbars, channels, bpm) |
| 357 | if res != {}: |
| 358 | bpm = res["bpm"] |
| 359 | else: |
| 360 | return {} |
| 361 | current_bar += 1 |
| 362 | return {"bpm": bpm} |
| 363 | |
| 364 | def play_Composition(self, composition, channels=None, bpm=120): |
| 365 | """Play a Composition object.""" |