Page 1 of 1

Exact DXD Player

Posted: Thu Jan 29, 2015 2:13 am
by igorzwx
It is not always convenient to play audio files with CMD tools from terminal.
One may prefer to click on audio files and play them as usual.
It is not difficult to create a simple script, which can do the work for pcm_play.
You click on a FLAC or wave, the script opens a terminal and runs pcm_play on it.
You can watch the output on terminal, and use "keyboard shortcuts" with pcm_play
(e.g. "pause", "seek backward/forward", "quit", etc.)

Code: Select all

$ cat /opt/scripts/dxd_play.sh
#!/bin/sh
#
   # NAME: Exact DXD Player
   # FILE: dxd_play.sh (dxd_play)
   # DESCRIPTION: Play DXD FLACs and DXD waves with Petrov's pcm_play
   # Depends: flacpcm_play, flac, xterm | xfce4-terminal | konsole | mate-terminal | gnome-terminal

   # PCM waves and FLACs are supported.

killall flacpcm_play -q
wait

filename=$(basename "$1")

xterm -title "$filename" -e "flacpcm_play \"$1\" && exit "

# Alternative terminals:
# MATE:
# mate-terminal --title "$filename" -x sh -c "flacpcm_play \"$1\" && exit "
# XFCE:
# xfce4-terminal --title "$filename" -e "flacpcm_play \"$1\" && exit "
# KDE:
# konsole --title "$filename" -e "flacpcm_play \"$1\" && exit "
# GNOME:
# gnome-terminal --title "$filename" -x sh -c "flacpcm_play \"$1\" && exit "

# Hold the terminal window:
# xterm -hold -title "$filename" -e "flac_play \"$1\" "
# xfce4-terminal --hold --title "$filename" -e "flacpcm_play \"$1\" "
# konsole --hold --title "$filename" -e "flacpcm_play \"$1\" "
# mate-terminal --title "$filename" -x sh -c "flacpcm_play \"$1\" ; bash "
# gnome-terminal --title "$filename" -x sh -c "flacpcm_play \"$1\" ; bash "

exit 0


Save it as "dxd_play.sh", and make it executable:

Code: Select all

$ chmod +x dxd_play.sh


Create folder /opt/scripts

Code: Select all

$ cd /opt
$ sudo mkdir scripts


and copy dxd_play.sh to it:

Code: Select all

$ sudo cp dxd_play.sh /opt/scripts


Create a symbolic link:

Code: Select all

$ sudo ln -s /opt/scripts/dxd_play.sh /usr/bin/dxd_play


Now we can create a launcher for dxd_play

Code: Select all

$ echo "[Desktop Entry]
Name=Exact DXD Player
Comment=play DXD waves and DXD FLACs with pcm_play
Exec=dxd_play %F
Icon=utilities-terminal.png
Terminal=false
Type=Application
Encoding=UTF-8
Categories=AudioVideo;Player;
MimeType=audio/wav;audio/x-wav;audio/wave;audio/x-pn-wav;audio/flac;audio/x-flac;" > dxd_play.desktop


You can view it on terminal:

Code: Select all

$ cat dxd_play.desktop


or open it with a text editor of your choice:

Code: Select all

$ pluma dxd_play.desktop


Code: Select all

$ nohup kate dxd_play.desktop & rm -f nohup.out


To enable this "application launcher", you can copy it to /usr/share/applications/

Code: Select all

$ sudo cp dxd_play.desktop /usr/share/applications/


However, dxd_play may not work without pcm_play and flacpcm_play.

Copy pcm_play to /opt/scripts

Code: Select all

$ sudo cp pcm_play /opt/scripts


Create a symbolic link:

Code: Select all

$ sudo ln -s /opt/scripts/pcm_play /usr/bin/pcm_play


Now we can create flacpcm_play

Code: Select all

$ cat /opt/scripts/flacpcm_play.sh
   #!/bin/sh
   #
   # NAME: playfolder.sh (playfolder)
   # DESCRIPTION: Play FLACs and PCM waves with Petrov's pcm_play
    # Depends: flac, pcm_play

   # DXD waves and DXD FLACs are supported.

# Default output format: 192kHz 32bit (Intel HDA codecs)
# Intel HDA: _https://en.wikipedia.org/wiki/Intel_High_Definition_Audio

# To find out which output formats are supported for your sound devices, type on terminal:
# ossinfo -a -v9

# Output format and default settings of pcm_play:

Freq=192000

Bit=32

fpcm_play(){
   pcm_play "$1" -s oss -f "$Freq" -b "$Bit" -T fft -e
}

tmp_wav=/tmp/tmp.wav

killall banshee -q
wait
killall ossplay -q
wait
killall flac -q
wait
killall pcm_play -q
wait
rm -f "$tmp_wav"
wait

filename=$(basename "$1")
extension="${filename##*.}"

case "$extension" in
wav)    echo "Playing:  $filename"
        fpcm_play "$1"
      wait
      ;;
flac)   rm -f "$tmp_wav"
      wait
      echo "Decoding FLAC:  $filename"
      flac -d -o "$tmp_wav" "$1"     #  -s, --silent
      wait
        echo "Playing:  $filename"
      fpcm_play "$tmp_wav"
      wait
      rm -f "$tmp_wav"
      wait             
      ;;
esac

exit 0


Save it as "flacpcm_play.sh", and make it executable:

Code: Select all

$ chmod +x flacpcm_play.sh


NOTE: flacpcm_play.sh is configured for 192kHz 32bit format (default).
You can change the settings in the script, according to your "ossinfo -a -v9".

Copy flacpcm_play.sh to /opt/scripts

