BASS_ChannelSetSync

Sets up a synchronizer on a MOD music or file stream channel.

HSYNC WINAPI BASS_ChannelSetSync(
    DWORD handle,
    DWORD type,
    DWORD param,
    SYNCPROC *proc,
    DWORD user
);

Parameters
handleThe channel handle... a HMUSIC or HSTREAM.
typeThe type of sync (see the table below), you may also use these flags.
BASS_SYNC_ONETIMECall the sync only once.
BASS_SYNC_MIXTIMECall the sync function when the sync occurs during mixing, instead of delaying the call until the sync is actually heard.
paramThe sync parameters, depends on the sync type... see the table below.
procThe callback function.
userUser instance data to pass to the callback function.

Sync types, with param and SYNCPROC data definitions.
BASS_SYNC_MUSICPOSSync when a MOD music reaches a position.
param : LOWORD = order (0=first, -1=all), HIWORD = row (0=first, -1=all). data : LOWORD = order, HIWORD = row.
BASS_SYNC_MUSICINSTSync when an instrument (sample for the MOD/S3M/MTM formats) is played in a MOD music (not including retrigs).
param : LOWORD = instrument (1=first), HIWORD = note (0=c0...119=b9, -1=all). data : LOWORD = note, HIWORD = volume (0-64).
BASS_SYNC_ENDSync when a MOD music or file stream reaches the end. Note that some MOD musics never reach the end, they may jump to another position first.
param : not used. data : not used.
BASS_SYNC_MUSICFXSync when the sync effect is used in a MOD music. The sync effect is E8x for the XM/MTM/MOD formats, and S0x for the IT/S3M formats (where x = any value).
param : 0 = the position is passed to the callback (data : LOWORD = order, HIWORD = row), 1 = the value of x is passed to the callback (data : x value).

Return value
If succesful, then the new synchronizer's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code.

Error codes
BASS_ERROR_NOSYNCSynchronizers have been disabled... the BASS_DEVICE_NOSYNC flag was used with BASS_Init.
BASS_ERROR_HANDLEhandle is not a valid channel.
BASS_ERROR_ILLPARAMAn illegal param was specified.
BASS_ERROR_ILLTYPEAn illegal type was specified.

Remarks
Multiple synchronizers may be used per channel. Use BASS_ChannelRemoveSync to remove a synchronizer. If the BASS_SYNC_ONETIME flag is used, then the sync is automatically removed after it's occured (ie. there's no need to remove it manually).

The channel does not have to be playing to set a synchronizer, you can set synchronizers before or while playing. There is only one case where you can not set a synchronizer, and that is from within a callback function. But you can remove synchronizers at any time, including from inside a callback function.

The BASS_SYNC_MIXTIME flag is only really useful for using a sync to switch DSP functions on/off. You could, for example, use a BASS_SYNC_MUSICFX sync to switch a reverb effect on/off on a MOD music.

Example
To do some processing until a MOD music reaches the 10th order.

BOOL order10=FALSE; // the order 10 flag
...
// the sync callback
void CALLBACK MySyncProc(HSYNC handle, DWORD channel, DWORD data, DWORD user) {
    order10=TRUE; // set the order 10 flag
}
...
BASS_ChannelSetSync(a_music, BASS_SYNC_MUSICPOS|BASS_SYNC_ONETIME, MAKELONG(10,0), &MySyncProc, 0); // set the one-time order 10 sync
while (!order10) {
    // order 10 has not arrived, so do some processing
}
// order 10 has arrived!

See also
BASS_ChannelRemoveSync, SYNCPROC callback