[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pygame] A bug and a snag in CD.play()



Hi everyone,

I'm writing a CD player with pygame, and I've run into a bug and a
snag. First the bug.

I've been using the optional 'start' argument to CD.play(), but it
works only half the time. If 'start' is in the second half of the
track, CD.play() fails silently.

The trouble is the endframe variable in src/cdrom.c/cd_play(). It is
initialized (somewhat confusingly) to the number of frames to play,
but then it is tested as if it were the end frame all along:

    if(endframe < startframe || ...)
        RETURN_NONE;

When I removed this test, the function worked as advertised. I've
included a patch below which also renames endframe to nframes.

Now the snag. No matter what you do with CD.play(), it will only play
to the end of the track. As far as I can tell, there is no way to make
it continue into the next track and play the rest of the CD the way
most CD players do.

I've found a trick. If you call SDL_CDPLayTracks() with nframes==0, it
will play the rest of the CD. So you can call CD.play() with the end
time equal to the start time, which will give nframes==0. This seems
a bit dirty, though.

Is there a way to add this functionality to pygame without making a
mess of pygame.cdrom?

Also, can anyone think of a way to play tracks 4-6 (and then stop) without
making more of a mess og pygame.cdrom?


269c269
<       int result, track, startframe, endframe;
---
>       int result, track, startframe, nframes;
286c286
<       endframe = 0;
---
>       nframes = 0;
290c290
<               endframe = (int)((end-start) * CD_FPS);
---
>               nframes = (int)((end-start) * CD_FPS);
292,293c292,293
<               endframe = cdrom->track[track].length - startframe;
<       if(endframe < startframe || startframe > 
(int)(cdrom->track[track].length * CD_FPS))
---
>               nframes = cdrom->track[track].length - startframe;
>       if(startframe > (int)(cdrom->track[track].length * CD_FPS))
296c296
<       result = SDL_CDPlayTracks(cdrom, track, startframe, 0, endframe);
---
>       result = SDL_CDPlayTracks(cdrom, track, startframe, 0, nframes);


-- 
   Ole Martin Bjoerndalen
 http://www.cs.uit.no/~olemb/ 
    olemb@stud.cs.uit.no
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org