#!/bin/bash
export TEXTDOMAIN=pmusic

GUI_VOLUME='
<hscale draw-value="false" scale-step="1" scale-min="0" scale-max="95" tooltip-text="'$(gettext 'Volume')'
'$(gettext 'Speaker channel')': '$SPEAKER'">
 <variable>VOLUME</variable>
 <input file>'$WORKDIR'/VOLUME</input>
 <action>. '$APPDIR'/func_mixer -set_volume</action>
</hscale>'

GUI_VOLUME_V='
<vscale name="mixer_vol_sliderV" width-request="22" draw-value="false" scale-step="1" scale-min="0" scale-max="95" inverted="true" tooltip-text="'$(gettext 'Volume')'
'$(gettext 'Speaker channel')': '$SPEAKER'" space-expand="true" space-fill="true">
 <variable>VOLUME</variable>
 <input file>'$WORKDIR'/VOLUME</input>
 <action>. '$APPDIR'/func_mixer -set_volume</action>
</vscale>'

GUI_VOLUME_IMG='
<pixmap>
 <height>12</height>
 <input file>'$APPDIR'/themes/'$THEME'/volume.svg</input>
</pixmap>
'

GUI_BALANCE='
<hscale draw-value="false" scale-step="1" scale-min="0" scale-max="200" tooltip-text="'$(gettext 'Balance')'
'$(gettext 'Speaker channel')': '$SPEAKER'" space-expand="false" space-fill="false">
 <variable>BALANCE</variable>
 <input file>'$WORKDIR'/BALANCE</input>
 <action>. '$APPDIR'/func_mixer -set_volume</action>
 <action signal="button-release-event">'$APPDIR'/func_mixer -check_stereo</action>
</hscale>
'

GUI_BUTTON_MIXER='
<button tooltip-text="'$(gettext 'Sound processing')'" space-expand="false" space-fill="false">
 <input file stock="gtk-volume"></input>
 <action>'$APPDIR'/func_mixer -gui &</action>
</button>'

GUI_BUTTON_MUTE='
<button relief="2" tooltip-text="'$(gettext 'Mute audio')'" space-expand="false" space-fill="false">
 <input file stock="gtk-volume_mute"></input>
 <action>. '$APPDIR'/func_mixer -mute</action>
</button>'

GUI_MIXER='
<vbox spacing="0">
 <text height-request="2" space-expand="false" space-fill="false"><label>""</label></text>
 <hbox spacing="0" homogeneous="true" space-expand="true" space-fill="true">
  <vbox>
   <text use-markup="true" wrap="false" angle="90" space-expand="false" space-fill="false"><label>"<b><i><span size='"'large'"' fgcolor='"'#555555'"'>'$(gettext 'Volume')'</span></i></b>  "</label></text>
   <text space-expand="true" space-fill="true"><label>""</label></text>
   <text use-markup="true" wrap="false" space-expand="false" space-fill="false"><label>"<b><span color='"'#FF6D00'"'>'$(gettext 'L')'</span></b>"</label></text>
  </vbox>
  <vbox space-expand="true" space-fill="true">
   '$GUI_VOLUME_V'
  </vbox>
  <vbox space-expand="false" space-fill="false">
   '$GUI_BUTTON_MUTE'
   <text space-expand="true" space-fill="true"><label>""</label></text>
   <text use-markup="true" wrap="false" space-expand="false" space-fill="false"><label>"<b><span color='"'#FF6D00'"'>'$(gettext 'R')'</span></b>"</label></text>
  </vbox>
 </hbox>
 '$GUI_BALANCE'
</vbox>'


#input sound processing - controlled by ffmpeg
if [ -s $WORKDIR/ffmpeg_filter ]; then
	FADE_IN="`awk -F 'afade=t=in:d=' '{print $2}' $WORKDIR/ffmpeg_filter | cut -d',' -f1`"
	TREBLE="`awk -F 'treble=gain=' '{print $2}' $WORKDIR/ffmpeg_filter | cut -d',' -f1`"
	BASS="`awk -F 'bass=gain=' '{print $2}' $WORKDIR/ffmpeg_filter | cut -d',' -f1`"
	TEMPO="`awk -F 'atempo=' '{print $2}' $WORKDIR/ffmpeg_filter | cut -d',' -f1 | tr -d '.'`"
