Originally Posted by
Alucard
One guy
requested MIDI fadeout script and got an unpleasant response: tampering with MIDI playback on the fly is not possible in ZC at all, sans start/stop in abrupt manner. Perharps something like Game->SetMIDIVolume or similar function may resolve this audio-related issue.
I added Audio->Volume[4], and Audio->PanStyle. Both work, but I advise being considerate when using them.
Always store the user settings before; and restore the user volume after, you use them for effects:
Code:
int oldaudio = FadeMidi(120, 4);
//FadeOut
int FadeMIDI(int time, int ticks_per_decrement)
{
int oldvol = Volume[VOL_MIDI]; //Store the ore-fade setting.
for ( int q = 0; q < fade ; ++q )
{
if ( !(q%ticks_per_decrement) ) --(Audio->Volume[VOL_MIDI]);
if ( Audio->Volume[VOL_MIDI] < 1 ) return oldvol;
//Do not waste frames if we reach 0!
Waitframe();
}
return oldvol;
}
//FadeIn to the old volume
void FadeMIDI(int time, int ticks_per_decrement, int oldsetting)
{
int oldvol = Volume[VOL_MIDI]; //Store the ore-fade setting.
int q;
while( Audio->Volume[VOL_MIDI] < oldsetting )
{
if ( !(q%ticks_per_decrement) ) ++(Audio->Volume[VOL_MIDI]);
++q;
Waitframe();
}
}