zIRCk Final Project — File Browser

zIRCkFinalProjectv2.5 / zIRCkFinalProjectv2.5 / System / script10.mrc

script10.mrc — 35.19 KB — Download this file

[SCRIPT]
NAME=zAmp Audio Player
VERSION=2.5

; ## Aliases

alias zamp { if (!$dialog(zamp)) { dialog -m $+ $iif($zread(Setup,Desktop) = on,d) zamp zamp } | else { dialog -v zamp } }
alias zcfg { $iif(!$dialog(zcfg),dialog -m zcfg zcfg,dialog -v zcfg) }
alias zplcreate { $iif(!$dialog(zplcreate),dialog -m zplcreate zplcreate,dialog -v zplcreate) }

alias -l mp3msg { $iif(!$dialog(mp3msg),dialog -m mp3msg mp3msg,dialog -v mp3msg) }
alias -l zadv { $iif(!$dialog(zadv),dialog -m zadv zadv,dialog -v zadv) }

alias zcon { .writeini $shortfn($scriptdirzamp\zamp.ini) $1 $2 $3- }
alias zschm { .write $shortfn($scriptdirzamp\schemes.zmp) $1- }
alias zread { return $readini($shortfn($scriptdirzamp\zamp.ini),$1,$2) }
alias zicl { return $shortfn($scriptdirzamp\ $+ $zread(Setup,Icl)) }
alias zsong { return $replace($nopath($remove($longfn($zread(MP3,MP3)),.mp3,.wav,.wma,.mp2)),_,$chr(32)) }
alias _dat { return $shortfn($scriptdirzAmp\ $+ $1 $+ .zmp) }

alias pop1 { 
  tokenize 32 $dll($shortfn($scriptdirDll\popups.dll),Popup,$1-) 
  if ($isid) return $1- 
  $iif($4- != did not select a menu item,$4-)
}

alias zpop {
  if ($1 = 1) {
    if ($zread(MP3,Search) = on) && ($zread(MP3,Playlist)) {
      var %a = srch 
      popup New %a 16 16
      popup SetMetrics %a iconpad 10 0 contentpad 0 0 spacing 1 0
      popup LoadImg %a icon small $shortfn($scriptdirzAmp\search.ico)
      $iif($did(zamp,7).lines,popup AddItem %a end +d Found $ifmatch matches)
      $iif($did(zamp,7).lines,popup AddItem %a end +)
      popup AddItem %a end +D 1 1 Search (Enter) $cr zamp_searchq
      popup AddItem %a end + Clear search results $cr $iif($dialog(zamp),did -r zamp 7) 
      popup AddItem %a end + Return to playlist $cr zamp_showsearch 0
      pop1 %a $mouse.dx $mouse.dy
    }
    else {
      var %a = plmenu
      popup New %a 16 16
      popup SetMetrics %a iconpad 10 0 contentpad 0 0 spacing 1 0
      popup LoadImg %a icon small $shortfn($scriptdirzAmp\Playlist.ico)
      popup LoadImg %a icon small $shortfn($scriptdirzAmp\search.ico)
      popup AddItem %a 1 1 Playlist: $iif($zread(MP3,Playlist),$remove($nopath($longfn($ifmatch)),.txt),None Selected) $cr plmenu_loadlist
      popup AddItem %a 0 0 Playlist editor $cr zplcreate
      popup AddItem %a end +
      popup AddItem %a end + $+ $iif(!$zread(MP3,Playlist),d) 2 2 Search... $cr zamp_showsearch 1
      pop1 %a $mouse.dx $mouse.dy
    }
  }
  elseif ($1 = 2) {
    var %a = zplcreate
    popup New %a 16 16
    popup SetMetrics %a iconpad 10 0 contentpad 0 0 spacing 1 0
    popup LoadImg %a icon small $shortfn($scriptdirzAmp\directory.ico)
    popup LoadImg %a icon small $shortfn($scriptdirzAmp\Playlist.ico) 
    popup AddItem %a 1 1 Directory $cr plmenu_dir
    popup AddItem %a 2 2 Playlist  $cr plmenu_pl
    pop1 %a $mouse.dx $mouse.dy
  }
  elseif ($1 = 3) {
    var %a = zplcreate_pl
    popup New %a 16 16
    popup SetMetrics %a iconpad 10 0 contentpad 0 0 spacing 1 0
    popup LoadImg %a icon small $shortfn($scriptdirzAmp\remove.ico)
    popup AddItem %a 1 1 Remove $cr zplcreate_rem
    popup AddItem %a end +
    popup AddItem %a 0 0 Move up $cr pl_moveup
    popup AddItem %a 0 0 Move down $cr pl_movedown
    pop1 %a $mouse.dx $mouse.dy
  }
  elseif ($1 = 4) {
    var %a = zplcreate_pldir
    popup New %a 16 16
    popup SetMetrics %a iconpad 10 0 contentpad 0 0 spacing 1 0
    popup LoadImg %a icon small $shortfn($scriptdirzAmp\directory.ico)
    popup AddItem %a end + 0 0 Add file to playlist $cr pl_addfile
    popup AddItem %a end + 1 1 Add whole directory to playlist $cr pl_adddir
    pop1 %a $mouse.dx $mouse.dy
  }
  elseif ($1 = 5) {
    var %a = zamp_modes 
    popup New %a 16 16
    popup SetMetrics %a iconpad 10 0 contentpad 0 0 spacing 1 0
    popup AddItem %a end + $+ $iif($zread(MP3,Mode) = rep,x) Repeat once $cr zamp_playmode 2
    popup AddItem %a end + $+ $iif($zread(MP3,Mode) = cont,x) Repeat all $cr zamp_playmode 1
    popup AddItem %a end + $+ $iif($zread(MP3,Mode) = shuffle,x) Shuffle $cr zamp_playmode 3
    pop1 %a $mouse.dx $mouse.dy
  }
}

alias mp3_prev {
  var %x = $read($zread(MP3,Playlist), w, * $+ $longfn($zread(MP3,MP3)) $+ *)
  if (%x) { 
    var %line = $readn 
    if (%line >= 1) && (%line < 2) { 
      var %line = $lines($zread(MP3,Playlist))
      zcon MP3 MP3 $shortfn($read($zread(MP3,Playlist), %line))
      if ($dialog(zamp)) {
        did -c zamp 12 $calc(%line)
      }
      mp3_play
    }
    else { 
      zcon MP3 MP3 $shortfn($read($zread(MP3,Playlist),$calc(%line - 1)))
      if ($dialog(zamp)) {
        did -c zamp 12 $calc(%line -1)
      }
      mp3_play 
    }
  }
}

