'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"
begin:
record = 0
rec = 0
oldp = 0
p = 0
PRINT " (1) Change Directory" PRINT " (3) Play Directory"
'Play One Song Here
song:
again2:
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
'OPTION _EXPLICIT
'_TITLE "Tiny Navigator mod orig post with perm tmpfile" 'B+
' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
' 2019-08-23 try fix (to nav all directories) with one place for tmpFile, theory can't write files in some dir's
' For some reason Windows won't write to a fully pathed file in my user folder???
' Try testing if dir exists "C:\temp" exists and making one if not, yes! and I can write my temp files there
' and now I can chDir anywhere!
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' Attention!!! this creates a temp directory "C:\temp", do not run this program if you forbid this.
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'Change Directory Here
changedirectory:
'SCREEN _NEWIMAGE(1200, 600, 32)
'_SCREENMOVE 100, 50
REDIM myFiles
(0) AS STRING ' >>>>>>>>>>>>>> you could change this name to myDIRs(0)
'loadFA "*.*", myFiles() ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
loadDIR myFiles() ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> myFiles to myDIRS()
mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
CHDIR myFiles
(mySelection&
) ' >>>>>>>>>>>>>>> myFiles(mySelection&) to myDIRS(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$
'attempting use this 4 things (2018-12-30)
' 1. expects HELP sub that uses message and message box but easy to comment out
' 2. expects to be in graphics mode
' 3. chages color of screen
' 4. needs _KEYCLEAR 2 before calling of previous keyhits will interfere!!!
'
' Future Help Message Box for the function.
' "*** Mouse and Key Instructions ***"
'
' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
' "Press spacebar to select a highlighted item or just click it."
' "Use number(s) + enter to select an array item by it's index number,"
' "backspace will remove last number pressed, c will clear a number started."
' "Numbers started are shown in bottom right PgDn bar."
' "Enter will also select the highlighted item, if no number has been started."
' "Home starts you at lowest array index, End highlights then highest index."
' "Use PgUp and PgDn keys to flip through pages of array items."
'
' "Escape returns -1719 to allow a Cancel function and signal no slection."
FUNCTION getArrayItemNumber&
(locateRow
, locateColumn
, boxWidth
, boxHeight
, arr
() AS STRING) 'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
'boxWidth and boxHeight are in character units, again for locate and print at correct places.
'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
'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
'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