Skip to content

Commit f816c97

Browse files
committed
[[ Cocoa ]] Refactored audio clip to use MCPlatformSound API (to be implemented).
[[ Cocoa ]] Changed beep over to use NSBeep() (beep properties not supported). [[ Cocoa ]] Changed system volume setting and getting to use AudioToolbox.
1 parent 5b4a20e commit f816c97

15 files changed

Lines changed: 353 additions & 32 deletions

engine/engine.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@
336336
4D8BED4811B95A1000DED42A /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D8BED0111B959F500DED42A /* Security.framework */; };
337337
4D982B1213C1CDC10066119A /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D982B1113C1CDC10066119A /* CoreServices.framework */; };
338338
4D982B1913C1CDD20066119A /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D982B1813C1CDD20066119A /* ApplicationServices.framework */; };
339+
4DA028F618F54B5D000CFCF8 /* mac-sound.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4DA028F518F54B5D000CFCF8 /* mac-sound.mm */; };
340+
4DA028F818F550E1000CFCF8 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DA028F718F550E1000CFCF8 /* AudioToolbox.framework */; };
339341
4DAB7D280FF3A0100009F91E /* md5.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DAB7D270FF3A0100009F91E /* md5.cpp */; };
340342
4DADCD5B12392EAF003CD17C /* sha1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DADCD5912392EAF003CD17C /* sha1.cpp */; };
341343
4DADCDFD12393F55003CD17C /* Installer.icns in Resources */ = {isa = PBXBuildFile; fileRef = 4DADCDFC12393F26003CD17C /* Installer.icns */; };
@@ -1321,6 +1323,8 @@
13211323
4D982BF513C2E8360066119A /* srvmain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = srvmain.h; path = src/srvmain.h; sourceTree = "<group>"; };
13221324
4D982FE113C5D59D0066119A /* executionerrors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = executionerrors.h; path = src/executionerrors.h; sourceTree = "<group>"; };
13231325
4D982FE213C5D5AE0066119A /* parseerrors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = parseerrors.h; path = src/parseerrors.h; sourceTree = "<group>"; };
1326+
4DA028F518F54B5D000CFCF8 /* mac-sound.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = "mac-sound.mm"; path = "src/mac-sound.mm"; sourceTree = "<group>"; };
1327+
4DA028F718F550E1000CFCF8 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
13241328
4DA0BEB715AB6046006C0677 /* mblandroidjava.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = mblandroidjava.cpp; path = src/mblandroidjava.cpp; sourceTree = "<group>"; };
13251329
4DA0BEB815AB6046006C0677 /* mblandroidjava.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = mblandroidjava.h; path = src/mblandroidjava.h; sourceTree = "<group>"; };
13261330
4DAB7B350FE120060009F91E /* bitmapeffect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bitmapeffect.cpp; path = src/bitmapeffect.cpp; sourceTree = "<group>"; };
@@ -1631,6 +1635,7 @@
16311635
4D8B47990BE7B3240046CD2F /* Cocoa.framework in Frameworks */,
16321636
4D00C6290CE1F27300341AD3 /* SystemConfiguration.framework in Frameworks */,
16331637
4D8BED0211B959F500DED42A /* Security.framework in Frameworks */,
1638+
4DA028F818F550E1000CFCF8 /* AudioToolbox.framework in Frameworks */,
16341639
4D221A73171D577E00E7E557 /* libcrypto.dylib in Frameworks */,
16351640
4D221A74171D577E00E7E557 /* libcups.dylib in Frameworks */,
16361641
4D221A75171D577E00E7E557 /* libcurl.dylib in Frameworks */,
@@ -1976,6 +1981,7 @@
19761981
4D5880AA0B80BDFE00200116 /* Frameworks */ = {
19771982
isa = PBXGroup;
19781983
children = (
1984+
4DA028F718F550E1000CFCF8 /* AudioToolbox.framework */,
19791985
4D982B1813C1CDD20066119A /* ApplicationServices.framework */,
19801986
4D8B47960BE7B3240046CD2F /* Cocoa.framework */,
19811987
4DFD495A13BA2BC0008DB91F /* CoreFoundation.framework */,
@@ -2100,6 +2106,7 @@
21002106
4D30E18118AA2FCE0034CDC6 /* mac-abort.mm */,
21012107
4D30E40618AA73870034CDC6 /* mac-dialog.mm */,
21022108
4DAF5C8618C0E76500B9713C /* mac-scripting.mm */,
2109+
4DA028F518F54B5D000CFCF8 /* mac-sound.mm */,
21032110
);
21042111
name = "Desktop - Mac";
21052112
sourceTree = "<group>";
@@ -3695,6 +3702,7 @@
36953702
4DEE2AF70FDE42710009423C /* regex.cpp in Sources */,
36963703
4DEE2AF80FDE42710009423C /* rtf.cpp in Sources */,
36973704
4DEE2AF90FDE42710009423C /* rtfsupport.cpp in Sources */,
3705+
4DA028F618F54B5D000CFCF8 /* mac-sound.mm in Sources */,
36983706
4DEE2AFA0FDE42710009423C /* scriptpt.cpp in Sources */,
36993707
4DEE2AFB0FDE42710009423C /* scrolbar.cpp in Sources */,
37003708
4DEE2AFC0FDE42710009423C /* scrollbardraw.cpp in Sources */,

engine/src/aclip.cpp

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
3636

3737
#include "globals.h"
3838

39-
#if defined _WINDOWS_DESKTOP
39+
#if defined FEATURE_PLATFORM_AUDIO
40+
#include "platform.h"
41+
static MCPlatformSoundRef s_current_sound = nil;
42+
#elif defined _WINDOWS_DESKTOP
4043
#include "w32prefix.h"
4144
static HWAVEOUT hwaveout; //handle to audio device opened
4245
static WAVEHDR wh; //wave header structure
@@ -151,7 +154,12 @@ const char *MCAudioClip::gettypestring()
151154
void MCAudioClip::timer(MCNameRef mptr, MCParameter *params)
152155
{
153156
if (play())
157+
{
158+
#ifndef FEATURE_PLATFORM_AUDIO
154159
MCscreen->addtimer(this, MCM_internal, looping ? LOOP_RATE: PLAY_RATE);
160+
#else
161+
#endif
162+
}
155163
else
156164
{
157165
MCacptr = NULL;
@@ -193,7 +201,11 @@ Exec_stat MCAudioClip::getprop(uint4 parid, Properties which, MCExecPoint &ep, B
193201
loudness = 0;
194202
else
195203
{
196-
#if defined _WINDOWS
204+
#if defined FEATURE_PLATFORM_AUDIO
205+
double t_volume;
206+
MCPlatformGetSystemProperty(kMCPlatformSystemPropertyVolume, kMCPlatformPropertyTypeDouble, &t_volume);
207+
loudness = t_volume * 100.0;
208+
#elif defined _WINDOWS
197209
if (hwaveout == NULL)
198210
{
199211
WAVEFORMATEX pwfx;
@@ -288,7 +300,11 @@ Exec_stat MCAudioClip::setprop(uint4 parid, Properties p, MCExecPoint &ep, Boole
288300
tptr = tptr->getnextplayer();
289301
}
290302
}
291-
#if defined _WINDOWS
303+
#if defined FEATURE_PLATFORM_AUDIO
304+
double t_volume;
305+
t_volume = loudness / 100.0;
306+
MCPlatformSetSystemProperty(kMCPlatformSystemPropertyVolume, kMCPlatformPropertyTypeDouble, &t_volume);
307+
#elif defined _WINDOWS
292308
WORD v = loudness * MAXUINT2 / 100;
293309
if (hwaveout != NULL)
294310
waveOutSetVolume(hwaveout, v | (v << 16));
@@ -341,7 +357,9 @@ void MCAudioClip::paste(void)
341357

342358
void MCAudioClip::init()
343359
{
344-
#if defined _WINDOWS
360+
#if defined FEATURE_PLATFORM_AUDIO
361+
supported = True;
362+
#elif defined _WINDOWS
345363
supported = True;
346364
#elif defined _MACOSX
347365
supported = True;
@@ -595,7 +613,36 @@ Boolean MCAudioClip::import(const char *fname, IO_handle stream)
595613
return True;
596614
}
597615

598-
#if defined _WINDOWS
616+
#if defined FEATURE_PLATFORM_AUDIO
617+
618+
void MCAudioClip::convert_tocontainer(void*& r_data, size_t& r_data_size)
619+
{
620+
}
621+
622+
Boolean MCAudioClip::open_audio(void)
623+
{
624+
if (s_current_sound != nil)
625+
return True;
626+
627+
void *t_data;
628+
size_t t_data_size;
629+
convert_tocontainer(t_data, t_data_size);
630+
631+
MCPlatformSoundCreateWithData(t_data, t_data_size, s_current_sound);
632+
633+
double t_volume;
634+
t_volume = loudness / 100.0;
635+
MCPlatformSoundSetProperty(s_current_sound, kMCPlatformSoundPropertyVolume, kMCPlatformPropertyTypeDouble, &t_volume);
636+
637+
bool t_looping;
638+
t_looping = looping == True;
639+
MCPlatformSoundSetProperty(s_current_sound, kMCPlatformSoundPropertyLooping, kMCPlatformPropertyTypeBool, &t_looping);
640+
641+
MCPlatformSoundPlay(s_current_sound);
642+
643+
return True;
644+
}
645+
#elif defined _WINDOWS
599646
Boolean MCAudioClip::open_audio()
600647
{
601648
if (hwaveout == NULL)
@@ -736,7 +783,10 @@ Boolean MCAudioClip::play()
736783
if (mstack == NULL)
737784
mstack = MCdefaultstackptr;
738785
#endif
739-
#ifdef _WINDOWS
786+
787+
#if defined FEATURE_PLATFORM_AUDIO
788+
return MCPlatformSoundIsPlaying(s_current_sound);
789+
#elif defined _WINDOWS
740790
if (wh.dwFlags & WHDR_DONE)
741791
{
742792
stop(False);//check to see if it is done, call stop();
@@ -834,7 +884,14 @@ Boolean MCAudioClip::play()
834884
void MCAudioClip::stop(Boolean abort)
835885
{
836886
MCscreen->cancelmessageobject(this, NULL);
837-
#if defined _WINDOWS
887+
888+
#if defined FEATURE_PLATFORM_AUDIO
889+
if (s_current_sound != nil)
890+
{
891+
MCPlatformSoundRelease(s_current_sound);
892+
s_current_sound = nil;
893+
}
894+
#elif defined _WINDOWS
838895
if (hwaveout != NULL)
839896
{
840897
waveOutReset(hwaveout);

engine/src/aclip.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class MCAudioClip : public MCObject
9191
void convert_slin8toslin16();
9292
void convert_slintoulin();
9393
void convert_ulintoslin();
94+
void convert_tocontainer(void*& r_data, size_t& r_data_size);
9495
Boolean isdisposable();
9596
Boolean issupported();
9697
void setdisposable();

engine/src/cmdse.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,9 +1738,12 @@ Exec_stat MCMM::exec(MCExecPoint &ep)
17381738
delete fname;
17391739
}
17401740
MCacptr->setlooping(looping);
1741+
MCacptr -> play();
17411742
MCU_play();
1743+
#ifndef FEATURE_PLATFORM_AUDIO
17421744
if (MCacptr != NULL)
17431745
MCscreen->addtimer(MCacptr, MCM_internal, looping ? LOOP_RATE : PLAY_RATE);
1746+
#endif
17441747
}
17451748
return ES_NORMAL;
17461749
#endif /* MCMM */

engine/src/desktop-dc.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,7 @@ bool MCScreenDC::transformimagecolors(MCColorTransformRef transform, MCImageBitm
647647

648648
void MCScreenDC::beep()
649649
{
650-
SndSetSysBeepState(sysBeepEnable | sysBeepSynchronous);
651-
SysBeep(beepduration / 16);
650+
MCPlatformBeep();
652651
}
653652

654653
void MCScreenDC::getbeep(uint4 which, MCExecPoint &ep)
@@ -657,38 +656,19 @@ void MCScreenDC::getbeep(uint4 which, MCExecPoint &ep)
657656
switch (which)
658657
{
659658
case P_BEEP_LOUDNESS:
660-
GetSysBeepVolume(&v);
661-
ep.setint(v);
659+
ep.setint(100);
662660
break;
663661
case P_BEEP_PITCH:
664-
ep.setint(beeppitch);
662+
ep.setint(1440);
665663
break;
666664
case P_BEEP_DURATION:
667-
ep.setint(beepduration);
665+
ep.setint(500);
668666
break;
669667
}
670668
}
671669

672670
void MCScreenDC::setbeep(uint4 which, int4 beep)
673671
{
674-
switch (which)
675-
{
676-
case P_BEEP_LOUDNESS:
677-
SetSysBeepVolume(beep);
678-
break;
679-
case P_BEEP_PITCH:
680-
if (beep == -1)
681-
beeppitch = 1440;
682-
else
683-
beeppitch = beep;
684-
break;
685-
case P_BEEP_DURATION:
686-
if (beep == -1)
687-
beepduration = 500;
688-
else
689-
beepduration = beep;
690-
break;
691-
}
692672
}
693673

694674
////////////////////////////////////////////////////////////////////////////////

engine/src/desktop.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "graphics_util.h"
4040
#include "redraw.h"
4141
#include "player.h"
42+
#include "aclip.h"
4243

4344
#include "desktop-dc.h"
4445

@@ -1038,6 +1039,14 @@ void MCPlatformHandlePlayerFrameChanged(MCPlatformPlayerRef p_player)
10381039

10391040
////////////////////////////////////////////////////////////////////////////////
10401041

1042+
void MCPlatformHandleSoundFinished(MCPlatformSoundRef p_sound)
1043+
{
1044+
if (MCacptr != nil)
1045+
MCscreen -> addtimer(MCacptr, MCM_internal, 0);
1046+
}
1047+
1048+
////////////////////////////////////////////////////////////////////////////////
1049+
10411050
#if 0
10421051
void MCPlatformProcess(MCPlatformCallback& p_callback)
10431052
{

engine/src/funcs.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4908,7 +4908,6 @@ Exec_stat MCSound::eval(MCExecPoint &ep)
49084908
return ES_NORMAL;
49094909
}
49104910
#endif
4911-
49124911
MCU_play();
49134912
if (MCacptr != NULL)
49144913
return MCacptr->getprop(0, P_NAME, ep, False);

engine/src/mac-core.mm

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,30 @@ void MCPlatformGetSystemProperty(MCPlatformSystemProperty p_property, MCPlatform
309309
*(MCPlatformCursorImageSupport *)r_value = kMCPlatformCursorImageSupportAlpha;
310310
break;
311311

312+
case kMCPlatformSystemPropertyVolume:
313+
MCMacPlatformGetGlobalVolume(*(double *)r_value);
314+
break;
315+
312316
default:
313317
assert(false);
314318
break;
315319
}
316320
}
317321

322+
void MCPlatformSetSystemProperty(MCPlatformSystemProperty p_property, MCPlatformPropertyType p_type, void *p_value)
323+
{
324+
switch(p_property)
325+
{
326+
case kMCPlatformSystemPropertyVolume:
327+
MCMacPlatformSetGlobalVolume(*(double *)p_value);
328+
break;
329+
330+
default:
331+
assert(false);
332+
break;
333+
}
334+
}
335+
318336
////////////////////////////////////////////////////////////////////////////////
319337

320338
static NSEvent *s_last_mouse_event = nil;
@@ -797,6 +815,11 @@ void MCPlatformFlushEvents(MCPlatformEventMask p_mask)
797815
}
798816
}
799817

818+
void MCPlatformBeep(void)
819+
{
820+
NSBeep();
821+
}
822+
800823
////////////////////////////////////////////////////////////////////////////////
801824

802825
void MCPlatformGetScreenCount(uindex_t& r_count)

engine/src/mac-internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,9 @@ bool MCMacPlatformMapMenuItemActionToSelector(MCPlatformMenuItemAction action, S
467467

468468
void MCMacPlatformResetCursor(void);
469469

470+
void MCMacPlatformGetGlobalVolume(double& r_volume);
471+
void MCMacPlatformSetGlobalVolume(double volume);
472+
470473
////////////////////////////////////////////////////////////////////////////////
471474

472475
NSDragOperation MCMacPlatformMapDragOperationToNSDragOperation(MCPlatformDragOperation);

0 commit comments

Comments
 (0)