= mod-host vs Pisound button
:customcss: presentation.css
:source-highlighter: highlight.js
:linkattrs:

https://sonoj.org/[Sonoj Convention, window=_blank]

https://github.com/danielappelt[Daniel Appelt, window=_blank] / 2023-09-30

== Pisound & the button

[%step]
* https://blokas.io/pisound/[Pisound, window=_blank] is a sound card and MIDI interface for the Raspberry Pi
* It comes with one https://github.com/BlokasLabs/pisound/blob/master/pisound-btn/pisound.conf[configurable button, window=_blank]
* Bash scripts are used for button action (https://github.com/BlokasLabs/pisound/blob/master/scripts/pisound-btn/toggle_wifi_hotspot.sh[example,window=_blank])

== mod-host

[%step]
* https://github.com/moddevices/mod-host[mod-host, window=_blank] is an LV2 host for JACK, controllable via socket or command line
* https://github.com/moddevices/mod-ui[mod-ui, window=_blank] is started together with mod-host in MODEP
* mod-ui uses file socket to communicate with mod-host

== Problem

[%step]
* Syncing mod-host as secondary via MIDI clock was unreliable
* How to start/stop transport in mod-host as MIDI clock primary not using mod-ui?

== Solution

[%step]
* Let Pisound button start/stop mod-host via web socket
* https://github.com/vi/websocat[websocat, window=_blank] is like netcat, curl and socat for WebSockets
* Example script to start/stop transport in mod-host

== Code

[source, bash]
----
#!/bin/sh

. /usr/local/pisound/scripts/common/common.sh

# Use websocket interface to mod-ui as the regular socket is exclusively used for
# communication between mod-ui and mod-host.

if [ -z $(echo -n '' | /usr/local/bin/websocat --text ws://127.0.0.1:80/websocket/ | grep 'transport 1') ]; then
    # Start transport and blinking
    echo 'transport-rolling 1' | /usr/local/bin/websocat ws://127.0.0.1:80/websocket/
else
    # Stop transport and blinking
    echo 'transport-rolling 0' | /usr/local/bin/websocat ws://127.0.0.1:80/websocket/
fi
----