alias mp3_next {
  var %x = $read($zread(MP3,Playlist), w, * $+ $longfn($zread(MP3,MP3)) $+ *)
  var %c = $readn,%lines = $lines($_dat(pl))
  if (%x) { 
    var %line = $readn 
    if (%line == $lines($zread(MP3,Playlist))) { 
      var %line = 1
      zcon MP3 MP3 $shortfn($read($zread(MP3,Playlist), %line))
      if ($dialog(zamp)) {
        did -c zamp 12 $calc(%line)
      }
      mp3_play
    }
    else { 
      zcon MP3 MP3 $shortfn($read($zread(MP3,Playlist),$calc(%line + 1)))
      if ($dialog(zamp)) {
        did -c zamp 12 $calc(%line +1)
      }
      mp3_play 
    }
  }
}

alias mp3_pause {
  if $insong {
    if ($1 = +xca) { 
      splay pause
      zcon MP3 Pause Pause
    }
    elseif ($1 = +ca) { 
      splay resume
      zcon MP3 Pause Resume
    }
  }
}

alias mp3_stop { 
  if ($zread(MP3,MP3)) {
    .splay stop
    .timermpos off
    .timerscroll off
    if ($dialog(zamp)) {
      did -ra zamp 1 $chr(160) $iif($len($zsong) > 30,$left($zsong,32) $+ ...,$zsong)
      did -ra zamp 2 $chr(160) 00:00 / $mlen($zread(MP3,MP3))
      did -i zamp 10 1 params 0
      $iif($zread(Setup,Titlebar) = on,dialog -t zamp zAmp $iif($zread(Setup,Alias) = off,[/zAmp]))
    }
  }
}

alias mp3_play { 
  if (!$zread(MP3,MP3)) || ($1 = -o) {
    var %x = $+(",$sfile(C:,Select a file to open,Open),")
    if (%x) { zcon MP3 MP3 %x }
  }
  if ($zread(MP3,MP3)) { 
    .splay -wp " $+ $shortfn($zread(MP3,MP3)) $+ "
    $iif($dialog(zamp) && $zread(Setup,Titlebar) = on,dialog -t zamp $zsong)
    $iif($dialog(zamp),did -ra zamp 3 $sound($zread(MP3,MP3)).bitrate $+ kbps $+ / $+ $calc($sound($zread(MP3,MP3)).sample / 1000) $+ khz $chr(160))
    $iif($dialog(zamp),did -ra zamp 1 $chr(160) $iif($len($zsong) > 30,$left($zsong,32) $+ ...,$zsong))
    if ($dialog(zamp)) { .timermpos 0 1 did -ra zamp 2 $chr(160) $!mpos / $mlen }
    $iif($dialog(zamp),.timerscroll 0 1 mp3_scroll)
    if ($zread(Setup,Advertise) = on && $chan(0) > 0) {
      if ($zread(Setup,ADMeth) = active) {
        if ($zread(Setup,MsgType) = custom) { 
          .scid $activecid ame $replace($zread(Setup,CustomMsg),<artist>,$iif($sound($zread(MP3,MP3)).artist,$ifmatch,Unknown artist),<title>,$iif($sound($zread(MP3,MP3)).title,$ifmatch,Unknown title),<dur>,$mlen($zread(MP3,MP3)),<kbps>,$zamp_kbps($zread(MP3,MP3)) $+ kbps,<khz>,$_khz($zread(MP3,MP3)) $+ khz,<fname>,$zsong,<bold>,,<underline>,))
        }
        elseif ($zread(Setup,MsgType) = random) {
          .scid $activecid ame $replace($read($shortfn($scriptdirzAmp\mp3msg.zmp)),<artist>,$iif($sound($zread(MP3,MP3)).artist,$ifmatch,Unknown artist),<title>,$iif($sound($zread(MP3,MP3)).title,$ifmatch,Unknown title),<dur>,$mlen($zread(MP3,MP3)),<kbps>,$zamp_kbps($zread(MP3,MP3)) $+ kbps,<khz>,$_khz($zread(MP3,MP3)) $+ khz,<fname>,$zsong,<bold>,,<underline>,))
        }
      }
      elseif ($zread(Setup,ADMeth) = all) {
        mp3_netadv
      }
      elseif ($zread(Setup,ADMeth) = specified) {
        var %x = 1 
        while %x <= $scon(0) {
          scon %x
          var %i = 1
          while (%i <= $chan(0)) {
            var %c = 1
            while (%c <= $lines($_dat(adtargets))) {
              if ($gettok($read($_dat(adtargets), %c),1,42) = $chan(%i)) && ($gettok($read($_dat(adtargets), %c),2,42) = $scon(%x).network) && ($me ison $chan(%i)) {
                describe $chan(%i) $iif($rconf(Setup,MsgType) = custom,$zamp_advstring(1),$zamp_advstring(2))
              }
              inc %c
            }
            inc %i
          }
          inc %x
        }
        .timer -m 1 1 load.sb
      }
    }
  }
}

alias zamp_advstring {
  return $replace($iif($1 = 1,$rconf(Setup,CustomMsg),$read($_dat(mp3msg))),<artist>,$iif($sound($zread(MP3,MP3)).artist,$ifmatch,Unknown artist),<title>,$iif($sound($zread(MP3,MP3)).title,$ifmatch,Unknown title),<dur>,$mlen($zread(MP3,MP3)),<kbps>,$zamp_kbps($zread(MP3,MP3)) $+ kbps,<khz>,$_khz($zread(MP3,MP3)) $+ khz,<fname>,$zsong,<bold>,,<underline>,))
}

alias -l zamp.showpl {
  if ($1 = +xca) { 
    dialog -s $dname -1 -1 214 278
  }
  elseif ($1 = +ca) { 
    dialog -s $dname -1 -1 214 84
  }
}

alias zamp_showsearch {
  if $1 = 0 {
    did -h zamp 6,7
    did -v zamp 12,13,14
    zcon MP3 Search off
  }
  elseif $1 = 1 {
    did -h zamp 12,13,14
    did -v zamp 6,7
    zcon MP3 Search on
  }
}

