Mp3 Player (DCX)

By kibo on Aug 16, 2015

This is my mp3 player , it is written completely in DCX and use an hashtable for playlist either to go forward is to go back.
The main timer use a edit control with a trasparent for antifocus.

The comments are in Italian.

;Alias mp3
;---------------------------------------------------------------------------------------------------------
alias pro_mp3 { dialog -mbps mp3 mp3 -1 -1 140 64 }
;---------------------------------------------------------------------------------------------------------
;ProMp3 Questo file fa parte del ProScript ver 0.1
;autore Kibo

dialog mp3 {
  title "ProScript-Music"
  ;size -1 -1 112 50
  size -1 -1 112 50
  ;option dbu
  option dbu notheme
  edit "Canzone.mp3", 1, 4 2 50 10, autohs center
  edit "Durata", 2, 4 13 50 10, autohs center
}

on *:dialog:mp3:*:*: {
  if ($devent == init) {
    dcx Mark mp3 mp3_cb
    ;- Creazione Edit
    ;xdialog -c $dname 10 edit 140 4 130 55 smooth notheme group bitmap
    xdialog -c $dname 11 text 140 4 130 55 smooth notheme transparent
    xdid -U $dname 11
    xdialog -c $dname 10 edit 140 4 130 55  group bitmap
    xdid -a $dname 10 00:00 
    xdid -f $dname 10 +a ansi 25 Arial 
    xdid -C $dname 10 +bk $rgb(255,128,0) 
    xdid -x $dname 10 +s 
    ;xdid -b $dname 10 ;Se disabilito mi cambia il colore del testo
    ;xdid -C $dname 10 +t $rgb(24,45,25)
    ;- Creazione Pulsanti
    xdialog -c $dname 4 button 5 70 50 50 smooth notheme
    ;xdialog -c $dname 5 button 5 70 50 50 smooth notheme
    xdialog -c $dname 6 button 60 70 50 50 smooth notheme
    xdialog -c $dname 7 button 115 70 50 50 smooth notheme
    xdialog -c $dname 8 button 170 70 50 50 smooth notheme
    xdialog -c $dname 9 button 225 70 50 50 smooth notheme
    ;- Icona
    xdid -w $dname 4 +ng 113 shell32.dll
    ;- Pulsante Play
    xdid -t $dname 6 4
    xdid -f $dname 6 +a symbol 10 Webdings
    ;- Pulsante Stop
    xdid -t $dname 7 ;
    xdid -f $dname 7 +a symbol 10 Webdings
    ;-
    xdid -t $dname 8 :
    xdid -f $dname 8 +a symbol 10 Webdings
    ;-
    xdid -t $dname 9 9
    xdid -f $dname 9 +a symbol 10 Webdings
    ;-
    ;xdid -v $dname 3 100 ;Per incrementare la progressbar
    ;Controllo se è settata una directory
  }
  if ($devent == sclick) {
    if ($did = 5) { _dir::setf | echo -s %pro_music_dir }
  }
  ;Gestione chiusura mp3
  ;deallochiamo l'hasktable e %c_song
  if ($devent == close) { 
    splay stop 
    splay -c 
    .timer_countdown off 
    if ($hget(mp3,0)) { .hfree -s mp3 }
    unset %pro_music_dir
    unset %c_song
  }
}

