#!/bin/bash

set -e

order=(
    c_cmus
    c_smplayer
)

function c_cmus {
    if [ "`pidof cmus`" == "" ]; then
        return 1
    fi

    case $1 in
        toggle) cmus-remote --pause;;
        previous) cmus-remote --prev;;
        next) cmus-remote --next;;
    esac
}

function c_smplayer {
    if [ "`pidof smplayer`" == "" ]; then
        return 1
    fi

    case $1 in
        toggle) smplayer -send-action pause;;
        previous) smplayer -send-action previous;;
        next) smplayer -send-action next;;
    esac
}

for i in `seq 1 ${#order[@]}`; do
    ${order[$i-1]} $1 && exit
done