alias zamp_searchq { 
  if ($dialog(zamp) && $zread(MP3,Search) = on && $did(zamp,6).text) {
    set %zsearch $+(*,$did(zamp,6).text,*)
    did -r zamp 7
    $iif(!$window(@zplsearch),window -h @zplsearch)
    $iif($window(@zplsearch),clear -@ @zplsearch)
    set %zct 1
    .filter -k $shortfn($zread(MP3,Playlist)) zplsearch_add
  }
}

alias zamp_playmode {
  if $1 = 1 { zcon MP3 Mode cont }
  elseif $1 = 2 { zcon MP3 Mode rep }
  elseif $1 = 3 { zcon MP3 Mode shuffle }
}

alias pl_addfile {
  if $did(zplcreate,1).sel {
    var %s = $calc($did(zplcreate,1).sel -1)
    did -a zplcreate 2 0 0 0 0 $remove($nopath($line(@DIR,%s)),.mp3,.wav,.wma,.mp2)
    aline @PL $+(",$line(@DIR,%s),")
  }
}

alias pl_adddir { 
  set %pl.inc 1
  .filter -k $window(@DIR) pl_writedir
  did -r zplcreate 2
  .filter -k $window(@PL) zplcreate_pl
}

alias pl_moveup {
  if ($did(zplcreate,2).sel) {
    var %s = $calc($ifmatch -1)
    iline @PL $calc(%s -1) $line(@PL,$calc(%s))
    dline @PL $calc(%s +1)
    did -r zplcreate 2 
    .filter -k $window(@PL) zplcreate_pl
    did -c zplcreate 2 %s
  }
}

alias pl_movedown {
  if ($did(zplcreate,2).sel) {
    var %s = $calc($ifmatch -1)
    iline @PL $calc(%s +2) $line(@PL,$calc(%s))
    dline @PL %s
    did -r zplcreate 2 
    .filter -k $window(@PL) zplcreate_pl
    did -c zplcreate 2 $calc(%s +2)
  }
}

alias zplcreate_rem {
  if ($did(zplcreate,2).sel) {
    var %s = $calc($did(zplcreate,2).sel -1)
    $iif($zread(MP3,Playlist),.write -dl $+ %s $shortfn($zread(MP3,Playlist)))
    dline @PL %s
    did -r zplcreate 2
    .filter -k $window(@PL) zplcreate_pl
  }
}

alias plmenu_loadlist {
  var %x = $sfile($shortfn($scriptdirzAmp\Playlists\),Select a playlist to load)
  if %x {
    zcon MP3 Playlist $shortfn(%x)
    if ($dialog(zamp)) {
      did -r zamp 12
      did -e zamp 13,14
      set %zct 1
      .filter -k $shortfn($zread(MP3,Playlist)) zpl_load
    }
  }
}

alias plmenu_dir {
  var %x = $sdir(C:\,Select a directory to open)
  if %x {
    clear -@ @DIR
    $iif($dialog(zplcreate),did -r zplcreate 1)
    var %c = $findfile(%x,*.mp3,0,aline @DIR $1-)
    var %c = $findfile(%x,*.wma,0,aline @DIR $1-)
    var %c = $findfile(%x,*.wav,0,aline @DIR $1-)
    var %c = $findfile(%x,*.mp2,0,aline @DIR $1-)
    .filter -k $window(@DIR) zplcreate_dir
  }
}

alias plmenu_pl {
  var %x = $sfile($shortfn($scriptdirzAmp\playlists\),Select a playlist to open)
  if %x {
    clear -@ @PL
    loadbuf 0 @PL $+(",%x,")
    did -r zplcreate 2
    .filter -k %x zplcreate_pl
  }
}

alias _khz { return $round($calc($sound($1-).sample / 1000),0) }

alias -l mp3_scroll { 
  if ($dialog(zamp)) { 
    did -i zamp 10 1 params $round($calc($calc($inmp3.pos / $inmp3.length) * 100),0) 
  } 
  else { .timerscroll off }
}

alias zamp_kbps { return $sound($1-).bitrate }

alias mp3_netadv {
  var %i = 1,%l = $zsong
  while (%i <= $scid(0)) {
    scid $scon(%i)
    var %c = 1
    while (%c <= $chan(0)) {
      if ($zread(Setup,MsgType) = custom) { 
        describe $chan(%c) $replace($zread(Setup,CustomMsg),<artist>,$sound($zread(MP3,MP3)).artist,<title>,$sound($zread(MP3,MP3)).title,<dur>,$mlen($zread(MP3,MP3)),<kbps>,$sound($zread(MP3,MP3)).bitrate $+ .kbps,<khz>,$_khz $+ .khz,<fname>,%l,<bold>,,<underline>,)
      }
      else {
        describe $chan(%c) $replace($read($shortfn($scriptdirzamp\mp3msg.zmp)),<artist>,$sound($zread(MP3,MP3)).artist,<title>,$sound($zread(MP3,MP3)).title,<dur>,$mlen($zread(MP3,MP3)),<kbps>,$sound($zread(MP3,MP3)).bitrate $+ .kbps,<khz>,$_khz $+ .khz,<fname>,%l,<bold>,,<underline>,)
      }
      inc %c
    }
    inc %i
  }
  .timer -m 1 1 load.sb 
}

alias mpos {
  if (!$insong) { return 2 | halt }
  var %x = $calc($insong.pos /1000)
  return $gmt(%x,$iif(%x >= 3600,hh:nn:ss,nn:ss))
}

alias mlen {
  if ($1) {
    if (!$exists($1-)) { return 1 | halt }
    var %x = $calc($sound($1-).length /1000)
    return $gmt(%x,$iif(%x >= 3600,hh:nn:ss,nn:ss))
  }
  if (!$1) {
    if (!$insong) { return 2 | halt }
    var %x = $calc($insong.length /1000)
    return $gmt(%x,$iif(%x >= 3600,hh:nn:ss,nn:ss))
  }
}

