diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml index aad2816..7524726 100644 --- a/.github/workflows/all.yml +++ b/.github/workflows/all.yml @@ -36,14 +36,12 @@ jobs: shell: cmd run: | cd thirdparty/libfaust - call download_libfaust.bat + python download_libfaust.py - name: Build TD-Faust shell: cmd run: | - call build_windows.bat - env: - PYTHONVER: ${{ matrix.python-version}} + python build_tdfaust.py --pythonver=${{ matrix.python-version}} - name: Build Reverb operator shell: cmd @@ -85,12 +83,18 @@ jobs: # cd install_script # python macos_install_python.py + # - name: Download Libfaust + # shell: cmd + # run: | + # cd thirdparty/libfaust + # python download_libfaust.py + # - name: Build Everything # run: | # export PATH=/Library/Frameworks/Python.framework/Versions/3.9:/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.9/lib:$PATH # which python3 # python3 --version - # sh -v build_macos.sh + # python build_tdfaust.py --pythonver=3.9 # - name: Build Reverb operator # shell: cmd diff --git a/.gitignore b/.gitignore index 2531337..4342ace 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ Backup/* Release/ Debug/ build* +!build_tdfaust.py TD-Faust.[0-9]*.toe SketchSynth.[0-9]*.toe *dsp.json diff --git a/README.md b/README.md index 840a3f0..1ef24b9 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,12 @@ The previous overview was about using a multi-purpose CHOP to dynamically compil These are the requirements: -* Download libfaust by going to `thirdparty/libfaust` and running either `call download_libfaust.bat` on Windows or `sh download_libfaust.sh` on macOS. +* Download libfaust by going to `thirdparty/libfaust` and running `python download_libfaust.py`. * Pick a Faust DSP file such as `reverb.dsp` that defines a `process = ...;`. * Python should be installed. * CMake should be installed. -If on Windows, you should open an x64 Native Tools for Visual Studio command prompt. On macOS, you can use Terminal. Then run a variation of the following script: +If on Windows, you should open an "x64 Native Tools for Visual Studio" command prompt. On macOS, you can use Terminal. Then run a variation of the following script: ```bash python faust2td.py --dsp reverb.dsp --type "Reverb" --label "Reverb" --icon "Rev" --author "David Braun" --email "github.com/DBraun" --drop-prefix @@ -62,7 +62,7 @@ Limitations and Gotchas: Visit TD-Faust's [Releases](https://github.com/DBraun/TD-Faust/releases) page. Download and unzip the latest Windows version. Copy `TD-Faust.dll` and the `faustlibraries` folder to this repository's `Plugins` folder. Open `TD-Faust.toe` and compile a few examples. -If you need to compile `TD-Faust.dll` yourself, you should first install [Python 3.11](https://www.python.org/downloads/release/python-3117/) to `C:/Python311/` and confirm it's in your system PATH. You'll also need Visual Studio 2022 and CMake. Then open a cmd window to `thirdparty/libsndfile` and run `call download_libfaust.bat`. Then you can open a cmd window to this repo's root directory and run `call build_windows.bat`. +If you need to compile `TD-Faust.dll` yourself, you should first install [Python 3.11](https://www.python.org/downloads/release/python-3117/) to `C:/Python311/` and confirm it's in your system PATH. You'll also need Visual Studio 2022 and CMake. Then open a "x64 Native Tools for Visual Studio" command prompt with Administrator privileges to `thirdparty/libsndfile` and run `python download_libfaust.py`. Then `cd` to this repo's root directory and run `python build_tdfaust.py`. ### macOS @@ -76,12 +76,10 @@ TD-Faust is designed for macOS version 11.0 and later. Also, macOS users need to 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 `sh download_libfaust.sh`. +5. In a Terminal window, navigate to `thirdparty/libfaust` and run `python 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. Optional: depending on the Python version associated with the TouchDesigner you intend to use, run `export PYTHONVER=3.11` or `export PYTHONVER=3.9`. -8. In the same Terminal window, navigate to the root of this repository and run `sh build_macos.sh` -9. In a Terminal window, navigate to the root of this repository and run `sh build_macos.sh`. -10. Open `TD-Faust.toe` +7. In the same Terminal window, navigate to the root of this repository and run `python build_tdfaust.py --pythonver=3.11` +8. Open `TD-Faust.toe` ## Tutorial diff --git a/build_macos.sh b/build_macos.sh deleted file mode 100644 index 7b1f9ca..0000000 --- a/build_macos.sh +++ /dev/null @@ -1,41 +0,0 @@ -# Remove any old plugins and dylib -rm -r Plugins/TD-Faust.plugin - -if [ "$TOUCHDESIGNER_APP" == "" ]; then - # a reasonable default in case you forget to set the path to TouchDesigner. - export TOUCHDESIGNER_APP=/Applications/TouchDesigner.app -fi -echo Assuming TouchDesigner is located at $TOUCHDESIGNER_APP - -if [ "$PYTHONVER" == "" ]; then - # Guess which Python version TD uses. - export PYTHONVER=3.11 -fi -echo Building for Python $PYTHONVER - -export CMAKE_OSX_DEPLOYMENT_TARGET=11.0 - -if [[ $(uname -m) == 'arm64' ]]; then - export LIBFAUST_DIR=$PWD/thirdparty/libfaust/darwin-arm64/Release -else - export LIBFAUST_DIR=$PWD/thirdparty/libfaust/darwin-x64/Release -fi - -# Build libsndfile -echo "Building libsndfile." -cd thirdparty/libsndfile -cmake -Bbuild $CMAKEOPTS -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_INSTALL_PREFIX="./install" -cmake --build build --config Release -cmake --build build --target install -cd ../.. - -# Use CMake for TD-Faust -cmake -Bbuild -G "Xcode" -DCMAKE_OSX_DEPLOYMENT_TARGET=$CMAKE_OSX_DEPLOYMENT_TARGET -DLIBFAUST_DIR="$LIBFAUST_DIR" -DPYTHONVER=$PYTHONVER -DPython_ROOT_DIR=/Applications/TouchDesigner.app/Contents/Frameworks/Python.framework/Versions/$PYTHONVER - -# Build TD-Faust (Release) -xcodebuild -configuration Release -project build/TD-Faust.xcodeproj - -# # Copy to Plugins directory -mv build/Release/TD-Faust.plugin Plugins - -echo "All Done!" \ No newline at end of file diff --git a/build_tdfaust.py b/build_tdfaust.py new file mode 100644 index 0000000..74f8d82 --- /dev/null +++ b/build_tdfaust.py @@ -0,0 +1,77 @@ +import argparse +import os +import platform +import subprocess + + +def run_command(command, shell=False): + subprocess.run(command, shell=shell, check=True) + +def build_windows(pythonver): + os.system('rm build/CMakeCache.txt') + + # Download libsndfile + libsndfile_dir = "thirdparty/libsndfile-1.2.0-win64/" + if not os.path.exists(libsndfile_dir): + print("Downloading libsndfile...") + os.chdir('thirdparty') + run_command(["curl", "-OL", "https://github.com/libsndfile/libsndfile/releases/download/1.2.0/libsndfile-1.2.0-win64.zip"]) + run_command(["7z", "x", "libsndfile-1.2.0-win64.zip", "-y"]) + os.remove("libsndfile-1.2.0-win64.zip") + print("Downloaded libsndfile.") + os.chdir("..") + + # Build with CMake + cmake_command = [ + "cmake", "-Bbuild", "-DCMAKE_BUILD_TYPE=Release", + "-DLIBFAUST_DIR=thirdparty/libfaust/win64/Release", + "-DSndFile_DIR=thirdparty/libsndfile/build", + f"-DPYTHONVER={pythonver}" + ] + run_command(cmake_command) + run_command(["cmake", "--build", "build", "--config", "Release"]) + os.system(f'cp "thirdparty/libsndfile-1.2.0-win64/bin/sndfile.dll" "Plugins/sndfile.dll"') + +def build_macos(pythonver, touchdesigner_app): + os.system('rm -r Plugins/TD-Faust.plugin') + + cmake_osx_deployment_target = "11.0" + if platform.machine() == 'arm64': + libfaust_dir = f"{os.getcwd()}/thirdparty/libfaust/darwin-arm64/Release" + elif platform.machine() == 'x86_64': + libfaust_dir = f"{os.getcwd()}/thirdparty/libfaust/darwin-x64/Release" + else: + raise RuntimeError(f"Unknown CPU architecture: {platform.machine()}.") + + # Build libsndfile + print("Building libsndfile.") + os.chdir("thirdparty/libsndfile") + run_command(["cmake", "-Bbuild", "-DCMAKE_VERBOSE_MAKEFILE=ON", "-DCMAKE_INSTALL_PREFIX=./install"]) + run_command(["cmake", "--build", "build", "--config", "Release"]) + run_command(["cmake", "--build", "build", "--target", "install"]) + os.chdir("../..") + + # Build with CMake + cmake_command = [ + "cmake", "-Bbuild", "-G", "Xcode", + f"-DCMAKE_OSX_DEPLOYMENT_TARGET={cmake_osx_deployment_target}", + f"-DLIBFAUST_DIR={libfaust_dir}", + f"-DPYTHONVER={pythonver}", + f"-DPython_ROOT_DIR={touchdesigner_app}/Contents/Frameworks/Python.framework/Versions/{pythonver}" + ] + run_command(cmake_command) + run_command(["xcodebuild", "-configuration", "Release", "-project", "build/TD-Faust.xcodeproj"], shell=True) + os.system('mv build/Release/TD-Faust.plugin Plugins') + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Build TD-Faust plugin for Windows or macOS.") + parser.add_argument("--pythonver", default="3.11", help="Specify the Python version.") + parser.add_argument("--touchdesigner_app", default="/Applications/TouchDesigner.app", help="Path to TouchDesigner app (macOS only).") + args = parser.parse_args() + + if platform.system() == "Windows": + build_windows(args.pythonver) + elif platform.system() == "Darwin": + build_macos(args.pythonver, args.touchdesigner_app) + else: + raise RuntimeError(f"Unsupported operating system: {platform.system()}.") diff --git a/build_windows.bat b/build_windows.bat deleted file mode 100644 index 8780982..0000000 --- a/build_windows.bat +++ /dev/null @@ -1,33 +0,0 @@ -@echo off -setlocal enabledelayedexpansion - -rem Remove any old plugins -rem rm Plugins/sndfile.dll -rem rm Plugins/TD-Faust.dll -rm build/CMakeCache.txt - -if "%PYTHONVER%"=="" ( - set PYTHONVER=3.11 -) -echo "Using Python version: %PYTHONVER%" - -rem Download libsndfile -if not exist "thirdparty/libsndfile-1.2.0-win64/" ( - echo "Downloading libsndfile..." - cd thirdparty - curl -OL https://github.com/libsndfile/libsndfile/releases/download/1.2.0/libsndfile-1.2.0-win64.zip - 7z x libsndfile-1.2.0-win64.zip -y - rm libsndfile-1.2.0-win64.zip - echo "Downloaded libsndfile." - cd .. -) - -rem Use CMake for TD-Faust -cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DLIBFAUST_DIR="thirdparty/libfaust/win64/Release" -DSndFile_DIR=thirdparty/libsndfile/build -DPYTHONVER=%PYTHONVER% - -rem Build TD-Faust -cmake --build build --config Release - -cp "thirdparty/libsndfile-1.2.0-win64/bin/sndfile.dll" "Plugins/sndfile.dll" - -echo "All Done!" \ No newline at end of file diff --git a/thirdparty/libfaust/download_libfaust.bat b/thirdparty/libfaust/download_libfaust.bat deleted file mode 100644 index 4b42fc6..0000000 --- a/thirdparty/libfaust/download_libfaust.bat +++ /dev/null @@ -1,3 +0,0 @@ -set VERSION=2.69.3 -curl -L https://github.com/grame-cncm/faust/releases/download/%VERSION%/Faust-%VERSION%-win64.exe -o Faust-%VERSION%-win64.exe -call Faust-%VERSION%-win64.exe /S /D=%cd%\win64\Release \ No newline at end of file diff --git a/thirdparty/libfaust/download_libfaust.py b/thirdparty/libfaust/download_libfaust.py new file mode 100644 index 0000000..bc2bf42 --- /dev/null +++ b/thirdparty/libfaust/download_libfaust.py @@ -0,0 +1,55 @@ +import argparse +import os +import platform +import subprocess +from pathlib import Path + + +def download_file(url: str, output: str) -> None: + if os.path.exists(output) and not args.force: + print(f"File already exists: {output}") + else: + subprocess.run(["curl", "-L", url, "-o", output], check=True) + +def install_windows(version: str) -> None: + exe_file = f"Faust-{version}-win64.exe" + download_file(f"https://github.com/grame-cncm/faust/releases/download/{version}/{exe_file}", exe_file) + cwd = str(Path(__file__).parent) + subprocess.run([exe_file, "/S", f"/D={cwd}\\win64\\Release"], check=True) + +def install_macos(version: str) -> None: + for arch in ["arm64", "x64"]: + dmg_file = f"Faust-{version}-{arch}.dmg" + download_file(f"https://github.com/grame-cncm/faust/releases/download/{version}/{dmg_file}", dmg_file) + subprocess.run(["hdiutil", "attach", dmg_file], check=True) + dir_path = f"darwin-{arch}/Release" + os.makedirs(dir_path, exist_ok=True) + subprocess.run(["cp", "-R", f"/Volumes/Faust-{version}/Faust-{version}/*", dir_path], check=True) + subprocess.run(["hdiutil", "detach", f"/Volumes/Faust-{version}/"], check=True) + +def install_linux(version: str) -> None: + zip_file = f"libfaust-ubuntu-x86_64.zip" + download_file(f"https://github.com/grame-cncm/faust/releases/download/{version}/{zip_file}", zip_file) + dir_path = "ubuntu-x86_64/Release" + os.makedirs(dir_path, exist_ok=True) + subprocess.run(["unzip", zip_file, "-d", dir_path], check=True) + +def main(version: str) -> None: + system = platform.system() + if system == "Windows": + install_windows(version) + elif system == "Darwin": + install_macos(version) + elif system == "Linux": + install_linux(version) + else: + raise RuntimeError(f"Unknown operating system: {system}.") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Download and install Libfaust.") + parser.add_argument("-v", "--version", default="2.69.3", help="Specify the version of Faust to download.") + parser.add_argument("--force", action="store_true", help="Force download even if files already exist.") + args = parser.parse_args() + + main(args.version) diff --git a/thirdparty/libfaust/download_libfaust.sh b/thirdparty/libfaust/download_libfaust.sh deleted file mode 100644 index e99d015..0000000 --- a/thirdparty/libfaust/download_libfaust.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -VERSION=2.69.3 - -if [ "$(uname)" = "Darwin" ]; then - echo "You are running macOS" - curl -L https://github.com/grame-cncm/faust/releases/download/$VERSION/Faust-$VERSION-arm64.dmg -o Faust-$VERSION-arm64.dmg - hdiutil attach Faust-$VERSION-arm64.dmg - mkdir -p "darwin-arm64/Release" - cp -R /Volumes/Faust-$VERSION/Faust-$VERSION/* darwin-arm64/Release/ - hdiutil detach /Volumes/Faust-$VERSION/ - - curl -L https://github.com/grame-cncm/faust/releases/download/$VERSION/Faust-$VERSION-x64.dmg -o Faust-$VERSION-x64.dmg - hdiutil attach Faust-$VERSION-x64.dmg - mkdir -p "darwin-x64/Release" - cp -R /Volumes/Faust-$VERSION/Faust-$VERSION/* darwin-x64/Release/ - hdiutil detach /Volumes/Faust-$VERSION/ -elif [ "$(expr substr $(uname -s) 1 5)" = "Linux" ]; then - echo "You are running Linux" - curl -L https://github.com/grame-cncm/faust/releases/download/$VERSION/libfaust-ubuntu-x86_64.zip -o libfaust-ubuntu-x86_64.zip - mkdir -p "ubuntu-x86_64/Release" - unzip libfaust-ubuntu-x86_64.zip -d ubuntu-x86_64/Release -elif [ "$(expr substr $(uname -s) 1 10)" = "MINGW32_NT" ] || [ "$(expr substr $(uname -s) 1 10)" = "MINGW64_NT" ]; then - echo "You are running Windows. You should run \"call download_libfaust.bat\"" >&2 - exit 1 -else - echo "Unknown operating system" >&2 - exit 1 -fi \ No newline at end of file