fi
[ ! "$FADE_IN" ] && FADE_IN=0
[ ! "$TREBLE" ] && TREBLE=0
[ ! "$BASS" ] && BASS=0
[ ! "$TEMPO" ] && TEMPO=100
#read status for normalize checkbox
NORMALIZE="`grep -F NORMALIZE $CONFIG 2> /dev/null | cut -d= -f2`"

GUI_NORMALIZE='
<checkbox tooltip-markup="'"$(gettext "This is handy when your tracks comes from different sources, since the recording level is not the same.
 
Depending on your system, the volume calculation will give a small gap before playing")"'" space-expand="false" space-fill="false">
 <label>'$(gettext 'Normalize (Unify volume of all audio tracks)')'</label>
 <variable>NORMALIZE</variable>
 <default>'$NORMALIZE'</default>
 <action>. '$APPDIR'/func_config -write_config</action>
</checkbox>'

GUI_SOUND_INPUT='
<vbox space-expand="true" space-fill="true">
 <text xalign="1" use-markup="true" space-expand="false" space-fill="false"><label>"<i>'$(gettext 'Restart track to hear effect')'</i> - <b><span color='"'#FF0000'"'>'$(gettext 'Not realtime')'</span></b>"</label></text>
 '$GUI_NORMALIZE'
 <hbox height-request="120" space-expand="true" space-fill="true"> 
  <hbox space-expand="false" space-fill="false">
   <text xalign="1" yalign="1" use-markup="true" wrap="false" angle="90" space-expand="false" space-fill="false"><label>"<b>'$(gettext 'Treble')'</b>"</label></text>
   <vscale width-request="39" range-max="10" range-min="-20" range-step="1" value-pos="2" inverted="true" space-expand="false" space-fill="false">
    <variable>TREBLE</variable>
    <default>'$TREBLE'</default>
    <item>"0|2|dB"</item>
    <action>'$APPDIR'/func_mixer -activate_effects</action>
   </vscale>
   <vscale width-request="28" range-max="10" range-min="-20" range-step="1" value-pos="2" inverted="true" space-expand="false" space-fill="false">
    <variable>BASS</variable>
    <default>'$BASS'</default>
    <item>"0|0|"</item>
    <action>'$APPDIR'/func_mixer -activate_effects</action>
   </vscale>
   <text xalign="0" yalign="1" use-markup="true" wrap="false" angle="90" space-expand="false" space-fill="false"><label>"<b>'$(gettext 'Bass')'</b>"</label></text>
  </hbox>

  <text width-request="30" space-expand="true" space-fill="true"><label>""</label></text>

  <hbox spacing="0" space-expand="false" space-fill="false">
   <vscale width-request="39" range-max="200" range-min="50" range-step="1" value-pos="2" inverted="true" space-expand="false" space-fill="false">
    <variable>TEMPO</variable>
    <default>'$TEMPO'</default>
    <item>"100|2|"</item>
    <action>'$APPDIR'/func_mixer -activate_effects</action>
   </vscale>
   <text xalign="0" yalign="1" use-markup="true" wrap="false" angle="90" space-expand="false" space-fill="false"><label>"<b>'$(gettext 'Tempo')'</b> (%)"</label></text>
   <text width-request="20" space-expand="true" space-fill="true"><label>""</label></text>
   <vscale width-request="39" range-max="9" range-min="0" range-step="1" value-pos="2" inverted="true" space-expand="false" space-fill="false">
    <variable>FADE_IN</variable>
    <default>'$FADE_IN'</default>
    <action>'$APPDIR'/func_mixer -activate_effects</action>
   </vscale>
   <text xalign="0" yalign="1" use-markup="true" wrap="false" angle="90" space-expand="false" space-fill="false"><label>"<b>'$(gettext 'Fade in')'</b> (sec)"</label></text>
  </hbox>
 </hbox>
</vbox>'
