Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS-friendly static library #8

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 73 additions & 0 deletions STK for iOS/README.md
@@ -0,0 +1,73 @@
##Setup

1. [Clone][clone_link] or [download][download_link] the STK into your project's directory.

1. Open the **STK for iOS** folder, and drag and drop **STK.xcodeproj** into your Xcode project.

1. Open your project's settings, open the *Build Phases* tab. In the *Link Binary with Libraries* section, add **libSTK.a**.
![][linking_libSTK_screenshot]

1. In your project's settings, open the *Build Settings* tab. In the *Search Paths* section, double click on the field to the right of *Header Search Paths*, and add the path to the STK's **include** directory relative to your Xcode project's directory.
![][header_search_paths_screenshot]


##Usage

1. Import the STK classes in the source files you require.
* E.g. `#import "SineWave.h"`

1. Change the extension of Objective-C files that import STK files to **.mm**.
* E.g. **ViewController.m** —> **ViewController.mm**

You can also look at the [iOS Demo project](..projects/demo/iOS%20Demo) for a sample usage.


##Troubleshooting

###'FileName.h' file not found

If you get this error when `#import`ing an STK header, you have added the wrong header search path for the STK in your project's settings (see Step 4 in Setup)

The STK's header search path you need to add is the path to the STK's **include** directory relative to your project's directory (as if you were `cd`ing into it). For example, it is `stk/include/` if the stk directory is inside your project's directory, but it is `../stk/include/` if both share the same directory.

If this problem doesn't go away:

1. Delete **STK.xcodeproj** from your Xcode project
1. Move the STK directory within your project's directory.
1. Follow step 1 from **Setup**, add `stk/include` to the *Header Search Paths*.

###Raw waves

If you use a class that makes use of raw waves (such as `Mandolin`, `Wurley`, or `Rhodey`) you need to copy the STK's raw wave files into your bundle. You'll know you need to if you get this runtime error:
`FileRead::open: could not open or find file (../../rawwaves/filename.raw)!`

1. Open your project's settings, open the *Build Phases* tab.
1. In the *Copy Bundle Resources*, drag and drop **rawwaves.bundle** (it's located in **STK.xcodeproj**'s **Helpers** folder).
1. Then add this code before using a class that needs the raw waves:

```objective-c
NSBundle *rawwaveBundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"rawwaves" withExtension:@"bundle"]];
stk::Stk::setRawwavePath([[rawwaveBundle resourcePath] UTF8String]);
```


###rawwaves.bundle: No such file or directory

This means that **rawwaves.bundle** hasn't been copied to the build folder, so you'll need to do it manually:

Select the rawwaves scheme:

![][rawwaves_scheme_screenshot]

Build it (⌘+B) then build your project's main scheme.

###Apple Mach-O Linker Error

This means that **STKLib.a** isn't being linked to your binary. Follow step 2 above in Setup.


[clone_link]: git@github.com:thestk/stk.git
[download_link]: https://github.com/thestk/stk/archive/master.zip
[linking_libSTK_screenshot]: http://i.imgur.com/cLbGrtq.png
[header_search_paths_screenshot]: http://i.imgur.com/iBTC06h.png
[rawwaves_scheme_screenshot]: http://i.imgur.com/PKd7epf.png
1,103 changes: 1,103 additions & 0 deletions STK for iOS/STK.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>18FB414F-2DD6-484D-A0A9-8AEE7068C849</string>
<key>IDESourceControlProjectName</key>
<string>STK for iOS</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>8F90F41D-319D-40FA-AE64-12325A91B6D4</key>
<string>ssh://github.com/arielelkin/stk.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>STK for iOS/STK for iOS.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>8F90F41D-319D-40FA-AE64-12325A91B6D4</key>
<string>../../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>ssh://github.com/arielelkin/stk.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>8F90F41D-319D-40FA-AE64-12325A91B6D4</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>8F90F41D-319D-40FA-AE64-12325A91B6D4</string>
<key>IDESourceControlWCCName</key>
<string>stk</string>
</dict>
</array>
</dict>
</plist>
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>361A7ADB-A5E2-4BAB-A539-EBF076762B44</string>
<key>IDESourceControlProjectName</key>
<string>STK</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>12089B0D-8850-4865-BB8F-9C05CB2D53D7</key>
<string>ssh://github.com/arielelkin/stk.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>STK for iOS/STK.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>12089B0D-8850-4865-BB8F-9C05CB2D53D7</key>
<string>../../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>ssh://github.com/arielelkin/stk.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>12089B0D-8850-4865-BB8F-9C05CB2D53D7</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>12089B0D-8850-4865-BB8F-9C05CB2D53D7</string>
<key>IDESourceControlWCCName</key>
<string>stk</string>
</dict>
</array>
</dict>
</plist>
12 changes: 12 additions & 0 deletions include/Stk.h
Expand Up @@ -174,6 +174,9 @@ class Stk
//! 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 );

Expand Down Expand Up @@ -519,13 +522,20 @@ 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

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__
Expand All @@ -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__
Expand Down