All pastes #147856 Raw Edit

Anonymous

public text v1 · immutable
#147856 ·published 2006-08-24 18:23 UTC
rendered paste body
menu channel {
  m|ndless' mp3 Player:{
    if ($dialog(mmp3)) { dialog -ve mmp3 mmp3 }
    else { dialog -md mmp3 mmp3 }
  }
}

; DIALOG

dialog mmp3 {
  title "m|ndless' mp3 Player"
  option dbu
  size -1 -1 200 200

  box "",230, 1 1 198 33

  text "No Music Playing", 1, 4 7 154 7
  text "00:00 / 00:00",2,160 7 37 7

  button "<<",100,4 20 37 12
  button "&Play",101,42 20 38 12
  button "Paus&e",102,81 20 38 12
  button "&Stop",103,120 20 38 12
  button ">>",104,159 20 38 12

  box "",231, 1 30 198 169

  list 3, 3 36 194 154, hsbar, vsbar, sort
  button "+ File",105, 4 186 18 10
  button "+ Dir",106, 24 186 18 10
  button "- Sel",107, 158 186 18 10
  button "- All",108, 178 186 18 10

  menu "&File",150
  menu "&Options", 170

  item "Add &File",151,150
  item "Add &Dir",152,150
  item break,153,150
  item "Delete &Selected",154,150
  item "Delete &All",155,150
  item break,156,150
  item "&Load Playlist",157,150,
  item "Save &Playlist",158,150
  item break,159,150
  item "E&xit",160,150

  menu "Play &Mode",183,170
  item "&Single",184,183
  item "&Continuous",185,183

  menu "Play &Order",171,170
  item "&Normal",172,171
  item "&Shuffle",173,171

  item break,177,170

  menu "&Announcing",178,170
  item "O&n",179,178
  item "O&ff",180,178
  item break,181,178
  item "&Configure",182,178

  button "", 255,0 0 0 0, ok default
}

; EVENTS

;dialog init
on *:dialog:mmp3:init:0:startup

; +File button
on *:dialog:mmp3:sclick:105:plusfile

; +Dir button
on *:dialog:mmp3:sclick:106:plusdir

; -Sel button
on *:dialog:mmp3:sclick:107:minsel

; -All button
on *:dialog:mmp3:sclick:108:minall

; Play button
on *:dialog:mmp3:sclick:101:playmp3

; Pause button
on *:dialog:mmp3:sclick:102:pausemp3

; Stop button
on *:dialog:mmp3:sclick:103:stopmp3

; Next button
on *:dialog:mmp3:sclick:104:playnext

; Previous button
on *:dialog:mmp3:sclick:100:playprev

; double click mp3
on *:dialog:mmp3:dclick:3:playmp3

; menu add file
on *:dialog:mmp3:menu:151:plusfile

; menu add dir
on *:dialog:mmp3:menu:152:plusdir

; menu del sel
on *:dialog:mmp3:menu:154:minsel

; menu del all
on *:dialog:mmp3:menu:155:minall

; menu load playlist
on *:dialog:mmp3:menu:157:loadplaylist

; menu save playlist
on *:dialog:mmp3:menu:158:saveplaylist

; menu exit
on *:dialog:mmp3:menu:160:dialog -x mmp3

; halt enter
on *:dialog:mmp3:sclick:255:halt

; menu play mode single
on *:dialog:mmp3:menu:184:modesingle

; menu play mode continuous
on *:dialog:mmp3:menu:185:modecontin

; menu play order normal
on *:dialog:mmp3:menu:172:ordernormal

; menu play order shuffle
on *:dialog:mmp3:menu:173:ordershuffle

; menu announce on
on *:dialog:mmp3:menu:179:announceon

; menu announce off
on *:dialog:mmp3:menu:180:announceoff

; configure announce
on *:dialog:mmp3:menu:182:$dialog(mannounce,mannounce)

; on exit : cleanup
on *:exit:cleanup

; on load
on *:load:.unset %mmp3-* | echo -a mp3 player loaded.

; ALIASES

alias -l mp3list return sounds\mp3list.mrc
alias -l mp3src return sounds\mp3src.mrc
alias -l mp3player { if ($dialog(mmp3)) return $true }
alias -l history return sounds\history.tmp

alias -l cleanup {
  unset %mmp3-paused
  .remove $history
}

alias -l announceoff {
  if (%mmp3-announce) { unset %mmp3-announce | did -u mmp3 179 }
  did -c mmp3 180
}