alias -l _dir::setf { _dir::path $sfile($+($iif($isdir($mircdir\Musica),$mircdir\Musica,$sound(mp3))),ProScript MP3 Music - Scegli Cartella) }
alias -l _dir::check { return $iif(%pro_music_dir,%pro_music_dir,0) }
alias mp3_cb { 

  ;Directory
  if ($2 == sclick) { if ($3 == 4) { _dir::setf } }

  ;AntiFocus 00:00
  if ($2 == mouse)  { if ($3 == 10) { xdid -U mp3 10 } }
  if ($2 == lbdown) { if ($3 == 10) { return nocopy } }
  if ($2 == sclick) { if ($3 == 10) { xdid -U mp3 10 } }

  ;Play
  ;Verifichiamo se è stata scelta una cartella e che al suo interno contenga almeno un brano
  if ($2 == sclick) {
    ;Pulsante play 
    if ($3 == 6) {
      if ($insong.pause) { splay resume | return }
      if ($isdir($_dir::check)) {
        if ($findfile($_dir::check,*.mp3,0)) { pro_mp3_play  } 
        else { _dir::setf | echo -s Non sono presenti mp3 }
      }
      else { _dir::setf }
    }
  }
  ;Pulsante stop
  if ($2 == sclick) {
    if ($3 == 7) { if ($insong) { splay pause | .timer_countdown off } }
  }
  ;Pulsante skip
  if ($2 == sclick) {
    if ($3 == 8) { splay -p skip }
  }
  ;Pulsante back
  if ($2 == sclick) {
    if ($3 == 9) { pro_mp3_back }
  }
  ;Visualizzo titolo canzone e durata
  if ($2 == sclick) { 
    if ( ($3 == 6) || ($3 == 8) || ($3 == 9) ) {
      Pro_mp3_title
      Pro_mp3_time
    }
  }
}
alias _dir::path {
  ;Implementazione $nofile(filename) esisteva già un comando e non lo sapevo :(
  var %i = $calc($gettok($1-,0,92) - 1)
  var %x = 1
  var %dir
  while (%i > 0) {
    ;echo -s $gettok($1-,%x,92)
    %dir = %dir $+ $gettok($1-,%x,92) $+ $chr(92)
    dec %i
    inc %x
  }
  set %pro_music_dir %dir
}

;Stampa su un hashtable tutti i file mp3 presenti nella directory selezionata precedentemente
alias pro_mp3_list {
  ;Se esiste già un hashtable mp3 la cancello e la ricreo
  if (!$hget(mp3)) { hmake -s mp3 1000 }
  else { hfree -sw mp3 | hmake -s mp3 1000 }
  ;Carico il percorso dei file nel hasktable
  ;esempio:
  ;hashtable: name item text
  ;hashtable: mp3    1  C:\Users\kibo\Desktop\Mirc\ProScript\sounds\avvio.mp3
  var %all_mp3 = $findfile(%pro_music_dir,*.mp3,0,1)
  var %x = 1
  while (%all_mp3 > 0) {
    echo -s $findfile(%pro_music_dir,*.mp3,%x)
    hadd mp3 %x $findfile(%pro_music_dir,*.mp3,%x,1)
    dec %all_mp3
    inc %x
  }
}

;Esegue tutti i file mp3 contenuti nella cartella
alias pro_mp3_play {
  ; splay -pq
  pro_mp3_list
  var %all_mp3 = $findfile(%pro_music_dir,*.mp3,0,1)
  var %x = 1
  while (%all_mp3 > 0) {
    splay -pq $hget(mp3,%x)
    dec %all_mp3
    inc %x
  }
  Pro_mp3_title
  Pro_mp3_time
}

;Gestisce avanzamento della progressbar settando la durata della canzone e il suo avanzamento
alias pro_mp3_pbar { }

;Esegue track precedente
;Quando metto in coda le canzoni per andare avanti ho il comando skip purtroppo non ho il corispettivo
;comando per andare indietro ... questo alias provvede a risolvere il problema

alias pro_mp3_back {
  if ($insong.pause) { 
    splay $iif($hget(mp3,$calc($hfind(mp3,$insong.fname,1).data - 1)).item == 0,$hget(mp3,$hget(mp3,0).item),$hget(mp3,$hget(mp3,$calc($hfind(mp3,$insong.fname,1).data - 1)).item))
  }
  if ($insong) { 
    splay $iif($hget(mp3,$calc($hfind(mp3,$insong.fname,1).data - 1)).item == 0,$hget(mp3,$hget(mp3,0).item),$hget(mp3,$hget(mp3,$calc($hfind(mp3,$insong.fname,1).data - 1)).item))
  }
}
;Stampa la hashtable mp3 
;Questo alias non serve al corretto utilizzo dello script ma è molto utile in fase di testing
alias _hmp3 { 
  if ($hget(mp3)) {
    var %x = 1
    var %n = $hget(mp3,0).item
    while (%n > 0) { echo -s %x $+ $chr(32) $+ $hget(mp3,%x) | dec %n | inc %x }
  }
}

;Gestione Repeat
on 1:mp3end:{
  if ($dialog(mp3)) {
    .timer_mp3_title 1 1 Pro_mp3_title
    .timer_mp3_time 1 1 Pro_mp3_time
    if (%c_song == $hget(mp3,$hget(mp3,0).item).data) {
      if ($dcx(MsgBox, yesno information $chr(9) Proscript $chr(9) La playlist è terminata ripeto ?) == yes) { pro_mp3_play }
    }
  }
}

alias -l Pro_mp3_title {
  did -r mp3 1
  did -a mp3 1 $nopath($insong.fname)
}

alias Pro_mp3_time { 
  did -r mp3 2
  ;did -a mp3 2 $$iif($insong.length,$ifmatch,$chr(32))
  did -a mp3 2 $mp3_time($insong.length)
  if ($insong) { .timer_countdown 0 1 progress_time }
}

;Per questo alias vorrei ringraziare Tobias Paul aka Ecronika
alias mp3_time {
  if ($insong) {
    tokenize 32 $1 $int($calc($1 / 60000))
    return $2 $+ : $+ $base($int($calc(($1 - $2 * 60000) / 1000)),10,10,2)
  }
}

;Ridefinizione splay
alias -l splay {
  Pro_mp3_time
  Pro_mp3_title
  splay $1-
  set %c_song $insong.fname
}

alias -l progress_time {
  xdid -r mp3 10
  if ($insong) {
    xdid -a mp3 10 $+ $chr(32) $+ $chr(48) $+ $mp3_time($calc($insong.pos))
  }
  else { xdid -a mp3 10 00:00 }
}

Comments

Sign in to comment.
kibo   -  Aug 16, 2015

Image

Wims  -  Aug 24, 2015

This is how it look for me here: https://dl.dropboxusercontent.com/u/4249275/pic/mp3.png

Since it's in italian it's a bit hard to understand, what's the point of the button on the left with a disc? When i load a song using this button nothing happens. When I then click on the play button, i get all the song from the path of the filename i previously selected using that disck button echoed. Then if you actually get /splay to fail, it will also get DCX to fail with sendmessage.

kibo  -  Aug 24, 2015

The graphics are completely busted !!! However to select the directory you press the first button if you have not selected even if you press the play button command is invoked to select.

kibo  -  Aug 24, 2015
Wims  -  Aug 24, 2015

I do have dcx, otherwise I wouldn't be able to run this. Your update do not solve the look of the dialog, I'm using windows 7.
If the disc button is supposed to load a folder, why not using $sdir instead of $sfile? you're overcomplicating the extraction of the folder in dir::path anyway.
To expand on my previous post, you're using /splay's queue to queue all the song from the folder, it's possible that /splay will fail (for example if the filename has two consecutives space in it), you should be using the goto label :error to catch the error from /splay to be able to recover from it, and ignore that filename.

Some improvements/criticisms:
-need a list with the song where we can double click them to listen to them, with option such as shuffle, shuffle all etc (look up DCX treeview),
-need an option to set up the volume (/vol)
-need an option to play the previous song
-need a progress bar (dcx) for the song so we can start playing from any position.
-play/pause button should be merged into one button

kibo  -  Aug 24, 2015

Thank for this information(splay fail) i patch immediatly and report you nick for thanks.This is only a version 0.1 in the future i add a trakbar and list for select song alway based on hashtable system.For Dialog i'dont understand the problem i send my code to others friend and works well ... for the rest of remains simple and functional.

Wims  -  Aug 24, 2015

Try sending it to someone using Windows 7 with the default look, it should look the same, perhaps the version of DCX is the reason, but i doubt it, i'm using 2.0-151-g91b9298 which may not be the latest.

kibo  -  Feb 02, 2016

Wims i have edit the code ... try it

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.