Not directly Zynthian; Performance Controller

Hi everybody,
I hope I´m right here.

Since I play the Zynthian with the Raspi4 I´m using the R3 to buildt a “Performance-Contoller” (PC).
The PC has

  • an Excel with a list of all songs of the performance and all the parameters, the hardware has to know to make fine music (Sound Change, volume, velocity correction etc)
  • 10 knobs to control the list up and down, send commands, start add-files
  • we´ll see …

Starting the project I buildt 2 scripts:
1st: play the background files
2nd: play the notes, comming from keyboard, manipulated by the parameters, going to the Zynthian.
Both were working.
Then I tried to build 1 script. I thought, I have to use multiprocessing features, but the boys from the german python forum said I don´t.

The actual script can use the buttons and it can play some notes. But after a short while it crashes. I hope someone here can solf the problem.

[ code]
#!/usr/bin/env python3
import threading
import time
from pathlib import Path
from queue import Queue

import openpyxl
import pygame.mixer
import mido
from RPi import GPIO

NEXT_SONG_PIN = 5 # Song + (grau)
PREVIOUS_SONG_PIN = 22 # Song - (lila)

SONG_PATH = Path("/home/pi/rpituto/wav")
EXCEL_FILENAME = “mperf1.xlsx”

def play_song(sheet, row):
song_nr = sheet[f"A{row}"].value
song_name = sheet[f"C{row}"].value
print(f"SongNr={song_nr} {song_name}")
pygame.mixer.music.load(str(SONG_PATH / song_name))
pygame.mixer.music.play(0)
time.sleep(0.5)

def tasten():
try:
GPIO.setmode(GPIO.BCM)
GPIO.setup([NEXT_SONG_PIN, PREVIOUS_SONG_PIN], GPIO.IN)
queue = Queue()
GPIO.add_event_detect(NEXT_SONG_PIN, GPIO.RISING, queue.put, 500)
GPIO.add_event_detect(PREVIOUS_SONG_PIN, GPIO.RISING, queue.put, 500)

    pygame.init()
    pygame.mixer.init(44100, 16, 2, 4096)
    pygame.mixer.music.set_volume(0.6)
    workbook = openpyxl.load_workbook(EXCEL_FILENAME)
    sheet = workbook.get_sheet_by_name("Tabelle1")
    current_row = 3
    while True:
        pin = queue.get()
        #
        # TODO Make sure the user cannot chose invalid rows without song
        # data.  Best to remove the workbook handling here and in
        # `play_song()` and pass in the songs as list of tuples or similar.
        #
        if pin == NEXT_SONG_PIN:
            current_row += 1
            play_song(sheet, current_row)
        elif pin == PREVIOUS_SONG_PIN:
            current_row -= 1
            play_song(sheet, current_row)
        else:
            assert False, "unexpected pin: {!r}".format(pin)
finally:
    GPIO.cleanup()

def spielen():
while True:
with mido.open_input(“Impulse:Impulse MIDI 1 28:0”) as inport:
with mido.open_output(“E-MU Xmidi 2x2 MIDI 1”) as outport:
outport.send(inport.receive())

def main():
threading.Thread(target=spielen, daemon=True).start()
tasten()

if name == “main”:
main()
[ /code]

Sry, I cannot copy the code correctly, but I hope you understand.

[code]
#!/usr/bin/env python3
import threading
import time
from pathlib import Path
from queue import Queue

import openpyxl
import pygame.mixer
import mido
from RPi import GPIO

NEXT_SONG_PIN = 5 # Song + (grau)
PREVIOUS_SONG_PIN = 22 # Song - (lila)

SONG_PATH = Path("/home/pi/rpituto/wav")
EXCEL_FILENAME = “mperf1.xlsx”

def play_song(sheet, row):
song_nr = sheet[f"A{row}"].value
song_name = sheet[f"C{row}"].value
print(f"SongNr={song_nr} {song_name}")
pygame.mixer.music.load(str(SONG_PATH / song_name))
pygame.mixer.music.play(0)
time.sleep(0.5)

def tasten():
try:
GPIO.setmode(GPIO.BCM)
GPIO.setup([NEXT_SONG_PIN, PREVIOUS_SONG_PIN], GPIO.IN)
queue = Queue()
GPIO.add_event_detect(NEXT_SONG_PIN, GPIO.RISING, queue.put, 500)
GPIO.add_event_detect(PREVIOUS_SONG_PIN, GPIO.RISING, queue.put, 500)

    pygame.init()
    pygame.mixer.init(44100, 16, 2, 4096)
    pygame.mixer.music.set_volume(0.6)
    workbook = openpyxl.load_workbook(EXCEL_FILENAME)
    sheet = workbook.get_sheet_by_name("Tabelle1")
    current_row = 3
    while True:
        pin = queue.get()
        #
        # TODO Make sure the user cannot chose invalid rows without song
        # data.  Best to remove the workbook handling here and in
        # `play_song()` and pass in the songs as list of tuples or similar.
        #
        if pin == NEXT_SONG_PIN:
            current_row += 1
            play_song(sheet, current_row)
        elif pin == PREVIOUS_SONG_PIN:
            current_row -= 1
            play_song(sheet, current_row)
        else:
            assert False, "unexpected pin: {!r}".format(pin)
finally:
    GPIO.cleanup()

def spielen():
while True:
with mido.open_input(“Impulse:Impulse MIDI 1 28:0”) as inport:
with mido.open_output(“E-MU Xmidi 2x2 MIDI 1”) as outport:
outport.send(inport.receive())

def main():
threading.Thread(target=spielen, daemon=True).start()
tasten()

if name == “main”:
main()
[ /code]

1 Like