alias zplcreate_pl { did -a zplcreate 2 0 0 0 0 $remove($nopath($1-),.mp3,.wav,.wma,.mp2) }
alias zplcreate_dir { did -a zplcreate 1 0 0 0 0 $remove($nopath($1-),.mp3,.wav,.wma,.mp2) }
alias zpl_load { did -a zAmp 12 %zct $+ . $remove($nopath($1-),.mp3,.wav,.wma,.mp2) | inc %zct }
alias -l load.mp3msg { .filter -k $shortfn($scriptdirzamp\mp3msg.zmp) add_mp3msg } 
alias -l add_mp3msg { did -a mp3msg 2 $1- }
alias zadv_add { did -a zadv 1 $gettok($1-,1,42) $chr(9) $gettok($1-,2,42) }
alias zplsearch_add { if (%zsearch iswm $1-) { did -a zamp 7 %zct $+ . $nopath($remove($1-,.mp3,.wav,.wma)) | aline @zplsearch $1- | inc %zct } } 
alias pl_writedir { aline @PL $line(@DIR,%pl.inc) | inc %pl.inc }

alias zsch_add { did -a zcfg 26 $gettok($1-,1,42) $chr(9) $gettok($1-,2,42) }

alias zscheme_update {
  var %z = $gettok($read($shortfn($scriptdirzAmp\Schemes.zmp),$zread(Setup,SchemeID)),3,42)
  var %txtbg = $gettok($read($shortfn($scriptdirzAmp\Schemes.zmp),$zread(Setup,SchemeID)),4,42)
  var %txt = $gettok($read($shortfn($scriptdirzAmp\Schemes.zmp),$zread(Setup,SchemeID)),5,42)

  var %z1 = $gettok(%z,1,44),%z2 = $gettok(%z,2,44),%z3 = $gettok(%z,3,44)
  var %tb1 = $gettok(%txtbg,1,44),%tb2 = $gettok(%txtbg,2,44),%tb3 = $gettok(%txtbg,3,44)
  var %t1 = $gettok(%txt,1,44),%t2 = $gettok(%txt,2,44),%t3 = $gettok(%txt,3,44)
  if $1 = zamp { goto zamp }
  if ($dialog(zamp)) {
    :zamp
    mdx SetColor zamp 1,2,3,6,7 background $rgb(%z1,%z2,%z3)
    mdx SetColor zamp 1,2,3,6,7 textbg $rgb(%z1,%z2,%z3)
    mdx SetColor zamp 1,2,3,6,7 text $rgb(%t1,%t2,%t3)
    did -h zamp 12

    mdx SetColor zamp 12 background $rgb(%tb1,%tb2,%tb3)
    mdx SetColor zamp 12 textbg $rgb(%tb1,%tb2,%tb3)
    mdx SetColor zamp 12 text $rgb(%t1,%t2,%t3)
    did -v zamp 12
  }
  if $1 = zplcreate { goto zplcreate }
  if ($dialog(zplcreate)) {
    :zplcreate
    if ($zread(Setup,Scheme) = on) {
      did -i zplcreate 1,2 1 setbkg color $rgb(%tb1,%tb2,%tb3)
      did -i zplcreate 1,2 1 settxt bgcolor $rgb(%tb1,%tb2,%tb3)
      did -i zplcreate 1,2 1 settxt color $rgb(%t1,%t2,%t2)
    }
  }
  if $1 = zcfg { goto zcfg }
  if ($dialog(zcfg)) {
    :zcfg
    if ($zread(Setup,Scheme) = on) {
      mdx SetColor zcfg 16 background $rgb(%tb1,%tb2,%tb3)
      mdx SetColor zcfg 16 textbg $rgb(%tb1,%tb2,%tb3)
      mdx SetColor zcfg 16 text $rgb(%t1,%t2,%t3)
      did -i zcfg 26 1 setbkg color $rgb(%tb1,%tb2,%tb3)
      did -i zcfg 26 1 settxt bgcolor $rgb(%tb1,%tb2,%tb3)
      did -i zcfg 26 1 settxt color $rgb(%t1,%t2,%t2)
    }
  }
  if $1 = addscheme { goto addscheme }
  if ($dialog(addscheme)) {
    :addscheme
    if ($zread(Setup,Scheme) = on) {
      mdx SetColor addscheme 2,4,5 background $rgb(%tb1,%tb2,%tb3)
      mdx SetColor addscheme 2,4,5 textbg $rgb(%tb1,%tb2,%tb3)
      mdx SetColor addscheme 2,4,5 text $rgb(%t1,%t2,%t3)
    }
  }
  if $1 = mp3msg { goto mp3msg }
  if ($dialog(mp3msg)) {
    :mp3msg
    if ($zread(Setup,Scheme) = on) { 
      did -i mp3msg 2 1 setbkg color $rgb(%tb1,%tb2,%tb3)
      did -i mp3msg 2 1 settxt color $rgb(%t1,%t2,%t2)
      did -i mp3msg 2 1 settxt bgcolor $rgb(%tb1,%tb2,%tb3)
      mdx SetColor mp3msg 3 textbg $rgb(%tb1,%tb2,%tb3)
      mdx SetColor mp3msg 3 background $rgb(%tb1,%tb2,%tb3)
      mdx SetColor mp3msg 3 text $rgb(%t1,%t2,%t3)
    }
  }
  if $1 = zadv { goto zadv }
  if ($dialog(zadv)) {
    :zadv
    if ($zread(Setup,Scheme) = on) {
      did -i zadv 1 1 setbkg color $rgb(%tb1,%tb2,%tb3)
      did -i zadv 1 1 settxt bgcolor $rgb(%tb1,%tb2,%tb3)
      did -i zadv 1 1 settxt color $rgb(%t1,%t2,%t2)
    }
  }
}

alias load_rgb {
  did -ra rgb 7 $hget(rgb,red)
  did -ra rgb 8 $hget(rgb,green)
  did -ra rgb 9 $hget(rgb,blue)
  mdx SetColor rgb 10 background $rgb($hget(rgb,red),$hget(rgb,green),$hget(rgb,blue))
}

alias zaddscheme { $iif(!$dialog(addscheme),dialog -m addscheme addscheme,dialog -v addscheme) }

; DIALOGS 

dialog zAmp {
  title "zAmp [/zAmp]"
  size -1 -1 107 42
  option dbu
  icon $shortfn($scriptdirzamp\zamp.ico), 0
  text "", 1, 2 2 103 7
  text "", 2, 2 9 60 8
  text "", 3, 62 9 43 8, right
  list 10, 0 20 107 10, size
  list 12, 1 43 105 81, size
  button "+ Add", 13, 2 127 18 10
  button "- Del", 14, 23 127 18 10
  box "", 15, 1 -2 105 20
  list 4, 5 30 107 12, size
  button "...", 5, 87 127 18 10
  edit "", 6, 1 127 82 10,hide
  list 7, 1 43 105 81, hide size
  button "", 8, 171 24 18 6, default
}