alias -l announceon {
  if (!%mmp3-announce) { set %mmp3-announce true | did -u mmp3 180 }
  did -c mmp3 179
}

alias -l ordernormal {
  if (%mmp3-shuffle) { unset %mmp3-shuffle | did -u mmp3 173 }
  did -c mmp3 172
}

alias -l ordershuffle {
  if (!%mmp3-shuffle) { set %mmp3-shuffle true | did -u mmp3 172 }
  did -c mmp3 173
}

alias -l modesingle {
  if (%mmp3-contin) { unset %mmp3-contin | did -u mmp3 185 }
  did -c mmp3 184
}

alias -l modecontin {
  if (!%mmp3-contin) { set %mmp3-contin true | did -u mmp3 184 }
  did -c mmp3 185
}


alias -l startup {
  if (%mmp3-paused) { unset %mmp3-paused }
  if (%mmp3-shuffle) { did -c mmp3 173 }
  else { did -c mmp3 172 }
  if (%mmp3-announce) { did -c mmp3 179 }
  else { did -c mmp3 180 }
  if (%mmp3-contin) { did -c mmp3 185 }
  else { did -c mmp3 184 }
  .timer -m 1 1 addmp3
}

alias -l saveplaylist {
  :begin
  var %file = $sfile(*.mpl,Save Playlist ...,Ok)
  if (%file) {
    if ($right(%file,4) !== .mpl) {
      var %tmp = $input(Wrong file extension selected! Playlists should have extension .mpl !,260,Error)
      goto begin
    }
    if ($len($nopath(%file)) == 4) {
      var %tmp = $input(Corrupt filename selected! Playlists should have extension .mpl AND have a filename!,260,Error)
      goto begin
    }
    :continue
    .copy -o $mp3list %file
    .copy -o $mp3src $left(%file,$calc($len(%file) - 4)) $+ .src
  }
}

alias -l loadplaylist {
  :begin
  var %file = $sfile(*.mpl,Select Playlist to load...,Ok)
  if ($isfile(%file)) {
    minall
    .copy -o %file $mp3list
    .copy -o $left(%file,$calc($len(%file) - 4)) $+ .src $mp3src
    addmp3
  }
}

alias -l minsel {
  var %tmp = $read($mp3list, swt, $did(mmp3,3).sel)
  write -dl $+ $readn $mp3src
  write -dl $+ $readn $mp3list
  did -d mmp3 3 $did(mmp3,3).sel
}

alias -l minall {
  .remove $mp3list
  .remove $mp3src
  did -r mmp3 3
}

