Author Topic: How to detect if PLAY "MB" is done playing a song?  (Read 3385 times)

0 Members and 1 Guest are viewing this topic.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
How to detect if PLAY "MB" is done playing a song?
« on: October 21, 2021, 10:41:04 am »
I'm starting to make some background tunes to loop/play for my puzzle games using the PLAY "MB.." command.  Was wondering if there is a way to detect when a PLAY command is finished playing the tune so I can replay it or load another song.  I suppose I could time how long a tune plays, and set up a timer to restart it, but was wondering is there's a built-in way to detect the finish that I don't know about.  Thanks!

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How to detect if PLAY "MB" is done playing a song?
« Reply #1 on: October 21, 2021, 12:04:56 pm »
Might be _sndplay function?, check Wiki. I know you can put a sound in a loop so it starts right back up after finishing one cycle.

Ha! pretty close, see _SndPlaying Function :)

I luv it when you can guess what a keyword might be.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How to detect if PLAY "MB" is done playing a song?
« Reply #2 on: October 21, 2021, 12:22:54 pm »
Oh the old Play command, sorry.

Can you record Play sounds to file to use _SndPlay?

Or do something like we do with images, record the sound in separate "destination" then play the destination stored in memory. Perhaps with memory handles.

Just need to load a Play string$ into a memory handle.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: How to detect if PLAY "MB" is done playing a song?
« Reply #3 on: October 21, 2021, 01:03:13 pm »
Old school, but perhaps not what you are looking for...

Code: QB64: [Select]
  1.     music$ = "MBT128O2P2P8L8GGGL2E-P24P8L8FFFL2D"
  2.     PLAY music$
  3.     WHILE PLAY(0): WEND
  4.     PRINT "Hello Dav!"
  5.     _DELAY .5

Pete

MB tells it to play in the background.
PLAY(0) is what's controlling the wait until finished to loop effect.

Pete

Edit: It turns out PLAY(0) is not supported in QB64. See my next post further down in this thread.
« Last Edit: October 21, 2021, 02:58:46 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: How to detect if PLAY "MB" is done playing a song?
« Reply #4 on: October 21, 2021, 01:46:01 pm »
Function Play() is just a stub in QB64, never really implemented.

Code: C++: [Select]
  1. int32 func_play(int32 ignore){
  2.     return 0;
  3. }

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: How to detect if PLAY "MB" is done playing a song?
« Reply #5 on: October 21, 2021, 02:53:45 pm »
@Fell Mick Jagger called, and he wants his old QB45 back!

Code: QB64: [Select]
  1. PRINT "Start scale...": PRINT
  2. M$ = "MB C D E F G A B C"
  3. PLAY M$
  4. WHILE PLAY(0) > 3: LOCATE 3, 1: PRINT "Notes in buffer ="; PLAY(0); " ";: WEND
  5. LOCATE 3, 1: PRINT SPACE$(20);
  6. LOCATE 3, 1: PRINT "Half done!"
  7.     IF PLAY(0) = 0 THEN LOCATE 5, 1: PRINT "Finished!": EXIT DO
  8.  

In QuickBASIC, that runs properly. PLAY(0) is (was) a function to store the number of notes left in the buffer. In QuickBASIC, the program starts, and halfway through the scale, if prints "Half finished!" The after the scale completes, it prints "Finished." In QB64 v1.0 and V2.0, the PLAY(0) function is not supported, so the screen printing completes immediately.

I'm a bit surprised Rob never implemented this function.

@Dav Sorry, I thought I had something for you there, but not unless you want to code your app in QuickBASIC.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: How to detect if PLAY "MB" is done playing a song?
« Reply #6 on: October 21, 2021, 08:02:02 pm »
Well thanks anyhow @Pete for the suggestion. I may just go with sound files after all.

- Dav

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: How to detect if PLAY "MB" is done playing a song?
« Reply #7 on: October 21, 2021, 10:25:26 pm »
Well thanks anyhow @Pete for the suggestion. I may just go with sound files after all.
- Dav

Well, you can still get some control with PLAY: https://www.qb64.org/forum/index.php?topic=4323.0
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/