Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
DBraun committed Apr 13, 2024
1 parent 6e1fcbc commit b878cd8
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 77 deletions.
78 changes: 54 additions & 24 deletions .github/workflows/all.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
env:
CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM: ${{ secrets.CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM }}
MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
MACOS_CERTIFICATE_BASE64: ${{ secrets.MACOS_CERTIFICATE_BASE64 }}
MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
NOTARIZATION_TEAM_ID: ${{ secrets.NOTARIZATION_TEAM_ID }}
NOTARIZATION_USERNAME: ${{ secrets.NOTARIZATION_USERNAME }}
NOTARIZATION_PASSWORD: ${{ secrets.NOTARIZATION_PASSWORD }}
name: Compile
on:
pull_request: {}
Expand Down Expand Up @@ -35,12 +39,6 @@ jobs:

# - name: Get CMake
# uses: lukka/get-cmake@latest

# - name: Download Libfaust
# shell: cmd
# run: |
# cd thirdparty/libfaust
# python download_libfaust.py

# - name: Build TD-Faust
# shell: cmd
Expand Down Expand Up @@ -79,20 +77,36 @@ jobs:
python-version: "3.11"
python-major: "311"

runs-on: macos-12
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Install Certificate
# https://docs.github.com/en/actions/deployment/deploying-xcode-applications/installing-an-apple-certificate-on-macos-runners-for-xcode-development
run: |
echo $MACOS_CERTIFICATE | base64 --decode > certificate.p12
security create-keychain -p "" build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p "" build.keychain
security import certificate.p12 -k build.keychain -P "$MACOS_CERTIFICATE_PASSWORD" -T /usr/bin/codesign
# create variables
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
# import certificate and provisioning profile from secrets
echo -n "$MACOS_CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH
# create temporary keychain
security create-keychain -p "$MACOS_CERTIFICATE_PASSWORD" $KEYCHAIN_PATH
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
security unlock-keychain -p "$MACOS_CERTIFICATE_PASSWORD" $KEYCHAIN_PATH
# import certificate to keychain
security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
security set-key-partition-list -S apple-tool:,apple: -k "$MACOS_CERTIFICATE_PASSWORD" $KEYCHAIN_PATH
echo "list-keychain:\n"
security list-keychain -d user -s $KEYCHAIN_PATH
echo "find-identity:\n"
security find-identity -v
echo "find-identity codesigning:\n"
security find-identity -p codesigning -v
- name: Setup Python
uses: actions/setup-python@v5
Expand Down Expand Up @@ -126,36 +140,52 @@ jobs:
run: |
brew install autoconf autogen automake flac libogg libtool libvorbis opus mpg123 pkg-config
- name: Download Libfaust
run: |
cd thirdparty/libfaust
which python
python --version
python download_libfaust.py
- name: Build Everything
run: |
export PATH=$pythonLocation:$PATH
python build_tdfaust.py --pythonver=3.11 --arch=${{matrix.arch}}
codesign --force --verify --verbose=2 --timestamp --options=runtime --deep --sign "Apple Distribution: David Braun" Plugins/TD-Faust.plugin
codesign --force --deep --timestamp --verify --verbose=2 --options=runtime --sign "Developer ID Application: David Braun (${{secrets.CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM}})" Plugins/TD-Faust.plugin
codesign --verify --deep --strict --verbose=2 Plugins/TD-Faust.plugin
- name: Build Reverb operator
run: |
export PATH=$PWD/thirdparty/libfaust/darwin-x64/Release/bin:$PATH
python faust2td.py --dsp reverb.dsp --type "Reverb" --label "Reverb" --icon "Rev" --author "David Braun" --email "github.com/DBraun" --drop-prefix --arch=${{matrix.arch}}
codesign --force --verify --verbose=2 --timestamp --options=runtime --deep --sign "Apple Distribution: David Braun" Plugins/Reverb.plugin
codesign --force --deep --timestamp --verify --verbose=2 --options=runtime --sign "Developer ID Application: David Braun (${{secrets.CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM}})" Plugins/Reverb.plugin
codesign --verify --deep --strict --verbose=2 Plugins/Reverb.plugin
- name: Make distribution
run: |
rm -rf Plugins/faustlibraries/.git
rm -rf Plugins/faustlibraries
zip -r Plugins.zip Plugins
- name: Notarize
run: |
xcrun notarytool submit "Plugins.zip" \
--team-id "$NOTARIZATION_TEAM_ID" \
--apple-id "$NOTARIZATION_USERNAME" \
--password "$NOTARIZATION_PASSWORD" \
--wait
- name: Staple
# While you can notarize a ZIP archive, you can’t staple to it directly.
# Instead, run stapler against each item that you added to the archive.
# Then create a new ZIP file containing the stapled items for distribution.
# Although tickets are created for standalone binaries, it’s not currently possible to staple tickets to them.
run: |
xcrun stapler staple Plugins/TD-Faust.plugin
xcrun stapler staple Plugins/Reverb.plugin
- name: Make stapled distribution
run: |
zip -r TD-Faust-${{ matrix.name }}-Python${{ matrix.python-major }}.zip Plugins
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: TD-Faust-${{ matrix.name }}-Python${{ matrix.python-major }}
path: Plugins
path: TD-Faust-${{ matrix.name }}-Python${{ matrix.python-major }}.zip
if-no-files-found: error

