How to catch finishing of playing of hsample,hchannel and/or hmusic

Started by sashakozlovskiy,

sashakozlovskiy

Hello everybody. Please,help me how i can catch,when playing of some track via bass library was finished in c++ code. Yes,probably i can get somehow length of hsample,hchannel and/or hmusic in ms,and set timer on it,but may be exists some simpler way to catch this. If no,how i can know length of track in ms and how i can add feature request,to bass developer add this feature. Sdl library,or android mediaplayer class,have this callback,but not bass library. Thanks everybody for any help.

Ian @ un4seen

You can set a BASS_SYNC_END sync via BASS_ChannelSetSync to receive a notification/callback when a BASS channel reaches the end. Please see the BASS_ChannelSetSync documentation for details. Note that syncs can't be set on sample channels, so you will need to use streams instead for this (you can use the BASS_SAMCHAN_STREAM flag with BASS_SampleGetChannel to create a stream from a sample).

sashakozlovskiy

Thank you very much for your reply. 1. Why i can't use callbacks  for hsample directly? 2. When i will create stream using way,as you wrote,should i free handle as hchannel,hsample or as hstream? 3. If my track has looping,whether exists possibility catch starting of n-th playing of track?

sashakozlovskiy

Why do you ignore my latest message? I also have a question,should i remove callback after freeing of hchannel,hsample,hmusic and/or hstream?

Ian @ un4seen

Quote from: sashakozlovskiyWhen i will create stream using way,as you wrote,should i free handle as hchannel,hsample or as hstream?

BASS_SampleGetChannel with the BASS_SAMCHAN_STREAM flag will create a stream, so you should use BASS_StreamFree to free it. You can also use the BASS_STREAM_AUTOFREE flag to have it freed automatically at the end of playback.

Quote from: sashakozlovskiyIf my track has looping,whether exists possibility catch starting of n-th playing of track?

A BASS_SYNC_END sync will be called for each loop. So you could use that to count the loops and stop the stream when it reaches the n'th one. Note a sync for this purpose should have the BASS_SYNC_MIXTIME flag set, so that it's called before looping (not after).

Quote from: sashakozlovskiyshould i remove callback after freeing of hchannel,hsample,hmusic and/or hstream?

Freeing a BASS channel will free all of its resources, so you don't need to seprately free the syncs.

sashakozlovskiy

Thank you very much for your reply. If i will use autofree flag for stream,whether callback will call,and if yes,whether it will be call before freeing of the stream? Can i free stream inside a callback? About looping,i meaned,what before looping it can be pause,so may be exists callback,which allow to know,when pause was finished and nth playing will started. Also in doc i read what this callback can call not only after finishing of track,but after playing of it at nth ms (position).

Ian @ un4seen

Quote from: sashakozlovskiyIf i will use autofree flag for stream,whether callback will call,and if yes,whether it will be call before freeing of the stream?

If the stream is freed at the end of the file then a BASS_SYNC_END sync would be called before it's freed. Note you can also set a BASS_SYNC_FREE sync if you want to know when the stream is freed by any means.

Quote from: sashakozlovskiyCan i free stream inside a callback?

You can free a stream within a normal sync callback, but not a "mixtime" sync callback. Please see the SYNCPROC (and STREAMPROC) documentation for what's unsafe.

Quote from: sashakozlovskiyAbout looping,i meaned,what before looping it can be pause,so may be exists callback,which allow to know,when pause was finished and nth playing will started.

There isn't a sync/callback for starting playback, but if you want to do something upon each playback start then you could simply put that next to the BASS_ChannelPlay/Start calls.

sashakozlovskiy

> You can free a stream within a normal sync callback, but not a "mixtime" sync callback.

Ok,how in this case i can free stream after nth looping,because i should use mix_time flag,to get event after nth playing. If i will try free stream in "mixtime" sync callback,whether exception will be thrown?

sashakozlovskiy

And autofree flag,as i understand,will not work for infinit loop,because we haven't any sence in it,because in this case bass dont know,when we want to stop this playing.

Ian @ un4seen

You cannot call BASS_StreamFree in the mixtime SYNCPROC, but you can call BASS_ChannelStop to end the stream and it will then be freed if the BASS_STREAM_AUTOFREE flag is set. Another option is to remove the BASS_SAMPLE_LOOP flag with BASS_ChannelFlags, instead of calling BASS_ChannelStop.

