Add beep sound to platforms with no beep

This commit is contained in:
elasota
2021-05-09 23:45:27 -04:00
parent d54ad576bc
commit 24169507bd
21 changed files with 85 additions and 25 deletions

View File

@@ -232,9 +232,10 @@ uint64_t GpSystemServices_Win32::GetFreeMemoryCosmetic() const
return memStatus.ullAvailPhys; return memStatus.ullAvailPhys;
} }
void GpSystemServices_Win32::Beep() const bool GpSystemServices_Win32::Beep() const
{ {
MessageBeep(MB_OK); MessageBeep(MB_OK);
return true;
} }
bool GpSystemServices_Win32::IsTouchscreen() const bool GpSystemServices_Win32::IsTouchscreen() const
@@ -264,7 +265,7 @@ bool GpSystemServices_Win32::IsFullscreenOnStartup() const
bool GpSystemServices_Win32::HasNativeFileManager() const bool GpSystemServices_Win32::HasNativeFileManager() const
{ {
return false; return true;
} }
unsigned int GpSystemServices_Win32::GetCPUCount() const unsigned int GpSystemServices_Win32::GetCPUCount() const

View File

@@ -28,7 +28,7 @@ public:
void *CreateThread(ThreadFunc_t threadFunc, void *context) override; void *CreateThread(ThreadFunc_t threadFunc, void *context) override;
IGpThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) override; IGpThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) override;
uint64_t GetFreeMemoryCosmetic() const override; uint64_t GetFreeMemoryCosmetic() const override;
void Beep() const override; bool Beep() const override;
bool IsTouchscreen() const override; bool IsTouchscreen() const override;
bool IsUsingMouseAsTouch() const override; bool IsUsingMouseAsTouch() const override;
bool IsTextInputObstructive() const override; bool IsTextInputObstructive() const override;

View File