create-release:
if: startsWith(github.ref, 'refs/tags/v')
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ message(STATUS "TD-Faust external")

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT TD-Faust)

set(FAUST_LIBRARIES_DIR ${LIBFAUST_DIR}/share/faust)

set(TOUCHDESIGNER_INC ${PROJECT_SOURCE_DIR}/thirdparty/TouchDesigner/)

set(Headers
Expand Down Expand Up @@ -52,6 +54,14 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/TD-Faust/Info.plist
XCODE_ATTRIBUTE_FRAMEWORK_SEARCH_PATHS "/System/Library/PrivateFrameworks /Library/Frameworks"
)
if(APPLE)
install(
DIRECTORY ${FAUST_LIBRARIES_DIR}
DESTINATION "$<TARGET_FILE_DIR:TD-Faust>/../Resources"
PATTERN "*.lproj" EXCLUDE
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
endif()

# Basic includes
include_directories(${PROJECT_SOURCE_DIR}/thirdparty/faust/architecture)
Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ If you need to compile `TD-Faust.dll` yourself, you should first install [Python

#### Pre-compiled

Visit TD-Faust's [Releases](https://github.com/DBraun/TD-Faust/releases) page. Download and unzip the latest macOS version. Users with "Apple Silicon" computers should download "arm64". Copy `Reverb.plugin`, `TD-Faust.plugin`, and the `faustlibraries` folder to this repository's `Plugins` folder. Then run the following in Terminal.
```bash
xattr -d com.apple.quarantine Plugins/Reverb.plugin
xattr -d com.apple.quarantine Plugins/TD-Faust.plugin
```
Visit TD-Faust's [Releases](https://github.com/DBraun/TD-Faust/releases) page. Download and unzip the latest macOS version. Users with "Apple Silicon" computers should download "arm64". Copy `TD-Faust.plugin` and `Reverb.plugin` to this repository's `Plugins` folder.

Open `TD-Faust.toe` and compile a few examples.

Expand All @@ -61,10 +57,8 @@ Open `TD-Faust.toe` and compile a few examples.
2. Install Xcode.
3. [Install CMake](https://cmake.org/download/) and confirm that it's installed by running `cmake --version` in Terminal. You may need to run `export PATH="/Applications/CMake.app/Contents/bin":"$PATH"`
4. Install requirements with [brew](http://brew.sh/): `brew install autoconf autogen automake flac libogg libtool libvorbis opus mpg123 pkg-config`
5. In a Terminal window, navigate to `thirdparty/libfaust` and run `python3 download_libfaust.py`.
6. In a Terminal Window, export a variable to the TouchDesigner.app to which you'd like to support. For example: `export TOUCHDESIGNER_APP=/Applications/TouchDesigner.app`, assuming this version is a 2022.22650 build or higher.
7. In the same Terminal window, navigate to the root of this repository and run `python3 build_tdfaust.py --pythonver=3.11`
8. Open `TD-Faust.toe`
5. In the same Terminal window, navigate to the root of this repository and run `python3 build_tdfaust.py --pythonver=3.11`
6. Open `TD-Faust.toe`

## Building a Custom Operator

Expand Down
82 changes: 77 additions & 5 deletions TD-Faust/FaustCHOP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,53 @@ std::list<GUI*> GUI::fGuiList;
ztimedmap GUI::gTimedZoneMap;
static int numCompiled = 0;

// This was made with ChatGPT 4 because I don't want to use Boost.Program_options.
// I can't use POSIX wordexp because I need Windows support.
std::vector<std::string> splitArguments(const std::string& args) {
std::vector<std::string> result;
std::string current;
bool inQuotes = false;
char currentQuote = '\0'; // to differentiate between single and double quotes

for (size_t i = 0; i < args.size(); ++i) {
char c = args[i];

// Check if the current character is a quote
if (c == '"' || c == '\'') {
// If we're not currently in quotes, start quoting
if (!inQuotes) {
inQuotes = true;
currentQuote = c;
}
// If we're in quotes and current character matches the quote we're in, stop quoting
else if (inQuotes && c == currentQuote) {
inQuotes = false;
currentQuote = '\0';
} else {
// It's a quote character inside different quotes
current += c;
}
}
// If it's a space and we're not inside quotes, finalize the current argument
else if (c == ' ' && !inQuotes) {
if (!current.empty()) {
result.push_back(current);
current.clear();
}
} else {
// It's part of an argument
current += c;
}
}

// If there's any argument left in the buffer, add it to the result
if (!current.empty()) {
result.push_back(current);
}

return result;
}

#define FAIL_IN_CUSTOM_OPERATOR_METHOD \
Py_INCREF(Py_None); \
return Py_None;
Expand Down Expand Up @@ -522,21 +569,31 @@ bool FaustCHOP::eval(const string& code) {
int argc = 0;
const char** argv = new const char*[128];

#if __APPLE__
auto faustlibrariespath = std::filesystem::path(m_NodeInfo->pluginPath)
.append("Contents")
.append("Resources")
.append("faust")
.string();
#else
auto faustlibrariespath = std::filesystem::path(m_NodeInfo->pluginPath)
.parent_path()
.append("faustlibraries")
.string();
#endif

argv[argc++] = "--import-dir";
argv[argc++] = faustlibrariespath.c_str();

if (std::strcmp(m_faustLibrariesPath, "") != 0) {
argv[argc++] = "--import-dir";
argv[argc++] = m_faustLibrariesPath;
// todo: allow the user to specify more args
// argv[argc++] = "-vec";
// argv[argc++] = "-vs";
// argv[argc++] = "128";
// argv[argc++] = "-dfs";
}

for (const std::string& arg : splitArguments(m_compile_options)) {
if (!arg.empty()) {
argv[argc++] = arg.c_str();
}
}

// optimization level
Expand Down Expand Up @@ -762,6 +819,8 @@ void FaustCHOP::execute(CHOP_Output* output, const OP_Inputs* inputs,
m_midi_virtual = inputs->getParInt("Midiinvirtual");
m_midi_virtual_name = inputs->getParString("Midiinvirtualname");

m_compile_options = inputs->getParString("Options");

const OP_DATInput* dat = inputs->getParDAT("Code");
eval(std::string(dat->getCell(0, 0)));
m_wantCompile = false;
Expand Down Expand Up @@ -1152,6 +1211,19 @@ void FaustCHOP::setupParameters(OP_ParameterManager* manager, void* reserved1) {
assert(res == OP_ParAppendResult::Success);
}

// Options
{
OP_StringParameter sp;

sp.name = "Options";
sp.label = "Options";

sp.defaultValue = "";

OP_ParAppendResult res = manager->appendString(sp);
assert(res == OP_ParAppendResult::Success);
}

// Compile
{
OP_NumericParameter np;
Expand Down
1 change: 1 addition & 0 deletions TD-Faust/FaustCHOP.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class FaustCHOP : public CHOP_CPlusPlusBase {
string m_errorString = string("");
string m_warningString = string("");
string m_name_app = string("");
string m_compile_options = string("");
// auto import
string m_autoImport;
bool m_groupVoices = true;
Expand Down
3 changes: 3 additions & 0 deletions build_tdfaust.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def build_macos(pythonver: str, touchdesigner_app: str, arch: str=None):
]
run_command(cmake_command)
run_command(["cmake", "--build", "build", "--config", "Release"])
run_command(["cmake", "--build", "build", "--config", "Release", "--target", "install"])
os.system('mv build/Release/TD-Faust.plugin Plugins')

if __name__ == "__main__":
Expand All @@ -75,8 +76,10 @@ def build_macos(pythonver: str, touchdesigner_app: str, arch: str=None):
args = parser.parse_args()

if platform.system() == "Windows":
subprocess.run(shlex.split("python download_libfaust.py"), check=True, cwd="thirdparty/libfaust")
build_windows(args.pythonver)
elif platform.system() == "Darwin":
subprocess.run(shlex.split("python3 download_libfaust.py"), check=True, cwd="thirdparty/libfaust")
build_macos(args.pythonver, args.touchdesigner_app, args.arch)
else:
raise RuntimeError(f"Unsupported operating system: {platform.system()}.")
Loading

0 comments on commit b878cd8

Please sign in to comment.