Author Topic: Tiny Navigator  (Read 9487 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Tiny Navigator
« Reply #15 on: August 24, 2019, 01:26:34 pm »
Your SUB has an error that won't make it work, on this line:
tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!   

The error says: Cannot convert number to string.

Do I need any of Steve's code for this windows temp directory?

QB64 thinks it's a number because we didn't DIM SHARED  tmpDir at start and then set it at start also.
So, you need this clip for starting program, sorry:
Code: QB64: [Select]
  1. DIM SHARED tmpDir AS STRING '  establish a permanent spot for temp files
  2. IF ENVIRON$("TEMP") <> "" THEN 'Thanks to Steve McNeill use user temp files directory
  3.     tmpDir = ENVIRON$("TEMP")
  4. ELSEIF ENVIRON$("TMP") <> "" THEN
  5.     tmpDir = ENVIRON$("TMP")
  6. ELSE 'Thanks to Steve McNeill this should be very unlikely
  7.     IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  8.     tmpDir = "C:\temp"
  9.  

ENVIRON$ is a function that returns values for various variables Windows uses for settings and Paths.
« Last Edit: August 24, 2019, 01:36:54 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tiny Navigator
« Reply #16 on: August 24, 2019, 03:50:41 pm »
Thanks, but we are now back where we started. Maybe you misunderstood me about the problem. Your menu exits out back to my main menu fine. There's no problem with that at all, that I know of. The problem is when after I use your menu, and go back to my main menu and choose "Play Directory", it just sits there, but it also plays the songs. So it DOES go to the playdir section, but for some crazy reason it doesn't CLS and PRINT the sound information that it's playing. Another funny thing is that I can still use the space bar to Pause and P to keep playing, etc., that's in the playdir section. Another strange thing is that if I do not use your code to change the directory and just open the program and choose Play Directory, everything displays fine. So in other words, half of my code is working and the other half is not, on the same section (playdir). Try it out if you want to see what it's doing. But like I said before, no pressure. You mentioned to put whatever I want in that area in the changedir area, I might play around with putting the playdir code inside that and just make 1 section both a change directory and a play directory at the same time. Maybe that will work. I'll try it out. For now, this is what I have. I do appreciate the help. Actually, since your menu exits out fine back to my main menu good, I'm not going to mess with combining them yet.

Edit: I also just added the right temp directory to all the code.

Code: QB64: [Select]
  1. 'This program was made on August 23, 2019 by Ken G. with lots of help by B+ and Petr from the QB64.org forum.
  2. 'This program makes 2 temporary files called MyMusicFiles.temp and DIR$INF0.INF in a directory called c:\temp
  3. 'If for some reason these files exist after this program is shut down, you are free to delete them.
  4.  
  5. _TITLE "Mini MP3 Player"
  6. SCREEN _NEWIMAGE(400, 400, 32)
  7. DIM SHARED tmpDir AS STRING '  establish a permanent spot for temp files
  8. IF ENVIRON$("TEMP") <> "" THEN 'Thanks to Steve McNeill use user temp files directory
  9.     tmpDir = ENVIRON$("TEMP")
  10. ELSEIF ENVIRON$("TMP") <> "" THEN
  11.     tmpDir = ENVIRON$("TMP")
  12. ELSE 'Thanks to Steve McNeill this should be very unlikely
  13.     IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  14.     tmpDir = "C:\temp"
  15.  
  16. begin:
  17.     DIM f$(10000)
  18.     record = 0
  19.     rec = 0
  20.     oldp = 0
  21.     p = 0
  22.     CLS
  23.     PRINT: PRINT: PRINT
  24.     PRINT "                Mini MP3 Player"
  25.     PRINT: PRINT: PRINT
  26.     PRINT "                  By Ken G."
  27.     PRINT
  28.     LOCATE 11, 1: PRINT "Directory: "; _CWD$
  29.     PRINT: PRINT
  30.     PRINT "            (1) Change Directory"
  31.     PRINT "            (2) Play Song"
  32.     PRINT "            (3) Play Directory"
  33.     PRINT "            (4) Quit"
  34.     PRINT
  35.     PRINT
  36.     INPUT "      ->", a
  37.     IF a = 1 THEN GOSUB changedirectory:
  38.     IF a = 2 THEN GOSUB song:
  39.     IF a = 3 THEN GOSUB playdir:
  40.     IF a = 4 THEN END
  41.  
  42. 'Play One Song Here
  43.  
  44. song:
  45. FILES "*.mp3"
  46. again2:
  47. INPUT "Song: ", song$
  48. IF song$ = "" THEN RETURN
  49. fe% = _FILEEXISTS(song$)
  50. IF fe% <> -1 THEN
  51.     PRINT "Filename doesn't exist."
  52.     PRINT "Try again, or Enter for Menu."
  53.     GOTO again2:
  54. s& = _SNDOPEN(song$)
  55. LOCATE 1, 1: PRINT song$
  56. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  57. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  58. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (S)top (M)enu"
  59.  
  60.     a$ = INKEY$
  61.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  62.     IF a$ = " " THEN _SNDPAUSE s&
  63.     IF a$ = "S" OR a$ = "s" THEN _SNDSTOP s&
  64.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  65.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: RETURN
  66.     oldp = p
  67.     p = _SNDGETPOS(s&)
  68.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  69.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN RETURN
  70.  
  71. 'Play Directory Here
  72.  
  73. playdir:
  74. record = 0
  75. rec = 0
  76. REDIM file(0) AS STRING 'create empty text array. 0 is record nr. 1!
  77. SHELL _HIDE "dir *.mp3 /B > " + tmpDir + "\MyMusicFiles.temp" 'create mp3 files list.
  78. OPEN tmpDir + "\MyMusicFiles.temp" FOR INPUT AS #1
  79.     CLOSE #1
  80.     SHELL _HIDE "DEL " + tmpDir + "\MyMusicFiles.temp"
  81.     CLS
  82.     PRINT "No mp3 songs on this folder."
  83.     PRINT
  84.     INPUT "Press Enter to go back to Menu.", menu$
  85.     RETURN
  86.     LINE INPUT #1, file$
  87.     file(record) = file$
  88.     f$(record) = file$
  89.     PRINT f$(record)
  90.     record = record + 1 'for next loop we needed array higher up to one
  91.     REDIM _PRESERVE file(record) AS STRING 'this do array bigger without deleting content
  92. SHELL _HIDE "DEL " + tmpDir + "\MyMusicFiles.temp"
  93. 'so now file(0) is first file from disk. file(3) is 4th file from disk. Try it:
  94. ready:
  95. a$ = ""
  96. p = 0
  97. oldp = 0
  98. s& = _SNDOPEN(file(rec))
  99. LOCATE 1, 1: PRINT f$(rec)
  100. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  101. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  102. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (N)ext Song (M)enu"
  103.     a$ = INKEY$
  104.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  105.     IF a$ = " " THEN _SNDPAUSE s&
  106.     IF a$ = "N" OR a$ = "n" THEN _SNDSTOP s&
  107.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  108.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: rec = 0: RETURN
  109.     oldp = p
  110.     p = _SNDGETPOS(s&)
  111.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  112.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN EXIT DO
  113. more:
  114. IF rec = record - 1 THEN RETURN
  115. rec = rec + 1
  116. GOTO ready:
  117. 'OPTION _EXPLICIT
  118. '_TITLE "Tiny Navigator mod orig post with perm tmpfile" 'B+
  119. ' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
  120. ' 2019-08-23 try fix (to nav all directories) with one place for tmpFile, theory can't write files in some dir's
  121. ' For some reason Windows won't write to a fully pathed file in my user folder???
  122. ' Try testing if dir exists "C:\temp" exists and making one if not, yes! and I can write my temp files there
  123. ' and now I can chDir anywhere!
  124.  
  125. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  126.  
  127. ' Attention!!!  this creates a temp directory "C:\temp", do not run this program if you forbid this.
  128.  
  129. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  130.  
  131. 'Change Directory Here
  132.  
  133.  
  134. changedirectory:
  135. 'SCREEN _NEWIMAGE(1200, 600, 32)
  136. '_SCREENMOVE 100, 50
  137.  
  138.  
  139. DIM mySelection&, done$
  140.  
  141.     PRINT "Current Directory: " + _CWD$
  142.     REDIM myFiles(0) AS STRING ' >>>>>>>>>>>>>> you could change this name to myDIRs(0)
  143.  
  144.     'loadFA "*.*", myFiles()  ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  145.     loadDIR myFiles() ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> myFiles to myDIRS()
  146.  
  147.     mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
  148.     CLS
  149.     IF mySelection& <> -1719 THEN
  150.         CHDIR myFiles(mySelection&) ' >>>>>>>>>>>>>>> myFiles(mySelection&) to myDIRS(mySelection&)
  151.     ELSE
  152.         _KEYCLEAR
  153.         EXIT DO
  154.     END IF
  155.     _LIMIT 60
  156. LOOP 'UNTIL done$ <> ""
  157.  
  158.  
  159.  
  160.  
  161. SUB loadDIR (fa() AS STRING)
  162.     DIM tmpFile AS STRING, Index%, fline$, d$
  163.     tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!
  164.     SHELL _HIDE "DIR /a:d >" + tmpFile 'get directories  but have to do a little pruning
  165.     OPEN tmpFile FOR INPUT AS #1
  166.     Index% = -1
  167.     DO WHILE NOT EOF(1)
  168.         LINE INPUT #1, fline$
  169.         IF INSTR(fline$, "<DIR>") THEN
  170.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  171.             Index% = Index% + 1
  172.             REDIM _PRESERVE fa(Index%)
  173.             fa(Index%) = d$
  174.         END IF
  175.     LOOP
  176.     CLOSE #1
  177.     KILL tmpFile
  178.  
  179. FUNCTION rightOf$ (source$, of$)
  180.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  181.  
  182. 'attempting use this 4 things (2018-12-30)
  183. ' 1. expects HELP sub that uses message and message box but easy to comment out
  184. ' 2. expects to be in graphics mode
  185. ' 3. chages color of screen
  186. ' 4. needs _KEYCLEAR 2 before calling of previous keyhits will interfere!!!
  187. '
  188. ' Future Help Message Box for the function.
  189. ' "*** Mouse and Key Instructions ***"
  190. '
  191. ' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  192. ' "Press spacebar to select a highlighted item or just click it."
  193. ' "Use number(s) + enter to select an array item by it's index number,"
  194. ' "backspace will remove last number pressed, c will clear a number started."
  195. ' "Numbers started are shown in bottom right PgDn bar."
  196. ' "Enter will also select the highlighted item, if no number has been started."
  197. ' "Home starts you at lowest array index, End highlights then highest index."
  198. ' "Use PgUp and PgDn keys to flip through pages of array items."
  199. '
  200. ' "Escape returns -1719 to allow a Cancel function and signal no slection."
  201. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  202.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  203.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  204.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  205.  
  206.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  207.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  208.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  209.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  210.     DIM clrStr AS STRING, b AS STRING
  211.  
  212.     'save old settings to restore at end ofsub
  213.     curRow = CSRLIN
  214.     curCol = POS(0)
  215.     fg = _DEFAULTCOLOR
  216.     bg = _BACKGROUNDCOLOR
  217.     _KEYCLEAR
  218.  
  219.     maxWidth = boxWidth '       number of characters in box
  220.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  221.     lba = LBOUND(arr)
  222.     uba = UBOUND(arr)
  223.     page = 0
  224.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  225.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  226.  
  227.     GOSUB update '              show the beginning of the array items for selection
  228.  
  229.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  230.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  231.  
  232.     DO 'until get a selection or demand exit
  233.  
  234.         'handle the key stuff
  235.         kh& = _KEYHIT
  236.         IF kh& THEN
  237.             IF kh& > 0 AND kh& < 255 THEN
  238.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  239.                 'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  240.  
  241.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  242.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  243.                     IF LEN(b$) THEN
  244.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  245.                             choice = VAL(b$): EXIT DO
  246.                         ELSE 'clear b$ to show some response to enter
  247.                             b$ = "": GOSUB update 'clear the value that doesn't work
  248.                         END IF
  249.                     ELSE
  250.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  251.                     END IF
  252.                 END IF
  253.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  254.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  255.                 IF kh& = 8 THEN 'backspace to edit number
  256.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  257.                 END IF
  258.             ELSE
  259.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  260.                     CASE 20736 'pg dn
  261.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  262.                     CASE 18688 'pg up
  263.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  264.                     CASE 18432 'up
  265.                         IF hlite - 1 < 0 THEN
  266.                             IF page > 0 THEN
  267.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  268.                             END IF
  269.                         ELSE
  270.                             hlite = hlite - 1: GOSUB update
  271.                         END IF
  272.                     CASE 20480 'down
  273.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  274.                             IF hlite + 1 > maxHeight - 1 THEN
  275.                                 page = page + 1: hlite = 0: GOSUB update
  276.                             ELSE
  277.                                 hlite = hlite + 1: GOSUB update
  278.                             END IF
  279.                         END IF
  280.                     CASE 18176 'home
  281.                         page = 0: hlite = 0: GOSUB update
  282.                     CASE 20224 ' end
  283.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  284.                 END SELECT
  285.             END IF
  286.         END IF
  287.  
  288.         'handle the mouse stuff
  289.         WHILE _MOUSEINPUT
  290.             IF _MOUSEWHEEL = -1 THEN 'up?
  291.                 IF hlite - 1 < 0 THEN
  292.                     IF page > 0 THEN
  293.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  294.                     END IF
  295.                 ELSE
  296.                     hlite = hlite - 1: GOSUB update
  297.                 END IF
  298.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  299.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  300.                     IF hlite + 1 > maxHeight - 1 THEN
  301.                         page = page + 1: hlite = 0: GOSUB update
  302.                     ELSE
  303.                         hlite = hlite + 1: GOSUB update
  304.                     END IF
  305.                 END IF
  306.             END IF
  307.         WEND
  308.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  309.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  310.             'clear mouse clicks
  311.             mb = _MOUSEBUTTON(1)
  312.             IF mb THEN 'clear it
  313.                 WHILE mb 'OK!
  314.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  315.                     _LIMIT 100
  316.                 WEND
  317.             END IF
  318.  
  319.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  320.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  321.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  322.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  323.                     EXIT DO 'escape plan for mouse click top right corner of display box
  324.                 ELSE 'PgUp bar clicked
  325.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  326.                 END IF
  327.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  328.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  329.             END IF
  330.         ELSE '   mouse over highlighting, only if mouse has moved!
  331.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  332.                 IF mx <> lastMX OR my <> lastMY THEN
  333.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  334.                         hlite = my - 1
  335.                         lastMX = mx: lastMY = my
  336.                         GOSUB update
  337.                     END IF
  338.                 END IF
  339.             END IF
  340.         END IF
  341.         _LIMIT 200
  342.     LOOP UNTIL choice >= lba AND choice <= uba
  343.     getArrayItemNumber& = choice
  344.     COLOR fg, bg
  345.     'clear key presses
  346.     _KEYCLEAR
  347.     LOCATE curRow, curCol
  348.     'clear mouse clicks
  349.     mb = _MOUSEBUTTON(1)
  350.     IF mb THEN 'clear it
  351.         WHILE mb 'OK!
  352.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  353.             _LIMIT 100
  354.         WEND
  355.     END IF
  356.     EXIT SUB
  357.  
  358.     'display of array sections and controls on screen
  359.     update:
  360.  
  361.     'fix hlite if it has dropped below last array item
  362.     WHILE hlite + page * maxHeight + lba > uba
  363.         hlite = hlite - 1
  364.     WEND
  365.  
  366.     'main display of array items at page * maxHeight (lines high)
  367.     FOR row = 0 TO maxHeight - 1
  368.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  369.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  370.         index = row + page * maxHeight + lba
  371.         IF index >= lba AND index <= uba THEN
  372.             LOCATE locateRow + row, locateColumn
  373.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  374.         END IF
  375.     NEXT
  376.  
  377.     'make page up and down bars to click, print PgUp / PgDn if available
  378.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  379.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  380.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  381.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  382.     IF page <> INT(uba / maxHeight) THEN
  383.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  384.     END IF
  385.     'make exit sign for mouse click
  386.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  387.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  388.     PRINT " X "
  389.  
  390.     'if a number selection has been started show it's build = b$
  391.     IF LEN(b$) THEN
  392.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  393.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  394.         PRINT b$;
  395.     END IF
  396.     _DISPLAY
  397.     _LIMIT 100
  398.     RETURN
  399.  
« Last Edit: August 24, 2019, 04:13:52 pm by SierraKen »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Tiny Navigator
« Reply #17 on: August 24, 2019, 04:06:15 pm »
Sounds like a sub is setting _DISPLAY internally, while the program expects _AUTODISPLAY to be in use.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Tiny Navigator
« Reply #18 on: August 24, 2019, 04:29:36 pm »
Sounds like a sub is setting _DISPLAY internally, while the program expects _AUTODISPLAY to be in use.

Aha! could be it! but isn't the menu showing OK, but that waits for INPUT... hmm...

I need to get that array display code updated with the Screen State saver sub!

Ken try _AUTODISPLAY in that insert section of changedDirectory GOSUB line 174 and then exit do.

Update: Yep! that fixed it! I just found out I have an MP3 file in QB64 Directory that plays fireworks, maybe you guys do too? It is just as Ken said, info displays fine until run the Change directory code and then nothing shows until there is an input line. And _AUTODISPLAY at line 174 fixed it.

Thanks Steve! saved me some time reworking code.

« Last Edit: August 24, 2019, 04:47:23 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tiny Navigator
« Reply #19 on: August 24, 2019, 04:36:13 pm »
ROFL WE DID IT!!!!!!!!!!!!!!! LOLOLOL Thanks Steve and B+! I added it right before it RETURN's back to the main menu and it's perfect now. I was almost getting to the point like on the Star Trek II Wrath of Khan when he talks about Kirk (who is this program to me): Khan Noonien Singh: He tasks me. He tasks me, and I shall have him. I'll chase him round the Moons of Nibia and round the Antares Maelstrom and round Perdition's flames before I give him up!

(Edit: I just added one CLS line so it would erase the name of the older song.)

Thanks guys.

Here is the code that works:

Code: QB64: [Select]
  1. '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.
  2. 'This program makes 2 temporary files called MyMusicFiles.temp and DIR$INF0.INF in your default temp directory.
  3. 'If for some reason these files exist after this program is shut down, you are free to delete them.
  4.  
  5. _TITLE "Mini MP3 Player"
  6. SCREEN _NEWIMAGE(400, 400, 32)
  7. DIM SHARED tmpDir AS STRING '  establish a permanent spot for temp files
  8. IF ENVIRON$("TEMP") <> "" THEN 'Thanks to Steve McNeill use user temp files directory
  9.     tmpDir = ENVIRON$("TEMP")
  10. ELSEIF ENVIRON$("TMP") <> "" THEN
  11.     tmpDir = ENVIRON$("TMP")
  12. ELSE 'Thanks to Steve McNeill this should be very unlikely
  13.     IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  14.     tmpDir = "C:\temp"
  15.  
  16. begin:
  17.     DIM f$(10000)
  18.     record = 0
  19.     rec = 0
  20.     oldp = 0
  21.     p = 0
  22.     CLS
  23.     PRINT: PRINT: PRINT
  24.     PRINT "                Mini MP3 Player"
  25.     PRINT: PRINT: PRINT
  26.     PRINT "                  By Ken G."
  27.     PRINT
  28.     LOCATE 11, 1: PRINT "Directory: "; _CWD$
  29.     PRINT: PRINT
  30.     PRINT "            (1) Change Directory"
  31.     PRINT "            (2) Play Song"
  32.     PRINT "            (3) Play Directory"
  33.     PRINT "            (4) Quit"
  34.     PRINT
  35.     PRINT
  36.     INPUT "      ->", a
  37.     IF a = 1 THEN GOSUB changedirectory:
  38.     IF a = 2 THEN GOSUB song:
  39.     IF a = 3 THEN GOSUB playdir:
  40.     IF a = 4 THEN END
  41.  
  42. 'Play One Song Here
  43.  
  44. song:
  45. FILES "*.mp3"
  46. again2:
  47. INPUT "Song: ", song$
  48. IF song$ = "" THEN RETURN
  49. fe% = _FILEEXISTS(song$)
  50. IF fe% <> -1 THEN
  51.     PRINT "Filename doesn't exist."
  52.     PRINT "Try again, or Enter for Menu."
  53.     GOTO again2:
  54. s& = _SNDOPEN(song$)
  55. LOCATE 1, 1: PRINT song$
  56. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  57. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  58. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (S)top (M)enu"
  59.  
  60.     a$ = INKEY$
  61.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  62.     IF a$ = " " THEN _SNDPAUSE s&
  63.     IF a$ = "S" OR a$ = "s" THEN _SNDSTOP s&
  64.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  65.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: RETURN
  66.     oldp = p
  67.     p = _SNDGETPOS(s&)
  68.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  69.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN RETURN
  70.  
  71. 'Play Directory Here
  72.  
  73. playdir:
  74. record = 0
  75. rec = 0
  76. REDIM file(0) AS STRING 'create empty text array. 0 is record nr. 1!
  77. SHELL _HIDE "dir *.mp3 /B > " + tmpDir + "\MyMusicFiles.temp" 'create mp3 files list.
  78. OPEN tmpDir + "\MyMusicFiles.temp" FOR INPUT AS #1
  79.     CLOSE #1
  80.     SHELL _HIDE "DEL " + tmpDir + "\MyMusicFiles.temp"
  81.     CLS
  82.     PRINT "No mp3 songs on this folder."
  83.     PRINT
  84.     INPUT "Press Enter to go back to Menu.", menu$
  85.     RETURN
  86.     LINE INPUT #1, file$
  87.     file(record) = file$
  88.     f$(record) = file$
  89.     record = record + 1 'for next loop we needed array higher up to one
  90.     REDIM _PRESERVE file(record) AS STRING 'this do array bigger without deleting content
  91. SHELL _HIDE "DEL " + tmpDir + "\MyMusicFiles.temp"
  92. 'so now file(0) is first file from disk. file(3) is 4th file from disk. Try it:
  93. ready:
  94. a$ = ""
  95. p = 0
  96. oldp = 0
  97. s& = _SNDOPEN(file(rec))
  98. LOCATE 1, 1: PRINT f$(rec)
  99. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  100. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  101. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (N)ext Song (M)enu"
  102.     a$ = INKEY$
  103.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  104.     IF a$ = " " THEN _SNDPAUSE s&
  105.     IF a$ = "N" OR a$ = "n" THEN _SNDSTOP s&
  106.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  107.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: rec = 0: RETURN
  108.     oldp = p
  109.     p = _SNDGETPOS(s&)
  110.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  111.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN EXIT DO
  112. more:
  113. IF rec = record - 1 THEN RETURN
  114. rec = rec + 1
  115. GOTO ready:
  116. 'OPTION _EXPLICIT
  117. '_TITLE "Tiny Navigator mod orig post with perm tmpfile" 'B+
  118. ' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
  119. ' 2019-08-23 try fix (to nav all directories) with one place for tmpFile, theory can't write files in some dir's
  120. ' For some reason Windows won't write to a fully pathed file in my user folder???
  121. ' Try testing if dir exists "C:\temp" exists and making one if not, yes! and I can write my temp files there
  122. ' and now I can chDir anywhere!
  123.  
  124. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  125.  
  126. ' Attention!!!  this creates a temp directory "C:\temp", do not run this program if you forbid this.
  127.  
  128. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  129.  
  130. 'Change Directory Here
  131.  
  132.  
  133. changedirectory:
  134. 'SCREEN _NEWIMAGE(1200, 600, 32)
  135. '_SCREENMOVE 100, 50
  136.  
  137.  
  138. DIM mySelection&, done$
  139.  
  140.     PRINT "Current Directory: " + _CWD$
  141.     REDIM myFiles(0) AS STRING ' >>>>>>>>>>>>>> you could change this name to myDIRs(0)
  142.  
  143.     'loadFA "*.*", myFiles()  ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  144.     loadDIR myFiles() ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> myFiles to myDIRS()
  145.  
  146.     mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
  147.     CLS
  148.     IF mySelection& <> -1719 THEN
  149.         CHDIR myFiles(mySelection&) ' >>>>>>>>>>>>>>> myFiles(mySelection&) to myDIRS(mySelection&)
  150.     ELSE
  151.         _KEYCLEAR
  152.         EXIT DO
  153.     END IF
  154.     _LIMIT 60
  155. LOOP 'UNTIL done$ <> ""
  156.  
  157.  
  158.  
  159. SUB loadDIR (fa() AS STRING)
  160.     DIM tmpFile AS STRING, Index%, fline$, d$
  161.     tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!
  162.     SHELL _HIDE "DIR /a:d >" + tmpFile 'get directories  but have to do a little pruning
  163.     OPEN tmpFile FOR INPUT AS #1
  164.     Index% = -1
  165.     DO WHILE NOT EOF(1)
  166.         LINE INPUT #1, fline$
  167.         IF INSTR(fline$, "<DIR>") THEN
  168.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  169.             Index% = Index% + 1
  170.             REDIM _PRESERVE fa(Index%)
  171.             fa(Index%) = d$
  172.         END IF
  173.     LOOP
  174.     CLOSE #1
  175.     KILL tmpFile
  176.  
  177. FUNCTION rightOf$ (source$, of$)
  178.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  179.  
  180. 'attempting use this 4 things (2018-12-30)
  181. ' 1. expects HELP sub that uses message and message box but easy to comment out
  182. ' 2. expects to be in graphics mode
  183. ' 3. chages color of screen
  184. ' 4. needs _KEYCLEAR 2 before calling of previous keyhits will interfere!!!
  185. '
  186. ' Future Help Message Box for the function.
  187. ' "*** Mouse and Key Instructions ***"
  188. '
  189. ' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  190. ' "Press spacebar to select a highlighted item or just click it."
  191. ' "Use number(s) + enter to select an array item by it's index number,"
  192. ' "backspace will remove last number pressed, c will clear a number started."
  193. ' "Numbers started are shown in bottom right PgDn bar."
  194. ' "Enter will also select the highlighted item, if no number has been started."
  195. ' "Home starts you at lowest array index, End highlights then highest index."
  196. ' "Use PgUp and PgDn keys to flip through pages of array items."
  197. '
  198. ' "Escape returns -1719 to allow a Cancel function and signal no slection."
  199. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  200.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  201.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  202.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  203.  
  204.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  205.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  206.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  207.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  208.     DIM clrStr AS STRING, b AS STRING
  209.  
  210.     'save old settings to restore at end ofsub
  211.     curRow = CSRLIN
  212.     curCol = POS(0)
  213.     fg = _DEFAULTCOLOR
  214.     bg = _BACKGROUNDCOLOR
  215.     _KEYCLEAR
  216.  
  217.     maxWidth = boxWidth '       number of characters in box
  218.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  219.     lba = LBOUND(arr)
  220.     uba = UBOUND(arr)
  221.     page = 0
  222.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  223.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  224.  
  225.     GOSUB update '              show the beginning of the array items for selection
  226.  
  227.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  228.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  229.  
  230.     DO 'until get a selection or demand exit
  231.  
  232.         'handle the key stuff
  233.         kh& = _KEYHIT
  234.         IF kh& THEN
  235.             IF kh& > 0 AND kh& < 255 THEN
  236.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  237.                 'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  238.  
  239.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  240.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  241.                     IF LEN(b$) THEN
  242.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  243.                             choice = VAL(b$): EXIT DO
  244.                         ELSE 'clear b$ to show some response to enter
  245.                             b$ = "": GOSUB update 'clear the value that doesn't work
  246.                         END IF
  247.                     ELSE
  248.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  249.                     END IF
  250.                 END IF
  251.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  252.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  253.                 IF kh& = 8 THEN 'backspace to edit number
  254.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  255.                 END IF
  256.             ELSE
  257.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  258.                     CASE 20736 'pg dn
  259.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  260.                     CASE 18688 'pg up
  261.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  262.                     CASE 18432 'up
  263.                         IF hlite - 1 < 0 THEN
  264.                             IF page > 0 THEN
  265.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  266.                             END IF
  267.                         ELSE
  268.                             hlite = hlite - 1: GOSUB update
  269.                         END IF
  270.                     CASE 20480 'down
  271.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  272.                             IF hlite + 1 > maxHeight - 1 THEN
  273.                                 page = page + 1: hlite = 0: GOSUB update
  274.                             ELSE
  275.                                 hlite = hlite + 1: GOSUB update
  276.                             END IF
  277.                         END IF
  278.                     CASE 18176 'home
  279.                         page = 0: hlite = 0: GOSUB update
  280.                     CASE 20224 ' end
  281.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  282.                 END SELECT
  283.             END IF
  284.         END IF
  285.  
  286.         'handle the mouse stuff
  287.         WHILE _MOUSEINPUT
  288.             IF _MOUSEWHEEL = -1 THEN 'up?
  289.                 IF hlite - 1 < 0 THEN
  290.                     IF page > 0 THEN
  291.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  292.                     END IF
  293.                 ELSE
  294.                     hlite = hlite - 1: GOSUB update
  295.                 END IF
  296.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  297.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  298.                     IF hlite + 1 > maxHeight - 1 THEN
  299.                         page = page + 1: hlite = 0: GOSUB update
  300.                     ELSE
  301.                         hlite = hlite + 1: GOSUB update
  302.                     END IF
  303.                 END IF
  304.             END IF
  305.         WEND
  306.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  307.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  308.             'clear mouse clicks
  309.             mb = _MOUSEBUTTON(1)
  310.             IF mb THEN 'clear it
  311.                 WHILE mb 'OK!
  312.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  313.                     _LIMIT 100
  314.                 WEND
  315.             END IF
  316.  
  317.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  318.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  319.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  320.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  321.                     EXIT DO 'escape plan for mouse click top right corner of display box
  322.                 ELSE 'PgUp bar clicked
  323.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  324.                 END IF
  325.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  326.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  327.             END IF
  328.         ELSE '   mouse over highlighting, only if mouse has moved!
  329.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  330.                 IF mx <> lastMX OR my <> lastMY THEN
  331.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  332.                         hlite = my - 1
  333.                         lastMX = mx: lastMY = my
  334.                         GOSUB update
  335.                     END IF
  336.                 END IF
  337.             END IF
  338.         END IF
  339.         _LIMIT 200
  340.     LOOP UNTIL choice >= lba AND choice <= uba
  341.     getArrayItemNumber& = choice
  342.     COLOR fg, bg
  343.     'clear key presses
  344.     _KEYCLEAR
  345.     LOCATE curRow, curCol
  346.     'clear mouse clicks
  347.     mb = _MOUSEBUTTON(1)
  348.     IF mb THEN 'clear it
  349.         WHILE mb 'OK!
  350.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  351.             _LIMIT 100
  352.         WEND
  353.     END IF
  354.     EXIT SUB
  355.  
  356.     'display of array sections and controls on screen
  357.     update:
  358.  
  359.     'fix hlite if it has dropped below last array item
  360.     WHILE hlite + page * maxHeight + lba > uba
  361.         hlite = hlite - 1
  362.     WEND
  363.  
  364.     'main display of array items at page * maxHeight (lines high)
  365.     FOR row = 0 TO maxHeight - 1
  366.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  367.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  368.         index = row + page * maxHeight + lba
  369.         IF index >= lba AND index <= uba THEN
  370.             LOCATE locateRow + row, locateColumn
  371.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  372.         END IF
  373.     NEXT
  374.  
  375.     'make page up and down bars to click, print PgUp / PgDn if available
  376.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  377.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  378.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  379.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  380.     IF page <> INT(uba / maxHeight) THEN
  381.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  382.     END IF
  383.     'make exit sign for mouse click
  384.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  385.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  386.     PRINT " X "
  387.  
  388.     'if a number selection has been started show it's build = b$
  389.     IF LEN(b$) THEN
  390.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  391.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  392.         PRINT b$;
  393.     END IF
  394.     _DISPLAY
  395.     _LIMIT 100
  396.     RETURN
  397.  
« Last Edit: August 24, 2019, 04:49:34 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tiny Navigator
« Reply #20 on: August 24, 2019, 05:32:51 pm »
It's too bad we can't use the Windows Default Music Directory with this. I tried adding it just now to my music program just with a couple lines to switch to it, which it did. But I then used the selection to change it again with your folder menu to go deeper to play music in it, but the subscript was out of range. I found out how to switch to it from a Wiki example. I have no idea why it wouldn't work with your folder changer once you are in it. I don't use the Windows Default Music Directory myself but just thought it would be good for people that did.
Here is the Wiki example:
http://www.qb64.org/wiki/DIR$

The subscript is out of range on this line:
 CHDIR myFiles(mySelection&)
« Last Edit: August 24, 2019, 05:40:12 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Tiny Navigator
« Reply #21 on: August 24, 2019, 05:50:48 pm »
Nice find Ken! I did not know of this command.

Try chdir to that directory first in the start of your code, the navigator code has to be in the directory to get more directory info to move around from where it is.

BTW I found a spot in my hard drive that has neither a dot directory nor a .. go up directory, hp is hole navigator can fall into and not be able to get out, no ..



Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tiny Navigator
« Reply #22 on: August 24, 2019, 05:55:04 pm »
Yes, that's what I did. I made Default Music Directory part of my main menu. So I went there first, then after it changed to the Default Music Directory, it automatically went back to the main menu so then I went to your directory changing selection to go deeper inside of it. When I did it, it showed the deeper folder, and I went to it, but  when I closed it with your X, is when I got that error and the program closed. The error is this:
The subscript is out of range on this line:
 CHDIR myFiles(mySelection&)
« Last Edit: August 24, 2019, 05:56:10 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tiny Navigator
« Reply #23 on: August 24, 2019, 05:58:53 pm »
The code is very simple to change to the Default Music Directory. It's just this:

Code: QB64: [Select]
  1.  
  2. defaultdir:
  3. CHDIR _DIR$("music")
  4.  
  5.  
« Last Edit: August 24, 2019, 06:00:41 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Tiny Navigator
« Reply #24 on: August 24, 2019, 06:10:18 pm »
Hi Ken,

Short on time I just put this line:
CHDIR _DIR$("music") 

Right after, we set tmpDir, and it seems OK to me, a quick test exiting by clicking X. I will test more after supper...

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tiny Navigator
« Reply #25 on: August 24, 2019, 06:19:04 pm »
It works fine when you don't click any folders inside your menu. Put a test folder inside of your default music folder and click that. Then click the X and see if you are getting the same error I am.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Tiny Navigator
« Reply #26 on: August 24, 2019, 07:46:52 pm »
Hi Ken, I am not able to replicate your error
 
attempt to replicate error.PNG

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tiny Navigator
« Reply #27 on: August 24, 2019, 08:01:27 pm »
Did you click the X or press Esc? Pressing Esc seems to work for some odd reason.
This also brings me back to something you offered me to change earlier, which I didn't do. You said to change myFiles to myFolders right? I didn't do it though but I wonder if that makes any difference? The reason I didn't do it is because it was already fixed by the time I saw your advice on the code.
Also, just so you know, the mouse's wheel never worked on the menu, I always have to press the top or bottom to scroll up or down. I don't know if you ever got that working yet.
« Last Edit: August 24, 2019, 08:05:10 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tiny Navigator
« Reply #28 on: August 24, 2019, 08:26:17 pm »
WOW! I fixed it! LOL! I will test it a couple more times but I think I found the problem. Every computer uses _LIMIT 100 probably a tiny bit differently. I commented out _LIMIT 100 on 2 of yours toward the bottom of your code (and the program). In my experience of working with the _LIMIT command is that when my computers gets around 100, the program slows down dramatically. Sometimes it takes to _LIMIT 50. But this is why I try to not keep it under _LIMIT 200 unless I need something to run very slow. So far I've tested my program and so far it's fixed! Thank you again for the help B+! :)
Now to decide if I want to move my tons of music from its own folder to the Windows Default Music folder lol. I probably should also make that the starting folder of the program as well. I think I will.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tiny Navigator
« Reply #29 on: August 24, 2019, 08:53:00 pm »
Here is my Music Player code that's fixed. I also had to fix the 1 song selection, it had an error when there were no .mp3 files in the directory. So I just changed it to FILES and not FILES *.mp3
I might change that section sometime but as for today, this is my finished version. :)
This version starts out in the Windows Default Music Folder and lets you use B+'s directory selector to choose which one you want to listen to. It also lets you come back to the Windows Default Music Folder if you leave it.

