# Start a remote ssh session with reverse port forwarding
# usage: remote hostname server-script $DTK_PROGRAM  
# starts a local server, then ssh to remote-host,
# and set up reverse port forwarding.
# See https://hackertarget.com/ssh-examples-tunnels/ for ssh tunnel tips
#Examples:
# remote host.example.com  speech-server outloud 

# Configuration:

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"  
SDIR=$DIR/../servers

# Primary server listens on 2222
# Notification server listens on 3333 
function remote () {
    REMOTE=$1
    SERVER=$2
    ENGINE=$3
    $SDIR/$SERVER  2222 $SDIR/$ENGINE  &
#notification stream listens on 3333
    (export ALSA_DEFAULT="tts_mono_left"; $SDIR/$SERVER 3333 $SDIR/$ENGINE &)
    play -q -n \
    synth -j 3 sin %3 sin %-2 sin %-5 sin %-9 sin %-14 sin %-21 \
    fade h .01 2 1.5 \
    delay 1.3 1 .76 .54 .27 \
    remix  - \
    fade h 0 2.7 2.5 norm -1 &
# Open SSH Connection
        ssh -R 2222:localhost:2222  -R 3333:localhost:3333 $REMOTE
}

#setup tts, but dont ssh.
#use when we need  to restart server
# hard-wire speech-server and outloud $remote not used 
function rtts () {
    SERVER=speech-server
    ENGINE=outloud 
    $SDIR/$SERVER  2222 $SDIR/$ENGINE  &
#notification stream listens on 3333
    (export ALSA_DEFAULT="tts_mono_left"; $SDIR/$SERVER 3333 $SDIR/$ENGINE &)
    play -q -n \
    synth -j 3 sin %3 sin %-2 sin %-5 sin %-9 sin %-14 sin %-21 \
    fade h .01 2 1.5 \
    delay 1.3 1 .76 .54 .27 \
    remix  - \
    fade h 0 2.7 2.5 norm -1 &
}
