From 279bb59056b3ad1c8a0ec3ccae0790624e1b5577 Mon Sep 17 00:00:00 2001 From: AnotherCommander Date: Mon, 31 Oct 2016 20:37:51 +0100 Subject: [PATCH] The sound source object of the music currently playing has been exposed to JS, thus allowing for real-time volume control of music, as well as other properties like looping, position, etc. The function returning the sound source object is Sound.musicSoundSource(). --- src/Core/OOALMusic.h | 2 ++ src/Core/OOALMusic.m | 7 ++++++- src/Core/OOMusicController.h | 3 +++ src/Core/OOMusicController.m | 6 ++++++ src/Core/Scripting/OOJSSound.m | 14 ++++++++++++++ 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Core/OOALMusic.h b/src/Core/OOALMusic.h index d1beb95b..053a286b 100644 --- a/src/Core/OOALMusic.h +++ b/src/Core/OOALMusic.h @@ -31,6 +31,7 @@ SOFTWARE. #import #import "OOALSound.h" +#import "OOSoundSource.h" @interface OOMusic: OOSound @@ -44,5 +45,6 @@ SOFTWARE. - (BOOL) isPlaying; - (void) setMusicGain:(float)newValue; - (float) musicGain; +- (OOSoundSource *)musicSoundSource; @end diff --git a/src/Core/OOALMusic.m b/src/Core/OOALMusic.m index 92111802..586845bb 100644 --- a/src/Core/OOALMusic.m +++ b/src/Core/OOALMusic.m @@ -27,7 +27,6 @@ SOFTWARE. */ #import "OOALMusic.h" -#import "OOSoundSource.h" static OOMusic *sPlayingMusic = nil; static OOSoundSource *sMusicSource = nil; @@ -106,6 +105,12 @@ static OOSoundSource *sMusicSource = nil; } +- (OOSoundSource *)musicSoundSource +{ + return sMusicSource; +} + + - (BOOL)isPlaying { return sPlayingMusic == self && [sMusicSource isPlaying]; diff --git a/src/Core/OOMusicController.h b/src/Core/OOMusicController.h index 186fd93c..c552a77f 100644 --- a/src/Core/OOMusicController.h +++ b/src/Core/OOMusicController.h @@ -26,6 +26,7 @@ MA 02110-1301, USA. */ #import "OOCocoa.h" +#import "OOSoundSource.h" @class OOMusic; @@ -77,6 +78,8 @@ typedef enum - (void) toggleDockingMusic; // Start docking music if none playing, stop docking music if currently playing docking music. +- (OOSoundSource *) soundSource; + - (NSString *) playingMusic; - (BOOL) isPlaying; diff --git a/src/Core/OOMusicController.m b/src/Core/OOMusicController.m index dcf5c825..4755619a 100644 --- a/src/Core/OOMusicController.m +++ b/src/Core/OOMusicController.m @@ -224,6 +224,12 @@ enum } +- (OOSoundSource *) soundSource +{ + return [_current musicSoundSource]; +} + + - (NSString *) playingMusic { return [_current name]; diff --git a/src/Core/Scripting/OOJSSound.m b/src/Core/Scripting/OOJSSound.m index 6cb4d2aa..76b9e326 100644 --- a/src/Core/Scripting/OOJSSound.m +++ b/src/Core/Scripting/OOJSSound.m @@ -40,6 +40,7 @@ static JSBool SoundGetProperty(JSContext *context, JSObject *this, jsid propID, // Static methods static JSBool SoundStaticLoad(JSContext *context, uintN argc, jsval *vp); +static JSBool SoundStaticMusicSoundSource(JSContext *context, uintN argc, jsval *vp); static JSBool SoundStaticPlayMusic(JSContext *context, uintN argc, jsval *vp); static JSBool SoundStaticStopMusic(JSContext *context, uintN argc, jsval *vp); @@ -88,6 +89,7 @@ static JSFunctionSpec sSoundStaticMethods[] = { // JS name Function min args { "load", SoundStaticLoad, 1, }, + { "musicSoundSource", SoundStaticMusicSoundSource,0, }, { "playMusic", SoundStaticPlayMusic, 1, }, { "stopMusic", SoundStaticStopMusic, 0, }, { 0 } @@ -196,6 +198,18 @@ static JSBool SoundStaticLoad(JSContext *context, uintN argc, jsval *vp) } +static JSBool SoundStaticMusicSoundSource(JSContext *context, uintN argc, jsval *vp) +{ + OOJS_NATIVE_ENTER(context) + OOSoundSource *musicSource = nil; + OOJS_BEGIN_FULL_NATIVE(context) + musicSource = [[OOMusicController sharedController] soundSource]; + OOJS_END_FULL_NATIVE + OOJS_RETURN_OBJECT(musicSource); + OOJS_NATIVE_EXIT +} + + // playMusic(name : String [, loop : Boolean] [, gain : float]) static JSBool SoundStaticPlayMusic(JSContext *context, uintN argc, jsval *vp) {