@@ -55,8 +55,9 @@ void *GpSystemServices_Android::CreateThread(ThreadFunc_t threadFunc, void *cont
return thread; return thread;
} }
void GpSystemServices_Android::Beep() const bool GpSystemServices_Android::Beep() const
{ {
return false;
} }
bool GpSystemServices_Android::IsTouchscreen() const bool GpSystemServices_Android::IsTouchscreen() const
@@ -84,6 +85,11 @@ bool GpSystemServices_Android::IsFullscreenOnStartup() const
return true; return true;
} }
bool GpSystemServices_Android::HasNativeFileManager() const
{
return false;
}
unsigned int GpSystemServices_Android::GetCPUCount() const unsigned int GpSystemServices_Android::GetCPUCount() const
{ {
return SDL_GetCPUCount(); return SDL_GetCPUCount();

View File

@@ -9,12 +9,13 @@ public:
GpSystemServices_Android(); GpSystemServices_Android();
void *CreateThread(ThreadFunc_t threadFunc, void *context) override; void *CreateThread(ThreadFunc_t threadFunc, void *context) override;
void Beep() const override; bool Beep() const override;
bool IsTouchscreen() const override; bool IsTouchscreen() const override;
bool IsUsingMouseAsTouch() const override; bool IsUsingMouseAsTouch() const override;
bool IsTextInputObstructive() const override; bool IsTextInputObstructive() const override;
bool IsFullscreenPreferred() const override; bool IsFullscreenPreferred() const override;
bool IsFullscreenOnStartup() const override; bool IsFullscreenOnStartup() const override;
bool HasNativeFileManager() const override;
unsigned int GetCPUCount() const override; unsigned int GetCPUCount() const override;
void SetTextInputEnabled(bool isEnabled) override; void SetTextInputEnabled(bool isEnabled) override;
bool IsTextInputEnabled() const override; bool IsTextInputEnabled() const override;

View File

@@ -136,8 +136,9 @@ void *GpSystemServices_Web::CreateThread(ThreadFunc_t threadFunc, void *context)
return nullptr; return nullptr;
} }
void GpSystemServices_Web::Beep() const bool GpSystemServices_Web::Beep() const
{ {
return false;
} }
bool GpSystemServices_Web::IsTouchscreen() const bool GpSystemServices_Web::IsTouchscreen() const
@@ -165,6 +166,11 @@ bool GpSystemServices_Web::IsFullscreenOnStartup() const
return false; return false;
} }
bool GpSystemServices_Web::HasNativeFileManager() const
{
return false;
}
unsigned int GpSystemServices_Web::GetCPUCount() const unsigned int GpSystemServices_Web::GetCPUCount() const
{ {
return SDL_GetCPUCount(); return SDL_GetCPUCount();

View File

@@ -12,12 +12,13 @@ public:
~GpSystemServices_Web(); ~GpSystemServices_Web();
void *CreateThread(ThreadFunc_t threadFunc, void *context) override; void *CreateThread(ThreadFunc_t threadFunc, void *context) override;
void Beep() const override; bool Beep() const override;
bool IsTouchscreen() const override; bool IsTouchscreen() const override;
bool IsUsingMouseAsTouch() const override; bool IsUsingMouseAsTouch() const override;
bool IsTextInputObstructive() const override; bool IsTextInputObstructive() const override;
bool IsFullscreenPreferred() const override; bool IsFullscreenPreferred() const override;
bool IsFullscreenOnStartup() const override; bool IsFullscreenOnStartup() const override;
bool HasNativeFileManager() const override;
unsigned int GetCPUCount() const override; unsigned int GetCPUCount() const override;
void SetTextInputEnabled(bool isEnabled) override; void SetTextInputEnabled(bool isEnabled) override;
bool IsTextInputEnabled() const override; bool IsTextInputEnabled() const override;

View File

@@ -64,8 +64,9 @@ void *GpSystemServices_X::CreateThread(ThreadFunc_t threadFunc, void *context)
return thread; return thread;
} }
void GpSystemServices_X::Beep() const bool GpSystemServices_X::Beep() const
{ {
return false;
} }
bool GpSystemServices_X::IsTouchscreen() const bool GpSystemServices_X::IsTouchscreen() const
@@ -93,6 +94,11 @@ bool GpSystemServices_X::IsFullscreenOnStartup() const
return false; return false;
} }
bool GpSystemServices_X::HasNativeFileManager() const
{
return true;
}
unsigned int GpSystemServices_X::GetCPUCount() const unsigned int GpSystemServices_X::GetCPUCount() const
{ {
return SDL_GetCPUCount(); return SDL_GetCPUCount();

View File

@@ -12,12 +12,13 @@ public:
~GpSystemServices_X(); ~GpSystemServices_X();
void *CreateThread(ThreadFunc_t threadFunc, void *context) override; void *CreateThread(ThreadFunc_t threadFunc, void *context) override;
void Beep() const override; bool Beep() const override;
bool IsTouchscreen() const override; bool IsTouchscreen() const override;
bool IsUsingMouseAsTouch() const override; bool IsUsingMouseAsTouch() const override;
bool IsTextInputObstructive() const override; bool IsTextInputObstructive() const override;
bool IsFullscreenPreferred() const override; bool IsFullscreenPreferred() const override;
bool IsFullscreenOnStartup() const override; bool IsFullscreenOnStartup() const override;
bool HasNativeFileManager() const override;
unsigned int GetCPUCount() const override; unsigned int GetCPUCount() const override;
void SetTextInputEnabled(bool isEnabled) override; void SetTextInputEnabled(bool isEnabled) override;
bool IsTextInputEnabled() const override; bool IsTextInputEnabled() const override;

View File

@@ -4,7 +4,7 @@
{ {
"name" : "Okay", "name" : "Okay",
"itemType" : "Button", "itemType" : "Button",
"pos" : [ 438, 292 ], "pos" : [ 438, 316 ],
"size" : [ 58, 20 ], "size" : [ 58, 20 ],
"id" : 1, "id" : 1,
"enabled" : true "enabled" : true
@@ -12,7 +12,7 @@
{ {
"name" : "Export Source Code to ZIP Archive...", "name" : "Export Source Code to ZIP Archive...",
"itemType" : "Button", "itemType" : "Button",
"pos" : [ 205, 292 ], "pos" : [ 205, 316 ],
"size" : [ 226, 20 ], "size" : [ 226, 20 ],
"id" : 1, "id" : 1,
"enabled" : false "enabled" : false
@@ -176,6 +176,14 @@
"size" : [ 66, 20 ], "size" : [ 66, 20 ],
"id" : 1, "id" : 1,
"enabled" : true "enabled" : true
},
{
"name" : "Ping sound original: Darrelle Jed Montojo (\"LittleRainySeasons\")",
"itemType" : "Label",
"pos" : [ 16, 277 ],
"size" : [ 406, 20 ],
"id" : 1,
"enabled" : true
} }
] ]
} }

