MacLO/src/Sounds.c

82 lines
1.8 KiB
C
Raw Permalink Normal View History

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. */
#define SndBaseResID 8192
2021-11-11 23:00:53 +00:00
2021-12-08 22:35:06 +00:00
/** The click snd resource ID. */
#define ClickSndResID SndBaseResID
2021-12-08 22:35:06 +00:00
/** The retry snd resource ID. */
#define RetrySndResID (ClickSndResID + 1)
2021-12-08 22:35:06 +00:00
/** The done snd resource ID. */
#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. */
#define PlaySoundsAsync false
2021-11-10 01:01:34 +00:00
void Sounds_Init(Sounds *pSounds)
{
pSounds->Enabled = DefaultEnabled;
pSounds->ClickSnd = Get1Resource('snd ', ClickSndResID);
2021-11-10 01:01:34 +00:00
if (pSounds->ClickSnd == nil)
{
ShowError("\pClick snd resource missing!", true);
}
pSounds->RetrySnd = Get1Resource('snd ', RetrySndResID);
2021-11-10 01:01:34 +00:00
if (pSounds->RetrySnd == nil)
{
ShowError("\pRetry snd resource missing!", true);
}
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);
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);
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);
SndPlay(nil, pSounds->DoneSnd, PlaySoundsAsync);
2021-11-11 23:00:53 +00:00
HUnlock(pSounds->DoneSnd);
2021-11-10 01:01:34 +00:00
}
}