From 8055f1d040ea32b91500f08dad16e5da2749351e Mon Sep 17 00:00:00 2001 From: Ariel Elkin Date: Wed, 12 Mar 2014 04:49:11 +0100 Subject: [PATCH] set raw wave path dynamically if needed --- include/Stk.h | 12 ++++++++++++ src/Stk.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/Stk.h b/include/Stk.h index 5c9c37b..c3467b4 100644 --- a/include/Stk.h +++ b/include/Stk.h @@ -174,6 +174,9 @@ public: //! Static method that returns the current rawwave path. static std::string rawwavePath(void) { return rawwavepath_; } + //! Static method to set the rawwave path on platforms where library resources are loaded dynamically. + static void setRawwavePathForDynamicallyLoadedRawwaves ( void ); + //! Static method that sets the STK rawwave path. static void setRawwavePath( std::string path ); @@ -519,6 +522,9 @@ const unsigned int RT_BUFFER_SIZE = 512; // the various STK core classes (ex. Clarinet.cpp). If you wish to // move the rawwaves directory to a different location in your file // system, you will need to set this path definition appropriately. +// Platforms that load resources dynamically will call +// Stk::setRawwavePathForDynamicallyLoadedRawwaves() and set the raw +//wave path accordingly. #if !defined(RAWWAVE_PATH) #define RAWWAVE_PATH "../../rawwaves/" #endif @@ -526,6 +532,10 @@ const unsigned int RT_BUFFER_SIZE = 512; const StkFloat PI = 3.14159265358979; const StkFloat TWO_PI = 2 * PI; const StkFloat ONE_OVER_128 = 0.0078125; + +#ifdef __APPLE__ + #include "TargetConditionals.h" +#endif #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_MM__) #define __OS_WINDOWS__ @@ -535,6 +545,8 @@ const StkFloat ONE_OVER_128 = 0.0078125; #define __STK_REALTIME__ #elif defined(__IRIX_AL__) #define __OS_IRIX__ +#elif defined TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + #define __OS_IOS__ #elif defined(__MACOSX_CORE__) || defined(__UNIX_JACK__) #define __OS_MACOSX__ #define __STK_REALTIME__ diff --git a/src/Stk.cpp b/src/Stk.cpp index 8f8e106..742875d 100644 --- a/src/Stk.cpp +++ b/src/Stk.cpp @@ -71,12 +71,39 @@ std::ostringstream Stk :: oStream_; Stk :: Stk( void ) : ignoreSampleRateChange_(false) { + setRawwavePathForDynamicallyLoadedRawwaves(); } Stk :: ~Stk( void ) { } +#ifdef __OS_IOS__ + #include +#endif +void Stk :: setRawwavePathForDynamicallyLoadedRawwaves ( void ) +{ + static bool rawwavesPathSet; + if (!rawwavesPathSet) + { +#ifdef __OS_IOS__ + CFBundleRef mainBundle = CFBundleGetMainBundle(); + CFURLRef url = CFBundleCopyResourceURL(mainBundle, CFSTR("rawwaves"), CFSTR("bundle"), NULL); + CFStringRef rawwavesPathCFString = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); + CFIndex length = CFStringGetLength(rawwavesPathCFString); + CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8); + char *rawwavesPathCString = (char *)malloc(maxSize); + CFStringGetCString(rawwavesPathCFString, rawwavesPathCString, maxSize, kCFStringEncodingUTF8); + std::string str(rawwavesPathCString); + setRawwavePath(rawwavesPathCString); + + CFRelease(url); + CFRelease(rawwavesPathCFString); +#endif + rawwavesPathSet = true; + } +} + void Stk :: setSampleRate( StkFloat rate ) { if ( rate > 0.0 && rate != srate_ ) {