Binary file not shown.

View File

@@ -39,7 +39,8 @@
"LICS/1004.txt" : "ApplicationResourcePatches/LICS/1004.txt", "LICS/1004.txt" : "ApplicationResourcePatches/LICS/1004.txt",
"LICS/1005.txt" : "ApplicationResourcePatches/LICS/1005.txt", "LICS/1005.txt" : "ApplicationResourcePatches/LICS/1005.txt",
"LICS/1006.txt" : "ApplicationResourcePatches/LICS/1006.txt", "LICS/1006.txt" : "ApplicationResourcePatches/LICS/1006.txt",
"STR$23/1006.txt" : "ApplicationResourcePatches/STR/1006.txt" "STR$23/1006.txt" : "ApplicationResourcePatches/STR/1006.txt",
"snd$20/1063.wav" : "ApplicationResourcePatches/SND/1063.wav"
}, },
"delete" : "delete" :
[ [

View File

@@ -56,7 +56,6 @@ add_library(PortabilityLayer STATIC
PortabilityLayer/MemoryManager.cpp PortabilityLayer/MemoryManager.cpp
PortabilityLayer/MemReaderStream.cpp PortabilityLayer/MemReaderStream.cpp
PortabilityLayer/MenuManager.cpp PortabilityLayer/MenuManager.cpp
PortabilityLayer/MMBlock.cpp
PortabilityLayer/MMHandleBlock.cpp PortabilityLayer/MMHandleBlock.cpp
PortabilityLayer/PLApplication.cpp PortabilityLayer/PLApplication.cpp
PortabilityLayer/PLButtonWidget.cpp PortabilityLayer/PLButtonWidget.cpp

View File

@@ -249,7 +249,7 @@ void DoAboutOpenSource(void)
static const int kAboutOpenSourceDialogTemplateID = 2005; static const int kAboutOpenSourceDialogTemplateID = 2005;
const Rect windowRect = Rect::Create(0, 0, 324, 512); const Rect windowRect = Rect::Create(0, 0, 348, 512);
PortabilityLayer::WindowDef wdef = PortabilityLayer::WindowDef::Create(windowRect, PortabilityLayer::WindowStyleFlags::kAlert, true, 0, 0, PSTR("")); PortabilityLayer::WindowDef wdef = PortabilityLayer::WindowDef::Create(windowRect, PortabilityLayer::WindowStyleFlags::kAlert, true, 0, 0, PSTR(""));

View File

@@ -115,7 +115,8 @@
#define kTransInSound 60 // <20><> <20><> #define kTransInSound 60 // <20><> <20><>
#define kBonusSound 61 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> #define kBonusSound 61 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define kHissSound 62 // #define kHissSound 62 //
#define kTriggerSound 63 #define kPingSound 63 //
#define kTriggerSound 64 // This must be the last one
#define kHitWallPriority 100 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> #define kHitWallPriority 100 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define kScoreTikPriority 101 // <20><> #define kScoreTikPriority 101 // <20><>
@@ -177,6 +178,7 @@
#define kFollowPriority 904 #define kFollowPriority 904
#define kTransInPriority 905 #define kTransInPriority 905
#define kTransOutPriority 906 #define kTransOutPriority 906
#define kPingPriority 907
#define kTriggerPriority 999 #define kTriggerPriority 999
#define kArrowCursor 0 #define kArrowCursor 0

View File

@@ -23,7 +23,7 @@
#define kBaseBufferSoundID 1000 #define kBaseBufferSoundID 1000
#define kMaxSounds 64 #define kMaxSounds 65
void CallBack0 (PortabilityLayer::AudioChannel *); void CallBack0 (PortabilityLayer::AudioChannel *);
@@ -38,7 +38,7 @@ IGpAudioBuffer *ParseAndConvertSound(const THandle<void> &handle);
PortabilityLayer::AudioChannel *channel0, *channel1, *channel2; PortabilityLayer::AudioChannel *channel0, *channel1, *channel2;
IGpAudioBuffer *theSoundData[kMaxSounds]; IGpAudioBuffer *theSoundData[kMaxSounds];
short numSoundsLoaded; short numSoundsLoaded;
Boolean soundLoaded[kMaxSounds], dontLoadSounds; Boolean dontLoadSounds;
Boolean channelOpen, isSoundOn, failedSound; Boolean channelOpen, isSoundOn, failedSound;
//============================================================== Functions //============================================================== Functions
@@ -341,6 +341,14 @@ void CloseSoundChannels (void)
channelOpen = false; channelOpen = false;
} }
//-------------------------------------------------------------- PingBeep
void PingBeep (int duration)
{
PlayPrioritySound(kPingSound, kPingPriority);
}
//-------------------------------------------------------------- InitSound //-------------------------------------------------------------- InitSound
void InitSound (void) void InitSound (void)
@@ -376,6 +384,8 @@ void InitSound (void)
failedSound = true; failedSound = true;
} }
} }
SetBeepFunction (PingBeep);
} }
//-------------------------------------------------------------- KillSound //-------------------------------------------------------------- KillSound

