;___________________________________
;         MoonCloud MP3 DLL aliases:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l mD if $1 == -u { dll -u $_md | return } | var %r $dll($_md,$1,$iif($2,$2-,$s)) | if $isid { return %r }
alias -l _mD return $shortfn($scriptdir $+ mooncloudmp3.dll)
;___________________________________
; Variable identifiers:
;   $c : main config var list
;   $p : playlist files list
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l c {
  var %h mCmp3.vars
  if $1 == -f && $hget(%h) { hfree %h | return }
  if $1 == -r && $hget(%h) { hsave -o %h $cfg | hfree %h | return }
  if $1 == -l { if !$hget(%h) { hmake %h  } | if $isfile($cfg) { hload %h $cfg | return } }
  if $isid { return $hget(%h,$1) }
  else { hadd -m %h $1 $2- }
}
alias -l p {
  var %h mCmp3.pl
  if $1 == -r && $hget(%h) { hfree %h | return }
  if $1 == -d { hdel -w %h $2- | return }
  if $1 == -m && !$hget(%h) { hmake %h | return }
  if $1 == -l { if !$hget(%h) { hmake %h } | hload %h $2- | return }
  if $1 == -s { hsave -o %h $2- | return }
  if $isid { return $hget(%h,$1) } | else { hadd -m %h $1 $2- }
}
;___________________________________
;      Misc identifiers and aliases:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l cdpl if $isid { return $c(pl.cd) } | c pl.cd $1
alias -l ch return $str($chr(159),$1)
alias -l cfg return $+(",$scriptdir,mcmp3.cfg,")
alias -l dr drawrect $1-
alias -l dt drawtext $1-
alias -l gt var %r $calc($2 + $1) | %r = $iif(%r > 255,255,$iif(%r < 0,0,%r)) | return %r
alias -l g var %r $1 | tokenize 46 $c(sh) | return $rgb($gt($1,%r),$gt($2,%r),$gt($3,%r))
alias -l help run $+(",$scriptdir,MCMP3.HLP,")
alias -l ismp3 return $iif($right($1-,3) == MP3,$true,$false)
alias -l insnd.fname { return $c(insnd.fname) }
alias -l insnd.pos { 
  if $cdpl { return $calc($md(MediaGet,position) - $md(MediaGet,position track $c(t))) }
  else { return $md(MediaGet,position) }
}
alias -l insnd.length if $cdpl { return $md(MediaGet,length track $c(t)) } | else { return $md(MediaGet,length) }
alias -l insnd {
  var %s $md(MediaGet,mode)
  If (%s == playing) || (%s == paused) { return $true }
  return $false
}
alias -l l return $line($iif($2,$2,$wl),$1,0)
alias -l mcEW { window -e +l @mcmp3.echo $w(-2).w 0 150 $w(-2).h }
alias -l mcicon return $+(",$scriptdir,MCLOGO.ICO,")
alias -l mcVer return 3.5
alias -l mE { aline @mcmp3.echo $1- }
alias -l mecho { echo $colour(info) -ai2t (mC) $1- }
alias -l mplay {
  if $1 == -s { md MediaCDStop | if (!$cdpl || $2) { md MediaClose } }
  elseif $1 == -p {
    if !$cdpl {
      var %r $md(MediaPlay,$2)
      if $gettok(%r,1,32) == OK { return OK }
      else { 
        var %e $gettok(%r,2,32)
        if (%e == MMSYSTEM277) || (%e == MMSYSTEM263) { %r = !Errore! Media Player e' in uso, o trova Windows Media Player 6.4/7.1 }
        return %r
      }
    }
    else {
      var %r $md(MediaCDPlay,$2)
      if %r == OK { return OK }
      else {
        var %e $gettok(%r,2,32)
        return %e
      }
    }
  }
  elseif $1 == -k { if $cdpl { md MediaCDSeek $calc($int($md(MediaGet,position track $c(t))) + $2) } | else { md MediaSeek $2 } }
  elseif $1 == -r {
    if $cdpl { md MediaCDSeek $c(pau.cdpos) }
    else { md MediaResume }
  }
  elseif $1 == -a {
    c pau.cdpos 0 
    if $cdpl { c pau.cdpos $md(MediaGet,position) }
    md MediaPause
  }
}
alias -l RGBfile return $+(",$scriptdir,CPRESET.CFG,")
alias -l RGBnew return $+(",$scriptdir,NEWPRESETS.CFG,")
alias -l s return $chr(160)
alias -l sd return $iif($isdir($c(ldir)),$c(ldir),$scriptdir)
alias -l sl return [ $ [ $+ [ sline($wl,$1) [ $+ [ $iif($prop,. $+ $prop)) ] ] ] ] ]
alias -l t $+(.timer,$iif(*MCL* !iswm $1,$chr(32)),$1-) 
alias -l to t MCL $+ $1 $+ * off
alias -l w if ($isid) return [ $ [ $+ [ window($1-) [ $+ [ $iif($prop,. $+ $prop) ] ] ] ] ] | else window $1-
alias -l wD return @mcmp3.dummy
alias -l wID3 return @mcmp3.ID3
alias -l wl return @mcmp3.List
alias -l wlm return @mcmp3.ListMain
alias -l wm return @MoonClouD
alias -l wp return @mcmp3.popup
alias -l wt if $isid { return @mcLISTTEMP } | else { if $1 == -c { w -c @mcLISTTEMP } | else { w -sh +st @mcLISTTEMP } }
alias -l wr var %r $dll($_wr,$1,$2-) | if (E_* iswm %r) { mecho *** Error with winrgn: %r : $1 $2- }
alias -l _wr return $shortfn($scriptdir $+ winrgn.dll)
alias -l x cdpl $false | mplay -s x | if $1 != exit { to | dll -u $_wr | md -u | w -c $wp | w -c $wl | w -c $wlm | w -c $wID3 | w -c $wm } | m -r | c -r | p -r | .disable #mc3mp3end
alias -l tags.val {
  var %v $2-,%f $longfn($1),%v2 $replace(%v,<length>,0,<album>,$chr(32),<trk>,0,<artist>,$chr(32),<title>,$chr(32),<kbps>,0)
  if !$ismp3($1) { %v = %v2 }
  if *<file.mp3>* iswm %v { %v = $replace(%v,<file.mp3>,$nopath(%f)) }
  if *<file>* iswm %v { %v = $replace(%v,<file>,$left($nopath(%f),-4)) }
  if *<drive>* iswm %v { %v = $replace(%v,<drive>,$left(%f,2)) }
  if *<fullpath>* iswm %v { %v = $replace(%v,<fullpath>,$right($nofile(%f),-3)) } 
  if *<filesize>* iswm %v { %v = $replace(%v,<filesize>,$round($calc($lof(%f)/1000000),2) $+ mb) }
  if *<length>* iswm %v { %v = $replace(%v,<length>,$remove($duration($calc($sound(%f).length / 1000)),ecs,ec,ins,in,rs,r,$chr(32))) }
  if *<album>* iswm %v { %v = $replace(%v,<album>,$sound(%f).album) }
  if *<trk>* iswm %v { %v = $replace(%v,<trk>,$sound(%f).track) }
  if *<artist>* iswm %v { %v = $replace(%v,<artist>,$sound(%f).artist) }
  if *<title>* iswm %v { %v = $replace(%v,<title>,$sound(%f).title) }
  if *<kbps>* iswm %v { %v = $replace(%v,<kbps>,$sound(%f).bitrate) }
  return %v
}
;___________________________________
;             Main ininitialization:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l mcl.cm { ;Define menus
  m.create 165 6 "Arial" 10 _Lista,_Opzioni,_Aiuto
  m.aItem 1 Carica Playlist... | m.setcmd 1 1 pl L
  m.aItem 1 Organizza playlist.. | m.setcmd 1 2 pl Sort
  m.aItem 1 salva Playlist... | m.setcmd 1 3 pl S
  m.aItem 1 -ADD
  m.aItem 1 File... | m.setcmd 1 5 pl A F
  m.aItem 1 Directory... | m.setcmd 1 6 pl A D
  m.aItem 1 Directory w/Recursion... | m.setcmd 1 7 pl A Dr
  m.aItem 1 -RIMUOVI
  m.aItem 1 Seleziona files  | m.setcmd 1 9 pl Rs
  m.aItem 1 Rimuovi TUTTI files | m.setcmd 1 10 pl Ra
  m.aItem 1 -TROVA
  m.aItem 1 Trova canzone in lista... | m.setcmd 1 12 find.mp3
  m.aItem 1 -
  m.aItem 1 Play Audio CD... | m.setcmd 1 14 pc Pcd
  m.aItem 1 -
  m.aItem 1 Chiudi Player | m.setcmd 1 16 x
  m.aItem 2 -Play Mode
  m.aItem 2 Continuo | m.setcmd 2 2 m.chk c
  m.aItem 2 casuale | m.setcmd 2 3 m.chk r
  m.aItem 2 Manuale | m.setcmd 2 4 m.chk m
  m.aItem 2 Ripeti (one) | m.setcmd 2 5 m.chk p
  m.aItem 2 -Play song on
  m.aItem 2 Doppio Click | m.setcmd 2 7 m.chk dclick
  m.aItem 2 Singolo Click | m.setcmd 2 8 m.chk sclick
  m.aItem 2 -
  m.aItem 2 Canale Spam Editor... | m.setcmd 2 10 spam.edit
  m.aItem 2 Visualizza template Playlist... | m.setcmd 2 11 pl.dView
  m.aItem 2 Cambia colore player... | m.setcmd 2 12 rgb.w
  m.aItem 2 -
  m.aItem 2 Apri ID3v1 Visualiz/Editor... | m.setcmd 2 14 id3.draw FROMMENU
  m.aItem 3 About... | m.setcmd 3 1 about
  m.aItem 3 Versione... | m.setcmd 3 2 run $scriptdirMCMP3VERSIONS.TXT
  m.aItem 3 -
  m.aItem 3 Aiuto... | m.setcmd 3 4 help
}
alias -l loadset {
  if $1 == -start { cdpl $false | mplay -s start | c t 1 | c ts 0 | c pau $false | c plHide $iif($c(plhide),$false,$true) | c id3c.file $s | c scr.f $false }
  elseif $isfile($cfg) {
    c -l
    if ($c(MCMP3VERSION) != $mcVer) {
      var %d $input(hai aggiornato una nuova versione di MoonCloudMP3 $crlf Your mcmp3 ora verranno aggiornate anche le configurazioni. $crlf Sfortunatamente il settagio non prevede il salvataggio dei colori.,68,mcMp3 Info)
      if $isfile($RGBFile) { .copy -a $RGBnew $RGBfile }
      else { .copy $RGBnew $RGBfile }
      c -f | .remove $cfg
      goto init
    }
  }
  else { :init
    if !$isfile($RGBfile) { .copy $RGBnew $RGBfile }
    c MCMP3VERSION $mcVer
    c Sh 0.-80.-100
    c w.x 0 | c w.y 0 | c w.w 366 | c w.h 112
    c pl.x $c(w.x) | c pl.y $calc($c(w.y) + $c(w.h)) | c pl.w 385 | c pl.h 250 | c pl.stick $false
    c id3.x $calc($c(w.x) + $c(w.w) + 20) | c id3.y 0 | c id3.w 300 | c id3.h 230 | c id3.stick $false
    c btns cP,cS,cPa,cPr,cN,cU,cD,cH,cC,cM,cVu,cVd,cAddDir,cAddRec,cAddFile,cRemAll,cRemSel,cReSize,cLoad,cSave,cCArtist,cCAlbum,cCTitle,cCYear,cCGenre,cCComments,cID3Update,cID3Done,cID3Help
    c plHide $false
    c bk 30 | c bkpop 110
    c pView <file>
    c plColor $false
    c V $int($calc($vol(song) / 8000)))
    c s.y 85 | c s.s 10 | c s.w 150 | c s.e $calc($c(s.s) + $c(s.w)) | c s.sz 15 | c s.h 22
    c clickMode dClick | c pMode c | c TimeMode inc
    c pl.font "Arial" | c pl.fontsize 12 | c pl.fontbold $false
    c spam.template playing) <file> )<length>)<kbps>kbPS)<filesize> (mC)
    c spam.target 2 | c spam.chan $s
  }
}
alias mCmp3 {
  .enable #mc3mp3end | loadset | loadset -start | d.switch
  w -Bdhpk +d $wm $c(w.x) $c(w.y) $c(w.w) $c(w.h) $mcicon | titlebar $wm mp3
  var %ww $w($wm).w,%wh $w($wm).h
  w -Bdhp +dL $wlm $c(pl.x) $c(pl.y) $c(pl.w) $c(pl.h)
  wr wrSelectWindow $w($wm).hwnd
  wr wrSetMode rmRect | wr wrSetRegion 0 0 %ww %wh
  wr wrDeleteRegion 0 0 %ww %wh
  wr wrSetMode rmRoundRect
  wr wrAddRegion 0 0 $calc(%ww + 1) %wh 30 30
  wr wrSetMode rmRect
  wr wrAddRegion 0 0 30 30
  w -Bdhl +dnL $wl $calc($w($wlm).dx + 3) $calc($w($wlm).dy + 20) $calc($c(pl.w) - 6) $calc($c(pl.h) - 50) $wl
  pc H init
  font $iif($c(pl.fontbold),-b) $wl $c(pl.fontsize) $c(pl.font)
  dr -fr $wm $g($c(bk)) 1 0 0 $w($wm).dw $w($wm).dh
  p -m | pl.draw
  mcl.cm | m.chk $iif($c(pmode),$ifmatch,c) | m.chk $iif($c(clickmode),$ifmatch,dClick)
  mcl.draw | pc | if $isfile($c(pl)) { t -mo 1 500 pl L $c(pl) | rs tI }
}
alias -l mcl.draw {
  var %ww $w($wm).w,%wh $w($wm).h,%i,%s,%x
  d.switch $wm | d.b 0 0 %ww $calc(%wh - 1) 28 28 $c(bk) | d.f 3 2 255 18 $c(bk) | d.b 0 0 $calc(%ww - 47) 25
  d.l -v 0 20 10 | d.l -h $calc(%ww - 50) 0 30 | d.l -h $calc(%ww - 50) 22 47 | drawfill -rs $wm $g(95) $g($c(bk)) $calc(%ww - 10) 10
  d.btn $calc(%ww - 26) 4 18 18 cC | d.btn $calc(%ww - 45) 4 18 18 cM
  %i = 1 | %x = 5 | %s = Lettore $+ $s $+ Mp3
  while %i <= $len(%s) {
    dt -nro $wm $g($calc(%i * 20)) "Arial" 12 %x 5 $mid(%s,%i,1)
    %x = %x + $width($mid(%s,%i,1),Arial,12,1,0) | inc %i
  }
  d.b 4 51 358 33 25 25 80 tCtl "Arial" 12 -5 $s
  drawline -r $wm $g(0) 1 240 64 240 70 244 70 252 78 252 56 244 64 240 64
  drawfill -rs $wm $g(175) $g(80) 245 68
  %i = 1 | while %i <= 8 { d.btn $calc(7 + (%i * 26) - 26) 55 25 25 $gettok($c(btns),%i,44) | inc %i }
  d.b 4 26 62 23 5 5 35 tT "System" 10 1 00:00 | d.b 68 26 294 23 15 15 1 tG "FixedSys" 6 1 $s
  d.b 182 86 178 20 20 20 55 tD "Arial" 11 1 $s
  d.b 255 56 100 22 15 15 80 tV "FixedSys" 6 1 $s
  d.btn 259 60 14 14 cVd | d.btn 337 60 14 14 cVu | rs tV | if $insnd { rs tD $c(tD.lline) }
  d.b $calc($c(s.s) - 4) $c(s.y) $calc($c(s.w) + 25) $c(s.h) 20 20 25 tE "FixedSys" 10 0 $s
  c tmode $s | var %i 1
  while %i <= $m(menu.subs) { dt -r $wm $g(255) $m(menu.font) $m(menu.fontsize) $m($+(menu.,%i,.x)) $m($+(menu.,%i,.y)) $m($+(menu.,%i,.name)) | inc %i }
}
;___________________________________
;                 Move/Size aliases:
; mws: resizes playlist window
; mw : move window
; ms : move seekbar
; mv : move file up/down in playlist
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l mws.d {
  if $1 != 0 { dr -nrf $wlm $g($c(bk)) 1 2 2 $calc($2 - 4) $calc($3 - 4) }
  dr -nr $wlm $g($1) 2 0 0 $2 $3 | pl.d.rs
  dt -nr $wlm $g(200) "Arial" 10 $calc($2 - 110) $calc($3 - 20) Trascina per ridimensionare ->
  c pl.mws.ow $2 | c pl.mws.oh $3
}
alias -l mws {
  if !$ctimer {
    wr wrSelectWindow $w($wlm).hwnd | wr wrResetWindow $w($wlm).hwnd | t -ho 1 10 md HW $w($wl).hwnd
    mws.d 255 $c(pl.w) $c(pl.h) | dr $wlm
  }
  elseif ($mouse.dx != $1 || $mouse.dy != $2) {
    if $calc($mouse.dy - $c(pl.y) + 15) < 150 { c pl.h 150 } | else { c pl.h $calc($mouse.dy - $c(pl.y) + 15) }
    if $calc($mouse.dx - $c(pl.x) + 15) < 368 { c pl.w 368  } | else { c pl.w $calc($mouse.dx - $c(pl.x) + 15) }
    w $wlm $c(pl.x) $c(pl.y) $c(pl.w) $c(pl.h) | mws.d 0 $c(pl.mws.ow) $c(pl.mws.oh) | mws.d 255 $c(pl.w) $c(pl.h) | dr $wlm
  }
  if $mouse.key & 1 { t -mo 1 0 mws $mouse.dx $mouse.dy } 
  else { pl.draw }
}
alias -l mw {
  if $1 == $wm { 
    c w.x $calc($mouse.dx - $2)
    c w.y $calc($mouse.dy - $3)
    w $wm $c(w.x) $c(w.y)
  }
  elseif $1 == $wlm {
    c pl.x $calc($mouse.dx - $2)
    c pl.y $calc($mouse.dy - $3)
    w $wlm $c(pl.x) $c(pl.y) | w $wl $calc($w($wlm).dx + 3) $calc($w($wlm).dy + 20)
  }
  elseif $1 == $wID3 {
    c id3.x $calc($mouse.dx - $2)
    c id3.y $calc($mouse.dy - $3)
    w $wID3 $c(id3.x) $c(id3.y)
  }
  if ($mouse.key & 1) { t MCL.move -o 1 0 mw $1- }
}
alias -l ms {
  if (!$insnd) return
  var %y $mouse.y
  if $mouse.key & 1 {
    if $1 == SCROLL {
      var %x $mouse.x, %y $mouse.y
      if !$ctimer { c scr.f $true }
      if $c(scr.f) {
        if $inrect(%x,%y,$c(tG.x),$c(tG.y),$c(tG.w),$c(tG.h)) &&  (2 // $calc(%x - $c(tG.x))) && ($c(scr.ox) != %x) { scroll.c -m $iif($c(scr.ox) > %x,$calc($c(scr.i) + 1),$calc($c(scr.i) - 1)) $c(scr) }
        c scr.ox %x | t MCL.msn -o 1 0 ms SCROLL
      }
    }
    else { 
      c s.f $true
      var %t $calc($mouse.x - $c(s.s) - 7), %a $calc($c(s.s) + %t)
      if %t != $c(s.o) && %a >= $c(s.s) && %a <= $c(s.e) && %y > $calc($c(s.y) + 3) && %y < $calc($c(s.y) + $c(s.h)) { ts2 %t | dr $wm }
      t MCL.ms -o 1 0 ms
    }
  }
  else { if $1 != SCROLL && $insnd { mplay -k $round($calc($c(s.sec) * $c(s.o) * 1000),-1) } }
}
alias -l mv {
  if $c(ts) > 0 {
    var %l $2,%o 
    %o = $l(%l)
    if %l $3 $4 {
      dline $wl %l | iline $wl $1 %o
      %o = $p($1)
      p $1 $p($2) | p $2 %o
    }
  }
}
;___________________________________
;               ID3V1 Viewer/Editor:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l id3.close t MCLb* off | w -c $wID3 | c id3c.file $s | w -a $wm
alias -l id3.draw {
  if $w($wID3) && $1 == FROMMENU { return }
  if !$w($wID3) { w -Bdhp +dL $wID3 $c(id3.x) $c(id3.y) $c(id3.w) $c(id3.h) }
  if $1 != -rgn {
    wr wrSelectWindow $w($wID3).hwnd | wr wrResetWindow $w($wID3).hwnd
    wr wrSetMode rmRoundRect
    wr wrSetRegion 0 0 $calc($c(id3.w) + 1) $c(id3.h) 30 30
    wr wrSetMode rmRect
    wr wrAddRegion 0 0 $c(id3.w) 140
  }
  d.switch $wID3
  d.b 0 0 $c(id3.w) $calc($c(id3.h) - 1) 28 28 $calc($c(bk) + 55)
  d.b 0 0 $c(id3.w) 20 0 0 65 tID3t "Arial" 11 1 $s | rs tID3t Mp3 Tag viewer/editor (ID3V1)
  d.l -v 0 15 10 | d.l -v $calc($c(id3.w) - 3) 15 10
  var %w $calc($c(id3.w) - 70)
  d.b 5 25 %w 20 15 15 15 tArtist "Arial" 11 1 $s
  d.b 5 50 %w 20 15 15 15 tAlbum "Arial" 11 1 $s
  d.b 5 75 %w 20 15 15 15 tTitle "Arial" 11 1 $s
  d.b 5 100 100 20 15 15 15 tYear "Arial" 11 1 $s
  d.b 5 125 175 20 15 15 15 tGenre "Arial" 11 1 $s
  d.b 5 150 %w 20 15 15 15 tComments "Arial" 11 1 $s
  d.b 5 175 $calc($c(id3.w) - 10) 20 15 15 15 tID3File "Arial" 11 1 $s
  d.b 35 200 200 20 15 15 15 tID3Status "Arial" 11 1 $s
  var %i 21,%i2 25 | while %i <= 26 { d.btn $calc($c(id3.w) - 60) %i2 55 20 $gettok($c(btns),%i,44) Round 100 15 15 | inc %i | inc %i2 25 }
  d.btn $calc($c(id3.w) - 60) 200 55 20 cID3Update Round 100 15 15
  d.btn $calc($c(id3.w) - 18) 3 14 14 cID3Done | d.btn $calc($c(id3.w) - 34) 3 14 14 cID3Help
  id3.refresh $null
}
alias -l id3.refresh {
  if !$w($wID3) { return }
  rs tArtist Artist: $iif($sound($1).artist,$ifmatch)
  rs tAlbum Album: $iif($sound($1).album,$ifmatch)
  rs tTitle Title: $iif($sound($1).title,$ifmatch)
  rs tYear Year: $iif($sound($1).year,$ifmatch)
  rs tGenre Genre: $iif($sound($1).genre,$ifmatch)
  rs tComments Comments: $iif($sound($1).comment,$ifmatch)
  rs tID3file $iif($isfile($1),$nopath($longfn($1)),$s)
  if !$ismp3($1) { rs tID3Status Status: Invalid file type $right($1,3) | c id3c.file $s | return }
  c id3c.file $1
  rs tID3Status Status:
}
alias -l id3.change {
  if !$isfile($c(id3c.file)) { return }
  c id3c.field $1 | c id3c.text $3- | c id3c.cancel $false
  var %r $iif($1 == genre,$dialog(id3cgenre.d,id3cgenre.t,$wID3),$dialog(id3c.d,id3c.t,$wID3))
  if !$c(id3c.cancel) {
    %r = $c(id3c.result)
    if $1 == year { %r = $left(%r,4) }
    rs $+(t,$1) $+($1,:,$s,%r)
  }
}
alias -l id3.update {
  rs tID3Status Status: Attempting ID3 tag Update
  if !$ismp3($1) { rs tID3Status Status: Invalid file type | return }
  if !$isfile($1) { rs tID3Status Status: File does not exist | return }
  if $insnd && $shortfn($insnd.fname) == $1 { rs tID3Status Status: Cannot edit playing mp3 | return }
  md SetID3Tag init
  md SetID3Tag artist $iif($right($c(tArtist.o),-8),$ifmatch,$s)
  md SetID3Tag album $iif($right($c(tAlbum.o),-7),$ifmatch,$s)
  md SetID3Tag title $iif($right($c(tTitle.o),-7),$ifmatch,$s)
  md SetID3Tag year $iif($right($c(tYear.o),-6),$ifmatch,$s)
  md SetID3Tag genre $iif($replace($right($c(tGenre.o),-7),$chr(32),_),$ifmatch,$s)
  md SetID3Tag comments $iif($right($c(tComments.o),-10),$ifmatch,$s)
  var %d $md(SetID3Tag,update $1)
  if %d == UPDATE_OK {
    rs tID3Status Status: ID3 tag Update successful!
    var %l $hfind(mcMp3.pl,$1,1).data
    var %pv $pl.view($1) | rline $wl %l $iif(%pv,%pv,$s)    
  }
  else { rs tID3Status Status: Error updating ID3 tag }  
}
dialog -l id3c.t {
  title $+(Change,$chr(32),$c(id3c.field))
  size -1 -1 132 37
  icon $mcicon
  option dbu
  edit "", 1, 2 11 127 10, limit 30
  button "Cambia", 2, 47 23 37 12
  button "Buttoni", 3, 45 40 37 12, cancel
  text "Scrivi cosa vuoi fare con questo id3 file da cambiare in:", 4, 2 2 123 8
}
on *:dialog:id3c.d:init:0: { did -ra $dname 1 $c(id3c.text) }
on *:dialog:id3c.d:sclick:2: { c id3c.result $did(1) | dialog -x $dname }
on *:dialog:id3c.d:sclick:3: { c id3c.cancel $true }
dialog id3CGenre.t {
  title "cambia genere"
  size -1 -1 88 100
  icon $mcicon
  option dbu
  list 1, 1 10 86 75, size, vsbar, sort
  text "Seleziona genere:", 2, 1 1 55 8
  button "Cambia", 3, 26 87 37 12
  button "Bottone", 4, 16 134 37 12, cancel
}
on *:dialog:id3cgenre.d:init:0: { md FillGenreBox /did -a $dname 1 | did -c $dname 1 1 }
on *:dialog:id3cgenre.d:sclick:3: { c id3c.result $did(1,$did(1).sel).text | dialog -x $dname }
on *:dialog:id3cgenre.d:sclick:4: { c id3c.cancel $true }
;___________________________________
;     Playlist Control/Manipulation:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l mi if $w($wID3) { md HW $w($wID3).hwnd } | md HW $w($wl).hwnd | md HW $w($wlm).hwnd | w -n $wm
alias -l pc.pau {
  if $ctimer {
    d.switch $c(tT.win)
    c tmode n | d.t tT $c(tT.bk) $c(tT.o)
    if 2 // $c(pau.i) { d.t tT 255 $c(tT.o) }
    else { d.t tT $c(tT.bk) $c(tT.o) }
    dt $wm | c pau.i $calc($c(pau.i) + 1)
  }
  else { c pau.i 1 | t MCL.pause -ho 0 500 pc.pau }
}
alias -l pc.stop { to . | mplay -s $1 | rs tT $iif($c(TimeMode) == dec,-) $+ 00:00 | rs tI | rs tG $s | rs tD $s | c pau $false }
alias -l pc.details {
  var %f $1-
  if $ismp3(%f) { c tD.lline $sound(%f).bitrate $+ kbPS }
  else { c tD.lline $str($s,2) $+ $iif($cdpl,CD Audio,$upper($right(%f,3)) File) }
  c tD.lline $c(tD.lline) ( $+ $round($calc($lof(%f)/1000000),2) $+ mb $+ ) $remove($duration($calc($insnd.length / 1000)),ecs,ec,ins,in,rs,r,$chr(32))
}
alias -l pc.vol {
  var %s
  if $cdpl { %s = -v }
  elseif !$insnd { %s = -w }
  elseif ($right($insnd.fname,3) == MID) { %s = -m }
  else { %s = -w }
  vol %s $calc($c(v) * 8000)
}  
alias -l pc { ;Playlist Control
  if $1 == P { 
    var %l $fline($wl,$replace($c(lf),$s,$chr(32)),1),%mp
    if %l { cline $color(listbox text) $wl %l }
    pc.stop | %l = $iif($2,$2,$c(t)),%f | %f = $p(%l) | c scr.f $false
    if $cdpl { %mp = $mplay(-p,%l) }
    else { %mp = $mplay(-p,$shortfn(%f)) }
    if %mp != OK { .scroll %mp | return }
    c insnd.fname %f
    id3.refresh %f
    c t %l | c pau $false | c lf $replace($l(%l),$chr(32),$s)
    cline $color(highlight) $wl $c(t)
    time | $+($iif($cdpl,.),scroll) %f | $iif(!$cdpl,spam.send $shortfn(%f)) | rs tI | pc.details %f | rs tD $c(tD.lline)
  }
  elseif $1 == Pcd {
    pl RA | c playlist
    var %r $md(MediaCDOpen)    
    if %r == OK {
      %r = $md(MediaGet,type track 1)
      if %r == audio {
        var %j $md(MediaGet,number of tracks),%i 1 | cdpl $true
        while %i <= %j { pl.aline (CD) Track %i | inc %i }
      }
      else { .scroll !Error! No audio tracks exist on disc, or CD Door open. }
    }
    else { .scroll !Error! CD Audio device is busy, or doesn't exist. }
    rs tI
  }
  elseif $1 == N { var %t $iif($c(pmode) == r,$rand(1,$c(ts))) | %t = $iif($c(pmode) == c || $c(pmode) == m,$calc($c(t) + 1),%t) | %t = $iif($c(pmode) == p,$c(t),%t) | t -o 1 0 pc P $iif(%t > $c(ts),1,%t) }
  elseif $1 == Pr { var %t $calc($c(t) - 1) | t -o 1 0 pc P $iif(%t < 1,$c(ts),%t) }
  elseif $1 == S { pc.stop }
  elseif $1 == Pa && ($iif(!$cdpl,$insnd,$true)) { if ($md(MediaGet,Mode) == stopped) && (!$c(pau)) { return } | c pau $iif($c(pau),$false,$true) | t MCL.Time $iif($c(pau),-p,-r) | t MCL.Scroll $iif($c(pau),-p,-r) | mplay $iif($c(pau),-a,-r) | if $c(pau) { pc.pau } | else { t MCL.pause off } }
  elseif $1 == C x | if $1 == M { t -mo 1 300 mi }
  elseif $1 == Vu { var %V2 $calc($c(V) + 1) | c V $iif(%v2 > 8,$c(V),%v2) } | if $1 == Vd { var %V2 $calc($c(V) - 1) | c V $iif(%v2 < 0,$c(V),%v2) }
  elseif $1 == H { c plHide $iif($c(plHide),$false,$true) | pl.hide $c(plHide) }
  elseif $1 == RemAll { pl RA }
  elseif $1 == Load { pl L }
  elseif $1 == ID3Help { help }
  elseif $1 == ID3Done { t -ho 1 250 id3.close }
  if $1 == U && $2 { if !$cdpl { mv $2 $calc($2 - 1) > 0 } | else { ia.d } }
  elseif $1 == D && $2 { if !$cdpl { mv $2 $calc($2 + 1) <= $c(ts) } | else { ia.d } }
  elseif $1 == Addfile { if !$cdpl { pl A F } | else { ia.d } }
  elseif $1 == AddDir { if !$cdpl { pl A D } | else { ia.d } }
  elseif $1 == AddRec { if !$cdpl { pl A DR } | else { ia.d } }
  elseif $1 == RemSel { if !$cdpl { pl RS } | else { ia.d } } 
  elseif $1 == Save { if !$cdpl { pl S } | else { ia.d } }
  elseif ($1 == ID3Update) && !$cdpl { id3.update $c(id3c.file) }
  elseif (C* iswm $1) && !$cdpl { id3.change $right($1,-1) 30 $right($c($+(t,$right($1,-1),.o)),$calc(($len($1) + 1) * -1)) }
  if $w($wm) { if $1 != H && $2 != init { rs tV } | pc.vol }
}
alias -l pl.d.rs {
  dt -nr $wlm $g(200) "WingDings" 16 $calc($c(pl.w) - 23) $calc($c(pl.h) - 28) $chr(235)
  dt -r $wlm $g(200) "WingDings" 16 $calc($c(pl.w) - 20) $calc($c(pl.h) - 24) $chr(238)
}
alias -l pl.draw {
  if $1 != -rgn {
    wr wrSelectWindow $w($wlm).hwnd | wr wrResetWindow $w($wlm).hwnd
    wr wrSetMode rmRoundRect
    wr wrSetRegion 0 0 $calc($c(pl.w) + 1) $c(pl.h) 30 30
    wr wrSetMode rmRect
    wr wrAddRegion 0 0 $c(pl.w) 140
    wr wrDeleteRegion 3 20 $calc($c(pl.w) - 3) $calc($c(pl.h) - 35)
  }
  w $iif(!$c(plHide),-a) $wl $calc($c(pl.x) + 3) $calc($c(pl.y) + 20) $calc($c(pl.w) - 6) $calc($c(pl.h) - 55)
  d.switch $wlm
  d.b 0 0 $c(pl.w) $calc($c(pl.h) - 1) 28 28 50
  d.b 0 0 $c(pl.w) 20 0 0 85 tI "Arial" 11 1 $s
  d.l -v 0 15 10 | d.l -v $calc($c(pl.w) - 3) 15 10
  d.l -h 3 $calc($c(pl.h) - 35) $calc($c(pl.w) - 6)
  d.b 235 $calc($c(pl.h) - 31) 108 26 25 25 100 tPLtool3 "Arial" 12 0 $s
  d.b 140 $calc($c(pl.h) - 31) 114 26 25 25 80 tPLtool2 "Arial" 10 -2 $s | rs tPLtool2 $str($s,4) $+ Rem(
  d.b 5 $calc($c(pl.h) - 31) 155 26 25 25 80 tPLtool "Arial" 10 -2 $s | rs tPLtool Add(
  d.l -h 25 $calc($c(pl.h) - 31) 300 | d.l -h 25 $calc($c(pl.h) - 8) 300
  d.btn 37 $calc($c(pl.h) - 28) 35 20 cAddFile Round 100 15 15
  d.btn 73 $calc($c(pl.h) - 28) 35 20 cAddDir Round 100 15 15
  d.btn 109 $calc($c(pl.h) - 28) 45 20 cAddRec Round 100 15 15
  d.btn 187 $calc($c(pl.h) - 28) 30 20 cRemSel Round 100 15 15
  d.btn 218 $calc($c(pl.h) - 28) 30 20 cRemAll Round 100 15 15
  d.btn 255 $calc($c(pl.h) - 28) 40 20 cLoad Round 100 15 15
  d.btn 296 $calc($c(pl.h) - 28) 40 20 cSave Round 100 15 15
  pl.d.rs | rs tI
}
alias -l pl.color {
  var %l listbox t
  if $c(plColor) && !$1 {
    c plColor.oText.i $color(listbox text) | c plColor.oBK.i $color(listbox)
    c plColor.oText.r $color($c(plColor.oText.i)) | c plColor.oBK.r $color($c(plColor.oBK.i))
    ;color $c(plColor.oText.i) $g(255) | color $c(plColor.oBK.i) $g(120)
    color 99 $g(255)
    color listbox t 20 | color 21 $g(120) | color listbox 21
  }
  else { color $c(plColor.oText.i) $c(plColor.oText.r) | color $c(plColor.oBK.i) $c(plColor.oBK.r) }
}
alias -l pl.hide { ;Hides playlist
  if $1 { md HW $w($wl).hwnd | md HW $w($wlm).hwnd }
  elseif !$1 { w -a $wlm | w -a $wl }
}
alias -l pl.sort { ;Playlist Sort
  var %i 1,%m | wt
  if $c(ts) > 0 {
    var %iPbar 1
    rs tI Sorting Playlist...
    pbar -init $calc($c(pl.w) - 110) $calc($c(tI.y)) $calc($c(ts) * 3)
    while %i <= $c(ts) {
      if 6 // %iPbar { pbar -calc %iPbar | if $pbar { pbar -inc } }
      aline $wt $l(%i) $chr(184) $+ %i
      inc %i | inc %iPbar
    }
    %i = 1 | var %o,%f | hmake _ptmp 200
    while %i <= $c(ts) {
      if 6 // %iPbar { pbar -calc %iPBar | if $pbar { pbar -inc } }
      %f = $gettok($l(%i,$wt),1,184) | %o = $gettok($l(%i,$wt),2,184)
      hadd _ptmp %i $p(%o)
      inc %i | inc %iPbar
    }
    var %f $shortfn($+($scriptdir,sort.tmp)) | hsave _ptmp %f  | p -r | p -l %f | .remove %f | hfree _ptmp
    wt -c | %i = 1 | clear $wl | rs tI Re-Displaying playlist...
    while %i <= $c(ts) {
      if 6 // %iPbar { pbar -calc %iPbar | if $pbar { pbar -inc } }
      %m = $p(%i)
      p %i %m | aline $wl $pl.view(%m)
      inc %i | inc %iPbar
    }
    pbar -erase
    rs tI
  }
}
alias -l pl.cView {
  var %v $iif($1-,$1-,$c(pView)),%i 1
  c pView %v | clear $wl
  rs tI Re-Displaying playlist: %v
  pbar -init $calc($c(pl.w) - 110) $calc($c(tI.y)) $c(ts)
  while %i <= $c(ts) {
    if  4 // %i { pbar -calc %i | if $pbar { pbar -inc } }
    aline $wl $pl.view($p(%i))
    inc %i
  }
  pbar -erase | rs tI
}
alias -l pl.tags return <file.mp3>,<file>,<drive>,<fullpath>,<filesize>,<length>,<album>,<trk>,<artist>,<title>,<kbps>
alias -l pl.dView w -a $wm | dialog -adm pview.d pview.t
alias -l pl.view return $iif($cdpl,$1-,$tags.val($1-,$c(pView)))
alias -l pl.aline var %pv $pl.view($1-) | aline $wl $iif(%pv,%pv,$s) | c ts $calc($c(ts) + 1) | p $c(ts) $iif(!$cdpl,$shortfn($1-),$1-)
alias -l pl.per if 8 // $1 { var %tmp $calc($2 + 1) | if %tmp == 5 { %tmp = 1 } | rs tI $3- $+ $str(.,%tmp) | return %tmp } | else { return $2 }

;fix commands that shouldn't be executed on cd play
alias -l pl {
  if $1 == Ra { if $c(ts) > 0 { clear $wl | p -r | p -m | to | cdpl $false } }
  if $1 == L || $1 == S { w -a $wm }
  var %fs
  if $1 == L {
    var %f $iif($2,$2,$sfile($sd $+ *.mpl,Select mp3 playlist *.mpl,Load))
    if $isfile(%f) {
      pc.stop c | rs tI Loading: $nopath(%f)
      clear $wl | p -r | p -l $shortfn(%f) | c ts 0 | cdpl $false
      var %l $hget(mCmp3.pl,0).item,%i 1,%m
      pbar -init $calc($c(pl.w) - 110) $calc($c(tI.y)) %l
      while %i <= %l {
        if 4 // %i { pbar -calc %i | if $pbar { pbar -inc } }
        %m = $p(%i)
        pl.aline %m
        inc %i
      }
      pbar -erase | c pl %f | c t 1
      c ldir $nofile(%f) | c pl %f
    }
    w -b $wl
  }
  if $cdpl { ia.d | return }
  if $1 == Rs {
    if $sl(0) {
      rs tI Removing selected files...
      var %i $sl(1).ln,%lastline $sl($sl(0)).ln,%j %i,%sel $sl(0),%lastdel 0,%trks $c(ts),%per 0
      while $sl(0) {
        hdel mCmp3.pl $sl($sl(0)).ln
        dline $wl $sl($sl(0)).ln
        c ts $calc($c(ts) - 1)
      }
      %per = 0
      if $c(ts) {
        while %i <= %lastline && %i <= %trks {
          %j = %i | %per = $pl.per(%i,%per,Compacting Playlist)
          while !$p(%j) && %j <= %trks { inc %j }
          if $p(%j) { p %i $p(%j) | hdel mCmp3.pl %j | %lastdel = %j }
          inc %i
        }
        if %lastdel {
          %per = 0
          %i = $calc(%lastdel + 1)
          while %i <= %trks {
            %per = $pl.per(%i,%per,Compacting Playlist)
            if $p(%i) { p $calc(%i - %sel) $p(%i) } | hdel mcMp3.pl %i | inc %i
          }
        }
      }
      if $c(ts) <= 0 { cdpl $false | p -r | p -m }
    }
  }
  if $1 == S { var %f $iif($2,$2,$sfile($sd $+ *.mpl,Select mp3 playlist *.mpl,Save)) | if %f { c ldir $nofile(%f) | rs tI Saving playlist... | %f = $replace($iif(*.mpl !iswm $right(%f,4),$+(%f,.mpl),%f),$chr(32),_) | p -s %f | c pl %f } }
  if $1 == A {
    w -a $wm
    if $2 == F { var %f $sfile($sd $+ *.mp3;*.wav;*.wma;*.mid,Choose MP3,Add) | if ($isfile(%f)) { c ldir $nofile(%f) | pl.aline %f } }
    else {
      var %f,%d $sdir($sd,Select directory to $iif($2 == Dr,add with recursion,add))
      if $isdir(%d) {
        rs tI Adding Directory...
        var %ext *.mp3-*.wma-*.wav-*.mid,%i 1,%t
        while $gettok(%ext,%i,45) {
          %t = $ifmatch
          %f = $iif($2 == Dr,$findfile(%d,%t,0,pl.aline $1-),$findfile(%d,%t,0,1,pl.aline $1-))
          inc %i
        }
        c ldir %d
      }
    }
    w -b $wl
  }
  if $1 == Sort { pl.sort }
  c ts $l(0) | $iif($c(ts) < 1,pc.stop c)
  if ($c(ts) <= 0) || ($c(t) > $c(ts)) { c t $c(ts) } | if $c(ts) <= 0 { c pl $s } | rs tI
}

;___________________________________
;Timed Aliases:
;
;   Contains SeekBar, time display
; and progress bar aliases.
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l ts dr -renf $wm $g($1) $2 $calc($c(s.s) + $c(s.o) + $3) $calc($c(s.y) + 4 + $4) $calc(15 - $5) $calc(15 - $5)
alias -l ts2 ts $c(tE.bk) 1 0 0 0 | c s.o $1 | ts 255 1 0 0 0 | ts 120 1 2 2 4 | d.switch $wm | d.btn $calc($c(s.s) + $c(s.o) + 2) $calc($c(s.y) + 6) 11 11
alias -l time.f {
  var %m,%s,%e $iif(*hr* iswm $1-,60,0)
  if (*min* iswm $1-) %m = $calc(%e + $remove($wildtok($1-,*min*,1,32),mins,min)) 
  else { %m = $calc(%e + 0) }
  if (%m < 10) %m = 0 $+ %m
  if (*sec* iswm $1-) %s = $remove($wildtok($1-,*sec*,1,32),secs,sec)
  else { %s = 0 }
  if (%s < 10) %s = 0 $+ %s
  return $+($iif($c(TimeMode) == dec,-),%m,:,%s)
}
alias -l time.gd { 
  if $c(TimeMode) == inc return $duration($calc($insnd.pos / 1000))
  else return $duration($calc(($c(TempLen) - $insnd.pos) / 1000)))
}
alias -l time {
  if $ctimer == MCL.Time {
    var %t,%d $time.gd,%str $time.f(%d)
    %t = $int($calc(($insnd.pos / 1000) / $c(s.sec)))
    if %t != $c(s.o) && (!$c(s.f)) ts2 %t
    if (!$cdpl) && ($md(MediaGet,mode) == stopped) { pc S | if $c(pmode) != m { pc N } }
    elseif $cdpl { 
      var %p $calc($md(MediaGet,position) - $md(MediaGet,position track $c(t)))
      if (%p >= $calc($insnd.length - 1000)) { pc S | if $c(pmode) != m { pc N } }
    }
  }
  else { ts2 0 | c s.f $false | c s.sec $calc(($insnd.length / 1000) / $c(s.w)) | c TempLen $insnd.length | t MCL.Time -co 0 1 time }
  rs tT $iif(%str,%str,$iif($c(TimeMode) == dec,$time.f($duration($calc($c(templen) / 1000))),00:00))
}
alias -l scroll.c {
  if $1 == -m { var %t $3-,%j $2 }
  else { var %t $2-,%j $1 }
  var %l $len(%t)
  if $1 != -m { inc %j } | if (%j > %l) { %j = 1 } | elseif (%j < 1) { %j = %l } | %i = %j
  %t = $right(%t,$calc(%l - %i)) $+ $left(%t,$calc(%i))
  c scr.i %i | rs tG %t
}
alias -l scroll { 
  var %i 1
  if $ctimer == MCL.Scroll && !$c(scr.f) { scroll.c $c(scr.i) $c(scr) }
  elseif !$c(scr.f) {
    var %t $+($iif($show,$+($s,$c(t),.),$s),$s,$replace($iif($show,$left($nopath($longfn($1-)),-4),$1-),$chr(32),$s),$s,$chr(40),mC,$chr(41),$str($s,4))
    if $len(%t) < 34 { %t = %t $+ $str($s,$calc(34 - $len(%t))) }
    c scr %t | c scr.f $false | t MCL.Scroll -mo 0 500 scroll | c scr.i %i | rs tG %t
  }
}
alias -l pbar {
  d.switch $wlm
  if $1 == -init {
    var %x $2,%y $3
    d.b %x %y 107 11 0 0 1 tProgress "Arial 10 0 $s
    %x = %x + 3 | c pbar.x %x | c pbar.y $calc(%y + 3) | c pbar.o 0 | c pbar.i $calc($4 / 100)
  }
  elseif $1 == -calc { c pbar.now $int($calc($2 / $c(pbar.i))) }
  elseif $1 == -inc {
    var %s $c(pbar.o),%e $c(pbar.now)
    while %s <= %e { drawline -nr $c(drw) $g($calc(100 + %s)) 1 $calc($c(pbar.x) + %s) $c(pbar.y) $calc($c(pbar.x) + %s) $calc($c(pbar.y) + 5) | inc %s }
    drawline $c(drw)
    c pbar.o $c(pbar.now)
  }
  elseif $isid { if $c(pbar.now) != $c(pbar.o) { return $true } | else { return $false } }
  elseif $1 == -erase { d.b 0 0 $c(pl.w) 20 0 0 85 tI "Arial" 11 1 $s }
  d.switch $wm
}

;___________________________________
;Main drawing functions:
;    rs    : resets textbox to string
;    d.b   : draw textbox
;    d.t   : draw text inside box
;    d.f   : draw fade
;    d.btn : draw buttons
;    d.l -h , -v : draw line horiz/vert
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l rs {
  c tmode n | d.switch $c($+($1,.win))
  if $1 != tV { d.t $1 $c($1 $+ .bk) $c($1 $+ .o) }
  if $1 == tV {
    var %i 1,%tw 7,%x %tw
    dr -frn $wm $g($c($1 $+ .bk)) 1 $calc($c(tV.x) + %x + 5) $calc($c(tV.y)) $calc(%tw * 8) 14
    while %i <= $c(V) {
      dr -frn $wm $g($calc(%i * 35)) 1 $calc($c(tV.x) + %x + 5) $calc($c(tV.y)) %tw 14
      dr -rn $wm $g(0) 1 $calc($c(tV.x) + %x + 5) $calc($c(tV.y)) %tw 14
      inc %i | inc %x %tw
    }
    %t = $+($s,$ch($c(V)))
    dr $wm
  }
  elseif $1 == tI {
    var %t $replace($iif($cdpl,Audio CD,$nopath($c(pl))),_,$chr(32)) (trk#( $+ $sl(1).ln $+ / $+ $c(ts) $+ ) $&
      $iif($insnd,<Playing<trk# $c(t)) $iif($c(pmode) == c,<Play Continuo) $&
      $iif($c(pmode) == r,<Random) $iif($c(pmode) == p,<Repeat(One)) $iif($c(pmode) == m,<Manual) 
  }
  c $1 $+ .o $iif($2,$2-,%t)
  c tmode $s
  if $1 != tV { d.t $1 255 $c($1 $+ .o) }
}
alias -l d.switch if $isid { return $c(drw) } | else { if !$1 { c drw $wm } | else { c drw $1 } }
alias -l d.b var %i 0,%r 110 150 110 $7 | while %i < $iif($7,4,3) { dr $+(-rn,$iif($5,d),$iif($7,f)) $c(drw) $g($gettok(%r,$calc(%i + 1),32)) 1 $calc($1 + %i) $calc($2 + %i) $calc($3 - %i * 2) $calc($4 - %i * 2) $5 $6 | inc %i } | if ($8) && ($7) { c $8 $+ .x $calc($1 + 10) | c $8 $+ .y $calc($2 + 4) | c $8 $+ .w $calc($3 - 20) | c $8 $+ .h $4 | c $8 $+ .bk $7 | c $8 $+ .fn $9 | c $8 $+ .fs $10 | c $8 $+ .fo $11 | c $8 $+ .def $12- | c $8 $+ .o $12- | c $8 $+ .win $c(drw) } | dr $c(drw)
alias -l d.t dt -rc $+ $c(tmode) $c(drw) $g($2) $c($1 $+ .fn) $c($1 $+ .fs) $c($1 $+ .x) $calc($c($1 $+ .y) - $c($1 $+ .fo)) $c($1 $+ .w) 15 $3- | if $c(tmode) != n dt $c(drw) | c $1 + .o $3-
alias -l d.l var %x $2,%y $3,%wh $4,%r 110 150 110,%i 0 | while %i < 3 { drawline -nr $c(drw) $g($gettok(%r,$calc(%i + 1),32)) 1 %x %y $iif($1 == -h,$calc(%x + %wh),%x) $iif($1 == -v,$calc(%y + %wh),%y) | if $1 == -h { inc %y } | else { inc %x } | inc %i } | drawline $c(drw)
alias -l d.f {
  var %r 255,%dec $calc((%r / $3)),%i 0
  while %i <= $3 {
    drawline -rn $wm $g(%r) 1 $calc($1) $calc($2 + $4) $calc($1 + %i) $calc($2)
    dec %r %dec
    inc %i
    if %r == $c(bk) { break }
  }
  drawline $wm
}
alias -l d.btntext c $+($1,.fx) $2 | c $+($1,.fy) $3 | c $+($1,.text) $4 | c $+($1,.font) $6- | c $+($1,.fontsize) $5
alias -l d.btxt dt -ro $c($+($1,.win)) $g($2) $c($+($1,.font)) $c($+($1,.fontsize)) $c($+($1,.fx)) $c($+($1,.fy)) $c($+($1,.text))
alias -l d.tctr { if $1 == -x { var %x $calc($c($+($2,.sx)) / 2),%w $calc($width($3,$5-,$4) / 2),%r $calc($c($+($2,.x)) + (%x - %w) + 2) | return %r } }
alias -l d.samex d.btntext $1 $calc($d.tctr(-x,$1,$s $+ $3,10,"Arial") + 3) $calc($2 - 6) $3 10 "Arial"
alias -l d.btn {
  ;Parameters: d.btn <x> <y> <w> <h> <name> (new param)<style>         :Alias is Compatible with window switching
  c $+($5,.x) $1 | c $+($5,.y) $2 | c $+($5,.sx) $3 | c $+($5,.sy) $4 | c $+($5,.win) $c(drw)
  c $+($5,.style) $6 | c $+($5,.stylep1) $8 | c $+($5,.stylep2) $9 | var %s
  %s = $iif($3 < $4,$3,$4)
  var %sx $3,%sy $4,%r 30,%i $calc((255 - %r) / %s * 3),%x $1,%y $2,%t 12 "Courier New",%t2 20 "WingDings"
  if $6 == Elliptical || !$6 || $6 == Round { c $+($5,.1stc) %r | while (%sx >= $calc($c($5 $+ .sx) / 2) && %sy >= $calc($c($5 $+ .sy) / 2))  { dr $iif($6 == Round,-dfrn,-efrn) $c(drw) $g(%r) 1 %x %y %sx %sy $iif($6 == Round,$8 $9) | dec %sx 2 | dec %sy 2 | inc %r %i | inc %x | inc %y } }
  elseif $6 == Flat { c $+($5.lstc) $7 | dr -dnfr $c(drw) $g($calc($7 + 50)) 1 %x %y %sx %sy $8 $9 | dr -dnr $c(drw) $g($7) 3 %x %y %sx %sy $8 $9 }
  dr $c(drw) | %x = $int($calc($1 + ($3 / 2))) | %y = $int($calc($2 + ($4 / 2)))
  if $+(*,$5,*) iswm $c(btns) {
    if $5 == cP d.btntext $5 $calc(%x - 6) $calc(%y - 8) $+($chr(124),>) %t
    elseif $5 == cS d.btntext $5 $calc(%x - 7) $calc(%y - 9) ¨ $replace(%t2,20,17)
    elseif $5 == cPa d.btntext $5 $calc(%x - 6) $calc(%y - 8) $str($chr(124),2) %t
    elseif $5 == cPr d.btntext $5 $calc(%x - 11) $calc(%y - 11) Ç %t2
    elseif $5 == cN d.btntext $5 $calc(%x - 9) $calc(%y - 9) Ê %t2
    elseif $5 == cU d.btntext $5 $calc(%x - 8) $calc(%y - 10) ñ %t2
    elseif $5 == cD d.btntext $5 $calc(%x - 7) $calc(%y - 10) ò %t2
    elseif $5 == cH d.btntext $5 $calc(%x - 7) $calc(%y - 10) 3 %t2
    elseif $5 == cC d.btntext $5 $calc(%x - 3) $calc(%y - 8) X %t
    elseif $5 == cM d.btntext $5 $calc(%x - 4) $calc(%y - 12) _ %t
    elseif $5 == cVd d.btntext $5 $calc(%x - 6) $calc(%y - 5) ß $replace(%t2,20,10)
    elseif $5 == cVu d.btntext $5 $calc(%x - 5) $calc(%y - 5) à $replace(%t2,20,10)
    elseif $5 == cAddDir d.btntext $5 $calc(%x - 7) $calc(%y - 6) Dir 10 "Arial"
    elseif $5 == cAddRec d.btntext $5 $calc(%x - 15) $calc(%y - 6) w/Rec 10 "Arial"
    elseif $5 == cAddFile d.btntext $5 $calc(%x - 8) $calc(%y - 6) File 10 "Arial"
    elseif $5 == cRemSel d.btntext $5 $calc(%x - 8) $calc(%y - 6) Sel 10 "Arial"
    elseif $5 == cRemAll d.btntext $5 $calc(%x - 6) $calc(%y - 6) All 10 "Arial"
    elseif $5 == cLoad d.btntext $5 $calc(%x - 12) $calc(%y - 6) Load 10 "Arial"
    elseif $5 == cSave d.btntext $5 $calc(%x - 13) $calc(%y - 6) Save 10 "Arial"
    elseif $5 == cID3update d.samex $5 %y Update
    elseif $5 == cID3done d.btntext $5 $calc(%x - 3) $calc(%y - 7) X $replace(%t,12,10)
    elseif $5 == cID3help d.btntext $5 $calc(%x - 3) $calc(%y - 7) ? $replace(%t,12,10)
    elseif (cC* iswm $5) d.samex $5 %y Change
    if $c($5 $+ .font) { d.btxt $5 0 }
  }  
}

;___________________________________
;            Button Highlighting/Chk:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l b { 
  dr $c($5 $+ .p) $c($5 $+ .win) $g($c(rgb)) 1 $1 $2 $3 $4 $c(btn.p1) $c(btn.p2) | d.btxt $5 $c(rgb)
  if ($calc($c(reps) / 2) == $c(i)) { c f $true }
  if ($c(f)) c rgb $calc($c(rgb) - $c(inc))
  else c rgb $calc($c(rgb) + $c(inc))
  c i $calc($c(i) + 1)
  if $c(i) > $c(reps) { c bn | dr $c($5 $+ .p) $c($5 $+ .win) $g($c($5 $+ .1stc)) 1 $1 $2 $3 $4 $c(btn.p1) $c(btn.p2) | d.btxt $5 0 }
}
alias -l btn var %o $c(bn) | if $timer(MCLb $+ %o) { t MCLb $+ %o off | dr $c(%o $+ .p) $c($+(%o,.win)) $g($c(%o $+ .1stc)) 1 $c(%o $+ .x) $c(%o $+ .y) $c(%o $+ .sx) $c(%o $+ .sy) $c(%o $+ .stylep1) $c(%o $+ .stylep2) | d.btxt %o 0 } | c i 1 | c reps 30 | c f $false | c rgb $c($1 $+ .1stc) | c inc $calc((255 - $c($1 $+ .1stc)) / ($c(reps) / 2)) | c bn $1 | t MCLb $+ $1 -ho $c(reps) 5 b $c($1 $+ .x) $c($1 $+ .y) $c($1 $+ .sx) $c($1 $+ .sy) $1
alias -l btn.chk {
  m.deSel
  var %n $numtok($c(btns),44),%i 1,%b,%win $1
  while %i <= %n {
    %b = $gettok($c(btns),%i,44)
    if $inrect($2,$3,$c(%b $+ .x),$c(%b $+ .y),$c(%b $+ .sx),$c(%b $+ .sy)) && ($c(%b $+ .win) == %win) {
      c %b $+ .p $iif($c(%b $+ .style) == round,-dr,-er)
      c btn.p1 $iif($c(%b $+ .stylep1),$ifmatch) | c btn.p2 $iif($c(%b $+ .stylep2),$ifmatch)
      btn %b | pc $right(%b,-1) $sl(1).ln | break
    }
    inc %i
  }
}
;___________________________________
;                     Shortcut Keys:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l key.handle {
  var %i 2,%f $+(",$scriptdir,MCMP3KEYS.CFG,"),%l $lines(%f),%t,%val $1,%chr $2
  while %i <= %l {
    %t = $read(%f,%i) | tokenize 32 %t
    if ($eval($+(%,$1),2) == $2) { if (($mouse.key & $3) || ($3 == no)) { $4- | break } }
    inc %i
  }
}
;___________________________________
;                       Misc Events:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
on *:close:$($wm): x
on *:exit: x exit
on *:unload: mecho MoonClouD mp3 e' ora disinstallato.
alias -l id3a if $w($wID3) { md ShowWin $w($wID3).hwnd }
alias -l plH if $c(plhide) { c plHide $false }
on *:active:*: {
  var %ok $false
  if $active == $wm { if !$c(plHide) { md ShowWin $w($wl).hwnd | md ShowWin $w($wlm).hwnd } | id3a | %ok = $true }
  elseif $active == $wl { if !$c(plHide) { md ShowWin $w($wlm).hwnd } | else { md HW $w($wl).hwnd } | id3a | %ok = $true }
  elseif $active == $wlm { if !$c(plHide) { md ShowWin $w($wl).hwnd } | else { md HW $w($wlm).hwnd } | id3a | %ok = $true }
  elseif $active == $wID3 { if !$c(plHide) { md ShowWin $w($wl).hwnd | md ShowWin $w($wlm).hwnd } | %ok = $true }
  if %ok { md ShowWin $w($wm).hwnd }
}
#mc3mp3end off
on *:keydown:*:* { if ($wm == $active) || ($wlm == $active) || ($wl == $active) { key.handle $keychar $keyval } }
#mc3mp3end end
alias -l ia.d { w -a $wm | if !$dialog(ia.d) { dialog -ma ia.d ia.t } }
dialog -l ia.t {
  title "Invalid Action"
  size -1 -1 123 38
  icon $mcicon
  option dbu notheme
  text "The following action cannot be completed on an Audio CD Playlist.", 1, 1 2 121 19
  button "Ok", 2, 43 22 37 12, ok
}
;___________________________________
;          Spam Template Tag Editor:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l spam.edit w -a $wm | dialog -adm spam.d spam.t
alias -l spam.get { var %i 1,%l $did(1).lines,%temp | while %i <= %l { %temp = $+(%temp,$did(1,%i)) | inc %i } | return %temp }
alias -l spam.send {
  if $c(spam.target) == 2 { mecho $tags.val($1,$c(spam.template)) }
  elseif $c(spam.target) == 1 {
    var %i 1
    while $gettok($c(spam.chan),%i,44) { if ($me ison $ifmatch) { msg $gettok($c(spam.chan),%i,44) $tags.val($1,$c(spam.template)) } | inc %i }
  }
}
dialog -l spam.t {
  title "Spam editor"
  size -1 -1 98 145
  option dbu notheme
  icon $mcicon
  edit "", 1, 4 10 90 18, multi return autovs
  list 2, 4 37 50 56, size
  text "Tags:", 3, 4 29 31 8
  button "Insert tag", 4, 56 38 37 12
  button "Default", 5, 56 52 37 12
  button "Ok", 6, 56 80 37 12, ok
  button "Preview", 8, 56 66 37 12
  box "Show spam in:", 9, 1 97 96 46
  radio "Channels:", 10, 4 106 34 10, group
  radio "Echo in active window", 11, 4 118 81 10
  radio "Do NOT display", 12, 4 130 81 10
  edit "", 13, 39 105 54 10, autohs
  box "Spam Template:", 14, 1 1 96 95
}
on *:dialog:spam.d:*:*: {
  if $devent == init { didtok $dname 2 44 $pl.tags | did -ra $dname 1 $c(spam.template) | did -ra $dname 13 $c(spam.chan) | did -c $dname $calc(10 + $c(spam.target) - 1) }
  if *click* iswm $devent {
    if $did == 5 { did -ra $dname 1 playing) <file> )<length>)<kbps>kbPS)<filesize> (mC) }
    if $did == 6 { c spam.template $spam.get | c spam.chan $did(13) }
    if $did == 8 {
      if $c(ts) < 1 || !$sl(1) { dialog -v spam.d | t -mo 1 0 var %s $input(There are no files in the playlist.. please add at least one file and select it to generate a preview.,$calc(4 + 256),Error) | return }
      mecho Preview of Spam: $tags.val($p($sl(1).ln),$spam.get)
    }
    if $did == 2 || $did == 4 { if $devent == sclick && $did == 2 { return } | did -a $dname 1 $did(2,$did(2).sel) }
    if $did >= 10 && $did <= 12 { c spam.target $calc($did - 9) }
  }
}

;___________________________________
;          Playlist View Tag Editor:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
dialog -l pview.t {
  title "Playlist Template"
  size -1 -1 109 105
  option dbu notheme
  icon $mcicon
  edit "", 1, 4 9 101 12, autohs
  list 2, 4 32 60 49, sort size
  button "Insert Tag", 4, 67 33 36 12
  button "Default", 5, 67 47 36 12
  button "Ok", 6, 17 90 35 12, ok
  box "Template:", 8, 1 1 107 85
  button "Help", 10, 67 61 36 12
  button "Cancel", 3, 56 90 35 12, cancel
  text "Tags:", 7, 5 23 25 8
}
on *:dialog:pview.d:*:*: {
  if $devent == init { didtok $dname 2 44 $pl.tags | did -ra $dname 1 $c(pview) }
  if $devent == sclick {
    if $did == 6 { if $c(pview) != $did(1) { c pview $did(1) | pl.cview } }
    if $did == 5 { did -ra $dname 1 <file> }
    if $did == 10 { help }
  }
  if *click* iswm $devent && ($did == 2 || $did == 4) { if $did == 2 && $devent == sclick { return } | did -a $dname 1 $did(2,$did(2).sel) }
}

;___________________________________
;              Find mp3 in playlist:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l find.mp3 w -a $wm | dialog -adm find.d find.t
dialog -l find.t {
  title "Find song in Playlist"
  icon $mcicon
  size -1 -1 163 31
  option dbu notheme
  text "Song to Find:", 1, 1 6 31 8
  edit "", 2, 31 5 88 10, autohs
  text "You may use wildcards such as * and ?", 3, 1 18 98 8
  button "Find", 4, 123 4 37 11
  button "Find Next", 5, 123 18 37 11
  button "",6,0 50 5 5, cancel
}
on *:dialog:find.d:init:0: { if $c(find.last) { did -ra $dname 2 $c(find.last) } }
on *:dialog:find.d:sclick:*: {
  var %fl
  if $did == 4 { %fl = $fline($wl,$did(2),1,0) | c find.l 0 }
  if $did == 5 { c find.l $iif($c(find.l) > 0,$calc($c(find.l) + 1),2) | %fl = $fline($wl,$did(2),$c(find.l),0) }
  if %fl { sline $wl %fl } | c find.last $did(2)
}
;___________________________________
;       Player Color aliases/events:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l rgb.w { w -a $wm | dialog -adm rgb.d rgb.t }
alias -l rgb.setd {
  tokenize 46 $1- | did -u $dname 11,12,13
  did -ra rgb.d 5 $1 | did -c rgb.d 8 $abs($did(5)) | if $1 < 0 did -c rgb.d 11
  did -ra rgb.d 6 $2 | did -c rgb.d 9 $abs($did(6)) | if $2 < 0 did -c rgb.d 12
  did -ra rgb.d 7 $3 | did -c rgb.d 10 $abs($did(7)) | if $3 < 0 did -c rgb.d 13
}
alias -l pre {
  var %h mCmp3.presets
  if $1 == -r && $hget(%h) { hsave -o %h $RGBfile | hfree %h | return }
  if $1 == -d && $hget(%h) { hdel %h $2 | return }
  if $1 == -l { if !$hget(%h) { hmake %h } | if $isfile($RGBfile) { hload %h $RGBfile | return } }
  if $isid { if $1 { return $hget(%h,$1) } | else { return $hget(%h) } }
  else { hadd -m %h $1 $2- }
}
dialog -l rgb.t {
  title "Player color settings"
  size -1 -1 112 135
  option dbu notheme
  icon $mcicon
  box "RGB Values:", 1, 1 1 110 41
  edit "", 5, 32 9 17 10, read
  edit "", 6, 32 19 17 10, read
  edit "", 7, 32 29 17 10, read
  scroll "", 8, 50 11 57 6, range 255 horizontal
  scroll "", 9, 50 21 57 6, range 255 horizontal
  scroll "", 10, 50 31 57 6, range 255 horizontal
  check "Red:", 11, 5 10 26 9
  check "Green:", 12, 5 20 26 9
  check "Blue:", 13, 5 30 26 9
  box "RGB value presets:", 14, 1 45 110 71
  text "Preset name:", 15, 5 54 33 8
  button "Add", 16, 81 62 26 12
  button "Delete", 17, 81 76 26 12
  combo 18, 5 62 73 52, sort size vsbar
  button "Ok", 19, 2 120 25 12, ok
  button "Cancel", 20, 29 120 25 12, cancel
  button "Apply", 21, 56 120 25 12
  button "Help", 22, 84 120 25 12
}
on *:dialog:rgb.d:sclick:* {
  if $did == 16 {
    var %n $replace($did(18,0),$chr(32),_)
    if %n { if !$pre(%n) { did -a $dname 18 %n } | pre %n $+($did(5),.,$did(6),.,$did(7)) }
  }
  if $did == 17 {
    var %l $did(18).sel,%n | %n = $did(18,%l)
    if %n { pre -d %n | did -d $dname 18 %l }
  }
  if $did == 18 { rgb.setd $pre($did(18)) }
  if $did == 19 || $did == 21 {
    var %r $+($did(5),.,$did(6),.,$did(7))
    if %r != $c(sh) && $numtok(%r,$asc(.)) == 3 { c sh %r | mcl.draw | pl.draw -rgn | $iif($w($wID3),id3.draw -rgn) }
  }
  if $did == 20 && $c(shtemp) != $c(sh) { c sh $c(shtemp) | mcl.draw | pl.draw -rgn | $iif($w($wID3),id3.draw -rgn) }
  if $did == 22 { help }
  if $did >= 11 && $did <= 13 { var %c $calc($did - 6),%v $calc($did - 3) | did -ra $dname %c $iif($did($did).state && $did(%v).sel != 0,$calc($did(%v).sel * -1),$did(%v).sel) }
  if $did == 19 || $did == 20 { pre -r }
}
on *:dialog:rgb.d:init:* {
  pre -l
  var %i 1,%j $hget(mCmp3.presets,0).item | while %i <= %j { did -a $dname 18 $hget(mCmp3.presets,%i).item | inc %i }
  c shtemp $c(sh) | rgb.setd $c(sh)
}
on *:dialog:rgb.d:scroll:* { var %c $calc($did - 3),%v $calc($did + 3) | did -ra $dname %c $iif($did(%v).state && $did($did).sel != 0,$calc($did($did).sel * -1),$did($did).sel) }

;___________________________________
;                      About Dialog:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l about w -a $wm | dialog -adm about.d about.t
dialog -l about.t {
  title "About mCmp3"
  size -1 -1 119 50
  icon $mcicon
  option dbu notheme
  text "MoonClouD Mp3", 1, 2 2 43 8
  text "", 2, 2 10 30 8
  link "mooncloud@eudoramail.com", 3, 48 1 75 8
  text "Author: KoOoRn", 4, 2 19 42 8
  button "Ok", 5, 80 13 37 12, ok
  text "Send bugs, and suggestions to above email address.  Comments like, 'Your script blows' or 'I don't like the name,' will be ignored.", 6, 2 29 111 23
}
on *:dialog:about.d:init:0: did -ra $dname 2 Version: $mcVer 
on *:dialog:about.d:sclick:*: if $did == 3 { run mailto:mooncloud@eudoramail.com }
;___________________________________
;                     Drawn menubar:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
alias -l m {
  if $1 == -r { hfree mCmp3.menu | return }
  elseif ($isid) {
    if ($1) return $hget(mCmp3.menu,$1)
    else { return $hget(mCmp3.menu) }
  }
  else { hadd -m mCmp3.menu $1 $2- }
}
alias -l m.get {
  var %i 1,%m,%x,%y,%w,%h $m(menu.h)
  if $3 != sub {
    while %i <= $m(menu.subs) {
      %x = $m($+(menu.,%i,.x)) | %y = $m($+(menu.,%i,.y)) | %w = $m($+(menu.,%i,.w))
      if $inrect($1,$2,%x,%y,%w,%h) { return %i } | inc %i
    }
  }
  else {
    %i = 1 | %m = $m(menu.sel) | %w = $calc($w($wp).w - ($m(menu.bw) * 2))
    while %i <= $m($+(menu.,%m,.subs)) {
      %x = $m($+(menu.,%m,.,%i,.x)) | %y = $m($+(menu.,%m,.,%i,.y))
      if $inrect($1,$2,%x,%y,%w,%h) { return %i } | inc %i
    }
  }
  return 0
}
alias -l m.sel {
  if $1 < 1 { return }
  var %x,%y,%w,%h
  %x = $m($+(menu.,$1,.x)) | %y = $m($+(menu.,$1,.y)) | %w = $m($+(menu.,$1,.w)) | %h = $m($+(menu.,$1,.h)) - 1
  c tmode $s
  dr -fr $wm $g($iif($2 == deSel,$c(bk),175)) 1 %x %y %w %h | dt -rc $wm $g($iif($2 == deSel,255,0)) $m(menu.font) $m(menu.fontsize) %x %y %w %h $m($+(menu.,$1,.name))
  if $2 != deSel { m menu.sel $1 }
}
alias -l m.deSel { if ($m(menu.sel) > 0) { m.sel $m(menu.sel) deSel | m.popup -close $1 } }
alias -l chk_ m $+(menu.,$1,.,$2.chk) $3
alias -l m.chk {
  if $1 == c { chk_ 2 2 $true | chk_ 2 3 $false | chk_ 2 4 $false | chk_ 2 5 $false | c pmode $1 }
  if $1 == r { chk_ 2 3 $true | chk_ 2 2 $false | chk_ 2 4 $false | chk_ 2 5 $false | c pmode $1 }
  if $1 == m { chk_ 2 4 $true | chk_ 2 2 $false | chk_ 2 3 $false | chk_ 2 5 $false | c pmode $1 }
  if $1 == p { chk_ 2 5 $true | chk_ 2 2 $false | chk_ 2 3 $false | chk_ 2 4 $false | c pmode $1 }
  if $1 == dclick { chk_ 2 7 $true | chk_ 2 8 $false | c clickmode $1 }
  if $1 == sclick { chk_ 2 8 $true | chk_ 2 7 $false | c clickmode $1 }
  if $1 == plUseColor { c plColor $iif($c(plColor),$false,$true) | chk_ 2 14 $c(plColor) | pl.color }
  if $2 != -notext { rs tI }
}
alias -l m.dl { drawline -r $wp $g($calc($c(bkpop) - 30)) 1 $1 $2 $3 $4 | drawline -r $wp $g($calc($c(bkpop) + 30)) 1 $1 $calc($2 + 1) $3 $calc($4 + 1) }
alias -l m.db { ; $1 x $2 y $3 w $4 h
  drawline -r $wp $g($calc($c(bkpop) - 30)) 1 $1 $calc($2 + $4) $1 $2 $calc($1 + $3) $2
  drawline -r $wp $g($calc($c(bkpop) + 30)) 1 $1 $calc($2 + $4) $calc($1 + $3) $calc($2 + $4) $calc($1 + $3) $2
}
alias -l m.p.c w -u $wp | md HW $w($wp).hwnd | w -a $wm | w -c $wp 
alias -l m.popup {
  if *-close* iswm $1 { t -ho 1 50 m.p.c | m $+(menu.,$m(menu.sel),.sel) 0 | m menu.sel 0 | return }
  var %x,%y,%w,%h,%i 1,%n,%sw $w(-1).w,%sh $w(-1).h
  %x = $m($+(menu.,$1,.x)) | %y = $m($+(menu.,$1,.y)) | %w = $calc($m($+(menu.,$1,.long)) + 6) | %h = $calc($m($+(menu.,$1,.suby)) + ($m(menu.h) / 2))
  if $calc($w($wm).dx + %x + %w) > %sw { %x = $calc(%x + %w) }
  if $calc($w($wm).dy + $m(menu.h) + %h + (%h / 2)) >= %sh { %y = $calc(%y - %h - $m(menu.h)) }
  w -Bdfhop +dL $wp $calc($w($wm).dx + %x) $calc($w($wm).dy + %y + $m(menu.h)) %w %h $wp
  dr -rf $wp $g(0) 1 0 0 %w %h
  wr wrSelectWindow $w($wp).hwnd | wr wrSetMode rmRoundRect | wr wrSetRegion 0 0 $w($wp).w $w($wp).h 10 10
  dr -fr $wp $g(30) 1 0 0 %w %h | dr -dfr $wp $g(70) 1 1 1 $calc(%w - 3) $calc(%h - 3) 10 10 | dr -dfr $wp $g($c(bkpop)) 1 2 2 $calc(%w - 5) $calc(%h - 5) 10 10
  c tmode n
  while %i <= $m($+(menu.,$1,.subs)) {
    %n = $m($+(menu.,$1,.,%i,.name))
    if *-* iswm %n {
      %n = $right(%n,-1)
      %x = $calc(($w($wp).w / 2) - ($m($+(menu.,$1,.,%i,.w)) / 2)) | %y = $m($+(menu.,$1,.,%i,.y))
      if %n { m.db %x $calc(%y + 1) $m($+(menu.,$1,.,%i,.w)) $calc($m(menu.h) - 3) }
      %y = $calc($m($+(menu.,$1,.,%i,.y)) + ($m(menu.h) / 2))
      if %n {
        m.dl $calc($m(menu.bw) + 2) %y $calc(%x - 1) %y | m.dl $calc(%x + $m($+(menu.,$1,.,%i,.w)) + 1) %y $calc($w($wp).w - ($m(menu.bw) * 2)) %y
        dt -r $wp $g(0) $m(menu.font) $m(menu.fontsize) $calc(%x + 5) $calc(1 + %y - ($m(menu.h) / 2)) %n
      }
      else { m.dl $calc($m(menu.bw) + 2) %y $calc($w($wp).w - ($m(menu.bw) * 2)) %y }
    }
    else {
      if $m($+(menu.,$1,.,%i,.chk)) { dt -r $wp $g(0) "WingDings" 15 $calc($m(menu.bw) + 1) $calc($m($+(menu.,$1,.,%i,.y)) - 1) $chr(252) }
      dt -r $wp $g(0) $m(menu.font) $m(menu.fontsize) $m($+(menu.,$1,.,%i,.x)) $m($+(menu.,$1,.,%i,.y)) %n
    }
    inc %i
  }
  c tmode $s | t -ho 1 50 w -a $wp
}
alias -l m.addmain {
  var %s $calc($m(menu.subs) + 1)
  m menu.subs %s
  m $+(menu.,%s,.sel) 0
  m $+(menu.,%s,.name) $+($s,$gettok($1-,1,44))
  m $+(menu.,%s,.len) $len($m($+(menu.,%s,.name)))
  m $+(menu.,%s,.substr) $gettok($1-,$+(2,-,$numtok($1-,44)),44)
  m $+(menu.,%s,.subs) 0
  m $+(menu.,%s,.w) $calc($width($m($+(menu.,%s,.name)),$m(menu.font),$calc($m(menu.fontsize) * -1)) + 5)
  m $+(menu.,%s,.long) 0
  m $+(menu.,%s,.h) $m(menu.h)
  m $+(menu.,%s,.x) $calc($m(menu.x) + $m(menu.w) + 5)
  m $+(menu.,%s,.y) $m(menu.y)
  m $+(menu.,%s,.suby) $calc($m(menu.bw) * 2)
  m menu.w $calc($m(menu.w) + $m($+(menu.,%s,.w)))
}
alias -l m.aItem {
  var %s $calc($m($+(menu.,$1,.subs)) + 1)
  m $+(menu.,$1,.subs) %s
  if *-* iswm $2- { m $+(menu.,$1,.,%s,.name) $2- | m $+(menu.,$1,.,%s,.w) $width($right($m($+(menu.,$1,.,%s,.name)),-1),$m(menu.font),$calc($m(menu.fontsize) * -1)) }
  else { m $+(menu.,$1,.,%s,.name) $+($s,$s,$s,$s,$2-,$s,$s) | m $+(menu.,$1,.,%s,.w) $width($m($+(menu.,$1,.,%s,.name)),$m(menu.font),$calc($m(menu.fontsize) * -1)) }
  m $+(menu.,$1,.,%s,.chk) $false
  if $m($+(menu.,$1,.long)) < $m($+(menu.,$1,.,%s,.w)) { m $+(menu.,$1,.long) $m($+(menu.,$1,.,%s,.w)) }
  m $+(menu.,$1,.,%s,.x) $m(menu.bw)
  m $+(menu.,$1,.,%s,.y) $m($+(menu.,$1,.suby))
  m $+(menu.,$1,.suby) $calc($m($+(menu.,$1,.suby)) + $m(menu.h))
}
alias -l m.setcmd { m $+(menu.,$1,.,$2,.cmd) $replace($3-,$chr(32),$s) }
alias -l m.docmd { t -mo 1 75 $replace($m($+(menu.,$1,.,$2,.cmd)),$s,$chr(32)) }
alias -l m.create {
  if $m { m -r }
  var %mstr $replace($+(.,$4-),$chr(32),$s),%i 2,%d
  m menu.subs 0 | m menu.x $1 | m menu.y $2 | m menu.w 0
  m menu.font $replace($3,_,$chr(32)) | m menu.fontsize $4 | m menu.over $false | m menu.sel 0 | m menu.bw 3
  m menu.h $height(AbCd,$m(menu.font),$calc($m(menu.fontsize) * -1))
  %d = $gettok(%mstr,%i,95)
  while %d { m.addmain %d | inc %i | %d = $gettok(%mstr,%i,95) }
}

;___________________________________
;                        menu lists:
;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

menu menubar,channel {
  * Mp3 *
  .Lettore Mp3
  ..Player...: if (!$w($wm)) mCmp3 | else w -a $wm
  ..-
  ..$iif(!$w($wm),$style(2)) Play: pc P $sl(1).ln
  ..$iif(!$w($wm),$style(2)) Pausa: pc Pa
  ..$iif(!$w($wm),$style(2)) Stop: pc S
  ..$iif(!$w($wm),$style(2)) Precedente: pc Pr
  ..$iif(!$w($wm),$style(2)) Successivo: pc N
  ..-
  ..Uninstall mCmp3: if $input(sei sicuro di voler disinstallare MoonCloud MP3?,8,Conferma Uninstall) { if $w($wm) { x } | .unload -rs $+(",$script,") }
  ..-
  ..$iif(!$w($wm),$style(2)) Exit Player: x
}

menu @MoonClouD {
  uclick: {
    if $inrect($mouse.x,$mouse.y,4,26,62,23) { c TimeMode $iif($c(TimeMode) == inc,dec,inc) | rs tT $iif($insnd,$time.f($time.gd),$iif($c(TimeMode) == dec,-) $+ 00:00) }
    elseif $inrect($mouse.x,$mouse.y,$c(s.s),$calc($c(s.y) + 3),$c(s.w),$c(s.sz)) { if !$c(s.f) && $insnd { mplay -k $round($calc($c(s.sec) * ($mouse.x - $c(s.s)) * 1000),-1) } | c s.f $false }
    c scr.f $false
  }
  sclick: {
    var %x $mouse.x,%y $mouse.y,%dx $mouse.dx,%dy $mouse.dy,%s $calc($c(s.s) + $c(s.o))
    if $inrect(%x,%y,1,1,165,24) { t -ho 1 25 m.desel | mw $wm $calc(%dx - $w($wm).x) $calc(%dy - $w($wm).y) }
    elseif ($inrect(%x,%y,$m(menu.x),$m(menu.y),$m(menu.w),$m(menu.h))) {
      var %sel | %sel = $m.get(%x,%y)
      if %sel && $m(menu.sel) != %sel { m.deSel | m.sel %sel | t -ho 1 100 m.popup %sel }
      elseif %sel == $m(menu.sel) { t -mo 1 100 w -a $wp }
    }
    elseif $inrect(%x,%y,%s,$calc($c(s.y) + 3),$c(s.sz),$calc(3 + $c(s.sz))) { m.desel | if $insnd { ms } }
    elseif $inrect(%x,%y,$c(tG.x),$c(tG.y),$c(tG.w),$c(tG.h)) { m.desel | if $insnd { ms SCROLL } }
    else { m.desel | btn.chk $wm $mouse.x $mouse.y }
  }
}
menu @mcmp3.ListMain {
  sclick: { 
    if $inrect($mouse.x,$mouse.y,0,0,$c(pl.w),20) { m.desel | mw $wlm $mouse.x $mouse.y }
    elseif $inrect($mouse.x,$mouse.y,$calc($c(pl.w) - 20),$calc($c(pl.h) - 28),20,20) { m.desel | mws $mouse.dx $mouse.dy }
    else { m.desel | btn.chk $wlm $mouse.x $mouse.y }
  }
}
menu @mcmp3.List {
  lbclick: m.deSel | rs tI | if $c(clickmode) == sclick { pc P $1 } | else { id3.refresh $p($1) }
  dclick: if $c(clickmode) == dclick { pc P $1 }
  Sort Playlist...: pl Sort
  -
  Play Audio CD: pc Pcd
  -
  Playlist Font...: font | c pl.font $w($wl).font | c pl.fontsize $w($wl).fontsize | c pl.fontbold $w($wl).fontbold 
}
menu @mcmp3.ID3 {
  sclick: {
    if $inrect($mouse.x,$mouse.y,0,0,$calc($c(id3.w) - 40),20) { m.desel | mw $wID3 $mouse.x $mouse.y }
    else { m.desel | btn.chk $wID3 $mouse.x $mouse.y }
  }
}
menu @mcmp3.Popup {
  leave: m.desel
  mouse: {
    var %i $m.get($mouse.x,$mouse.y,sub),%m $m(menu.sel),%w $calc($w($wp).w - ($m(menu.bw) * 2)),%x,%os
    if %i && %i != $m($+(menu.,%m,.sel)) {
      %os = $m($+(menu.,%m,.sel)) | %x = $m(menu.bw)
      if %os > 0 && *-* !iswm $m($+(menu.,%m,.,%os,.name)) { 
        drawrect -fr $wp $g($c(bkpop)) 1 %x $m($+(menu.,%m,.,%os,.y)) %w $m(menu.h)
        dt -r $wp $g(0) $m(menu.font) $m(menu.fontsize) $m($+(menu.,%m,.,%os,.x)) $m($+(menu.,%m,.,%os,.y)) $m($+(menu.,%m,.,%os,.name))
        if $m($+(menu.,%m,.,%os,.chk)) { dt -r $wp $g(0) "WingDings" 15 $calc($m(menu.bw) + 1) $calc($m($+(menu.,%m,.,%os,.y)) - 1) $chr(252) }
      }
      if *-* !iswm $m($+(menu.,%m,.,%i,.name)) {
        drawrect -fr $wp $g($calc($c(bkpop) + 55)) 1 %x $m($+(menu.,%m,.,%i,.y)) %w $m(menu.h)
        dt -r $wp $g(0) $m(menu.font) $m(menu.fontsize) $m($+(menu.,%m,.,%i,.x)) $m($+(menu.,%m,.,%i,.y)) $m($+(menu.,%m,.,%i,.name))
        if $m($+(menu.,%m,.,%i,.chk)) { dt -r $wp $g(0) "WingDings" 15 $calc($m(menu.bw) + 1) $calc($m($+(menu.,%m,.,%i,.y)) - 1) $chr(252) }
      }
      if $m($+(menu.,%m,.,%os,.chk)) { dt -r $wp $g(0) "WingDings" 15 $calc($m(menu.bw) + 1) $calc($m($+(menu.,%m,.,%os,.y)) - 1) $chr(252) }
      m $+(menu.,%m,.sel) %i
    }
  }
  uclick: var %i $m.get($mouse.x,$mouse.y,sub),%m $m(menu.sel) | if %i { m.desel | m.docmd %m %i }
}
