By Jove, I think I got it!
In this section:
Code:
StringTrimRight, Length, Length, 3
; Convert the specified number of seconds to hh:mm:ss format.
time = 19990101 ; *Midnight* of an arbitrary date.
time += %Length%, seconds
; \/--I added these three lines and made "newTime" & "tmpTime" Global
tmpTime += Length
newTime = 19990101
newTime += %tmpTime%, seconds
FormatTime, newTime, %newTime%, mm:ss
FormatTime, mmss, %time%, mm:ss
Return mmss ; This method is used to support more than 24 hours worth of sections.
Then:
Code:
LV_Add("", a_Index, tmpSong1, tmpSong2, MP3Len)
GuiControl,, sngTtlTime, %newTime% ; This puts "newTime" into the disabled edit box.
tmpSong1 =
tmpSong2 =
if c = 1
{
LV_ChangeColor(a_index, "0x000000", "0xdadada")
c = 0
}
else
c = 1
AND:
Code:
Gui, Add, ListView, x10 y+10 w500 h250 NoSortHdr Grid -Multi AltSubmit vSongView gSongClick, %lvwTtlBar%
Gui, Add, Text, x10 y+10 h15, Total Time:
Gui, Add, Edit, x+0 yp+0 w50 h20 Disabled vsngTtlTime,
Put in the last 2 lines for my GUI.
The modified script {though not quite finished}:
Code:
; <<Description>>
; Working Name: SongLister.ahk
; Created By: Matthew "Dra'Gon" Stohler
; Begun: 15Jun08
; Completed:
; Email: mattstohler@yahoo.com
; ScreenName: Dra_Gon
; Use it however you wish and enjoy!
; -> With thanks to "AGermanUser" for the function GetMP3Len.
; -> With thanks to "Ace_NoOne" for the ListView Width Sizer.
; -> With thanks to "toralf"/"evl"/"shimanov" for the Line Color Changer
; -------------------------------------
#SingleInstance ignore
Gosub SetVaris
Menu, tray, NoStandard
Menu, tray, add, Exit, GuiClose
Menu, tray, Default, Exit
MAIN_GUI_BELOW:
Gui, Add, Button, x10 y10 h20 gStartList, New List
Gui, Add, Button, x+5 yp+0 h20 DISABLED gRedoList vRefList, Refresh List
Gui, Add, Button, x+5 yp+0 h20 DISABLED gSaveList vSvList, Save List
Gui, Add, Button, x+5 yp+0 h20 %DisEn% gOpenList vOpnList, Open List
Gui, Add, Button, x+5 yp+0 h20 DISABLED gCloseList vClsList, Close List
Gui, Add, Text, x10 y+10 w250 h15 vNoRename, Double-Click song to RENAME.
Gui, Add, ListView, x10 y+10 w500 h250 NoSortHdr Grid -Multi AltSubmit vSongView gSongClick, %lvwTtlBar%
Gui, Add, Text, x10 y+10 h15, Total Time:
Gui, Add, Edit, x+0 yp+0 w50 h20 Disabled vsngTtlTime,
LV_ModifyCol(1, 45)
LV_ModifyCol(2, 200)
LV_ModifyCol(3, 200)
LV_ModifyCol(4, 50)
Gui, Show, Center Autosize, Song Meister
Return
GuiClose:
ExitApp
Return
StartList:
LV_Delete()
IfExist, D:\
FileSelectFolder, mscFolder, *D:\, 0, Where is your music?
Else
FileSelectFolder, mscFolder, *%sngFolder%, 0, Where is your music?
IfEqual drvType, CDROM
{
GuiControl,, NoRename, Music Drive is CDROM. Cannot RENAME files!
YNRen = 0
}
Else
{
GuiControl,, NoRename, Double-Click song to RENAME.
YNRen = 1
}
IfNotEqual, mscFolder,
Gosub GetSongs
Else
mscFolder = C:\
IniWrite, %mscFolder%, SLData.ini, Misc, SongFldr
Return
RedoList:
LV_Delete()
Gosub GetSongs
Return
GetSongs:
LV_ActivateColor()
c = 0
tmpTime =
Loop, %mscFolder%\*.mp3
{
MP3Len := GetMP3Len(A_LoopFileFullPath)
sngName%a_Index% := A_LoopFileName
StringReplace, tmpSong, A_LoopFileName, .mp3
IfInString, tmpSong, %a_Space%-%a_Space%
{
StringReplace, tmpSong, tmpSong, %a_Space%-%a_Space%,|
StringSplit, tmpSong, tmpSong, |
}
Else
tmpSong2 := tmpSong
LV_Add("", a_Index, tmpSong1, tmpSong2, MP3Len)
GuiControl,, sngTtlTime, %newTime%
tmpSong1 =
tmpSong2 =
if c = 1
{
LV_ChangeColor(a_index, "0x000000", "0xdadada")
c = 0
}
else
c = 1
}
LV_ModifyCol(2, "Auto")
LV_ModifyCol(3, "Auto")
GUI, +LastFound ; activate GUI window
LsVwWidth := 0 ; initialize ListView width variable
; get columns' widths
Loop % LV_GetCount("Column")
{
SendMessage, 4125, A_Index - 1, 0, SysListView321 ; 4125 is LVM_GETCOLUMNWIDTH.
LsVwWidth := LsVwWidth + ErrorLevel
}
Guicontrol, Enable, RefList
Guicontrol, Enable, SvList
Guicontrol, Enable, ClsList
; resize ListView control and GUI
GuiControl, Move, SongView, % "W" . LsVwWidth + 8
Gui, Show, AutoSize Center Resize
SplitPath, mscFolder,,,,, mscDrive
DriveGet, drvType, Type, %mscDrive%
Return
SaveList:
IniRead, nLists, SLData.ini, Lists, nbrLists
nLists += 1
lstName = SongList%nLists%
InputBox, lstFile, Name, Name of Save File,,,,,,,, %lstName%
FileSelectFolder, lstFolder, *%lstFolder%, 3, Folder to save your list?
Loop % LV_GetCount()
{
LV_GetText(svArtist, A_Index, 2)
LV_GetText(svTitle, A_Index, 3)
LV_GetText(svTime, A_Index, 4)
svCombo := a_Index "$" svArtist "$" svTitle "$" svTime
FileAppend , %svCombo%`n, %lstFolder%\%lstFile%.txt
}
IniWrite, %lstFile%, SLData.ini, Lists, List_%nLists%
IniWrite, %mscFolder%, SLData.ini, Lists, Dir_%nLists%
IniWrite, %nLists%, SLData.ini, Lists, nbrLists
Return
OpenList:
IniRead, nLists, SLData.ini, Lists, nbrLists
If nLists > 0
{
Gui, 3:Add, Text, x10 y10 h15, Select List
iX = 10
iY = 30
i = 0
Loop, %nLists%
{
IniRead, opnList_%a_Index%, SLData.ini, Lists, List_%a_Index%
tmpList := opnList_%a_Index%
Gui, 3:Add, Button, x%iX% y%iY% h20 vbtnList_%a_Index% gGetList, %tmpList%
i += 1
iX = +10
if i = 6
{
iX = 10
iY += 10
i = 0
}
}
Gui, 3:Show, Center Autosize, Song Lists
}
Return
3GUIClose:
Gui, 3:Destroy
Return
CloseList:
LV_Delete()
Return
GetList:
Gui, 1:Default
LV_Delete()
LV_ActivateColor()
c = 0
StringReplace, tmpList, A_GuiControl, btnList_
lstFile := opnList_%tmpList%
Loop, Read, %lstFolder%%lstFile%.txt
{
StringSplit, lstCol, A_LoopReadLine, $
LV_Add("", lstCol1, lstCol2, lstCol3, lstCol4)
if c = 1
{
LV_ChangeColor(a_index, "0x000000", "0xdadada")
c = 0
}
else
c = 1
}
Gosub 3GUIClose
Return
SongClick:
if A_GuiControl = SongView
{
if A_GuiEvent = Normal
{
rowSong := A_EventInfo
LV_GetText(sngArtist, rowSong, 2)
LV_GetText(sngTitle, rowSong, 3)
}
If YNRen = 1
If A_GuiEvent = DoubleClick
Gosub RenSong
}
Return
RenSong:
tmpArtist := sngArtist
tmpTitle := sngTitle
; Gui, 2:+owner1
Gui, 2:Add, Text, x10 y10 h15, Artist(s):
Gui, 2:Add, Edit, x+5 yp+0 w150 h20 vedtArtist, %tmpArtist%
Gui, 2:Add, Text, x10 y40 h15, Song:
Gui, 2:Add, Edit, x+5 yp+0 w150 h20 vedtTitle, %tmpTitle%
Gui, 2:Add, Button, x10 y+10 w50 h20 gGoRename, Do It!
Gui, 2:Add, Button, x+10 yp+0 w50 h20 g2GUIClose, Cancel
Gui, 2:Show, Center Autosize, Rename Song
Return
2GUIClose:
LV_Modify(rowSong, "-Select")
Gui, 2:Destroy
Return
GoRename:
GuiControlGet, newArtist, 2:, edtArtist
GuiControlGet, newTitle, 2:, edtTitle
oldSong := sngName%rowSong%
newSong := newArtist " - " newTitle ".mp3"
FileMove, %mscFolder%\%oldSong%, %mscFolder%\%newSong%
MsgBox, 48, Done!, Your file has been RENAMED!`nOld Name: %oldSong%`nNew Name: %newSong%
Gui, 2:Destroy
Gui, 1:Default
LV_GetText(sngTime, rowSong, 4)
LV_Delete(rowSong)
LV_Insert(rowSong, "", rowSong, newArtist, newTitle, sngTime)
Return
VARIABLE_INITIALIZER_BELOW:
Return
SetVaris:
lvwTtlBar = No.|Artist(s)|Title|Time
IniRead, lstFolder, %A_ScriptDir%\SLData.ini, Misc, SaveFldr
IniRead, sngFolder, %A_ScriptDir%\SLData.ini, Misc, SongFldr
IfExist, %lstFolder%*.txt
DisEn =
Else
DisEn = DISABLED
Return
FUNCTIONS_BELOW:
Return
GetMP3Len(In_PathFile)
{
Global newTime, tmpTime
; In_PathFile: Absolute path to your mp3 file - e.g. C:\Music\test.mp3
; Set variable capacities for dllcalls
VarSetCapacity(ShortName, 255)
VarSetCapacity(Length , 255)
; Transforms FilePath into it's 8.3-Value
RetValue := DllCall("kernel32.dll\GetShortPathNameA"
, "Str", In_PathFile
, "Str", ShortName
, "UInt", 255)
; Open MP3
RetValue := DllCall("winmm.dll\mciSendStringA"
, "Str", "open " . ShortName . " type MPEGVideo alias mp3audio"
, "Str", 0
, "UInt", 0
, "UInt", 0)
; Read Length
RetValue := DllCall("winmm.dll\mciSendStringA"
, "Str", "status mp3audio length"
, "Str", Length
, "UInt", 255
, "UInt", 0)
; Close MP3
RetValue := DllCall("winmm.dll\mciSendStringA"
, "Str", "close mp3audio"
, "Str", 0
, "UInt", 0
, "UInt", 0)
; Trim milliseconds -> just seconds needed
StringTrimRight, Length, Length, 3
; Convert the specified number of seconds to hh:mm:ss format.
time = 19990101 ; *Midnight* of an arbitrary date.
time += %Length%, seconds
tmpTime += Length
newTime = 19990101
newTime += %tmpTime%, seconds
FormatTime, newTime, %newTime%, mm:ss
FormatTime, mmss, %time%, mm:ss
Return mmss ; This method is used to support more than 24 hours worth of sections.
}
LV_ActivateColor()
{
global hw_LV_Sample
OnMessage( 0x4E, "WM_NOTIFY" )
ControlGet, hw_LV_Sample, HWND,, SysListView321
}
LV_ChangeColor(Index, TextColor, BackColor){
global
Line_Color_%Index%_Text := TextColor
Line_Color_%Index%_Back := BackColor
WinSet, Redraw,, ahk_id %hw_LV_Sample%
}
WM_NOTIFY( p_w, p_l, p_m ) {
global hw_LV_Sample
if ( DecodeInteger( "uint4", p_l, 0 ) = hw_LV_Sample ) {
if ( DecodeInteger( "int4", p_l, 8 ) = -12 ) { ; NM_CUSTOMDRAW
draw_stage := DecodeInteger( "uint4", p_l, 12 )
if ( draw_stage = 1 ) ; CDDS_PREPAINT
return, 0x20 ; CDRF_NOTIFYITEMDRAW
else if ( draw_stage = 0x10000|1 ){ ; CDDS_ITEM
Current_Line := DecodeInteger( "uint4", p_l, 36 )+1
LV_GetText(Index, Current_Line)
If (Line_Color_%Index%_Text != ""){
EncodeInteger( Line_Color_%Index%_Text, 4, p_l, 48 ) ; foreground
EncodeInteger( Line_Color_%Index%_Back, 4, p_l, 52 ) ; background
}
}
}
}
}
DecodeInteger( p_type, p_address, p_offset, p_hex=true ){
old_FormatInteger := A_FormatInteger
ifEqual, p_hex, 1, SetFormat, Integer, hex
else, SetFormat, Integer, dec
StringRight, size, p_type, 1
loop, %size%
value += *( ( p_address+p_offset )+( A_Index-1 ) ) << ( 8*( A_Index-1 ) )
if ( size <= 4 and InStr( p_type, "u" ) != 1 and *( p_address+p_offset+( size-1 ) ) & 0x80 )
value := -( ( ~value+1 ) & ( ( 2**( 8*size ) )-1 ) )
SetFormat, Integer, %old_FormatInteger%
return, value
}
EncodeInteger( p_value, p_size, p_address, p_offset ){
loop, %p_size%
DllCall( "RtlFillMemory", "uint", p_address+p_offset+A_Index-1, "uint", 1, "uchar", p_value >> ( 8*( A_Index-1 ) ) )
}
So far so goooood!
Ciao,
Dra'Gon