on *:dialog:zamp:init:0: {
  var %t = $dialog($dname).title
  $iif($zread(Setup,Alias) = on,dialog -t $dname $gettok(%t,1,91))
  if (!$zread(MP3,Playlist)) { did -b $dname 13,14 }
  mdx MarkDialog $dname
  mdxbutton zamp 5,8,13,14
  mdx SetFont $dname 1 -10 700 Tahoma
  mdx SetFont $dname 2,3,6,7,12,13,14,15 -10 400 Tahoma
  mdx SetControlMDX $dname 10 Trackbar > $bars
  mdx SetControlMDX $dname 4 Toolbar flat wrap nodivider > $bars
  mdx SetBorderStyle $dname 4,10
  did -i $dname 10 1 params * * * * * * * 10
  did -i $dname 4 1 bmpsize 16 16
  did -i $dname 4 1 setimage icon small 0, $+ $zicl
  did -i $dname 4 1 setimage icon small 1, $+ $zicl
  did -i $dname 4 1 setimage icon small 2, $+ $zicl
  did -i $dname 4 1 setimage icon small 3, $+ $zicl
  did -i $dname 4 1 setimage icon small 4, $+ $zicl
  did -i $dname 4 1 setimage icon small $shortfn($scriptdirzamp\playlist.ico)
  did -i $dname 4 1 setimage icon small $shortfn($scriptdirzamp\options.ico)
  did -i $dname 4 1 setimage icon small $shortfn($scriptdirzamp\modes.ico)
  did -a $dname 4 +a 1 $chr(9) $+ Previous
  did -a $dname 4 +a 2 $chr(9) $+ Play
  did -a $dname 4 +ac 3 $chr(9) $+ Pause
  did -a $dname 4 +a 4 $chr(9) $+ Stop
  did -a $dname 4 +a 5 $chr(9) $+ Next
  did -a $dname 4 -
  did -a $dname 4 +ac 6 $chr(9) $+ Playlist
  did -a $dname 4 +a 7 $chr(9) $+ Options
  did -a $dname 4 +a 8 $chr(9) $+ Modes
  did -ra $dname 1 $chr(160) $iif(!$zread(MP3,MP3),Standing by...,$iif($len($zsong) > 30,$left($zsong,32) $+ ...,$zsong))
  if (!$zread(MP3,MP3)) { 
    did -ra $dname 2 $chr(160) 00:00 / 00:00
    did -ra $dname 3 khz/kbps $chr(160)
  } 
  else { 
    did -ra $dname 2 $chr(160) 00:00 / $mlen($zread(MP3,MP3)) 
    did -ra $dname 3 $sound($zread(MP3,MP3)).bitrate $+ kbps $+ / $+ $calc($sound($zread(MP3,MP3)).sample / 1000) $+ khz $chr(160) 
  } 
  if ($insong) {
    did -ra $dname 3 $sound($zread(MP3,MP3)).bitrate $+ kbps $+ / $+ $calc($sound($zread(MP3,MP3)).sample / 1000) $+ khz $chr(160)
    did -ra $dname 1 $chr(160) $iif($len($zsong) > 30,$left($zsong,32) $+ ...,$zsong)
    .timermpos 0 1 /did -ra zamp 2 $chr(160) $!mpos / $!mlen
    .timerscroll 0 1 mp3_scroll
  }
  zscheme_update zamp
  if ($zread(MP3,Playlist)) {
    set %zct 1
    .filter -k $shortfn($zread(MP3,Playlist)) zpl_load
  }
  $iif($insong && $zread(Setup,Titlebar) = on,dialog -t zamp $zsong)
  if ($zread(MP3,Search) = on) { zamp_showsearch 1 }
}

on *:dialog:zamp:sclick:4: {
  var %s = $calc($did($dname,4).sel -1)
  if %s = 1 { mp3_prev }
  elseif %s = 2 { mp3_play }
  elseif %s = 3 { mp3_pause $gettok($did($dname,4).seltext,1,32) }
  elseif %s = 4 { mp3_stop }
  elseif %s = 5 { mp3_next }
  elseif %s = 7 { zamp.showpl $gettok($did($dname,4).seltext,1,32) }
  elseif %s = 8 { zcfg }
  elseif %s = 9 { zpop 5 }
}

on *:dialog:zamp:sclick:5: { zpop 1 }

on *:dialog:zamp:sclick:8: {
  if ($zread(MP3,Search) = on) {
    zamp_searchq
  }
}

on *:dialog:zamp:dclick:7: {
  var %s = $did(zamp,7).sel
  if %s {
    zcon MP3 MP3 $shortfn($line(@zplsearch,%s))
    mp3_play
  }
}

on *:DIALOG:zamp:sclick:10:{ 
  if ($gettok($did($dname,10).seltext,9,32) = end) { 
    $iif($inmp3,splay seek $round($calc($calc($gettok($did(zamp,10).seltext,1,32) / 100) * $inmp3.length),0))
  }
}

on *:dialog:zamp:dclick:12: {
  if ($did($dname,12).sel) {
    var %sel = $did($dname,12).sel
    zcon MP3 MP3 $shortfn($read($zread(MP3,Playlist), %sel))
    mp3_play
  }
}

on *:dialog:zamp:sclick:13: {
  var %x = $sfile(C:,Select MP3 to add...,Select)
  if (%x) { 
    write $zread(MP3,Playlist) %x
    if ($dialog(zamp)) {
      did -r zamp 12
      set %zct 1
      .filter -k $shortfn($zread(MP3,Playlist)) zpl_load
    }
  }
}

on *:dialog:zamp:sclick:14: {
  if ($did($dname,12).sel) {
    var %sel = $did($dname,12).sel
    write -dl $+ %sel $zread(MP3,Playlist)
    did -r $dname 12
    set %zct 1
    .filter -k $shortfn($zread(MP3,Playlist)) zpl_load
  }
}

on *:dialog:zamp:close:0: {
  .timerscroll off
  .timermpos off
}