Code: QB64: [Select]
  1. '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.
  2. 'This program makes 2 temporary files called MyMusicFiles.temp and DIR$INF0.INF in your default temp directory.
  3. 'If for some reason these files exist after this program is shut down, you are free to delete them.
  4.  
  5. _TITLE "Mini MP3 Player"
  6. SCREEN _NEWIMAGE(400, 400, 32)
  7. DIM SHARED tmpDir AS STRING '  establish a permanent spot for temp files
  8. IF ENVIRON$("TEMP") <> "" THEN 'Thanks to Steve McNeill use user temp files directory
  9.     tmpDir = ENVIRON$("TEMP")
  10. ELSEIF ENVIRON$("TMP") <> "" THEN
  11.     tmpDir = ENVIRON$("TMP")
  12. ELSE 'Thanks to Steve McNeill this should be very unlikely
  13.     IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  14.     tmpDir = "C:\temp"
  15.  
  16. GOSUB defaultdir: 'Set default folder to Windows Music Default Folder
  17.  
  18. begin:
  19.     DIM f$(10000)
  20.     record = 0
  21.     rec = 0
  22.     oldp = 0
  23.     p = 0
  24.     CLS
  25.     PRINT: PRINT: PRINT
  26.     PRINT "                Mini MP3 Player"
  27.     PRINT: PRINT: PRINT
  28.     PRINT "                  By Ken G."
  29.     PRINT
  30.     LOCATE 11, 1: PRINT "Directory: "; _CWD$
  31.     PRINT: PRINT
  32.     PRINT "(1) Change Directory"
  33.     PRINT "(2) Change Back To Windows Default Music Directory"
  34.     PRINT "(3) Play Entire Directory"
  35.     PRINT "(4) Play One Song"
  36.     PRINT "(5) Quit"
  37.     PRINT
  38.     PRINT
  39.     INPUT "->", a
  40.     IF a = 1 THEN GOSUB changedirectory:
  41.     IF a = 2 THEN GOSUB defaultdir:
  42.     IF a = 3 THEN GOSUB playdir:
  43.     IF a = 4 THEN GOSUB song:
  44.     IF a = 5 THEN END
  45.  
  46. defaultdir:
  47. CHDIR _DIR$("music")
  48.  
  49. 'Play One Song Here
  50.  
  51. song:
  52. again2:
  53. PRINT "Press only Enter to go back to Menu."
  54. INPUT "Song Name: ", song$
  55. IF song$ = "" THEN RETURN
  56. fe% = _FILEEXISTS(song$)
  57. IF fe% <> -1 THEN
  58.     PRINT "Filename doesn't exist."
  59.     PRINT "Try again, or Enter for Menu."
  60.     GOTO again2:
  61. s& = _SNDOPEN(song$)
  62. LOCATE 1, 1: PRINT song$
  63. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  64. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  65. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (S)top (M)enu"
  66.  
  67.     a$ = INKEY$
  68.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  69.     IF a$ = " " THEN _SNDPAUSE s&
  70.     IF a$ = "S" OR a$ = "s" THEN _SNDSTOP s&
  71.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  72.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: RETURN
  73.     oldp = p
  74.     p = _SNDGETPOS(s&)
  75.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  76.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN RETURN
  77.  
  78. 'Play Directory Here
  79.  
  80. playdir:
  81. record = 0
  82. rec = 0
  83. REDIM file(0) AS STRING 'create empty text array. 0 is record nr. 1!
  84. SHELL _HIDE "dir *.mp3 /B > " + tmpDir + "\MyMusicFiles.temp" 'create mp3 files list.
  85. OPEN tmpDir + "\MyMusicFiles.temp" FOR INPUT AS #1
  86.     CLOSE #1
  87.     SHELL _HIDE "DEL " + tmpDir + "\MyMusicFiles.temp"
  88.     CLS
  89.     PRINT "No mp3 songs on this folder."
  90.     PRINT
  91.     INPUT "Press Enter to go back to Menu.", menu$
  92.     RETURN
  93.     LINE INPUT #1, file$
  94.     file(record) = file$
  95.     f$(record) = file$
  96.     record = record + 1 'for next loop we needed array higher up to one
  97.     REDIM _PRESERVE file(record) AS STRING 'this do array bigger without deleting content
  98. SHELL _HIDE "DEL " + tmpDir + "\MyMusicFiles.temp"
  99. 'so now file(0) is first file from disk. file(3) is 4th file from disk. Try it:
  100. ready:
  101. a$ = ""
  102. p = 0
  103. oldp = 0
  104. s& = _SNDOPEN(file(rec))
  105. LOCATE 1, 1: PRINT f$(rec)
  106. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  107. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  108. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (N)ext Song (M)enu"
  109.     a$ = INKEY$
  110.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  111.     IF a$ = " " THEN _SNDPAUSE s&
  112.     IF a$ = "N" OR a$ = "n" THEN _SNDSTOP s&
  113.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  114.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: rec = 0: RETURN
  115.     oldp = p
  116.     p = _SNDGETPOS(s&)
  117.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  118.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN EXIT DO
  119. more:
  120. IF rec = record - 1 THEN RETURN
  121. rec = rec + 1
  122. GOTO ready:
  123.  
  124.  
  125. 'Change Directory Here
  126.  
  127.  
  128. changedirectory:
  129.  
  130.  
  131. DIM mySelection&
  132.  
  133.  
  134.     PRINT "Current Directory: " + _CWD$
  135.     REDIM myFiles(0) AS STRING
  136.  
  137.     loadDIR myFiles()
  138.  
  139.     mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
  140.     CLS
  141.     IF mySelection& <> -1719 THEN
  142.         CHDIR myFiles(mySelection&)
  143.     ELSE
  144.         _KEYCLEAR
  145.         EXIT DO
  146.     END IF
  147.     _LIMIT 60
  148.  
  149.  
  150.  
  151. SUB loadDIR (fa() AS STRING)
  152.     DIM tmpFile AS STRING, Index%, fline$, d$
  153.     tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!
  154.     SHELL _HIDE "DIR /a:d >" + tmpFile 'get directories  but have to do a little pruning
  155.     OPEN tmpFile FOR INPUT AS #1
  156.     Index% = -1
  157.     DO WHILE NOT EOF(1)
  158.         LINE INPUT #1, fline$
  159.         IF INSTR(fline$, "<DIR>") THEN
  160.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  161.             Index% = Index% + 1
  162.             REDIM _PRESERVE fa(Index%)
  163.             fa(Index%) = d$
  164.         END IF
  165.     LOOP
  166.     CLOSE #1
  167.     KILL tmpFile
  168.  
  169. FUNCTION rightOf$ (source$, of$)
  170.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  171.  
  172.  
  173. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  174.  
  175.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  176.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  177.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  178.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  179.     DIM clrStr AS STRING, b AS STRING
  180.  
  181.     'save old settings to restore at end ofsub
  182.     curRow = CSRLIN
  183.     curCol = POS(0)
  184.     fg = _DEFAULTCOLOR
  185.     bg = _BACKGROUNDCOLOR
  186.     _KEYCLEAR
  187.  
  188.     maxWidth = boxWidth '       number of characters in box
  189.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  190.     lba = LBOUND(arr)
  191.     uba = UBOUND(arr)
  192.     page = 0
  193.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  194.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  195.  
  196.     GOSUB update '              show the beginning of the array items for selection
  197.  
  198.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  199.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  200.  
  201.     DO 'until get a selection or demand exit
  202.  
  203.         'handle the key stuff
  204.         kh& = _KEYHIT
  205.         IF kh& THEN
  206.             IF kh& > 0 AND kh& < 255 THEN
  207.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  208.                 'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  209.  
  210.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  211.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  212.                     IF LEN(b$) THEN
  213.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  214.                             choice = VAL(b$): EXIT DO
  215.                         ELSE 'clear b$ to show some response to enter
  216.                             b$ = "": GOSUB update 'clear the value that doesn't work
  217.                         END IF
  218.                     ELSE
  219.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  220.                     END IF
  221.                 END IF
  222.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  223.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  224.                 IF kh& = 8 THEN 'backspace to edit number
  225.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  226.                 END IF
  227.             ELSE
  228.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  229.                     CASE 20736 'pg dn
  230.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  231.                     CASE 18688 'pg up
  232.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  233.                     CASE 18432 'up
  234.                         IF hlite - 1 < 0 THEN
  235.                             IF page > 0 THEN
  236.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  237.                             END IF
  238.                         ELSE
  239.                             hlite = hlite - 1: GOSUB update
  240.                         END IF
  241.                     CASE 20480 'down
  242.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  243.                             IF hlite + 1 > maxHeight - 1 THEN
  244.                                 page = page + 1: hlite = 0: GOSUB update
  245.                             ELSE
  246.                                 hlite = hlite + 1: GOSUB update
  247.                             END IF
  248.                         END IF
  249.                     CASE 18176 'home
  250.                         page = 0: hlite = 0: GOSUB update
  251.                     CASE 20224 ' end
  252.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  253.                 END SELECT
  254.             END IF
  255.         END IF
  256.  
  257.         'handle the mouse stuff
  258.         WHILE _MOUSEINPUT
  259.             IF _MOUSEWHEEL = -1 THEN 'up?
  260.                 IF hlite - 1 < 0 THEN
  261.                     IF page > 0 THEN
  262.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  263.                     END IF
  264.                 ELSE
  265.                     hlite = hlite - 1: GOSUB update
  266.                 END IF
  267.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  268.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  269.                     IF hlite + 1 > maxHeight - 1 THEN
  270.                         page = page + 1: hlite = 0: GOSUB update
  271.                     ELSE
  272.                         hlite = hlite + 1: GOSUB update
  273.                     END IF
  274.                 END IF
  275.             END IF
  276.         WEND
  277.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  278.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  279.             'clear mouse clicks
  280.             mb = _MOUSEBUTTON(1)
  281.             IF mb THEN 'clear it
  282.                 WHILE mb 'OK!
  283.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  284.                     _LIMIT 100
  285.                 WEND
  286.             END IF
  287.  
  288.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  289.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  290.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  291.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  292.                     EXIT DO 'escape plan for mouse click top right corner of display box
  293.                 ELSE 'PgUp bar clicked
  294.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  295.                 END IF
  296.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  297.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  298.             END IF
  299.         ELSE '   mouse over highlighting, only if mouse has moved!
  300.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  301.                 IF mx <> lastMX OR my <> lastMY THEN
  302.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  303.                         hlite = my - 1
  304.                         lastMX = mx: lastMY = my
  305.                         GOSUB update
  306.                     END IF
  307.                 END IF
  308.             END IF
  309.         END IF
  310.         _LIMIT 200
  311.     LOOP UNTIL choice >= lba AND choice <= uba
  312.     getArrayItemNumber& = choice
  313.     COLOR fg, bg
  314.     'clear key presses
  315.     _KEYCLEAR
  316.     LOCATE curRow, curCol
  317.     'clear mouse clicks
  318.     mb = _MOUSEBUTTON(1)
  319.     IF mb THEN 'clear it
  320.         WHILE mb 'OK!
  321.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  322.             '_LIMIT 100
  323.         WEND
  324.     END IF
  325.     EXIT SUB
  326.  
  327.     'display of array sections and controls on screen
  328.     update:
  329.  
  330.     'fix hlite if it has dropped below last array item
  331.     WHILE hlite + page * maxHeight + lba > uba
  332.         hlite = hlite - 1
  333.     WEND
  334.  
  335.     'main display of array items at page * maxHeight (lines high)
  336.     FOR row = 0 TO maxHeight - 1
  337.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  338.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  339.         index = row + page * maxHeight + lba
  340.         IF index >= lba AND index <= uba THEN
  341.             LOCATE locateRow + row, locateColumn
  342.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  343.         END IF
  344.     NEXT
  345.  
  346.     'make page up and down bars to click, print PgUp / PgDn if available
  347.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  348.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  349.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  350.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  351.     IF page <> INT(uba / maxHeight) THEN
  352.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  353.     END IF
  354.     'make exit sign for mouse click
  355.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  356.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  357.     PRINT " X "
  358.  
  359.     'if a number selection has been started show it's build = b$
  360.     IF LEN(b$) THEN
  361.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  362.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  363.         PRINT b$;
  364.     END IF
  365.     _DISPLAY
  366.     '_LIMIT 100
  367.     RETURN
  368.  
« Last Edit: August 24, 2019, 08:59:58 pm by SierraKen »