# Support for Audacious in Fvwm-Crystal
# Written by: Rafael Antonio Porras Samaniego <spoek@distrobit.net>
# Modifications, debugging and improvments by Dominique Michel 2008-2013
# <dominique_libre@users.sourceforge.net>
# See ChangeLog for details

# Initialisations, shared functions
Include components/functions/Music

# First button {{{1
# Player controls and prefs
# mouse 1 Menu /Player
AddToFunc Music-GUI
+ I All (audacious) Iconify toggle

AddToFunc Player-generator
+ I DestroyMenu recreate /Player
+ I AddToMenu /Player '%22x22/fvwm-crystal/audio-x-generic.png%$[gt.Recreate the Playlists]' Music-RecreatePlaylist
+ I AddToMenu /Player '%22x22/fvwm-crystal/audio-x-generic.png%$[gt.Music player]' Popup /Preferences/MusicPlayer
+ I AddToMenu /Player "" Nop
+ I AddToMenu /Player '$[gt.Start QJackCtl]' Exec exec qjackctl
+ I AddToMenu /Player "" Nop
+ I AddToMenu /Player '$[gt.Start Audacious]' Exec exec audacious
+ I AddToMenu /Player '$[gt.Stop Audacious]' Exec exec audtool --shutdown
+ I AddToMenu /Player '$[gt.Show/Hide player]' Music-GUI

# mouse 2 Music-GUI : allready here {{{2
# mouse 3 Music-QJackGUI : in Music
# mouse 4 Mixer-Volume-Up
# mouse 5 Mixer-Volume-Down
# are in components/Mixer

# Second button {{{1
# Player controls and main vol
# mouse 1 Menu /Playlist-button
AddToFunc Music-RemoveSong
+ I Exec exec audtool playlist-delete `audtool playlist-position`

