2021-11-10 01:01:34 +00:00
|
|
|
// Copyright (c) Jon Thysell <http://jonthysell.com>
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
2021-12-08 22:35:06 +00:00
|
|
|
/**
|
|
|
|
* @file Sounds.c
|
|
|
|
*
|
|
|
|
* This file provides implementations for Sounds.h.
|
|
|
|
*/
|
|
|
|
|
2021-11-10 01:01:34 +00:00
|
|
|
#include "Sounds.h"
|
|
|
|
|
2021-12-08 22:35:06 +00:00
|
|
|
/** The first snd resource ID. */
|
2021-12-12 23:45:28 +00:00
|
|
|
#define SndBaseResID 8192
|
2021-11-11 23:00:53 +00:00
|
|
|
|
2021-12-08 22:35:06 +00:00
|
|
|
/** The click snd resource ID. */
|
2021-12-16 20:57:00 +00:00
|
|
|
#define ClickSndResID SndBaseResID
|
2021-12-08 22:35:06 +00:00
|
|
|
|
|
|
|
/** The retry snd resource ID. */
|
2021-12-16 20:57:00 +00:00
|
|
|
#define RetrySndResID (ClickSndResID + 1)
|
2021-12-08 22:35:06 +00:00
|
|
|
|
|
|
|
/** The done snd resource ID. */
|
2021-12-16 20:57:00 +00:00
|
|
|
#define DoneSndResID (RetrySndResID + 1)
|
2021-11-10 01:01:34 +00:00
|
|
|
|
2021-12-08 22:35:06 +00:00
|
|
|
/** Whether or not sound is enabled by default. */
|
2021-11-10 01:01:34 +00:00
|
|
|
#define DefaultEnabled true
|
2021-12-08 22:35:06 +00:00
|
|
|
|
|
|
|
/** Whether or not to play sound async. */
|
2021-11-25 01:21:44 +00:00
|
|
|
#define PlaySoundsAsync false
|
2021-11-10 01:01:34 +00:00
|
|
|
|
|
|
|
void Sounds_Init(Sounds *pSounds)
|
|
|
|
{
|
|
|
|
pSounds->Enabled = DefaultEnabled;
|
|
|
|
|
2021-12-01 18:08:07 +00:00
|
|
|
pSounds->ClickSnd = Get1Resource('snd ', ClickSndResID);
|
2021-11-10 01:01:34 +00:00
|
|
|
if (pSounds->ClickSnd == nil)
|
|
|
|
{
|
|
|
|
ShowError("\pClick snd resource missing!", true);
|
|
|
|
}
|
|
|
|
|
2021-12-01 18:08:07 +00:00
|
|
|
pSounds->RetrySnd = Get1Resource('snd ', RetrySndResID);
|
2021-11-10 01:01:34 +00:00
|
|
|
if (pSounds->RetrySnd == nil)
|
|
|
|
{
|
|
|
|
ShowError("\pRetry snd resource missing!", true);
|
|
|
|
}
|
|
|
|
|
2021-12-01 18:08:07 +00:00
|
|
|
pSounds->DoneSnd = Get1Resource('snd ', DoneSndResID);
|
2021-11-10 01:01:34 +00:00
|
|
|
if (pSounds->DoneSnd == nil)
|
|
|
|
{
|
|
|
|
ShowError("\pDone snd resource missing!", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sounds_PlayClickSnd(const Sounds *pSounds)
|
|
|
|
{
|
|
|
|
if (pSounds->Enabled)
|
|
|
|
{
|
2021-11-11 23:00:53 +00:00
|
|
|
HLock(pSounds->ClickSnd);
|
2021-11-25 01:21:44 +00:00
|
|
|
SndPlay(nil, pSounds->ClickSnd, PlaySoundsAsync);
|
2021-11-11 23:00:53 +00:00
|
|
|
HUnlock(pSounds->ClickSnd);
|
2021-11-10 01:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sounds_PlayRetrySnd(const Sounds *pSounds)
|
|
|
|
{
|
|
|
|
if (pSounds->Enabled)
|
|
|
|
{
|
2021-11-11 23:00:53 +00:00
|
|
|
HLock(pSounds->RetrySnd);
|
2021-11-25 01:21:44 +00:00
|
|
|
SndPlay(nil, pSounds->RetrySnd, PlaySoundsAsync);
|
2021-11-11 23:00:53 +00:00
|
|
|
HUnlock(pSounds->RetrySnd);
|
2021-11-10 01:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sounds_PlayDoneSnd(const Sounds *pSounds)
|
|
|
|
{
|
|
|
|
if (pSounds->Enabled)
|
|
|
|
{
|
2021-11-11 23:00:53 +00:00
|
|
|
HLock(pSounds->DoneSnd);
|
2021-11-25 01:21:44 +00:00
|
|
|
SndPlay(nil, pSounds->DoneSnd, PlaySoundsAsync);
|
2021-11-11 23:00:53 +00:00
|
|
|
HUnlock(pSounds->DoneSnd);
|
2021-11-10 01:01:34 +00:00
|
|
|
}
|
|
|
|
}
|