sashakozlovskiy

Ok,but can i free this stream out of callback,or it will be the same requires,as in callback? How i can delete loop flag for the channel?

Ian @ un4seen

Yes, it is fine to call BASS_StreamFree outside of a mixtime callback. Wouldn't be much point having the function if it couldn't be called anywhere :)

You can remove the BASS_SAMPLE_LOOP flag with BASS_ChannelFlags like this:

BASS_ChannelFlags(handle, 0, BASS_SAMPLE_LOOP);

Please see the BASS_ChannelFlags documentation for details.

sashakozlovskiy

Hello. When i try:
```
BASS_ChannelSetSync(back_channel, BASS_SYNC_ONETIME, BASS_SYNC_END, finishCallback, 0); //for channel,which created from hsample as stream.
BASS_ChannelPlay(back_channel, FALSE);

static void CALLBACK finishCallback(HSYNC handle, DWORD channel, DWORD data, void* user)
{
...
}
```
I get crash of my app. If i set callback after playing,i haven't crash,but it seems,what callback not call. If i set callback without playing,i haven't crash too. Also i have other questions about your library:
1. Some file types not supported hsample,such as xm,mod,mo3,it,mtm,umx. Whether it fix now,and if not,why? Because i want simplefy my code,because for this types we use hmusic,and for others - hsample.
2. May be i can get file path from hsample/hchannel,or i should myself save it,during setting of sound/music?

Chris

QuoteBASS_ChannelSetSync(back_channel, BASS_SYNC_ONETIME, BASS_SYNC_END, finishCallback, 0);
 //for channel,which created from hsample as stream.
hi im not a C++ Coder but that cannot work should be something like this
BASS_ChannelSetSync(back_channel, BASS_SYNC_ONETIME | BASS_SYNC_END, 0, finishCallback, 0); 

https://www.un4seen.com/doc/#bass/BASS_ChannelSetSync.html

sashakozlovskiy

Thank you very much. Now,it seems,all ok. Yes,i mistake,it c,not c++. But according bass doc BASS_SYNC_END should be,as i understand,third param of BASS_ChannelSetSync method. Thank you very much for your help.

Ian @ un4seen

What question? Do you mean the BASS_SYNC_END comment? If so, that needs to be in the 2nd parameter, like Chris posted above.

sashakozlovskiy

1. Yes,it works,but what we should set in third param of BASS_ChannelSetSync func. Because,i thought before,it should be BASS_SYNC_END param. 2. I probably not asked before,but ask now: whether it possible get path to file,if i know hsample or hchannel. 3. if i call bass_channel_free,should i call bass_sample_free,if i create hchannel from hsample?

Ian @ un4seen

Quote from: sashakozlovskiy1. Yes,it works,but what we should set in third param of BASS_ChannelSetSync func. Because,i thought before,it should be BASS_SYNC_END param.

The sync type (eg. BASS_SYNC_END) goes in the 2nd parameter. The 3rd parameter ("param") depends on the sync type, as described in the BASS_ChannelSetSync documentation. Please note that it is "not used" in the case of BASS_SYNC_END syncs.

Quote from: sashakozlovskiy2. I probably not asked before,but ask now: whether it possible get path to file,if i know hsample or hchannel.

You can get the filename of a stream (HSTREAM) from BASS_ChannelGetInfo, but not of a sample (HSAMPLE/HCHANNEL) currently. If you need the filename of a sample then you could retain a copy of the filename that you used in the BASS_SampleLoad call.

Quote from: sashakozlovskiy3. if i call bass_channel_free,should i call bass_sample_free,if i create hchannel from hsample?

If you want to free a HCHANNEL then you should only call BASS_ChannelFree, not BASS_SampleFree. BASS_SampleFree will free a sample (HSAMPLE) and all of its channels.

sashakozlovskiy

1. If i created channel from hsample,and want to free sound,it enough call bass_channelFree (or bass_musicFree or bass_streamFree) and i shouldn't call bass_sampleFree?
2. So,i can't get direct file path even from hstream channel? Why features of hsample so limited? Why we can't set callbacks to it,but should create stream for this,get file name from channels,created from hsample,etc. Why we can't get direct file path,which we set for specific channel? How i can create feature request for bass library,to have support of this features?