View File

@@ -26,7 +26,7 @@ public:
virtual void *CreateThread(ThreadFunc_t threadFunc, void *context) = 0; virtual void *CreateThread(ThreadFunc_t threadFunc, void *context) = 0;
virtual IGpThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) = 0; virtual IGpThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) = 0;
virtual uint64_t GetFreeMemoryCosmetic() const = 0; // Returns free memory in bytes, does not have to be accurate virtual uint64_t GetFreeMemoryCosmetic() const = 0; // Returns free memory in bytes, does not have to be accurate
virtual void Beep() const = 0; virtual bool Beep() const = 0;
virtual bool IsTouchscreen() const = 0; virtual bool IsTouchscreen() const = 0;
virtual bool IsUsingMouseAsTouch() const = 0; virtual bool IsUsingMouseAsTouch() const = 0;
virtual bool IsFullscreenPreferred() const = 0; virtual bool IsFullscreenPreferred() const = 0;

View File

@@ -13,6 +13,7 @@
#include "WindowDef.h" #include "WindowDef.h"
#include "WindowManager.h" #include "WindowManager.h"
#include "PLApplication.h"
#include "PLArrayView.h" #include "PLArrayView.h"
#include "PLBigEndian.h" #include "PLBigEndian.h"
#include "PLButtonWidget.h" #include "PLButtonWidget.h"
@@ -471,7 +472,7 @@ namespace PortabilityLayer
Rect2i windowFullRect = WindowManager::GetInstance()->GetWindowFullRect(window); Rect2i windowFullRect = WindowManager::GetInstance()->GetWindowFullRect(window);
if (!windowFullRect.Contains(Vec2i(mouseEvent.m_x, mouseEvent.m_y))) if (!windowFullRect.Contains(Vec2i(mouseEvent.m_x, mouseEvent.m_y)))
{ {
PLDrivers::GetSystemServices()->Beep(); SysBeep(1);
continue; continue;
} }
} }
@@ -834,7 +835,7 @@ namespace PortabilityLayer
// If sound index is 0, play no sound // If sound index is 0, play no sound
if (soundIndexes[0] != 0) if (soundIndexes[0] != 0)
PLDrivers::GetSystemServices()->Beep(); SysBeep(1);
const Rect dialogRect = alertResData.m_rect.ToRect(); const Rect dialogRect = alertResData.m_rect.ToRect();

View File

