on *:LOAD: {
  mkdir MP3Player\
  mp3ini main size large
  mp3ini main ldir C:\
  write -a $qt(MP3Player\bcmsg.txt) NP: &artist - &title [&length]
  mp3ini broadcast method msg
  mp3ini broadcast chan active
  mp3ini broadcast auto off
  mp3ini color text 255,255,255
  mp3ini color background 0,0,0
  mp3ini shoutbox status on
  mp3ini icons set omega
  if (!$mp3ini(shoutbox,added)) {
    shoutcount
    mp3ini shoutbox added 1
  }
}
on *:START: { if ($mp3ini(toolbar,status) == on) { mp3.toolbar } }
dialog mp3 {
  title "Buzz-Zyrus SoulFly Quantum MP3 Player"
  icon icons\zyrus.ico, 0
  size -1 -1 360 346
  option pixels
  list 23, 334 90 20 22
  list 2, 4 52 352 24, size
  list 3, 4 74 280 32, size
  text "", 5, 16 10 80 30
  list 28, 4 314 340 32, size
  text "", 7, 109 26 242 16, center
  text "", 6, 110 10 242 16, center
}
alias -l mp3.toolbar {
  toolbar -r
  toolbar -as line
  toolbar -az1 mp3 Open $mp3.icons(mp3.ico) /mp3
  toolbar -az1 prev Previous $mp3.icons(prev.ico) /mp3.previous
  toolbar -az1 play Play $mp3.icons(play.ico) /mp3.play
  toolbar -az1 pause Pause $mp3.icons(pause.ico) /mp3.pause
  toolbar -az1 stop Stop $mp3.icons(stop.ico) /mp3.stop
  toolbar -az1 next Next $mp3.icons(next.ico) /mp3.next
}
on *:MP3END: { mp3.next }
alias -l mp3.next {
  if ($mp3ini(main,mode) == once) { mp3.stop }
  if ($mp3ini(main,mode) == continuous) {
    if ($mp3ini(main,songnum) == $lines($qt(MP3Player\list.txt))) { mp3.stop }
    else {
      mp3ini main songnum $calc($mp3ini(main,songnum) + 1)
      mp3.play $mp3.insong
    }
  }
  if ($mp3ini(main,mode) == random) {
    mp3ini main songnum $rand(1,$lines($qt(MP3Player\list.txt)))
    mp3.play $mp3.insong
  }
  if ($mp3ini(main,mode) == repeat) { mp3.play $mp3.insong }
}
alias -l mp3.previous {
  if ($mp3ini(main,mode) == once || $mp3ini(main,mode) == continuous) { 
    if ($mp3ini(main,songnum) == 1) { mp3.play $mp3.insong }
    else {
      mp3ini main songnum $calc($mp3ini(main,songnum) - 1)
      mp3.play $mp3.insong
    }  
  }
  if ($mp3ini(main,mode) == random) {
    mp3ini main songnum $rand(1,$lines($qt(MP3Player\list.txt)))
    mp3.play $mp3.insong
  }
  if ($mp3ini(main,mode) == repeat) { mp3.play $mp3.insong }
}
alias -l ldir {
  var %ld = $sdir($iif($mp3ini(main,ldir),$v1,C:\),Choose an MP3 directory)
  mp3ini main ldir %ld
  return %ld
}
alias f12 { mp3.broadcast }
on *:DIALOG:mp3:DCLICK:8: { 
  mp3ini main songnum $did(mp3,8).sel
  mp3.play $mp3.insong 
}
alias -l checklist {
  if ($1 == once) { return $iif($mp3ini(main,mode) == once,+c,+) }
  if ($1 == continuous) { return $iif($mp3ini(main,mode) == continuous,+c,+) }
  if ($1 == random) { return $iif($mp3ini(main,mode) == random,+c,+) }
  if ($1 == repeat) { return $iif($mp3ini(main,mode) == repeat,+c,+) }
}
alias -l mp3.cbc {
  if ($1 == on) { return $iif($mp3ini(broadcast,auto) == on,+c,+) }
  if ($1 == off) { return $iif($mp3ini(broadcast,auto) == off,+c,+) }
}
alias mp3pops {
  if ($xpopup(mp3menu).ismenu) { xpopup -d mp3menu }
  xpopup -c mp3menu office2003
  xpop -a mp3menu 1 $chr(9) + 8 0 Search
  xpop -a mp3menu 1 $chr(9) + 7 0 -
  xpop -a mp3menu 1 $chr(9) + 6 0 MP3 Information
  xpop -a mp3menu 1 $chr(9) + 5 0 -
  xpop -a mp3menu 1 $chr(9) + 4 0 Remove All
  xpop -a mp3menu 1 $chr(9) + 3 0 Remove File
  xpop -a mp3menu 1 $chr(9) + 2 0 Add File
  xpop -a mp3menu 1 $chr(9) + 1 0 Add Directory
  xpopup -s mp3menu +t $mouse.dx $mouse.dy
}
on *:DIALOG:mp3:SCLICK:*: {
  if ($did == 23) { 
    if ($mp3ini(main,size) == large) { mp3ini main size small }
    elseif ($mp3ini(main,size) == small) { mp3ini main size large }
    mp3.size
  }
  if ($did == 3) { 
    var %sel = $did(mp3,3,1).sel
    if (%sel == 2) { mp3.previous }
    if (%sel == 3) {
      mp3ini main songnum $did(mp3,8).sel
      mp3.play $mp3.insong 
    }
    if (%sel == 4) { mp3.pause }
    if (%sel == 5) { mp3.stop }
    if (%sel == 6) { mp3.next }
  }
  if ($did == 28) {
    var %sel = $did(mp3,28,1).sel
    if (%sel == 2) { 
      if ($xpopup(fmenu).ismenu) { xpopup -d fmenu }
      xpopup -c fmenu office2003
      xpop -a fmenu 1 $chr(9) + 4 0 Remove all
      xpop -a fmenu 1 $chr(9) + 3 0 Remove file
      xpop -a fmenu 1 $chr(9) + 2 0 Add file
      xpop -a fmenu 1 $chr(9) + 1 0 Add directory
      xpopup -s fmenu +t $mouse.dx $mouse.dy
    }
    if (%sel == 3) { 
      if ($xpopup(pmenu).ismenu) { xpopup -d pmenu }
      xpopup -c pmenu office2003
      xpop -a pmenu 1 $chr(9) $checklist(repeat) 4 0 Repeat
      xpop -a pmenu 1 $chr(9) $checklist(random) 3 0 Random
      xpop -a pmenu 1 $chr(9) $checklist(continuous) 2 0 Continuous
      xpop -a pmenu 1 $chr(9) $checklist(once) 1 0 Once
      xpopup -s pmenu +t $mouse.dx $mouse.dy    
    }
    if (%sel == 4) { 
      if ($xpopup(bmenu).ismenu) { xpopup -d bmenu }
      xpopup -c bmenu office2003
      xpop -a bmenu 1 $chr(9) + 4 0 Options
      xpop -a bmenu 2 $chr(9) +s 1 2 Automatic Broadcasting
      xpop -a bmenu 2 1 $chr(9) $mp3.cbc(off) 3 0 Off
      xpop -a bmenu 2 1 $chr(9) $mp3.cbc(on) 2 0 On
      xpopup -s bmenu +t $mouse.dx $mouse.dy
    }
    if (%sel == 6) { dialog $iif($dialog(id3),-v,-m) id3 id3 }
    if (%sel == 7) { dialog $iif($dialog(shoutbox),-v,-m) shoutbox shoutbox }
    if (%sel == 8) { dialog $iif($dialog(mp3chat),-v,-m) mp3chat mp3chat }
    if (%sel == 9) { dialog $iif($dialog(lyrics),-v,-m) lyrics lyrics }
    if (%sel == 11) { run $iif($os == XP,sndvol32.exe,sndvol.exe) }
    if (%sel == 12) { dialog $iif($dialog(mp3color),-v,-m) mp3color mp3color }
    if (%sel == 13) { 
      dialog $iif($dialog(search),-v,-m) search search 
      dialog -bs search $dialog(mp3).x $calc($dialog(mp3).y + 375) 180 25
    }
    if (%sel == 14) {
      if ($xpopup(omenu).ismenu) { xpopup -d omenu }
      xpopup -c omenu office2003
      xpop -a omenu 1 $chr(9) +s 1 2 Icon set
      xpop -a omenu 1 1 $chr(9) $mp3.ico(ruby) 4 0 Ruby
      xpop -a omenu 1 1 $chr(9) $mp3.ico(omega) 1 0 Omega
      xpop -a omenu 1 1 $chr(9) $mp3.ico(isimple) 2 0 iSimple
      xpop -a omenu 1 1 $chr(9) $mp3.ico(crystal) 6 0 Crystal  
      xpop -a omenu 1 1 $chr(9) $mp3.ico(cleardisk) 7 0 Cleardisk
      xpop -a omenu 1 1 $chr(9) $mp3.ico(bluevelvet) 3 0 Blue Velvet
      xpop -a omenu 1 $chr(9) +s 1 10 Toolbar
      xpop -a omenu 1 10 $chr(9) $mp3.ctool(on) 11 0 On
      xpop -a omenu 1 10 $chr(9) $mp3.ctool(off) 12 0 Off
      xpopup -s omenu +t $mouse.dx $mouse.dy
    }
  }
  if ($did == 2) { if ($gettok($did(mp3,2,1).text,1,32)) .splay seek $v1 }
}
alias -l mp3.ctool {
  if ($1 == on) { return $iif($mp3ini(toolbar,status) == on,+c,+) }
  if ($1 == off) { return $iif($mp3ini(toolbar,status) == off,+c,+) }
}
alias -l mp3.ico {
  if ($1 == ruby) { return $iif($mp3ini(icons,set) == ruby,+c,+) }
  if ($1 == omega) { return $iif($mp3ini(icons,set) == omega,+c,+) }
  if ($1 == bluevelvet) { return $iif($mp3ini(icons,set) == blue velvet,+c,+) }
  if ($1 == isimple) { return $iif($mp3ini(icons,set) == isimple,+c,+) }
  if ($1 == boomy) { return $iif($mp3ini(icons,set) == boomy,+c,+) }
  if ($1 == crystal) { return $iif($mp3ini(icons,set) == crystal,+c,+) }
  if ($1 == cleardisk) { return $iif($mp3ini(icons,set) == cleardisk,+c,+) }
}
on *:SIGNAL:Xpopup-*: {
  var %m = $gettok($signal,2-,45)
  if (%m == fmenu) {
    if ($1 == 1) { $iif($dialog(mp3),mp3.adddir) }
    elseif ($1 == 2) { $iif($dialog(mp3),mp3.addfile) }
    elseif ($1 == 3) { $iif($dialog(mp3),mp3.remfile) }
    elseif ($1 == 4) { $iif($dialog(mp3),mp3.remall) }
  }
  if (%m == pmenu) {
    if ($1 == 1) { mp3ini main mode once }
    elseif ($1 == 2) { mp3ini main mode continuous }
    elseif ($1 == 3) { mp3ini main mode random }
    elseif ($1 == 4) { mp3ini main mode repeat }
  }
  if (%m == bmenu) {
    if ($1 == 4) { dialog $iif($dialog(mp3bc),-v,-m) mp3bc mp3bc }
    elseif ($1 == 2) { mp3ini broadcast auto on }
    elseif ($1 == 3) { mp3ini broadcast auto off }
  }
  if (%m == mp3menu) {
    if ($1 == 1) { $iif($dialog(mp3),mp3.adddir) }
    elseif ($1 == 2) { $iif($dialog(mp3),mp3.addfile) }
    elseif ($1 == 3) { $iif($dialog(mp3),mp3.remfile) }
    elseif ($1 == 4) { $iif($dialog(mp3),mp3.remall) }
    elseif ($1 == 8) {
      dialog $iif($dialog(search),-v,-m) search search 
      dialog -bs search $dialog(mp3).x $calc($dialog(mp3).y + 375) 180 25
    }
  }
  if (%m == omenu) {
    if ($1 == 4) { mp3.loadicons ruby }
    elseif ($1 == 1) { mp3.loadicons omega }
    elseif ($1 == 2) { mp3.loadicons isimple }
    elseif ($1 == 3) { mp3.loadicons blue velvet }
    elseif ($1 == 5) { mp3.loadicons boomy }
    elseif ($1 == 6) { mp3.loadicons crystal }
    elseif ($1 == 7) { mp3.loadicons cleardisk }
    elseif ($1 == 11) { 
      mp3ini toolbar status on
      mp3.toolbar
    }
    elseif ($1 == 12) {
      mp3ini toolbar status off
      toolbar -r
    }
  }
}
alias -l mp3.loadicons { 
  mp3ini icons set $1-
  dialog -x mp3 mp3
  dialog -m mp3 mp3
  mp3.toolbar
}
alias -l mp3.pause { splay $iif($insong.pause,resume,pause) }
alias -l mp3.stop {
  splay stop
  if ($dialog(mp3)) {
    did -ra mp3 5 00:00
    did -r mp3 7
    did -ra mp3 6 Nothing playing
    did -i mp3 2 1 params 0 0 1
    did -i mp3 2 1 params 0 0 1
  }
  remini $qt(MP3Player\config.ini) main songnum
  .timerpos off
  .timerscroll off
}
alias -l mp3.size {
  if ($mp3ini(main,size) == small) { 
    dialog -bs mp3 -1 -1 180 55
    did -i mp3 23 1 setimage icon small 0, $+ $mp3.icons(download.ico)
  }
  if ($mp3ini(main,size) == large) { 
    dialog -bs mp3 -1 -1 180 168
    did -i mp3 23 1 setimage icon small 0, $+ $mp3.icons(upload.ico)
  }
}
alias cb_mp3 { if ($1- == mp3 rclick 8) { mp3pops } }
alias -l mp3.icons {
  if ($1 == mp3.ico) { return $shortfn(MP3Player\mp3.ico) | halt }
  if ($mp3ini(icons,set) == Omega) { var %ico = MP3Player\aicons\Omega\ }
  elseif ($mp3ini(icons,set) == Ruby) { var %ico = MP3Player\aicons\Ruby\ }
  elseif ($mp3ini(icons,set) == Blue Velvet) { var %ico = MP3Player\aicons\Blue Velvet\ }
  elseif ($mp3ini(icons,set) == iSimple) { var %ico = MP3Player\aicons\iSimple\ }
  elseif ($mp3ini(icons,set) == Boomy) { var %ico = MP3Player\aicons\Boomy\ }
  elseif ($mp3ini(icons,set) == Crystal) { var %ico = MP3Player\aicons\Crystal\ }
  elseif ($mp3ini(icons,set) == Cleardisk) { var %ico = MP3Player\aicons\Cleardisk\ }
  return $shortfn($+(%ico,$1)) 
}
on *:DIALOG:mp3:INIT:0: {
  did -a mp3 5 00:00
  dcx Mark mp3 cb_mp3
  xdialog -c mp3 8 list 4 116 352 227 vsbar
  xdialog -c mp3 4 panel 4 4 100 44
  xdialog -c mp3 1 panel 106 4 250 44
  xdid -C mp3 8,4,1 +bk $rgb($gettok($mp3ini(color,background),1,44),$gettok($mp3ini(color,background),2,44),$gettok($mp3ini(color,background),3,44))
  dll $mdx SetMircVersion $version
  dll $mdx MarkDialog mp3
  dll $mdx SetControlMDX mp3 2 trackbar noticks > $bars
  did -i mp3 2 1 params $insong.pos 0 $insong.length
  dll $mdx SetControlMDX mp3 3,23,28 Toolbar flat wrap nodivider > $bars
  did -i mp3 3 1 bmpsize 32 32
  did -i mp3 3 1 setimage icon large 0, $+ $mp3.icons(prev.ico)
  did -i mp3 3 1 setimage icon large 0, $+ $mp3.icons(play.ico)
  did -i mp3 3 1 setimage icon large 0, $+ $mp3.icons(pause.ico)
  did -i mp3 3 1 setimage icon large 0, $+ $mp3.icons(stop.ico)
  did -i mp3 3 1 setimage icon large 0, $+ $mp3.icons(next.ico)
  did -a $dname 3 1 $chr(9) $+ Previous
  did -a $dname 3 2 $chr(9) $+ Play
  did -a $dname 3 3 $chr(9) $+ Pause
  did -a $dname 3 4 $chr(9) $+ Stop
  did -a $dname 3 5 $chr(9) $+ Next
  did -i mp3 23 1 bmpsize 16 16
  did -i mp3 23 1 setimage icon small 0, $+ $mp3.icons(channel.ico)
  did -a mp3 23 1 $chr(9) $+ Show
  did -i mp3 28 1 bmpsize 16 16
  did -i mp3 28 1 setimage icon small 0, $+ $mp3.icons(folder.ico)
  did -i mp3 28 1 setimage icon small 0, $+ $mp3.icons(note.ico)
  did -i mp3 28 1 setimage icon small 0, $+ $mp3.icons(world.ico) 
  did -i mp3 28 1 setimage icon small 0, $+ $mp3.icons(options.ico)
  did -i mp3 28 1 setimage icon small 0, $+ $mp3.icons(sbox.ico)
  did -i mp3 28 1 setimage icon small 0, $+ $mp3.icons(web.ico)
  did -i mp3 28 1 setimage icon small 0, $+ $mp3.icons(favs.ico)
  did -i mp3 28 1 setimage icon small 0, $+ $mp3.icons(sounds.ico)
  did -i mp3 28 1 setimage icon small 0, $+ $mp3.icons(prot.ico)
  did -i mp3 28 1 setimage icon small 0, $+ $mp3.icons(search.ico)
  did -i mp3 28 1 setimage icon small 0, $+ $mp3.icons(other.ico)
  did -i mp3 28 1 setimage icon small 0, $+ $mp3.icons(question.ico) 
  did -a mp3 28 1 $chr(9) $+ Files
  did -a mp3 28 2 $chr(9) $+ Play mode
  did -a mp3 28 3 $chr(9) $+ Broadcasting
  did -a mp3 28 4 -
  did -a mp3 28 4 $chr(9) $+ ID3 Tag Editor
  did -a mp3 28 5 $chr(9) $+ Shoutbox
  did -a mp3 28 6 $chr(9) $+ MP3 Chat
  did -a mp3 28 7 $chr(9) $+ Lyrics Finder
  did -a mp3 28 8 -
  did -a mp3 28 8 $chr(9) $+ Volume
  did -a mp3 28 9 $chr(9) $+ Color
  did -a mp3 28 10 $chr(9) $+ Search
  did -a mp3 28 11 $chr(9) $+ Other
  did -a mp3 28 12 -
  did -a mp3 28 12 $chr(9) $+ Help
  mp3.loadlist
  mp3.size
  dll $mdx SetColor mp3 1,8,4,5,6,7 text $rgb($gettok($mp3ini(color,text),1,44),$gettok($mp3ini(color,text),2,44),$gettok($mp3ini(color,text),3,44))
  dll $mdx SetColor mp3 1,4,5,7,6 background $rgb($gettok($mp3ini(color,background),1,44),$gettok($mp3ini(color,background),2,44),$gettok($mp3ini(color,background),3,44))
  dll $mdx SetColor mp3 1,4,5,7,6 textbg $rgb($gettok($mp3ini(color,background),1,44),$gettok($mp3ini(color,background),2,44),$gettok($mp3ini(color,background),3,44))
  dll $mdx SetFont mp3 1,8,6,7 13 700 Tahoma
  dll $mdx SetFont mp3 3 -11 400 Tahoma
  dll $mdx SetFont mp3 5 ANSI 34 400 Arial
  dll $mdx SetBorderStyle mp3 1,8,4 clientedge staticedge
  dll $mdx SetBorderStyle mp3 2,3,23,28
  if ($insong.fname) {
  did -a mp3 6 $replace($iif($sound($insong.fname).artist,$v1 -) $left($nopath($insong.fname),-4),$chr(32),$chr(160)) }
  did -a mp3 7 $+($sound($insong.fname).bitrate,kbps,$str($chr(160),5),$sound($insong.fname).mode,$str($chr(160),5),$calc($sound($insong.fname).sample / 1000) kHz)
  var %poss = $iif($int($calc(($insong.pos /1000)/60)) > 10,$int($calc(($insong.pos /1000)/60)), 0 $+ $int($calc(($insong.pos /1000)/60)) ) $+ : $+ $iif($round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0) > 10, $round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0), 0 $+ $round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0))
  did -a mp3 5 $replace(%poss,010,10)  
  did -c mp3 8 $mp3ini(main,songnum)
  did -i mp3 2 1 params $insong.pos 0 $insong.length
  .timerpos 0 1 mp3.updatepos
  if ($len($did(mp3,6).text) >= 42) { scrolltext 300 mp3 6 }
  elseif ($len($did(mp3,6).text) < 42) {
    .timerscroll off
    did -ra mp3 6 $replace($iif($sound($insong.fname).artist,$v1 -) $left($nopath($insong.fname),-4),$chr(32),$chr(160))
  }
  else { did -ra mp3 6 Nothing playing }
}
alias -l mp3.loadlist {
  if ($isfile($qt(MP3Player\list.txt))) {
    window -h @loadFromInit 
    loadbuf @loadFromInit $qt(MP3Player\list.txt)
    window -h @stripPath 
    filter -wk @loadFromInit mp3.listalias
    filter -wo @stripPath mp3 8
    window -c @stripPath
    window -c @loadFromInit
  }
}
alias -l mp3.listalias { aline @stripPath $left($nopath($1-),-4) }
on *:DIALOG:mp3:close:0: { 
  if ($dialog(mp3color)) { dialog -x mp3color mp3color }
  .timerpos off 
  .timerscroll off
  mp3.closedialogs
}
alias -l mp3.updatepos { 
  did -i mp3 2 1 params $insong.pos 0 $insong.length 
  var %poss = $iif($int($calc(($insong.pos /1000)/60)) > 10,$int($calc(($insong.pos /1000)/60)), 0 $+ $int($calc(($insong.pos /1000)/60)) ) $+ : $+ $iif($round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0) > 10, $round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0), 0 $+ $round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0))
  did -ra mp3 5 $replace(%poss,010,10)
  if ($len($did(mp3,6).text) < 42) { 
  did -ra mp3 6 $replace($iif($sound($insong.fname).artist,$v1 -) $left($nopath($insong.fname),-4),$chr(32),$chr(160)) }
  did -ra mp3 7 $+($sound($insong.fname).bitrate,kbps,$str($chr(160),5),$sound($insong.fname).mode,$str($chr(160),5),$calc($sound($insong.fname).sample / 1000) kHz)
}
alias -l mp3.insong { return $read($qt(MP3Player\list.txt),$mp3ini(main,songnum)) }
alias -l mp3.play {
  splay $iif(!$1-,$insong.fname,$qt($1-))
  shoutcheck
  if ($dialog(mp3)) {
    did -ra mp3 5 $iif($int($calc(($insong.pos /1000)/60)) > 10,$int($calc(($insong.pos /1000)/60)), 0 $+ $int($calc(($insong.pos /1000)/60)) ) $+ : $+ $iif($round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0) > 10, $round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0), 0 $+ $round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0))
    did -c mp3 8 $mp3ini(main,songnum)
    mp3ini main songnum $did(mp3,8).sel
    did -a mp3 6 $replace($iif($sound($mp3.insong).artist,$v1 -) $left($nopath($mp3.insong),-4),$chr(32),$chr(160)) $+ $str($chr(160),12)
    did -ra mp3 7 $+($sound($insong.fname).bitrate,kbps,$str($chr(160),5),$sound($insong.fname).mode,$str($chr(160),5),$calc($sound($insong.fname).sample / 1000) kHz)
    did -i mp3 2 1 params 0 0 1
    .timerpos 0 1 mp3.updatepos
    if ($len($did(mp3,6).text) >= 42) { scrolltext 300 mp3 6 }
    else {
      .timerscroll off
      did -o mp3 6 1 $left($did(mp3,6).text,-12)     
    }
  }
  if ($mp3ini(broadcast,auto) == on) { mp3.broadcast }
}
alias mp3 { dialog $iif($dialog(mp3),-v,-m) mp3 mp3 }
alias -l mp3ini {
  if ($isid) { return $readini($qt(MP3Player\config.ini),$1,$2) }
  else { writeini $qt(MP3Player\config.ini) $1 $2 $3- }
}
alias -l mp3.addfile {
  var %f = $sfile(C:\*.mp3,Choose an MP3)
  write -a $qt(MP3Player\list.txt) $iif(%f,%f)
  did -a mp3 8 $left($nopath(%f),-4)
}
alias -l mp3.adddir {
  if ($ldir(/,Choose mp3 directory)) {
    var %d = $v1
    window -h @mp3files
    window -h @mp3names
    noop $findfile(%d,*.mp3,0,mp3.adddir2 $1-)
    filter -wo @mp3names mp3 8
    savebuf -a @mp3files $qt(MP3Player\list.txt)
    window -c @mp3names
    window -c @mp3files
  }
}
alias -l mp3.adddir2 { 
  aline @mp3names $left($nopath($1-),-4)
  aline @mp3files $1- 
}
alias -l mp3.remfile {
  if (!$did(mp3,8).sel) { noop $input(You have not selected any file to remove!,uwo,Error!) }
  else { 
    did -d mp3 8 $did(mp3,8).sel
    write -dl $+ $did(mp3,8).sel $qt(MP3Player\list.txt)
  }
}
alias -l mp3.remall {
  if ($input(Are you sure you want to remove all files?,iou,Attention!) == $true) {
    write -c $qt(MP3Player\list.txt)
    did -r mp3 8
    splay stop
  }
}
alias -l mp3.addlist {
  write -a $qt(MP3Player\list.txt) $1-
  if ($dialog(mp3)) { did -a mp3 8 $left($nopath($1-),-4) }
}
dialog search {
  title "Search"
  icon $mp3.icons(search.ico), 0
  size -1 -1 180 25
  option dbu
  edit "", 1, 2 2 176 10
  button "Search", 2, 98 13 40 11
  button "Search && Play", 3, 139 13 40 11
}
on *:DIALOG:search:sclick:*: {
  if ($did == 2) {
    if ($hget(mp3,previousSearch) != $did(search,1).text) var %line = 1
    else var %line = $iif($did(mp3,8,1).sel,$v1 + 1,1)
    var %nextLine = $didwm(mp3,8,$+(*,$did(search,1).text,*),%line)
    hadd -m mp3 previousSearch $did(search,1).text
    if (!%nextLine) %nextLine = $didwm(mp3,8,$+(*,$did(search,1).text,*),1)
    if (%nextLine) did -c mp3 8 %nextLine
    else {
      did -ra search 1 No results.
      .timer 1 2 did -r search 1
    }
  }
  if ($did == 3) {
    if ($hget(mp3,previousSearch) != $did(search,1).text) var %line = 1
    else var %line = $iif($did(mp3,8,1).sel,$v1 + 1,1)
    var %nextLine = $didwm(mp3,8,$+(*,$did(search,1).text,*),%line)
    hadd -m mp3 previousSearch $did(search,1).text
    if (!%nextLine) %nextLine = $didwm(mp3,8,$+(*,$did(search,1).text,*),1)
    if (%nextLine) { 
      did -c mp3 8 %nextLine
      mp3ini main songnum %nextLine
      mp3.play $read($qt(MP3Player\list.txt),%nextLine)
      else {
        did -ra search 1 No results.
        .timer 1 2 did -r search 1
      }
    }
  }
}
alias -l mp3.closedialogs {
  if ($dialog(mp3bc)) { dialog -x mp3bc mp3bc }
  if ($dialog(lyrics)) { dialog -x lyrics lyrics }
  if ($dialog(search)) { dialog -x search search }
  if ($dialog(mp3color)) { dialog -x mp3color mp3color }
  if ($dialog(shoutbox)) { dialog -x shoutbox shoutbox }
  if ($dialog(id3)) { dialog -x id3 id3 }
}
dialog mp3bc {
  title "MP3 Broadcasting"
  icon $mp3.icons(mp3.ico), 0
  size -1 -1 180 116
  option dbu
  edit "", 1, 5 45 170 10, autohs
  list 2, 2 2 176 35, size
  box "Message (you can use mIRC identifiers/variables too!):", 3, 2 37 175 31
  button "Preview", 4, 140 56 34 10
  button "ASCII", 6, 105 56 34 10
  box "Channel configuration:", 5, 2 69 175 35
  text "Enter the channels you want broadcast to, seperated by a comma. For all channels, type 'all'. For the active channel only, type 'active'.", 7, 7 77 169 13
  edit "", 8, 5 92 170 10, autohs
  radio "/msg", 11, 6 57 26 8
  radio "/me", 12, 34 57 26 8
  button "OK", 9, 2 105 175 10
}
on *:DIALOG:mp3bc:INIT:0: {
  dll $mdx SetMircVersion $version
  dll $mdx MarkDialog mp3bc
  dll $mdx SetControlMDX mp3bc 2 listview center report grid nosortheader rowselect showsel > $views
  dll $mdx SetFont mp3bc 3,5 13 700 Tahoma
  did -i mp3bc 2 1 headerdims 100 230
  did -i mp3bc 2 1 headertext +c Token $chr(9) Value
  didtok mp3bc 2 124 &title $chr(9) Returns the title of the song|&artist $chr(9) Returns the artist of the song|&album $chr(9) Returns the album of the song|&length $chr(9) Returns the total length of the song|&pos $chr(9) Returns the current position of the song|&rem $chr(9) Returns the remaining length of the song|&genre $chr(9) Returns the genre of the song|&year $chr(9) Returns the year of the song|&bitrate $chr(9) Returns the bitrate of the song|&sample $chr(9) Returns a sample of the song|&track $chr(9) Returns the track number of the song|&mode $chr(9) Returns the playing mode|&comment $chr(9) Returns any comments on the song|&shortfn $chr(9) Returns the short filepath of the song|
  did -a mp3bc 2 &longfn $chr(9) Returns the long filepath of the song
  did -c mp3bc $iif($mp3ini(broadcast,method) == me,12,11)
  did -d mp3bc 2 $did(mp3bc,2).lines
  did -a mp3bc 1 $mp3msg
  did -a mp3bc 8 $mp3ini(broadcast,chan)
}
on *:DIALOG:mp3bc:SCLICK:*: {
  if ($did == 9) {
    if (!$did(mp3bc,1).text || !$did(mp3bc,8).text) { noop $input(Please fill in both edit fields $crlf $str($chr(160),5) $+ before pressing OK.,uwo,Error!) }
    else {
      write -l1 $qt(MP3Player\bcmsg.txt) $did(mp3bc,1).text
      mp3ini broadcast method $iif($did(mp3bc,11).state == 1,msg,me)
      mp3ini broadcast chan $did(mp3bc,8).text
      dialog -x mp3bc mp3bc
      noop $input(Your settings have been saved!,iou,Information)
    }
  }
  if ($did == 11) { mp3ini broadcast method msg }
  if ($did == 12) { mp3ini broadcast method me }
  if ($did == 6) { dialog $iif($dialog(mp3ascii),-v,-m) mp3ascii mp3ascii }
  if ($did == 4) { echo -a $did(mp3bc,1).text }
}
alias -l mp3.broadcast {
  if (!$mp3msg || !$mp3ini(broadcast,method) || !$mp3ini(broadcast,chan)) {
    var %noop = $input(MP3 Broadcast options are not set up correctly. $crlf $+ Would you like to set them up now?,ynu,Error!)
    if (%noop == $true) { dialog $iif($dialog(mp3bc),-v,-m) mp3bc mp3bc }
  }
  elseif (!$insong.fname) { noop $input(You cannot broadcast while $crlf $+ no song is playing!,uwo,Error!) }
  else {
    var %title = $iif($sound($insong.fname).title,$v1,$left($nopath($insong.fname),-4)), %artist = $iif($sound($insong.fname).artist,$v1,Unknown), %album = $iif($sound($insong.fname).album,$v1,Unknown), %length = $remove($duration($calc($insong.length /1000),3),00:), %rem = $remove($duration($calc(($insong.fname.length -$insong.pos) /1000),3),00:), %genre = $iif($sound($insong.fname).genre,$v1,Unknown), %year = $iif($sound($insong.fname).year,$v1,Unknown), %bitrate = $sound($insong.fname).bitrate, %sample = $sound($insong.fname).sample, %track = $iif($sound($insong.fname).track,$v1,Unknown), %mode = $sound($insong.fname).mode, %comment = $iif($sound($insong.fname).comment,$v1,None), %shortfn = $shortfn($insong.fname), %longfn = $longfn($insong.fname)
    var %poss = $iif($int($calc(($insong.pos /1000)/60)) > 10,$int($calc(($insong.pos /1000)/60)), 0 $+ $int($calc(($insong.pos /1000)/60)) ) $+ : $+ $iif($round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0) > 10, $round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0), 0 $+ $round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0))
    var %pos = $replace(%poss,010,10)
    var %mp3.msg = $replace($mp3msg,&title,%title,&artist,%artist,&album,%album,&length,%length,&pos,%pos,&rem,%rem,&genre,%genre,&year,%year,&bitrate,%bitrate,&sample,%sample,&track,%track,&mode,%mode,&comment,%comment,&shortfn,%shortfn,&longfn,%longfn)
    if ($mp3ini(broadcast,chan) == active) {
      if ($active == Status Window) { halt }
      $iif($mp3ini(broadcast,method) == msg,msg $active,describe $active) %mp3.msg 
    }
    elseif ($mp3ini(broadcast,chan) == all) { scon -a $iif($mp3ini(broadcast,method) == msg,amsg,ame) %mp3.msg }
    elseif ($chr(35) isin $mp3ini(broadcast,chan)) {
      var %x = 1
      while (%x <= $numtok($mp3ini(broadcast,chan),44)) {
        scon -a $iif($mp3ini(broadcast,method) == msg,msg $gettok($mp3ini(broadcast,chan),%x,44),describe $gettok($mp3ini(broadcast,chan),%x,44)) %mp3.msg
        inc %x
      }
    }
  }
}
alias -l mp3msg { return $read($qt(MP3Player\bcmsg.txt),1) }
alias -l mdx { 
  if ($isid) { return $qt($shortfn(dlls\mdx.dll)) }
  else { dll $qt($shortfn(dlls\mdx.dll)) $1- }
}
alias -l bars { return $shortfn(dlls\bars.mdx) }
dialog mp3color {
  title "MP3 Color"
  icon $mp3.icons(mp3.ico), 0
  size -1 -1 157 131
  option dbu
  list 1, 7 14 18 100, size
  list 2, 30 14 18 100, size
  list 3, 53 14 18 100, size
  box "R", 6, 5 6 22 110
  box "G", 7, 28 6 22 110
  box "B", 8, 51 6 22 110
  button "Save colors", 9, 2 119 152 11
  list 4, 84 14 18 100, size
  list 5, 107 14 18 100, size
  list 10, 130 14 18 100, size
  box "R", 11, 82 6 22 110
  box "G", 12, 105 6 22 110
  box "B", 13, 128 6 22 110
  box "Text", 14, 2 0 74 118
  box "Background", 15, 80 0 74 118
}
on *:DIALOG:mp3color:init:0: {
  dll $mdx SetMircVersion $version
  dll $mdx MarkDialog mp3color
  dll $mdx SetControlMDX mp3color 1,2,3,4,5,10 Trackbar vertical noticks > $bars
  dll $mdx SetBorderStyle mp3color 1,2,3,4,5,10
  did -i mp3color 1 1 params $gettok($mp3ini(color,text),1,44) 0 255
  did -i mp3color 2 1 params $gettok($mp3ini(color,text),2,44) 0 255
  did -i mp3color 3 1 params $gettok($mp3ini(color,text),3,44) 0 255
  did -i mp3color 4 1 params $gettok($mp3ini(color,background),1,44) 0 255
  did -i mp3color 3 5 params $gettok($mp3ini(color,background),2,44) 0 255
  did -i mp3color 3 10 params $gettok($mp3ini(color,background),3,44) 0 255
}
on *:DIALOG:mp3color:SCLICK:*: {
  dll $mdx SetMircVersion $version
  dll $mdx MarkDialog mp3
  var %rgb = $rgb($gettok($did(mp3color,1,1).text,1,32),$gettok($did(mp3color,2,1).text,1,32),$gettok($did(mp3color,3,1).text,1,32))
  var %rgb2 = $rgb($gettok($did(mp3color,4,1).text,1,32),$gettok($did(mp3color,5,1).text,1,32),$gettok($did(mp3color,10,1).text,1,32)) 
  if ($did == 1 || $did == 2 || $did == 3) { dll $mdx SetColor mp3 1,8,4,5,6,7 text %rgb }
  elseif ($did == 4 || $did == 5 || $did == 10)  {
    xdid -C mp3 8,1,4 +bk %rgb2
    dll $mdx SetColor mp3 6,7,5 textbg %rgb2
    dll $mdx SetColor mp3 6,7,5 background %rgb2
  }
  if ($did == 9) {
    mp3ini color text $+($gettok($did(mp3color,1,1).text,1,32),$chr(44),$gettok($did(mp3color,2,1).text,1,32),$chr(44),$gettok($did(mp3color,3,1).text,1,32))
    mp3ini color background $+($gettok($did(mp3color,4,1).text,1,32),$chr(44),$gettok($did(mp3color,5,1).text,1,32),$chr(44),$gettok($did(mp3color,10,1).text,1,32))   
    dialog -x mp3color mp3color 
  }
}
dialog mp3ascii {
  title "ASCII Table"
  icon $mp3.icons(ascii.ico), 0
  size -1 -1 101 127
  option dbu
  list 1, 4 8 40 116, vsbar size
  box "Preview", 2, 49 0 50 50
  button "Clipboard", 3, 49 53 50 12
  button "Extended table", 4, 49 66 50 12
  box "ASCII Table", 5, 2 0 45 126
  button "OK", 6, 49 114 50 12
  text "...", 7, 51 8 45 40, center
}
on *:DIALOG:mp3ascii:init:0: {
  dll $mdx SetMircVersion $version
  dll $mdx MarkDialog mp3ascii
  dll $mdx SetFont mp3ascii 2,5 13 700 Tahoma
  dll $mdx SetFont mp3ascii 7 72 300 Tahoma
  var %x = 4
  while (%x <= 255) {
    if ($istok(10|11|12|14|29|30|31|32|33|161,%x,124)) { goto ascii }
    did -a mp3ascii 1 $chr(%x)
    :ascii
    inc %x
  }
  did -d mp3ascii 1 6
  did -d mp3ascii 1 6
  did -d mp3ascii 1 19
  did -b mp3ascii 3
}
on *:DIALOG:mp3ascii:SCLICK:*: {
  if ($did == 1) { did -ra mp3ascii 7 $did(mp3ascii,1).seltext | did -e mp3ascii 3 }
  if ($did == 3) { clipboard $did(mp3ascii,1).seltext }
  if ($did == 4) { run charmap }
  if ($did == 6) { dialog -x mp3ascii mp3ascii }
}
alias -l views { return $shortfn(dlls\views.mdx) }
alias -l scrolltext { 
  if (!$timer(scroll)) { .timerscroll -m 0 $1 scrolltext $1 $2 $3 }
  did -ra $2 $3 $+($right($did($2,$3).text,-1),$left($did($2,$3).text,1))
  did -ra mp3 7 $+($sound($insong.fname).bitrate,kbps,$str($chr(160),5),$sound($insong.fname).mode,$str($chr(160),5),$calc($sound($insong.fname).sample / 1000) kHz) 
  var %poss = $iif($int($calc(($insong.pos /1000)/60)) > 10,$int($calc(($insong.pos /1000)/60)), 0 $+ $int($calc(($insong.pos /1000)/60)) ) $+ : $+ $iif($round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0) > 10, $round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0), 0 $+ $round($calc(($insong.pos /1000) - $int($calc(($insong.pos /1000)/60))*60),0))
  did -a mp3 5 $replace(%poss,010,10)
}
dialog ID3 {
  title "ID3 Tag Editor"
  icon $mp3.icons(options.ico), 0
  size -1 -1 180 121
  option dbu
  edit "", 1, 26 64 152 10, read autohs
  edit "", 3, 26 95 95 11, autohs
  combo 8, 123 95 55 60, size drop
  button "Update", 5, 2 110 176 10
  button "", 7, 0 0 0 0, hide ok
  combo 4, 26 81 152 100, size drop
  list 2, 2 2 176 60, vsbar size
  text "Editing:", 6, 4 65 20 8
  box "", 9, -4 76 187 1
  text "Select:", 10, 4 82 20 8
  text "Value:", 11, 4 96 20 8
  box "", 12, -2 107 187 1
}
on *:dialog:ID3:*:*:{
  if ($devent == init) {
    if ($isfile($qt(MP3Player\list.txt))) { 
      window -h @mplist
      loadbuf @mplist $qt(MP3Player\list.txt) 
      var %x = 1
      while (%x <= $line(@mplist,0)) {
        did -a id3 2 $left($nopath($line(@mplist,%x)),-4)
        inc %x
      }
    }
    window -c @mplist
    dll $mdx SetMircVersion $version
    dll $mdx MarkDialog $dname
    dll $mdx SetColor id3 2 text $rgb($gettok($mp3ini(color,text),1,44),$gettok($mp3ini(color,text),2,44),$gettok($mp3ini(color,text),3,44))
    dll $mdx SetColor id3 2 background $rgb(0,0,0)
    dll $mdx SetColor id3 2 textbg $rgb(0,0,0)
    dll $mdx SetFont id3 2 13 700 Tahoma
    did -b $dname 3,4,8,5
    did -a $dname 1 No file selected.
    genre
    didtok -a $dname 4 32 Title Artist Album Year Comment Genre
  }
  if ($devent == sclick) {
    if ($did == 2) {
      if ($did(id3,2).sel == $mp3ini(main,songnum)) {
        noop $input(You cannot change the attributes of a file in use.,uwo,Error!)
        halt
      }
      did -ra id3 1 $read($qt(MP3Player\list.txt),$did(id3,2).sel)
      did -e $dname 3,4,8,5
    }
    if ($did == 4) {
      did -f $dname 3
      dialog -t $dname $+(ID3 Tag Editor:,$chr(32),$did(4).seltext)
      did -ra $dname 3 $PR0P($did(1),$did(4).sel)
      if $did(4).sel == 6 { did -c $dname 8 $didwm(8,$did(3)) }
    }
    if ($did == 5 && $did(4).sel) {
      var %file = $shortfn($did(ID3,1))
      $EDIT(%file,$did(4).sel)
    }
    if ($did(4).sel == 6) { did -e $dname 8 | did -m $dname 3 }
    else { did -b $dname 8 | did -n $dname 3 }
    if ($did == 8 && $did(4).sel == 6) { did -ra $dname 3 $did(8).seltext  }
  }
}
alias -l PR0P {
  if $2 == 1 return $mp3($1).title
  elseif $2 == 2 return $mp3($1).artist
  elseif $2 == 3 return $mp3($1).album
  elseif $2 == 4 return $mp3($1).year
  elseif $2 == 5 return $mp3($1).comment
  elseif $2 == 6 return $mp3($1).genre
}
alias -l EDIT {
  bread $1 $B_CALC($1,128) 3 &tag
  if ($bvar(&tag,1-3).text != TAG) {
    bwrite $1 $B_CALC($1,128) 3 TAG
    bset &fill 125 0
    bwrite $1 $B_CALC($1,125) 124 &fill
    bunset &fill
  }
  if ($mp3($1).version == MPEG 1.0 Layer 3) {
    if ($did(ID3,3)) {
      bset &val $N_BYTE($2) $iif($2 == 6,$calc($did(ID3,8).sel - 1),$did(ID3,3))
      bwrite $1 $S_BYTE($1,$2) $N_BYTE($2) &val
      $iif($2 < 6,.bwrite $1 $S_BYTE($1,$2) $N_BYTE($2) $did(ID3,3))
    }
    else {
      bset &val 30 $asc($chr(32))
      bwrite $1 $S_BYTE($1,$2) $N_BYTE($2) &val
    }
    bunset &val
    dialog -t $dname $+(ID3 Tag Editor:,$chr(32),Updated!)
  }
}
alias -l B_CALC { return $calc($file($1).size - $2) }
alias -l N_BYTE { return $gettok(30 30 30 4 30 1,$1,32) }
alias -l S_BYTE { return $calc($file($1).size - $gettok(125 95 65 35 31 1,$2,32)) }
alias -l genre {
  didtok ID3 8 44 Blues,Classic Rock,Country,Dance,Disco,Funk,Grunge,Hip-Hop,Jazz,Metal,New Age,Oldies,Other,Pop,R&B,Rap,Reggae,Rock,Techno,Industrial,Alternative,Ska,Death Metal,Pranks,SoundTrack,Euro-Techno,Ambient,Trip-Hop,Vocal,Jazz+Funk,Fusion,Trance,Classical,Instrumental,Acid,House,Game,Sound Clip,Gospel,Noise,Alternative Rock $&
    ,Bass,Soul,Punk,Space,Meditative,Instrumental Pop,Instrumental Rock,Ethnic,Gothic,Darkwave,Techno-Industrial,Electronic,Pop-Folk,Euro Dance,Dream,Southern Rock,Comedy,Cult,Gangsta Rap,Top 40,Christian Rap,Pop/Funk,Jungle,Native American,Cabaret,New Wave,Psychedelic,Rave,Showtunes,Trailer,Lo-Fi,Tribal,Acid Punk,Acid Jazz,Polka,Retro,Musical,Rock n' Roll
  didtok ID3 8 44 Hard Rock,Folk,Folk-Rock,National Folk,Swing,Fast Fusion,Bebop,Latin,Revival,Celtic,Bluegrass,Avantgarde,Gothic Rock,Progressive Rock,Psychedelic Rock,Symphonic Rock,Slow Rock,Big Band,Chorus,Easy Listening,Acoustic,Humour,Speech,Chanson,Opera,Chamber Music,Sonata,Symphony,Booty Bass,Primus,Porn Groove,Satire,Slow Jam,Club,Tango $&
    ,Samba,Folklore,Ballad,Power Ballad,Rhythmic Soul,Freestyle,Duet,Punk Rock,Drum Solo,Acapella,Euro-House,Dance Hall, 
}
alias -l shoutcheck {
  if ($mp3ini(shoutbox,status) == on) {
    var %x = $calc($ctime - $ctime($mp3ini(shoutbox,lastdate)))
    if ($calc(%x / 60) >= 5) { shout }
  } 
}
alias -l shout {
  mp3ini shoutbox lastdate $date $time
  sockopen shout www.dark-purple.comuv.com 80
  sockmark shout $+($date,|,$time,|,$mnick,|,$iif($sound($insong.fname).artist,$v1 -) $iif($sound($insong.fname).title,$v1,$left($nopath($insong.fname),-4)),|,$server,|,$network,|)
}
on *:sockopen:shout: {
  sockwrite -n $sockname POST /shoutbox/shout.php HTTP/1.0
  sockwrite -n $sockname Host: www.dark-purple.comuv.com
  sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
  sockwrite -n $sockname Content-Length: $calc($len($sock(shout).mark) + 15)[20:41:38]
  sockwrite -n $sockname $crlf
  sockwrite -n $sockname $+(info=,$sock(shout).mark,&submit=Go)
}
on *:sockread:shout: { sockread %shout }
alias -l shoutcount {
  if (!$mp3ini(shoutbox,added)) { halt }
  sockopen shoutcount www.dark-purple.comuv.com 80
  sockmark shoutcount 1
}
on *:sockopen:shoutcount: {
  sockwrite -n $sockname POST /shoutbox/count.php HTTP/1.0
  sockwrite -n $sockname Host: www.dark-purple.comuv.com
  sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
  sockwrite -n $sockname Content-Length: $calc($len($sock(shout).mark) + 15)[20:41:38]
  sockwrite -n $sockname $crlf
  sockwrite -n $sockname $+(info=,$sock(shout).mark,&submit=Go)
}
alias -l scount {
  sockclose scount
  sockopen scount www.dark-purple.comuv.com 80
}
on *:SOCKOPEN:scount: {
  sockwrite -n $sockname GET /shoutbox/count.php HTTP/1.0
  sockwrite -n $sockname Host: www.dark-purple.comuv.com $crlf $+ $crlf $+
}
on *:SOCKREAD:scount: {
  sockread %scount
  if (%scount isnum) { did -a shoutbox 4 %scount people have used this script. }
}
dialog shoutbox {
  title "Shoutbox"
  icon $mp3.icons(mp3.ico), 0
  size -1 -1 305 177
  option dbu
  list 1, 2 2 300 100, size
  button "Talk to this person!", 2, 202 164 50 12
  button "OK", 3, 253 164 50 12
  text "", 4, 2 166 155 8
  list 5, 2 103 300 60, size
}
on *:DIALOG:shoutbox:SCLICK:*: {
  if ($did == 2) { server -m $gettok($did(shoutbox,1,1).seltext,-1,32) }
  if ($did == 3) { dialog -x shoutbox shoutbox }
}
on *:DIALOG:shoutbox:INIT:0: {
  dll $mdx SetMircVersion $version
  dll $mdx MarkDialog shoutbox
  dll $mdx SetControlMDX shoutbox 1,5 listview center report grid nosortheader rowselect showsel > $views
  did -i shoutbox 1 1 headerdims 70 70 100 239 117
  did -i shoutbox 1 1 headertext Date $chr(9) Time $chr(9) Nickname $chr(9) Song $chr(9) Server
  did -i shoutbox 5 1 headerdims 450 146
  did -i shoutbox 5 1 headertext Network $chr(9) Listeners
  sockclose sbox
  sockopen sbox www.dark-purple.comuv.com 80
  scount
}
on *:SOCKOPEN:sbox: {
  sockwrite -n $sockname GET /shoutbox/shout.php HTTP/1.0
  sockwrite -n $sockname Host: www.dark-purple.comuv.com $crlf $+ $crlf $+
}
on *:SOCKREAD:sbox: {
  sockread %sbox
  if (<br /><br /> isin %sbox) { sockread %sbox }
  if (<br /> isin %sbox) { 
    did -a shoutbox 1 $gettok($htmlfree(%sbox),1,124) $chr(9) $gettok($htmlfree(%sbox),2,124) $chr(9) $gettok($htmlfree(%sbox),3,124) $chr(9) $gettok($htmlfree(%sbox),4,124) $chr(9) $gettok($htmlfree(%sbox),5,124) 
    write -a $qt(MP3Player\temp.txt) $+($gettok($htmlfree(%sbox),3,124),•,$gettok($htmlfree(%sbox),6,124))
  }
}
alias -l incini {
  echo -s $qt($1) $2 $3 $iif($readini($qt($1),$2,$3) > 0,$calc($readini($qt($1),$2,$3) + 1),1)
  writeini $qt($1) $2 $3 $iif($readini($qt($1),$2,$3) > 0,$calc($readini($qt($1),$2,$3) + 1),1) 
}
on *:SOCKCLOSE:sbox: {
  remini $qt(MP3Player\config.ini) temp
  var %d = 1
  while (%d <= $calc($lines($qt(MP3Player\temp.txt)) - 1)) {
    if !($mp3ini(temp,$gettok($read($qt(MP3Player\temp.txt),%d),1,149)) == 1) {
      incini $qt(MP3Player\temp.ini) names $gettok($read($qt(MP3Player\temp.txt),%d),2,149)
      mp3ini temp $gettok($read($qt(MP3Player\temp.txt),%d),1,149) 1
    }
    inc %d
  }
  write -c $qt(MP3Player\temp.txt)
  var %w = 1
  while (%w <= $ini($qt(MP3Player\temp.ini),names,0)) {
    var -s %o = $ini($qt(MP3Player\temp.ini),names,%w)
    did -a shoutbox 5 %o $chr(9) $readini($qt(MP3Player\temp.ini),names,%o)
    inc %w
  }
  .remove $qt(MP3Player\temp.ini)
}
alias -l htmlfree { 
  var %b,%p 
  %p = $regsub($1-,/[^<]*>|<[^>]*>|<[^>]*/g,$chr(32),%b)
  %b = $remove(%b, ) 
  return %b
}
dialog lyrics {
  title "Lyrics Finder"
  icon $mp3.icons(favs.ico), 0
  size -1 -1 368 236
  option dbu
  edit "", 1, 263 28 100 10, autohs center
  edit "", 2, 263 8 100 10, autohs center
  button "Go", 3, 263 58 100 10
  edit "", 4, 2 2 255 233, read multi vsbar center
  box "Song", 5, 260 0 106 20
  box "Artist", 6, 260 20 106 20
  box "", 7, 256 70 114 1
  list 8, 262 84 100 115, hsbar vsbar size
  text "Last 50 successful searches:", 9, 263 75 71 8
  box "", 10, 256 201 114 1
  check "Auto-input for playing song", 11, 272 208 100 8
  box "", 12, 256 219 114 1
  combo 13, 262 223 100 40, drop
  combo 14, 263 44 100 35, drop center sort
}
on *:dialog:lyrics:edit:*: {
  if ($did(lyrics,1).text) && ($did(lyrics,2).text) { did -e lyrics 3 }
  else { did -b lyrics 3 }
}
on *:dialog:lyrics:init:0: {
  dll $mdx SetMircVersion $version
  dll $mdx MarkDialog lyrics
  dll $mdx SetColor lyrics 4 textbg $rgb(0,0,0)
  dll $mdx SetColor lyrics 4 background $rgb(0,0,0)
  dll $mdx SetColor lyrics 4 text $iif($mp3ini(color,text),$rgb($gettok($v1,1,44),$gettok($v1,2,44),$gettok($v1,3,44)),$rgb(255,255,255))
  dll $mdx SetFont lyrics 5,6 13 700 Tahoma
  did -b lyrics 3
  did -f lyrics 2
  didtok lyrics 13 124 Save lyrics|Load lyrics
  did -c lyrics 13 1
  didtok lyrics 14 124 azlyrics.com|plyrics.com|urbanlyrics.com|oldielyrics.com|lyricsbay.com|alivelyrics.com
  did -c lyrics 14 1
  if ($isfile($qt(lyrics\hist.txt))) { 
    loadbuf -o lyrics 8 $qt(lyrics\hist.txt)
    did -z lyrics 8  
  }
  if ($readini($qt(lyrics\config.ini),config,auto) == 1) { did -c lyrics 11 }
  if ($readini($qt(lyrics\config.ini),config,auto) == 1) && ($insong.fname) {
    if ($sound($insong.fname).artist) { did -a lyrics 1 $sound($insong.fname).artist }
    if ($sound($insong.fname).title) { did -a lyrics 2 $sound($insong.fname).title }
  }
  if ($did(lyrics,2).text) && ($did(lyrics,1).text) { did -e lyrics 3 }
}
alias -l nospace { return $remove($1-,$chr(32)) }
alias -l nospace2 { return $replace($1-,$chr(32),_) }
on *:dialog:lyrics:sclick:11: {
  if (!$isdir($qt(lyrics\))) { mkdir $qt(lyrics\) }
  if ($did(lyrics,11).state == 1) { writeini $qt(lyrics\config.ini) config auto 1 }
  elseif ($did(lyrics,11).state == 0) { remini $qt(lyrics\config.ini) config auto }
}
on *:dialog:lyrics:sclick:13: {
  if (!$isdir($qt(lyrics\lyrics\))) { mkdir $qt(lyrics\lyrics\) }
  if ($did(lyrics,13).sel == 1) {
    if ($did(lyrics,4).lines > 1) {
      var %sf = $?=\"What do you want to call the file?"
      savebuf -o lyrics 4 $qt(lyrics\lyrics\ $+ %sf $+ .txt)
      dialog -t lyrics Lyrics Finder - saved!
      .timer 1 2 dialog -t lyrics Lyrics Finder
    }
    elseif ($did(lyrics,4).lines == 1) { noop $input(There is nothing to save!,uwo,Error!) }
  }
  elseif ($did(lyrics,13).sel == 2) { 
    var %p = $sfile($qt(lyrics\lyrics\*.txt),Load lyrics)
    loadbuf -o lyrics 4  $qt(%p)
    did -z lyrics 8
  }
}
on *:dialog:lyrics:sclick:3: {
  did -r lyrics 4
  if ($did(lyrics,14).seltext == azlyrics.com) {
    if ($sock(lyrics)) { sockclose lyrics }
    sockopen lyrics www.azlyrics.com 80
  }
  elseif ($did(lyrics,14).seltext == oldielyrics.com) {
    if ($sock(nlyrics)) { sockclose nlyrics }
    sockopen nlyrics www.oldielyrics.com 80
  }
  elseif ($did(lyrics,14).seltext == plyrics.com) {
    if ($sock(plyrics)) { sockclose plyrics }
    sockopen plyrics www.plyrics.com 80 
  }
  elseif ($did(lyrics,14).seltext == urbanlyrics.com) {
    if ($sock(ulyrics)) { sockclose ulyrics }
    sockopen ulyrics www.urbanlyrics.com 80
  }
  elseif ($did(lyrics,14).seltext == lyricsbay.com) {
    if ($sock(mlyrics)) { sockclose mlyrics }
    sockopen mlyrics www.lyricsbay.com 80
  }
  elseif ($did(lyrics,14).seltext == alivelyrics.com) {
    if ($sock(alyrics)) { sockclose alyrics }
    sockopen alyrics www.alivelyrics.com 80
  }
  dialog -t lyrics Lyrics Finder - Searching...
}
on *:SOCKOPEN:lyrics: {
  var %lurl = $remove($lower($+(lyrics/,$remove($nospace($did(lyrics,1).text),/,.),/,$remove($nospace($did(lyrics,2).text),/,.),.html)),',$chr(44))
  sockwrite -n $sockname GET / $+ %lurl HTTP/1.0
  sockwrite -n $sockname Host: www.azlyrics.com $crlf $+ $crlf $+
}
on *:SOCKREAD:lyrics: {
  sockread %lyvar
  if ([ album lyrics ] isin %lyvar) {
    .signal nolyrics
    sockclose lyrics
  }
  elseif (<br> isin %lyvar) {
    did -a lyrics 4 $crlf $+ $htmlfree(%lyvar) 
    set %lsuc 1
  }
}
on *:SOCKCLOSE:lyrics: {
  if (%lsuc == 1) {
    clearlyrics
    addlyricshist
    dialog -t lyrics Lyrics Finder
    unset %lsuc
  }
}
alias -l clearlyrics {
  var %x = 1
  while (%x <= $did(lyrics,4).lines) {
    if (*READONLY>* iswm $did(lyrics,4,%x).text) { did -d lyrics 4 %x }
    if (*/font&* iswm $did(lyrics,4,%x).text) { did -d lyrics 4 %x }
    if (*lyricsbay.com* iswm $did(lyrics,4,%x).text) { did -d lyrics 4 %x }
    if (*</textarea>* iswm $did(lyrics,4,%x).text) { did -d lyrics 4 %x }
    if ([Thanks* iswm $did(lyrics,4,%x)) { did -d lyrics 4 %x }
    if ([Thanks* iswm $did(lyrics,4,%x)) { did -d lyrics 4 %x }     
    if (*azlyrics.com* iswm $did(lyrics,4,%x)) { did -d lyrics 4 %x }
    if (*album lyrics* iswm $did(lyrics,4,%x)) { did -d lyrics 4 %x }
    if (*LATEST SITE NEWS* iswm $did(lyrics,4,%x)) { did -d lyrics 4 %x }     
    if (*all lyrics are property and copyright* iswm $did(lyrics,4,%x)) { did -d lyrics 4 %x }
    if (*<textarea name=* iswm $did(lyrics,4,%x).text) { did -d lyrics 4 %x }
    inc %x
  }
  if ($did(lyrics,4,2).text === only.) { did -d lyrics 4 2 }
  if ($1 == n) {
    did -d lyrics 4 1
    did -d lyrics 4 1
    did -d lyrics 4 1
  }
}
alias lyrics { dialog $iif($dialog(lyrics),-v,-m) lyrics lyrics }
on *:SOCKOPEN:mlyrics: {
  var %murl = $remove($lower($+($nospace2($did(lyrics,2).text),_lyrics-,$nospace2($did(lyrics,1).text),.html)),')
  sockwrite -n $sockname GET / $+ %murl HTTP/1.0
  sockwrite -n $sockname Host: www.lyricsbay.com $crlf $+ $crlf $+
}
on *:SOCKREAD:mlyrics: {
  sockread %mlyrics
  if (<textarea name="songscpy isin %mlyrics) { 
    did -a lyrics 4 $htmlfree($replace(%mlyrics,<br />,$crlf,<br>,$crlf,f*ck,fuck)) 
    set %msuc 1
    dialog -t lyrics Lyrics Finder
  }
}
on *:SOCKCLOSE:mlyrics: {
  did -d lyrics 4 1
  did -d lyrics 4 1
  did -d lyrics 4 $did(lyrics,4).lines
  did -d lyrics 4 $did(lyrics,4).lines
  did -d lyrics 4 $did(lyrics,4).lines
  did -i lyrics 4 1 $crlf
  if (%msuc == 1) { addlyricshist }
  elseif (!%msuc) { .signal nolyrics }
  unset %msuc
}
on *:SOCKOPEN:plyrics: {
  var %purl = $remove($lower($+(lyrics/,$remove($nospace($did(lyrics,1).text),/,.),/,$remove($nospace($did(lyrics,2).text),/,.),.html)),',$chr(44))
  sockwrite -n $sockname GET / $+ %purl HTTP/1.0
  sockwrite -n $sockname Host: www.plyrics.com $crlf $+ $crlf $+
}
on *:SOCKREAD:plyrics: {
  sockread %plyrics
  if (Please check the spelling isin %plyrics) {
    .signal nolyrics 
    sockclose plyrics
  } 
  elseif (<br> isin %plyrics) {
    set %q 1  
    did -a lyrics 4 $crlf $+ $htmlfree(%plyrics) 
  }
}
on *:SOCKCLOSE:plyrics: {
  if (%q == 1) {
    addlyricshist
    unset %q
    did -i lyrics 4 1 $crlf    
  }
}
on *:SIGNAL:nolyrics: {
  dialog -t lyrics Lyrics Finder
  noop $input(No results were found.,uwo,Error!)
  did -r lyrics 4
}
on *:SOCKOPEN:ulyrics: {
  var %uurl = $remove($lower($+(lyrics/,$remove($nospace($did(lyrics,1).text),/,.),/,$remove($nospace($did(lyrics,2).text),/,.),.html)),',$chr(44))
  sockwrite -n $sockname GET / $+ %uurl HTTP/1.0
  sockwrite -n $sockname Host: www.urbanlyrics.com $crlf $+ $crlf $+
}
on *:SOCKREAD:ulyrics: {
  sockread %ulyrics
  if (<h2>404 error isin %ulyrics) {
    .signal nolyrics 
    sockclose ulyrics
  }
  elseif (<br> isin %ulyrics) {
    set %usuc 1
    if (*Ringtone to your Cell* iswm %ulyrics) { goto u }
    did -a lyrics 4 $crlf $+ $htmlfree(%ulyrics) 
  }
  :u
}
on *:SOCKCLOSE:ulyrics: { 
  if (%usuc == 1) { addlyricshist | unset %usuc }
}
alias -l addlyricshist {
  if (!$isdir($qt(lyrics\))) { mkdir $qt(lyrics\) }
  var %x = 1
  while (%x <= $lines($qt(lyrics\hist.txt))) {
    if ($read($qt(lyrics\hist.txt),%x) == $did(lyrics,2).text - $did(lyrics,1).text) { set %ly 1 }
    inc %x
  }
  if (%ly == 1) { unset %ly | halt }
  if ($lines($qt(lyrics\hist.txt)) == 100) { write -dl1 $qt(lyrics\hist.txt) }
  write -a $qt(lyrics\hist.txt) $did(lyrics,2).text - $did(lyrics,1).text
  did -r lyrics 8
  loadbuf -o lyrics 8 $qt(lyrics\hist.txt)
  did -z lyrics 8
}
on *:SOCKCLOSE:mlyrics: {
  did -d lyrics 4 1
  did -d lyrics 4 1
  did -d lyrics 4 1
  did -d lyrics 4 $did(lyrics,4).lines
  did -d lyrics 4 $did(lyrics,4).lines
  did -d lyrics 4 $did(lyrics,4).lines
  did -i lyrics 4 1 $crlf
}
on *:SOCKOPEN:nlyrics: {
  var %nurl = $remove($lower($+(lyrics/,$remove($nospace2($did(lyrics,1).text),/,.),/,$remove($nospace2($did(lyrics,2).text),/,.),.html)),',$chr(40),$chr(41))
  sockwrite -n $sockname GET / $+ %nurl HTTP/1.0
  sockwrite -n $sockname Host: www.oldielyrics.com $crlf $+ $crlf $+
}
on *:SOCKREAD:nlyrics: {
  sockread %nlyvar
  if (Browse Oldies Lyrics isin %nlyvar) {
    .signal nolyrics 
    sockclose nlyrics
  }
  elseif (<br> isin %nlyvar) {
    did -a lyrics 4 $crlf $+ $htmlfree(%nlyvar)
    set %nsuc 1   
  }
}
on *:SOCKCLOSE:nlyrics: {
  if (%nsuc == 1) {
    addlyricshist
    dialog -t lyrics Lyrics Finder
    unset %nsuc
  }
}
on *:SOCKOPEN:alyrics: {
  var %aurl = $remove($lower($+($left($remove($nospace($did(lyrics,1).text),/,.),1),/,$remove($nospace($did(lyrics,1).text),/,.),/,$remove($nospace($did(lyrics,2).text),/,.),.html)),',$chr(44))
  sockwrite -n $sockname GET / $+ %aurl HTTP/1.0
  sockwrite -n $sockname Host: www.alivelyrics.com $crlf $+ $crlf $+
}
on *:SOCKREAD:alyrics: {
  sockread %alyrics
  if (Featured albums: isin %alyrics) {
    .signal nolyrics 
    sockclose alyrics
  }
  if (<pre class="lyrics"> isin %alyrics) { set %ayes 1 }
  if (</pre> isin %alyrics) { unset %ayes }
  if ($chr(60) !isin %alyrics) { 
    if (%ayes == 1) { did -a lyrics 4 $crlf $+ %alyrics } 
    set %asuc 1
  }
}
on *:SOCKCLOSE:alyrics: { if (%asuc == 1) { addlyricshist | unset %asuc } }
on *:DIALOG:lyrics:close:0: { unset %*lyrics* }
alias -l dcx {
  if ($isid) returnex $dll($qt(dlls\dcx.dll),$1,$2-)
  else dll $qt(dlls\dcx.dll) $1 $2-
}
alias -l xpop {
  if ( $isid ) returnex $dcx( _xpop, $1 $prop $2- )
  dcx xpop $2 $1 $3-
}
alias -l udcx {
  if ($dcx(IsUnloadSafe)) $iif($menu, .timer 1 0) dll -u dcx.dll
  else echo 4 -qmlbfti2 [DCX] Unable to Unload Dll.
}
alias -l xdid {
  if ( $isid ) returnex $dcx( _xdid, $1 $2 $prop $3- )
  dcx xdid $2 $3 $1 $4-
}
alias -l xdialog {
  if ( $isid ) returnex $dcx( _xdialog, $1 $prop $2- )
  dcx xdialog $2 $1 $3-
}
alias -l xpopup {
  if ( $isid ) returnex $dcx( _xpopup, $1 $prop $2- )
  dcx xpopup $2 $1 $3-
}
alias -l mpopup { dcx mpopup $1 $2 }
dialog mp3chat {
  title "MP3 Chatroom"
  size -1 -1 297 237
  option dbu
}
alias cb_chat { return }
on *:DIALOG:mp3chat:init:0: {
  dcx Mark mp3chat cb_chat
  xdialog -c mp3chat 1 webctrl 4 4 587 467
  xdid -n mp3chat 1 http://www.freeshoutbox.net/MP3Player&delete=1&start=0&PHPSESSID=u0rjtk1t8kdlgnodgj1hg414s6
}
