Pachabel's Canon in D is a very interesting piece because it repeats the same 8 notes/chords over and over again with different melodies over it. I like to use it as background music for homework, but all of the "1-hour versions" that I find on youtube are just short versions repeated over and over, and I decided there had to be a better solution.
After spending hours figuring out how to play a sound file with Python, I have begun writing my Infinite Canon Generator. When completed, it will select one base line and two treble lines at random to play at the same time, repeating this over and over.
So far, I have gotten multiple lines to play at once just fine and now have figured out how to make the event loop end, but I can't make the process repeat yet:
Code:
When run, the sound files of Lines 2, 3, A, and B will all play at once, (as a bunch of error messages spew out into the shell) and then the program will end. How should I go about making it repeat?
This is the error text:
Code:
After spending hours figuring out how to play a sound file with Python, I have begun writing my Infinite Canon Generator. When completed, it will select one base line and two treble lines at random to play at the same time, repeating this over and over.
So far, I have gotten multiple lines to play at once just fine and now have figured out how to make the event loop end, but I can't make the process repeat yet:
Code:
import pyglet
Line1 = pyglet.resource.media('Line1.aiff')
Line2 = pyglet.resource.media('Line2.aiff')
Line3 = pyglet.resource.media('Line3.aiff')
LineA = pyglet.resource.media('LineA.aiff')
LineB = pyglet.resource.media('LineB.aiff')
while True:
Line2.play()
Line3.play()
LineA.play()
LineB.play()
event_loop = pyglet.app.EventLoop()
@event_loop.event
def on_window_close(window):
event_loop.exit()
When run, the sound files of Lines 2, 3, A, and B will all play at once, (as a bunch of error messages spew out into the shell) and then the program will end. How should I go about making it repeat?
This is the error text:
Code:
Traceback (most recent call last):
File "/Users/Johnny/Documents/Programming/Python/Sound/music4.py", line 12, in <module>
Line3.play()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyglet/media/__init__.py", line 472, in play
player.queue(self)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyglet/media/__init__.py", line 978, in queue
group.queue(source)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyglet/media/__init__.py", line 695, in queue
source = source._get_queue_source()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyglet/media/__init__.py", line 579, in _get_queue_source
raise MediaException('This source is already queued on a player.')
pyglet.media.MediaException: This source is already queued on a player.