Hi people :)
Is there a way to get only the filename with FILEREQUEST$() or DDgui_File() ?
I want my App to import .wav files and play them, but these ones give me the full path :(
Thank you in advance :D
Quote from: jonaspm on 2013-May-01Is there a way to get only the filename with FILEREQUEST$() or DDgui_File() ?
Hello jonaspm. I'm not sure if there's any GLBasic function to do this, but perhaps you could use this simple routine for your needs:
file$ = FILEREQUEST$(TRUE, "Wave|*.wav|All|*.*")
FOR L = LEN(file$) TO 1 STEP -1
IF MID$(file$, L, 1) = "/"
file$ = RIGHT$(file$, LEN(file$) - L - 1)
BREAK
ENDIF
NEXT
PRINT file$, 10, 10
SHOWSCREEN
MOUSEWAIT
Hope it helps!
Try rinstr(path$, "/") to get the last slash. Then cut there with mid$
thank you for your help, im unable to reproduce sounds, :( wav files
both solutions gave me the filename, but how to make it usable with a FOR, TO , LOADSOUND?
here is my App:
number=10
DIM sound$[10]
DIM pos$[10]
DIM keycode$[10]
keycode$[0] = "02"
keycode$[1] = "03"
keycode$[2] = "04"
keycode$[3] = "05"
keycode$[4] = "06"
keycode$[5] = "07"
keycode$[6] = "08"
keycode$[7] = "09"
keycode$[8] = "10"
keycode$[9] = "11"
WHILE TRUE
DDgui_show(FALSE);
SHOWSCREEN
FOR files=0 TO (number)-1
IF DDgui_get$("sound"+files, "CLICKED") = TRUE
sound$[files] = FILEREQUEST$(TRUE, ".wav|*.wav|Todos los Archivos|*.*")
pos$[files] = REVINSTR(sound$[files], "/")+1
sound$[files] = MID$(sound$[files], pos$[files])
DDgui_set("sound"+files, "TEXT", sound$[files])
LOADSOUND sound$[files], files, 1
//LOADSOUND DDgui_get$("sound"+files, "TEXT"), files, 1
ENDIF
IF KEY(keycode$[files]) = TRUE THEN PLAYSOUND(files, 0, 1)
NEXT
WEND
keycode$[10] is defined as "02", "03" to match key code
is anything wrong? thank you
Quote from: jonaspm on 2013-May-01...im unable to reproduce sounds, :( wav files
sound$[files] = FILEREQUEST$(TRUE, ".wav|*.wav|Todos los Archivos|*.*")
pos$[files] = REVINSTR(sound$[files], "/")+1
sound$[files] = MID$(sound$[files], pos$[files])
DDgui_set("sound"+files, "TEXT", sound$[files])
LOADSOUND sound$[files], files, 1 // the path to the sound file has been stripped away
Hello again jonaspm. It seems that the sounds are not playing because the sound files have not been loaded. When you stripped the file path away, LOADSOUND is unable to locate them. Have a look:
sound$ = FILEREQUEST$(TRUE, "Wave|*.wav|All|*.*")
LOADSOUND sound$, 1, 1
PLAYSOUND(1, 0, 1)
PRINT "First sound file with the full path loaded and played...", 10, 10
SHOWSCREEN
KEYWAIT
sound2$ = GetFileName$(FILEREQUEST$(TRUE, "Wave|*.wav|All|*.*"))
LOADSOUND sound2$, 2, 1
PLAYSOUND(2, 0, 1)
PRINT "Second sound file with the path stripped away was not loaded...", 10, 10
SHOWSCREEN
KEYWAIT
FUNCTION GetFileName$: fullPath$
RETURN MID$(fullPath$, REVINSTR(fullPath$, "/") + 1)
ENDFUNCTION
The full path may not be necessary if the selected sound file is located in the app's current directory. If you need to display the sound filename in your interface without the full path, you could use a function like the one above without altering the actual full filename:
DDgui_set("sound"+files, "TEXT", GetFilename$(sound$[files]))
Hope it works out.
** EDIT: Is there any reason you used a STRING type for the
pos variable?
pos$[files] = REVINSTR(sound$[files], "/")+1
sound$[files] = MID$(sound$[files], pos$[files])
Thank you for your help,
The LOADSOUND shouldn't have problems since im using: SETCURRENTDIR("Media") // go to media dir
that's why i'm stripping the full path, all sound files are located in "Media"
** EDIT: Is there any reason you used a STRING type for the pos variable?
mistake :D
Still not working the LOADSOUND, I don't know why it doesn't work :(
Check your spelling, look for hidden characters, and try to use the file extension in the name. When saving your sound file, be careful about duplicating the extension in the name. I once wound up with something like "SpriteFile.png.png" which messed me all up. I don't know if any of this will solve your problem, but I have run into similar problems trying to load custom fonts by name only, and these were all sources for my errors. If you get it figured out, let us know what the problem was. If you can't figure it out, zip up the entire folder and post it here. We will be happy to take a look.
-CW
I am having problems understanding why you just need the filename only. I just wrote a test where I selected 5 songs 1 after the other & the result of each was stored in an array. I then looped through the array & it loaded the wav file & played it waiting for a key press before doing the same again on the next item in the array.
The full filename with path was stored in the array as that is what was returned from the filerequest command.
Are you trimming off the path so that only the wav file is bring displayed on-screen?. If so then only do that when you are displaying the wav file. DO NOT modify what is stored in the array as there is no need to, what value the filerequester returns works so there is no need to alter it.
Lee
Sent from my HTC Wildfire using Tapatalk 2
This is my App (screenshot) and translation is below:
Sound Effects Player v1.000
Select the sound effects you wish to use:
bear_growl_y.wav - Press 1 key
sound 2 - Press 2 key
sound 3 - Press 3 key
sound 4 - Press 4 key
sound 5 - Press 5 key
sound 6 - Press 6 key
sound 7 - Press 7 key
sound 8 - Press 8 key
sound 9 - Press 9 key
sound 10 - Press 10 key
only .WAV files are admitted
The intention of my App is to select a button (click it) and then file dialog appears, allowing you to choose a file, after closing the dialog with choosen file, the name of the file is displayed on the button BUT the main feature is to be able to reproduce the sound of the file, pressing a key, so you can play many sound just pressing keys...
Useful for theater plays
So the simple solution to that is like I said, keep the full path etc from the file requester in the array but only edit what is shown on screen.
For example the array has something like "C:/sounds/mywave.wav" stored in it but what you display on screen you can use the code TI-994A posted for stripping the the text.
Lee
Hi Jona.
I downloaded the zip file and had a look at your program. I'm unable to run your code on my platform so I'm at a dead end. I wish I could have been more help. For what it is worth, you seem to be a more advanced programer than I am; so I'll bet you will find a solution. Try Fuzzy's suggestion using full paths and cropping the name out just before you display on the screen button. Good luck and keep us in the loop. -CW
IF KEY(keycode%[files]) = TRUE THEN PLAYSOUND(files, 0, 1)
is a problem, instead it should point to where the sound was loaded i.e
PLAYSOUND(sound$[files], 0, 1)
Lee
@CW some of the commands are V11 BETA hence why you might have had a problem compiling it
Are you sure?
i ask because in the help document says:
LOADSOUND file$, num%, buffers%
channel% = PLAYSOUND(num%, pan#, volume#)
Sample:
LOADSOUND "Super.wav", 0, 1
PLAYSOUND (0, -1, 1)
also i am using:
SETCURRENTDIR("Media") // go to media files
Anyways, doing what you suggested compiles without errors but still without sound :(
Just wrote this & it works with no problems
GLOBAL keycodes%[],file$,songs$[],loop%
DIM songs$[10]
DIMDATA keycodes%[],2,3,4,5
SETSCREEN 800,600,0
FOR loop=0 TO 3
file$=FILEREQUEST$(TRUE,"Wave|*.wav")
songs$[loop]=file$
LOADSOUND songs$[loop],loop,4
NEXT
WHILE TRUE
FOR loop=2 TO 5
IF KEY(loop) THEN PLAYSOUND (loop-2,0,1)
NEXT
SHOWSCREEN
WEND
Yours uses DDGui which I have never looked at as had no need to but shouldn't really affect anything.
Lee
I have changed your code & it now works, however it does not work with the wav files you supplied. Even Audicity was unable to load & recognise them which is odd but when I tried some wav files of my own it worked fine :D
// --------------------------------- //
// Project: SE Player
// Start: Tuesday, April 30, 2013
// IDE Version: 11.322
SETCURRENTDIR("Media") // go to media files
GLOBAL sx%,sy%,number%=10,sound$[],keycode%[],file$[],position[],files%
GETSCREENSIZE sx,sy
DIM file$[number]
DIM sound$[number]
DIMDATA keycode%[],2,3,4,5,6,7,8,9,10,11
LOADFONT "font.png", 0
SETFONT 0
DDgui_UpdateFont(TRUE);
DDgui_pushdialog(0, 0, sx, sy, TRUE);
DDgui_set("", "TEXT", "Sound Effects Player "+"v"+LTRIM$(PLATFORMINFO$("VERSION"),"0"));
DDgui_framestart("frame1", "", sx);
DDgui_widget("intro", "Seleccione los efectos de sonido que desea usar:", 0, 0);
DDgui_spacer(10000,15);
DDgui_spacer(10000,15);
DDgui_framestart("buttons", "Sonidos", 0);
DDgui_set("buttons","ALIGN", 0)
DDgui_spacer(10000,30);
FOR widget=0 TO (number)-1
DDgui_button("sound"+widget, "sonido "+(widget+1),(sx/2)/2,0);
IF widget<9; DDgui_widget("key"+widget, "Presione la tecla "+(widget+1), 0, 0); DDgui_set("key"+widget,"ALIGN", 0); ENDIF
IF widget=9; DDgui_widget("key10", "Presione la tecla 0", 0, 0); DDgui_set("key10","ALIGN", 0); ENDIF
DDgui_spacer(10000,30);
DDgui_set("sound"+widget,"ALIGN", 0)
NEXT
DDgui_widget("credits", "Solo son admitidos archivos de sonido con extensión .WAV", 0, 0);
DDgui_spacer(10000,0);
DDgui_widget("credits2", "Ditrabox © 2013", 0, 0);
DDgui_set("credits","ALIGN", 0)
DDgui_set("credits2","ALIGN", 0)
DDgui_frameend();
DDgui_frameend();
WHILE TRUE
DDgui_show(FALSE);
SHOWSCREEN
FOR files=0 TO number-1
IF DDgui_get("sound"+files, "CLICKED") = TRUE
sound$[files] = FILEREQUEST$(TRUE, ".wav|*.wav|Todos los Archivos|*.*")
LOADSOUND sound$[files], files, 1
DDgui_set("sound"+files, "TEXT", GetFileName$(sound$[files]))
ENDIF
IF KEY(keycode%[files]) = TRUE THEN PLAYSOUND(files, 0, 1)
NEXT
WEND
FUNCTION GetFileName$: fullPath$
RETURN MID$(fullPath$, REVINSTR(fullPath$, "/") + 1)
ENDFUNCTION
Lee
Hello again jonaspm. Your code's fine, but PLAYSOUND doesn't support MPEGs.
Simply replace it with PLAYMUSIC sound$[files], FALSE, in which case LOADSOUND is not required. Alternatively, you could simply use WAV format sound files, and call LOADSOUND sound$[files], files, 1 after FILEREQUEST.
In either case, remove the LOADSOUND loop at the top of the code; the dimensions are wrong, and it's not required in the first place.
Cool code, BTW. Good luck! ;)
Im trying to play those wav files, not mp3 files but not works, also maybe the wav files are encoded different?
Anyway, im going to try PLAYMUSIC thank you
PLAYMUSIC WORKS AMAZING, ALSO I CAN PLAY .MP3 OR .WAV FILES IN ANY FOLDER!!!
THANK YOU FOR YOUR HELP, MY APP IS FINALLY WORKING! :D