dialog zplcreate {
  title "Playlist Editor [/zplcreate]"
  size -1 -1 166 148
  option dbu
  icon $shortfn($scriptdirzAmp\directory.ico), 0
  list 1, 2 49 78 80, size
  list 2, 86 49 78 80, size
  box "", 3, 83 55 1 65
  button "Done", 4, 127 133 37 12, ok
  button "Open", 5, 3 133 27 12
  button "Save", 6, 33 133 27 12
  text "Click Open to open a directory or existing playlist file. Right click in the left list to add the selected file or whole directory. Once done adding all the files to the playlist, click Save to save your playlist. You can also move files in the playlist up or down in proper order (right click on the right list)", 8, 2 13 162 34
  text "Playlist editor usage:", 7, 2 2 62 8
}

on *:dialog:zplcreate:init:0: {
  var %t = $dialog($dname).title
  $iif($zread(Setup,Alias) = on,dialog -t $dname $gettok(%t,1,91))
  window -h @DIR
  window -h @PL
  mdx MarkDialog $dname
  mdxbutton zplcreate 4,5,6
  mdx SetFont $dname 1,2,4,5,6,8 -11 400 Tahoma
  mdx SetFont $dnmae 7 -11 700 Tahoma
  mdx SetControlMDX $dname 1,2 Listview report showsel rowselect noheader > $views
  did -i $dname 1,2 1 headerdims 135
  zscheme_update zplcreate
}

on *:dialog:zplcreate:dclick:1: {
  pl_addfile
}

on *:dialog:zplcreate:sclick:1: {
  if ($gettok($did($dname,1,1),1,32) = rclick) { 
    zpop 4
  }
}

on *:dialog:zplcreate:sclick:2: {
  if ($gettok($did($dname,2,1),1,32) = rclick) { 
    zpop 3
  }
}

on *:dialog:zplcreate:sclick:6: {
  var %x = $$?="Enter playlist name:"
  if %x {
    savebuf 0 @PL $+(",$scriptdirzAmp\Playlists\,%x,.txt")
  }
}

on *:dialog:zplcreate:close:0: {
  window -c @DIR
  window -c @PL
}

on *:dialog:zplcreate:sclick:5: { zpop 2 }

dialog zcfg {
  title "zAmp Config [/zcfg]"
  size -1 -1 145 113
  option dbu
  icon $shortfn($scriptdirzAmp\options.ico), 0
  tab "General", 1, 2 1 140 93
  check "Allow zAmp to open on the desktop", 2, 6 22 98 10, tab 1
  check "When playing, change zAmp titlebar to playing song", 3, 6 31 134 10, tab 1
  check "Don't show aliases in all of zAmps' dialogs", 4, 6 40 110 10, tab 1
  check "Use scheme colors on all of zAmps' dialogs", 5, 6 49 119 10, tab 1
  text "Button set:", 6, 6 75 64 8, tab 1
  combo 7, 71 73 68 50, tab 1 size
  tab "Advertising", 8
  check "Advertise", 10, 6 22 36 10, tab 8
  radio "Active network", 11, 44 22 48 10, group tab 8
  radio "Specified", 13, 44 31 36 10, tab 8
  radio "All networks", 12, 96 22 40 10, tab 8
  radio "Use random messages", 14, 6 49 68 10, group tab 8
  radio "Use pre-made message", 15, 6 58 67 10, tab 8
  edit "", 16, 17 68 122 10, tab 8 autohs
  text "Tags: ", 17, 16 79 17 8, disable tab 8
  text "<fname>, <artist>, <title>, <dur>, <kbps>, <khz>, <bold>, <underline>", 18, 34 79 107 15, disable tab 8
  box "", 19, 12 41 120 4, tab 8
  button "Messages", 21, 64 99 37 12, tab 8
  button "Ad targets", 22, 23 99 37 12, tab 8
  box "", 20, 103 96 1 15, tab 8
  tab "Schemes", 25
  list 26, 5 17 134 74, tab 25 size
  button "Delete", 28, 64 99 37 12, tab 25
  button "Add", 29, 23 99 37 12, tab 25
  box "", 27, 103 96 1 15, tab 25
  button "Done", 9, 106 99 37 12, ok
  box "", 23, 12 62 120 4, tab 1
}

on *:dialog:zcfg:init:0: {
  var %t = $dialog($dname).title
  $iif($zread(Setup,Alias) = on,dialog -t $dname $gettok(%t,1,91))
  mdx MarkDialog $dname
  mdxbutton zcfg 9,21,22,28,29
  mdx SetFont $dname 2,3,4,5,6,7,9,10,11,12,13,14,15,16,21,22,26,28,29 -11 400 Tahoma
  mdx SetFont $dname 17,18 -11 700 Tahoma
  mdx SetControlMDX $dname 7 ComboBoxEx drop > $views
  mdx SetControlMDX $dname 26 Listview report single showsel rowselect > $views
  did -i $dname 26 1 headerdims 115 180
  did -i $dname 26 1 headertext Scheme $chr(9) Description
  .filter -k $shortfn($scriptdirzAmp\Schemes.zmp) zsch_add
  did -i $dname 7 1 iconsize small
  var %i = 1,%a = $calc($findfile($shortfn($scriptdirzAmp\),*.icl,0))
  while %i <= %a {
    did -i $dname 7 1 seticon 0 4, $+ $findfile($shortfn($scriptdirzAmp\),*.icl,%i)
    did -a $dname 7 %i %i 0 0 $nopath($findfile($shortfn($scriptdirzAmp\),*.icl,%i))
    inc %i
  }
  $iif($zread(Setup,Desktop) = on,did -c $dname 2)
  $iif($zread(Setup,Titlebar) = on,did -c $dname 3)
  $iif($zread(Setup,Alias) = on,did -c $dname 4)
  $iif($zread(Setup,Scheme) = on,did -c $dname 5)
  $iif($zread(Setup,Icln),did -c $dname 7 $ifmatch)
  $iif($zread(Setup,Advertise) = on,did -c $dname 10)
  $iif($zread(Setup,ADMeth) = Active,did -c $dname 11,$iif($zread(Setup,ADMeth) = All,did -c $dname 12,$iif($zread(Setup,ADMeth) = Specified,did -c $dname 13)))
  $iif($zread(Setup,MsgType) = Random,did -c $dname 14,did -c $dname 15)
  $iif($zread(Setup,CustomMsg),did -a $dname 16 $ifmatch)
  did -ra $dname 6 Button set ( $+ %a found):
  zscheme_update zcfg
}