Code: Select all

$ sudo cp flacpcm_play.sh /opt/scripts


Create a symbolic link:

Code: Select all

$ sudo ln -s /opt/scripts/flacpcm_play.sh /usr/bin/flacpcm_play


Right click on a FLAC file → Properties → Open With → +Add → Exact DXD Player
The same for PCM waves.

Now you can play FLACs and PCM waves with a mouse click.

Re: Exact DXD Player

Posted: Thu Jan 29, 2015 2:23 am
by igorzwx
Script playfolder

How to use:

Open terminal in a folder with FLACs and/or waves. Run:

Code: Select all

$ playfolder


It will play all FLACs and/or PCM waves in the current folder.

Code: Select all

$ cat /opt/scripts/playfolder.sh
#!/bin/bash
#
   # NAME: playfolder.sh (playfolder)
   # DESCRIPTION: Play FLACs and PCM waves with Petrov's pcm_play
    # Depends: flac, pcm_play

   # DXD waves and DXD FLACs are supported.

# Default output format: 192kHz 32bit (Intel HDA codecs)
# Intel HDA: _https://en.wikipedia.org/wiki/Intel_High_Definition_Audio

# To find out which output formats are supported for your sound devices, type on terminal:
# ossinfo -a -v9

# Output format and default settings of pcm_play:

Freq=192000

Bit=32

fpcm_play(){
   pcm_play "$1" -s oss -f "$Freq" -b "$Bit" -T fft -e
}

tmp_wav=/tmp/tmp.wav

killall banshee -q
wait
killall ossplay -q
wait
killall flac -q
wait
killall pcm_play -q
wait
rm -f "$tmp_wav"
wait

# [path] the full filename of the current working directory
locus="$PWD"

# Name of the current working directory
foldername=$(basename "$PWD")

nwaves=0
nflacs=0

for file in *
do
filename=$(basename "$file")
extension="${filename##*.}"

case "$extension" in
wav)    nwaves=$(( $nwaves + 1 ))
      echo "Playing:  $filename"
        fpcm_play "$file"
      wait
      ;;
flac)   nflacs=$(( $nflacs + 1 ))
      rm -f "$tmp_wav"
      wait
      echo "Decoding FLAC:  $filename"
      flac -d -o "$tmp_wav" "$file"     #  -s, --silent
      wait
        echo "Playing:  $filename"
      fpcm_play "$tmp_wav"
      wait
      rm -f "$tmp_wav"
      wait             
      ;;
esac
done

echo "WAVES: $nwaves"
echo "FLACs: $nflacs"
echo "APPLICATION: playfolder → pcm_play"
echo "FOLDER: $foldername"
echo "LOCATION: $locus"
echo "TEMPORAL FILE: /tmp/tmp.wav"

exit 0


Save it as "playfolder.sh", and make it executable:

Code: Select all

$ chmod +x playfolder.sh


NOTE: playfolder.sh is configured for 192kHz 32bit format (default).
You can change the settings in the script, according to your "ossinfo -a -v9".

Copy playfolder.sh to /opt/scripts

Code: Select all

$ sudo cp playfolder.sh /opt/scripts


Create a symbolic link:

Code: Select all

$ sudo ln -s /opt/scripts/playfolder.sh /usr/bin/playfolder


Now it is ready to use.

Caja script for MATE Desktop

Code: Select all

$ cat "$HOME/.config/caja/scripts/Play FLACs and Waves in the current folder"
#!/bin/bash
    #
   # Caja script for MATE Desktop, e.g. Linux Mint MATE

   # NAME: Play FLACs and waves in the current folder
   # DESCRIPTION: opens terminal in the current working directory, and runs "playfolder" on it.
    # Depends: caja, playfolder, flac, pcm_play, mate-terminal | xterm | xfce4-terminal | konsole

   # "playfolder" plays FLACs and PCM waves with "pcm_play".
   # DXD FLACs and DXD waves are supported.

    # Install into ~/.config/caja/scripts/
    # You need to be running Caja to use scripts.
   # HowTo: http://www.linuxgator.org/gnome/forum/viewtopic.php?f=15&t=4676
   # Ubuntu Docs: https://help.ubuntu.com/community/NautilusScriptsHowto
    # MATE Wiki: http://wiki.mate-desktop.org/migrating

# Name of the current working directory
foldername=$(basename "$PWD")

# Open terminal in the current working directory and run "playfolder" on it
exec mate-terminal --title "$foldername" -x bash -c "playfolder ; bash "

# Alternative terminals:
# exec xterm -hold -title "$foldername" -e "playfolder"
# exec xfce4-terminal --hold --title "$foldername" -e "playfolder"
# exec konsole --hold --title "$foldername" -e "playfolder"

# Close the terminal window, when "playfolder" exits:
# exec xterm -title "$foldername" -e "playfolder && exit "
# exec mate-terminal --title "$foldername" -x sh -c "playfolder && exit "
# exec xfce4-terminal --title "$foldername" -e "playfolder && exit "
# exec konsole --title "$foldername" -e "playfolder && exit "

# End of file


Save it to ~/.config/caja/scripts/
Make it executable.
Rename it how you want.

How to enable a Caja script:

Right mouse click inside a folder → Scripts → Open Scripts Folder → OK

Now you can open your file browser (caja) in a folder with FLACs and/or waves.
Right mouse click inside this folder and select from drop down menu:

Scripts → "Play FLACs and Waves in the current folder"

It will open terminal in the current folder, and run "playfolder" on it.

NOTE: You can make "right-click → playfolder-script" on files or on empty space inside your folder.
The result is the same.