@@ -21,6 +21,7 @@
#include "WindowDef.h" #include "WindowDef.h"
#include "MacRomanConversion.h" #include "MacRomanConversion.h"
#include "PLApplication.h"
#include "PLArrayView.h" #include "PLArrayView.h"
#include "PLControlDefinitions.h" #include "PLControlDefinitions.h"
#include "PLCore.h" #include "PLCore.h"
@@ -756,7 +757,7 @@ namespace PortabilityLayer
PLPasStr nameStr = editBox->GetString(); PLPasStr nameStr = editBox->GetString();
if (nameStr.Length() == 0 || !fs->ValidateFilePath(nameStr.Chars(), nameStr.Length())) if (nameStr.Length() == 0 || !fs->ValidateFilePath(nameStr.Chars(), nameStr.Length()))
{ {
PLDrivers::GetSystemServices()->Beep(); SysBeep(1);
FileBrowserUIImpl::PopUpAlert(Rect::Create(0, 0, 135, 327), kFileBrowserUIBadNameDialogTemplateID, nullptr); FileBrowserUIImpl::PopUpAlert(Rect::Create(0, 0, 135, 327), kFileBrowserUIBadNameDialogTemplateID, nullptr);
hit = -1; hit = -1;
} }
@@ -772,7 +773,7 @@ namespace PortabilityLayer
{ {
DialogTextSubstitutions substitutions(nameStr); DialogTextSubstitutions substitutions(nameStr);
PLDrivers::GetSystemServices()->Beep(); SysBeep(1);
int16_t subHit = FileBrowserUIImpl::PopUpAlert(Rect::Create(0, 0, 135, 327), kFileBrowserUIOverwriteDialogTemplateID, &substitutions); int16_t subHit = FileBrowserUIImpl::PopUpAlert(Rect::Create(0, 0, 135, 327), kFileBrowserUIOverwriteDialogTemplateID, &substitutions);
if (subHit == kOverwriteNoButton) if (subHit == kOverwriteNoButton)
@@ -783,7 +784,7 @@ namespace PortabilityLayer
if ((mode == Mode_Open && hit == kOpenDeleteButton) || (mode == Mode_SaveWithDelete && hit == kSaveDeleteButton)) if ((mode == Mode_Open && hit == kOpenDeleteButton) || (mode == Mode_SaveWithDelete && hit == kSaveDeleteButton))
{ {
PLDrivers::GetSystemServices()->Beep(); SysBeep(1);
int16_t subHit = FileBrowserUIImpl::PopUpAlert(Rect::Create(0, 0, 135, 327), kFileBrowserUIDeleteDialogTemplateID, &substitutions); int16_t subHit = FileBrowserUIImpl::PopUpAlert(Rect::Create(0, 0, 135, 327), kFileBrowserUIDeleteDialogTemplateID, &substitutions);
if (subHit == kOverwriteYesButton) if (subHit == kOverwriteYesButton)

View File

@@ -18,9 +18,18 @@ namespace PortabilityLayer
memcpy(dest + 1, src, sz); memcpy(dest + 1, src, sz);
} }
} }
static BeepFunction_t gs_beepFunction = nullptr;
} }
void SysBeep(int duration) void SysBeep(int duration)
{ {
PLDrivers::GetSystemServices()->Beep(); if (!PLDrivers::GetSystemServices()->Beep())
if (PortabilityLayer::gs_beepFunction != nullptr)
PortabilityLayer::gs_beepFunction(duration);
}
void SetBeepFunction(BeepFunction_t beepFunction)
{
PortabilityLayer::gs_beepFunction = beepFunction;
} }

View File

@@ -25,6 +25,10 @@ void PasStringCopy(const PortabilityLayer::PascalStrLiteral<TSize> &src, unsigne
void SysBeep(int duration); void SysBeep(int duration);
typedef void (*BeepFunction_t)(int duration);
void SetBeepFunction(BeepFunction_t beepFunction);
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#include "PascalStrLiteral.h" #include "PascalStrLiteral.h"

View File

@@ -180,6 +180,9 @@ namespace PortabilityLayer
bool AudioChannelImpl::AddBuffer(IGpAudioBuffer *buffer, bool blocking) bool AudioChannelImpl::AddBuffer(IGpAudioBuffer *buffer, bool blocking)
{ {
if (!buffer)
return false;
buffer->AddRef(); buffer->AddRef();
AudioCommand cmd; AudioCommand cmd;