on *:dialog:zcfg:sclick:7: {
  zcon Setup Icl $gettok($did($dname,7).seltext,5-,32)
  zcon Setup Icln $did($dname,7).sel 
  if ($dialog(zamp)) {
    did -r zamp 4
    did -i zamp 4 1 bmpsize 16 16
    did -i zamp 4 1 setimage icon small 0, $+ $zicl
    did -i zamp 4 1 setimage icon small 1, $+ $zicl
    did -i zamp 4 1 setimage icon small 2, $+ $zicl
    did -i zamp 4 1 setimage icon small 3, $+ $zicl
    did -i zamp 4 1 setimage icon small 4, $+ $zicl
    did -i zamp 4 1 setimage icon small $shortfn($scriptdirzamp\playlist.ico)
    did -i zamp 4 1 setimage icon small $shortfn($scriptdirzamp\options.ico)
    did -i zamp 4 1 setimage icon small $shortfn($scriptdirzamp\modes.ico)
    did -a zamp 4 +a 1 $chr(9) $+ Previous
    did -a zamp 4 +a 2 $chr(9) $+ Play
    did -a zamp 4 +ac $+ $iif($zread(MP3,Pause) = Pause,x) 3 $chr(9) $+ Pause
    did -a zamp 4 +a 4 $chr(9) $+ Stop
    did -a zamp 4 +a 5 $chr(9) $+ Next
    did -a zamp 4 -
    did -a zamp 4 +ac 6 $chr(9) $+ Playlist
    did -a zamp 4 +a 7 $chr(9) $+ Options
    did -a zamp 4 +a 8 $chr(9) $+ Modes
  } 
  if ($dialog(bbar)) {  
    did -r bbar 5
    did -i bbar 5 1 bmpsize 16 16
    did -i bbar 5 1 setimage icon small 0, $+ $zicl
    did -i bbar 5 1 setimage icon small 1, $+ $zicl
    did -i bbar 5 1 setimage icon small 2, $+ $zicl
    did -i bbar 5 1 setimage icon small 3, $+ $zicl
    did -i bbar 5 1 setimage icon small 4, $+ $zicl
    did -i bbar 5 1 setimage icon small $shortfn($scriptdirzamp\options.ico)
    did -a bbar 5 +a 1 $chr(9) $+ Previous
    did -a bbar 5 +a 2 $chr(9) $+ Play
    did -a bbar 5 +ac $+ $iif($zread(MP3,Pause) = Pause,x) 3 $chr(9) $+ Pause
    did -a bbar 5 +a 4 $chr(9) $+ Stop
    did -a bbar 5 +a 5 $chr(9) $+ Next
    did -a bbar 5 -
    did -a bbar 5 +a 6 $chr(9) $+ Playlist
    did -a bbar 5 -
  }
}

on *:dialog:zcfg:sclick:9: {
  zcon Setup Titlebar $iif($did($dname,3).state = 1,on,off)
  zcon Setup Desktop $iif($did($dname,2).state = 1,on,off)
  zcon Setup Alias $iif($did($dname,4).state = 1,on,off)
  zcon Setup Scheme $iif($did($dname,5).state = 1,on,off)
  zcon Setup Advertise $iif($did($dname,10).state = 1,on,off)
  zcon Setup ADMeth $iif($did($dname,11).state = 1,Active,$iif($did($dname,12).state = 1,All,$iif($did($dname,13).state = 1,Specified)))
  zcon Setup MsgType $iif($did($dname,14).state = 1,Random,Custom)
  $iif($did($dname,16).text,zcon Setup CustomMsg $ifmatch)
}

on *:dialog:zcfg:sclick:21: { mp3msg }
on *:dialog:zcfg:sclick:22: { zadv }

on *:dialog:zcfg:dclick:26: {
  var %s = $calc($did($dname,26).sel -1)
  zcon Setup SchemeID %s
  zscheme_update
}

on *:dialog:zcfg:sclick:28: {
  if ($did($dname,26).sel) {
    var %s = $calc($ifmatch -1)
    write -dl $+ %s $shortfn($scriptdirzAmp\Schemes.zmp)
    did -r $dname 26 
    .filter -k $shortfn($scriptdirzAmp\Schemes.zmp) zsch_add
  }
}

on *:dialog:zcfg:sclick:29: {
  var %n = $$?="Enter scheme name:",%d = $$?="Enter description for scheme:"
  if %n && %d {
    zaddscheme
    did -ra addscheme 10 %n
    did -ra addscheme 11 %d
  }
}

dialog addscheme {
  title "Add Scheme"
  size -1 -1 118 85
  option dbu
  text "zAmp MP3 information:", 1, 3 31 57 8
  edit ",,", 2, 66 30 50 10, autohs
  text "Lists/editbox color:", 3, 3 43 57 8
  edit ",,", 4, 66 42 50 10, autohs
  edit ",,", 5, 66 54 50 10, autohs
  text "Lists/editbox text:", 6, 3 55 57 8
  button "Done", 7, 79 71 37 12
  box "", 8, 76 68 1 15
  button "RGB select", 9, 36 71 37 12
  text "", 10, 3 2 112 8
  text "", 11, 3 9 112 13
  box "", 12, 4 22 110 4
}

on *:dialog:addscheme:init:0: {
  mdx MarkDialog $dname
  mdxbutton addscheme 7,9
  mdx SetFont $dname 10,11 -11 700 Tahoma
  mdx SetFont $dname 1,2,3,4,5,6,7,9 -11 400 Tahoma
  zscheme_update addscheme
}

