[Gambas-user] To fast do..loops for process management!
Demosthenes Koptsis
demosthenesk at ...626...
Thu Nov 27 10:32:20 CET 2008
Hi dear list,
I write a front-end for mpg123 mp3 console player in gambas2 but i
came face to face with a bug and i need your help!
i dont know if the bug is due to gambas or my writing code or mpg123 player's.
The story is like this....
'### I have two public vars
PUBLIC hProcess AS Process 'varProcess is a Process variable for SHELL command
PUBLIC iNrPlayingSong AS Integer 'public var to hold the nr of playing song
'### i execute a command to play mp3 songs
.....
'format sting command
sCommand = "mpg123 -vC@ " & sPlaylistFile 'play in verbose mode
(v), interactive (C), and load a playlist (@)
'execute command
hProcess = SHELL sCommand FOR INPUT OUTPUT
.....
'### previous track sub
PUBLIC SUB btnPreviousTrack_Click()
IF NOT IsNull(hProcess) THEN
IF hProcess.State = 1 THEN PRINT #hProcess, "d" 'mpg123 recieve
a keyboard "d" to go previous track
ENDIF
END
'### next track sub
PUBLIC SUB btnNextTrack_Click()
IF NOT IsNull(hProcess) THEN
IF hProcess.State = 1 THEN PRINT #hProcess, "f" 'mpg123 recieve
a keyboard "f" to go next track
ENDIF
END
'### NOTE, the previous SUBs are the same. They differ only to letters
"f" and "d"
'#### A wait sub for the system, see next!
PUBLIC SUB WaitSystem()
'wait the system
FMain.Mouse = 3
WAIT 0.05
FMain.Mouse = 0
END
'########### So far with no bug, the code is working
'### i write a sub if user click in playlist a list item = a mp3 track
PUBLIC SUB lvwPlayList_DblClick()
DIM iCounter AS Integer = iNrPlayingSong 'var get current playing
song and also act as counter. iNrPlayingSong get its value from SUB
Process_Read()
IF NOT IsNull(lvwPlayList.Key) THEN
'### This do..loop part working fine
'if user click an item with key greater than number of playing song
IF (lvwPlayList.key + 1) > iCounter THEN 'go next track
DO
IF iCounter = (lvwPlayList.key + 1) THEN BREAK
'PRINT "Go next track"
btnNextTrack_Click()
INC iCounter
LOOP
ENDIF
'if user click an item with key smaller than number of playing song
IF (lvwPlayList.key + 1) < iCounter THEN 'go previous track
DO
IF iCounter = (lvwPlayList.key + 1) THEN BREAK
'PRINT "Go previous track"
btnPreviousTrack_Click()
' ### Now the strange bug
'!FIXEME!
####################################################################################
WaitSystem() '***!!!!!***---> ### [ -- i need to force a
wait system sub to working correctly --- ]
'Probably there is a bug.
'the hProcess does not recieve the btnPreviousTrack_Click() command
as recieves btnNextTrack_Click()
'The same code in btnNextTrack_Click() works fine.
'Sorry for the annoying bug.
'!FIXEME!
####################################################################################
DEC iCounter
LOOP
ENDIF
ENDIF
END
'####################
To test this bug make a long playlist with up to 200 mp3s.
if you check the two subs btnNextTrack_Click() and
btnPreviousTrack_Click() are the same.
If you check the two DO..LOOPs parts are the same, they only change in
btnNextTrack_Click() and btnPreviousTrack_Click().
In first case the btnNextTrack_Click() works.
In second case i need to force a wait to application to work the
btnPreviousTrack_Click().
I test to PRINT the vars which they be read from Sub Read_Process and
they are ok. Vars iNrPlayingSong, iCounter are OK.
My conclusion is that hProcess cannot recieve so quickly the previous
command from gambas2.
So the questions now!
Is this a bug of mpg123 player or a bug of gambas in process management?
I attach my project if you want to look its strange bug.
--
Γεια χαρα σε όλους!!!
Regards,
Demosthenes Koptsis
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gambas-mpg123player-src.tar.gz
Type: application/x-gzip
Size: 35281 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20081127/68f5c9db/attachment.bin>
More information about the User
mailing list