alias -l plusfile {
  var %file = $sfile(*.mp3,Select mp3 to add,Ok)
  if (%file) {
    addlist %file 
    addmp3 %file 
  }
}
alias -l plusdir {
  unset %mp3dir
  set %mp3dir $sdir(Select directory, Ok)
  echo -a dir: %mp3dir
  if (%mp3dir) { set %i 1 | set %total $findfile(%mp3dir,*.mp3,0) | echo -a Adding %total mp3's to list, this could take a while ... | .timermp3list 0 0 makelist }
}
alias makelist {
  if (%i <= %total) {
    var %file = $findfile(%mp3dir,*.mp3,%i)
    if (!$read($mp3src,w,%file)) {
      write $mp3src %file
      write $mp3list $getinfo(%file)
    }
    inc %i
  }
  else { .timermp3list off | echo -a Finished adding %total mp3's to list | unset %i | unset %total | unset %mp3dir | addmp3 }
}
alias -l addmp3 {
  var %count = $lines($mp3list)
  if ($1) {
    did -a mmp3 3 $read($mp3list,%count)
  }
  else {
    did -r mmp3 3
    var %i = 1
    while (%i <= %count) {
      did -a mmp3 3 $read($mp3list,%i)
      inc %i
    }
  }
  did -z mmp3 3
}
alias -l addlist {
  var %file = $1-
  if (!$read($mp3src,w,%file)) {
    write $mp3src %file
    write $mp3list $getinfo(%file)
  }
}
alias -l getinfo {
  var %x = $1-
  var %artist = $mp3(%x).artist
  var %title = $mp3(%x).title
  if ((%artist == $null) || (%title == $null)) {
    return $left($nopath(%x),$calc($len($nopath(%x)) - 4))
  }
  else { return %artist - %title }
}

alias -l playmp3 {
  if ($did(mmp3,3).sel) {
    did -a mmp3 1 $did(mmp3,3).seltext
    dialog -t mmp3 $did(mmp3,3).seltext
    .timersetinfo 0 1 setinfo
    if (%mmp3-paused) {
      unset %mmp3-paused
      splay resume
    }
    else {
      var %tmp = $read($mp3list,swt,$did(mmp3,3).seltext)
      var %src = $read($mp3src,$readn)
      .splay -p %src
      if (%mmp3-announce) { announce %src }
    }
  }
  else {
    var %tmp = $input(No File Selected!,260, Error)
    dialog -ve mmp3
  }
  write $history $did(mmp3,3).seltext
}

alias -l stopmp3 {
  splay stop
  did -a mmp3 2 00:00 / 00:00
  did -a mmp3 1 No Music Playing
  dialog -t mmp3 m|ndless' mp3 Player
  if (%mmp3-paused) { unset %mmp3-paused }
  .timersetinfo off
}

alias -l pausemp3 {
  if (%mmp3-paused) { unset %mmp3-paused | splay resume | .timersetinfo 0 1 setinfo }
  else { splay pause | set %mmp3-paused true | .timersetinfo off }
}

alias -l setinfo {
  if ($mp3player) {
    if ($inmp3) {
      var %long = $calc($int($calc($inmp3.pos / 1000)) / 60)
      var %mins = $int(%long)
      var %secs = $calc(%long - %mins)
      var %secs = $round($calc(%secs * 60),0)
      if (%mins < 10) { %mins = $+(0,%mins) }
      if (%secs < 10) { %secs = $+(0,%secs) }

      did -a mmp3 2 $+(%mins,:,%secs) / $getlength($inmp3.fname)
    }
    else {
      .timersetinfo off
      if (!%mmp3-contin) { stopmp3 }
      else {
        if (!%mmp3-shuffle) { playnext }
        else { shuffle }
        playmp3
      }
    }
  }
  else { splay stop | .timersetinfo off }
}

alias -l getlength {
  return $right($duration($calc($mp3($inmp3.fname).length / 1000),3),4)
}

alias -l playnext {
  if (%mmp3-shuffle) { shuffle }
  else {
    if ($did(mmp3,3).sel == $did(mmp3,3).lines) { did -c mmp3 3 1 }
    else { did -c mmp3 3 $calc($did(mmp3,3).sel + 1) }
    if ($inmp3) { unset %mmp3-paused | playmp3 }
  }
  if ($inmp3) { unset %mmp3-paused | playmp3 }
}

alias -l shuffle {
  if (%mmp3-paused) { unset %mmp3-paused }
  did -c mmp3 3 $rand(1,$did(mmp3,3).lines) 
}

alias -l playprev {
  var %tmp = $read($history,w, $did(mmp3,3).seltext)
  did -c mmp3 3 $didwm(mmp3,3,$read($history,$calc($readn - 1)))
  write -d $history
  if ($inmp3) { unset %mmp3-paused | playmp3 }
}

alias -l announce {
  if ($server) {
    if (!%mmp3-noid3) {
      echo -at No settings for m|ndless' mp3 Player found. Running single time initialisation.
      $dialog(mannounce,mannounce)
    }
    var %artist = $mp3($1-).artist
    var %title = $mp3($1-).title
    if ((%artist == $null) || (%title == $null)) {
      var %msg = $replace(%mmp3-noid3,&filename,$left($nopath($inmp3.fname),$calc($len($nopath($inmp3.fname)) - 4)))
    }
    else {
      var %msg = $replace(%mmp3-msg,&artist,%artist,&title,%title)
    }
    if (!%mmp3-sep) { set %mmp3-sep <> }
    if (%mmp3-saylen) { %msg = $+(%msg,$chr(160),%mmp3-sep $getlength($inmp3.fname)) }
    if (%mmp3-saybit) { %msg = $+(%msg,$chr(160),%mmp3-sep $mp3($inmp3.fname).bitrate,Kbs) }
    if (%mmp3-saysize) { %msg = $+(%msg,$chr(160),%mmp3-sep $bytes($file($inmp3.fname).size,m),Mb) }

    if (!%mmp3-ann) { set %mp3-ann all }
    if (%mmp3-ann == all) {
      var %chans = $chan(0)
      var %i = 1
      while (%i <= %chans) {
        var %t = $replace(%msg,&chan,$chan(%i))
        %t
        inc %i
      }
    }
    else {
      if (%mmp3-ann == dont) {
        var %chans = $chan(0)
        var %i = 1
        while (%i <= %chans) {
          if ( $matchtok(%mmp3-chans-dont,$chan(%i),1,$chr(44)) ) { }
          else {
            var %t = $replace(%msg,&chan,$chan(%i))
            %t
          }
          inc %i
        }
      }
      elseif (%mmp3-ann == only) {
        var %chans = $chan(0)
        var %i = 1
        while (%i <= %chans) {
          if ( $matchtok(%mmp3-chans-only,$chan(%i),1,$chr(44)) ) {
            var %t = $replace(%msg,&chan,$chan(%i))
            %t
          }
          inc %i
        }
      }
    }
  }
}

;=========================================================================================================

; MMP3 ANNOUNCE CONFIG DIALOG

; Dialog
dialog mannounce {
  size -1 -1 150 160
  title "m|ndless' mp3 Player announce config"
  option dbu

  box "Misc. Options",254, 2 2 146 30

  check "Say Track Length",1,5 11 60 7
  check "Say Track Bitrate",2,5 22 60 7
  check "Say Track Filesize",3,75 11 60 7
  text "Separator:",250,75 22 30 7
  edit "",70,104 19 25 11,limit 5

  box "Chan Options",253,2 35 146 41

  radio "Announce in all chans",10,5 44 68 7
  radio "Don't say in these chans:",11,5 55 69 7
  edit "#chan1,#chan2,...",20,75 52 70 11,autohs
  radio "Only say in these chans:",12,5 66 69 7
  edit "#chan1,#chan2,...",21,75 63 70 11,autohs

  box "Message",252,2 78 146 65
  edit "",50,5 85 140 11,autohs
  text "If song has no id3 tag : ",251,10 100 100 7
  edit "",51,10 108 135 11
  text "Important Note: Do not use /ame or /amsg in your msg, use /describe or /msg instead!!!",249,5 123 135 15

  button "Ok",200,60 146 30 12

  button "",255,0 0 0 0, ok default
}

; Events

on *:dialog:mannounce:init:0:{
  if (%mmp3-saylen) { did -c mannounce 1 }
  if (%mmp3-saybit) { did -c mannounce 2 }
  if (%mmp3-saysize) { did -c mannounce 3 }

  if (!%mmp3-sep) { set %mmp3-sep <> }
  did -a mannounce 70 %mmp3-sep

  if (!%mmp3-ann) { %mmp3-ann = all }
  if (%mmp3-ann == all) { did -c mannounce 10 | did -b mannounce 20,21 }
  if (%mmp3-ann == dont) { did -c mannounce 11 | did -b mannounce 21 }
  if (%mmp3-ann == only) { did -c mannounce 12 | did -b mannounce 20 }
  did -ra mannounce 20 %mmp3-chans-dont
  did -ra mannounce 21 %mmp3-chans-only

  if (!%mmp3-msg) { %mmp3-msg = /describe &chan is listening to &artist - &title }
  did -a mannounce 50 %mmp3-msg
  if (!%mmp3-noid3) { %mmp3-noid3 = /describe &chan is listening to &filename }
  did -a mannounce 51 %mmp3-noid3
}

; Ok button
on *:dialog:mannounce:sclick:200:{
  if ($did(mannounce,1).state == 1) { set %mmp3-saylen true }
  else { unset %mmp3-saylen }
  if ($did(mannounce,2).state == 1) { set %mmp3-saybit true }
  else { unset %mmp3-saybit }
  if ($did(mannounce,3).state == 1) { set %mmp3-saysize true }
  else { unset %mmp3-saysize }

  if ($did(mannounce,10).state == 1) { set %mmp3-ann all }
  if ($did(mannounce,11).state == 1) { set %mmp3-ann dont }
  if ($did(mannounce,12).state == 1) { set %mmp3-ann only }
  %mmp3-chans-dont = $did(mannounce,20).text
  %mmp3-chans-only = $did(mannounce,21).text 

  set %mmp3-msg $did(mannounce,50).text
  set %mmp3-noid3 $did(mannounce,51).text

  set %mmp3-sep $did(mannounce,70).text

  dialog -x mannounce
  dialog -v mmp3
}

; radio buttons
on *:dialog:mannounce:sclick:11:{ did -e mannounce 20 | did -b mannounce 21 }
on *:dialog:mannounce:sclick:12:{ did -e mannounce 21 | did -b mannounce 20 }
on *:dialog:mannounce:sclick:10:{ did -b mannounce 20,21 }