(1)
I would do it in a simpler way unless there is a specific reason to stick with C++. A basic shell script will do the job perfectly, something like the cplay
script (https://wiki.archlinux.org/index.php/Cmus#Remote_Control):
$ ps h -C cmus || cmus
Since Cmus is not a real background service, – eg. you cannot start it without the ncurses GUI – the best if you are running it in a screen session.
$ screen -rD cmus || screen -dmS 'cmus' /usr/bin/cmus
With this command, you always have a running cmus session within a screen session. You can even close the terminal, the service will be keep running in the backround. Just put this command to your .bashrc as an alias and you'll always have an easy access to the player
$ alias mycmus='screen -rD cmus || screen -dmS 'cmus' /usr/bin/cmus'
Will start a cmus+screen session if it's not running, otherwise it opens the session. "Ctrl+a d" detaches the window.
Putting them together and answering your question (in shell script):
Add the following lines to a file, eg.: "mycplayer.sh
"
(don't forget the chmod +x mycplayer.sh
, then add it to the the PATH)
#!/bin/sh
cmus-remote -Q > /dev/null || screen -dmS 'cmus' /usr/bin/cmus
cmus-remote $1
The first line will make sure there is a running cmus instance (in the background, using screen), the second line will execute the remote command.
Usage:
$ mycplayer.sh -u start/stop the player
$ mycplayer.sh -n next in the playlist
etc.
(2) In C++
(3) If cmus
is a network service, so it was started with --listen host[:port]
, then you'll need an ssh to start the service on the remote box. See the screen command above how to do it.
Hope this helps.