python - Raspberry Pi3 sampler using pygame.mixer -
i'm new python , raspberry.
i'm making sampler raspberry. objective "play specific wave file when specific key pressed".
i specify wave files, loop , gate attributes in xml file. code working there's lag between key pressed , sound.
how can improve code ? pygame problem ? need use module pyglet or wave module ?
thanks in advance answer , sorry bad english.
here's code :
def playsample(spl, snd, bool): if spl.get_loop() == "on": if spl.get_gate() == "on": #loop on, gate on snd.play(-1) else: #loop on, gate off bool = not bool if bool: snd.play(-1) else: snd.stop() elif spl.get_gate() == "on": #loop off, gate on snd.play() else: #loop off, gate off snd.stop() snd.play() return bool def stopsample(spl, snd): if spl.get_gate() == "on": snd.stop() while true: event in pygame.event.get(): if event.type == pygame.keydown: if event.key == pygame.k_left: loopa = playsample(spla, sounda, loopa) if event.key == pygame.k_up: loopb = playsample(splb, soundb, loopb) if event.key == pygame.k_down: loopc = playsample(splc, soundc, loopc) if event.key == pygame.k_right: #next patch pos += 1 if pos > len(tab_patch) - 1: pos = 0 loadsamples() if event.key == pygame.k_p: #previous patch pos -= 1 if pos < 0: pos = len(tab_patch) - 1 loadsamples() if event.type == pygame.keyup: if event.key == pygame.k_left: stopsample(spla, sounda) if event.key == pygame.k_up: stopsample(splb, soundb) if event.key == pygame.k_down: stopsample(splc, soundc)
Comments
Post a Comment