#!/bin/bash
# Script to refresh audio subsystem when Zoom H5 is connected via USB

echo "Zoom H5 connection detected. Refreshing audio stack..."

# 1. Restart user-space multimedia layers using explicit patch environment mapping
sudo -u patch XDG_RUNTIME_DIR=/run/user/1000 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus systemctl --user restart pipewire.service wireplumber.service
sleep 2

# 2. Restart the main effects host and its web user interface
sudo systemctl restart modep-mod-host.service
sudo systemctl restart modep-mod-ui.service

# 3. Restart your custom loop framework service
sudo systemctl restart LooPyStation.service

echo "Audio stack and MODEP successfully re-linked to Zoom H5!"