on *:dialog:addscheme:sclick:7: {
  if ($did($dname,2) && $did($dname,4) && $did($dname,5) && $did($dname,10) && $did($dname,11)) {
    var %n = $did($dname,10).text,%d = $did($dname,11).text,%z = $did($dname,2),%lb = $did($dname,4),%lt = $did($dname,5)
    zschm $+(%n,*,%d,*,%z,*,%lb,*,%lt)
    dialog -x $dname
    if ($dialog(zcfg)) {
      did -r zcfg 26
      .filter -k $shortfn($scriptdirzAmp\Schemes.zmp) zsch_add
    }
  }
  else {
    var %x = $input(You didn't enter all the fields in. Close anyways?,iyn,Confirm)
    if %x = $true { dialog -x $dname }
  }
}

on **:dialog:addscheme:sclick:9: { dodialog rgb }

dialog mp3msg {
  title "Random MP3 Messages"
  size -1 -1 151 112
  option dbu
  icon $shortfn($scriptdirzamp\mp3msgs.ico), 0
  button "&Done", 6, 112 98 37 12, ok
  button "Add", 7, 29 98 37 12
  button "Delete", 8, 70 98 37 12
  list 2, 1 2 147 69, size
  edit "", 3, 1 73 148 10, autohs
  button "", 5, 2 85 147 8, disable
  box "", 1, 109 95 1 15
}

on *:dialog:mp3msg:init:0: {
  mdx MarkDialog $dname
  mdxbutton mp3msg 6,7,8
  window -lph @mp3msg.preview 0 0 315 20
  mdx SetControlMDX $dname 2 Listview report single rowselect > $views
  mdx SetControlMDX $dname 5 window > $dlg
  mdx SetFont $dname 2,3,5,6,7,8 -11 400 Tahoma
  did -i $dname 2 1 headerdims 360
  did -i $dname 2 1 headertext MP3 Messages
  did -a $dname 5 grab $window(@mp3msg.preview).hwnd @mp3msg.preview
  zscheme_update mp3msg
  load.mp3msg
}

on *:dialog:mp3msg:sclick:2: {
  if ($did($dname,2).sel) {
    did -ra $dname 3 $read($shortfn($scriptdirzamp\mp3msg.zmp), $calc($did($dname,2).sel - 1))
    dline @mp3msg.preview 1 1
    aline @mp3msg.preview $did($dname,3).text
  }
}

on *:dialog:mp3msg:edit:3: {
  var %m = $did(mp3msg,3).text
  if (%m) { .rline @mp3msg.preview 1 $did($dname,3).text }
  else { .dline @mp3msg.preview 1 }
}

on *:dialog:mp3msg:sclick:7: {
  if ($did($dname,3).text) {
    .write $shortfn($scriptdirzamp\mp3msg.zmp) $did($dname,3).text
    did -r $dname 2,3
    load.mp3msg
  }
}

on *:dialog:mp3msg:sclick:8: {
  if ($did($dname,2).sel) {
    var %sel = $calc($did($dname,2).sel - 1)
    .write -dl $+ %sel $shortfn($scriptdirzamp\mp3msg.zmp)
    did -r $dname 2,3
    load.mp3msg
  }
}

dialog zadv {
  title "Ad Targets"
  size -1 -1 135 73
  option dbu
  icon $shortfn($scriptdirzamp\mp3msgs.ico), 0
  list 1, 1 2 132 53, size
  button "Done", 2, 96 59 37 12, ok
  box "", 3, 93 56 1 15
  button "Delete", 4, 54 59 37 12
  button "Add", 5, 13 59 37 12
}

on *:dialog:zadv:init:0: {
  mdx MarkDialog $dname
  mdxbutton 2,4,5
  mdx SetFont $dname 1,2,4,5 -11 400 Tahoma
  mdx SetControlMDX $dname 1 Listview report single rowselect > $views
  did -i $dname 1 1 headerdims 135 125
  did -i $dname 1 1 headertext Channel $chr(9) Network

  zscheme_update zadv
  .filter -k $shortfn($scriptdirzamp\adtargets.zmp) zadv_add
}


on *:dialog:zadv:sclick:5: {
  var %x = $$?="Enter channel:",%y = $$?="Enter network"
  if %x && %y {
    write $shortfn($scriptdirzAmp\adtargets.zmp) %x $+ * $+ %y
    did -r zadv 1
    .filter -k $shortfn($scriptdirzAmp\adtargets.zmp) zadv_add
  }
}

on *:dialog:zadv:sclick:4: {
  if ($did(zadv,1).sel) {
    write -dl $+ $calc($did(zadv,1).sel -1) $shortfn($scriptdirzAmp\adtargets.zmp)
    did -r zadv 1
    .filter -k $shortfn($scriptdirzAmp\adtargets.zmp) zadv_add
  }
}

dialog rgb {
  title "RGB Creator"
  size -1 -1 143 29
  option dbu
  icon images\BlockOS.icl,36
  list 1, 19 3 75 9, size
  list 2, 19 12 75 9, size
  list 3, 19 21 75 9, size
  text "Red:", 4, 8 3 12 8
  text "Green:", 5, 3 12 15 8
  text "Blue:", 6, 7 21 12 8
  text "0", 7, 93 3 20 8, read,center
  text "0", 8, 93 12 20 8, read,center
  text "0", 9, 93 21 20 8, read,center
  list 10, 115 2 27 27, size
}

on *:dialog:rgb:init:0:{
  mdx SetMircVersion $version
  mdx MarkDialog $dname
  mdx SetFont $dname 4,5,6 -11 400 Tahoma
  mdx SetFont $dname 7,8,9 -11 700 Tahoma
  mdx SetBorderStyle $dname 18,19,20,21 staticedge
  mdx SetBorderStyle $dname 1,2,3
  mdx SetControlMDX $dname 1,2,3 trackbar select tooltips noticks both > $bars
  mdx SetColor $dname 10 background $rgb(0,0,0)
  did -i $dname 1,2,3 1 params  0 0 255 1 5 * * 10
  hadd -m rgb red 0
  hadd -m rgb green 0
  hadd -m rgb blue 0
}

on *:dialog:rgb:sclick:1:{
  hadd -m $dname red $gettok($did($did,1),1,32) | load_rgb
}

on *:dialog:rgb:sclick:2:{
  hadd -m $dname green $gettok($did($did,1),1,32) | load_rgb
}

on *:dialog:rgb:sclick:3:{
  hadd -m $dname blue $gettok($did($did,1),1,32) | load_rgb 
}


; EVENTS 

on *:MP3End: {
  if ($zread(MP3,MP3)) {
    mp3_stop
    if ($zread(MP3,Mode) = shuffle) && ($zread(MP3,Playlist)) {
      var %f = $shortfn($read($zread(MP3,Playlist))),%r = $readn
      zcon MP3 MP3 %f
      mp3_play
      $iif($dialog(zamp),did -c zamp 12 %r)
    }
    if ($zread(MP3,Mode) = cont) {
      mp3_next
    }
    if ($zread(MP3,Mode) = rep) {
      var %x = $read($zread(MP3,Playlist), w, * $+ $longfn($zread(MP3,MP3)) $+ *)
      var %l = $readn
      if %l = $lines($zread(MP3,Playlist)) { mp3_stop }
      else { mp3_next }
    }
  }
}