45 |
45 |
46 // MUSIC |
46 // MUSIC |
47 |
47 |
48 // Obvious music commands for music track |
48 // Obvious music commands for music track |
49 procedure SetMusic(enabled: boolean); // Enable/disable music. |
49 procedure SetMusic(enabled: boolean); // Enable/disable music. |
50 procedure SetMusic(musicname: shortstring); // Enable/disable music and set name of musicfile to play. |
50 procedure SetMusicName(musicname: shortstring); // Enable/disable music and set name of musicfile to play. |
51 procedure PlayMusic; // Play music from the start. |
51 procedure PlayMusic; // Play music from the start. |
52 procedure PauseMusic; // Pause music. |
52 procedure PauseMusic; // Pause music. |
53 procedure ResumeMusic; // Resume music from pause point. |
53 procedure ResumeMusic; // Resume music from pause point. |
54 procedure ChangeMusic(musicname: shortstring); // Replaces music track with musicname and plays it. |
54 procedure ChangeMusic(musicname: shortstring); // Replaces music track with musicname and plays it. |
55 procedure StopMusic; // Stops and releases the current track. |
55 procedure StopMusic; // Stops and releases the current track. |
60 // Plays the sound snd [from a given voicepack], |
60 // Plays the sound snd [from a given voicepack], |
61 // if keepPlaying is given and true, |
61 // if keepPlaying is given and true, |
62 // then the sound's playback won't be interrupted if asked to play again. |
62 // then the sound's playback won't be interrupted if asked to play again. |
63 procedure PlaySound(snd: TSound); |
63 procedure PlaySound(snd: TSound); |
64 procedure PlaySound(snd: TSound; keepPlaying: boolean); |
64 procedure PlaySound(snd: TSound; keepPlaying: boolean); |
65 procedure PlaySound(snd: TSound; voicepack: PVoicepack); |
65 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack); |
66 procedure PlaySound(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean); |
66 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean); |
67 |
67 |
68 // Plays sound snd [of voicepack] in a loop, but starts with fadems milliseconds of fade-in. |
68 // Plays sound snd [of voicepack] in a loop, but starts with fadems milliseconds of fade-in. |
69 // Returns sound channel of the looped sound. |
69 // Returns sound channel of the looped sound. |
70 function LoopSound(snd: TSound): LongInt; |
70 function LoopSound(snd: TSound): LongInt; |
71 function LoopSound(snd: TSound; fadems: LongInt): LongInt; |
71 function LoopSound(snd: TSound; fadems: LongInt): LongInt; |
72 function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt; // WTF? |
72 function LoopSoundV(snd: TSound; voicepack: PVoicepack): LongInt; // WTF? |
73 function LoopSound(snd: TSound; voicepack: PVoicepack; fadems: LongInt): LongInt; |
73 function LoopSoundV(snd: TSound; voicepack: PVoicepack; fadems: LongInt): LongInt; |
74 |
74 |
75 // Stops the normal/looped sound of the given type/in the given channel |
75 // Stops the normal/looped sound of the given type/in the given channel |
76 // [with a fade-out effect for fadems milliseconds]. |
76 // [with a fade-out effect for fadems milliseconds]. |
77 procedure StopSound(snd: TSound); |
77 procedure StopSound(snd: TSound); |
78 procedure StopSound(chn: LongInt); |
78 procedure StopSoundChan(chn: LongInt); |
79 procedure StopSound(chn, fadems: LongInt); |
79 procedure StopSoundChan(chn, fadems: LongInt); |
80 |
80 |
81 procedure AddVoice(snd: TSound; voicepack: PVoicepack); |
81 procedure AddVoice(snd: TSound; voicepack: PVoicepack); |
82 procedure PlayNextVoice; |
82 procedure PlayNextVoice; |
83 |
83 |
84 |
84 |
231 end; |
231 end; |
232 end; |
232 end; |
233 |
233 |
234 procedure PlaySound(snd: TSound); |
234 procedure PlaySound(snd: TSound); |
235 begin |
235 begin |
236 PlaySound(snd, nil, false); |
236 PlaySoundV(snd, nil, false); |
237 end; |
237 end; |
238 |
238 |
239 procedure PlaySound(snd: TSound; keepPlaying: boolean); |
239 procedure PlaySound(snd: TSound; keepPlaying: boolean); |
240 begin |
240 begin |
241 PlaySound(snd, nil, keepPlaying); |
241 PlaySoundV(snd, nil, keepPlaying); |
242 end; |
242 end; |
243 |
243 |
244 procedure PlaySound(snd: TSound; voicepack: PVoicepack); |
244 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack); |
245 begin |
245 begin |
246 PlaySound(snd, voicepack, false); |
246 PlaySoundV(snd, voicepack, false); |
247 end; |
247 end; |
248 |
248 |
249 procedure PlaySound(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean); |
249 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean); |
250 var s:shortstring; |
250 var s:shortstring; |
251 begin |
251 begin |
252 if (not isSoundEnabled) or fastUntilLag then |
252 if (not isSoundEnabled) or fastUntilLag then |
253 exit; |
253 exit; |
254 |
254 |
323 if (VoiceList[i].snd <> sndNone) then |
323 if (VoiceList[i].snd <> sndNone) then |
324 begin |
324 begin |
325 LastVoice.snd:= VoiceList[i].snd; |
325 LastVoice.snd:= VoiceList[i].snd; |
326 LastVoice.voicepack:= VoiceList[i].voicepack; |
326 LastVoice.voicepack:= VoiceList[i].voicepack; |
327 VoiceList[i].snd:= sndNone; |
327 VoiceList[i].snd:= sndNone; |
328 PlaySound(LastVoice.snd, LastVoice.voicepack) |
328 PlaySoundV(LastVoice.snd, LastVoice.voicepack) |
329 end |
329 end |
330 else LastVoice.snd:= sndNone; |
330 else LastVoice.snd:= sndNone; |
331 end; |
331 end; |
332 |
332 |
333 function LoopSound(snd: TSound): LongInt; |
333 function LoopSound(snd: TSound): LongInt; |
334 begin |
334 begin |
335 LoopSound:= LoopSound(snd, nil) |
335 LoopSound:= LoopSoundV(snd, nil) |
336 end; |
336 end; |
337 |
337 |
338 function LoopSound(snd: TSound; fadems: LongInt): LongInt; |
338 function LoopSound(snd: TSound; fadems: LongInt): LongInt; |
339 begin |
339 begin |
340 LoopSound:= LoopSound(snd, nil, fadems) |
340 LoopSound:= LoopSoundV(snd, nil, fadems) |
341 end; |
341 end; |
342 |
342 |
343 function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt; |
343 function LoopSoundV(snd: TSound; voicepack: PVoicepack): LongInt; |
344 begin |
344 begin |
345 voicepack:= voicepack; // avoid compiler hint |
345 voicepack:= voicepack; // avoid compiler hint |
346 LoopSound:= LoopSound(snd, nil, 0) |
346 LoopSoundV:= LoopSoundV(snd, nil, 0) |
347 end; |
347 end; |
348 |
348 |
349 function LoopSound(snd: TSound; voicepack: PVoicepack; fadems: LongInt): LongInt; |
349 function LoopSoundV(snd: TSound; voicepack: PVoicepack; fadems: LongInt): LongInt; |
350 var s: shortstring; |
350 var s: shortstring; |
351 begin |
351 begin |
352 if (not isSoundEnabled) or fastUntilLag then |
352 if (not isSoundEnabled) or fastUntilLag then |
353 begin |
353 begin |
354 LoopSound:= -1; |
354 LoopSoundV:= -1; |
355 exit |
355 exit |
356 end; |
356 end; |
357 |
357 |
358 if (voicepack <> nil) then |
358 if (voicepack <> nil) then |
359 begin |
359 begin |
367 if voicepack^.chunks[snd] = nil then |
367 if voicepack^.chunks[snd] = nil then |
368 WriteLnToConsole(msgFailed) |
368 WriteLnToConsole(msgFailed) |
369 else |
369 else |
370 WriteLnToConsole(msgOK) |
370 WriteLnToConsole(msgOK) |
371 end; |
371 end; |
372 LoopSound:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1) |
372 LoopSoundV:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1) |
373 end |
373 end |
374 else |
374 else |
375 begin |
375 begin |
376 if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then |
376 if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then |
377 begin |
377 begin |
382 defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
382 defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
383 SDLTry(defVoicepack^.chunks[snd] <> nil, true); |
383 SDLTry(defVoicepack^.chunks[snd] <> nil, true); |
384 WriteLnToConsole(msgOK); |
384 WriteLnToConsole(msgOK); |
385 end; |
385 end; |
386 if fadems > 0 then |
386 if fadems > 0 then |
387 LoopSound:= Mix_FadeInChannelTimed(-1, defVoicepack^.chunks[snd], -1, fadems, -1) |
387 LoopSoundV:= Mix_FadeInChannelTimed(-1, defVoicepack^.chunks[snd], -1, fadems, -1) |
388 else |
388 else |
389 LoopSound:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1); |
389 LoopSoundV:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1); |
390 end; |
390 end; |
391 end; |
391 end; |
392 |
392 |
393 procedure StopSound(snd: TSound); |
393 procedure StopSound(snd: TSound); |
394 begin |
394 begin |
400 Mix_HaltChannel(lastChan[snd]); |
400 Mix_HaltChannel(lastChan[snd]); |
401 lastChan[snd]:= -1; |
401 lastChan[snd]:= -1; |
402 end; |
402 end; |
403 end; |
403 end; |
404 |
404 |
405 procedure StopSound(chn: LongInt); |
405 procedure StopSoundChan(chn: LongInt); |
406 begin |
406 begin |
407 if not isSoundEnabled then |
407 if not isSoundEnabled then |
408 exit; |
408 exit; |
409 |
409 |
410 if (chn <> -1) and (Mix_Playing(chn) <> 0) then |
410 if (chn <> -1) and (Mix_Playing(chn) <> 0) then |
411 Mix_HaltChannel(chn); |
411 Mix_HaltChannel(chn); |
412 end; |
412 end; |
413 |
413 |
414 procedure StopSound(chn, fadems: LongInt); |
414 procedure StopSoundChan(chn, fadems: LongInt); |
415 begin |
415 begin |
416 if not isSoundEnabled then |
416 if not isSoundEnabled then |
417 exit; |
417 exit; |
418 |
418 |
419 if (chn <> -1) and (Mix_Playing(chn) <> 0) then |
419 if (chn <> -1) and (Mix_Playing(chn) <> 0) then |