Skip to content

Commit

Permalink
Merge pull request #85 from DBraun/warpbuf-fixes
Browse files Browse the repository at this point in the history
WarpBuf fixes
  • Loading branch information
nshaheed authored Nov 2, 2023
2 parents 3828bf8 + 79a1d22 commit 1bfa047
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 92 deletions.
44 changes: 25 additions & 19 deletions .github/workflows/WarpBuf.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name: WarpBuf

env:
WARPBUF_VERSION: 0.0.1

on:
# pull_request: {}
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

pull_request: {}
push:
# branches:
# - main
paths:
- 'WarpBuf/**'

Expand Down Expand Up @@ -41,29 +45,31 @@ jobs:
run: |
brew install autoconf autogen automake flac libogg libtool libvorbis opus mpg123 pkg-config
- name: Build release
shell: bash
run: |
cd WarpBuf
sh build_all_platforms.sh
- name: Package release (macOS)
if: startsWith(matrix.os, 'macos')
- name: Install dependencies Windows
if: startsWith(matrix.os, 'windows')
run: |
mv WarpBuf/build/libWarpBuf.dylib WarpBuf/build/WarpBuf.chug
cd WarpBuf/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
- name: Package release (Windows)
if: startsWith(matrix.os, 'windows')
- name: Build Libsndfile
if: startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu')
run: |
mv WarpBuf/build/x64/Release/WarpBuf.dll WarpBuf/build/WarpBuf.chug
cd WarpBuf/thirdparty/libsndfile
cmake -Bbuild -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_C_FLAGS="-fPIC" -DCMAKE_CXX_FLAGS="-fPIC" -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX="./install"
cmake --build build --config Release
cmake --build build --target install
- name: Package release (Ubuntu)
if: startsWith(matrix.os, 'ubuntu')
- name: Build WarpBuf Release
run: |
mv WarpBuf/build/libWarpBuf.so WarpBuf/build/WarpBuf.chug
cd WarpBuf
cmake -Bbuild -DCMAKE_VERBOSE_MAKEFILE=ON
cmake --build build --config Release
cmake --build build --config Release --target install
- uses: actions/upload-artifact@v3
with:
name: warpbuf-${{ matrix.name }}.zip
path: "WarpBuf/build/WarpBuf.chug"
path: "WarpBuf/package/warpbuf-${{ env.WARPBUF_VERSION }}"
if-no-files-found: error
95 changes: 71 additions & 24 deletions WarpBuf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
cmake_minimum_required(VERSION 3.13.0 FATAL_ERROR)

project(WarpBuf VERSION 0.0.1)
set(ROOT ${CMAKE_CURRENT_SOURCE_DIR})

if (DEFINED ENV{WARPBUF_VERSION})
set (VERSION $ENV{WARPBUF_VERSION})
else()
set (VERSION "0.0.1")
endif()

project(WarpBuf VERSION ${VERSION})

# Set startup project for Visual Studio
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT WarpBuf)
Expand All @@ -18,9 +26,6 @@ set(Sources
)
source_group("Sources" FILES ${Sources})

# Add libsamplerate project
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libsamplerate)

