'This program was made on August 23, 2019 by Ken G. with lots of help by B+, SMcneill, and Petr from the QB64.org forum.
'This program makes 2 temporary files called MyMusicFiles.temp and DIR$INF0.INF in your default temp directory.
'If for some reason these files exist after this program is shut down, you are free to delete them.
IF ENVIRON$("TEMP") <> "" THEN 'Thanks to Steve McNeill use user temp files directory ELSE 'Thanks to Steve McNeill this should be very unlikely tmpDir = "C:\temp"
GOSUB defaultdir:
'Set default folder to Windows Music Default Folder
begin:
record = 0
rec = 0
oldp = 0
p = 0
PRINT "(1) Change Directory" PRINT "(2) Change Back To Windows Default Music Directory" PRINT "(3) Play Entire Directory" PRINT "(4) Play One Song"
defaultdir:
'Play One Song Here
song:
again2:
PRINT "Press only Enter to go back to Menu." INPUT "Song Name: ", song$
PRINT "Filename doesn't exist." PRINT "Try again, or Enter for Menu." LOCATE 6, 1:
PRINT "Space Bar = Pause (P)lay (S)top (M)enu"
oldp = p
'Play Directory Here
playdir:
record = 0
rec = 0
REDIM file
(0) AS STRING 'create empty text array. 0 is record nr. 1! SHELL _HIDE "dir *.mp3 /B > " + tmpDir
+ "\MyMusicFiles.temp" 'create mp3 files list. SHELL _HIDE "DEL " + tmpDir
+ "\MyMusicFiles.temp" PRINT "No mp3 songs on this folder." INPUT "Press Enter to go back to Menu.", menu$
file(record) = file$
f$(record) = file$
record = record + 1 'for next loop we needed array higher up to one
SHELL _HIDE "DEL " + tmpDir
+ "\MyMusicFiles.temp" 'so now file(0) is first file from disk. file(3) is 4th file from disk. Try it:
ready:
a$ = ""
p = 0
oldp = 0
LOCATE 6, 1:
PRINT "Space Bar = Pause (P)lay (N)ext Song (M)enu" oldp = p
more:
rec = rec + 1
'Change Directory Here
changedirectory:
loadDIR myFiles()
mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
CHDIR myFiles
(mySelection&
)
tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!
SHELL _HIDE "DIR /a:d >" + tmpFile
'get directories but have to do a little pruning Index% = -1
d$
= _TRIM$(rightOf$
(fline$
, "<DIR>")) Index% = Index% + 1
fa(Index%) = d$
FUNCTION getArrayItemNumber&
(locateRow
, locateColumn
, boxWidth
, boxHeight
, arr
() AS STRING)
'save old settings to restore at end ofsub
maxWidth = boxWidth ' number of characters in box
maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
page = 0
hlite = 0 ' line in display ready for selection by spacebar or if no number is started, enter
clrStr$
= SPACE$(maxWidth
) 'clearing a display line
GOSUB update
' show the beginning of the array items for selection
'signal cancel selection process, exit sub with this unlikely index to signal canel
choice = -1719 'primes 7 and 8, not likely to be a select index of an array
DO 'until get a selection or demand exit
'handle the key stuff
'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
IF kh&
= 13 THEN 'enter pressed check if number is being entered? ELSE 'clear b$ to show some response to enter b$
= "":
GOSUB update
'clear the value that doesn't work choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
IF kh&
= 27 THEN EXIT DO 'escape clause offered to Cancel selection process IF kh&
= 32 THEN choice
= hlite
+ page
* maxHeight
+ lba
'best way to choose highlighted selection IF kh&
= 8 THEN 'backspace to edit number SELECT CASE kh&
'choosing sections of array to display and highlighted item IF (page
+ 1) * maxHeight
+ lba
<= uba
THEN page
= page
+ 1:
GOSUB update
IF (page
- 1) * maxHeight
+ lba
>= lba
THEN page
= page
- 1:
GOSUB update
page
= page
- 1: hlite
= maxHeight
- 1:
GOSUB update
hlite
= hlite
- 1:
GOSUB update
IF (hlite
+ 1) + page
* maxHeight
+ lba
<= uba
THEN 'ok to move up IF hlite
+ 1 > maxHeight
- 1 THEN page
= page
+ 1: hlite
= 0:
GOSUB update
hlite
= hlite
+ 1:
GOSUB update
page
= 0: hlite
= 0:
GOSUB update
page
= INT((uba
- lba
) / maxHeight
): hlite
= maxHeight
- 1:
GOSUB update
'handle the mouse stuff
page
= page
- 1: hlite
= maxHeight
- 1:
GOSUB update
hlite
= hlite
- 1:
GOSUB update
IF (hlite
+ 1) + page
* maxHeight
+ lba
<= uba
THEN 'ok to move up IF hlite
+ 1 > maxHeight
- 1 THEN page
= page
+ 1: hlite
= 0:
GOSUB update
hlite
= hlite
+ 1:
GOSUB update
'clear mouse clicks
choice = my + page * maxHeight + lba - 1 'select item clicked
IF my
= 0 AND (mx
<= maxWidth
AND mx
>= maxWidth
- 2) THEN 'exit sign EXIT DO 'escape plan for mouse click top right corner of display box IF (page
- 1) * maxHeight
+ lba
>= lba
THEN page
= page
- 1:
GOSUB update
ELSEIF mx
>= 1 AND mx
<= maxWidth
AND my
= maxHeight
+ 1 THEN 'page down bar clicked IF (page
+ 1) * maxHeight
+ lba
<= uba
THEN page
= page
+ 1:
GOSUB update
ELSE ' mouse over highlighting, only if mouse has moved! IF my
- 1 <> hlite
AND (my
- 1 + page
* maxHeight
+ lba
<= uba
) THEN hlite = my - 1
lastMX = mx: lastMY = my
getArrayItemNumber& = choice
'clear key presses
'clear mouse clicks
'_LIMIT 100
'display of array sections and controls on screen
update:
'fix hlite if it has dropped below last array item
WHILE hlite
+ page
* maxHeight
+ lba
> uba
hlite = hlite - 1
'main display of array items at page * maxHeight (lines high)
FOR row
= 0 TO maxHeight
- 1 IF hlite
= row
THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255) index = row + page * maxHeight + lba
LOCATE locateRow
+ row
, locateColumn
'make page up and down bars to click, print PgUp / PgDn if available
'make exit sign for mouse click
LOCATE locateRow
- 1, locateColumn
+ maxWidth
- 3
'if a number selection has been started show it's build = b$
LOCATE locateRow
+ maxHeight
, locateColumn
+ maxWidth
- LEN(b$
) - 1 '_LIMIT 100