*Music-SavePlaylist-Dialog: Title "$[gt.Save playlist]"
*Music-SavePlaylist-Dialog: Text "$[gt.Name of the playlist]"
*Music-SavePlaylist-Dialog: Line center
*Music-SavePlaylist-Dialog: Input PlaylistName 40 ""
*Music-SavePlaylist-Dialog: Line center
*Music-SavePlaylist-Dialog: Line center
*Music-SavePlaylist-Dialog: Button quit " $[gt.Cancel] " ^[
*Music-SavePlaylist-Dialog: Command Nop
*Music-SavePlaylist-Dialog: Button quit " $[gt.Save] " ^M
*Music-SavePlaylist-Dialog: Command PipeRead 'numero=1; echo "#EXTM3U" > "$[infostore.UserManagedAudioPlaylists]/$(PlaylistName).m3u"; while [ $numero -le `audtool playlist-length` ]; do \
  echo "#EXTINF:-1,"`audtool playlist-song $numero` >> "$[infostore.UserManagedAudioPlaylists]/$(PlaylistName).m3u"; \
  audtool playlist-song-filename $numero >> "$[infostore.UserManagedAudioPlaylists]/$(PlaylistName).m3u"; \
  numero=`expr $numero + 1`; \
  done'
*Music-SavePlaylist-Dialog: Line center

AddToFunc Music-SavePlaylist
+ I Module FvwmForm Music-SavePlaylist-Dialog

# /Music/LoadPlaylist
AddToFunc FuncFvwmMenuAudioDirectory
+ I PipeRead 'case \"$0\" in \
	"$[infostore.AudioPlaylists]"*) myexec="audacious";; \
	"$[infostore.UserManagedAudioPlaylists]"*) myexec="audacious";; \
    esac; \
    test -f \"$0\"/.icontitle.png && mytitle=\"$0\"/.icontitle.png; \
    test -f \"$0\"/.media.png && mypng=\"$0\"/.media.png; \
    fvwm-menu-directory --icon-title "${mytitle:-22x22/categories/directory.png}" \
    --icon-file "${mypng:-22x22/categories/Audio.png}" \
    --func="FuncFvwmMenuAudioDirectory" \
    --exec-file "^${myexec}" --dir \"$0\" \
    --exec-t="-"'

AddToFunc Music-ClearPlaylist
+ I Exec exec audtool playlist-clear

AddToFunc Playlist-generator-button
+ I DestroyMenu recreate /Playlist-button
+ I AddToMenu /Playlist-button '$[gt.Remove current song]' Music-RemoveSong
+ I AddToMenu /Playlist-button '$[gt.Remove playlist]' Popup /Music/RemovePlaylist
+ I AddToMenu /Playlist-button '$[gt.Playlist copy]' Popup /Music/CopyPlaylist
+ I AddToMenu /Playlist-button '$[gt.Save playlist...]'	Music-SavePlaylist
+ I AddToMenu /Playlist-button "" Nop
+ I AddToMenu /Playlist-button '$[gt.Load playlist]' Popup /Music/LoadPlaylist
+ I AddToMenu /Playlist-button '$[gt.Clear playlist]' Music-ClearPlaylist

AddToMenu /Playlist-button
+ DynamicPopupAction Function Playlist-generator-button

## mouse 2 Menu /Playback
#########################
AddToFunc Music-Next
+ I Exec exec audtool playlist-advance

AddToFunc Music-Prev
+ I Exec exec audtool playlist-reverse

AddToFunc Music-Stop
+ I Exec exec audtool playback-stop

AddToFunc Music-Play
+ I Exec exec audtool playback-play

AddToFunc Music-Pause
+ I Exec exec audtool playback-pause

AddToFunc Music-PlayPause
+ I Exec exec audacious -t

AddToFunc Music-ToggleRandom
+ I Exec exec audtool playlist-shuffle-toggle

AddToFunc Playback-generator
+ I DestroyMenu recreate /Playback
+ I AddToMenu /Playback '$[gt.Next]' Music-Next
+ I AddToMenu /Playback '$[gt.Prev]' Music-Prev
+ I AddToMenu /Playback "" Nop
+ I AddToMenu /Playback '$[gt.Stop playback]' Music-Stop
+ I AddToMenu /Playback '$[gt.Play]' Music-Play
+ I AddToMenu /Playback '$[gt.Pause]' Music-Pause
+ I AddToMenu /Playback '$[gt.Play/Pause]' Music-PlayPause
+ I AddToMenu /Playback '$[gt.Toggle random]' Music-ToggleRandom
+ I AddToMenu /Playback '$[gt.Toggle repeat]' Exec exec audtool playlist-repeat-toggle

## mouse 3 Menu /Mixer : in components/Mixer
## mouse 4 Music-Next : allready here
## mouse 4 Music-Prev : allready here

# Third button {{{1
# Player controls and vol
# mouse 1 Music-Pause : allready here {{{2
# mouse 2 Music-PlayPause : allready here
# mouse 3 Menu /Music/Volume
AddToFunc Music-Volume
+ I Exec exec audtool set-volume $0

AddToMenu /Music/Volume
+ '$[gt.Player volume]'
+ "" Nop
+ " 0 dB" Music-Volume '100'
+ "-3 dB" Music-Volume '71'
+ "-6 dB" Music-Volume '50'
+ "-12 dB" Music-Volume '25'
+ "-18 dB" Music-Volume '12'
+ "-24 dB" Music-Volume '6'
+ "-30 dB" Music-Volume '3'
+ " 0" Music-Volume '0'

# Music menus {{{1
# Recipe without audio buttons use the following:
# Popup /Music
AddToFunc Music-generator
+ I DestroyMenu recreate /Music
+ I AddToMenu /Music '$[gt.Load playlist]'		Popup /Music/LoadPlaylist
+ I AddToMenu /Music '$[gt.Save playlist...]'		Music-SavePlaylist
+ I AddToMenu /Music '$[gt.Clear playlist]'		Music-ClearPlaylist
+ I AddToMenu /Music '$[gt.Remove current song]'	Music-RemoveSong
+ I AddToMenu /Music '$[gt.Remove playlist]'		Popup /Music/RemovePlaylist
+ I AddToMenu /Music '$[gt.Playlist copy]' 		Popup /Music/CopyPlaylist
+ I AddToMenu /Music "" Nop
+ I PipeRead 'audtool get-volume | sed -e "s:[ \t]::g" | sed -e "s:^.\\+$:AddToMenu\ /Music \'$[gt.Volume] \(&%%\)\' Popup /Music/Volume:"'
+ I AddToMenu /Music '$[gt.Toggle random]'		Music-ToggleRandom
+ I AddToMenu /Music '$[gt.Toggle repeat]'		Exec exec audtool playlist-repeat-toggle
+ I AddToMenu /Music "" Nop
+ I AddToMenu /Music '$[gt.Stop playback]'		Music-Stop
+ I AddToMenu /Music '$[gt.Show/Hide player]'		Music-GUI
+ I AddToMenu /Music '$[gt.Start Audacious]' Exec exec audacious
+ I AddToMenu /Music '$[gt.Stop Audacious]' Exec exec audtool --shutdown
+ I AddToMenu /Music '$[gt.Play/Pause]'			Music-PlayPause
+ I AddToMenu /Music "" Nop
+ I AddToMenu /Music '$[gt.Recreate the Playlists]'	Music-RecreatePlaylist
+ I AddToMenu /Music '$[gt.Music player]' 		Popup /Preferences/MusicPlayer

# Fake button functions (see Music-cdcd) {{{1
# Music-Speed-Up
AddToFunc Music-Speed-Up
+ I Nop
# Music-Speed-Down
AddToFunc Music-Speed-Down
+ I Nop
# Menu /Speed
AddToMenu /Speed
+ "" Nop
# Music-Seek-+
# Music-Seek--
AddToFunc Music-Seek
+ I Nop

# vim:ft=fvwm