# Add Rubber Band sources
set(RUBBERBAND_SRC_CPP
src/RubberBandStretcher.cpp
Expand Down Expand Up @@ -53,14 +58,44 @@ set(RUBBERBAND_HEADERS
)

# Create shared library
add_library(WarpBuf SHARED ${CK_SOURCES} ${Sources} ${RUBBERBAND_SOURCES} ${RUBBERBAND_HEADERS}
add_library(WarpBuf MODULE ${CK_SOURCES} ${Sources} ${RUBBERBAND_SOURCES} ${RUBBERBAND_HEADERS}
${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libsamplerate/include/samplerate.h
${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/portable_endian/include/portable_endian.h
)

####################################
# Install - used for packaging
####################################
set (PACKDIR ${ROOT}/package)
set (DST warpbuf-${VERSION})
install ( TARGETS WarpBuf
RUNTIME DESTINATION ${PACKDIR}/${DST}
LIBRARY DESTINATION ${PACKDIR}/${DST}
ARCHIVE DESTINATION ${PACKDIR}/${DST}
)

set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_compile_options(-fPIC)

if(APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES
LINK_FLAGS "-Wl,-U,_object_new_imp -Wl,-U,_object_method_imp"
BUNDLE TRUE
BUNDLE_EXTENSION chug
OUTPUT_NAME WarpBuf
MACOSX_BUNDLE_GUI_IDENTIFIER edu.stanford.chuck.${PROJECT_NAME}
MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME}
MACOSX_BUNDLE_BUNDLE_VERSION ${VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${VERSION}
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/Info.plist
)
else()
set_target_properties (${PROJECT_NAME} PROPERTIES
SUFFIX ".chug"
OUTPUT_NAME WarpBuf)
endif()

target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_LIBSAMPLERATE)

# Platform-specific libraries and definitions
Expand Down Expand Up @@ -92,16 +127,17 @@ else()
)
endif()

target_link_libraries(WarpBuf PRIVATE samplerate)

# link libsndfile statically
# Find sndfile and link it
if (MSVC)
set (SNDFILE_LIBRARIES ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libsndfile-win64/lib/sndfile.lib)
target_link_libraries (WarpBuf PRIVATE ${SNDFILE_LIBRARIES})
set(SndFile_DIR "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libsndfile-1.2.0-win64/cmake")
find_package(SndFile REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE SndFile::sndfile)
else()
# We expect the user to have built libsndfile as a static lib
# and for it to be accessible via `pkg-config --static libsndfile`
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libsndfile/install")
find_package(PkgConfig REQUIRED)
# We expect the user to have used brew to install the dependencies
# for libsndfile, to have built libsndfile as a static lib,
# and for it to be accessible via `pkg-config --static libsndfile`.
if(APPLE)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
list(APPEND PKG_CONFIG_EXECUTABLE "--static") # append temporarily
Expand All @@ -116,27 +152,24 @@ else()
execute_process(COMMAND find /usr/local/Cellar/lame -name libmp3lame.a OUTPUT_VARIABLE SNDFILE_STATIC_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
list(POP_BACK PKG_CONFIG_EXECUTABLE) # undo the append above
endif()
target_link_libraries (WarpBuf PRIVATE PkgConfig::SNDFILE PkgConfig::FLAC PkgConfig::VORBIS PkgConfig::OGG PkgConfig::OPUS PkgConfig::MPG123 ${SNDFILE_STATIC_LIBS})
target_link_libraries (${PROJECT_NAME} PRIVATE PkgConfig::SNDFILE PkgConfig::FLAC PkgConfig::VORBIS PkgConfig::OGG PkgConfig::OPUS PkgConfig::MPG123 ${SNDFILE_STATIC_LIBS})
endif()

# Add libsamplerate project
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libsamplerate)
target_link_libraries(${PROJECT_NAME} PRIVATE samplerate)

# Include header directories
target_include_directories(WarpBuf PRIVATE
target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../chuck/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/Rubberband>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/Rubberband/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/rubberband>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/rubberband/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libsamplerate/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libsamplerate/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/portable_endian/include>
$<INSTALL_INTERFACE:WarpBuf>
)

# Install library
INSTALL(TARGETS WarpBuf
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if (MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_COMMAND "C:\\Program\ Files\ (x86)\\ChucK\\bin\\chuck.exe"
Expand All @@ -147,4 +180,18 @@ if (MSVC)
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:WarpBuf>"
"%USERPROFILE%/Documents/ChucK/chugins/WarpBuf.chug")
endif()
endif()

if (WIN32)
####################################
# install sndfile
install (
FILES ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libsndfile-1.2.0-win64/bin/sndfile.dll DESTINATION ${PACKDIR}/${DST}
)
endif()

if (APPLE)
install (
CODE "execute_process (COMMAND codesign --sign - --deep --force ${PACKDIR}/${DST}/WarpBuf.chug)"
)
endif()
28 changes: 28 additions & 0 deletions WarpBuf/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>WarpBuf</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>edu.stanford.chuck.WarpBuf</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>0.0.1</string>
<key>CFBundleLongVersionString</key>
<string>WarpBuf 0.0.1, Copyright 2023 Stanford CCRMA</string>
<key>CFBundlePackageType</key>
<string>iLaX</string>
<key>CFBundleShortVersionString</key>
<string>0.0.1</string>
<key>CFBundleSignature</key>
<string>max2</string>
<key>CFBundleVersion</key>
<string>0.0.1</string>
<key>CSResourcesFileMapped</key>
<true/>
</dict>
</plist>
26 changes: 24 additions & 2 deletions WarpBuf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,31 @@ Make sure you have `cmake`, `git`, and `sh` available from the command line/Term
Update submodules:
`git submodule update --init --recursive`

If on Windows, create an extra folder for your chugins, `%USERPROFILE%/Documents/ChucK/chugins/`. Create a system environment variable `CHUCK_CHUGIN_PATH` equal to this path.
### Windows

In `chugins/WarpBuf`, open a command window on Windows or Terminal window on macOS and run `sh build_all_platforms.sh`. On Windows, the `WarpBuf.chug` should appear inside `%USERPROFILE%/Documents/ChucK/chugins/`, and on macOS/Linux it should appear in `/usr/local/lib/chuck`.
Create an extra folder for your chugins, `%USERPROFILE%/Documents/ChucK/chugins/`. Create a system environment variable `CHUCK_CHUGIN_PATH` equal to this path. In `chugins/WarpBuf`, open a command window and run `call build_windows.bat`. The `WarpBuf.chug` should appear inside `%USERPROFILE%/Documents/ChucK/chugins/` and `chugins/WarpBuf/package`.

### Ubuntu

Install dependencies:

```bash
sudo apt install autoconf autogen automake build-essential libasound2-dev libflac-dev libogg-dev libtool libvorbis-dev libopus-dev libmp3lame-dev libmpg123-dev pkg-config python
```

In `chugins/WarpBuf`, open a Terminal window and run `sh build_unix.sh`. The `WarpBuf.chug` should appear inside `chugins/WarpBuf/package`.

### macOS

Install dependencies with brew:

```zsh
brew install autoconf autogen automake flac libogg libtool libvorbis opus mpg123 pkg-config
```

In `chugins/WarpBuf`, open a Terminal window and run `sh build_unix.sh`. The `WarpBuf.chug` should appear inside `chugins/WarpBuf/package`.

## Testing

Run any of the test scripts: `chuck.exe --verbose:10 level:10 "tests/warpbuf_basic.ck"`.

Expand Down
42 changes: 0 additions & 42 deletions WarpBuf/build_all_platforms.sh

This file was deleted.

15 changes: 15 additions & 0 deletions WarpBuf/build_unix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# The quirky thing about this build script is that on macOS, we can't
# use the libsndfile from brew because it's not a static library.
# Therefore, we build libsndfile statically locally and link against it
# in the CMakeLists.txt. On Windows, we can just download libsndfile
# from its GitHub releases.

cd thirdparty/libsndfile
cmake -Bbuild $CMAKEOPTS -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_C_FLAGS="-fPIC" -DCMAKE_CXX_FLAGS="-fPIC" -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX="./install"
cmake --build build --config Release
cmake --build build --target install
cd ../..

cmake -Bbuild . -DCMAKE_VERBOSE_MAKEFILE=ON
cmake --build build --config Release
cmake --build build --config Release --target install
14 changes: 14 additions & 0 deletions WarpBuf/build_windows.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 ..
)

cmake -Bbuild . -DCMAKE_VERBOSE_MAKEFILE=ON
cmake --build build --config Release
cmake --build build --config Release --target install
10 changes: 5 additions & 5 deletions WarpBuf/src/WarpBufChugin.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// this should align with the correct versions of these ChucK files
#include "chuck_dl.h"
#include "chuck_def.h"
#include "chuck_instr.h"
#include "chuck_vm.h"
#include <chuck_dl.h>
#include <chuck_def.h>
#include <chuck_instr.h>
#include <chuck_vm.h>

// general includes
#include <stdio.h>
Expand All @@ -16,7 +16,7 @@ using namespace std;

#include <sndfile.h>

#include "rubberband/RubberBandStretcher.h"
#include <rubberband/RubberBandStretcher.h>
#include "AbletonClipInfo.h"

#define WARPBUF_MAX_OUTPUTS 16
Expand Down

0 comments on commit 1bfa047

Please sign in to comment.