Skip to content

Instantly share code, notes, and snippets.

@jneen
Last active September 23, 2020 19:32
Show Gist options
  • Save jneen/9c947491fc1d1ff1ff9503f60162697b to your computer and use it in GitHub Desktop.
Save jneen/9c947491fc1d1ff1ff9503f60162697b to your computer and use it in GitHub Desktop.
A script I use to preview looping music
#!/usr/bin/env python3
import pyglet
class LoopingGroup(pyglet.media.SourceGroup):
def _advance(self):
if not self._sources: return
print('loop seek!')
source = self._sources[0]
super()._advance()
source.seek(0)
self._sources.append(source)
def make_looper(source):
out = LoopingGroup()
out.add(source)
return out
class Music:
def __init__(self, intro, loop):
if intro: self.intro = pyglet.media.load(intro)
self.loop = make_looper(pyglet.media.load(loop))
self.group = pyglet.media.SourceGroup()
if intro: self.group.add(self.intro)
self.group.add(self.loop)
def queue(self, player):
player.queue(self.group)
def main(argv):
intro = None
loop = None
while argv:
el = argv.pop(0)
if el == '-i' or el == '--intro':
intro = argv.pop(0)
elif not loop:
loop = el
else:
print('usage: loop [-i INTRO_FILE] LOOP_FILE')
exit(1)
player = pyglet.media.Player()
Music(intro, loop).queue(player)
player.play()
pyglet.app.run()
if __name__ == '__main__':
from sys import argv
main(argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment