Skip to content

Commit

Permalink
Added Playback Device Selection during and POST installation.
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyTromp committed Feb 1, 2022
1 parent d9fb003 commit bad26fe
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Docker/.env
Docker/docker-compose.yml
./CONFIG
1 change: 1 addition & 0 deletions CONFIG
6 changes: 1 addition & 5 deletions Docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
echo "Starting Speaker Application in Background (TMUX)"
/usr/bin/tmux new-session -d -s speaker_controller_application '/app/ifi-tidal-release/bin/speaker_controller_application'


echo "Starting TIDAL Connect.."
/app/ifi-tidal-release/bin/tidal_connect_application \
--tc-certificate-path "/app/ifi-tidal-release/id_certificate/IfiAudio_ZenStream.dat" \
--playback-device "{PLAYBACK_DEVICE}"
-f "${FRIENDLY_NAME}" \
--codec-mpegh true \
--codec-mqa ${MQA_CODEC} \
Expand All @@ -17,8 +17,4 @@ echo "Starting TIDAL Connect.."
--log-level 3 \
--enable-websocket-log "0" \

#echo "Starting Speaker Control Application.."
#/app/ifi-tidal-release/bin/speaker_controller_application


echo "TIDAL Connect Container Stopped.."
24 changes: 0 additions & 24 deletions Docker/entrypoint.sh.old

This file was deleted.

11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,14 @@ For 'HifiBerry Digi+ Pro', if it doesn't work out-of-the-box, you will need to e

Note you can list/print your device/DAC name by running the following command
```
docker run -ti \
--device /dev/snd \
-v /var/run/dbus:/var/run/dbus \
-v /var/run/avahi-daemon/socket:/var/run/avahi-daemon/socket \
--entrypoint /app/ifi-tidal-release/bin/ifi-pa-devs-get edgecrush3r/tidal-connect
docker run --device /dev/snd \
-v /var/run/dbus:/var/run/dbus \
-v /var/run/avahi-daemon/socket:/var/run/avahi-daemon/socket \
--entrypoint "" \
edgecrush3r/tidal-connect /app/ifi-tidal-release/bin/ifi-pa-devs-get 2>/dev/null | grep device#
```


Edit the entryfile.sh and set the playback-device accordingly should solve your issue.

# *** Other Stuff *** #
Expand Down
51 changes: 51 additions & 0 deletions install.sh → install_hifiberry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,45 @@ usage()
echo ""
}

select_playback_device()
{
ARRAY_DEVICES=()
DEVICES=$(docker run --device /dev/snd \
--entrypoint "" \
edgecrush3r/tidal-connect \
/app/ifi-tidal-release/bin/ifi-pa-devs-get 2>/dev/null | grep device#)

echo ""
echo "Found output devices..."
echo ""
#make newlines the only separator
IFS=$'\n'
re_parse="^device#([0-9])+=(.*)$"
for line in $DEVICES
do
if [[ $line =~ $re_parse ]]
then
device_num="${BASH_REMATCH[1]}"
device_name="${BASH_REMATCH[2]}"

echo "${device_num}=${device_name}"
ARRAY_DEVICES+=( ${device_name} )
fi
done

while :; do
read -ep 'Choose your output Device (0-9): ' number
[[ $number =~ ^[[:digit:]]+$ ]] || continue
(( ( (number=(10#$number)) <= 9999 ) && number >= 0 )) || continue
# Here I'm sure that number is a valid number in the range 0..9999
# So let's break the infinite loop!
break
done

PLAYBACK_DEVICE="${ARRAY_DEVICES[$number]}"
}


# define defaults
FRIENDLY_NAME_DEFAULT=${HOSTNAME}
MODEL_NAME_DEFAULT=${HOSTNAME}
Expand All @@ -79,6 +118,7 @@ DOCKER_IMAGE_DEFAULT="edgecrush3r/tidal-connect:latest"
BUILD_OR_PULL_DEFAULT="pull"
MQA_PASSTHROUGH_DEFAULT="false"
MQA_CODEC_DEFAULT="false"
PLAYBACK_DEVICE="default"

# override defaults with environment variables, if they have been set
FRIENDLY_NAME=${FRIENDLY_NAME:-${FRIENDLY_NAME_DEFAULT}}
Expand Down Expand Up @@ -188,15 +228,26 @@ then
fi
fi

log INFO "Select audio output device"
select_playback_device
echo ${PLAYBACK_DEVICE}

log INFO "Creating .env file."
ENV_FILE="Docker/.env"
CONFIG_FILE="CONFIG"

> ${ENV_FILE}
echo "FRIENDLY_NAME=${FRIENDLY_NAME}" >> ${ENV_FILE}
echo "MODEL_NAME=${MODEL_NAME}" >> ${ENV_FILE}
echo "MQA_PASSTHROUGH=${MQA_PASSTHROUGH}" >> ${ENV_FILE}
echo "MQA_CODEC=${MQA_CODEC}" >> ${ENV_FILE}
echo "PLAYBACK_DEVICE=${PLAYBACK_DEVICE}" >> ${ENV_FILE}
log INFO "Finished creating .env file."

log INFO "Create config symlink -> ${ENV_FILE}"
[ -e "${CONFIG_FILE}" ] && rm "${CONFIG_FILE}"
ln -s ${ENV_FILE} ${CONFIG_FILE}

# Generate docker-compose.yml
log INFO "Generating docker-compose.yml."
eval "echo \"$(cat templates/docker-compose.yml.tpl)\"" > Docker/docker-compose.yml
Expand Down
46 changes: 46 additions & 0 deletions select_playback_device.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

CONFIG_FILE=./CONFIG

ARRAY_DEVICES=()
DEVICES=$(docker exec -ti tidal_connect /app/ifi-tidal-release/bin/ifi-pa-devs-get 2>/dev/null | grep device#)

echo ""
echo "Found output devices..."
echo ""
#make newlines the only separator
IFS=$'\n'
re_parse="^device#([0-9])+=(.*)$"
for line in $DEVICES
do
if [[ $line =~ $re_parse ]]
then
device_num="${BASH_REMATCH[1]}"
device_name="${BASH_REMATCH[2]}"

echo "${device_num}=${device_name}"
ARRAY_DEVICES+=( ${device_name} )
fi
done

while :; do
read -ep 'Choose your output Device (0-9): ' number
[[ $number =~ ^[[:digit:]]+$ ]] || continue
(( ( (number=(10#$number)) <= 9999 ) && number >= 0 )) || continue
# Here I'm sure that number is a valid number in the range 0..9999
# So let's break the infinite loop!
break
done

export PLAYBACK_DEVICE="${ARRAY_DEVICES[$number]}"
echo ""
echo "Playback device is set to: ${PLAYBACK_DEVICE}"

CONFIG_FILE=./CONFIG
if test -f "$CONFIG_FILE"; then
sed -i -e "s/^PLAYBACK_DEVICE.*$/PLAYBACK_DEVICE\=${PLAYBACK_DEVICE}/g" Docker/.env
echo "Updated config file..."
echo ""
echo "Please restart TIDAL Service for changes to take effect."
fi

4 changes: 4 additions & 0 deletions show-audio.controller.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "Shows Audio Controller UI started within a running Tidal Container"
docker exec -ti tidal_connect /usr/bin/tmux a -t speaker_controller_application
12 changes: 12 additions & 0 deletions start-audio-controller.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Stop if already running
if pgrep -f ^/app/ifi-tidal-release/bin/speaker_controller_application >/dev/null 2>&1
then
./stop-audio-controller.sh
fi


echo "Starting Speaker Controller Application..."
docker exec -ti tidal_connect /usr/bin/tmux new-session -d -s speaker_controller_application '/app/ifi-tidal-release/bin/speaker_controller_application'

5 changes: 5 additions & 0 deletions stop-audio-controller.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo "Stopping Speaker Controller Application..."
docker exec -ti tidal_connect /usr/bin/tmux kill-session -t speaker_controller_application

1 change: 1 addition & 0 deletions templates/docker-compose.yml.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: '2.2'
services:
tidal-connect:
container_name: tidal_connect
env_file:
- .env
image: ${DOCKER_IMAGE}
Expand Down
1 change: 0 additions & 1 deletion templates/tidal.service.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ After=docker.service network-online.target
Requires=docker.service network-online.target

[Service]
#WorkingDirectory=/data/tidal-connect-docker/Docker/
WorkingDirectory=${PWD}/Docker/
Type=oneshot
RemainAfterExit=yes
Expand Down

0 comments on commit bad26fe

Please sign in to comment.