diff --git a/.coderabbit.yaml b/.coderabbit.yaml index c14d3bfd..114c588a 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -1,7 +1,7 @@ reviews: path_filters: - - "!7.x/src/stk/src/**" - - "!7.x/src/stk/include/**" - - "!7.x/src/stk/rawwaves/**" - - "!7.x/src/dssi4cs/include/dssi/**" - - "!7.x/src/dssi4cs/include/ladspa/**" + - "!src/stk/src/**" + - "!src/stk/include/**" + - "!src/stk/rawwaves/**" + - "!src/dssi4cs/include/dssi/**" + - "!src/dssi4cs/include/ladspa/**" diff --git a/.github/workflows/plugins_build.yml b/.github/workflows/plugins_build.yml index 2f811079..fa13ad70 100644 --- a/.github/workflows/plugins_build.yml +++ b/.github/workflows/plugins_build.yml @@ -1,93 +1,567 @@ -name: Csound plugins build +name: Csound 7 plugins build -env: - VCPKG_BINARY_SOURCES: "clear;nuget,GitHub,readwrite" +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true on: + push: + branches: + - develop + - main + pull_request: + branches: + - develop + - main workflow_dispatch: +env: + CSOUND_VERSION: 7.0.0 + FAUST_VERSION: 2.88.0 + VCPKG_BINARY_SOURCES: "clear;files,${{ github.workspace }}/vcpkg-cache,readwrite" + jobs: - build_package: - runs-on: ${{ matrix.os }} - - env: - CSOUND_VERSION: 6.17.2 - - strategy: - matrix: - os: [windows-latest] - version: ["6.17.0"] - include: - - os: "windows-latest" - mono: "" - # - os: "ubuntu-latest" - # mono: "mono" - # - os: "macos-latest" - # mono: "mono" + update_version: + name: Update plugin version + runs-on: ubuntu-latest + permissions: + contents: write + outputs: + version: ${{ steps.tag.outputs.new_tag }} + release: ${{ steps.check_pr.outputs.has_label }} + steps: + - name: Checkout source + uses: actions/checkout@v7.0.1 + with: + fetch-depth: 0 + - name: Compute next version + id: tag + uses: anothrNick/github-tag-action@1.75.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DEFAULT_BUMP: patch + DEFAULT_BRANCH: main + PRERELEASE: ${{ github.ref != 'refs/heads/main' }} + PRERELEASE_SUFFIX: beta + DRY_RUN: true + + - name: Check for release label + id: check_pr + uses: ./.github/actions/check-pr-label + with: + label: release + github_token: ${{ secrets.GITHUB_TOKEN }} + + linux: + name: Linux (ubuntu-latest) + needs: update_version + runs-on: ubuntu-latest steps: - - name: Checkout Source Code + - name: Checkout source uses: actions/checkout@v7.0.1 + + - name: Install Csound build dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + build-essential cmake pkg-config \ + libsndfile1-dev libsamplerate0-dev libasound2-dev libportaudio2 libportmidi-dev \ + libeigen3-dev libfluidsynth-dev libpng-dev \ + libwebsockets-dev libuv1-dev libhdf5-dev \ + ocl-icd-opencl-dev libtinfo-dev \ + libgtest-dev \ + flex bison + + - name: Cache Csound install + id: cache-csound + uses: actions/cache@v6.1.0 with: - fetch-depth: 1 - submodules: true + path: ~/csound-install + key: csound-${{ runner.os }}-${{ runner.arch }}-${{ env.CSOUND_VERSION }} - - name: Setup platform (windows) - if: startsWith(matrix.os, 'windows') + - name: Build and install Csound + if: steps.cache-csound.outputs.cache-hit != 'true' + run: | + git clone --depth 1 --branch "$CSOUND_VERSION" \ + https://github.com/csound/csound.git "$RUNNER_TEMP/csound" + cmake -S "$RUNNER_TEMP/csound" -B "$RUNNER_TEMP/csound-build" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="$HOME/csound-install" \ + -DBUILD_TESTS=OFF \ + -DINSTALL_PYTHON_INTERFACE=OFF + cmake --build "$RUNNER_TEMP/csound-build" --parallel "$(nproc)" + cmake --install "$RUNNER_TEMP/csound-build" + + - name: Cache Faust + id: cache-faust + uses: actions/cache@v4 + with: + path: ~/faust + key: faust-${{ runner.os }}-${{ runner.arch }}-${{ env.FAUST_VERSION }} + + - name: Install Faust + if: steps.cache-faust.outputs.cache-hit != 'true' + run: | + mkdir -p "$HOME/faust" + curl -sL -o "$RUNNER_TEMP/libfaust.zip" \ + "https://github.com/grame-cncm/faust/releases/download/$FAUST_VERSION/libfaust-ubuntu-x86_64.zip" + curl -sL -o "$RUNNER_TEMP/faust-src.tar.gz" \ + "https://github.com/grame-cncm/faust/releases/download/$FAUST_VERSION/faust-$FAUST_VERSION.tar.gz" + unzip -q "$RUNNER_TEMP/libfaust.zip" -d "$HOME/faust" + tar xzf "$RUNNER_TEMP/faust-src.tar.gz" -C "$RUNNER_TEMP" \ + "faust-$FAUST_VERSION/architecture" "faust-$FAUST_VERSION/libraries" + mv "$RUNNER_TEMP/faust-$FAUST_VERSION/architecture" "$HOME/faust/include" + mv "$RUNNER_TEMP/faust-$FAUST_VERSION/libraries" "$HOME/faust/stdlib" + rm -f "$RUNNER_TEMP/libfaust.zip" "$RUNNER_TEMP/faust-src.tar.gz" + + - name: Configure plugin build + run: | + echo "CSOUND_INCLUDE_DIR_HINT=$HOME/csound-install/include/csound" >> "$GITHUB_ENV" + echo "CSOUND_LIBRARY_DIR_HINT=$HOME/csound-install/lib" >> "$GITHUB_ENV" + echo "FAUST_INCLUDE_DIR_HINT=$HOME/faust/include" >> "$GITHUB_ENV" + echo "FAUST_LIB_DIR_HINT=$HOME/faust/lib" >> "$GITHUB_ENV" + echo "FAUST_STDLIB_DIR_HINT=$HOME/faust/stdlib" >> "$GITHUB_ENV" + + - name: Build plugins + run: | + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \ + -DFAUST_STATIC=ON \ + -DCSOUND_INCLUDE_DIR_HINT="$CSOUND_INCLUDE_DIR_HINT" \ + -DCSOUND_LIBRARY_DIR_HINT="$CSOUND_LIBRARY_DIR_HINT" \ + -DFAUST_INCLUDE_DIR_HINT="$FAUST_INCLUDE_DIR_HINT" \ + -DFAUST_LIB_DIR_HINT="$FAUST_LIB_DIR_HINT" \ + -DFAUST_STDLIB_DIR_HINT="$FAUST_STDLIB_DIR_HINT" + cmake --build build --parallel "$(nproc)" + + - name: Run plugin tests + run: ctest --test-dir build --output-on-failure + + - name: Stage plugins + run: | + mkdir -p package + cp build/src/chua/*.so \ + build/src/linear_algebra/*.so \ + build/src/fluidOpcodes/*.so \ + build/src/dssi4cs/*.so \ + build/src/image/*.so \ + build/src/websockets/*.so \ + build/src/hdf5/*.so \ + build/src/py/*.so \ + build/src/OpenCL/*.so \ + build/src/stk/*.so package/ + cp build/src/faustcsound/*.so package/ + mkdir -p package/stk/rawwaves + cp src/stk/rawwaves/*.raw package/stk/rawwaves/ + mkdir -p package/faust + cp -R "$HOME/faust/stdlib/." package/faust/ + + - name: Upload plugins + uses: actions/upload-artifact@v7.0.2 + with: + name: csound7-plugins-linux + path: package/ + if-no-files-found: error + + macos: + name: macOS (macos-latest) + needs: update_version + runs-on: macos-latest + steps: + - name: Checkout source + uses: actions/checkout@v7.0.1 + + - name: Install Csound build dependencies env: - FAUST_URL: https://github.com/grame-cncm/faust/releases/download/2.60.3/Faust-2.60.3-win64.exe - run: | - Invoke-WebRequest $env:FAUST_URL -OutFile faustInstaller.exe - ./faustInstaller.exe /S - echo "C:/Program Files/csound/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - echo "OPCODE6DIR64=C:/Program Files/csound/plugins64" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - echo "PYTHONPATH=C:/Program Files/csound/bin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - echo "RAWWAVE_PATH=C:/Program Files/csound/samples" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - .\6.x\vcpkg\bootstrap-vcpkg.bat - choco install csound --version=6.17.0 - echo $GITHUB_ENV - ls 'C:\Program Files\Faust\' - echo "C:\Program Files\Faust\;C:\Program Files\Faust\lib" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - # - name: Setup platform (linux) - # if: startsWith(matrix.os, 'ubuntu') - # run: | - # ./vcpkg/bootstrap-vcpkg.sh - # sudo apt-get update - # sudo apt-get install libcsound64-dev - - # - name: Setup platform (macos) - # if: startsWith(matrix.os, 'macos') - # run: | - # ./vcpkg/bootstrap-vcpkg.sh - # brew install csound - - - name: Setup VCPKG cache - shell: bash - run: | - ${{ matrix.mono }} `./6.x/vcpkg/vcpkg fetch nuget | tail -n 1` \ - sources add \ - -source "https://nuget.pkg.github.com/csound/index.json" \ - -storepasswordincleartext \ - -name "GitHub" \ - -username "csound" \ - -password "${{ secrets.GITHUB_TOKEN }}" - ${{ matrix.mono }} `./6.x/vcpkg/vcpkg fetch nuget | tail -n 1` \ - setapikey "${{ secrets.GITHUB_TOKEN }}" \ - -source "https://nuget.pkg.github.com/csound/index.json" - - - name: Generate CMake build - run: cmake 6.x/. -B build -DUSE_VCPKG=1 -DBUILD_ABLETON_LINK_OPCODES=OFF + HOMEBREW_NO_AUTO_UPDATE: 1 + run: | + brew install cmake ninja pkg-config bison flex libsndfile + echo "$(brew --prefix bison)/bin" >> "$GITHUB_PATH" + echo "$(brew --prefix flex)/bin" >> "$GITHUB_PATH" + + - name: Checkout vcpkg submodule + run: git submodule update --init vcpkg + + - name: Set up vcpkg + run: vcpkg/bootstrap-vcpkg.sh -disableMetrics + + - name: Cache vcpkg binary cache + uses: actions/cache@v6.1.0 + with: + path: vcpkg-cache + key: vcpkg-macos-${{ github.run_id }} + restore-keys: vcpkg-macos- + + - name: Cache Csound install + id: cache-csound + uses: actions/cache@v6.1.0 + with: + path: ~/csound-install + key: csound-${{ runner.os }}-${{ runner.arch }}-${{ env.CSOUND_VERSION }} + + - name: Build and install Csound + if: steps.cache-csound.outputs.cache-hit != 'true' + run: | + git clone --depth 1 --branch "$CSOUND_VERSION" \ + https://github.com/csound/csound.git "$RUNNER_TEMP/csound" + cmake -S "$RUNNER_TEMP/csound" -B "$RUNNER_TEMP/csound-build" -G Ninja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="$HOME/csound-install" \ + -DCS_FRAMEWORK_DEST="$HOME/csound-install/Frameworks" \ + -DCMAKE_PREFIX_PATH="$(brew --prefix)" \ + -DBUILD_TESTS=OFF \ + -DBUILD_STATIC_LIBRARY=OFF \ + -DBUILD_VIRTUAL_KEYBOARD=OFF \ + -DBUILD_JAVA_INTERFACE=OFF \ + -DBUILD_PYTHON_INTERFACE=OFF \ + -DINSTALL_PYTHON_INTERFACE=OFF \ + -DBUILD_LUA_INTERFACE=OFF \ + -DBUILD_CSBEATS=OFF \ + -DUSE_LIBSAMPLERATE=OFF \ + -DUSE_CURL=OFF \ + -DUSE_GETTEXT=OFF \ + -DUSE_JACK=OFF \ + -DUSE_PORTAUDIO=OFF \ + -DUSE_PORTMIDI=OFF \ + -DUSE_MP3=OFF + cmake --build "$RUNNER_TEMP/csound-build" --parallel "$(sysctl -n hw.ncpu)" + cmake --install "$RUNNER_TEMP/csound-build" + + - name: Cache Faust + id: cache-faust + uses: actions/cache@v4 + with: + path: ~/faust + key: faust-${{ runner.os }}-${{ runner.arch }}-${{ env.FAUST_VERSION }} + + - name: Install Faust + if: steps.cache-faust.outputs.cache-hit != 'true' + run: | + if [ "$(uname -m)" = "arm64" ]; then + asset="Faust-$FAUST_VERSION-arm64.dmg" + else + asset="Faust-$FAUST_VERSION-x64.dmg" + fi + curl -sL -o "$RUNNER_TEMP/faust.dmg" \ + "https://github.com/grame-cncm/faust/releases/download/$FAUST_VERSION/$asset" + mkdir -p "$HOME/faust" "$RUNNER_TEMP/faust_dmg" + hdiutil attach "$RUNNER_TEMP/faust.dmg" \ + -mountpoint "$RUNNER_TEMP/faust_dmg" -nobrowse -quiet + root=$(dirname "$(find "$RUNNER_TEMP/faust_dmg" -maxdepth 2 -type d -name include | head -1)") + cp -R "$root/include" "$HOME/faust/include" + cp -R "$root/lib" "$HOME/faust/lib" + cp -R "$root/share/faust" "$HOME/faust/stdlib" + hdiutil detach "$RUNNER_TEMP/faust_dmg" -quiet + rm -f "$RUNNER_TEMP/faust.dmg" + + - name: Configure plugin build + run: | + framework="$HOME/csound-install/Frameworks/CsoundLib64.framework" + headers="$framework/Versions/7.0/Headers" + if [ ! -f "$headers/csound.h" ]; then + headers="$framework/Headers" + fi + echo "CSOUND_INCLUDE_DIR_HINT=$headers" >> "$GITHUB_ENV" + echo "CSOUND_FRAMEWORK_DIR_HINT=$HOME/csound-install/Frameworks" >> "$GITHUB_ENV" + echo "CSOUND_LIBRARY_DIR_HINT=$HOME/csound-install/Frameworks" >> "$GITHUB_ENV" + echo "FAUST_INCLUDE_DIR_HINT=$HOME/faust/include" >> "$GITHUB_ENV" + echo "FAUST_LIB_DIR_HINT=$HOME/faust/lib" >> "$GITHUB_ENV" + echo "FAUST_STDLIB_DIR_HINT=$HOME/faust/stdlib" >> "$GITHUB_ENV" + + - name: Build plugins + run: | + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \ + -DUSE_VCPKG=ON \ + -DFAUST_STATIC=ON \ + -DCSOUND_INCLUDE_DIR_HINT="$CSOUND_INCLUDE_DIR_HINT" \ + -DCSOUND_FRAMEWORK_DIR_HINT="$CSOUND_FRAMEWORK_DIR_HINT" \ + -DCSOUND_LIBRARY_DIR_HINT="$CSOUND_LIBRARY_DIR_HINT" \ + -DFAUST_INCLUDE_DIR_HINT="$FAUST_INCLUDE_DIR_HINT" \ + -DFAUST_LIB_DIR_HINT="$FAUST_LIB_DIR_HINT" \ + -DFAUST_STDLIB_DIR_HINT="$FAUST_STDLIB_DIR_HINT" + cmake --build build --parallel "$(sysctl -n hw.ncpu)" + + - name: Stage plugins + run: | + mkdir -p package + cp build/src/chua/*.dylib \ + build/src/linear_algebra/*.dylib \ + build/src/fluidOpcodes/*.dylib \ + build/src/image/*.dylib \ + build/src/websockets/*.dylib \ + build/src/hdf5/*.dylib \ + build/src/py/*.dylib \ + build/src/OpenCL/*.dylib \ + build/src/stk/*.dylib package/ + cp build/src/faustcsound/*.dylib package/ + mkdir -p package/stk/rawwaves + cp src/stk/rawwaves/*.raw package/stk/rawwaves/ + mkdir -p package/faust + cp -R "$HOME/faust/stdlib/." package/faust/ + + - name: Upload plugins + uses: actions/upload-artifact@v7.0.2 + with: + name: csound7-plugins-macos + path: package/ + if-no-files-found: error + + windows: + name: Windows (windows-latest) + needs: update_version + runs-on: windows-latest + defaults: + run: + shell: pwsh + steps: + - name: Checkout source + uses: actions/checkout@v7.0.1 + + - name: Install Csound build dependencies + run: choco install -y winflexbison3 + + - name: Clone Csound (with vcpkg) + run: | + git clone --recursive --depth 1 --branch "$env:CSOUND_VERSION" ` + https://github.com/csound/csound.git csound + + - name: Cache Csound install + id: cache-csound + uses: actions/cache@v6.1.0 + with: + path: ${{ runner.temp }}\csound-install + key: csound-${{ runner.os }}-${{ runner.arch }}-${{ env.CSOUND_VERSION }} + + - name: Bootstrap vcpkg (Csound) + if: steps.cache-csound.outputs.cache-hit != 'true' + run: .\csound\vcpkg\bootstrap-vcpkg.bat -disableMetrics + + - name: Checkout vcpkg submodule + run: git submodule update --init vcpkg + + - name: Bootstrap vcpkg (plugins) + run: .\vcpkg\bootstrap-vcpkg.bat -disableMetrics + + - name: Cache vcpkg binary cache + uses: actions/cache@v6.1.0 + with: + path: ${{ github.workspace }}\vcpkg-cache + key: vcpkg-windows-${{ github.run_id }} + restore-keys: vcpkg-windows- + + - name: Build and install Csound + if: steps.cache-csound.outputs.cache-hit != 'true' + run: | + cmake -S csound -B csound-build -A x64 ` + -DUSE_VCPKG=ON ` + -DCMAKE_INSTALL_PREFIX="$env:RUNNER_TEMP\csound-install" ` + -DBUILD_TESTS=OFF ` + -DBUILD_STATIC_LIBRARY=OFF ` + -DBUILD_VIRTUAL_KEYBOARD=OFF ` + -DBUILD_JAVA_INTERFACE=OFF ` + -DBUILD_PYTHON_INTERFACE=OFF ` + -DINSTALL_PYTHON_INTERFACE=OFF ` + -DBUILD_LUA_INTERFACE=OFF ` + -DBUILD_CSBEATS=OFF + cmake --build csound-build --config Release --parallel + cmake --install csound-build --config Release + + - name: Cache Faust + id: cache-faust + uses: actions/cache@v4 + with: + path: ~/faust + key: faust-${{ runner.os }}-${{ runner.arch }}-${{ env.FAUST_VERSION }} + + - name: Install Faust + if: steps.cache-faust.outputs.cache-hit != 'true' + run: | + $faustDir = Join-Path $env:USERPROFILE 'faust' + New-Item -ItemType Directory -Force -Path $faustDir | Out-Null + curl.exe -sL -o "$env:RUNNER_TEMP\faust.exe" ` + "https://github.com/grame-cncm/faust/releases/download/$env:FAUST_VERSION/Faust-$env:FAUST_VERSION-win64.exe" + & 'C:\Program Files\7-Zip\7z.exe' x "$env:RUNNER_TEMP\faust.exe" "-o$faustDir" -y | Out-Null + Remove-Item "$env:RUNNER_TEMP\faust.exe" + + - name: Configure plugin build + run: | + $install = Join-Path $env:RUNNER_TEMP 'csound-install' + $header = Get-ChildItem -Path $install -Recurse -File -Filter 'csound.h' | + Select-Object -First 1 + $lib = Get-ChildItem -Path $install -Recurse -File -Filter 'csound64.lib' | + Select-Object -First 1 + if (-not $header) { throw "csound.h not found under $install" } + if (-not $lib) { throw "csound64.lib not found under $install" } + "CSOUND_INCLUDE_DIR_HINT=$($header.DirectoryName)" >> $env:GITHUB_ENV + "CSOUND_LIBRARY_DIR_HINT=$($lib.DirectoryName)" >> $env:GITHUB_ENV + $faustDir = Join-Path $env:USERPROFILE 'faust' + "FAUST_INCLUDE_DIR_HINT=$faustDir\include" >> $env:GITHUB_ENV + "FAUST_LIB_DIR_HINT=$faustDir\lib" >> $env:GITHUB_ENV + "FAUST_STDLIB_DIR_HINT=$faustDir\share\faust" >> $env:GITHUB_ENV - name: Build plugins - run: cmake --build build --config Release + run: | + cmake -S . -B build -A x64 ` + -DUSE_VCPKG=ON ` + -DFAUST_STATIC=ON ` + -DCSOUND_INCLUDE_DIR_HINT="$env:CSOUND_INCLUDE_DIR_HINT" ` + -DCSOUND_LIBRARY_DIR_HINT="$env:CSOUND_LIBRARY_DIR_HINT" ` + -DFAUST_INCLUDE_DIR_HINT="$env:FAUST_INCLUDE_DIR_HINT" ` + -DFAUST_LIB_DIR_HINT="$env:FAUST_LIB_DIR_HINT" ` + -DFAUST_STDLIB_DIR_HINT="$env:FAUST_STDLIB_DIR_HINT" + cmake --build build --config Release --parallel - - name: Build installer - run: iscc /o. .\installer\win64\Installer.iss + - name: Stage plugins + run: | + $package = 'package' + New-Item -ItemType Directory -Force -Path $package | Out-Null + Get-ChildItem -Path build/src -Recurse -Include *.dll | + Where-Object { $_.FullName -match 'Release' } | + Copy-Item -Destination $package + $vcpkgBin = Join-Path 'build' 'vcpkg_installed\x64-windows-csound\bin' + if (Test-Path $vcpkgBin) { + Copy-Item (Join-Path $vcpkgBin '*.dll') -Destination $package -ErrorAction SilentlyContinue + } + $rawwaves = Join-Path $package 'stk/rawwaves' + New-Item -ItemType Directory -Force -Path $rawwaves | Out-Null + Copy-Item 'src\stk\rawwaves\*.raw' -Destination $rawwaves + $faustOut = Join-Path $package 'faust' + New-Item -ItemType Directory -Force -Path $faustOut | Out-Null + Copy-Item "$env:USERPROFILE\faust\share\faust\*" -Destination $faustOut -Recurse - - name: Upload installer + - name: Upload plugins uses: actions/upload-artifact@v7.0.2 with: - name: Csound_win_x64-${{env.CSOUND_VERSION}}.${{github.run_number}}-plugins-installer - path: ./csound6-plugins-win_x86_64-*.exe + name: csound7-plugins-windows + path: package/ if-no-files-found: error + + linux_cuda: + name: Linux CUDA (ubuntu-latest) + needs: update_version + runs-on: ubuntu-latest + container: + image: nvidia/cuda:12.4.1-devel-ubuntu22.04 + steps: + - name: Checkout source + uses: actions/checkout@v7.0.1 + + - name: Install build dependencies + run: | + apt-get update + apt-get install -y --no-install-recommends \ + build-essential cmake git ca-certificates pkg-config \ + libsndfile1-dev libsamplerate0-dev libasound2-dev flex bison + + - name: Show CUDA toolchain + run: | + nvcc --version + nvidia-smi || true + + - name: Cache Csound install + id: cache-csound + uses: actions/cache@v6.1.0 + with: + path: /csound-install + key: csound-cuda-${{ runner.os }}-${{ runner.arch }}-${{ env.CSOUND_VERSION }} + + - name: Build and install Csound + if: steps.cache-csound.outputs.cache-hit != 'true' + run: | + git clone --depth 1 --branch "$CSOUND_VERSION" \ + https://github.com/csound/csound.git /tmp/csound + cmake -S /tmp/csound -B /tmp/csound-build \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/csound-install \ + -DBUILD_TESTS=OFF \ + -DINSTALL_PYTHON_INTERFACE=OFF + cmake --build /tmp/csound-build --parallel "$(nproc)" + cmake --install /tmp/csound-build + + - name: Build CUDA plugins + run: | + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_CUDA_OPCODES=ON \ + -DBUILD_CHUA_OPCODES=OFF \ + -DBUILD_DSSI_OPCODES=OFF \ + -DBUILD_FLUID_OPCODES=OFF \ + -DBUILD_HDF5_OPCODES=OFF \ + -DBUILD_IMAGE_OPCODES=OFF \ + -DBUILD_LINEAR_ALGEBRA_OPCODES=OFF \ + -DBUILD_PYTHON_OPCODES=OFF \ + -DBUILD_WEBSOCKET_OPCODE=OFF \ + -DBUILD_WIIMOTE_OPCODES=OFF \ + -DBUILD_P5GLOVE_OPCODES=OFF \ + -DCMAKE_CUDA_ARCHITECTURES="50;60;70;75;80;86" \ + -DCSOUND_INCLUDE_DIR_HINT=/csound-install/include/csound \ + -DCSOUND_LIBRARY_DIR_HINT=/csound-install/lib + cmake --build build --parallel "$(nproc)" \ + --target cudaop1 cudaop2 cudaop3 cudaop4 cudaop5 + + - name: Stage plugins + run: | + mkdir -p package + cp build/src/CUDA/*.so package/ + + - name: Upload plugins + uses: actions/upload-artifact@v7.0.2 + with: + name: csound7-plugins-linux-cuda + path: package/ + if-no-files-found: error + + publish_release: + name: Publish release + if: ${{ (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main') && needs.update_version.outputs.release == 'true' }} + needs: [update_version, linux, linux_cuda, macos, windows] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Download Linux plugins + uses: actions/download-artifact@v8.0.2 + with: + name: csound7-plugins-linux + path: release/linux + + - name: Download Linux CUDA plugins + uses: actions/download-artifact@v8.0.2 + with: + name: csound7-plugins-linux-cuda + path: release/linux + + - name: Download macOS plugins + uses: actions/download-artifact@v8.0.2 + with: + name: csound7-plugins-macos + path: release/macos + + - name: Download Windows plugins + uses: actions/download-artifact@v8.0.2 + with: + name: csound7-plugins-windows + path: release/windows + + - name: Package release assets + run: | + version="${{ needs.update_version.outputs.version }}" + ( cd release/linux && zip -r "../../csound7-plugins-${version}-linux-x86_64.zip" . ) + ( cd release/macos && zip -r "../../csound7-plugins-${version}-macos.zip" . ) + ( cd release/windows && zip -r "../../csound7-plugins-${version}-windows.zip" . ) + ls -l csound7-plugins-*.zip + + - name: Create release + uses: softprops/action-gh-release@v3.0.3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + tag_name: ${{ needs.update_version.outputs.version }} + name: ${{ needs.update_version.outputs.version }} + generate_release_notes: true + prerelease: ${{ github.ref != 'refs/heads/main' }} + files: | + csound7-plugins-${{ needs.update_version.outputs.version }}-linux-x86_64.zip + csound7-plugins-${{ needs.update_version.outputs.version }}-macos.zip + csound7-plugins-${{ needs.update_version.outputs.version }}-windows.zip diff --git a/.github/workflows/plugins_build_7.yml b/.github/workflows/plugins_build_7.yml deleted file mode 100644 index b118242c..00000000 --- a/.github/workflows/plugins_build_7.yml +++ /dev/null @@ -1,567 +0,0 @@ -name: Csound 7 plugins build - -permissions: - contents: read - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -on: - push: - branches: - - develop - - main - pull_request: - branches: - - develop - - main - workflow_dispatch: - -env: - CSOUND_VERSION: 7.0.0 - FAUST_VERSION: 2.88.0 - VCPKG_BINARY_SOURCES: "clear;files,${{ github.workspace }}/vcpkg-cache,readwrite" - -jobs: - update_version: - name: Update plugin version - runs-on: ubuntu-latest - permissions: - contents: write - outputs: - version: ${{ steps.tag.outputs.new_tag }} - release: ${{ steps.check_pr.outputs.has_label }} - steps: - - name: Checkout source - uses: actions/checkout@v7.0.1 - with: - fetch-depth: 0 - - - name: Compute next version - id: tag - uses: anothrNick/github-tag-action@1.75.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - DEFAULT_BUMP: patch - DEFAULT_BRANCH: main - PRERELEASE: ${{ github.ref != 'refs/heads/main' }} - PRERELEASE_SUFFIX: beta - DRY_RUN: true - - - name: Check for release label - id: check_pr - uses: ./.github/actions/check-pr-label - with: - label: release - github_token: ${{ secrets.GITHUB_TOKEN }} - - linux: - name: Linux (ubuntu-latest) - needs: update_version - runs-on: ubuntu-latest - steps: - - name: Checkout source - uses: actions/checkout@v7.0.1 - - - name: Install Csound build dependencies - run: | - sudo apt-get update - sudo apt-get install -y \ - build-essential cmake pkg-config \ - libsndfile1-dev libasound2-dev libportaudio2 libportmidi-dev \ - libeigen3-dev libfluidsynth-dev libpng-dev \ - libwebsockets-dev libuv1-dev libhdf5-dev \ - ocl-icd-opencl-dev libtinfo-dev \ - libgtest-dev \ - flex bison - - - name: Cache Csound install - id: cache-csound - uses: actions/cache@v6.1.0 - with: - path: ~/csound-install - key: csound-${{ runner.os }}-${{ runner.arch }}-${{ env.CSOUND_VERSION }} - - - name: Build and install Csound - if: steps.cache-csound.outputs.cache-hit != 'true' - run: | - git clone --depth 1 --branch "$CSOUND_VERSION" \ - https://github.com/csound/csound.git "$RUNNER_TEMP/csound" - cmake -S "$RUNNER_TEMP/csound" -B "$RUNNER_TEMP/csound-build" \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX="$HOME/csound-install" \ - -DBUILD_TESTS=OFF \ - -DINSTALL_PYTHON_INTERFACE=OFF - cmake --build "$RUNNER_TEMP/csound-build" --parallel "$(nproc)" - cmake --install "$RUNNER_TEMP/csound-build" - - - name: Cache Faust - id: cache-faust - uses: actions/cache@v4 - with: - path: ~/faust - key: faust-${{ runner.os }}-${{ runner.arch }}-${{ env.FAUST_VERSION }} - - - name: Install Faust - if: steps.cache-faust.outputs.cache-hit != 'true' - run: | - mkdir -p "$HOME/faust" - curl -sL -o "$RUNNER_TEMP/libfaust.zip" \ - "https://github.com/grame-cncm/faust/releases/download/$FAUST_VERSION/libfaust-ubuntu-x86_64.zip" - curl -sL -o "$RUNNER_TEMP/faust-src.tar.gz" \ - "https://github.com/grame-cncm/faust/releases/download/$FAUST_VERSION/faust-$FAUST_VERSION.tar.gz" - unzip -q "$RUNNER_TEMP/libfaust.zip" -d "$HOME/faust" - tar xzf "$RUNNER_TEMP/faust-src.tar.gz" -C "$RUNNER_TEMP" \ - "faust-$FAUST_VERSION/architecture" "faust-$FAUST_VERSION/libraries" - mv "$RUNNER_TEMP/faust-$FAUST_VERSION/architecture" "$HOME/faust/include" - mv "$RUNNER_TEMP/faust-$FAUST_VERSION/libraries" "$HOME/faust/stdlib" - rm -f "$RUNNER_TEMP/libfaust.zip" "$RUNNER_TEMP/faust-src.tar.gz" - - - name: Configure plugin build - run: | - echo "CSOUND_INCLUDE_DIR_HINT=$HOME/csound-install/include/csound" >> "$GITHUB_ENV" - echo "CSOUND_LIBRARY_DIR_HINT=$HOME/csound-install/lib" >> "$GITHUB_ENV" - echo "FAUST_INCLUDE_DIR_HINT=$HOME/faust/include" >> "$GITHUB_ENV" - echo "FAUST_LIB_DIR_HINT=$HOME/faust/lib" >> "$GITHUB_ENV" - echo "FAUST_STDLIB_DIR_HINT=$HOME/faust/stdlib" >> "$GITHUB_ENV" - - - name: Build plugins - run: | - cmake -S 7.x -B build -DCMAKE_BUILD_TYPE=Release \ - -DFAUST_STATIC=ON \ - -DCSOUND_INCLUDE_DIR_HINT="$CSOUND_INCLUDE_DIR_HINT" \ - -DCSOUND_LIBRARY_DIR_HINT="$CSOUND_LIBRARY_DIR_HINT" \ - -DFAUST_INCLUDE_DIR_HINT="$FAUST_INCLUDE_DIR_HINT" \ - -DFAUST_LIB_DIR_HINT="$FAUST_LIB_DIR_HINT" \ - -DFAUST_STDLIB_DIR_HINT="$FAUST_STDLIB_DIR_HINT" - cmake --build build --parallel "$(nproc)" - - - name: Run plugin tests - run: ctest --test-dir build --output-on-failure - - - name: Stage plugins - run: | - mkdir -p package - cp build/src/chua/*.so \ - build/src/linear_algebra/*.so \ - build/src/fluidOpcodes/*.so \ - build/src/dssi4cs/*.so \ - build/src/image/*.so \ - build/src/websockets/*.so \ - build/src/hdf5/*.so \ - build/src/py/*.so \ - build/src/OpenCL/*.so \ - build/src/stk/*.so package/ - cp build/src/faustcsound/*.so package/ - mkdir -p package/stk/rawwaves - cp 7.x/src/stk/rawwaves/*.raw package/stk/rawwaves/ - mkdir -p package/faust - cp -R "$HOME/faust/stdlib/." package/faust/ - - - name: Upload plugins - uses: actions/upload-artifact@v7.0.2 - with: - name: csound7-plugins-linux - path: package/ - if-no-files-found: error - - macos: - name: macOS (macos-latest) - needs: update_version - runs-on: macos-latest - steps: - - name: Checkout source - uses: actions/checkout@v7.0.1 - - - name: Install Csound build dependencies - env: - HOMEBREW_NO_AUTO_UPDATE: 1 - run: | - brew install cmake ninja pkg-config bison flex libsndfile - echo "$(brew --prefix bison)/bin" >> "$GITHUB_PATH" - echo "$(brew --prefix flex)/bin" >> "$GITHUB_PATH" - - - name: Checkout 7.x/vcpkg submodule - run: git submodule update --init 7.x/vcpkg - - - name: Set up vcpkg - run: 7.x/vcpkg/bootstrap-vcpkg.sh -disableMetrics - - - name: Cache vcpkg binary cache - uses: actions/cache@v6.1.0 - with: - path: vcpkg-cache - key: vcpkg-macos-${{ github.run_id }} - restore-keys: vcpkg-macos- - - - name: Cache Csound install - id: cache-csound - uses: actions/cache@v6.1.0 - with: - path: ~/csound-install - key: csound-${{ runner.os }}-${{ runner.arch }}-${{ env.CSOUND_VERSION }} - - - name: Build and install Csound - if: steps.cache-csound.outputs.cache-hit != 'true' - run: | - git clone --depth 1 --branch "$CSOUND_VERSION" \ - https://github.com/csound/csound.git "$RUNNER_TEMP/csound" - cmake -S "$RUNNER_TEMP/csound" -B "$RUNNER_TEMP/csound-build" -G Ninja \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX="$HOME/csound-install" \ - -DCS_FRAMEWORK_DEST="$HOME/csound-install/Frameworks" \ - -DCMAKE_PREFIX_PATH="$(brew --prefix)" \ - -DBUILD_TESTS=OFF \ - -DBUILD_STATIC_LIBRARY=OFF \ - -DBUILD_VIRTUAL_KEYBOARD=OFF \ - -DBUILD_JAVA_INTERFACE=OFF \ - -DBUILD_PYTHON_INTERFACE=OFF \ - -DINSTALL_PYTHON_INTERFACE=OFF \ - -DBUILD_LUA_INTERFACE=OFF \ - -DBUILD_CSBEATS=OFF \ - -DUSE_LIBSAMPLERATE=OFF \ - -DUSE_CURL=OFF \ - -DUSE_GETTEXT=OFF \ - -DUSE_JACK=OFF \ - -DUSE_PORTAUDIO=OFF \ - -DUSE_PORTMIDI=OFF \ - -DUSE_MP3=OFF - cmake --build "$RUNNER_TEMP/csound-build" --parallel "$(sysctl -n hw.ncpu)" - cmake --install "$RUNNER_TEMP/csound-build" - - - name: Cache Faust - id: cache-faust - uses: actions/cache@v4 - with: - path: ~/faust - key: faust-${{ runner.os }}-${{ runner.arch }}-${{ env.FAUST_VERSION }} - - - name: Install Faust - if: steps.cache-faust.outputs.cache-hit != 'true' - run: | - if [ "$(uname -m)" = "arm64" ]; then - asset="Faust-$FAUST_VERSION-arm64.dmg" - else - asset="Faust-$FAUST_VERSION-x64.dmg" - fi - curl -sL -o "$RUNNER_TEMP/faust.dmg" \ - "https://github.com/grame-cncm/faust/releases/download/$FAUST_VERSION/$asset" - mkdir -p "$HOME/faust" "$RUNNER_TEMP/faust_dmg" - hdiutil attach "$RUNNER_TEMP/faust.dmg" \ - -mountpoint "$RUNNER_TEMP/faust_dmg" -nobrowse -quiet - root=$(dirname "$(find "$RUNNER_TEMP/faust_dmg" -maxdepth 2 -type d -name include | head -1)") - cp -R "$root/include" "$HOME/faust/include" - cp -R "$root/lib" "$HOME/faust/lib" - cp -R "$root/share/faust" "$HOME/faust/stdlib" - hdiutil detach "$RUNNER_TEMP/faust_dmg" -quiet - rm -f "$RUNNER_TEMP/faust.dmg" - - - name: Configure plugin build - run: | - framework="$HOME/csound-install/Frameworks/CsoundLib64.framework" - headers="$framework/Versions/7.0/Headers" - if [ ! -f "$headers/csound.h" ]; then - headers="$framework/Headers" - fi - echo "CSOUND_INCLUDE_DIR_HINT=$headers" >> "$GITHUB_ENV" - echo "CSOUND_FRAMEWORK_DIR_HINT=$HOME/csound-install/Frameworks" >> "$GITHUB_ENV" - echo "CSOUND_LIBRARY_DIR_HINT=$HOME/csound-install/Frameworks" >> "$GITHUB_ENV" - echo "FAUST_INCLUDE_DIR_HINT=$HOME/faust/include" >> "$GITHUB_ENV" - echo "FAUST_LIB_DIR_HINT=$HOME/faust/lib" >> "$GITHUB_ENV" - echo "FAUST_STDLIB_DIR_HINT=$HOME/faust/stdlib" >> "$GITHUB_ENV" - - - name: Build plugins - run: | - cmake -S 7.x -B build -DCMAKE_BUILD_TYPE=Release \ - -DUSE_VCPKG=ON \ - -DFAUST_STATIC=ON \ - -DCSOUND_INCLUDE_DIR_HINT="$CSOUND_INCLUDE_DIR_HINT" \ - -DCSOUND_FRAMEWORK_DIR_HINT="$CSOUND_FRAMEWORK_DIR_HINT" \ - -DCSOUND_LIBRARY_DIR_HINT="$CSOUND_LIBRARY_DIR_HINT" \ - -DFAUST_INCLUDE_DIR_HINT="$FAUST_INCLUDE_DIR_HINT" \ - -DFAUST_LIB_DIR_HINT="$FAUST_LIB_DIR_HINT" \ - -DFAUST_STDLIB_DIR_HINT="$FAUST_STDLIB_DIR_HINT" - cmake --build build --parallel "$(sysctl -n hw.ncpu)" - - - name: Stage plugins - run: | - mkdir -p package - cp build/src/chua/*.dylib \ - build/src/linear_algebra/*.dylib \ - build/src/fluidOpcodes/*.dylib \ - build/src/image/*.dylib \ - build/src/websockets/*.dylib \ - build/src/hdf5/*.dylib \ - build/src/py/*.dylib \ - build/src/OpenCL/*.dylib \ - build/src/stk/*.dylib package/ - cp build/src/faustcsound/*.dylib package/ - mkdir -p package/stk/rawwaves - cp 7.x/src/stk/rawwaves/*.raw package/stk/rawwaves/ - mkdir -p package/faust - cp -R "$HOME/faust/stdlib/." package/faust/ - - - name: Upload plugins - uses: actions/upload-artifact@v7.0.2 - with: - name: csound7-plugins-macos - path: package/ - if-no-files-found: error - - windows: - name: Windows (windows-latest) - needs: update_version - runs-on: windows-latest - defaults: - run: - shell: pwsh - steps: - - name: Checkout source - uses: actions/checkout@v7.0.1 - - - name: Install Csound build dependencies - run: choco install -y winflexbison3 - - - name: Clone Csound (with vcpkg) - run: | - git clone --recursive --depth 1 --branch "$env:CSOUND_VERSION" ` - https://github.com/csound/csound.git csound - - - name: Cache Csound install - id: cache-csound - uses: actions/cache@v6.1.0 - with: - path: ${{ runner.temp }}\csound-install - key: csound-${{ runner.os }}-${{ runner.arch }}-${{ env.CSOUND_VERSION }} - - - name: Bootstrap vcpkg (Csound) - if: steps.cache-csound.outputs.cache-hit != 'true' - run: .\csound\vcpkg\bootstrap-vcpkg.bat -disableMetrics - - - name: Checkout 7.x/vcpkg submodule - run: git submodule update --init 7.x/vcpkg - - - name: Bootstrap vcpkg (plugins) - run: .\7.x\vcpkg\bootstrap-vcpkg.bat -disableMetrics - - - name: Cache vcpkg binary cache - uses: actions/cache@v6.1.0 - with: - path: ${{ github.workspace }}\vcpkg-cache - key: vcpkg-windows-${{ github.run_id }} - restore-keys: vcpkg-windows- - - - name: Build and install Csound - if: steps.cache-csound.outputs.cache-hit != 'true' - run: | - cmake -S csound -B csound-build -A x64 ` - -DUSE_VCPKG=ON ` - -DCMAKE_INSTALL_PREFIX="$env:RUNNER_TEMP\csound-install" ` - -DBUILD_TESTS=OFF ` - -DBUILD_STATIC_LIBRARY=OFF ` - -DBUILD_VIRTUAL_KEYBOARD=OFF ` - -DBUILD_JAVA_INTERFACE=OFF ` - -DBUILD_PYTHON_INTERFACE=OFF ` - -DINSTALL_PYTHON_INTERFACE=OFF ` - -DBUILD_LUA_INTERFACE=OFF ` - -DBUILD_CSBEATS=OFF - cmake --build csound-build --config Release --parallel - cmake --install csound-build --config Release - - - name: Cache Faust - id: cache-faust - uses: actions/cache@v4 - with: - path: ~/faust - key: faust-${{ runner.os }}-${{ runner.arch }}-${{ env.FAUST_VERSION }} - - - name: Install Faust - if: steps.cache-faust.outputs.cache-hit != 'true' - run: | - $faustDir = Join-Path $env:USERPROFILE 'faust' - New-Item -ItemType Directory -Force -Path $faustDir | Out-Null - curl.exe -sL -o "$env:RUNNER_TEMP\faust.exe" ` - "https://github.com/grame-cncm/faust/releases/download/$env:FAUST_VERSION/Faust-$env:FAUST_VERSION-win64.exe" - & 'C:\Program Files\7-Zip\7z.exe' x "$env:RUNNER_TEMP\faust.exe" "-o$faustDir" -y | Out-Null - Remove-Item "$env:RUNNER_TEMP\faust.exe" - - - name: Configure plugin build - run: | - $install = Join-Path $env:RUNNER_TEMP 'csound-install' - $header = Get-ChildItem -Path $install -Recurse -File -Filter 'csound.h' | - Select-Object -First 1 - $lib = Get-ChildItem -Path $install -Recurse -File -Filter 'csound64.lib' | - Select-Object -First 1 - if (-not $header) { throw "csound.h not found under $install" } - if (-not $lib) { throw "csound64.lib not found under $install" } - "CSOUND_INCLUDE_DIR_HINT=$($header.DirectoryName)" >> $env:GITHUB_ENV - "CSOUND_LIBRARY_DIR_HINT=$($lib.DirectoryName)" >> $env:GITHUB_ENV - $faustDir = Join-Path $env:USERPROFILE 'faust' - "FAUST_INCLUDE_DIR_HINT=$faustDir\include" >> $env:GITHUB_ENV - "FAUST_LIB_DIR_HINT=$faustDir\lib" >> $env:GITHUB_ENV - "FAUST_STDLIB_DIR_HINT=$faustDir\share\faust" >> $env:GITHUB_ENV - - - name: Build plugins - run: | - cmake -S 7.x -B build -A x64 ` - -DUSE_VCPKG=ON ` - -DFAUST_STATIC=ON ` - -DCSOUND_INCLUDE_DIR_HINT="$env:CSOUND_INCLUDE_DIR_HINT" ` - -DCSOUND_LIBRARY_DIR_HINT="$env:CSOUND_LIBRARY_DIR_HINT" ` - -DFAUST_INCLUDE_DIR_HINT="$env:FAUST_INCLUDE_DIR_HINT" ` - -DFAUST_LIB_DIR_HINT="$env:FAUST_LIB_DIR_HINT" ` - -DFAUST_STDLIB_DIR_HINT="$env:FAUST_STDLIB_DIR_HINT" - cmake --build build --config Release --parallel - - - name: Stage plugins - run: | - $package = 'package' - New-Item -ItemType Directory -Force -Path $package | Out-Null - Get-ChildItem -Path build/src -Recurse -Include *.dll | - Where-Object { $_.FullName -match 'Release' } | - Copy-Item -Destination $package - $vcpkgBin = Join-Path 'build' 'vcpkg_installed\x64-windows-csound\bin' - if (Test-Path $vcpkgBin) { - Copy-Item (Join-Path $vcpkgBin '*.dll') -Destination $package -ErrorAction SilentlyContinue - } - $rawwaves = Join-Path $package 'stk/rawwaves' - New-Item -ItemType Directory -Force -Path $rawwaves | Out-Null - Copy-Item '7.x\src\stk\rawwaves\*.raw' -Destination $rawwaves - $faustOut = Join-Path $package 'faust' - New-Item -ItemType Directory -Force -Path $faustOut | Out-Null - Copy-Item "$env:USERPROFILE\faust\share\faust\*" -Destination $faustOut -Recurse - - - name: Upload plugins - uses: actions/upload-artifact@v7.0.2 - with: - name: csound7-plugins-windows - path: package/ - if-no-files-found: error - - linux_cuda: - name: Linux CUDA (ubuntu-latest) - needs: update_version - runs-on: ubuntu-latest - container: - image: nvidia/cuda:12.4.1-devel-ubuntu22.04 - steps: - - name: Checkout source - uses: actions/checkout@v7.0.1 - - - name: Install build dependencies - run: | - apt-get update - apt-get install -y --no-install-recommends \ - build-essential cmake git ca-certificates pkg-config \ - libsndfile1-dev libasound2-dev flex bison - - - name: Show CUDA toolchain - run: | - nvcc --version - nvidia-smi || true - - - name: Cache Csound install - id: cache-csound - uses: actions/cache@v6.1.0 - with: - path: /csound-install - key: csound-cuda-${{ runner.os }}-${{ runner.arch }}-${{ env.CSOUND_VERSION }} - - - name: Build and install Csound - if: steps.cache-csound.outputs.cache-hit != 'true' - run: | - git clone --depth 1 --branch "$CSOUND_VERSION" \ - https://github.com/csound/csound.git /tmp/csound - cmake -S /tmp/csound -B /tmp/csound-build \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=/csound-install \ - -DBUILD_TESTS=OFF \ - -DINSTALL_PYTHON_INTERFACE=OFF - cmake --build /tmp/csound-build --parallel "$(nproc)" - cmake --install /tmp/csound-build - - - name: Build CUDA plugins - run: | - cmake -S 7.x -B build -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_CUDA_OPCODES=ON \ - -DBUILD_CHUA_OPCODES=OFF \ - -DBUILD_DSSI_OPCODES=OFF \ - -DBUILD_FLUID_OPCODES=OFF \ - -DBUILD_HDF5_OPCODES=OFF \ - -DBUILD_IMAGE_OPCODES=OFF \ - -DBUILD_LINEAR_ALGEBRA_OPCODES=OFF \ - -DBUILD_PYTHON_OPCODES=OFF \ - -DBUILD_WEBSOCKET_OPCODE=OFF \ - -DBUILD_WIIMOTE_OPCODES=OFF \ - -DBUILD_P5GLOVE_OPCODES=OFF \ - -DCMAKE_CUDA_ARCHITECTURES="50;60;70;75;80;86" \ - -DCSOUND_INCLUDE_DIR_HINT=/csound-install/include/csound \ - -DCSOUND_LIBRARY_DIR_HINT=/csound-install/lib - cmake --build build --parallel "$(nproc)" \ - --target cudaop1 cudaop2 cudaop3 cudaop4 cudaop5 - - - name: Stage plugins - run: | - mkdir -p package - cp build/src/CUDA/*.so package/ - - - name: Upload plugins - uses: actions/upload-artifact@v7.0.2 - with: - name: csound7-plugins-linux-cuda - path: package/ - if-no-files-found: error - - publish_release: - name: Publish release - if: ${{ (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main') && needs.update_version.outputs.release == 'true' }} - needs: [update_version, linux, linux_cuda, macos, windows] - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - name: Download Linux plugins - uses: actions/download-artifact@v8.0.2 - with: - name: csound7-plugins-linux - path: release/linux - - - name: Download Linux CUDA plugins - uses: actions/download-artifact@v8.0.2 - with: - name: csound7-plugins-linux-cuda - path: release/linux - - - name: Download macOS plugins - uses: actions/download-artifact@v8.0.2 - with: - name: csound7-plugins-macos - path: release/macos - - - name: Download Windows plugins - uses: actions/download-artifact@v8.0.2 - with: - name: csound7-plugins-windows - path: release/windows - - - name: Package release assets - run: | - version="${{ needs.update_version.outputs.version }}" - ( cd release/linux && zip -r "../../csound7-plugins-${version}-linux-x86_64.zip" . ) - ( cd release/macos && zip -r "../../csound7-plugins-${version}-macos.zip" . ) - ( cd release/windows && zip -r "../../csound7-plugins-${version}-windows.zip" . ) - ls -l csound7-plugins-*.zip - - - name: Create release - uses: softprops/action-gh-release@v3.0.3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - tag_name: ${{ needs.update_version.outputs.version }} - name: ${{ needs.update_version.outputs.version }} - generate_release_notes: true - prerelease: ${{ github.ref != 'refs/heads/main' }} - files: | - csound7-plugins-${{ needs.update_version.outputs.version }}-linux-x86_64.zip - csound7-plugins-${{ needs.update_version.outputs.version }}-macos.zip - csound7-plugins-${{ needs.update_version.outputs.version }}-windows.zip diff --git a/.gitignore b/.gitignore index d91c3aa4..8754df97 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ build dist -csound6-plugins-win_x86_64-* node_modules/ result* *.tgz diff --git a/.gitmodules b/.gitmodules index 4e57bf2b..a0a57f3d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "vcpkg"] - path = 6.x/vcpkg - url = https://github.com/microsoft/vcpkg.git -[submodule "7.x/vcpkg"] - path = 7.x/vcpkg + path = vcpkg url = https://github.com/microsoft/vcpkg.git diff --git a/6.x/CMakeLists.txt b/6.x/CMakeLists.txt deleted file mode 100644 index 3cea4fa0..00000000 --- a/6.x/CMakeLists.txt +++ /dev/null @@ -1,317 +0,0 @@ -cmake_minimum_required(VERSION 3.5) -cmake_policy(SET CMP0077 NEW) - -option(USE_VCPKG "Use VCPKG to download and manage dependencies" OFF) - -if (USE_VCPKG) - # Detect correct triplet based on CMake env - if (WIN32) - set(VCPKG_HOST_TRIPLET "x64-windows-csound" CACHE STRING "") - set(VCPKG_TARGET_TRIPLET "x64-windows-csound") - set(CSOUND_INCLUDE_DIR_HINT "C:/Program Files/Csound6_x64") - elseif(APPLE) - set(VCPKG_HOST_TRIPLET "x64-osx" CACHE STRING "") - set(VCPKG_TARGET_TRIPLET "x64-osx") - elseif (UNIX) - set(VCPKG_HOST_TRIPLET "x64-linux" CACHE STRING "") - set(VCPKG_TARGET_TRIPLET "x64-linux") - endif() - - set(VCPKG_FEATURE_FLAGS versions) - set(X_VCPKG_APPLOCAL_DEPS_INSTALL ON) - set(VCPKG_OVERLAY_TRIPLETS ${CMAKE_CURRENT_SOURCE_DIR}/) - set(VCPKG_OVERLAY_PORTS ${CMAKE_CURRENT_SOURCE_DIR}/) - set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake - CACHE STRING "Vcpkg toolchain file") -endif() - -project(Csound-plugins) - -if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") - set(CMAKE_COMPILER_IS_CLANG 1) -endif() - -set(APIVERSION "6.0") - -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_MACOSX_RPATH 1) -set(CMAKE_VERBOSE_MAKEFILE ON) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") - -find_package(CSOUND) - -if(NOT CSOUND_INCLUDE_DIRS) - message(FATAL_ERROR "Csound header files are required") -endif() - -include(TestBigEndian) -include(CheckFunctionExists) -include(CheckCCompilerFlag) -include(CheckCXXCompilerFlag) - -### COMPILER OPTIMIZATION FLAGS -option(USE_COMPILER_OPTIMIZATIONS "Use the default Csound compiler optimization flags" ON) -if(USE_COMPILER_OPTIMIZATIONS) - include(${CMAKE_SOURCE_DIR}/cmake/CompilerOptimizations.cmake) -endif() - -##/Library/Frameworks/CsoundLib64.framework/Versions/Current/Resources/Opcodes64 - -if(APPLE) - message(STATUS "Building on OSX") - set(OSX_VERSION " ") -endif() - -## USER OPTIONS ## -# Optional targets, they should all default to ON (check_deps will disable them if not possible to build) -option(USE_DOUBLE "Set to use double-precision floating point for audio samples." ON) -option(USE_LRINT "Use lrint/lrintf for converting floating point values to integers." ON) -option(BUILD_RELEASE "Build for release" ON) -option(USE_GIT_COMMIT "Show the git commit in version information" ON) -option(REQUIRE_PTHREADS "For non-Windows systems, set whether Csound will use threads or not" ON) - -# in Release configuration, set NDEBUG -if(${CMAKE_BUILD_TYPE} MATCHES "Release") - message("-----> Release mode") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG") -elseif(${CMAKE_BUILD_TYPE} MATCHES "Debug") - message("-----> Debug mode") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBETA") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBETA") -endif() - -# set -Werror if in Debug configuration -if(NOT MSVC AND NOT WASM) - set(CMAKE_CXX_FLAGS_RELEASE "-O3 ") - set(CMAKE_C_FLAGS_RELEASE "-O3 ") - if(${CMAKE_BUILD_TYPE} MATCHES "Debug") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-missing-field-initializers") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wno-missing-field-initializers") - endif() -endif() - -if(NOT MSVC AND REQUIRE_PTHREADS) - # Use ladder of if's to support older CMake versions (i.e., travis) - find_library(PTHREAD_LIBRARY winpthread-1) - - if(NOT PTHREAD_LIBRARY) - find_library(PTHREAD_LIBRARY pthread) - endif() - - if(NOT PTHREAD_LIBRARY) - find_library(PTHREAD_LIBRARY pthreadGC2) - endif() - - if(NOT (PTHREAD_LIBRARY OR HAIKU)) - # pthreads are built in to Haiku - message(STATUS "Csound requires the pthread library") - endif() - - #FIXME this variable is for required include directories, possible bug - list(APPEND CMAKE_REQUIRED_INCLUDES pthread.h) - if (NOT HAIKU) - set(CMAKE_REQUIRED_LIBRARIES pthread) - endif() -endif() - -if(CMAKE_SYSTEM_NAME MATCHES "Linux") - set(LINUX YES) -else() - set(LINUX NO) -endif() - -set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}) -check_c_compiler_flag(-fvisibility=hidden HAS_VISIBILITY_HIDDEN) -check_cxx_compiler_flag(-fvisibility=hidden HAS_CXX_VISIBILITY_HIDDEN) - -if (HAS_VISIBILITY_HIDDEN) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") -endif() - -if (HAS_CXX_VISIBILITY_HIDDEN) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") -endif() - -check_c_compiler_flag(-std=gnu99 HAS_GNU99) -if (HAS_GNU99) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") -endif() - -if (HAS_CXX_VISIBILITY_HIDDEN) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") -endif() - -if(LINUX) - option(USE_LIB64 "Set to on to set installation directory for libraries to lib64" OFF) - - if(USE_LIB64) - set(LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib64") - add_definitions("-DLIB64") - else() - set(LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib") - endif() - - message(STATUS "LIBRARY INSTALL DIR: ${LIBRARY_INSTALL_DIR}") -endif() - -# plugin install directories (CS_USER_PLUGIN on MacOs/Windows) -if(USE_DOUBLE) - message(STATUS "Building with 64-bit floats") - if(APPLE) - set(PLUGIN_INSTALL_DIR "$ENV{HOME}/Library/csound/${APIVERSION}/plugins64") - elseif(LINUX) - set(PLUGIN_INSTALL_DIR "${LIBRARY_INSTALL_DIR}/csound/plugins64-${APIVERSION}") - elseif(MSVC) - set(PLUGIN_INSTALL_DIR "$ENV{LOCALAPPDATA}/csound/${APIVERSION}/plugins64") - endif() -else() - message(STATUS "Building with 32-bit floats") - if(APPLE) - set(PLUGIN_INSTALL_DIR "$ENV{HOME}/Library/csound/${APIVERSION}/plugins") - elseif(LINUX) - set(PLUGIN_INSTALL_DIR "${LIBRARY_INSTALL_DIR}/csound/plugins-${APIVERSION}") - elseif(MSVC) - set(PLUGIN_INSTALL_DIR "$ENV{LOCALAPPDATA}/csound/${APIVERSION}/plugins") - endif() -endif() - -message("-- Csound headers: ${CSOUND_INCLUDE_DIR}") -if(APPLE) - message("-- Csound framework: ${CSOUND_FRAMEWORK}") -endif() -message("-- Plugins to be installed at: ${PLUGIN_INSTALL_DIR}") - -# Checks if dependencies for an enabled target are fulfilled. -# If FAIL_MISSING is true and the dependencies are not fulfilled, -# it will abort the cmake run. -# If FAIL_MISSING is false, it will set the option to OFF. -# If the target is not enabled, it will do nothing. -# example: check_deps(BUILD_NEW_PARSER FLEX_EXECUTABLE BISON_EXECUTABLE) -function(check_deps option) - if(${option}) - set(i 1) - while( ${i} LESS ${ARGC} ) - set(dep ${ARGV${i}}) - if(NOT ${dep}) - if(FAIL_MISSING) - message(FATAL_ERROR - "${option} is enabled, but ${dep}=\"${${dep}}\"") - else() - message(STATUS "${dep}=\"${${dep}}\", so disabling ${option}") - set(${option} OFF PARENT_SCOPE) - # Set it in the local scope too - set(${option} OFF) - endif() - endif() - math(EXPR i "${i}+1") - endwhile() - endif() - if(${option}) - message(STATUS "${option} is enabled.") - else() - message(STATUS "${option} is disabled.") - endif() -endfunction(check_deps) - -# Utility function to make plugins. All plugin targets should use this as it -# sets up output directory set in top-level CmakeLists.txt -# and adds the appropriate install target -# -# libname - name of library to produce -# srcs - list of src files (must be quoted if a list) -# extralibs (OPTIONAL) - extra libraries to link the plugin to -# -# NB - this was moved here as it needs some VARS defined above -# for setting up the framework -function(make_plugin libname srcs) - if(APPLE) - add_library(${libname} SHARED ${srcs}) - else() - add_library(${libname} MODULE ${srcs}) - endif() - - set(i 2) - while( ${i} LESS ${ARGC} ) - target_link_libraries(${libname} PRIVATE ${ARGV${i}}) - math(EXPR i "${i}+1") - endwhile() - - install(TARGETS ${libname} - LIBRARY DESTINATION "${PLUGIN_INSTALL_DIR}" - ARCHIVE DESTINATION "${PLUGIN_INSTALL_DIR}" ) -endfunction(make_plugin) - -#checking pthread functions -if(REQUIRE_PTHREADS AND (PTHREAD_LIBRARY OR HAIKU)) - - #list(APPEND libcsound_CFLAGS -DHAVE_PTHREAD) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_PTHREAD") - - check_function_exists(pthread_spin_lock PTHREAD_SPIN_LOCK_EXISTS) - check_function_exists(pthread_barrier_init PTHREAD_BARRIER_INIT_EXISTS) - - if(PTHREAD_SPIN_LOCK_EXISTS) - list(APPEND libcsound_CFLAGS -DHAVE_PTHREAD_SPIN_LOCK) - endif() - - if(PTHREAD_BARRIER_INIT_EXISTS) - list(APPEND libcsound_CFLAGS -DHAVE_PTHREAD_BARRIER_INIT) - endif() -endif() - -# Linux does not have a separate libintl, it is part of libc -set(LIBINTL_AVAIL (LIBINTL_LIBRARY OR LINUX)) - -if(LINUX) - message(STATUS "Building on Linux.") - add_definitions(-DLINUX -DPIPES -DNO_FLTK_THREADS -D_GNU_SOURCE -DHAVE_SOCKETS) - list(APPEND libcsound_LIBS ${MATH_LIBRARY} dl) - - find_library(LIBRT_LIBRARY rt) - - if(LIBRT_LIBRARY) - list(APPEND libcsound_LIBS ${LIBRT_LIBRARY}) - message(STATUS " ADDING LIBRT LIBRARY: ${LIBRT_LIBRARY}.") - endif() - - find_library(LIBEXECINFO_LIBRARY execinfo) - - if(LIBEXECINFO_LIBRARY) - list(APPEND libcsound_LIBS ${LIBEXECINFO_LIBRARY}) - message(STATUS " ADDING LIBEXECINFO LIBRARY: ${LIBEXECINFO_LIBRARY}.") - endif() -endif() - -if(APPLE AND NOT IOS) - add_definitions(-DMACOSX -DPIPES -DNO_FLTK_THREADS -DHAVE_SOCKETS) - find_library(ACCELERATE_LIBRARY Accelerate) - find_path(VECLIB_PATH "Accelerate/Accelerate.h") - include_directories(${VECLIB_PATH}) - list(APPEND libcsound_LIBS ${MATH_LIBRARY} dl ${ACCELERATE_LIBRARY}) -endif() - -if(WIN32) - add_definitions(-DWIN32) -endif() - -add_subdirectory(./src/chua) -add_subdirectory(./src/faustcsound) -add_subdirectory(./src/image) -add_subdirectory(./src/py) -add_subdirectory(./src/widgets) - -if(BUILD_ABLETON_LINK_OPCODES) -add_subdirectory(./src/AbletonLinkOpcodes) -endif() -add_subdirectory(./src/stk) -add_subdirectory(./src/CUDA) -add_subdirectory(./src/opencl) -add_subdirectory(./src/websockets) -add_subdirectory(./src/hdf5) -add_subdirectory(./src/linear_algebra) -add_subdirectory(./src/mp3) -add_subdirectory(./src/wiimote) -add_subdirectory(./src/p5glove) -add_subdirectory(./src/jackops) -add_subdirectory(./src/fluidOpcodes) diff --git a/6.x/README.md b/6.x/README.md deleted file mode 100644 index f251e7d3..00000000 --- a/6.x/README.md +++ /dev/null @@ -1,114 +0,0 @@ -Plugins for Csound 6.x -======= - -Currently, the plugins available in this tree are - -- AbletonLive Link (requires Ableton link) - **link_create link_enable link_is_enabled link_tempo_set link_tempo_get link_beat_get link_metro link_beat_request link_beat_force** - -- chua (requires Eigen library, header-only) - **chuap** - -- Faust (requires libfaust) - **faustgen faustcompile faustaudio faustdsp faustplay faustctl** - -- image (requires libpng) - **imageload imagesave imagecreate imagesize imagegetpixel imagesetpixel imagefree** - -- py (requires a Python 3.x installation with dev libs) - **Many opcodes to call Python code** - -- widgets (requires the FLTK LIB) -**FLTK-based widgets.** -NB: These opcodes do not work correctly on MacOS due -to incompatibilities with the operating system. - -- virtual keyboard (requires the FLTK LIB) -**Virtual MIDI keyboard midi backend** - -- STK opcodes (requires STK library) -**Physical model opcodes using the STK library** - - -Install location --------------- -The CMake scripts in this repository use the default CS_USER_PLUGIN -location on MacOS and Windows as defined in the Csound build, or a -library instalation directory (customisable) on LINUX. These are: - -- LINUX: depends on both `CMAKE_INSTALL_PREFIX` and `USE_LIB64`. It is then installed in: - * if `USE_LIB64=1` then to - * for doubles: `${CSOUND_INSTALL_PREFIX}/lib64/csound/plugins64-${APIVERSION}` - * for floats: `${CSOUND_INSTALL_PREFIX}/lib64/csound/plugins-${APIVERSION}` (floats)` - * if `USE_LIB64=0` then to - * for doubles: `${CSOUND_INSTALL_PREFIX}/lib/csound/plugins64-${APIVERSION}` - * for floats: `${CSOUND_INSTALL_PREFIX}/lib/csound/plugins-${APIVERSION}` - -- MACOS: - * For doubles: `$HOME/Library/csound/${APIVERSION}/plugins64` - * For floats: `$HOME/Library/csound/${APIVERSION}/plugins` -- Windows: - * For doubles: `%LOCALAPPDATA%\csound\${APIVERSION}\plugins64` - * For floats: `%LOCALAPPDATA%\csound\${APIVERSION}\plugins` - - -Build Instructions for Linux and MacOS ---- - -The build requires Csound to be installed, as well as CMake. With this -in place, you can do : - -``` -$ git clone https://github.com/csound/plugins.git -$ cd plugins -$ mkdir build -$ cd build -$ cmake ../ -$ make -``` - -By default, all the plugins are built. If one wants to exclude a -plugin from the build process, one can pass an option to the cmake command. -For example, to exclude the chua plugin, the `cmake` command would be: - -``` -$ cmake -DBUILD_CHUA_OPCODES=OFF ../ -``` - -For the FLTK dependent plugins, the configuration variable used is -`USE_FLTK`. - -To install the opcodes you have built - -``` -$ make install -``` - -Depending on your permissions, you might need to prepend `sudo` to -these commands. After the first build the plugins can be updated with - -``` -$ git pull -$ make -$ make install -``` - -using `sudo` in the last step if raised permissions are needed. On -Linux, the installation location can be set with the relevant CMake -variables as indicated above. - -Csound Location ------------- -CMake will normally find the installed Csound headers (and library) -automatically. However, if your Csound headers and library are not -placed in the usual locations, you can use the following CMake option variables -to tell CMake where they are: - -``` -CSOUND_INCLUDE_DIR_HINT -``` -and - -``` -CSOUND_LIBRARY_DIR_HINT -``` diff --git a/6.x/cmake/Modules/FindCSOUND.cmake b/6.x/cmake/Modules/FindCSOUND.cmake deleted file mode 100644 index d83c0c05..00000000 --- a/6.x/cmake/Modules/FindCSOUND.cmake +++ /dev/null @@ -1,65 +0,0 @@ -# Try to find the Csound library. -# Once done this will define: -# CSOUND_FOUND - System has the Csound library -# CSOUND_INCLUDE_DIRS - The Csound include directories. -# CSOUND_LIBRARIES - The libraries needed to use the Csound library. - -if(APPLE) - find_path(CSOUND_INCLUDE_DIR csound.h - HINTS - "$ENV{HOME}/Library/Frameworks/CsoundLib64.framework/Headers" - "$ENV{HOME}/Library/Frameworks/CsoundLib.framework/Headers" - /Library/Frameworks/CsoundLib64.framework/Headers - /Library/Frameworks/CsoundLib.framework/Headers - ${CSOUND_INCLUDE_DIR_HINT} - ) - - find_path(CSOUND_FRAMEWORK CsoundLib64 - HINTS - "$ENV{HOME}/Library/Frameworks/CsoundLib64.framework" - /Library/Frameworks/CsoundLib64.framework - ${CSOUND_FRAMEWORK_DIR_HINT} - ) - - find_path(CSOUND_FRAMEWORK32 CsoundLib - HINTS - "$ENV{HOME}/Library/Frameworks/CsoundLib64.framework" - "$ENV{HOME}/Library/Frameworks/CsoundLib.framework" - /Library/Frameworks/CsoundLib64.framework - /Library/Frameworks/CsoundLib.framework - ${CSOUND_FRAMEWORK32_DIR_HINT} - ) -else() - find_path(CSOUND_INCLUDE_DIR csound.h - PATH_SUFFIXES csound - HINTS ${CSOUND_INCLUDE_DIR_HINT} - ) -endif() - -if(APPLE) - find_library(CSOUND_LIBRARY - NAMES CsoundLib64 - HINTS - /Library/Frameworks/CsoundLib64.framework/ - "$ENV{HOME}/Library/Frameworks/CsoundLib64.framework" - ${CSOUND_LIBRARY_DIR_HINT} - ) -else() - find_library(CSOUND_LIBRARY - NAMES csound64 csound - HINTS ${CSOUND_LIBRARY_DIR_HINT} - ) -endif() - -include(FindPackageHandleStandardArgs) - -# handle the QUIETLY and REQUIRED arguments and set CSOUND_FOUND to TRUE -# if all listed variables are TRUE -find_package_handle_standard_args(CSOUND - CSOUND_LIBRARY CSOUND_INCLUDE_DIR -) - -mark_as_advanced(CSOUND_INCLUDE_DIR CSOUND_LIBRARY) - -set(CSOUND_INCLUDE_DIRS ${CSOUND_INCLUDE_DIR}) -set(CSOUND_LIBRARIES ${CSOUND_LIBRARY}) diff --git a/6.x/cmake/Modules/FindFAUST.cmake b/6.x/cmake/Modules/FindFAUST.cmake deleted file mode 100644 index d1d329e5..00000000 --- a/6.x/cmake/Modules/FindFAUST.cmake +++ /dev/null @@ -1,59 +0,0 @@ -# Find Faust2 -include(FindPackageHandleStandardArgs) - -find_path(FAUST_INCLUDE_DIR faust/dsp/llvm-dsp.h - HINTS - C:/Program Files/Faust/include/ - /opt/lib/faust/architecture/ - /usr/lib/faust/architecture/ - /usr/local/lib/faust/architecture/ - "${FAUST_INCLUDE_DIR_HINT}" -) - -find_library(FAUST_LIBRARY - NAMES - libfaust.so - libfaust.dylib - faust.dll - faust - libfaust - HINTS - "${FAUST_LIB_DIR_HINT}" -) - -find_package_handle_standard_args(FAUST FAUST_INCLUDE_DIR FAUST_LIBRARY) - -if(FAUST_FOUND) - set(FAUST_LIBRARIES ${FAUST_LIBRARY}) - set(FAUST_INCLUDE_DIRS ${FAUST_INCLUDE_DIR}) - - if("${FAUST_LIBRARY}" MATCHES ".*\\.a") - # This is a static build of faust, hence - # we have to add all the LLVM flags... - - find_program(LLVM_CONFIG llvm-config - HINTS - /usr/bin - /usr/local/bin - /usr/local/opt/llvm/bin - ) - - if(NOT LLVM_CONFIG) - message(WARNING "Using a static Faust library requires LLVM tooling to be present in the path.") - UNSET(FAUST_FOUND) - else() - exec_program(${LLVM_CONFIG} ARGS --includedir OUTPUT_VARIABLE LLVM_DIR) - exec_program(${LLVM_CONFIG} ARGS --libs OUTPUT_VARIABLE LLVM_LIBS) - exec_program(${LLVM_CONFIG} ARGS --version OUTPUT_VARIABLE LLVM_VERSION) - exec_program(${LLVM_CONFIG} ARGS --ldflags OUTPUT_VARIABLE LLVM_LDFLAGS) - - set(LLVM_VERSION LLVM_${LLVM_VERSION_MAJOR}${LLVM_VERSION_MINOR}) - - find_package(OpenSSL REQUIRED) - set(FAUST_LIBRARIES ${FAUST_LIBRARIES} dl ${OPENSSL_LIBRARIES} ncurses z ${LLVM_LDFLAGS} ${LLVM_LIBS} ) - endif() - endif() -else() - set(FAUST_LIBRARIES) - set(FAUST_INCLUDE_DIRS) -endif() diff --git a/6.x/cmake/Modules/FindGMM.cmake b/6.x/cmake/Modules/FindGMM.cmake deleted file mode 100644 index 1b4d3596..00000000 --- a/6.x/cmake/Modules/FindGMM.cmake +++ /dev/null @@ -1,20 +0,0 @@ -# Try to find the GMM library. -# Once done this will define: -# GMM_FOUND - System has the GMM library. -# GMM_VERSION -# GMM_INCLUDE_DIR - The GMM include directories. -# GMM_HAS_VECTOR_OSTREAM - Wether GMM defines operator<< for std::vector - -if (GMM_INCLUDE_DIR) - # in cache already - set(GMM_FOUND TRUE) -else (GMM_INCLUDE_DIR) - find_path(GMM_INCLUDE_DIR NAMES gmm/gmm.h - PATHS - ${INCLUDE_INSTALL_DIR} - ${GMM_INCLUDE_PATH} - ) - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(GMM DEFAULT_MSG GMM_INCLUDE_DIR) - mark_as_advanced(GMM_INCLUDE_DIR) -endif(GMM_INCLUDE_DIR) \ No newline at end of file diff --git a/6.x/installer/macosx/release-build.sh b/6.x/installer/macosx/release-build.sh deleted file mode 100644 index a7af92de..00000000 --- a/6.x/installer/macosx/release-build.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/sh -# set -x -# directories -export OPVERSION=$2 -export BRANCH_NAME=$1 -echo "Using branch: $BRANCH_NAME" -export RELEASE_DIR=`date +%Y-%m-%d-%H%M%S` -export BASEDIR=`pwd`/$RELEASE_DIR -export INSTALLDIR=Package_Contents -export DMGNAME="Csound6-Plugins-MacOS_x86_64-${OPVERSION}.dmg" - -# build -mkdir $RELEASE_DIR -cd $RELEASE_DIR -export BUILD_DIR=build -mkdir $BUILD_DIR -git clone -b $BRANCH_NAME https://github.com/csound/plugins -cd $BUILD_DIR -cmake ../plugins -DCMAKE_BUILD_TYPE=Release -make - -# zip install - -# image opcodes (LIB_PNG needs to be set correctly) -echo "--- making image zip ---" -cd .. -export IMAGE_DIR=$BUILD_DIR/image -export LIB_PNG=/usr/local/lib/libpng16.16.dylib -cp $IMAGE_DIR/libimage.dylib . -cp $LIB_PNG . -install_name_tool -id libpng16.16.dylib libpng16.16.dylib -install_name_tool -change /usr/local/lib/libpng16.16.dylib libpng16.16.dylib libimage.dylib -mkdir image -mv *.dylib image -zip image.zip image/*.dylib - -# chua -echo "--- making chua zip ---" -export CHUA_DIR=$BUILD_DIR/chua -mkdir chua -cp $CHUA_DIR/libchua.dylib chua -zip chua.zip chua/*.dylib - -# faustcsound -echo "--- making faustcsound zip ---" -export FCS_DIR=$BUILD_DIR/faustcsound -mkdir faustcsound -cp $FCS_DIR/libfaustcsound.dylib faustcsound -zip faustcsound.zip faustcsound/*.dylib - -# python opcodes (python PYVERSION used needs to be set correctly) -echo "--- making py zip ---" -export PYVERSION=3.9 -export PY_ZIP_DIR="python${PYVERSION}-opcodes" -export PY_DIR=$BUILD_DIR/py -mkdir $PY_ZIP_DIR -cp $PY_DIR/libpy.dylib $PY_ZIP_DIR/libpy${PYVERSION}.dylib -zip $PY_ZIP_DIR.zip $PY_ZIP_DIR/*.dylib - -# installer (ALL) -cd $BASEDIR -mkdir -p $INSTALLDIR/tmp/csound - -cp chua/*.dylib $INSTALLDIR/tmp/csound/. -cp faustcsound/*.dylib $INSTALLDIR/tmp/csound/. -cp $PY_ZIP_DIR/*.dylib $INSTALLDIR/tmp/csound/. -cp image/*.dylib $INSTALLDIR/tmp/csound/. - -mkdir dmgsrc -pkgbuild --identifier com.csound.csound6Environment.csoundOps64 --root $INSTALLDIR --version 1 --scripts ../scripts dmgsrc/CsoundPlugins64.pkg -hdiutil create $DMGNAME -srcfolder dmgsrc -fs HFS+ - -open $BASEDIR diff --git a/6.x/installer/macosx/scripts/postinstall b/6.x/installer/macosx/scripts/postinstall deleted file mode 100755 index 3c7469f8..00000000 --- a/6.x/installer/macosx/scripts/postinstall +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -set -x -if [ -d "$HOME/Library/csound/6.0/plugins64/" ]; then - mv /tmp/csound/*.dylib $HOME/Library/csound/6.0/plugins64/. -else - mkdir -p $HOME/Library/csound/6.0/plugins64 - mv /tmp/csound/*.dylib $HOME/Library/csound/6.0/plugins64/. -fi -chown -R $USER $HOME/Library/csound - diff --git a/6.x/installer/win64/Installer.iss b/6.x/installer/win64/Installer.iss deleted file mode 100644 index 12763dc1..00000000 --- a/6.x/installer/win64/Installer.iss +++ /dev/null @@ -1,104 +0,0 @@ -; Cabbage Installer Script, Copyright Rory Walsh 2017. - -;swap this with plugin name -#define MyAppName "Csound Plugins" -#define Manufacturer "Csound" -#define OPVERSION "1.0" -#define AppMinVersion GetEnv("CSOUND_VERSION") -#define BuildNumber GetEnv("GITHUB_RUN_NUMBER") - -[Setup] -; NOTE: The value of AppId uniquely identifies this application. -; Do not use the same AppId value in installers for other applications. -; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) -AppId={{0E50FA48-4C41-4D27-A742-C77D1A3A3905} -AppName={#MyAppName} -AppVersion={#OPVERSION} -DefaultDirName={localappdata}\csound\6.0\ -DisableDirPage=no -DisableProgramGroupPage=yes -UsePreviousAppDir=no - -;if you want to add a license.. -;LicenseFile= "../LICENSE" - -;swap this with plugin name -OutputBaseFilename=csound6-plugins-win_x86_64-{#AppMinVersion}-{#BuildNumber} - -;to add install icon -;SetupIconFile=icon.ico -Compression=lzma -SolidCompression=yes -ChangesEnvironment=yes - - -[Components] -Name: "core"; Description: "Install all plugins"; Types: full custom; Flags: fixed - -[Languages] -Name: "english"; MessagesFile: "compiler:Default.isl" -Name: "french"; MessagesFile: "compiler:Languages\French.isl" -Name: "german"; MessagesFile: "compiler:Languages\German.isl" -Name: "norwegian"; MessagesFile: "compiler:Languages\Norwegian.isl" - -; add files - dlls go standard location, or one of the users choosing, csd and other reousrce go to program data -[Files] -Source: "..\..\build\src\AbletonLinkOpcodes\Release\ableton_link_opcodes.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; -Source: "..\..\build\src\chua\Release\chua.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; -Source: "..\..\build\src\image\Release\image.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; -Source: "..\..\build\src\py\Release\py.dll"; DestDir: "{app}\plugins64"; Flags: ignoreversion; Components: core; Permissions: users-full; -Source: "..\..\build\src\stk\Release\stkops.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; -Source: "..\..\build\src\websockets\Release\websocketIO.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; - -; faust -Source: "..\..\build\src\faustcsound\Release\faustcsound.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; -Source: "C:\Program Files\Faust\lib\faust.dll"; DestDir: "{autopf64}\Csound6_x64\bin\"; Flags: ignoreversion; Components: core; Permissions: users-full; - -; widgets -Source: "..\..\build\src\widgets\Release\virtual.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; -Source: "..\..\build\src\widgets\Release\widgets.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; - -; fluidsynth -Source: "..\..\build\src\fluidOpcodes\Release\fluidOpcodes.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; -Source: "..\..\build\src\fluidOpcodes\Release\glib-2.0-0.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; -Source: "..\..\build\src\fluidOpcodes\Release\iconv-2.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; -Source: "..\..\build\src\fluidOpcodes\Release\intl-8.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; -Source: "..\..\build\src\fluidOpcodes\Release\libfluidsynth-3.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; -Source: "..\..\build\src\fluidOpcodes\Release\pcre2-8.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; - -; hdf5 -Source: "..\..\build\src\hdf5\Release\hdf5ops.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; -Source: "..\..\build\src\hdf5\Release\zlib1.dll"; DestDir: "{app}\plugins64\"; Flags: ignoreversion; Components: core; Permissions: users-full; - -[Tasks] -;Name: modifypath; Description: &Add application directory to your PATH environment variable (recommended); - -[Code] -var - NewPage: TWizardPage; - -const - installerMessage = -'This installer will install the Python, Faust, Image, Chua and Ableton Link ' + #13#10 + -'plugin opcodes for Csound.' + #13#10 + #13#10 + -'Opcodes will be installed to C:\Users\\AppData\Local\csound\6.0\plugins64' + #13#10 + -'' + #13#10 + -'Csound should detect and load these plugins whenever it runs. The Faust library will' + #13#10 + -'be installed to C:/Program Files/Csound_x64/bin. If you do not have Csound installed' + #13#10 + -'at this location, please move the faust.dll file after installation'; - - -procedure InitializeWizard(); -var - DescLabel: TNewStaticText ; -begin - NewPage := CreateCustomPage(wpWelcome, 'Csound Plugins Installer', - '') - DescLabel := TNewStaticText .Create(NewPage); - DescLabel.AutoSize := True - DescLabel.Width := NewPage.SurfaceWidth; - DescLabel.WordWrap := True - DescLabel.Parent := NewPage.Surface; - DescLabel.Caption := installerMessage; -end; - diff --git a/6.x/installer/win64/Output/Csound6-Plugins-Windows_x86_64-1.0.exe b/6.x/installer/win64/Output/Csound6-Plugins-Windows_x86_64-1.0.exe deleted file mode 100644 index c5843b82..00000000 Binary files a/6.x/installer/win64/Output/Csound6-Plugins-Windows_x86_64-1.0.exe and /dev/null differ diff --git a/6.x/installer/win64/buildWindows.sh b/6.x/installer/win64/buildWindows.sh deleted file mode 100644 index ec3e4202..00000000 --- a/6.x/installer/win64/buildWindows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#Simple script to build plugins on Windows. Modify each of the paths below for your own needs.. - -cd ../../build -cmake -DFLTK_BASE_LIBRARY_DEBUG=../../../../vcpkg/installed/x64-windows-csound/lib/fltkd.lib \ --DFLTK_BASE_LIBRARY_RELEASE=../../vcpkg/installed/x64-windows-csound/lib/fltk.lib \ --DFLTK_INCLUDE_DIR=../../vcpkg/packages/fltk_x64-windows-csound/include \ --DFLTK_FLUID_EXECUTABLE=../../vcpkg/installed/x64-windows-csound/tools/fluidsynth/fluidsynth.exe \ --DFLTK_FORMS_LIBRARY_RELEASE=../../vcpkg/installed/x64-windows-csound/lib/fltk_forms.lib \ --DFLTK_IMAGES_LIBRARY_RELEASE=../../vcpkg/installed/x64-windows-csound/lib/fltk_images.lib \ --DABLETON_LINK_HOME=D:/sourcecode/link \ --DPNG_PNG_INCLUDE_DIR=../../vcpkg/installed/x64-windows-csound/include \ --DPNG_LIBRARY_RELEASE=C:/Python36/DLLs/png.lib \ --DEIGEN3_INCLUDE_DIR=D:/sourcecode/eigen-3.4-rc1 \ --DFAUST_INCLUDE_DIR_HINT="C:/Program Files/Faust/include" \ --DFAUST_LIB_DIR_HINT="C:/Program Files/Faust/lib" \ --DBUILD_FAUST_OPCODES=ON .. - -cmake --build . --config Release - - - diff --git a/6.x/src/AbletonLinkOpcodes/CMakeLists.txt b/6.x/src/AbletonLinkOpcodes/CMakeLists.txt deleted file mode 100644 index fe2e8dba..00000000 --- a/6.x/src/AbletonLinkOpcodes/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -# Build Ableton Link Opcodes -option(BUILD_ABLETON_LINK_OPCODES "Build the Ableton link opcodes" OFF) - -if(BUILD_ABLETON_LINK_OPCODES) - message(STATUS "Ableton Link home: ${ABLETON_LINK_HOME}") - - if(APPLE) - make_plugin(ableton_link_opcodes ableton_link_opcodes.cpp) - set_target_properties(ableton_link_opcodes - PROPERTIES - COMPILE_FLAGS "-std=c++11 -stdlib=libc++ -Wno-multichar -DLINK_PLATFORM_MACOSX=1" - LINK_FLAGS "-std=c++11 -stdlib=libc++" - ) - elseif(LINUX) - include(CheckCXXCompilerFlag) - CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_CXX11) - - if(COMPILER_SUPPORTS_CXX11) - make_plugin(ableton_link_opcodes ableton_link_opcodes.cpp) - set_target_properties(ableton_link_opcodes PROPERTIES COMPILE_FLAGS "-std=gnu++11 -Wno-multichar -DLINK_PLATFORM_LINUX=1") - else() - message(STATUS "Not building ableton_link_opcodes as no C++11 support found.") - endif() - else() - make_plugin(ableton_link_opcodes ableton_link_opcodes.cpp) - - if(WIN32) - if(USE_VCPKG) - find_package(AbletonLink CONFIG REQUIRED PATH_SUFFIXES share/ableton-link) - target_link_libraries(ableton_link_opcodes PRIVATE Ableton::Link) - else() - set_target_properties(ableton_link_opcodes - PROPERTIES - COMPILE_FLAGS "-std=gnu++11 -Wno-multichar -DLINK_PLATFORM_WINDOWS=1" - LINK_FLAGS "-std=gnu++11" - ) - target_link_libraries(ableton_link_opcodes wsock32 ws2_32 iphlpapi) - endif() - endif() - endif() - - target_include_directories(ableton_link_opcodes - PRIVATE - ${CSOUND_INCLUDE_DIRS} - ${ABLETON_LINK_HOME}/include - ${ABLETON_LINK_HOME}/modules/asio-standalone/asio/include - ) - - install(TARGETS ableton_link_opcodes - LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR} - ARCHIVE DESTINATION ${LIBRARY_INSTALL_DIR} - ) -endif() diff --git a/6.x/src/AbletonLinkOpcodes/ableton_link_opcodes.cpp b/6.x/src/AbletonLinkOpcodes/ableton_link_opcodes.cpp deleted file mode 100644 index dd83d12f..00000000 --- a/6.x/src/AbletonLinkOpcodes/ableton_link_opcodes.cpp +++ /dev/null @@ -1,890 +0,0 @@ -/* - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ -#if defined(__MINGW64__) -#include -#include - -extern "C" { - uint64_t htonll(uint64_t value) - { - _byteswap_uint64(value); - } - uint64_t ntohll(uint64_t value) - { - _byteswap_uint64(value); - } -} -#endif -#if defined(__ANDROID__) -/* Ableton Link preupposes GNU libc, but we are using clang. - * So we must replace all the ifaddrs code. - * Pretend that ifaddrs.h has been included: - */ -#define _IFADDRS_H_ -// Put in our own ifaddrs.h from https://raw.githubusercontent.com/libpd/abl_link/master/external/android-ifaddrs/ifaddrs.h. -////////////////////////////////////////////////////////////////////////////// -/* - * libjingle - * Copyright 2013, Google Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef TALK_BASE_IFADDRS_ANDROID_H_ -#define TALK_BASE_IFADDRS_ANDROID_H_ -#include -#include -// Implementation of getifaddrs for Android. -// Fills out a list of ifaddr structs (see below) which contain information -// about every network interface available on the host. -// See 'man getifaddrs' on Linux or OS X (nb: it is not a POSIX function). -struct ifaddrs { - struct ifaddrs* ifa_next; - char* ifa_name; - uint32_t ifa_flags; - struct sockaddr* ifa_addr; - struct sockaddr* ifa_netmask; - // Real ifaddrs has broadcast, point to point and data members. - // We don't need them (yet?). -}; -int getifaddrs(struct ifaddrs** result); -void freeifaddrs(struct ifaddrs* addrs); -#endif // TALK_BASE_IFADDRS_ANDROID_H_ -////////////////////////////////////////////////////////////////////////////// -// Put in our own ifaddrs.cpp from https://raw.githubusercontent.com/libpd/abl_link/master/external/android-ifaddrs/ifaddrs.cpp. -////////////////////////////////////////////////////////////////////////////// -/* libjingle - * Copyright 2012, Google Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -//#include "ifaddrs.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -struct netlinkrequest { - nlmsghdr header; - ifaddrmsg msg; -}; -namespace { -const int kMaxReadSize = 4096; -}; -int set_ifname(struct ifaddrs* ifaddr, int interface) { - char buf[IFNAMSIZ] = {0}; - char* name = if_indextoname(interface, buf); - if (name == NULL) { - return -1; - } - ifaddr->ifa_name = new char[strlen(name) + 1]; - strncpy(ifaddr->ifa_name, name, strlen(name) + 1); - return 0; -} -int set_flags(struct ifaddrs* ifaddr) { - int fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd == -1) { - return -1; - } - ifreq ifr; - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, ifaddr->ifa_name, IFNAMSIZ - 1); - int rc = ioctl(fd, SIOCGIFFLAGS, &ifr); - close(fd); - if (rc == -1) { - return -1; - } - ifaddr->ifa_flags = ifr.ifr_flags; - return 0; -} -int set_addresses(struct ifaddrs* ifaddr, ifaddrmsg* msg, void* data, - size_t len) { - if (msg->ifa_family == AF_INET) { - sockaddr_in* sa = new sockaddr_in; - sa->sin_family = AF_INET; - memcpy(&sa->sin_addr, data, len); - ifaddr->ifa_addr = reinterpret_cast(sa); - } else if (msg->ifa_family == AF_INET6) { - sockaddr_in6* sa = new sockaddr_in6; - sa->sin6_family = AF_INET6; - sa->sin6_scope_id = msg->ifa_index; - memcpy(&sa->sin6_addr, data, len); - ifaddr->ifa_addr = reinterpret_cast(sa); - } else { - return -1; - } - return 0; -} -int make_prefixes(struct ifaddrs* ifaddr, int family, int prefixlen) { - char* prefix = NULL; - if (family == AF_INET) { - sockaddr_in* mask = new sockaddr_in; - mask->sin_family = AF_INET; - memset(&mask->sin_addr, 0, sizeof(in_addr)); - ifaddr->ifa_netmask = reinterpret_cast(mask); - if (prefixlen > 32) { - prefixlen = 32; - } - prefix = reinterpret_cast(&mask->sin_addr); - } else if (family == AF_INET6) { - sockaddr_in6* mask = new sockaddr_in6; - mask->sin6_family = AF_INET6; - memset(&mask->sin6_addr, 0, sizeof(in6_addr)); - ifaddr->ifa_netmask = reinterpret_cast(mask); - if (prefixlen > 128) { - prefixlen = 128; - } - prefix = reinterpret_cast(&mask->sin6_addr); - } else { - return -1; - } - for (int i = 0; i < (prefixlen / 8); i++) { - *prefix++ = 0xFF; - } - char remainder = 0xff; - remainder <<= (8 - prefixlen % 8); - *prefix = remainder; - return 0; -} -int populate_ifaddrs(struct ifaddrs* ifaddr, ifaddrmsg* msg, void* bytes, - size_t len) { - if (set_ifname(ifaddr, msg->ifa_index) != 0) { - return -1; - } - if (set_flags(ifaddr) != 0) { - return -1; - } - if (set_addresses(ifaddr, msg, bytes, len) != 0) { - return -1; - } - if (make_prefixes(ifaddr, msg->ifa_family, msg->ifa_prefixlen) != 0) { - return -1; - } - return 0; -} -int getifaddrs(struct ifaddrs** result) { - int fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE); - if (fd < 0) { - return -1; - } - netlinkrequest ifaddr_request; - memset(&ifaddr_request, 0, sizeof(ifaddr_request)); - ifaddr_request.header.nlmsg_flags = NLM_F_ROOT | NLM_F_REQUEST; - ifaddr_request.header.nlmsg_type = RTM_GETADDR; - ifaddr_request.header.nlmsg_len = NLMSG_LENGTH(sizeof(ifaddrmsg)); - ssize_t count = send(fd, &ifaddr_request, ifaddr_request.header.nlmsg_len, 0); - if (static_cast(count) != ifaddr_request.header.nlmsg_len) { - close(fd); - return -1; - } - struct ifaddrs* start = NULL; - struct ifaddrs* current = NULL; - char buf[kMaxReadSize]; - ssize_t amount_read = recv(fd, &buf, kMaxReadSize, 0); - while (amount_read > 0) { - nlmsghdr* header = reinterpret_cast(&buf[0]); - size_t header_size = static_cast(amount_read); - for ( ; NLMSG_OK(header, header_size); - header = NLMSG_NEXT(header, header_size)) { - switch (header->nlmsg_type) { - case NLMSG_DONE: - // Success. Return. - *result = start; - close(fd); - return 0; - case NLMSG_ERROR: - close(fd); - freeifaddrs(start); - return -1; - case RTM_NEWADDR: { - ifaddrmsg* address_msg = - reinterpret_cast(NLMSG_DATA(header)); - rtattr* rta = IFA_RTA(address_msg); - ssize_t payload_len = IFA_PAYLOAD(header); - while (RTA_OK(rta, payload_len)) { - if (rta->rta_type == IFA_ADDRESS) { - int family = address_msg->ifa_family; - if (family == AF_INET || family == AF_INET6) { - ifaddrs* newest = new ifaddrs; - memset(newest, 0, sizeof(ifaddrs)); - if (current) { - current->ifa_next = newest; - } else { - start = newest; - } - if (populate_ifaddrs(newest, address_msg, RTA_DATA(rta), - RTA_PAYLOAD(rta)) != 0) { - freeifaddrs(start); - *result = NULL; - return -1; - } - current = newest; - } - } - rta = RTA_NEXT(rta, payload_len); - } - break; - } - } - } - amount_read = recv(fd, &buf, kMaxReadSize, 0); - } - close(fd); - freeifaddrs(start); - return -1; -} -void freeifaddrs(struct ifaddrs* addrs) { - struct ifaddrs* last = NULL; - struct ifaddrs* cursor = addrs; - while (cursor) { - delete[] cursor->ifa_name; - delete cursor->ifa_addr; - delete cursor->ifa_netmask; - last = cursor; - cursor = cursor->ifa_next; - delete last; - } -} -#endif // defined(ANDROID) -#include -#include - -/** - * A B L E T O N L I N K O P C O D E S - * - * Author: Michael Gogins - * January 2017 - * - * These opcodes implement the Ableton Link protocol from: - * - * https://github.com/Ableton/link - * - * The purpose of Ableton Link is to sychronize musical time, beat, and phase - * between musical applications performing in real time from separate - * programs, processes, and network addresses. This is useful e.g. for laptop - * orchestras. - * - * There is one global, peer-to-peer Link session that maintains a global time - * and beat on the local area network. Any peer may set the global tempo, - * and thereafter all peers in the session share that tempo. A process may - * have any number of peers (i.e., any number of Link objects). Each peer - * may also define its own "quantum" i.e. some multiple of the beat, e.g. a - * quantum of 4 might imply 4/4 time. The phase of the time is defined w.r.t - * the quantum, e.g. phase 0.5 of a quantum of 4 would be the second beat of - * the measure. Peers may read and write timelines with local time, beat, and - * phase, counting from when the peer is enabled, but the tempo and beat on - * all timelines for all peers in the session will coincide. - * - * The first peer to enable a session determines the initial tempo. After - * that, the tempo is changed only, and whenever, any peer explicity calls - * the set tempo functon (link_tempo_set, in Csound). - * - * The Link tempo is independent of the Csound score tempo. Performances that - * need to synchronize the score tempo with the Link tempo may use the tempo - * opcode to set the score tempo from the Link tempo; or conversely, set the - * Link tempo from the score tempo using the tempoval opcode. - * - * Please note, the phase and beat obtained or set by these opcodes is only as - * precise as allowed by the duration of Csound's kperiod, the audio driver - * used by Csound, the network stability, and the system's most precise clock. - * - * Build for testing with something like: - * - * g++ ableton_link_opcodes.cpp -std=gnu++11 -DLINK_PLATFORM_WINDOWS=1 -Werror -Wno-multichar -O2 -g -lcsound64 -I/home/restore/link/include -I/home/restore/link/modules/asio-standalone/asio/include -I../include -I../H -shared -oableton_link_opcodes.dll - * g++ ableton_link_opcodes.cpp -std=gnu++11 -DLINK_PLATFORM_LINUX=1 -Werror -Wno-multichar -O2 -g -fPIC -lcsound64 -I/home/mkg/link/include -I/home/mkg/link/modules/asio-standalone/asio/include -I/usr/local/include/csound -I/home/mkg/csound/csound/include -shared -oableton_link_opcodes.so - */ -using namespace csound; - -static bool enable_debug = 0; - -#define debug(fmt, ...) \ - do { if (enable_debug) fprintf(stderr, fmt, __VA_ARGS__); } while (0) - -using floating_point_microseconds = std::chrono::duration; -using floating_point_seconds = std::chrono::duration; - -/** - * This is used to perform a static type cast in a clear, obvious, and - * bulletproof way. Here, we want a bit-for-bit cast between a Csound MYFLT - * (usually a double) and a pointer. This will only work if sizeof(MYFLT) > - * sizeof(void *). That is always the case on 32 bit CPU architecture, and - * will be the case on 64 bit CPU architecture if MYFLT is double-precision. - */ -typedef union { - MYFLT myflt; - ableton::Link *pointer; -} link_cast_t; - -// i_link link_create [j_bpm = 60] - -class link_create_t : public OpcodeBase -{ - // Pfields out: - MYFLT *r0_link; - // Pfields in: - MYFLT *p0_bpm; - // State: - link_cast_t link; - double bpm; -public: - int init(CSOUND *csound) { - if (*p0_bpm == FL(-1.0)) { - bpm = 60; - } else { - bpm = *p0_bpm; - } - link.pointer = new ableton::Link(bpm); - debug("link_create: bpm: %f link.pointer: %p link.myflt: %g\n", bpm, link.pointer, link.myflt); - *r0_link = link.myflt; - return OK; - } -}; - -// link_enable i_link [, P_enabled = 1] - -class link_enable_t : public OpcodeBase -{ - // Pfields out: - // Pfields in: - MYFLT *p0_link; - MYFLT *p1_enabled; - // State: - link_cast_t link; - MYFLT prior_enabled; -public: - int init(CSOUND *csound) { - link.myflt = *p0_link; - link.pointer->enable(*p1_enabled); - prior_enabled = *p1_enabled; - debug("link_enable: link.pointer: %p link.myflt: %g p1_enabled: %f isEnabled: %d\n", link.pointer, link.myflt, *p1_enabled, link.pointer->isEnabled()); - return OK; - } - int kontrol(CSOUND *csound) { - if (prior_enabled != *p1_enabled) { - link.pointer->enable(*p1_enabled); - debug("link_enable: link.pointer: %p link.myflt: %g p1_enabled: %f isEnabled: %d\n", link.pointer, link.myflt, *p1_enabled, link.pointer->isEnabled()); - prior_enabled = *p1_enabled; - } - return OK; - } -}; - -// k_is_enabled link_is_enabled i_link - -class link_is_enabled_t : public OpcodeBase -{ - // Pfields out: - MYFLT *r0_is_enabled; - // Pfields in: - MYFLT *p0_link; - // State: - link_cast_t link; -public: - int init(CSOUND *csound) { - link.myflt = *p0_link; - *r0_is_enabled = link.pointer->isEnabled(); - return OK; - } - int kontrol(CSOUND *csound) { - *r0_is_enabled = link.pointer->isEnabled(); - return OK; - } -}; - -// link_tempo_set i_link, k_bpm [, P_at_time_seconds = current time] - -class link_tempo_set_t : public OpcodeBase -{ - // Pfields out: - // Pfields in: - MYFLT *p0_link; - MYFLT *p1_bpm; - MYFLT *p2_at_time_seconds; - // State: - link_cast_t link; - MYFLT prior_bpm; - std::chrono::microseconds at_time_microseconds; -public: - int init(CSOUND *csound) { - link.myflt = *p0_link; - auto timeline = link.pointer->captureAudioSessionState(); - prior_bpm = *p1_bpm; - if (*p2_at_time_seconds == FL(-1.0)) { - at_time_microseconds = link.pointer->clock().micros(); - } else { - at_time_microseconds = std::chrono::duration_cast(floating_point_seconds(*p2_at_time_seconds)); - } - timeline.setTempo(prior_bpm, at_time_microseconds); - link.pointer->commitAudioSessionState (timeline); - return OK; - } - int kontrol(CSOUND *csound) { - if (prior_bpm != *p1_bpm) { - auto timeline = link.pointer->captureAudioSessionState(); - prior_bpm = *p1_bpm; - if (*p2_at_time_seconds == FL(-1.0)) { - at_time_microseconds = link.pointer->clock().micros(); - } else { - at_time_microseconds = std::chrono::duration_cast(floating_point_seconds(*p2_at_time_seconds)); - } - timeline.setTempo(prior_bpm, at_time_microseconds); - link.pointer->commitAudioSessionState(timeline); - } - return OK; - } -}; - -// k_bpm link_tempo_get i_link - -class link_tempo_get_t : public OpcodeBase -{ - // Pfields out: - MYFLT *r0_bpm; - // Pfields in: - MYFLT *p0_link; - // State: - link_cast_t link; -public: - int init(CSOUND *csound) { - link.myflt = *p0_link; - auto timeline = link.pointer->captureAudioSessionState(); - *r0_bpm = timeline.tempo(); - return OK; - } - int kontrol(CSOUND *csound) { - auto timeline = link.pointer->captureAudioSessionState(); - *r0_bpm = timeline.tempo(); - return OK; - } -}; - -// k_beat_number, k_phase, k_current_time_seconds link_beat_get i_link [, P_quantum = 1] - -class link_beat_get_t : public OpcodeBase -{ - // Pfields out: - MYFLT *r0_beat; - MYFLT *r1_phase; - MYFLT *r2_seconds; - // Pfields in: - MYFLT *p0_link; - MYFLT *p1_quantum; - // State: - link_cast_t link; - std::chrono::microseconds at_time_microseconds; -public: - int init(CSOUND *csound) { - link.myflt = *p0_link; - auto timeline = link.pointer->captureAudioSessionState(); - at_time_microseconds = link.pointer->clock().micros(); - *r0_beat = timeline.beatAtTime(at_time_microseconds, *p1_quantum); - *r1_phase = timeline.phaseAtTime(at_time_microseconds, *p1_quantum); - *r2_seconds = std::chrono::duration_cast(at_time_microseconds).count(); - return OK; - } - int kontrol(CSOUND *csound) { - auto timeline = link.pointer->captureAudioSessionState(); - at_time_microseconds = link.pointer->clock().micros(); - *r0_beat = timeline.beatAtTime(at_time_microseconds, *p1_quantum); - *r1_phase = timeline.phaseAtTime(at_time_microseconds, *p1_quantum); - *r2_seconds = std::chrono::duration_cast(at_time_microseconds).count(); - return OK; - } -}; - -// k_trigger, k_beat, k_phase, k_current_time_seconds link_metro i_link [, P_quantum = 1] - -class link_metro_t : public OpcodeBase -{ - // Pfields out: - MYFLT *r0_trigger; - MYFLT *r1_beat; - MYFLT *r2_phase; - MYFLT *r3_seconds; - // Pfields in: - MYFLT *p0_link; - MYFLT *p1_quantum; - // State: - link_cast_t link; - std::chrono::microseconds at_time_microseconds; - MYFLT prior_phase; -public: - // The trigger is "on" when the new phase is less than the prior phase, and "off" - // when the new phase is greater than the prior phase. - int init(CSOUND *csound) { - link.myflt = *p0_link; - debug("link_metro i: link.pointer: %p link.myflt: %g\n", link.pointer, link.myflt); - auto timeline = link.pointer->captureAudioSessionState(); - at_time_microseconds = link.pointer->clock().micros(); - *r0_trigger = 0; - *r1_beat = timeline.beatAtTime(at_time_microseconds, *p1_quantum); - *r2_phase = timeline.phaseAtTime(at_time_microseconds, *p1_quantum); - prior_phase = *r2_phase; - *r3_seconds = std::chrono::duration_cast(at_time_microseconds).count(); - debug("link_metro i: r0_trigger: %f r1_beat: %f r2_phase: %f r3_seconds: %f\n", *r0_trigger, *r1_beat, *r2_phase, *r3_seconds); - return OK; - } - int kontrol(CSOUND *csound) { - auto timeline = link.pointer->captureAudioSessionState(); - at_time_microseconds = link.pointer->clock().micros(); - *r1_beat = timeline.beatAtTime(at_time_microseconds, *p1_quantum); - *r2_phase = timeline.phaseAtTime(at_time_microseconds, *p1_quantum); - if (*r2_phase < prior_phase) { - *r0_trigger = 1; - debug("link_metro k: r0_trigger: %f r1_beat: %f r2_phase: %f r3_seconds: %f\n", *r0_trigger, *r1_beat, *r2_phase, *r3_seconds); - } else { - *r0_trigger = 0; - } - prior_phase = *r2_phase; - *r3_seconds = std::chrono::duration_cast(at_time_microseconds).count(); - return OK; - } -}; - -// link_beat_request i_link k_beat [, J_at_time_seconds = current time [, P_quantum = 1]] - -class link_beat_request_t : public OpcodeBase -{ - // Pfields out: - // Pfields in: - MYFLT *p0_link; - MYFLT *p1_beat; - MYFLT *p2_at_time_seconds; - MYFLT *p3_quantum; - // State: - link_cast_t link; - MYFLT prior_beat; - MYFLT prior_at_time_seconds; - MYFLT prior_quantum; - std::chrono::microseconds at_time_microseconds; -public: - int init(CSOUND *csound) { - link.myflt = *p0_link; - prior_beat = *p1_beat; - prior_at_time_seconds = *p2_at_time_seconds; - prior_quantum = *p3_quantum; - if (*p2_at_time_seconds == FL(-1.0)) { - at_time_microseconds = link.pointer->clock().micros(); - } else { - at_time_microseconds = std::chrono::duration_cast(floating_point_seconds(*p2_at_time_seconds)); - } - auto timeline = link.pointer->captureAudioSessionState(); - timeline.requestBeatAtTime(prior_beat, at_time_microseconds, prior_quantum); - link.pointer->commitAudioSessionState(timeline); - return OK; - } - int kontrol(CSOUND *csound) { - if ((prior_beat != *p1_beat) || (prior_at_time_seconds != *p2_at_time_seconds) || (prior_quantum != *p3_quantum)) { - if (*p2_at_time_seconds == FL(-1.0)) { - at_time_microseconds = link.pointer->clock().micros(); - } else { - at_time_microseconds = std::chrono::duration_cast(floating_point_seconds(*p2_at_time_seconds)); - } - auto timeline = link.pointer->captureAudioSessionState(); - timeline.requestBeatAtTime(prior_beat, at_time_microseconds, prior_quantum); - link.pointer->commitAudioSessionState(timeline); - prior_beat = *p1_beat; - prior_at_time_seconds = *p2_at_time_seconds; - prior_quantum = *p3_quantum; - } - return OK; - } -}; - -// link_beat_force i_link k_beat [, J_at_time_seconds = current time [, P_quantum = 1]] - -class link_beat_force_t : public OpcodeBase -{ - // Pfields out: - // Pfields in: - MYFLT *p0_link; - MYFLT *p1_beat; - MYFLT *p2_at_time_seconds; - MYFLT *p3_quantum; - // State: - link_cast_t link; - MYFLT prior_beat; - MYFLT prior_at_time_seconds; - MYFLT prior_quantum; - std::chrono::microseconds at_time_microseconds; -public: - int init(CSOUND *csound) { - link.myflt = *p0_link; - prior_beat = *p1_beat; - prior_at_time_seconds = *p2_at_time_seconds; - prior_quantum = *p3_quantum; - if (*p2_at_time_seconds == FL(-1.0)) { - at_time_microseconds = link.pointer->clock().micros(); - } else { - at_time_microseconds = std::chrono::duration_cast(floating_point_seconds(*p2_at_time_seconds)); - } - auto timeline = link.pointer->captureAudioSessionState(); - timeline.forceBeatAtTime(prior_beat, at_time_microseconds, prior_quantum); - link.pointer->commitAudioSessionState(timeline); - return OK; - } - int kontrol(CSOUND *csound) { - if ((prior_beat != *p1_beat) || (prior_at_time_seconds != *p2_at_time_seconds) || (prior_quantum != *p3_quantum)) { - if (*p2_at_time_seconds == FL(-1.0)) { - at_time_microseconds = link.pointer->clock().micros(); - } else { - at_time_microseconds = std::chrono::duration_cast(floating_point_seconds(*p2_at_time_seconds)); - } - auto timeline = link.pointer->captureAudioSessionState(); - timeline.forceBeatAtTime(prior_beat, at_time_microseconds, prior_quantum); - link.pointer->commitAudioSessionState(timeline); - prior_beat = *p1_beat; - prior_at_time_seconds = *p2_at_time_seconds; - prior_quantum = *p3_quantum; - } - return OK; - } -}; - -// k_count link_peers i_link - -class link_peers_t : public OpcodeBase -{ - // Pfields out: - MYFLT *r0_peers; - // Pfields in: - MYFLT *p0_link; - // State: - link_cast_t link; -public: - int init(CSOUND *csound) { - link.myflt = *p0_link; - *r0_peers = link.pointer->numPeers(); - return OK; - } - int kontrol(CSOUND *csound) { - *r0_peers = link.pointer->numPeers(); - return OK; - } -}; - -extern "C" { - - OENTRY oentries[] = - { -// i_link link_create [j_bpm = 60] - { - (char*)"link_create", - sizeof(link_create_t), - 0, - 1, - (char*)"i", - (char*)"j", - (SUBR) link_create_t::init_, - 0, - 0, - }, -// link_enable i_link [, P_enabled = 1] - { - (char*)"link_enable", - sizeof(link_enable_t), - 0, - 3, - (char*)"", - (char*)"iP", - (SUBR) link_enable_t::init_, - (SUBR) link_enable_t::kontrol_, - 0, - }, -// k_is_enabled link_is_enabled i_link - { - (char*)"link_is_enabled", - sizeof(link_is_enabled_t), - 0, - 3, - (char*)"k", - (char*)"i", - (SUBR) link_is_enabled_t::init_, - (SUBR) link_is_enabled_t::kontrol_, - 0, - }, - // link_tempo_set i_link, k_bpm [, J_at_time_seconds = current time] - { - (char*)"link_tempo_set", - sizeof(link_tempo_set_t), - 0, - 3, - (char*)"", - (char*)"ikJ", - (SUBR) link_tempo_set_t::init_, - (SUBR) link_tempo_set_t::kontrol_, - 0, - }, -// k_bpm link_tempo_get i_link - { - (char*)"link_tempo_get", - sizeof(link_tempo_set_t), - 0, - 3, - (char*)"k", - (char*)"i", - (SUBR) link_tempo_get_t::init_, - (SUBR) link_tempo_get_t::kontrol_, - 0, - }, -// k_beat_number, k_phase, k_current_time_seconds link_beat_get i_link [, P_quantum = 1] - { - (char*)"link_beat_get", - sizeof(link_beat_get_t), - 0, - 3, - (char*)"kkk", - (char*)"iP", - (SUBR) link_beat_get_t::init_, - (SUBR) link_beat_get_t::kontrol_, - 0, - }, -// k_trigger, k_beat, k_phase, k_current_time_seconds link_metro i_link [, P_quantum = 1] - { - (char*)"link_metro", - sizeof(link_metro_t), - 0, - 3, - (char*)"kkkk", - (char*)"iP", - (SUBR) link_metro_t::init_, - (SUBR) link_metro_t::kontrol_, - 0, - }, -// link_beat_request i_link k_beat [, J_at_time_seconds = current time [, P_quantum = 1]] - { - (char*)"link_beat_request", - sizeof(link_beat_request_t), - 0, - 3, - (char*)"", - (char*)"ikJP", - (SUBR) link_beat_request_t::init_, - (SUBR) link_beat_request_t::kontrol_, - 0, - }, -// link_beat_force i_link k_beat [, J_at_time_seconds = current time [, P_quantum = 1]] - { - (char*)"link_beat_force", - sizeof(link_beat_force_t), - 0, - 3, - (char*)"", - (char*)"ikJP", - (SUBR) link_beat_force_t::init_, - (SUBR) link_beat_force_t::kontrol_, - 0, - }, -// k_count link_peers i_link - { - (char*)"link_peers", - sizeof(link_peers_t), - 0, - 3, - (char*)"k", - (char*)"i", - (SUBR) link_peers_t::init_, - (SUBR) link_peers_t::kontrol_, - 0, - }, - { - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - } - }; - - PUBLIC int csoundModuleCreate(CSOUND *csound) - { - return 0; - } - - PUBLIC int csoundModuleInit(CSOUND *csound) - { - int status = 0; - for(OENTRY *oentry = &oentries[0]; oentry->opname; oentry++) - { - status |= csound->AppendOpcode(csound, oentry->opname, - oentry->dsblksiz, oentry->flags, - oentry->thread, - oentry->outypes, oentry->intypes, - (int (*)(CSOUND*,void*)) oentry->iopadr, - (int (*)(CSOUND*,void*)) oentry->kopadr, - (int (*)(CSOUND*,void*)) oentry->aopadr); - } - return status; - } - - PUBLIC int csoundModuleDestroy(CSOUND *csound) - { - return 0; - } - -} diff --git a/6.x/src/AbletonLinkOpcodes/jni/Android.mk b/6.x/src/AbletonLinkOpcodes/jni/Android.mk deleted file mode 100644 index 5111a741..00000000 --- a/6.x/src/AbletonLinkOpcodes/jni/Android.mk +++ /dev/null @@ -1,20 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -CSOUND_SRC_ROOT := ../../../.. -ABLETON_LINK_HOME :=/home/mkg/link - -LOCAL_MODULE := ableton_link_opcodes - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../Engine $(LOCAL_PATH)/../../../../H $(LOCAL_PATH)/../../../../include $(LOCAL_PATH)/../../../.. $(LOCAL_PATH)/../../../ $(NDK_MODULE_PATH)/libsndfile-android/jni $(LOCAL_PATH)/../../../CsoundAndroid/jni $(ABLETON_LINK_HOME)/include $(ABLETON_LINK_HOME)/modules/asio-standalone/asio/include -LOCAL_CFLAGS := -O3 -D__BUILDING_LIBCSOUND -DENABLE_NEW_PARSER -DLINUX -DHAVE_DIRENT_H -DHAVE_FCNTL_H -DHAVE_UNISTD_H -DHAVE_STDINT_H -DHAVE_SYS_TIME_H -DHAVE_SYS_TYPES_H -DHAVE_TERMIOS_H -DLINK_PLATFORM_LINUX=1 -DANDROID=1 -LOCAL_CPPFLAGS :=$(LOCAL_CFLAGS) -LOCAL_CPPFLAGS += -std=c++11 -pthread -frtti -fcxx-exceptions -Wno-multichar -fexceptions #-Werror -LOCAL_LDLIBS := -latomic -LOCAL_LDFLAGS += -Wl,--export-dynamic - -LOCAL_SRC_FILES := $(CSOUND_SRC_ROOT)/Opcodes/ableton_link_opcodes.cpp - -include $(BUILD_SHARED_LIBRARY) - diff --git a/6.x/src/AbletonLinkOpcodes/jni/Application.mk b/6.x/src/AbletonLinkOpcodes/jni/Application.mk deleted file mode 100644 index 27e8ae21..00000000 --- a/6.x/src/AbletonLinkOpcodes/jni/Application.mk +++ /dev/null @@ -1,6 +0,0 @@ -APP_ABI := armeabi-v7a arm64-v8a -APP_CPPFLAGS += -fexceptions -frtti -APP_OPTIM := release -APP_PLATFORM := android-21 -APP_STL := c++_shared -NDK_TOOLCHAIN_VERSION := clang diff --git a/6.x/src/CUDA/CMakeLists.txt b/6.x/src/CUDA/CMakeLists.txt deleted file mode 100644 index 608f75f2..00000000 --- a/6.x/src/CUDA/CMakeLists.txt +++ /dev/null @@ -1,68 +0,0 @@ -option(BUILD_CUDA_OPCODES "Build the CUDA GPU opcodes" OFF) - -function(make_cuda_plugin libname srcs) - SET(LIB_TYPE_DYNAMIC) #set the lib type - CUDA_ADD_LIBRARY(${libname} ${LIB_TYPE} ${srcs}) - - set(i 2) - while( ${i} LESS ${ARGC} ) - target_link_libraries(${libname} ${ARGV${i}}) - math(EXPR i "${i}+1") - endwhile() - - target_include_directories(${libname} PRIVATE ${CSOUND_INCLUDE_DIRS}) - - # set_target_properties(${libname} PROPERTIES - # RUNTIME_OUTPUT_DIRECTORY ${BUILD_PLUGINS_DIR} - # LIBRARY_OUTPUT_DIRECTORY ${BUILD_PLUGINS_DIR} - # ARCHIVE_OUTPUT_DIRECTORY ${BUILD_PLUGINS_DIR}) - - install(TARGETS ${libname} LIBRARY DESTINATION "${PLUGIN_INSTALL_DIR}" ) -endfunction() - -if(BUILD_CUDA_OPCODES) - find_package(CUDA REQUIRED) - check_deps(BUILD_CUDA_OPCODES CUDA_FOUND) - message(STATUS "Building the CUDA opcodes") - - include_directories(${CMAKE_HOME_DIRECTORY}/include) - include_directories(/usr/local/include) - LIST(APPEND CUDA_NVCC_FLAGS "-use_fast_math") - - if(APPLE) - if(CMAKE_OSX_DEPLOYMENT_TARGET MATCHES 10.6) - LIST(APPEND CUDA_NVCC_FLAGS "-arch=sm_11") - make_cuda_plugin(cudaop1 adsyn11.cu) - make_cuda_plugin(cudaop2 pvsopsf.cu) - make_cuda_plugin(cudaop3 slidingm.cu) - make_cuda_plugin(cudaop4 convf.cu) - make_cuda_plugin(cudaop5 pconv11.cu) - else() - LIST(APPEND CUDA_NVCC_FLAGS "-ccbin /usr/bin/clang -arch=sm_30 -Xcompiler -stdlib=libstdc++") - make_cuda_plugin(cudaop1 adsyn.cu) - make_cuda_plugin(cudaop2 pvsops.cu) - make_cuda_plugin(cudaop3 slidingm.cu) - make_cuda_plugin(cudaop4 conv.cu) - make_cuda_plugin(cudaop5 pconv.cu) - endif() - else() - if(CUDA_VERSION VERSION_LESS 9.0) - LIST(APPEND CUDA_NVCC_FLAGS "-arch=sm_20") - else() - LIST(APPEND CUDA_NVCC_FLAGS "-arch=sm_75") - endif() - - make_cuda_plugin(cudaop1 adsyn.cu) - make_cuda_plugin(cudaop2 pvsops.cu) - # make_cuda_plugin(cudaop3 slidingm.cu) - make_cuda_plugin(cudaop4 conv.cu) - make_cuda_plugin(cudaop5 pconv.cu) - endif() - - CUDA_ADD_CUFFT_TO_TARGET(cudaop2) - CUDA_ADD_CUFFT_TO_TARGET(cudaop5) - - SET(CUDA_VERBOSE_BUILD ON CACHE BOOL "nvcc verbose" FORCE) -else() - message(STATUS "Not building the CUDA opcodes") -endif() diff --git a/6.x/src/CUDA/adsyn.cu b/6.x/src/CUDA/adsyn.cu deleted file mode 100644 index 13063478..00000000 --- a/6.x/src/CUDA/adsyn.cu +++ /dev/null @@ -1,187 +0,0 @@ -// -*- c++ -*- -/* adsyn.cu - experimental cuda opcodes - - (c) Victor Lazzarini, 2013 - - based on M Puckette's pitch tracking algorithm. - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include -#include - -typedef struct cudadsyn_ { - OPDS h; - MYFLT *asig; - PVSDAT *fsig; - MYFLT *kamp, *kfreq; - MYFLT *inum; - float *out; - float *frame; - int64_t *ndx; - float *fp, *previous; - AUXCH out_; - int bins, blocks, threads; - int count; - int vsamps, mblocks, mthreads; - int framecount; -} CUDADSYN; - -static int destroy_cudadsyn(CSOUND *csound, void *pp); - -static int init_cudadsyn(CSOUND *csound, CUDADSYN *p){ - - int asize, ipsize, fpsize, blockspt; - if(p->fsig->overlap > 1024) - return csound->InitError(csound, "overlap is too large\n"); - cudaDeviceProp deviceProp; - cudaGetDeviceProperties(&deviceProp, 0); - blockspt = deviceProp.maxThreadsPerBlock; - if(deviceProp.major < 2) - return csound->InitError(csound, - "this opcode requires device capability 2.0 minimum. Device is %d.%d\n", - deviceProp.major, deviceProp.minor ); - - p->bins = (p->fsig->N)/2; - - if(*p->inum > 0 && *p->inum < p->bins) p->bins = *p->inum; - - p->vsamps = p->fsig->overlap; - p->threads = p->bins*p->vsamps; - p->blocks = p->threads > blockspt ? p->threads/blockspt : 1; - p->mthreads = p->bins; - p->mblocks = p->mthreads > blockspt ? p->mthreads/blockspt : 1; - - p->threads /= p->blocks; - p->mthreads /= p->mblocks; - - asize = p->vsamps*sizeof(float); - ipsize = p->fsig->N*sizeof(int64_t)/2; - fpsize = p->fsig->N*sizeof(float); - - cudaMalloc(&p->out, asize); - cudaMalloc(&p->ndx, ipsize); - cudaMalloc(&p->frame, fpsize); - cudaMalloc(&p->previous, fpsize/2); - cudaMemset(p->previous, 0, fpsize/2); - cudaMemset(p->ndx, 0, ipsize); - cudaMemset(p->out, 0, sizeof(float)*p->vsamps); - - asize = p->vsamps*sizeof(float); - if(p->out_.auxp == NULL || - p->out_.size < asize) - csound->AuxAlloc(csound, asize , &p->out_); - - csound->RegisterDeinitCallback(csound, p, destroy_cudadsyn); - p->count = 0; - return OK; -} - -__global__ void sample(float *out, float *frame, float pitch, int64_t *ph, - float *amps, int vsize, float sr) { - - int t = (threadIdx.x + blockIdx.x*blockDim.x); - int n = t%vsize; /* sample index */ - int h = t/vsize; /* bin index */ - //if(amps[h] < 0.001) return; - int k = h<<1; - int64_t lph; - float a = amps[h], ascl = ((float)n)/vsize; - int64_t d = (int64_t) round(frame[k+1]*pitch*FMAXLEN/sr); - lph = ph[h] + n*d; - a += ascl*(frame[k] - a); - atomicAdd(&out[n], a*sinf((2*PI*lph)/FMAXLEN)); - // if(n) return; - // ph[h] = (ph[h] + vsize*d) & PHMASK; - // amps[h] = frame[k]; -} - -__global__ void update(float *frame, float *amps, - int64_t *ph,float pitch, int vsize, float sr){ - - int h = threadIdx.x + blockIdx.x*blockDim.x; - int k = h << 1; - /* update phases and amps */ - ph[h] = (ph[h] + (int64_t)(vsize*round(pitch*frame[k+1]*FMAXLEN/sr))) & PHMASK; - amps[h] = frame[k]; -} - -static int perf_cudadsyn(CSOUND *csound, CUDADSYN *p){ - - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - float *out_ = (float *) p->out_.auxp; - MYFLT *asig = p->asig; - int count = p->count, vsamps = p->vsamps; - p->fp = (float *) (p->fsig->frame.auxp); - - if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); - } - - for(n=offset; n < nsmps; n++){ - if(count == 0) { - cudaMemcpy(out_,p->out,vsamps*sizeof(float),cudaMemcpyDeviceToHost); - update<<mblocks,p->mthreads>>>(p->frame, - p->previous, - p->ndx, - *p->kfreq, - vsamps, - csound->GetSr(csound)); - cudaMemset(p->out, 0, sizeof(float)*vsamps); - cudaMemcpy(p->frame,p->fp,sizeof(float)*p->bins*2,cudaMemcpyHostToDevice); - sample<<blocks,p->threads>>>(p->out,p->frame, - *p->kfreq, - p->ndx, - p->previous, - vsamps, - csound->GetSr(csound)); - - count = vsamps; - } - asig[n] = (MYFLT) out_[vsamps - count]; - count--; - } - p->count = count; - return OK; -} - -static int destroy_cudadsyn(CSOUND *csound, void *pp){ - CUDADSYN *p = (CUDADSYN *) pp; - cudaFree(p->out); - cudaFree(p->ndx); - cudaFree(p->previous); - cudaFree(p->frame); - return OK; -} - - -static OENTRY localops[] = { - {"cudasynth", sizeof(CUDADSYN),0, 3, "a", "fkko", (SUBR) init_cudadsyn, - (SUBR) perf_cudadsyn} -}; - -extern "C" { - LINKAGE -} - diff --git a/6.x/src/CUDA/adsyn11.cu b/6.x/src/CUDA/adsyn11.cu deleted file mode 100644 index f104e160..00000000 --- a/6.x/src/CUDA/adsyn11.cu +++ /dev/null @@ -1,185 +0,0 @@ -// -*- c++ -*- -/* adsyn11.cu - (c) Victor Lazzarini, 2013 - - based on M Puckette's pitch tracking algorithm. - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include -#include - -typedef struct cudadsyn_ { - OPDS h; - MYFLT *asig; - PVSDAT *fsig; - MYFLT *kamp, *kfreq; - MYFLT *inum; - float *out; - float *frame; - int64_t *ndx; - float *fp, *previous; - AUXCH out_; - int bins, blocks, threads; - int count; - int vsamps, mblocks, mthreads; - int framecount; -} CUDADSYN; - -static int destroy_cudadsyn(CSOUND *csound, void *pp); - -static int init_cudadsyn(CSOUND *csound, CUDADSYN *p){ - - int asize, ipsize, fpsize, blockspt; - if(p->fsig->overlap > 1024) - return csound->InitError(csound, "overlap is too large\n"); - cudaDeviceProp deviceProp; - cudaGetDeviceProperties(&deviceProp, 0); - blockspt = deviceProp.maxThreadsPerBlock; - if(deviceProp.major < 1) - csound->InitError(csound, - "this opcode requires device capability 1.0 minimum. Device is %d.%d\n", - deviceProp.major, deviceProp.minor ); - - p->bins = (p->fsig->N)/2; - - if(*p->inum > 0 && *p->inum < p->bins) p->bins = *p->inum; - - p->vsamps = p->fsig->overlap; - p->threads = p->bins*p->vsamps; - p->blocks = p->threads > blockspt ? p->threads/blockspt : 1; - p->mthreads = p->bins; - p->mblocks = p->mthreads > blockspt ? p->mthreads/blockspt : 1; - - p->threads /= p->blocks; - p->mthreads /= p->mblocks; - - asize = p->vsamps*p->bins*sizeof(float); - ipsize = p->fsig->N*sizeof(int64_t)/2; - fpsize = p->fsig->N*sizeof(float); - - cudaMalloc(&p->out, asize); - cudaMalloc(&p->ndx, ipsize); - cudaMalloc(&p->frame, fpsize); - cudaMalloc(&p->previous, fpsize/2); - cudaMemset(p->previous, 0, fpsize/2); - cudaMemset(p->ndx, 0, ipsize); - - asize = p->vsamps*sizeof(float); - if(p->out_.auxp == NULL || - p->out_.size < asize) - csound->AuxAlloc(csound, asize , &p->out_); - - csound->RegisterDeinitCallback(csound, p, destroy_cudadsyn); - p->count = 0; - return OK; -} - -__global__ void sample(float *out, float *frame, float pitch, int64_t *ph, - float *amps, int bins, int vsize, float sr) { - - int t = (threadIdx.x + blockIdx.x*blockDim.x); - int n = t%vsize; /* sample index */ - int h = t/vsize; /* bin index */ - int k = h<<1; - int64_t lph; - float a = amps[h], ascl = ((float)n)/vsize; - float fscal = pitch*FMAXLEN/sr; - lph = (ph[h] + (int64_t)(n*round(frame[k+1]*fscal))) & PHMASK; - a += ascl*(frame[k] - a); - out[t] = a*sinf((2*PI*lph)/FMAXLEN); - if(t >= vsize) return; - __syncthreads(); - for(int i=vsize; i < vsize*bins; i+=vsize) - out[t] += out[t + i]; -} - -__global__ void update(float *frame, float *amps, - int64_t *ph,float pitch, int vsize, float sr){ - - int h = threadIdx.x + blockIdx.x*blockDim.x; - int k = h << 1; - /* update phases and amps */ - ph[h] = (ph[h] + (int64_t)(vsize*round(pitch*frame[k+1]*FMAXLEN/sr))) & PHMASK; - amps[h] = frame[k]; -} - -static int perf_cudadsyn(CSOUND *csound, CUDADSYN *p){ - - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - float *out_ = (float *) p->out_.auxp; - MYFLT *asig = p->asig; - int count = p->count, vsamps = p->vsamps; - p->fp = (float *) (p->fsig->frame.auxp); - - if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); - } - - for(n=offset; n < nsmps; n++){ - if(count == 0) { - cudaMemset(p->out, 0, sizeof(float)*vsamps); - cudaMemcpy(p->frame,p->fp,sizeof(float)*p->bins*2,cudaMemcpyHostToDevice); - sample<<blocks,p->threads>>>(p->out,p->frame, - *p->kfreq, - p->ndx, - p->previous, - p->bins, - vsamps, - csound->GetSr(csound)); - if (cudaDeviceSynchronize() != cudaSuccess) - csound->Message(csound,"Cuda error: Failed to synchronize\n"); - update<<mblocks,p->mthreads>>>(p->frame, - p->previous, - p->ndx, - *p->kfreq, - vsamps, - csound->GetSr(csound)); - cudaMemcpy(out_,p->out,vsamps*sizeof(float),cudaMemcpyDeviceToHost); - count = vsamps; - } - asig[n] = (MYFLT) out_[vsamps - count]; - count--; - } - p->count = count; - return OK; -} - -static int destroy_cudadsyn(CSOUND *csound, void *pp){ - CUDADSYN *p = (CUDADSYN *) pp; - cudaFree(p->out); - cudaFree(p->ndx); - cudaFree(p->previous); - cudaFree(p->frame); - return OK; -} - - -static OENTRY localops[] = { - {"cudasynth", sizeof(CUDADSYN),0, 5, "a", "fkko", (SUBR) init_cudadsyn, NULL, - (SUBR) perf_cudadsyn} -}; - -extern "C" { - LINKAGE -} diff --git a/6.x/src/CUDA/build.sh b/6.x/src/CUDA/build.sh deleted file mode 100644 index 52611c3e..00000000 --- a/6.x/src/CUDA/build.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -# use -Xptxas="-v" to check register usage and --maxrregcount 32 to limit it -echo "building cuda opcodes ..." -nvcc -O3 -shared -o libcudaop1.dylib adsyn.cu -use_fast_math -I../../debug/CsoundLib64.framework/Headers -arch=sm_30 -I/usr/local/cuda/include -L/usr/local/cuda/lib -nvcc -O3 -shared -o libcudaop2.dylib pvsops.cu -use_fast_math -g -I../../debug/CsoundLib64.framework/Headers -arch=sm_30 -I/usr/local/cuda/include -L/usr/local/cuda/lib -lcufft -nvcc -O3 -shared -o libcudaop3.dylib slidingm.cu -use_fast_math -I../../debug/CsoundLib64.framework/Headers -arch=sm_30 -I/usr/local/cuda/include -L/usr/local/cuda/lib -nvcc -O3 -shared -o libcudaop4.dylib conv.cu -I../../debug/CsoundLib64.framework/Headers -arch=sm_30 -I/usr/local/cuda/include -L/usr/local/cuda/lib -nvcc -O3 -shared -o libcudaop5.dylib pconv.cu -I../../debug/CsoundLib64.framework/Headers -arch=sm_30 -I/usr/local/cuda/include -L/usr/local/cuda/lib -lcufft -echo "...done" diff --git a/6.x/src/CUDA/conv.cu b/6.x/src/CUDA/conv.cu deleted file mode 100644 index 43be9f33..00000000 --- a/6.x/src/CUDA/conv.cu +++ /dev/null @@ -1,153 +0,0 @@ -// -*- c++ -*- -/* conv.cu - - (c) Victor Lazzarini, 2013 - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include - -__global__ void convol(MYFLT *out, MYFLT *del, MYFLT *coefs, int irsize, int rp, int vsize) { - int t = (threadIdx.x + blockIdx.x*blockDim.x); - if(t >= irsize*vsize) return; - int n = t%vsize; /* sample index */ - int h = t/vsize; /* coeff index */ - int end = irsize+vsize; - rp += n + h; /* read point, oldest -> newest */ - out[t] = del[rp < end ? rp : rp%end]*coefs[irsize-1-h]; /* single tap */ - if(t >= vsize) return; - __syncthreads(); - MYFLT a = 0.0; - for(int i=1, j=vsize; i < irsize; i++, j+=vsize) - a += out[n + j]; /* mix all taps */ - out[n] += a; -} - -// __device__ double atomicAdd(double* address, double val) -// { -// unsigned long long int* address_as_ull = -// (unsigned long long int*)address; -// unsigned long long int old = *address_as_ull, assumed; -// do { -// assumed = old; -// old = atomicCAS(address_as_ull, assumed, -// __double_as_longlong(val + -// __longlong_as_double(assumed))); -// } while (assumed != old); -// return __longlong_as_double(old); -// } - -// __global__ void convol2(MYFLT *out, MYFLT *del, MYFLT *coefs, int irsize, int rp, int vsize) { -// int t = (threadIdx.x + blockIdx.x*blockDim.x); -// if(t >= irsize*vsize) return; -// int n = t%vsize; /* sample index */ -// int h = t/vsize; /* coeff index */ -// int end = irsize+vsize; -// rp += n + h; /* read point, oldest -> newest */ -// MYFLT s = del[rp < end ? rp : rp%end]*coefs[irsize-1-h]; /* single tap */ -// t == n ? out[n] = s : atomicAdd(&out[n], s); -// } - -typedef struct _CONV { - OPDS h; - MYFLT *aout, *asig, *ifn; - MYFLT *coeffs, *out, *del; - int wp, irsize; - int blocks, threads; -} CONV; - - -static int destroy_conv(CSOUND *csound, void *pp){ - CONV *p = (CONV *) pp; - cudaFree(p->coeffs); - cudaFree(p->del); - cudaFree(p->out); - return OK; -} - -static int conv_init(CSOUND *csound, CONV *p){ - - FUNC *ftab = csound->FTnp2Find(csound, p->ifn); - int irsize = ftab->flen; - int nsmps = CS_KSMPS; - int threads = irsize*nsmps; - - cudaMalloc(&p->coeffs, sizeof(MYFLT)*irsize); - cudaMemcpy(p->coeffs, ftab->ftable, sizeof(MYFLT)*irsize, - cudaMemcpyHostToDevice); - - cudaMalloc(&p->del, sizeof(MYFLT)*(irsize+nsmps)); - cudaMalloc(&p->out, sizeof(MYFLT)*threads); - cudaMemset(p->del,0,sizeof(MYFLT)*(irsize+nsmps)); - cudaMemset(p->out, 0, sizeof(MYFLT)*threads); - - p->wp = 0; - p->irsize = irsize; - - cudaDeviceProp deviceProp; - cudaGetDeviceProperties(&deviceProp, 0); - int blockspt = deviceProp.maxThreadsPerBlock; - csound->Message(csound, "CUDAconv: using device %s (capability %d.%d)\n", - deviceProp.name,deviceProp.major, deviceProp.minor); - - p->blocks = threads > blockspt ? ceil(threads/blockspt) : 1; - p->threads = threads > blockspt ? blockspt : threads; - - csound->RegisterDeinitCallback(csound, p, destroy_conv); - OPARMS parms; - csound->GetOParms(csound, &parms); - if(parms.odebug) - csound->Message(csound, "blocks %d, threads %d - %d\n", p->blocks, p->threads, threads); - - return OK; - -} -/* the delay size is irsize + vsize so that - we can shift in a whole block of samples */ -int conv_perf(CSOUND *csound, CONV *p){ - - int nsmps = CS_KSMPS; - MYFLT *sig = p->asig, *aout = p->aout; - MYFLT *del = p->del, *out = p->out, *coefs = p->coeffs; - int irsize = p->irsize; - int wp = p->wp; - - if(wp > irsize) { - int front = wp - irsize; - cudaMemcpy(&del[wp], sig, sizeof(MYFLT)*(nsmps-front), cudaMemcpyHostToDevice); - cudaMemcpy(del, &sig[nsmps-front], sizeof(MYFLT)*front, cudaMemcpyHostToDevice); - } - else cudaMemcpy(&del[wp], sig, sizeof(MYFLT)*nsmps, cudaMemcpyHostToDevice); - - wp = (wp+nsmps)%(irsize+nsmps); /* wp is now the oldest sample in the delay */ - convol<<blocks,p->threads>>>(out, del, coefs, irsize, wp, nsmps); - - cudaMemcpy(aout, out, sizeof(MYFLT)*nsmps, cudaMemcpyDeviceToHost); - p->wp = wp; - return OK; -} - -static OENTRY localops[] = { - {"cudaconv", sizeof(CONV),0, 5, "a", "ai", (SUBR) conv_init, NULL, - (SUBR) conv_perf}, -}; - -extern "C" { - LINKAGE -} diff --git a/6.x/src/CUDA/convf.cu b/6.x/src/CUDA/convf.cu deleted file mode 100644 index 387fafb4..00000000 --- a/6.x/src/CUDA/convf.cu +++ /dev/null @@ -1,141 +0,0 @@ -// -*- c++ -*- -/* convf.cu - (c) Victor Lazzarini, 2013 - - based on M Puckette's pitch tracking algorithm. - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include - -__global__ void convol(float *out, float *del, float *coefs, int irsize, int rp, int vsize) { - int t = (threadIdx.x + blockIdx.x*blockDim.x); - if(t >= irsize*vsize) return; - int n = t%vsize; /* sample index */ - int h = t/vsize; /* coeff index */ - int end = irsize+vsize; - rp += n + h; /* read point, oldest -> newest */ - out[t] = del[rp < end ? rp : rp%end]*coefs[irsize-1-h]; /* single tap */ - if(t >= vsize) return; - __syncthreads(); - float a = 0.0; - for(int i=1, j=vsize; i < irsize; i++, j+=vsize) - a += out[n + j]; /* mix all taps */ - out[n] += a; -} - -typedef struct _CONV { - OPDS h; - MYFLT *aout, *asig, *ifn; - float *coeffs, *out, *del; - int wp, irsize; - AUXCH buf; - int blocks, threads; -} CONV; - - -static int destroy_conv(CSOUND *csound, void *pp){ - CONV *p = (CONV *) pp; - cudaFree(p->coeffs); - cudaFree(p->del); - cudaFree(p->out); - return OK; -} - -static int conv_init(CSOUND *csound, CONV *p){ - - FUNC *ftab = csound->FTnp2Find(csound, p->ifn); - int irsize = ftab->flen; - int nsmps = CS_KSMPS,i; - int threads = irsize*nsmps; - float *tmp; - - cudaMalloc(&p->coeffs, sizeof(float)*irsize); - - tmp = (float*) malloc(sizeof(float)*irsize); - for(i=0; i< irsize; i++) - tmp[i] = (float) ftab->ftable[i]; - cudaMemcpy(p->coeffs,tmp, sizeof(float)*irsize, - cudaMemcpyHostToDevice); - free(tmp); - - cudaMalloc(&p->del, sizeof(float)*(irsize+nsmps)); - cudaMalloc(&p->out, sizeof(float)*threads); - cudaMemset(p->del,0,sizeof(float)*(irsize+nsmps)); - cudaMemset(p->out, 0, sizeof(float)*threads); - - p->wp = 0; - p->irsize = irsize; - - cudaDeviceProp deviceProp; - cudaGetDeviceProperties(&deviceProp, 0); - int blockspt = deviceProp.maxThreadsPerBlock; - csound->Message(csound, "CUDAconv: using device %s (capability %d.%d)\n", - deviceProp.name,deviceProp.major, deviceProp.minor); - - p->blocks = threads > blockspt ? ceil(threads/blockspt) : 1; - p->threads = threads > blockspt ? blockspt : threads; - - csound->RegisterDeinitCallback(csound, p, destroy_conv); - OPARMS parms; - csound->GetOParms(csound, &parms); - if(parms.odebug) - csound->Message(csound, "blocks %d, threads %d - %d\n", p->blocks, p->threads, threads); - if(p->buf.auxp == NULL) - csound->AuxAlloc(csound, sizeof(float)*CS_KSMPS, &p->buf); - - return OK; - -} -/* the delay size is irsize + vsize so that - we can shift in a whole block of samples */ -int conv_perf(CSOUND *csound, CONV *p){ - - int nsmps = CS_KSMPS; - MYFLT *sig = p->asig, *aout = p->aout; - float *del = p->del, *out = p->out, *coefs = p->coeffs, *buf = (float *)p->buf.auxp; - int irsize = p->irsize; - int wp = p->wp, i; - - for(i=0; i < nsmps; i++) buf[i] = (float) sig[i]; - if(wp > irsize) { - int front = wp - irsize; - cudaMemcpy(&del[wp], buf, sizeof(float)*(nsmps-front), cudaMemcpyHostToDevice); - cudaMemcpy(del, &buf[nsmps-front], sizeof(float)*front, cudaMemcpyHostToDevice); - } - else cudaMemcpy(&del[wp], buf, sizeof(float)*nsmps, cudaMemcpyHostToDevice); - - wp = (wp+nsmps)%(irsize+nsmps); /* wp is now the oldest sample in the delay */ - convol<<blocks,p->threads>>>(out, del, coefs, irsize, wp, nsmps); - - cudaMemcpy(buf, out, sizeof(float)*nsmps, cudaMemcpyDeviceToHost); - - for(i=0; i < nsmps; i++) aout[i] = (float) buf[i]; - p->wp = wp; - return OK; -} - -static OENTRY localops[] = { - {"cudaconv", sizeof(CONV),0, 5, "a", "ai", (SUBR) conv_init, NULL, - (SUBR) conv_perf}, -}; - -extern "C" { - LINKAGE -} diff --git a/6.x/src/CUDA/cuda_pvs_example.csd b/6.x/src/CUDA/cuda_pvs_example.csd deleted file mode 100644 index 9eeb7716..00000000 --- a/6.x/src/CUDA/cuda_pvs_example.csd +++ /dev/null @@ -1,40 +0,0 @@ - - -;--opcode-lib=./libcudaop2.dylib - - - -ksmps = 64 -0dbfs = 1 - -instr 1 -ifftsize = 4096 -ihopsize = 512 -asig = diskin2:a("flutec3.wav",1,0,1) -fsig = cudanal(asig, - ifftsize, - ihopsize, - ifftsize, 1) -asig = cudasynth(fsig) -asig = linenr(asig,0.005,0.01,0.01) - out(asig) -endin - -instr 2 -S1 = "flutec3.wav" -ifftsize = 32768 -ihopsize = 512 -asig diskin2 S1, 1, 0, 1 -fsig pvsanal asig, ifftsize, ihopsize, ifftsize, 1 -a1 pvsynth fsig -a2 linenr a1*0.5,0.005,0.01,0.01 - out a2 -endin - - - - -i1 0 60 - - - diff --git a/6.x/src/CUDA/cuda_sliding_example.csd b/6.x/src/CUDA/cuda_sliding_example.csd deleted file mode 100644 index 847e0e2b..00000000 --- a/6.x/src/CUDA/cuda_sliding_example.csd +++ /dev/null @@ -1,24 +0,0 @@ - - ---opcode-lib=./libcudaop3.dylib - - - -ksmps = 64 -0dbfs = 1 - -instr 1 -asig,adp diskin "metheny.wav",1,0,1 -amod = p4; oscil:a(2,3) -asig2 = cudasliding(asig,amod,p5) -asig = linenr(asig2,0.005,0.01,0.01) - out(asig*0.5) -endin - - - -i1 0 60 1 512 -;i1 0 5 0.5 1024 - - - diff --git a/6.x/src/CUDA/cudaconv.csd b/6.x/src/CUDA/cudaconv.csd deleted file mode 100644 index c81f48cf..00000000 --- a/6.x/src/CUDA/cudaconv.csd +++ /dev/null @@ -1,22 +0,0 @@ - - ---opcode-lib=libcudaop4.dylib - - -ksmps = 128 -i1 ftgen 1,0,1024,1,"/Users/victor/audio/church.wav",0,0,1 - -instr 1 - -asig diskin2 "/Users/victor/audio/cornetto.wav",1,01 -a1 cudaconv asig,1 -;a1 dconv asig,ftlen(1),1 - out a1/20 -endin - - - -i1 0 10 - - - diff --git a/6.x/src/CUDA/cudadsyn_pvs_example.csd b/6.x/src/CUDA/cudadsyn_pvs_example.csd deleted file mode 100644 index 00923131..00000000 --- a/6.x/src/CUDA/cudadsyn_pvs_example.csd +++ /dev/null @@ -1,39 +0,0 @@ - - ---opcode-lib=./libcudaop1.dylib --opcode-lib=./libcudaop2.dylib - - - -ksmps = 64 -0dbfs = 1 - -instr 1 -ifftsize = 2048 -ihopsize = 512 -ibins = 1024 -asig1,adp diskin "/users/victor/audio/metheny.wav",1,0,1 -fsig = pvsanal(asig1, ifftsize,ihopsize, ifftsize, 1) -asig = cudasynth(fsig,1,1,ibins) -asig = linenr(asig,0.001,0.01,0.01) - out(asig*0.5) - -endin - -instr 2 -ifftsize = 2048 -ihopsize = 512 -ibins = 1024 -asig1,adp diskin "/users/victor/audio/metheny.wav",1,0,1 -fsig = pvsanal(asig1, ifftsize,ihopsize, ifftsize, 1) -asig = pvsadsyn(fsig,ibins,1) -asig = linenr(asig,0.001,0.01,0.01) - out(asig*0.5) - -endin - - - -i1 0 60 - - - diff --git a/6.x/src/CUDA/cudapconv.csd b/6.x/src/CUDA/cudapconv.csd deleted file mode 100644 index be2e3372..00000000 --- a/6.x/src/CUDA/cudapconv.csd +++ /dev/null @@ -1,45 +0,0 @@ - - - - -ksmps = 8 -nchnls =2 -i1 ftgen 1,0,0,1,"church.wav",0,0,1 -i2 ftgen 2,0,64,1,"church.wav",0,0,1 -;i1 ftgen 1,0,65536,7,1,1,1,0,65534,0 -i1 ftgen 1,0,0,1,"/Users/victor/audio/metheny.wav",0,0,1 -instr 1 - -;asig oscili 0dbfs/4, 440; - -asig diskin2 "/Users/victor/audio/cornetto.wav",1,0,1 -a1 cudapconv asig,1,16384 -;a2 cudaconv asig,2 -;a1 ftconv asig,1,64 -;a1 pconvolve asig,"/Users/victor/audio/church_00.wav",1024 - out a1/500, a1/500 -endin - - - -i1 0 60 - - - - - - - 100 - 100 - 320 - 240 - true - - - 255 - 255 - 255 - - - - diff --git a/6.x/src/CUDA/pconv.cu b/6.x/src/CUDA/pconv.cu deleted file mode 100644 index 93f72e55..00000000 --- a/6.x/src/CUDA/pconv.cu +++ /dev/null @@ -1,263 +0,0 @@ -// -*- c++ -*- -/* pconv.cu - (c) Victor Lazzarini, 2013 - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ -#include -#include - -/* - each kernel processes one bin -*/ -__global__ void pconvol(float *out,float *in, - float *coef,int rp, int dftsize, - int nparts, int end) { - float re,im,re2,im2; - - /* thread count */ - int t = (threadIdx.x + blockIdx.x*blockDim.x); - - int k = t<<1; /* coef pos */ - int n = k%(dftsize+2); /* inframe pos */ - - /* if beyond the buffer end, exit */ - if(k >= end) return; - rp += k/(dftsize+2); /* rp pos */ - - /* select correct input buffer */ - in += (rp < nparts ? rp : rp%nparts)*(dftsize+2); - - re = coef[k]; im = coef[k+1]; - re2 = in[n]; im2 = in[n+1]; - - /* complex multiplication + sums */ - atomicAdd(&out[n], re*re2 - im*im2); - (n || n != dftsize) ? atomicAdd(&out[n+1], re*im2 + re2*im) : im; - -} - -/* sample-by-sample overlap-add operation */ -__global__ void olapadd(float *buf, float *in, int parts){ - int n = (threadIdx.x + blockIdx.x*blockDim.x); - buf[n] = in[n] + buf[parts+n]; - buf[parts+n] = in[parts+n]; -} - - - -typedef struct _pconv{ - OPDS h; - MYFLT *aout, *asig, *ifn, *parts; - float *out, *coef, *in, *buf; - AUXCH bufin, bufout; - int wp, nparts, dftsize, cnt; - cufftHandle plan, iplan; - int threads, blocks, othreads, oblocks; -} PCONV; - - -int isPowerOfTwo (unsigned int x) -{ - return ((x != 0) && !(x & (x - 1))); -} - - -static int destroy_pconv(CSOUND *csound, void *pp){ - PCONV *p = (PCONV *) pp; - cufftDestroy(p->plan); - cufftDestroy(p->iplan); - cudaFree(p->coef); - cudaFree(p->in); - cudaFree(p->out); - cudaFree(p->buf); - return OK; -} - - -int pconv_init(CSOUND *csound, PCONV *p){ - - FUNC *ftab = csound->FTnp2Find(csound, p->ifn); - float *tmp; - int tlen = ftab->flen; - int end, i, j, k, parts = *p->parts, dftsize, nparts; - MYFLT *tab = ftab->ftable; - - if(!isPowerOfTwo(parts)) - return csound->InitError(csound, "partition size needs to be power of two\n"); - - if(parts > tlen) - return csound->InitError(csound, "partition size too big \n"); - - end = tlen + parts - 1; - - nparts = end / parts; - dftsize = parts << 1; - end = nparts*(dftsize+2); - - cudaMalloc(&p->coef, sizeof(float)*end); - cudaMalloc(&p->in, sizeof(float)*end); - cudaMalloc(&p->out, sizeof(float)*(dftsize+2)); - cudaMalloc(&p->buf, sizeof(float)*(dftsize)); - cudaMemset(p->in,0,sizeof(float)*end); - cudaMemset(p->out, 0, sizeof(float)*(dftsize+2)); - cudaMemset(p->buf, 0, sizeof(float)*(dftsize)); - cudaMemset(p->coef, 0, sizeof(float)*end); - - p->wp = 0; - - if(!p->bufin.auxp || p->bufin.size < sizeof(float)*dftsize) - csound->AuxAlloc(csound, sizeof(float)*dftsize, &p->bufin); - if(!p->bufout.auxp || p->bufout.size < sizeof(float)*parts) - csound->AuxAlloc(csound, sizeof(float)*parts, &p->bufout); - - memset(p->bufout.auxp, 0, sizeof(float)*parts); - - tmp = (float *) p->bufin.auxp; - cufftPlan1d(&p->plan, dftsize, CUFFT_R2C, 1); -#if __CUDACC_VER_MAJOR__ < 8 - cufftSetCompatibilityMode(p->plan, CUFFT_COMPATIBILITY_NATIVE); -#endif - cufftPlan1d(&p->iplan, dftsize, CUFFT_C2R, 1); -#if __CUDACC_VER_MAJOR__ < 8 - cufftSetCompatibilityMode(p->iplan, CUFFT_COMPATIBILITY_NATIVE); -#endif - - for(i =0, k=0; i < nparts; i++){ - for(j=0; j < dftsize; j++) - tmp[j] = j < parts && k < tlen ? tab[k++] : 0.f; - float *pp = p->coef + (nparts - 1 - i)*(dftsize+2); - cudaMemcpy(pp, tmp, sizeof(float)*dftsize, - cudaMemcpyHostToDevice); - // csound->Message(csound,"CUDA init: copy buffer %d to device\n",i); - cufftExecR2C(p->plan,pp,(cufftComplex*)pp); - //csound->Message(csound,"CUDA init: done transform %d\n",i); - } - - cudaDeviceSynchronize(); - cudaDeviceProp deviceProp; - cudaGetDeviceProperties(&deviceProp, 0); - int blockspt = deviceProp.maxThreadsPerBlock; - csound->Message(csound, "CUDApconv: using device %s (capability %d.%d)\n", - deviceProp.name,deviceProp.major, deviceProp.minor); - - - end >>= 1; - - p->blocks = end > blockspt ? ceil(end/blockspt) : 1; - p->threads = end > blockspt ? blockspt : end; - p->oblocks = parts > blockspt ? ceil(parts/blockspt) : 1; - p->othreads = parts > blockspt ? blockspt : parts; - - csound->RegisterDeinitCallback(csound, p, destroy_pconv); - - OPARMS parms; - csound->GetOParms(csound, &parms); - if(parms.odebug) - csound->Message(csound, - "blocks %d - threads/block %d - threads %d - dftsize %d - parts %d\n", - p->blocks, p->threads, end, dftsize, nparts); - - p->nparts = nparts; - p->dftsize = dftsize; - p->cnt = 0; - - return OK; -} - -int pconv_perf(CSOUND *csound, PCONV *p){ - - int dftsize = p->dftsize, cnt = p->cnt, wp = p->wp, nparts = p->nparts; - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - float *bufin = (float *) p->bufin.auxp, *bufout = (float *) p->bufout.auxp; - MYFLT *asig = p->asig, *aout = p->aout; - float *in = p->in, *out = p->out, *coef = p->coef, *buf = p->buf; - int end = nparts*(dftsize+2); - int parts = *p->parts; - - if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); - } - - //csound->Message(csound,"pconv perf count: %d\n", cnt); - for(n = offset; n < nsmps; n++){ - bufin[cnt] = (float) asig[n]; - aout[n] = (MYFLT) bufout[cnt]/dftsize; - - if(++cnt == parts){ - //csound->Message(csound,"CUDA execution:\n"); - /* in buffer pos */ - int pos = wp*(dftsize+2); - - /* increment delay line pos - so that it points to the oldest partition - */ - wp += 1; - if(wp == nparts) wp = 0; - - /* copy current buffer into newest partition */ - cudaMemset(out, 0, sizeof(float)*(dftsize+2)); - cudaMemcpy(&in[pos],bufin,sizeof(float)*dftsize,cudaMemcpyHostToDevice); - //csound->Message(csound,"done copy to device\n"); - - /* apply transform */ - if(cufftExecR2C(p->plan,&in[pos],(cufftComplex*)&in[pos]) - != CUFFT_SUCCESS) csound->Message(csound, "cuda fft error\n"); - if (cudaDeviceSynchronize() != cudaSuccess) - csound->Message(csound,"Cuda error: Failed to synchronize\n"); - //csound->Message(csound,"done transform\n"); - - /* convolution */ - pconvol<<blocks,p->threads>>>(out, in, coef, wp, dftsize, nparts, end); - if (cudaDeviceSynchronize() != cudaSuccess) - csound->Message(csound,"Cuda error: Failed to synchronize\n"); - //csound->Message(csound,"done convolution\n"); - - /* transform output */ - if(cufftExecC2R(p->iplan,(cufftComplex*)out,out) - != CUFFT_SUCCESS) csound->Message(csound, "cuda fft error\n"); - //csound->Message(csound,"done inverse transform\n"); - - /* overlap-add */ - olapadd<<oblocks,p->othreads>>>(buf,out,parts); - //csound->Message(csound,"done overlap-add\n"); - - /* copy buffer out */ - cudaMemcpy(bufout,buf, sizeof(float)*parts,cudaMemcpyDeviceToHost); - //csound->Message(csound,"done copy from device\n"); - - cnt = 0; - } - } - p->cnt = cnt; - p->wp = wp; - return OK; -} - -static OENTRY localops[] = { - {"cudapconv", sizeof(PCONV),0, 3, "a", "aii", (SUBR) pconv_init, - (SUBR) pconv_perf}, -}; - -extern "C" { - LINKAGE -} diff --git a/6.x/src/CUDA/pconv11.cu b/6.x/src/CUDA/pconv11.cu deleted file mode 100644 index 7035ff4a..00000000 --- a/6.x/src/CUDA/pconv11.cu +++ /dev/null @@ -1,266 +0,0 @@ -// -*- c++ -*- -/* pconv.cu - experimental cuda opcodes - (c) Victor Lazzarini, 2013 - - based on M Puckette's pitch tracking algorithm. - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include -#include - -/* - each kernel processes one bin -*/ -__global__ void pconvol(float *out,float *in, - float *coef,int rp, int dftsize, - int nparts, int end) { - float re,im,re2,im2; - - /* thread count */ - int t = (threadIdx.x + blockIdx.x*blockDim.x); - - int k = t<<1; /* coef pos */ - int n = k%(dftsize+2); /* inframe pos */ - - /* if beyond the buffer end, exit */ - if(k >= end) return; - rp += k/(dftsize+2); /* rp pos */ - - /* select correct input buffer */ - in += (rp < nparts ? rp : rp%nparts)*(dftsize+2); - - re = coef[k]; im = coef[k+1]; - re2 = in[n]; im2 = in[n+1]; - - /* complex multiplication + sums */ - out[k] = re*re2 - im*im2; - out[k+1] = re*im2 + re2*im; - - if(t > dftsize+1) return; - __syncthreads(); - for(int i=dftsize+2; i < end; i+=(dftsize+2)) - out[t] += out[t + i]; - - -} - -/* sample-by-sample overlap-save operation */ -__global__ void olapsave(float *buf, float *in, int parts){ - int n = (threadIdx.x + blockIdx.x*blockDim.x); - buf[n] = in[n] + buf[parts+n]; - buf[parts+n] = in[parts+n]; -} - - - -typedef struct _pconv{ - OPDS h; - MYFLT *aout, *asig, *ifn, *parts; - float *out, *coef, *in, *buf; - AUXCH bufin, bufout; - int wp, nparts, dftsize, cnt; - cufftHandle plan, iplan; - int threads, blocks, othreads, oblocks; -} PCONV; - - -int isPowerOfTwo (unsigned int x) -{ - return ((x != 0) && !(x & (x - 1))); -} - - -static int destroy_pconv(CSOUND *csound, void *pp){ - PCONV *p = (PCONV *) pp; - cufftDestroy(p->plan); - cufftDestroy(p->iplan); - cudaFree(p->coef); - cudaFree(p->in); - cudaFree(p->out); - cudaFree(p->buf); - return OK; -} - - -int pconv_init(CSOUND *csound, PCONV *p){ - - FUNC *ftab = csound->FTnp2Find(csound, p->ifn); - float *tmp; - int tlen = ftab->flen; - int end, i, j, k, parts = *p->parts, dftsize, nparts; - MYFLT *tab = ftab->ftable; - - if(!isPowerOfTwo(parts)) - return csound->InitError(csound, "partition size needs to be power of two\n"); - - if(parts > tlen) - return csound->InitError(csound, "partition size too big \n"); - - end = tlen + parts - 1; - - nparts = end / parts; - dftsize = parts << 1; - end = nparts*(dftsize+2); - - cudaMalloc(&p->coef, sizeof(float)*end); - cudaMalloc(&p->in, sizeof(float)*end); - cudaMalloc(&p->out, sizeof(float)*end); - cudaMalloc(&p->buf, sizeof(float)*(dftsize)); - - cudaMemset(p->in,0,sizeof(float)*end); - cudaMemset(p->out, 0, sizeof(float)*end); - cudaMemset(p->buf, 0, sizeof(float)*(dftsize)); - cudaMemset(p->coef, 0, sizeof(float)*end); - - p->wp = 0; - - if(!p->bufin.auxp || p->bufin.size < sizeof(float)*dftsize) - csound->AuxAlloc(csound, sizeof(float)*dftsize, &p->bufin); - if(!p->bufout.auxp || p->bufout.size < sizeof(float)*parts) - csound->AuxAlloc(csound, sizeof(float)*parts, &p->bufout); - - memset(p->bufout.auxp, 0, sizeof(float)*parts); - - cufftResult res; - - tmp = (float *) p->bufin.auxp; - if((res = cufftPlan1d(&p->plan, dftsize, CUFFT_R2C, 1)) - != CUFFT_SUCCESS) csound->Message(csound, "cuda fft setup error %d\n", res); - cufftSetCompatibilityMode(p->plan, CUFFT_COMPATIBILITY_NATIVE); - cufftPlan1d(&p->iplan, dftsize, CUFFT_C2R, 1); - cufftSetCompatibilityMode(p->iplan, CUFFT_COMPATIBILITY_NATIVE); - - - for(i =0, k=0; i < nparts; i++){ - for(j=0; j < dftsize; j++) - tmp[j] = j < parts && k < tlen ? tab[k++] : 0.f; - float *pp = p->coef + (nparts - 1 - i)*(dftsize+2); - cudaMemcpy(pp, tmp, sizeof(float)*dftsize, - cudaMemcpyHostToDevice); - if((res = cufftExecR2C(p->plan,pp,(cufftComplex*)pp)) - != CUFFT_SUCCESS) csound->Message(csound, "cuda fft error %d\n", res); - } - - cudaDeviceSynchronize(); - cudaDeviceProp deviceProp; - cudaGetDeviceProperties(&deviceProp, 0); - int blockspt = deviceProp.maxThreadsPerBlock; - - end >>= 1; - - p->blocks = end > blockspt ? ceil(end/blockspt) : 1; - p->threads = end > blockspt ? blockspt : end; - p->oblocks = parts > blockspt ? ceil(parts/blockspt) : 1; - p->othreads = parts > blockspt ? blockspt : parts; - - csound->RegisterDeinitCallback(csound, p, destroy_pconv); - - OPARMS parms; - csound->GetOParms(csound, &parms); - if(parms.odebug) - csound->Message(csound, - "blocks %d - threads/block %d - threads %d - dftsize %d - parts %d\n", - p->blocks, p->threads, end, dftsize, nparts); - - p->nparts = nparts; - p->dftsize = dftsize; - p->cnt = 0; - - return OK; -} - -int pconv_perf(CSOUND *csound, PCONV *p){ - - int dftsize = p->dftsize, cnt = p->cnt, wp = p->wp, nparts = p->nparts; - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - float *bufin = (float *) p->bufin.auxp, *bufout = (float *) p->bufout.auxp; - MYFLT *asig = p->asig, *aout = p->aout; - float *in = p->in, *out = p->out, *coef = p->coef, *buf = p->buf; - int end = nparts*(dftsize+2); - int parts = *p->parts; - - if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); - } - - for(n = offset; n < nsmps; n++){ - bufin[cnt] = (float) asig[n]; - aout[n] = (MYFLT) bufout[cnt]/dftsize; - - if(++cnt == parts){ - /* in buffer pos */ - int pos = wp*(dftsize+2); - - /* increment delay line pos - so that it points to the oldest partition - */ - wp += 1; - if(wp == nparts) wp = 0; - - /* copy current buffer into newest partition */ - cudaMemset(out, 0, sizeof(float)*(dftsize+2)); - cudaMemcpy(&in[pos],bufin,sizeof(float)*dftsize,cudaMemcpyHostToDevice); - - /* apply transform */ - if(cufftExecR2C(p->plan,&in[pos],(cufftComplex*)&in[pos]) - != CUFFT_SUCCESS) csound->Message(csound, "cuda in fft error\n"); - if (cudaDeviceSynchronize() != cudaSuccess) - csound->Message(csound,"Cuda error: Failed to synchronize\n"); - - /* convolution */ - pconvol<<blocks,p->threads>>>(out, in, coef, wp, dftsize, nparts, end); - - if (cudaDeviceSynchronize() != cudaSuccess) - csound->Message(csound,"Cuda error: Failed to synchronize\n"); - - /* transform output */ - if(cufftExecC2R(p->iplan,(cufftComplex*)out,out) - != CUFFT_SUCCESS) csound->Message(csound, "cuda out fft error\n"); - - if (cudaDeviceSynchronize() != cudaSuccess) - csound->Message(csound,"Cuda error: Failed to synchronize\n"); - - /* overlap-save */ - olapsave<<oblocks,p->othreads>>>(buf,out,parts); - - /* copy buffer out */ - cudaMemcpy(bufout,buf, sizeof(float)*parts,cudaMemcpyDeviceToHost); - - cnt = 0; - } - } - p->cnt = cnt; - p->wp = wp; - return OK; -} - -static OENTRY localops[] = { - {"cudapconv", sizeof(PCONV),0, 5, "a", "aii", (SUBR) pconv_init, NULL, - (SUBR) pconv_perf}, -}; - -extern "C" { - LINKAGE -} diff --git a/6.x/src/CUDA/pvsops.cu b/6.x/src/CUDA/pvsops.cu deleted file mode 100644 index df3268de..00000000 --- a/6.x/src/CUDA/pvsops.cu +++ /dev/null @@ -1,448 +0,0 @@ -// -*- c++ -*- -/* pvsops.cu - experimental cuda opcodes - - (c) Victor Lazzarini, 2013 - - based on M Puckette's pitch tracking algorithm. - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include -#include - -#include - -/* kernel to convert from pvs to rectangular frame */ -__global__ void frompvs(float* inframe, double* lastph, - double scal, double fac) { - - int k = threadIdx.x + blockIdx.x*blockDim.x + 1; - int i = k << 1; - float mag = inframe[i]; - double delta = (inframe[i+1] - k*scal)*fac; - double phi = fmod(lastph[k-1] + delta, TWOPI); - lastph[k-1] = phi; - inframe[i] = (float) (mag*cos(phi)); - inframe[i+1] = (float) (mag*sin(phi)); -} - -__global__ void winrotate(float* inframe2, float* inframe, float *win, - int N, int offset){ - int k = (threadIdx.x + blockIdx.x*blockDim.x); - inframe2[k] = win[k]*inframe[(k+offset)%N]; -} - -typedef struct _pvsyn{ - OPDS h; - MYFLT *asig; - PVSDAT *fsig; - float *inframe; /* N */ - float *inframe2; - double *lastph; /* N/2 */ - float *win; /* N */ - int framecount; - int curframe; - AUXCH frames; - AUXCH count; - cufftHandle plan; - double scal, fac; - int bblocks, nblocks; - int bthreads, nthreads; -} PVSYN; - -static int destroy_pvsyn(CSOUND *csound, void *pp); - -static int pvsynset(CSOUND *csound, PVSYN *p){ - - int N = p->fsig->N; - - if((N != 0) && !(N & (N - 1))) { - int hsize = p->fsig->overlap; - int size, numframes, i, blockspt; - MYFLT sum = 0.0, bins = N/2; - float *win; - cudaDeviceProp deviceProp; - cudaGetDeviceProperties(&deviceProp, 0); - blockspt = deviceProp.maxThreadsPerBlock; - csound->Message(csound, "CUDAsynth: using device %s (capability %d.%d)\n", - deviceProp.name,deviceProp.major, deviceProp.minor); - - if(p->fsig->wintype != 1) - return csound->InitError(csound, - "window type not implemented yet\n"); - numframes = N/hsize; - size = N*sizeof(float)*numframes; - if(p->frames.auxp == NULL || - p->frames.size < size) - csound->AuxAlloc(csound, size, &p->frames); - memset(p->frames.auxp, 0, size); - - size = sizeof(int)*numframes; - if(p->count.auxp == NULL || - p->count.size < size) - csound->AuxAlloc(csound, size, &p->count); - *((int *)(p->count.auxp)) = 0; - for(i=1; i < numframes; i++) - ((int *)(p->count.auxp))[i] = - (i + (1.f - (float)i/numframes))*N; - - size = (N+2)*sizeof(float); - cudaMalloc(&p->inframe, size); - cudaMemset(p->inframe, 0, size); - size = (N+2)*sizeof(float); - cudaMalloc(&p->inframe2, size); - size = (N+2)*sizeof(float); - cudaMalloc(&p->lastph, size); - cudaMemset(p->lastph, 0, size); - size = N*sizeof(float); - cudaMalloc(&p->win, size); - - win = (float *) malloc(sizeof(float)*(N+1)); - for(i=0; i <= N; i++) - win[i] = (float) (0.5 - 0.5*cos(i*TWOPI/N)); - - for(i = 0; i < N; i++) sum += win[i]; - sum = FL(2.0) / sum; - for(i = 0; i < N; i++) win[i] *= sum; - sum = FL(0.0); - for(i = 0; i <= N; i+=hsize) - sum += win[i] * win[i]; - sum = (1.0/N)/(sum); - for(i = 0; i < N; i++) win[i] *= 3*sum/sqrt(numframes); - cudaMemcpy(p->win,win,N*sizeof(float), - cudaMemcpyHostToDevice); - free(win); - - p->framecount = 0; - p->curframe = 0; - - p->fac = TWOPI*hsize/csound->GetSr(csound); - p->scal =csound->GetSr(csound)/N; - cufftPlan1d(&p->plan, N, CUFFT_C2R, 1); -#if __CUDACC_VER_MAJOR__ < 8 - cufftSetCompatibilityMode(p->plan, CUFFT_COMPATIBILITY_NATIVE); -#endif - csound->RegisterDeinitCallback(csound, p, destroy_pvsyn); - - p->bblocks = bins > blockspt? bins/blockspt : 1; - p->nblocks = N > blockspt ? N/blockspt : 1; - p->bthreads = bins/p->bblocks; - p->nthreads = N/p->nblocks; - if(csound->GetDebug(csound)) - csound->Message(csound, "%d (%d each), %d (%d each)\n", - p->nblocks, p->nthreads, p->bblocks, p->bthreads); - return OK; - } - return csound->InitError(csound, "fftsize not power-of-two \n"); - -} - -static int pvsynperf(CSOUND *csound, PVSYN *p){ - - int N = p->fsig->N, i; - int hsize = p->fsig->overlap; - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - MYFLT *asig = p->asig; - float *frames = (float *) p->frames.auxp; - int framecount = p->framecount; - int numframes = N/hsize; - int *count = (int *) p->count.auxp; - - if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); - } - - for(n=offset; n < nsmps; n++) { - - if(framecount == 0) { - int curframe = p->curframe; - /* start offset for current frame */ - int start = N*curframe; - float *cur = &(frames[start]); - float *win = (float *) p->win; - float *inframe = p->inframe; - float *inframe2 = p->inframe2; - float *fsig = (float *) p->fsig->frame.auxp; - /* copy fsig data to device */ - fsig[N+1] = fsig[1] = 0.f; - cudaMemcpy(inframe,fsig,(N+2)*sizeof(float), - cudaMemcpyHostToDevice); - /* perf pvs to rect conversion */ - frompvs<<bblocks,p->bthreads-1>>>(inframe,p->lastph,p->scal,p->fac); - /* execute inverse real FFT */ - if(cufftExecC2R(p->plan,(cufftComplex*)inframe,inframe) - != CUFFT_SUCCESS) csound->Message(csound, "cuda fft error\n"); - if (cudaDeviceSynchronize() != cudaSuccess) - csound->Message(csound,"Cuda error: Failed to synchronize\n"); - /* window and rotate data on device */ - winrotate<<nblocks,p->nthreads>>>(inframe2,inframe,win,N,hsize*curframe); - /* copy data to current out frame */ - cudaMemcpy(cur,inframe2,N*sizeof(float),cudaMemcpyDeviceToHost); - /* reset counter for this frame to the start */ - count[curframe] = start; - /* move current to next frame circularly */ - p->curframe = ++(curframe) == numframes ? 0 : curframe; - framecount = hsize; - } - asig[n] = FL(0.0); - for(i=0; i < numframes; i++){ - /* overlap-add */ - asig[n] += frames[count[i]]; - count[i]++; - } - framecount--; - } - p->framecount = framecount; - return OK; -} - -static int destroy_pvsyn(CSOUND *csound, void *pp){ - PVSYN *p = (PVSYN *) pp; - cufftDestroy(p->plan); - cudaFree(p->inframe); - cudaFree(p->inframe2); - cudaFree(p->lastph); - cudaFree(p->win); - return OK; -} - -__device__ double modTwoPi(double x) -{ - x = fmod(x,TWOPI); - return x <= -PI ? x + TWOPI : - (x > PI ? x - TWOPI : x); -} - -/* kernel to convert from rectangular to pvs frame */ -__global__ void topvs(float* aframe, double* oldph, - double scal, double fac) { - int k = threadIdx.x + blockIdx.x*blockDim.x + 1; - int i = k << 1; - - float re = aframe[i], im = aframe[i+1]; - float mag = sqrtf(re*re + im*im); - double phi = atan2f(im,re); - double delta = phi - oldph[k-1]; - oldph[k-1] = phi; - aframe[i] = mag; - aframe[i+1] = (float) ((modTwoPi(delta) + k*scal)*fac); -} - -__global__ void rotatewin(float* aframe2, float *aframe, float *win, - int N, int offset){ - int k = threadIdx.x + blockIdx.x*blockDim.x; - aframe2[(k+offset)%N] = win[k]*aframe[k]; -} - -typedef struct _pvan { - OPDS h; - PVSDAT *fsig; - MYFLT *asig,*fftsize,*hsize,*winsize,*wintype; - - float *aframe; /* N */ - float *aframe2; - double *oldph; /* N/2 */ - float *win; /* N */ - - int framecount; - int curframe; - AUXCH frames; - AUXCH count; - cufftHandle plan; - double scal, fac; - int bblocks, nblocks; - int bthreads, nthreads; -} PVAN; - -static int destroy_pvanal(CSOUND *csound, void *pp); - -static int pvanalset(CSOUND *csound, PVAN *p){ - - int N = *p->fftsize; - if((N != 0) && !(N & (N - 1))) { - int size, numframes, i, bins = N/2; - int hsize = *p->hsize, blockspt; - float *win; - cudaDeviceProp deviceProp; - cudaGetDeviceProperties(&deviceProp, 0); - blockspt = deviceProp.maxThreadsPerBlock; - csound->Message(csound, "CUDAnal: using device %s (capability %d.%d)\n", - deviceProp.name,deviceProp.major, deviceProp.minor); - - p->fsig->N = N; - p->fsig->overlap = hsize; - /* ignore winsize & wintype */ - p->fsig->winsize = N; - p->fsig->wintype = 1; - p->fsig->framecount = 0; - - numframes = N/hsize; - size = N*sizeof(float)*numframes; - if(p->frames.auxp == NULL || - p->frames.size < size) - csound->AuxAlloc(csound, size, &p->frames); - memset(p->frames.auxp, 0, size); - - size = (N+2)*sizeof(float); - if(p->fsig->frame.auxp == NULL || - p->fsig->frame.size < size) - csound->AuxAlloc(csound, size, &p->fsig->frame); - memset(p->fsig->frame.auxp, 0, size); - - size = sizeof(int)*numframes; - if(p->count.auxp == NULL || - p->count.size < size) - csound->AuxAlloc(csound, size, &p->count); - *((int *)(p->count.auxp)) = 0; - for(i=1; i < numframes; i++) - ((int *)(p->count.auxp))[i] = - (i + (float)i/numframes)*N; - - size = (N+2)*sizeof(float); - cudaMalloc(&p->aframe, size); - size = (N+2)*sizeof(float); - cudaMalloc(&p->aframe2, size); - size = (N/2-1)*sizeof(double); - cudaMalloc(&p->oldph, size); - cudaMemset(p->oldph, 0, size); - size = N*sizeof(float); - cudaMalloc(&p->win, size); - - win = (float *) malloc(sizeof(float)*N); - for(i=0; i < N; i++) - win[i] = (float) (0.5 - 0.5*cos(i*TWOPI/N)); - float sum = 0.0; - for(i = 0; i < N; i++) sum += win[i]; - sum = FL(2.0) / sum; - for(i = 0; i < N; i++) win[i] *= sum; - - cudaMemcpy(p->win,win,N*sizeof(float), - cudaMemcpyHostToDevice); - free(win); - - p->framecount = 1; - p->curframe = numframes-1; - p->fac = csound->GetSr(csound)/(TWOPI*hsize); - p->scal = (TWOPI*hsize)/N; - cufftPlan1d(&p->plan, N, CUFFT_R2C, 1); -#if __CUDACC_VER_MAJOR__ < 8 - cufftSetCompatibilityMode(p->plan, CUFFT_COMPATIBILITY_NATIVE); -#endif - csound->RegisterDeinitCallback(csound, p, destroy_pvanal); - - p->bblocks = bins > blockspt? bins/blockspt : 1; - p->nblocks = N > blockspt ? N/blockspt : 1; - p->bthreads = bins/p->bblocks; - p->nthreads = N/p->nblocks; - if(csound->GetDebug(csound)) - csound->Message(csound, "%d (%d each), %d (%d each)\n", - p->nblocks, p->nthreads, p->bblocks, p->bthreads); - return OK; - } - return csound->InitError(csound, "fftsize not power-of-two \n"); -} - -static int pvanalperf(CSOUND *csound, PVAN *p){ - - int N = p->fsig->N, i; - int hsize = p->fsig->overlap; - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - MYFLT *asig = p->asig; - float *frames = (float *) p->frames.auxp; - int framecount = p->framecount; - int numframes = N/hsize; - int *count = (int *) p->count.auxp; - - if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); - } - - for(n=offset; n < nsmps; n++) { - for(i=0; i < numframes; i++){ - frames[count[i]] = asig[n]; - count[i]++; - } - framecount++; - - if(framecount == hsize) { - int curframe = p->curframe; - /* start offset for current frame */ - int start = N*curframe; - float *cur = &(frames[start]); - float *win = (float *) p->win; - float *aframe = p->aframe; - float *aframe2 = p->aframe2; - float *fsig = (float *) p->fsig->frame.auxp; - /* copy fsig data to device */ - cudaMemcpy(aframe,cur,N*sizeof(float), - cudaMemcpyHostToDevice); - /* window and rotate data on device */ - rotatewin<<nblocks,p->nthreads>>>(aframe2,aframe,win,N, - hsize*(numframes-curframe)); - /* execute inverse real FFT */ - if(cufftExecR2C(p->plan,aframe2,(cufftComplex*)aframe2) - != CUFFT_SUCCESS) csound->Message(csound, "cuda fft error\n"); - if (cudaDeviceSynchronize() != cudaSuccess) - csound->Message(csound,"Cuda error: Failed to synchronize\n"); - /* perf rect to pvs conversion */ - topvs<<bblocks,p->bthreads-1>>>(aframe2,p->oldph,p->scal,p->fac); - /* copy data to current out frame */ - cudaMemcpy(fsig,aframe2,(N+2)*sizeof(float),cudaMemcpyDeviceToHost); - /* reset counter for this frame to the start */ - fsig[N+1] = fsig[1] = 0.f; - count[curframe] = start; - /* move current to next frame circularly */ - p->curframe = --(curframe) < 0 ? numframes-1 : curframe; - framecount = 0; - p->fsig->framecount++; - } - } - p->framecount = framecount; - return OK; -} - -static int destroy_pvanal(CSOUND *csound, void *pp){ - PVAN *p = (PVAN *) pp; - cufftDestroy(p->plan); - cudaFree(p->aframe); - cudaFree(p->aframe2); - cudaFree(p->oldph); - cudaFree(p->win); - return OK; -} - -static OENTRY localops[] = { - {"cudasynth", sizeof(PVSYN),0, 3, "a", "f", (SUBR) pvsynset, - (SUBR) pvsynperf}, - {"cudanal", sizeof(PVAN),0, 3, "f", "aiiii", (SUBR) pvanalset, - (SUBR) pvanalperf} -}; - -extern "C" { - LINKAGE -} diff --git a/6.x/src/CUDA/pvsops2-build.sh b/6.x/src/CUDA/pvsops2-build.sh deleted file mode 100644 index a762cf77..00000000 --- a/6.x/src/CUDA/pvsops2-build.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -# use -Xptxas="-v" to check register usage and --maxrregcount 32 to limit it -echo "building cuda opcodes ..." -nvcc -O3 -shared -o libcudapvs2.dylib pvsops2.cu -use_fast_math -g -I../../debug/CsoundLib64.framework/Headers -arch=sm_30 -I/usr/local/cuda/include -L/usr/local/cuda/lib -lcufft -echo "...done" diff --git a/6.x/src/CUDA/pvsops2.cu b/6.x/src/CUDA/pvsops2.cu deleted file mode 100644 index 4e1eb2ef..00000000 --- a/6.x/src/CUDA/pvsops2.cu +++ /dev/null @@ -1,530 +0,0 @@ -// -*- c++ -*- -/* pvsops.cu - experimental cuda opcodes - - (c) Victor Lazzarini, 2013 - - based on M Puckette's pitch tracking algorithm. - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include -#include - -#include - -void AuxCudaAlloc(int size, AUXCH *p){ - float *mem; - cudaMalloc(&mem, size); - cudaMemset(mem, 0, size); - p->auxp = mem; - p->size = size; -} - - -/* kernel to convert from pvs to rectangular frame */ -__global__ void frompvs(float* inframe, float* fsig, double* lastph, - double scal, double fac) { - - int k = threadIdx.x + blockIdx.x*blockDim.x; - int i = k << 1; - float mag = fsig[i]; - double delta = (fsig[i+1] - k*scal)*fac; - double phi = fmod(lastph[k] + delta, TWOPI); - lastph[k] = phi; - inframe[i] = (float) (mag*cos(phi)); - inframe[i+1] = (float) (mag*sin(phi)); -} - -__global__ void winrotate(float* inframe2, float* inframe, float *win, - int N, int offset){ - int k = (threadIdx.x + blockIdx.x*blockDim.x); - inframe2[k] = win[k]*inframe[(k+offset)%N]; -} - -typedef struct _pvsyn{ - OPDS h; - MYFLT *asig; - PVSDAT *fsig; - float *inframe; /* N */ - float *inframe2; - double *lastph; /* N/2 */ - float *win; /* N */ - int framecount; - int curframe; - AUXCH frames; - AUXCH count; - cufftHandle plan; - double scal, fac; - int bblocks, nblocks; - int bthreads, nthreads; -} PVSYN; - -static int destroy_pvsyn(CSOUND *csound, void *pp); - -static int pvsynset(CSOUND *csound, PVSYN *p){ - - int N = p->fsig->N; - - if((N != 0) && !(N & (N - 1))) { - int hsize = p->fsig->overlap; - int size, numframes, i, blockspt; - MYFLT sum = 0.0, bins = N/2; - float *win; - cudaDeviceProp deviceProp; - cudaGetDeviceProperties(&deviceProp, 0); - blockspt = deviceProp.maxThreadsPerBlock; - csound->Message(csound, "CUDAsynth: using device %s (capability %d.%d)\n", - deviceProp.name,deviceProp.major, deviceProp.minor); - - if(p->fsig->wintype != 1) - return csound->InitError(csound, - "window type not implemented yet\n"); - numframes = N/hsize; - size = N*sizeof(float)*numframes; - if(p->frames.auxp == NULL || - p->frames.size < size) - csound->AuxAlloc(csound, size, &p->frames); - memset(p->frames.auxp, 0, size); - - size = sizeof(int)*numframes; - if(p->count.auxp == NULL || - p->count.size < size) - csound->AuxAlloc(csound, size, &p->count); - *((int *)(p->count.auxp)) = 0; - for(i=1; i < numframes; i++) - ((int *)(p->count.auxp))[i] = - (i + (1.f - (float)i/numframes))*N; - - size = (N+2)*sizeof(float); - cudaMalloc(&p->inframe, size); - cudaMemset(p->inframe, 0, size); - size = (N+2)*sizeof(float); - cudaMalloc(&p->inframe2, size); - size = (N/2)*sizeof(double); - cudaMalloc(&p->lastph, size); - cudaMemset(p->lastph, 0, size); - size = N*sizeof(float); - cudaMalloc(&p->win, size); - - win = (float *) malloc(sizeof(float)*(N+1)); - for(i=0; i <= N; i++) - win[i] = (float) (0.5 - 0.5*cos(i*TWOPI/N)); - - for(i = 0; i < N; i++) sum += win[i]; - sum = FL(2.0) / sum; - for(i = 0; i < N; i++) win[i] *= sum; - sum = FL(0.0); - for(i = 0; i <= N; i+=hsize) - sum += win[i] * win[i]; - sum = (1.0/N)/(sum); - for(i = 0; i < N; i++) win[i] *= 3*sum/sqrt(numframes); - cudaMemcpy(p->win,win,N*sizeof(float), - cudaMemcpyHostToDevice); - free(win); - - p->framecount = 0; - p->curframe = 0; - - p->fac = TWOPI*hsize/csound->GetSr(csound); - p->scal =csound->GetSr(csound)/N; - cufftPlan1d(&p->plan, N, CUFFT_C2R, 1); - cufftSetCompatibilityMode(p->plan, CUFFT_COMPATIBILITY_NATIVE); - csound->RegisterDeinitCallback(csound, p, destroy_pvsyn); - - p->bblocks = bins > blockspt? bins/blockspt : 1; - p->nblocks = N > blockspt ? N/blockspt : 1; - p->bthreads = bins/p->bblocks; - p->nthreads = N/p->nblocks; - if(csound->GetDebug(csound)) - csound->Message(csound, "%d (%d each), %d (%d each)\n", - p->nblocks, p->nthreads, p->bblocks, p->bthreads); - return OK; - } - return csound->InitError(csound, "fftsize not power-of-two \n"); - -} - -static int pvsynperf(CSOUND *csound, PVSYN *p){ - - int N = p->fsig->N, i; - int hsize = p->fsig->overlap; - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - MYFLT *asig = p->asig; - float *frames = (float *) p->frames.auxp; - int framecount = p->framecount; - int numframes = N/hsize; - int *count = (int *) p->count.auxp; - - if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); - } - - for(n=offset; n < nsmps; n++) { - - if(framecount == 0) { - int curframe = p->curframe; - /* start offset for current frame */ - int start = N*curframe; - float *cur = &(frames[start]); - float *win = (float *) p->win; - float *inframe = p->inframe; - float *inframe2 = p->inframe2; - float *fsig = (float *) p->fsig->frame.auxp; - /* perf pvs to rect conversion */ - frompvs<<bblocks,p->bthreads>>>(inframe,fsig,p->lastph,p->scal,p->fac); - /* execute inverse real FFT */ - if(cufftExecC2R(p->plan,(cufftComplex*)inframe,inframe) - != CUFFT_SUCCESS) csound->Message(csound, "cuda fft error\n"); - if (cudaDeviceSynchronize() != cudaSuccess) - csound->Message(csound,"Cuda error: Failed to synchronize\n"); - /* window and rotate data on device */ - winrotate<<nblocks,p->nthreads>>>(inframe2,inframe,win,N,hsize*curframe); - /* copy data to current out frame */ - cudaMemcpy(cur,inframe2,N*sizeof(float),cudaMemcpyDeviceToHost); - /* reset counter for this frame to the start */ - count[curframe] = start; - /* move current to next frame circularly */ - p->curframe = ++(curframe) == numframes ? 0 : curframe; - framecount = hsize; - } - asig[n] = FL(0.0); - for(i=0; i < numframes; i++){ - /* overlap-add */ - asig[n] += frames[count[i]]; - count[i]++; - } - framecount--; - } - p->framecount = framecount; - return OK; -} - -static int destroy_pvsyn(CSOUND *csound, void *pp){ - PVSYN *p = (PVSYN *) pp; - cufftDestroy(p->plan); - cudaFree(p->inframe); - cudaFree(p->inframe2); - cudaFree(p->lastph); - cudaFree(p->win); - return OK; -} - -__device__ double modTwoPi(double x) -{ - x = fmod(x,TWOPI); - return x <= -PI ? x + TWOPI : - (x > PI ? x - TWOPI : x); -} - -/* kernel to convert from rectangular to pvs frame */ -__global__ void topvs(float *fsig, float *aframe, double* oldph, - double scal, double fac) { - int k = threadIdx.x + blockIdx.x*blockDim.x; - int i = k << 1; - float re = aframe[i], im = aframe[i+1]; - float mag = sqrtf(re*re + im*im); - double phi = atan2f(im,re); - double delta = phi - oldph[k]; - oldph[k] = phi; - fsig[i] = mag; - fsig[i+1] = (float) ((modTwoPi(delta) + k*scal)*fac); -} - -__global__ void rotatewin(float* aframe2, float *aframe, float *win, - int N, int offset){ - int k = threadIdx.x + blockIdx.x*blockDim.x; - aframe2[(k+offset)%N] = win[k]*aframe[k]; -} - -typedef struct _pvan { - OPDS h; - PVSDAT *fsig; - MYFLT *asig,*fftsize,*hsize,*winsize,*wintype; - - float *aframe; /* N */ - float *aframe2; - double *oldph; /* N/2 */ - float *win; /* N */ - - int framecount; - int curframe; - AUXCH frames; - AUXCH count; - cufftHandle plan; - double scal, fac; - int bblocks, nblocks; - int bthreads, nthreads; -} PVAN; - -static int destroy_pvanal(CSOUND *csound, void *pp); - -static int pvanalset(CSOUND *csound, PVAN *p){ - - int N = *p->fftsize; - if((N != 0) && !(N & (N - 1))) { - int size, numframes, i, bins = N/2; - int hsize = *p->hsize, blockspt; - float *win; - cudaDeviceProp deviceProp; - cudaGetDeviceProperties(&deviceProp, 0); - blockspt = deviceProp.maxThreadsPerBlock; - csound->Message(csound, "CUDAnal: using device %s (capability %d.%d)\n", - deviceProp.name,deviceProp.major, deviceProp.minor); - - p->fsig->N = N; - p->fsig->overlap = hsize; - p->fsig->format = -1; - /* ignore winsize & wintype */ - p->fsig->winsize = N; - p->fsig->wintype = 1; - p->fsig->framecount = 0; - - numframes = N/hsize; - size = N*sizeof(float)*numframes; - if(p->frames.auxp == NULL || - p->frames.size < size) - csound->AuxAlloc(csound, size, &p->frames); - memset(p->frames.auxp, 0, size); - - size = (N+2)*sizeof(float); - if(p->fsig->frame.auxp == NULL || - p->fsig->frame.size < size) - AuxCudaAlloc(size, &p->fsig->frame); - - size = sizeof(int)*numframes; - if(p->count.auxp == NULL || - p->count.size < size) - csound->AuxAlloc(csound, size, &p->count); - *((int *)(p->count.auxp)) = 0; - for(i=1; i < numframes; i++) - ((int *)(p->count.auxp))[i] = - (i + (float)i/numframes)*N; - - size = (N+2)*sizeof(float); - cudaMalloc(&p->aframe, size); - size = (N+2)*sizeof(float); - cudaMalloc(&p->aframe2, size); - size = (N/2)*sizeof(double); - cudaMalloc(&p->oldph, size); - cudaMemset(p->oldph, 0, size); - size = N*sizeof(float); - cudaMalloc(&p->win, size); - - - win = (float *) malloc(sizeof(float)*N); - for(i=0; i < N; i++) - win[i] = (float) (0.5 - 0.5*cos(i*TWOPI/N)); - float sum = 0.0; - for(i = 0; i < N; i++) sum += win[i]; - sum = FL(2.0) / sum; - for(i = 0; i < N; i++) win[i] *= sum; - - cudaMemcpy(p->win,win,N*sizeof(float), - cudaMemcpyHostToDevice); - free(win); - - p->framecount = 1; - p->curframe = numframes-1; - p->fac = csound->GetSr(csound)/(TWOPI*hsize); - p->scal = (TWOPI*hsize)/N; - cufftPlan1d(&p->plan, N, CUFFT_R2C, 1); - cufftSetCompatibilityMode(p->plan, CUFFT_COMPATIBILITY_NATIVE); - csound->RegisterDeinitCallback(csound, p, destroy_pvanal); - - p->bblocks = bins > blockspt? bins/blockspt : 1; - p->nblocks = N > blockspt ? N/blockspt : 1; - p->bthreads = bins/p->bblocks; - p->nthreads = N/p->nblocks; - if(csound->GetDebug(csound)) - csound->Message(csound, "%d (%d each), %d (%d each)\n", - p->nblocks, p->nthreads, p->bblocks, p->bthreads); - return OK; - } - return csound->InitError(csound, "fftsize not power-of-two \n"); -} - -static int pvanalperf(CSOUND *csound, PVAN *p){ - - int N = p->fsig->N, i; - int hsize = p->fsig->overlap; - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - MYFLT *asig = p->asig; - float *frames = (float *) p->frames.auxp; - int framecount = p->framecount; - int numframes = N/hsize; - int *count = (int *) p->count.auxp; - - if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); - } - - for(n=offset; n < nsmps; n++) { - for(i=0; i < numframes; i++){ - frames[count[i]] = asig[n]; - count[i]++; - } - framecount++; - - if(framecount == hsize) { - int curframe = p->curframe; - /* start offset for current frame */ - int start = N*curframe; - float *cur = &(frames[start]); - float *win = (float *) p->win; - float *aframe = p->aframe; - float *aframe2 = p->aframe2; - float *fsig = (float *) p->fsig->frame.auxp; - cudaMemcpy(aframe,cur,N*sizeof(float), - cudaMemcpyHostToDevice); - /* window and rotate data on device */ - rotatewin<<nblocks,p->nthreads>>>(aframe2,aframe,win,N, - hsize*(numframes-curframe)); - /* execute inverse real FFT */ - if(cufftExecR2C(p->plan,aframe2,(cufftComplex*)aframe2) - != CUFFT_SUCCESS) csound->Message(csound, "cuda fft error\n"); - if (cudaDeviceSynchronize() != cudaSuccess) - csound->Message(csound,"Cuda error: Failed to synchronize\n"); - /* perf rect to pvs conversion */ - topvs<<bblocks,p->bthreads>>>(fsig,aframe2,p->oldph,p->scal,p->fac); - /* reset counter for this frame to the start */ - count[curframe] = start; - /* move current to next frame circularly */ - p->curframe = --(curframe) < 0 ? numframes-1 : curframe; - framecount = 0; - p->fsig->framecount++; - } - } - p->framecount = framecount; - return OK; -} - -static int destroy_pvanal(CSOUND *csound, void *pp){ - PVAN *p = (PVAN *) pp; - cufftDestroy(p->plan); - cudaFree(p->aframe); - cudaFree(p->aframe2); - cudaFree(p->oldph); - cudaFree(p->fsig->frame.auxp); - p->fsig->frame.size = 0; - cudaFree(p->win); - return OK; -} - -typedef struct _cudapvsgain2 { - OPDS h; - PVSDAT *fout; - PVSDAT *fa; - MYFLT *kgain; - int gridSize; // number of blocks in the grid (1D) - int blockSize; // number of threads in one block (1D) - uint32 lastframe; -} CUDAPVSGAIN2; - -// kernel for scaling PV amplitudes -__global__ void applygain(float* output, float* input, MYFLT g, int length) { - int i = threadIdx.x + blockDim.x * blockIdx.x; - int j = i<<1; - - if(j < length){ - output[j] = (float) input[j] * g; - output[j+1] = input[j+1]; - } -} - -static int free_device(CSOUND* csound, void* pp){ - CUDAPVSGAIN2* p = (CUDAPVSGAIN2*) pp; - cudaFree(p->fout->frame.auxp); - return OK; -} - -static int cudapvsgain2set(CSOUND *csound, CUDAPVSGAIN2 *p){ - - int32 N = p->fa->N; - int size = (N+2) * sizeof(float); - int maxBlockDim; - int SMcount; - int totNumThreads = (N+2)/2; - cudaDeviceProp deviceProp; - cudaGetDeviceProperties(&deviceProp,0); - maxBlockDim = deviceProp.maxThreadsPerBlock; - SMcount = deviceProp.multiProcessorCount; - csound->Message(csound, "cudapvsgain2 running on device %s (capability %d.%d)\n", deviceProp.name, - deviceProp.major, deviceProp.minor); - - p->fout->sliding = 0; - - if (p->fout->frame.auxp == NULL || p->fout->frame.size < size) - AuxCudaAlloc(size, &p->fout->frame); - - p->blockSize = (((totNumThreads/SMcount)/32)+1)*32; - if (p->blockSize > maxBlockDim) p->blockSize = maxBlockDim; - p->gridSize = totNumThreads / p->blockSize + 1; - p->fout->N = N; - p->fout->overlap = p->fa->overlap; - p->fout->winsize = p->fa->winsize; - p->fout->wintype = p->fa->wintype; - p->fout->format = p->fa->format; - p->fout->framecount = 1; - p->lastframe = 0; - - csound->RegisterDeinitCallback(csound, p, free_device); - - return OK; -} - -static int cudapvsgain2(CSOUND *csound, CUDAPVSGAIN2 *p) -{ - int32 framelength = p->fa->N + 2; - MYFLT gain = *p->kgain; - float* fo = (float*) p->fout->frame.auxp; - float* fi = (float*) p->fa->frame.auxp; - - if (p->lastframe < p->fa->framecount) { - if (cudaDeviceSynchronize() != cudaSuccess) - csound->Message(csound,"Cuda error: Failed to synchronize\n"); - applygain<<gridSize,p->blockSize>>>(fo, fi, gain, framelength); - p->fout->framecount = p->fa->framecount; - p->lastframe = p->fout->framecount; - } - - return OK; -} - - -static OENTRY localops[] = { - {"cudasynth2", sizeof(PVSYN),0, 5, "a", "f", (SUBR) pvsynset, NULL, - (SUBR) pvsynperf}, - {"cudanal2", sizeof(PVAN),0, 5, "f", "aiiii", (SUBR) pvanalset, NULL, - (SUBR) pvanalperf}, - {"cudapvsgain2", sizeof(CUDAPVSGAIN2), 0, 3, "f", "fk", - (SUBR) cudapvsgain2set, (SUBR) cudapvsgain2, NULL} -}; - -extern "C" { - LINKAGE -} diff --git a/6.x/src/CUDA/pvsopsf.cu b/6.x/src/CUDA/pvsopsf.cu deleted file mode 100644 index da778197..00000000 --- a/6.x/src/CUDA/pvsopsf.cu +++ /dev/null @@ -1,445 +0,0 @@ -// -*- c++ -*- -/* pvsopsf.cu - experimental cuda opcodes - version using single-precision floats - (c) Victor Lazzarini, 2013 - - based on M Puckette's pitch tracking algorithm. - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include -#include - -#include - -/* kernel to convert from pvs to rectangular frame */ -__global__ void frompvs(float* inframe, float* lastph, - float scal, float fac) { - - int k = threadIdx.x + blockIdx.x*blockDim.x + 1; - int i = k << 1; - float mag = inframe[i]; - float delta = (inframe[i+1] - k*scal)*fac; - float phi = fmod((double)lastph[k-1] + delta, TWOPI); - lastph[k-1] = phi; - inframe[i] = (float) (mag*cos(phi)); - inframe[i+1] = (float) (mag*sin(phi)); - -} - -__global__ void winrotate(float* inframe2, float* inframe, float *win, - int N, int offset){ - int k = (threadIdx.x + blockIdx.x*blockDim.x); - inframe2[k] = win[k]*inframe[(k+offset)%N]; -} - -typedef struct _pvsyn{ - OPDS h; - MYFLT *asig; - PVSDAT *fsig; - float *inframe; /* N */ - float *inframe2; - float *lastph; /* N/2 */ - float *win; /* N */ - int framecount; - int curframe; - AUXCH frames; - AUXCH count; - cufftHandle plan; - float scal, fac; - int bblocks, nblocks; - int bthreads, nthreads; -} PVSYN; - -static int destroy_pvsyn(CSOUND *csound, void *pp); - -static int pvsynset(CSOUND *csound, PVSYN *p){ - - int N = p->fsig->N; - - if((N != 0) && !(N & (N - 1))) { - int hsize = p->fsig->overlap; - int size, numframes, i, blockspt; - MYFLT sum = 0.0, bins = N/2; - float *win; - cudaDeviceProp deviceProp; - cudaGetDeviceProperties(&deviceProp, 0); - blockspt = deviceProp.maxThreadsPerBlock; - csound->Message(csound, "CUDAsynth: using device %s (capability %d.%d)\n", - deviceProp.name,deviceProp.major, deviceProp.minor); - - if(p->fsig->wintype != 1) - return csound->InitError(csound, - "window type not implemented yet\n"); - numframes = N/hsize; - size = N*sizeof(float)*numframes; - if(p->frames.auxp == NULL || - p->frames.size < size) - csound->AuxAlloc(csound, size, &p->frames); - memset(p->frames.auxp, 0, size); - - size = sizeof(int)*numframes; - if(p->count.auxp == NULL || - p->count.size < size) - csound->AuxAlloc(csound, size, &p->count); - *((int *)(p->count.auxp)) = 0; - for(i=1; i < numframes; i++) - ((int *)(p->count.auxp))[i] = - (i + (1.f - (float)i/numframes))*N; - - size = (N+2)*sizeof(float); - cudaMalloc(&p->inframe, size); - cudaMemset(p->inframe, 0, size); - size = (N+2)*sizeof(float); - cudaMalloc(&p->inframe2, size); - size = (N+2)*sizeof(float); - cudaMalloc(&p->lastph, size); - cudaMemset(p->lastph, 0, size); - size = N*sizeof(float); - cudaMalloc(&p->win, size); - - win = (float *) malloc(sizeof(float)*(N+1)); - for(i=0; i <= N; i++) - win[i] = (float) (0.5 - 0.5*cos(i*TWOPI/N)); - - for(i = 0; i < N; i++) sum += win[i]; - sum = FL(2.0) / sum; - for(i = 0; i < N; i++) win[i] *= sum; - sum = FL(0.0); - for(i = 0; i <= N; i+=hsize) - sum += win[i] * win[i]; - sum = (1.0/N)/(sum); - for(i = 0; i < N; i++) win[i] *= 3*sum/sqrt(numframes); - cudaMemcpy(p->win,win,N*sizeof(float), - cudaMemcpyHostToDevice); - free(win); - - p->framecount = 0; - p->curframe = 0; - - p->fac = TWOPI*hsize/csound->GetSr(csound); - p->scal =csound->GetSr(csound)/N; - cufftPlan1d(&p->plan, N, CUFFT_C2R, 1); - cufftSetCompatibilityMode(p->plan, CUFFT_COMPATIBILITY_NATIVE); - csound->RegisterDeinitCallback(csound, p, destroy_pvsyn); - - p->bblocks = bins > blockspt? bins/blockspt : 1; - p->nblocks = N > blockspt ? N/blockspt : 1; - p->bthreads = bins/p->bblocks; - p->nthreads = N/p->nblocks; - if(csound->GetDebug(csound)) - csound->Message(csound, "%d (%d each), %d (%d each)\n", - p->nblocks, p->nthreads, p->bblocks, p->bthreads); - return OK; - } - return csound->InitError(csound, "fftsize not power-of-two \n"); - -} - -static int pvsynperf(CSOUND *csound, PVSYN *p){ - - int N = p->fsig->N, i; - int hsize = p->fsig->overlap; - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - MYFLT *asig = p->asig; - float *frames = (float *) p->frames.auxp; - int framecount = p->framecount; - int numframes = N/hsize; - int *count = (int *) p->count.auxp; - - if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); - } - - for(n=offset; n < nsmps; n++) { - - if(framecount == 0) { - int curframe = p->curframe; - /* start offset for current frame */ - int start = N*curframe; - float *cur = &(frames[start]); - float *win = (float *) p->win; - float *inframe = p->inframe; - float *inframe2 = p->inframe2; - float *fsig = (float *) p->fsig->frame.auxp; - /* copy fsig data to device */ - fsig[N+1] = fsig[1] = 0.f; - cudaMemcpy(inframe,fsig,(N+2)*sizeof(float), - cudaMemcpyHostToDevice); - /* perf pvs to rect conversion */ - frompvs<<bblocks,p->bthreads-1>>>(inframe,p->lastph,p->scal,p->fac); - /* execute inverse real FFT */ - if(cufftExecC2R(p->plan,(cufftComplex*)inframe,inframe) - != CUFFT_SUCCESS) csound->Message(csound, "cuda fft error\n"); - if (cudaDeviceSynchronize() != cudaSuccess) - csound->Message(csound,"Cuda error: Failed to synchronize\n"); - /* window and rotate data on device */ - winrotate<<nblocks,p->nthreads>>>(inframe2,inframe,win,N,hsize*curframe); - /* copy data to current out frame */ - cudaMemcpy(cur,inframe2,N*sizeof(float),cudaMemcpyDeviceToHost); - /* reset counter for this frame to the start */ - count[curframe] = start; - /* move current to next frame circularly */ - p->curframe = ++(curframe) == numframes ? 0 : curframe; - framecount = hsize; - } - asig[n] = FL(0.0); - for(i=0; i < numframes; i++){ - /* overlap-add */ - asig[n] += frames[count[i]]; - count[i]++; - } - framecount--; - } - p->framecount = framecount; - return OK; -} - -static int destroy_pvsyn(CSOUND *csound, void *pp){ - PVSYN *p = (PVSYN *) pp; - cufftDestroy(p->plan); - cudaFree(p->inframe); - cudaFree(p->lastph); - cudaFree(p->win); - return OK; -} - -__device__ float modTwoPi(float x) -{ - x = fmod((double)x,TWOPI); - return x <= -PI ? x + TWOPI : - (x > PI ? x - TWOPI : x); -} - -/* kernel to convert from rectangular to pvs frame */ -__global__ void topvs(float* aframe, float* oldph, - float scal, float fac) { - int k = threadIdx.x + blockIdx.x*blockDim.x + 1; - int i = k << 1; - - float re = aframe[i], im = aframe[i+1]; - float mag = sqrtf(re*re + im*im); - float phi = atan2f(im,re); - float delta = phi - oldph[k-1]; - oldph[k-1] = phi; - aframe[i] = mag; - aframe[i+1] = (float) ((modTwoPi(delta) + k*scal)*fac); -} - -__global__ void rotatewin(float* aframe2, float *aframe, float *win, - int N, int offset){ - int k = threadIdx.x + blockIdx.x*blockDim.x; - aframe2[(k+offset)%N] = win[k]*aframe[k]; -} - -typedef struct _pvan { - OPDS h; - PVSDAT *fsig; - MYFLT *asig,*fftsize,*hsize,*winsize,*wintype; - - float *aframe; /* N */ - float *aframe2; - float *oldph; /* N/2 */ - float *win; /* N */ - - int framecount; - int curframe; - AUXCH frames; - AUXCH count; - cufftHandle plan; - float scal, fac; - int bblocks, nblocks; - int bthreads, nthreads; -} PVAN; - -static int destroy_pvanal(CSOUND *csound, void *pp); - -static int pvanalset(CSOUND *csound, PVAN *p){ - - int N = *p->fftsize; - if((N != 0) && !(N & (N - 1))) { - int size, numframes, i, bins = N/2; - int hsize = *p->hsize, blockspt; - float *win; - cudaDeviceProp deviceProp; - cudaGetDeviceProperties(&deviceProp, 0); - blockspt = deviceProp.maxThreadsPerBlock; - csound->Message(csound, "CUDAnal: using device %s (capability %d.%d)\n", - deviceProp.name,deviceProp.major, deviceProp.minor); - - p->fsig->N = N; - p->fsig->overlap = hsize; - /* ignore winsize & wintype */ - p->fsig->winsize = N; - p->fsig->wintype = 1; - p->fsig->framecount = 0; - - numframes = N/hsize; - size = N*sizeof(float)*numframes; - if(p->frames.auxp == NULL || - p->frames.size < size) - csound->AuxAlloc(csound, size, &p->frames); - memset(p->frames.auxp, 0, size); - - size = N*sizeof(float); - if(p->fsig->frame.auxp == NULL || - p->fsig->frame.size < size) - csound->AuxAlloc(csound, size, &p->fsig->frame); - memset(p->fsig->frame.auxp, 0, size); - - size = sizeof(int)*numframes; - if(p->count.auxp == NULL || - p->count.size < size) - csound->AuxAlloc(csound, size, &p->count); - *((int *)(p->count.auxp)) = 0; - for(i=1; i < numframes; i++) - ((int *)(p->count.auxp))[i] = - (i + (float)i/numframes)*N; - - size = (N+2)*sizeof(float); - cudaMalloc(&p->aframe, size); - size = (N+2)*sizeof(float); - cudaMalloc(&p->aframe2, size); - size = (N/2-1)*sizeof(float); - cudaMalloc(&p->oldph, size); - cudaMemset(p->oldph, 0, size); - size = N*sizeof(float); - cudaMalloc(&p->win, size); - - win = (float *) malloc(sizeof(float)*N); - for(i=0; i < N; i++) - win[i] = (float) (0.5 - 0.5*cos(i*TWOPI/N)); - float sum = 0.0; - for(i = 0; i < N; i++) sum += win[i]; - sum = FL(2.0) / sum; - for(i = 0; i < N; i++) win[i] *= sum; - - cudaMemcpy(p->win,win,N*sizeof(float), - cudaMemcpyHostToDevice); - free(win); - - - - p->framecount = 1; - p->curframe = numframes-1; - p->fac = csound->GetSr(csound)/(TWOPI*hsize); - p->scal = (TWOPI*hsize)/N; - cufftPlan1d(&p->plan, N, CUFFT_R2C, 1); - cufftSetCompatibilityMode(p->plan, CUFFT_COMPATIBILITY_NATIVE); - csound->RegisterDeinitCallback(csound, p, destroy_pvanal); - - p->bblocks = bins > blockspt? bins/blockspt : 1; - p->nblocks = N > blockspt ? N/blockspt : 1; - p->bthreads = bins/p->bblocks; - p->nthreads = N/p->nblocks; - if(csound->GetDebug(csound)) - csound->Message(csound, "%d (%d each), %d (%d each)\n", - p->nblocks, p->nthreads, p->bblocks, p->bthreads); - return OK; - } - return csound->InitError(csound, "fftsize not power-of-two \n"); -} - -static int pvanalperf(CSOUND *csound, PVAN *p){ - - int N = p->fsig->N, i; - int hsize = p->fsig->overlap; - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - MYFLT *asig = p->asig; - float *frames = (float *) p->frames.auxp; - int framecount = p->framecount; - int numframes = N/hsize; - int *count = (int *) p->count.auxp; - - if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); - } - - for(n=offset; n < nsmps; n++) { - for(i=0; i < numframes; i++){ - frames[count[i]] = asig[n]; - count[i]++; - } - framecount++; - - if(framecount == hsize) { - int curframe = p->curframe; - /* start offset for current frame */ - int start = N*curframe; - float *cur = &(frames[start]); - float *win = (float *) p->win; - float *aframe = p->aframe; - float *aframe2 = p->aframe2; - float *fsig = (float *) p->fsig->frame.auxp; - /* copy fsig data to device */ - cudaMemcpy(aframe,cur,N*sizeof(float), - cudaMemcpyHostToDevice); - /* window and rotate data on device */ - rotatewin<<nblocks,p->nthreads>>>(aframe2,aframe,win,N, - hsize*(numframes-curframe)); - /* execute inverse real FFT */ - if(cufftExecR2C(p->plan,aframe2,(cufftComplex*)aframe2) - != CUFFT_SUCCESS) csound->Message(csound, "cuda fft error\n"); - if (cudaDeviceSynchronize() != cudaSuccess) - csound->Message(csound,"Cuda error: Failed to synchronize\n"); - /* perf rect to pvs conversion */ - topvs<<bblocks,p->bthreads-1>>>(aframe2,p->oldph,p->scal,p->fac); - /* copy data to current out frame */ - cudaMemcpy(fsig,aframe2,(N+2)*sizeof(float),cudaMemcpyDeviceToHost); - /* reset counter for this frame to the start */ - fsig[N+1] = fsig[1] = 0.f; - count[curframe] = start; - /* move current to next frame circularly */ - p->curframe = --(curframe) < 0 ? numframes-1 : curframe; - framecount = 0; - p->fsig->framecount++; - } - } - p->framecount = framecount; - return OK; -} - -static int destroy_pvanal(CSOUND *csound, void *pp){ - PVAN *p = (PVAN *) pp; - cufftDestroy(p->plan); - cudaFree(p->aframe); - cudaFree(p->oldph); - cudaFree(p->win); - return OK; -} - -static OENTRY localops[] = { - {"cudasynth", sizeof(PVSYN),0, 5, "a", "f", (SUBR) pvsynset, NULL, - (SUBR) pvsynperf}, - {"cudanal", sizeof(PVAN),0, 5, "f", "aiiii", (SUBR) pvanalset, NULL, - (SUBR) pvanalperf} -}; - -extern "C" { - LINKAGE -} diff --git a/6.x/src/CUDA/slidingm.cu b/6.x/src/CUDA/slidingm.cu deleted file mode 100644 index 69d662cd..00000000 --- a/6.x/src/CUDA/slidingm.cu +++ /dev/null @@ -1,640 +0,0 @@ -// -*- c++ -*- -/* - slindingm.cu: - - Copyright (C) 2014 Russell Bradford, Victor Lazzarini, John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ -// slindingm.cu -// experimental cuda opcodes -// using the sliding DFT -// adapted from Russell Bradford & John ffitch -// - -#include -#if defined(WIN32) -# include -#else -# include -#endif -#include -#include -#include -#include -// #include -#include - -//#define RB - -#ifndef RB -typedef float real; -#else -typedef double real; -#endif - -#define real(x) x -#define M_PI 3.14159265358979323846 -#define TWO_PI (2.0*M_PI) -#define NBATCH (256) - -#define Re(z) ((z).x) -#define Im(z) ((z).y) -#define R(p) ((p).x) -#define Theta(p) ((p).y) - -#define RectA (real(1.0)) -#define RectB (real(0.0)) -#define HannA (real(0.5)) -#define HannB (real(-0.5)) -#define A HannA -#define B2 (HannB/real(2.0)) -#define WINDOW - - -typedef double2 complex; -typedef double2 phasor; - -// Put a few things into constant memory to free up a couple of registers -//__constant__ int N, N2; -__constant__ real binbandwidth, nyquist; -// array alignment -__constant__ int offset; -// process in batches of this size -__constant__ int nbatch; - - -#define CUDA(name, args ...) { name(args); checkcuda(csound, #name, __LINE__); } -#define CHK(name) checkcuda(csound, #name, __LINE__) -#define NEXT(p) p += offset - -void checkcuda(CSOUND *csound, char* name, int line) -{ - cudaError_t err = cudaGetLastError(); - - if (err) { - csound->Message(csound, "%s: %s\nLine: %d\n", name, cudaGetErrorString(err), line); - exit(1); - } -} - -#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600 - -#else -__device__ double atomicAdd(double* address, double val) { - unsigned long long int* address_as_ull = (unsigned long long int*)address; - unsigned long long int old = *address_as_ull, assumed; - do { assumed = old; - old = atomicCAS(address_as_ull, - assumed, __double_as_longlong(val + __longlong_as_double(assumed))); - } while (assumed != old); - return __longlong_as_double(old); -} -#endif - -__device__ complex conjugate(complex z) -{ - return (complex){ Re(z), -Im(z) }; -} - -// round up to multiple of 256 -__host__ __device__ int roundup(int n) -{ - return 1 + ((n - 1) | 0xff); -} - -// Fin/Fout -// thread k does bin k; parallel across bins in a batch item.. -__global__ void slide(real deltas[/*nbatch*/], complex Fin[/*N*/], - complex Fout[/*N*nbatch*/], - real *sine, real *cosine, int N) -{ - int k = blockIdx.x * blockDim.x + threadIdx.x; - int b, N2 = N/2; - complex f; - real Fr, Fi, c, s; - - if (k > N2) return; - f = Fin[k]; - - // in constant memory - s = sine[k]; - c = cosine[k]; - - for (b = 0; b < nbatch; b++) { - Fr = Re(f) + deltas[b]; - Fi = Im(f); - f = (complex){ Fr*c - Fi*s, Fi*c + Fr*s }; - Fout[k] = f; - NEXT(Fout); - } - Fin[k] = f; -} - -__device__ real mod2Pi(real x) -{ - x = fmod(x, (real)TWO_PI); - if (x > PI) return x - TWO_PI; - if (x <= -PI) return x + TWO_PI; - return x; -} - -#ifdef RB -// below is one thread per bin, as per other kernels -// data is spread across blocks, but there is no sync across blocks -// thus cannot do in-place window -// parallel across bins in a batch item -// could do bins*batches -__global__ void window(complex Foutw[/*N*nbatch*/], - complex Fout[/*N*nbatch*/], int N) -{ - int k = blockIdx.x * blockDim.x + threadIdx.x; - int b, N2 = N/2; - complex F, Fm1, Fp1, f; - real Fr, Fi; - - // in the last block - if (k > N2) return; - - for (b = 0; b < nbatch; b++) { - F = Foutw[k]; - // conjugate reflection at edges - Fp1 = k < N2 ? Foutw[k + 1] : conjugate(Foutw[N2-1]); - Fm1 = k > 0 ? Foutw[k - 1] : conjugate(Foutw[1]); - Fr = A*Re(F) + B2*(Re(Fm1) + Re(Fp1)); - Fi = A*Im(F) + B2*(Im(Fm1) + Im(Fp1)); - - Re(f) = Fr; - Im(f) = Fi; - Fout[k] = f; - - NEXT(Fout); - NEXT(Foutw); - } -} - -// parallel across batches -// <<>> -// what is memory access pattern? -// small array sum, so not worth a tree reduction? -// middle sample only, so +- on real parts -__global__ void reconstruct(complex f[/*nbatch*N*/], real s[/*nbatch*/], int N) -{ - int k = blockIdx.x * blockDim.x + threadIdx.x; - complex *F = f + offset*k; - real sum = real(0.0); - int bin, N2 = N/2; - - if (k >= nbatch) return; - for (bin = 0; bin < N; bin += 2) { - real v0 = bin <= N2 ? Re(F[bin]) : Re(F[N - bin]); - real v1 = bin < N2 ? Re(F[bin + 1]) : Re(F[N - bin - 1]); - sum += v0 - v1; - } - s[k] = sum/N; -} - -#else -// the code below depends on fast single-precision -// atomic addition - -// this parallelises across N*nbatch -__global__ void window(complex Foutw[/*N*nbatch*/], - complex Fout[/*N*nbatch*/], int N) -{ - int n = blockIdx.x * blockDim.x + threadIdx.x; - int N2 = N/2; - int s = n/N; - int k = n%N; - complex F, Fm1, Fp1, f; - real Fr, Fi; - Foutw += s*offset; - Fout += s*offset; - - // in the last block - if (n > N*nbatch) return; - - F = Foutw[k]; - Fp1 = k < N2 ? Foutw[k + 1] : conjugate(Foutw[N2-1]); - Fm1 = k > 0 ? Foutw[k - 1] : conjugate(Foutw[1]); - - Fr = A*Re(F) + B2*(Re(Fm1) + Re(Fp1)); - Fi = A*Im(F) + B2*(Im(Fm1) + Im(Fp1)); - - Re(f) = Fr; - Im(f) = Fi; - Fout[k] = f; -} - -// this parallelises across N2*nbatch -__global__ void reconstruct(complex f[/*nbatch*N*/], real s[/*nbatch*/], int N) -{ - int n = blockIdx.x * blockDim.x + threadIdx.x, N2 = N/2; - int k = n/N2; - int bin = (n%N2)*2; - complex *F = &f[offset*k]; - - if (n >= nbatch*N2) return; - - real v0 = bin <= N2 ? Re(F[bin]) : Re(F[N - bin]); - real v1 = bin < N2 ? Re(F[bin + 1]) : Re(F[N - bin - 1]); - atomicAdd(&s[k],v0-v1); -} -#endif - - -__device__ phasor convert(complex f, real &oldiphase, int bin, int N) -{ - real Fr, Fi; - real phase, deltaphase; - phasor pha; - - Fr = Re(f); - Fi = Im(f); - - // magnitude is easy - R(pha) = hypot(Fi, Fr); - - phase = atan2(Fi, Fr); - deltaphase = phase - oldiphase; - oldiphase = phase; - - // subtract expected phase diff - deltaphase = mod2Pi(deltaphase - bin*TWO_PI/N); - - // find actual freq - // scale by bin width to give freq - Theta(pha) = binbandwidth * (bin + deltaphase*N/TWO_PI); - - return pha; -} - -__device__ phasor harmonic_shift(phasor pha, real fm) -{ - real sfreq; - - // tweak the freq using fm - // same across all channels - sfreq = Theta(pha)*fm; - - if (sfreq >= nyquist || sfreq <= -nyquist) R(pha) = real(0.0); - Theta(pha) = sfreq; - - return pha; -} - -__device__ real unconvert(phasor pha, real &oldophase, int N) -{ - real bin, phase; - - bin = Theta(pha)/binbandwidth; - phase = bin*TWO_PI/N; - phase = mod2Pi(oldophase + phase); - oldophase = phase; - - return R(pha)*cos(phase); -} - -// parallelism across bins*channels -__global__ void fmsyn(real inphase[/*N*/], complex F[/*nbatch*N*/], - real fm[/*nbatch*/], real outphase[/*N*/], int N) -{ - int k = blockIdx.x * blockDim.x + threadIdx.x; - int b, N2 = N/2; - real oldiphase, oldophase, val; - phasor pha; - - if (k > N2) return; - - oldiphase = inphase[k]; - oldophase = outphase[k]; - - for (b = 0; b < nbatch; b++) { - pha = convert(F[k], oldiphase, k, N); // updates oldiphase - pha = harmonic_shift(pha, fm[b]); - - // ignore imag part - val = unconvert(pha, oldophase, N); // updates oldophase - Re(F[k]) = val; - NEXT(F); - } - - inphase[k] = oldiphase; - outphase[k] = oldophase; -} - - -// blocks a multiple of 32 threads -// more blocks than multiprocessors -// perhaps 128 threads per block, as long as you have more blocks than -// multiprocessors -void threadblock(int device, int n, int *nblocks, int *nthreads) -{ - int nt, nb, nproc; - cudaDeviceProp deviceProp; - - //printf("%d threads needed\n", n); - - cudaGetDeviceProperties(&deviceProp, device); - nt = deviceProp.warpSize; // usually 32 threads - nproc = deviceProp.multiProcessorCount; - - nb = 1 + (n - 1)/nt; - - - //more blocks than procs - if (nb >= 2*nproc) { - nt *= 2; // 64 threads - nb = 1 + (n - 1)/nt; - } - - // // still more blocks than procs - if (nb >= 2*nproc) { - nt *= 2; // 128 threads - nb = 1 + (n - 1)/nt; - } - - if (nblocks) *nblocks = nb; - if (nthreads) *nthreads = nt; -} - -typedef struct _SPV { - OPDS h; - MYFLT *out, *in, *shift, *iN; - int nbins, ptr, nbtch, nblocks, nblocks1, nthreads, nthreads1, rblocks, rthreads; - real *deltas, *ddeltas, *dinphase, *doutphase, *dfm; - real *sine, *cosine; - complex *dFin, *dFout, *dFoutw; - real *samples, srate; - real *framesin, *framesout, *fm; - AUXCH aframesfm, aframesout, aframesin; - uint32_t count; -} SPV; - - -void init_tables(CSOUND *csound, SPV *p, int nbins) -{ - int k; - real s[nbins], c[nbins]; - - for (k = 0; k < nbins; k++) { - sincos(TWO_PI*k/nbins, &s[k], &c[k]); - } - - CUDA(cudaMemcpy, p->sine, s, nbins*sizeof(real), cudaMemcpyHostToDevice); - CUDA(cudaMemcpy, p->cosine, c, nbins*sizeof(real), cudaMemcpyHostToDevice); -} - -void cuinit(CSOUND *csound, - SPV *p, uint32_t nframes, - int nbins, int device) -{ - int csize, rsize, off, nbins2; - real binbw, nyq; - cudaDeviceProp deviceProp; - - if(!p->aframesin.auxp || p->aframesin.size < sizeof(real)*NBATCH) - csound->AuxAlloc(csound, sizeof(real)*NBATCH, &p->aframesin); - if(!p->aframesout.auxp || p->aframesout.size < sizeof(real)*NBATCH) - csound->AuxAlloc(csound, sizeof(real)*NBATCH, &p->aframesout); - if(!p->aframesfm.auxp || p->aframesfm.size < sizeof(real)*NBATCH) - csound->AuxAlloc(csound, sizeof(real)*NBATCH, &p->aframesfm); - - p->framesin = (real *) p->aframesin.auxp; - p->framesout = (real *) p->aframesout.auxp; - p->fm = (real *) p->aframesfm.auxp; - - p->nbins = nbins; - nbins2 = nbins/2; - p->nbtch = nframes; - p->srate = (real) csound->GetSr(csound); - binbw = p->srate/p->nbins; - nyq = p->srate/real(2.0); - - CUDA(cudaSetDevice, device); - - cudaGetDeviceProperties(&deviceProp, device); - - // allocate contiguous arrays to aid cudaMemcpy; round up to align - // arrays for coalescence - csize = roundup(p->nbins*sizeof(complex)); - rsize = roundup(p->nbins*sizeof(real)); - off = csize/sizeof(complex); - - if (off != rsize/sizeof(real)) { - csound->InitError(csound, "Something weird happening with offsets at line %d\n", - __LINE__); - } - - if (!csound->QueryGlobalVariable(csound, "::cusliding::init")) { - csound->CreateGlobalVariable(csound, "::cusliding::init",1); -#ifndef RB - csound->Message(csound, "Sliding PV: using floats on device %s (capability %d.%d)\n", deviceProp.name, - deviceProp.major, deviceProp.minor); -#else - csound->Message(csound, "Sliding PV: using doubles on device %s (capability %d.%d)\n", deviceProp.name, - deviceProp.major, deviceProp.minor); -#endif - // global constants - CUDA(cudaMemcpyToSymbol, offset, &off, sizeof(int)); - CUDA(cudaMemcpyToSymbol, nbatch, &p->nbtch, sizeof(int)); - CUDA(cudaMemcpyToSymbol, binbandwidth, &binbw, sizeof(real)); - CUDA(cudaMemcpyToSymbol, nyquist, &nyq, sizeof(real)); - - } - // N complexes - CUDA(cudaMalloc, &p->dFin, csize); - CUDA(cudaMemset, p->dFin, 0, csize); - - // N*nbatch complexes - CUDA(cudaMalloc, &p->dFout, p->nbtch*csize); - CUDA(cudaMalloc, &p->dFoutw, p->nbtch*csize); - - // N reals - CUDA(cudaMalloc, &p->dinphase, p->nbins*sizeof(real)); - CUDA(cudaMalloc, &p->doutphase, p->nbins*sizeof(real)); - CUDA(cudaMemset, p->dinphase, 0, p->nbins*sizeof(real)); - CUDA(cudaMemset, p->doutphase, 0, p->nbins*sizeof(real)); - - CUDA(cudaMalloc, &p->sine, p->nbins*sizeof(real)); - CUDA(cudaMalloc, &p->cosine, p->nbins*sizeof(real)); - - // nbatch reals - CUDA(cudaMalloc, &p->ddeltas, p->nbtch*sizeof(real)); - CUDA(cudaMalloc, &p->dfm, p->nbtch*sizeof(real)); - - // circular history of nbins samples - p->samples = (real*) csound->Calloc(csound, p->nbins*sizeof(real)); - if (p->samples == NULL) { - csound->InitError(csound, "calloc failed at line %d\n", __LINE__); - return; - } - - // pinned memory is marginally faster - //CUDA(cudaHostAlloc, &deltas, p->nbtch*sizeof(real), cudaHostAllocDefault); - p->deltas = (real*) csound->Malloc(csound, p->nbtch*sizeof(real)); - if (p->deltas == NULL) { - csound->InitError(csound, "malloc failed at line %d\n", __LINE__); - return; - } - - init_tables(csound, p, p->nbins); - - // index of oldest sample - p->ptr = 0; - -#ifdef RB - threadblock(device, p->nbtch, &p->rblocks, &p->rthreads); -#else - threadblock(device, p->nbtch*(nbins2), &p->rblocks, &p->rthreads); - threadblock(device, p->nbtch*nbins, &p->nblocks1, &p->nthreads1); -#endif - threadblock(device, (nbins2+1), &p->nblocks, &p->nthreads); - - if(csound->GetDebug(csound)) { - csound->Message(csound, "%d bins, %d actual\n", p->nbins, nbins2 + 1); - csound->Message(csound, "csize = %d -> %d bytes, offset %d elements\n", (int) (p->nbins*sizeof(complex)), - csize, off); - csound->Message(csound, "%gHz bin bandwidth, Nyquist %gHz\n", binbw, nyq); - csound->Message(csound, "period %d samples (%g sec)\n", p->nbtch, (real)p->nbtch/p->srate); - csound->Message(csound, "%d multiprocessors\n", deviceProp.multiProcessorCount); - csound->Message(csound, "%d blocks with %d threads = %d\n", p->nblocks, p->nthreads, - p->nblocks1*p->nthreads); - csound->Message(csound, "%d idle threads in last block\n", p->nblocks*p->nthreads - - (nbins2 + 1)); - csound->Message(csound, "%d blocks per SM\n", - (int)ceil((double)p->nblocks/deviceProp.multiProcessorCount)); - csound->Message(csound, "reconstruct using %d blocks of %d threads = %d\n", p->rblocks, p->rthreads, - p->rblocks*p->rthreads); - } -} - -int cushutdown(CSOUND *csound, void *pp) -{ - SPV *p = (SPV *) pp; - csound->Free(csound, p->samples); - - CUDA(cudaFree, p->dinphase); - CUDA(cudaFree, p->doutphase); - CUDA(cudaFree, p->ddeltas); - CUDA(cudaFree, p->dFoutw); - CUDA(cudaFree, p->dFout); - CUDA(cudaFree, p->dFin); - CUDA(cudaFree, p->sine); - CUDA(cudaFree, p->cosine); - - //CUDA(cudaFreeHost, deltas); - csound->Free(csound, p->deltas); - - if(csound->GetDebug(csound)) - csound->Message(csound, "cuda shutdown\n"); - - return OK; -} - -// in samples with channels muxed 0 1 2 0 1 2 ... -void cuprocess(CSOUND *csound, SPV *p, real in[/*nbatch*/], real out[/*nbatch*/], - real fm[/*nbatch*/]) -{ - int b; - - for (b = 0; b < p->nbtch; b++) { - p->deltas[b] = in[b] - p->samples[p->ptr]; - p->samples[p->ptr] = in[b]; - p->ptr = (p->ptr + 1) % (p->nbins); - } - - CUDA(cudaMemcpy, p->ddeltas, p->deltas, p->nbtch*sizeof(real), - cudaMemcpyHostToDevice); - - slide<<nblocks,p->nthreads>>>(p->ddeltas, p->dFin, p->dFoutw, - p->sine, p->cosine, p->nbins); - cudaDeviceSynchronize(); CHK(slide); - - // Foutw and Fout must be separate to avoid data race -#ifdef RB - window<<nblocks,p->nthreads>>>(p->dFoutw, p->dFout, p->nbins); -#else - window<<nblocks1,p->nthreads1>>>(p->dFoutw, p->dFout, p->nbins); -#endif - cudaDeviceSynchronize(); CHK(window); - - CUDA(cudaMemcpy, p->dfm, fm, p->nbtch*sizeof(real), cudaMemcpyHostToDevice); - - fmsyn<<nblocks,p->nthreads>>>(p->dinphase, p->dFout, p->dfm, p->doutphase, p->nbins); - - // reuse ddeltas array - reconstruct<<rblocks,p->rthreads>>>(p->dFout, p->ddeltas, p->nbins); - CHK(reconstruct); - // is is faster to transfer to pinned memory then copy; or just - // transfer directly to out? - CUDA(cudaMemcpy, out, p->ddeltas, p->nbtch*sizeof(real), - cudaMemcpyDeviceToHost); - -#ifndef RB - for(b=0; b < p->nbtch; b++) out[b] /= p->nbins; -#endif - -} - - -int spv_init(CSOUND *csound, SPV *p) { - cuinit(csound,p,NBATCH,*p->iN,0); - csound->RegisterDeinitCallback(csound, p, cushutdown); - return OK; -} - -int spv_perf(CSOUND *csound, SPV *p) { - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - uint32_t count = p->count; - - if (UNLIKELY(offset)) memset(p->out, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&p->out[nsmps], '\0', early*sizeof(MYFLT)); - } - - for(n=offset; n < nsmps; n++) { - p->framesin[count] = p->in[n]; - p->out[n] = p->framesout[count]; - p->fm[count] = p->shift[n]; - count++; - if(count == NBATCH) { - cuprocess(csound, p,p->framesin,p->framesout,p->fm); - count = 0; - } - - } - - p->count = count; - return OK; -} - -static OENTRY localops[] = { - {"cudasliding", sizeof(SPV),0, 5, "a", "aai", (SUBR) spv_init, NULL, - (SUBR) spv_perf} -}; - -extern "C" { - LINKAGE -} - - - diff --git a/6.x/src/chua/CMakeLists.txt b/6.x/src/chua/CMakeLists.txt deleted file mode 100644 index 1946da33..00000000 --- a/6.x/src/chua/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# Build chuap opcodes -option(BUILD_CHUA_OPCODES "Build the chua opcodes" ON) - -if(USE_VCPKG) - find_package(Eigen3 CONFIG REQUIRED) -else() - find_package(EIGEN3) -endif() - -check_deps(BUILD_CHUA_OPCODES EIGEN3_FOUND) - -if(BUILD_CHUA_OPCODES AND EIGEN3_FOUND) - make_plugin(chua ChuaOscillator.cpp) - target_include_directories(chua PRIVATE ${EIGEN3_INCLUDE_DIR} ${CSOUND_INCLUDE_DIRS}) - - if(USE_VCPKG) - target_link_libraries(chua PRIVATE Eigen3::Eigen) - else() - target_link_libraries(chua PRIVATE ${EIGEN_LIBRARIES}) - endif() - - if(APPLE) - set_target_properties(chua PROPERTIES - COMPILE_FLAGS "-Wno-unused-local-typedef" - ) - endif() -endif() diff --git a/6.x/src/chua/ChuaOscillator.cpp b/6.x/src/chua/ChuaOscillator.cpp deleted file mode 100644 index 9a8188fe..00000000 --- a/6.x/src/chua/ChuaOscillator.cpp +++ /dev/null @@ -1,636 +0,0 @@ -/* - - Copyright 2008 Michael Gogins - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ -// function TimeSeries = -// chuacc(L,R0,C2,G,Ga,Gb,C1,E,x0,y0,z0,dataset_size,step_size) -// %0.00945,7.5,2e-007,0.00105,0,-0.00121,1.5e-008,1.76e-005,0,-0.1,0.1,2500,5e-6 -// % Syntax: -// TimeSeries=chua(L,R0,C2,G,Ga,Gb,C1,E,x0,y0,z0,dataset_size,step_size) -// % ______________________________________ -// % -// % Chua's oscillator is described by a set of three -// % ordinary differential equations called Chua's equations: -// % -// % dI3 R0 1 -// % --- = - -- I3 - - V2 -// % dt L L -// % -// % dV2 1 G -// % --- = -- I3 - -- (V2 - V1) -// % dt C2 C2 -// % -// % dV1 G 1 -// % --- = -- (V2 - V1) - -- f(V1) -// % dt C1 C1 -// % -// % where -// % -// % f(V1) = Gb V1 + - (Ga - Gb)(|V1 + E| - |V1 - E|) -// % -// % A solution of these equations (I3,V2,V1)(t) starting from an -// % initial state (I3,V2,V1)(0) is called a trajectory of Chua's -// % oscillator. -// % -// % This function uses a RungeKutta integration method optimised for the chua -// % paradigm -// % -// % Reference: -// % ABC - Adventures in Bifurication & Chaos ... Prof M.P Kennedy 1993 -// % -// % James McEvoy, Tom Murray -// % -// % University e-mail: 99375940@student.ucc.ie -// % Lifetime e-mail: sacevoy@eircom.net -// % Homepage: http://www.sacevoy.com -// % -// % 2 Nov 2002 -// % Models Initial Variables -// %------------------------- -// %Initial Conditions set by x0,y0,z0 -// TimeSeries = [x0, y0, z0]'; % models initial conditions -// %x0 = I3, y0 = V2, z0 = V1 from datafiles -// % Optimized Runge-Kutta Variables -// %-------------------------------- -// h = step_size; %*(G/C2); -// h2 = (h)*(.5); -// h6 = (h)/(6); -// sys_variables(9:12) = [1.76e-005,0,-0.00121,0]; -// k1 = [0 0 0]'; -// k2 = [0 0 0]'; -// k3 = [0 0 0]'; -// k4 = [0 0 0]'; -// M = [0 0 0]'; -// % Calculate Time Series -// %---------------------- -// % values have to be switched around -// M(1) = TimeSeries(3); %V1 -// M(2) = TimeSeries(2); %V2 -// M(3) = TimeSeries(1); %I3 - -// for i=1:dataset_size -// % Runge Kutta -// % Round One -// k1(1) = (G*(M(2) - M(1)) - gnor(M(1),sys_variables))/C1; -// k1(2) = (G*(M(1) - M(2)) + M(3))/C2; -// k1(3) = (-(M(2) + R0*M(3)))/L; -// % Round Two -// k2(1) = (G*(M(2) + h2*k1(2) - (M(1) + h2*k1(1))) - gnor(M(1) + -// h2*k1(1),sys_variables))/C1; -// k2(2) = (G*(M(1) + h2*k1(1) - (M(2) + h2*k1(2))) + M(3) + h2*k1(3))/C2; -// k2(3) = (-(M(2) + h2*k1(2) + R0*(M(3) + h2*k1(3))))/L; -// % Round Three -// k3(1) = (G*(M(2) + h2*k2(2) - (M(1) + h2*k2(1))) - gnor(M(1) + -// h2*k2(1),sys_variables))/C1; -// k3(2) = (G*(M(1) + h2*k2(1) - (M(2) + h2*k2(2))) + M(3) + h2*k2(3))/C2; -// k3(3) = (-(M(2) + h2*k2(2) + R0*(M(3) + h2*k2(3))))/L; -// % Round Four -// k4(1) = (G*(M(2) + h*k3(2) - (M(1) + h*k3(1))) - gnor(M(1) + -// h*k3(1),sys_variables))/C1; -// k4(2) = (G*(M(1) + h*k3(1) - (M(2) + h*k3(2))) + M(3) + h*k3(3))/C2; -// k4(3) = (-(M(2) + h*k3(2) + R0*(M(3) + h*k3(3))))/L; -// %Finishes integration and assigns values to M(1), -// M = M + (k1 + 2*k2 + 2*k3 + k4)*(h6); -// %M(2) and M(3) -// TimeSeries(3,i+1) = M(1); %TimeSeries 3 is V1 -// TimeSeries(2,i+1) = M(2); %TimeSeries 2 is V2 -// TimeSeries(1,i+1) = M(3); %TimeSeries 1 is I3 -// i=i+1; -// end -// %gnor Calculates the cubic nonlinearity -// function gnor = gnor(x,sys_variables) -// a = sys_variables(9); -// b = sys_variables(10); -// c = sys_variables(11); -// d = sys_variables(12); -// gnor = a*(x.^3) + b*(x.^2) + c*x + d; - -#include "OpcodeBase.hpp" -#include -#include - -using namespace csound; - -class ChuasOscillatorCubic : public OpcodeNoteoffBase { -public: - // OUTPUTS - MYFLT *I3; - MYFLT *V2; - MYFLT *V1; - // INPUTS - // % L,R0,C2,G,Ga,Gb,E,C1,a,b,c,d - // sys_variables = [system_vars(5:12),system_vars(23:26)]; - // % x0,y0,z0,dataset_size,step_size - // integ_variables = [system_vars(14:16),system_vars(1:2)]; - // function TimeSeries = chuacc(L,R0,C2,G,Ga,Gb,C1,E,x0,y0,z0, - // dataset_size,step_size) - // Circuit elements. - MYFLT *L_; - MYFLT *R0_; - MYFLT *C2_; - MYFLT *G_; - // Omit Ga, not used with cubic nonlinearity. - // Omit Gb, not used with cubic nonlinearity. - MYFLT *C1_; - // Omit E, not used with cubic nonlinearity. - // Initial values... - // %x0 = I3, y0 = V2, z0 = V1 from datafiles - MYFLT *I3_; - MYFLT *V2_; - MYFLT *V1_; - MYFLT *step_size_; - // STATE - // Runge-Kutta step sizes. - MYFLT h; - MYFLT h2; - MYFLT h6; - // Runge-Kutta slopes. - Eigen::VectorXd k1; - Eigen::VectorXd k2; - Eigen::VectorXd k3; - Eigen::VectorXd k4; - // Temporary value. - Eigen::VectorXd M; - // Polynomial for nonlinear element. - MYFLT a; - MYFLT b; - MYFLT c; - MYFLT d; - size_t ksmps; - -public: - int init(CSOUND *csound) { - if (!csound->GetReinitFlag(csound) && !csound->GetTieFlag(csound)) { - csound->RegisterDeinitCallback(csound, this, ¬eoff_); - } - // h = step_size; %*(G/C2); - h = *step_size_; - // h2 = (h)*(.5); - h2 = h / 2.0; - // h6 = (h)/(6); - h6 = h / 6.0; - // NOTE: The original MATLAB code uses 1-based indexing. - // Although the MATLAB vectors are columns, - // these are rows; it doesn't matter here. - // k1 = [0 0 0]'; - k1.resize(4); - // k2 = [0 0 0]'; - k2.resize(4); - // k3 = [0 0 0]'; - k3.resize(4); - // k4 = [0 0 0]'; - k4.resize(4); - // M = [0 0 0]'; - M.resize(4); - // % values have to be switched around - // M(1) = TimeSeries(3); %V1 - M(1) = *V1_; - // M(2) = TimeSeries(2); %V2 - M(2) = *V2_; - // M(3) = TimeSeries(1); %I3 - M(3) = *I3_; - // sys_variables(9:12) = [1.76e-005,0,-0.00121,0]; - a = 1.76e-5; - b = 0.0; - c = -0.00121; - d = 0.0; - ksmps = opds.insdshead->ksmps; - warn(csound, "ChuasOscillatorCubic::init: L: %f R0: %f C2: %f G: %f" - " C1: %f V1: %f V2: %f I3: %f step: %f\n", - *L_, *R0_, *C2_, *G_, *C1_, M(1), M(2), M(3), h); - warn(csound, "ChuasOscillatorCubic::init: a: %f b: %f c: %f d: %f\n", a, - b, c, d); - return OK; - } - int noteoff(CSOUND *csound) { - warn(csound, "ChuasOscillatorCubic::noteoff\n"); - k1.resize(0); - k2.resize(0); - k3.resize(0); - k4.resize(0); - M.resize(0); - return OK; - } - static int noteoff_(CSOUND *csound, void *opcode) { - return ((ChuasOscillatorCubic *)opcode)->noteoff(csound); - } - int kontrol(CSOUND *csound) { - // NOTE: MATLAB code goes into eigen3 C++ code pretty straightforwardly, - // probaby by design. This is very handy and should prevent mistakes. - // Start with aliases for the Csound inputs, in order - // to preserve the clarity of the original code. - uint32_t offset = opds.insdshead->ksmps_offset; - uint32_t early = opds.insdshead->ksmps_no_end; - uint32_t nsmps = opds.insdshead->ksmps; - if (UNLIKELY(offset)) { - memset(I3, '\0', offset * sizeof(MYFLT)); - memset(V1, '\0', offset * sizeof(MYFLT)); - memset(V2, '\0', offset * sizeof(MYFLT)); - } - if (UNLIKELY(early)) { - memset(&I3[nsmps - early], '\0', early * sizeof(MYFLT)); - memset(&V1[nsmps - early], '\0', early * sizeof(MYFLT)); - memset(&V2[nsmps - early], '\0', early * sizeof(MYFLT)); - } - MYFLT &L = *L_; - MYFLT &R0 = *R0_; - MYFLT &C2 = *C2_; - MYFLT &G = *G_; - MYFLT &C1 = *C1_; - // Recompute Runge-Kutta step sizes if necessary. - if (h != *step_size_) { - // h = step_size; %*(G/C2); - h = *step_size_; - // h2 = (h)*(.5); - h2 = h / 2.0; - // h6 = (h)/(6); - h6 = h / 6.0; - } - // Standard 4th-order Runge-Kutta integration. - for (size_t i = 0; i < ksmps; i++) { - // TimeSeries(3,i+1) = M(1); %TimeSeries 3 is V1 - // TimeSeries(2,i+1) = M(2); %TimeSeries 2 is V2 - // TimeSeries(1,i+1) = M(3); %TimeSeries 1 is I3 - V1[i] = M(1); - V2[i] = M(2); - I3[i] = M(3); - // std::printf("%4d V1: %f V2: %f I3: %f\n", i, V1[i], V2[i], I3[i]); - // Runge Kutta - // Round One - k1(1) = (G * (M(2) - M(1)) - gnor(M(1))) / C1; - k1(2) = (G * (M(1) - M(2)) + M(3)) / C2; - k1(3) = (-1.0 * (M(2) + R0 * M(3))) / L; - // Round Two - k2(1) = (G * (M(2) + h2 * k1(2) - (M(1) + h2 * k1(1))) - - gnor(M(1) + h2 * k1(1))) / - C1; - k2(2) = - (G * (M(1) + h2 * k1(1) - (M(2) + h2 * k1(2))) + M(3) + h2 * k1(3)) / - C2; - k2(3) = (-(M(2) + h2 * k1(2) + R0 * (M(3) + h2 * k1(3)))) / L; - // Round Three - k3(1) = (G * (M(2) + h2 * k2(2) - (M(1) + h2 * k2(1))) - - gnor(M(1) + h2 * k2(1))) / - C1; - k3(2) = - (G * (M(1) + h2 * k2(1) - (M(2) + h2 * k2(2))) + M(3) + h2 * k2(3)) / - C2; - k3(3) = (-(M(2) + h2 * k2(2) + R0 * (M(3) + h2 * k2(3)))) / L; - // Round Four - k4(1) = (G * (M(2) + h * k3(2) - (M(1) + h * k3(1))) - - gnor(M(1) + h * k3(1))) / - C1; - k4(2) = - (G * (M(1) + h * k3(1) - (M(2) + h * k3(2))) + M(3) + h * k3(3)) / C2; - k4(3) = (-(M(2) + h * k3(2) + R0 * (M(3) + h * k3(3)))) / L; - // Finishes integration and assigns values to M - M = M + (k1 + 2 * k2 + 2 * k3 + k4) * (h6); - } - return OK; - } - MYFLT gnor(MYFLT x) { // Odd to use std::pow here for integer powers when - // there is intpow function - return (a * std::pow(x, FL(3.0))) + (b * std::pow(x, FL(2.0))) + (c * x) + - d; - } -}; - -// %%%%%%%%%%%%%%%%%%%%%% -// % SubFunction (James)% -// %%%%%%%%%%%%%%%%%%%%%% -// function TimeSeries = chua(sys_variables,integ_variables) -// % Syntax: TimeSeries=chua(sys_variables,integ_variables) -// % sys_variables = [L,R0,C2,G,Ga,Gb,E,C1]; -// % integ_variables = [x0,y0,z0,dataset_size,step_size]; -// % Models Initial Variables -// %------------------------- -// L = sys_variables(1); -// R0 = sys_variables(2); -// C2 = sys_variables(3); -// G = sys_variables(4); -// Ga = sys_variables(5); -// Gb = sys_variables(6); -// E = sys_variables(7); -// C1 = sys_variables(8); -// x0 = integ_variables(1); -// y0 = integ_variables(2); -// z0 = integ_variables(3); -// dataset_size = integ_variables(4); -// step_size = integ_variables(5); -// TimeSeries = [x0, y0, z0]'; % models initial conditions -// % Optimized Runge-Kutta Variables -// %-------------------------------- -// h = step_size*G/C2; -// h2 = (h)*(.5); -// h6 = (h)/(6); -// anor = Ga/G; -// bnor = Gb/G; -// bnorplus1 = bnor + 1; -// alpha = C2/C1; -// beta = C2/(L*G*G); -// gammaloc = (R0*C2)/(L*G); -// bh = beta*h; -// bh2 = beta*h2; -// ch = gammaloc*h; -// ch2 = gammaloc*h2; -// omch2 = 1 - ch2; -// k1 = [0 0 0]'; -// k2 = [0 0 0]'; -// k3 = [0 0 0]'; -// k4 = [0 0 0]'; -// M = [0 0 0]'; -// % Calculate Time Series -// %---------------------- -// M(1) = TimeSeries(3)/E; -// M(2) = TimeSeries(2)/E; -// M(3) = TimeSeries(1)/(E*G); -// for i=1:dataset_size -// % Runge Kutta -// % Round One -// k1(1) = alpha*(M(2) - bnorplus1*M(1) - (.5)*(anor - bnor)*(abs(M(1) + 1) -// - abs(M(1) - -// 1))); -// k1(2) = M(1) - M(2) + M(3); -// k1(3) = -beta*M(2) - gammaloc*M(3); -// % Round Two -// temp = M(1) + h2*k1(1); -// k2(1) = alpha*(M(2) + h2*k1(2) - bnorplus1*temp - -// (.5)*(anor - bnor)*(abs(temp + 1) - abs(temp - 1))); -// k2(2) = k1(2) + h2*(k1(1) - k1(2) + k1(3)); -// k2(3) = omch2*k1(3) - bh2*k1(2); -// % Round Three -// temp = M(1) + h2*k2(1); -// k3(1) = alpha*(M(2) + h2*k2(2) - bnorplus1*temp - -// (.5)*(anor - bnor)*(abs(temp + 1) - abs(temp - 1))); -// k3(2) = k1(2) + h2*(k2(1) - k2(2) + k2(3)); -// k3(3) = k1(3) - bh2*k2(2) - ch2*k2(3); -// % Round Four -// temp = M(1) + h*k3(1); -// k4(1) = alpha*(M(2) + h*k3(2) - bnorplus1*temp - -// (.5)*(anor - bnor)*(abs(temp + 1) - abs(temp - 1))); -// k4(2) = k1(2) + h*(k3(1) - k3(2) + k3(3)); -// k4(3) = k1(3) - bh*k3(2) - ch*k3(3); -// M = M + (k1 + 2*k2 + 2*k3 + k4)*(h6); -// TimeSeries(3,i+1) = E*M(1); -// TimeSeries(2,i+1) = E*M(2); -// TimeSeries(1,i+1) = (E*G)*M(3); -// i=i+1; -// end - -class ChuasOscillatorPiecewise - : public OpcodeNoteoffBase { -public: - // OUTPUTS - MYFLT *I3; - MYFLT *V2; - MYFLT *V1; - // INPUTS - // sys_variables = system_vars(5:12); % L,R0,C2,G,Ga,Gb,E,C1 - // % x0,y0,z0,dataset_size,step_size - // integ_variables = [system_vars(14:16),system_vars(1:2)]; - // function TimeSeries = chuacc(L,R0,C2,G,Ga,Gb,C1,E,x0,y0,z0, - // dataset_size,step_size) - // Circuit elements. - MYFLT *L_; - MYFLT *R0_; - MYFLT *C2_; - MYFLT *G_; - MYFLT *Ga_; - MYFLT *Gb_; - MYFLT *E_; - MYFLT *C1_; - // Initial values... - MYFLT *I3_; - MYFLT *V2_; - MYFLT *V1_; - MYFLT *step_size_; - // STATE - // Runge-Kutta step sizes. - MYFLT h; - MYFLT h2; - MYFLT h6; - // Runge-Kutta slopes. - Eigen::VectorXd k1; - Eigen::VectorXd k2; - Eigen::VectorXd k3; - Eigen::VectorXd k4; - // Temporary value. - Eigen::VectorXd M; - // Other variables. - MYFLT step_size; - MYFLT anor; - MYFLT bnor; - MYFLT bnorplus1; - MYFLT alpha; - MYFLT beta; - MYFLT gammaloc; - MYFLT bh; - MYFLT bh2; - MYFLT ch; - MYFLT ch2; - MYFLT omch2; - MYFLT temp; - size_t ksmps; - int init(CSOUND *csound) { - if (!csound->GetReinitFlag(csound) && !csound->GetTieFlag(csound)) { - csound->RegisterDeinitCallback(csound, this, ¬eoff_); - } - // NOTE: The original MATLAB code uses 1-based indexing. - // Although the MATLAB vectors are columns, - // these are rows; it doesn't matter here. - // k1 = [0 0 0]'; - k1.resize(4); - // k2 = [0 0 0]'; - k2.resize(4); - // k3 = [0 0 0]'; - k3.resize(4); - // k4 = [0 0 0]'; - k4.resize(4); - // M = [0 0 0]'; - M.resize(4); - // M(1) = TimeSeries(3)/E; - M(1) = *V1_ / *E_; - // M(2) = TimeSeries(2)/E; - M(2) = *V2_ / *E_; - // M(3) = TimeSeries(1)/(E*G); - M(3) = *I3_ / (*E_ * *G_); - ksmps = opds.insdshead->ksmps; - warn(csound, "ChuasOscillatorPiecewise::init: L: %f R0: %f C2: %f G: " - "%f Ga: %f Gb: %f E: %f C1: %f iI3: %f iV2:" - " %f iV1: %f step: %f\n", - *L_, *R0_, *C2_, *G_, *Ga_, *Gb_, *E_, *C1_, *I3_, *V2_, *V1_, - step_size); - return OK; - } - int noteoff(CSOUND *csound) { - warn(csound, "ChuasOscillatorPiecewise::noteoff\n"); - k1.resize(0); - k2.resize(0); - k3.resize(0); - k4.resize(0); - M.resize(0); - return OK; - } - static int noteoff_(CSOUND *csound, void *opcode) { - return ((ChuasOscillatorPiecewise *)opcode)->noteoff(csound); - } - int kontrol(CSOUND *csound) { - // NOTE: MATLAB code goes into eigen3 C++ code pretty straightforwardly, - // probaby by design. This is very handy and should prevent mistakes. - // Start with aliases for the Csound inputs, in order - // to preserve the clarity of the original code. - uint32_t offset = opds.insdshead->ksmps_offset; - uint32_t early = opds.insdshead->ksmps_no_end; - if (UNLIKELY(offset)) { - memset(I3, '\0', offset * sizeof(MYFLT)); - memset(V1, '\0', offset * sizeof(MYFLT)); - memset(V2, '\0', offset * sizeof(MYFLT)); - } - if (UNLIKELY(early)) { - ksmps -= early; - memset(&I3[ksmps], '\0', early * sizeof(MYFLT)); - memset(&V1[ksmps], '\0', early * sizeof(MYFLT)); - memset(&V2[ksmps], '\0', early * sizeof(MYFLT)); - } - MYFLT &L = *L_; - MYFLT &R0 = *R0_; - MYFLT &C2 = *C2_; - MYFLT &G = *G_; - MYFLT &Ga = *Ga_; - MYFLT &Gb = *Gb_; - MYFLT &E = *E_; - MYFLT &C1 = *C1_; - // Recompute Runge-Kutta stuff every kperiod in case kontrol variables - // have changed. - step_size = *step_size_; - // h = step_size*G/C2; - h = step_size * G / C2; - // h2 = (h)*(.5); - h2 = h / 2.0; - // h6 = (h)/(6); - h6 = h / 6.0; - // anor = Ga/G; - anor = Ga / G; - // bnor = Gb/G; - bnor = Gb / G; - // bnorplus1 = bnor + 1; - bnorplus1 = bnor + 1.0; - // alpha = C2/C1; - alpha = C2 / C1; - // beta = C2/(L*G*G); - beta = C2 / (L * G * G); - // gammaloc = (R0*C2)/(L*G); - gammaloc = (R0 * C2) / (L * G); - // bh = beta*h; - bh = beta * h; - // bh2 = beta*h2; - bh2 = beta * h2; - // ch = gammaloc*h; - ch = gammaloc * h; - // ch2 = gammaloc*h2; - ch2 = gammaloc * h2; - // omch2 = 1 - ch2; - omch2 = 1.0 - ch2; - // Standard 4th-order Runge-Kutta integration. - for (size_t i = offset; i < ksmps; i++) { - // Stage 1. - k1(1) = alpha * (M(2) - bnorplus1 * M(1) - - (.5) * (anor - bnor) * (abs(M(1) + 1) - abs(M(1) - 1))); - k1(2) = M(1) - M(2) + M(3); - k1(3) = -beta * M(2) - gammaloc * M(3); - // Stage 2. - temp = M(1) + h2 * k1(1); - k2(1) = alpha * (M(2) + h2 * k1(2) - bnorplus1 * temp - - (.5) * (anor - bnor) * (abs(temp + 1) - abs(temp - 1))); - k2(2) = k1(2) + h2 * (k1(1) - k1(2) + k1(3)); - k2(3) = omch2 * k1(3) - bh2 * k1(2); - // Stage 3. - temp = M(1) + h2 * k2(1); - k3(1) = alpha * (M(2) + h2 * k2(2) - bnorplus1 * temp - - (.5) * (anor - bnor) * (abs(temp + 1) - abs(temp - 1))); - k3(2) = k1(2) + h2 * (k2(1) - k2(2) + k2(3)); - k3(3) = k1(3) - bh2 * k2(2) - ch2 * k2(3); - // Stage 4. - temp = M(1) + h * k3(1); - k4(1) = alpha * (M(2) + h * k3(2) - bnorplus1 * temp - - (.5) * (anor - bnor) * (abs(temp + 1) - abs(temp - 1))); - k4(2) = k1(2) + h * (k3(1) - k3(2) + k3(3)); - k4(3) = k1(3) - bh * k3(2) - ch * k3(3); - M = M + (k1 + 2 * k2 + 2 * k3 + k4) * (h6); - // TimeSeries(3,i+1) = E*M(1); - V1[i] = E * M(1); - // TimeSeries(2,i+1) = E*M(2); - V2[i] = E * M(2); - // TimeSeries(1,i+1) = (E*G)*M(3); - I3[i] = (E * G) * M(3); - // warn(csound, "%4d V1: %f V2: %f I3: %f\n", i, V1[i], V2[i], I3[i]); - } - return OK; - } -}; - -extern "C" { -OENTRY oentries[] = { - // { - // (char*)"chuac", - // sizeof(ChuasOscillatorCubic), - // 0, - // 5, - // // kL, kR0, kC2, kG, kC1, iI3, iV2, iV1, - // kstep_size - // // 0.00945, 7.5, 2e-007, 0.00105, 1.5e-008, 0, -0.1, 0.1, 5e-6 - // (char*)"aaa", - // (char*)"kkkkkiiik", - // (SUBR) ChuasOscillatorCubic::init_, - // 0, - // (SUBR) ChuasOscillatorCubic::kontrol_, - // }, - { - (char *)"chuap", sizeof(ChuasOscillatorPiecewise), 0, 3, - // kL, kR0, kC2, kG, kGa, kGb, kE, kC1, - // iI3, iV2, iV1, kstep_size - // 0.00945, 7.5, 2e-007, 0.00105, 0, -0.00121, 1.76e-005, - // 1.5e-008, - // 0, -0.1, 0.1, 5e-6 - (char *)"aaa", (char *)"kkkkkkkkiiik", - (SUBR)ChuasOscillatorPiecewise::init_, - (SUBR)ChuasOscillatorPiecewise::kontrol_, - }, - { - 0, 0, 0, 0, 0, 0, 0, 0, 0, - }}; - -PUBLIC int csoundModuleCreate(CSOUND *csound) { return 0; } - -PUBLIC int csoundModuleInit(CSOUND *csound) { - int status = 0; - for (OENTRY *oentry = &oentries[0]; oentry->opname; oentry++) { - status |= csound->AppendOpcode(csound, oentry->opname, oentry->dsblksiz, - oentry->flags, oentry->thread, - oentry->outypes, oentry->intypes, - (int (*)(CSOUND *, void *))oentry->iopadr, - (int (*)(CSOUND *, void *))oentry->kopadr, - (int (*)(CSOUND *, void *))oentry->aopadr); - } - return status; -} - -PUBLIC int csoundModuleDestroy(CSOUND *csound) { return 0; } -} diff --git a/6.x/src/chua/OpcodeBase.hpp b/6.x/src/chua/OpcodeBase.hpp deleted file mode 100644 index 21ca8a0c..00000000 --- a/6.x/src/chua/OpcodeBase.hpp +++ /dev/null @@ -1,492 +0,0 @@ -/* - OpcodeBase.hpp: - - Copyright (C) 2005, 2009, 2017 by Istva Varga, Victor Lazzarini and - Michael Gogins - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ -#pragma once - -/** - * There is a conflict between the preprocessor definition "_CR" in the - * standard C++ library and in Csound. To work around this, undefine "_CR" and - * include ALL standard library include files BEFORE including ANY Csound - * include files. - */ -#if defined(_CR) -#undef _CR -#endif - -#include -#include -#include -#if !(defined(__wasi__)) -#include -#endif -#include -#include -#include -#include - -/** - * Template base class, or pseudo-virtual base class, - * for writing Csound opcodes in C++. - * Derive opcode implementation classes like this: - * - * DerivedClass : public OpcodeBase - * { - * public: - * // All output fields must be declared first as MYFLT *: - * MYFLT *aret1; - * // All input fields must be declared next as MYFLT *: - * MYFLT *iarg1; - * MYFLT *karg2; - * MYFLT *aarg3; - * // All internal state variables must be declared after that: - * size_t state1; - * double state2; - * MYFLT state3; - * // If the opcode shares data protect it by creating one or more void - * // *mutex member pointers: - * void *mutex1; - * void *mutex2; - * // and create them usind csound->Create_Mutex() in csoundModuleCreate - * // and destroy them using csound->DeleteMutex(mutex) - * // csoundModuleDestroy, and lock them using LockGuard guard(mutex). - * int init(); - * int kontrol(); - * int audio; - * int noteoff(); - * void deinit(); - * }; - */ - -namespace csound { - -static bool diagnostics_enabled = false; - -/** - * Use this to guard against data races in opcode functions. The mutex should - * be created by csound->Create_Mutex() in csoundModuleCreate(), and should - * be destroyed by csound->DeleteMutex() in csoundModuleDestroy(). - * - * If data is shared between opcode instances, the mutex should be global to - * the opcode library; if data is shared between threads for a single instance, - * the mutex should belong to the opcode instance. - */ -struct LockGuard { - LockGuard(CSOUND *csound_, void *mutex_) : csound(csound_), mutex(mutex_) - { - csound->LockMutex(mutex); - } - ~LockGuard() - { - csound->UnlockMutex(mutex); - } - CSOUND *csound; - void *mutex; -}; - -/** - * Use this to store a pointer to a global heap-allocated object, e.g. one - * used to manage state between opcode instances. - */ - -template int CreateGlobalPointer(CSOUND *csound, const char *name, T *pointer) -{ - T **pointer_to_pointer = 0; - int result = csound->CreateGlobalVariable(csound, name, sizeof(pointer_to_pointer)); - pointer_to_pointer = static_cast(csound->QueryGlobalVariable(csound, name)); - *pointer_to_pointer = pointer; - return result; -} - -/** - * Retrieve a pointer to a global heap-allocated object, e.g. one - * used to manage state between opcode instances. - */ -template T *QueryGlobalPointer(CSOUND *csound, const char *name, T*& pointer) -{ - T **pointer_to_pointer = static_cast(csound->QueryGlobalVariableNoCheck(csound, name)); - if (pointer_to_pointer != 0) { - pointer = *pointer_to_pointer; - } else { - pointer = 0; - } - return pointer; -} - -template -class OpcodeBase -{ -public: - int init(CSOUND *csound) - { - return NOTOK; - } - static int init_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->init(csound); - } - int kontrol(CSOUND *csound) - { - return NOTOK; - } - static int kontrol_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->kontrol(csound); - } - int audio(CSOUND *csound) - { - return NOTOK; - } - static int audio_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->audio(csound); - } - /** - This is how to compute audio signals for normal opcodes: - (1) Zero all frames from 0 up to but not including Offset. - (2) Compute all frames from ksmps_offset up to but not including End. - (3) Zero all frames from End up to but not including ksmps. - Example from a C opcode: - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); - } - for (n = offset; n < nsmps; n++) { - input1 = MYFLT2LRND(p->a[n]); - p->r[n] = (MYFLT) (input1 >> input2); - } - So in C++ it should look like this (which is much easier to understand): - int frameIndex = 0; - for( ; frameIndex < kperiodOffset(); ++frameIndex) { - asignal[frameIndex] = 0; - } - for( ; frameIndex < kperiodEnd(); ++frameIndex) { - asignal[frameIndex] = compute(); - } - for( ; frameIndex < ksmps(); ++frameIndex) { - asignal[frameIndex] = 0; - } - */ - uint32_t kperiodOffset() const - { - return opds.insdshead->ksmps_offset; - } - uint32_t kperiodEnd() const - { - uint32_t end = opds.insdshead->ksmps_no_end; - if (end) { - return end; - } else { - return ksmps(); - } - } - uint32_t ksmps() const - { - return opds.insdshead->ksmps; - } - uint32_t output_arg_count() - { - return (uint32_t)opds.optext->t.outArgCount; - } - uint32_t input_arg_count() - { - return (uint32_t)opds.optext->t.inArgCount; - } - void log(CSOUND *csound, const char *format,...) - { - va_list args; - va_start(args, format); - if(csound) { - csound->MessageV(csound, 0, format, args); - } else { - vfprintf(stdout, format, args); - } - va_end(args); - } - void warn(CSOUND *csound, const char *format,...) - { - if(csound) { - if(csound->GetMessageLevel(csound) & CS_WARNMSG) { - va_list args; - va_start(args, format); - csound->MessageV(csound, CSOUNDMSG_WARNING, format, args); - va_end(args); - } - } else { - va_list args; - va_start(args, format); - vfprintf(stdout, format, args); - va_end(args); - } - } - OPDS opds; -}; - -template -class OpcodeNoteoffBase -{ -public: - int init(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int init_(CSOUND *csound, void *opcode) - { - if (!csound->GetReinitFlag(csound) && !csound->GetTieFlag(csound)) { - csound->RegisterDeinitCallback(csound, opcode, - &OpcodeNoteoffBase::noteoff_); - } - return reinterpret_cast(opcode)->init(csound); - } - int kontrol(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int kontrol_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->kontrol(csound); - } - int audio(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int audio_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->audio(csound); - } - /** - This is how to compute audio signals for normal opcodes: - (1) Zero all frames from 0 up to but not including Offset. - (2) Compute all frames from ksmps_offset up to but not including End. - (3) Zero all frames from End up to but not including ksmps. - Example from a C opcode: - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); - } - for (n = offset; n < nsmps; n++) { - input1 = MYFLT2LRND(p->a[n]); - p->r[n] = (MYFLT) (input1 >> input2); - } - So in C++ it should look like this (which is much easier to understand): - int frameIndex = 0; - for( ; frameIndex < kperiodOffset(); ++frameIndex) { - asignal[frameIndex] = 0; - } - for( ; frameIndex < kperiodEnd(); ++frameIndex) { - asignal[frameIndex] = compute(); - } - for( ; frameIndex < ksmps(); ++frameIndex) { - asignal[frameIndex] = 0; - } - */ - uint32_t kperiodOffset() const - { - return opds.insdshead->ksmps_offset; - } - uint32_t kperiodEnd() const - { - uint32_t end = opds.insdshead->ksmps_no_end; - if (end) { - return end; - } else { - return ksmps(); - } - } - uint32_t ksmps() const - { - return opds.insdshead->ksmps; - } - uint32_t output_arg_count() - { - return (uint32_t)opds.optext->t.outArgCount; - } - uint32_t input_arg_count() - { - return (uint32_t)opds.optext->t.inArgCount; - } - void log(CSOUND *csound, const char *format,...) - { - va_list args; - va_start(args, format); - if(csound) { - csound->MessageV(csound, 0, format, args); - } else { - vfprintf(stdout, format, args); - } - va_end(args); - } - void warn(CSOUND *csound, const char *format,...) - { - if(csound) { - if(csound->GetMessageLevel(csound) & CS_WARNMSG) { - va_list args; - va_start(args, format); - csound->MessageV(csound, CSOUNDMSG_WARNING, format, args); - va_end(args); - } - } else { - va_list args; - va_start(args, format); - vfprintf(stdout, format, args); - va_end(args); - } - } - int noteoff(CSOUND *csound) - { - return OK; - } - static int noteoff_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->noteoff(csound); - } - OPDS opds; -}; - -#if (__cplusplus >= 201103L) && !(defined(__wasi__)) -#pragma message("Defining heap_object_manager_t.") - -/** - * The memory of non-POD C++ or C objects allocated on the heap by Csound - * plugins is managed not by Csound, but by the plugin module. This class - * performs that function. - * - * As long as all memory is allocated in or after csoundModuleCreate and - * de-allocated in csoundModuleDestroy, all will be well. The danger however - * is that memory leaks will occur if allocations are not matched with - * de-allocations, or worse, that crashes will occur if any objects are - * deleted twice or de-referenced after deletion. - * - * So, the plugin should manage a collection of all heap-allocated objects, - * keyed first off the Csound instance, and second off an object handle; and - * all such objects must be accessed only by handle, from this collection. - * - * In csoundModuleDestroy, all objects for the calling instance of Csound - * should be de-allocated, and the sub-collection for that instance should - * also be de-allocated. - * - * If then there are no more sub-collections for other instances of Csound, - * the entire contents of the collection should be de-allocated. - * - * This should be done as a singleton, and in a thread-safe way. - * - * There might still be a problem if any of the heap-allocated objects, - * themselves, have global static members, perhaps created by some external - * dependency. - * - * Please note, objects O in the declaration below must not be std::shared_ptr - * objects. Deletion of objects herein must be unconditional. Rather, the - * objects passed are raw pointers to instances of class O. - */ - template class heap_object_manager_t { - private: - std::map> objects_; - std::recursive_mutex mutex; - heap_object_manager_t(){}; - ~heap_object_manager_t(){}; - public: - static heap_object_manager_t &instance() { - static heap_object_manager_t singleton; - return singleton; - } - std::map> &objects() { - std::lock_guard lock(mutex); - return objects_; - } - /** - * Returns a list of pointers to all objects allocated for this - * instance of Csound. - */ - std::vector &objects_for_csound(CSOUND *csound) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects()[csound]; - return objects_for_csound_; - } - /** - * Returns the handle for the object; if the object has not yet been - * stored, inserts it into the list of object pointers for this - * instance of Csound; otherwise, returns the handle of the stored - * object pointer. - */ - int handle_for_object(CSOUND *csound, O *object) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - auto iterator = std::find(objects_for_csound_.begin(), objects_for_csound_.end(), object); - if (iterator == objects_for_csound_.end()) { - int handle = objects_for_csound_.size(); - objects_for_csound_.push_back(object); - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::handle_for_object %p: new object handle: %d (of %ld)\n", object, handle, objects_for_csound_.size()); - return handle; - } else { - int handle = static_cast(iterator - objects_for_csound_.begin()); - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::handle_for_object: existing object handle: %d\n", handle); - return handle; - } - } - /** - * Returns the object pointer for the handle; - * if the object pointer has not been stored by - * handle, returns a null pointer. - */ - O *object_for_handle(CSOUND *csound, int handle) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - if (handle >= objects_for_csound_.size()) { - return nullptr; - } - O *object = objects_for_csound_[handle]; - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::object_for_handle: %p %d (of %ld)\n", object, handle, objects_for_csound_.size()); - return object; - } - /** - * First destroys all objects created by the calling - * instance of Csound, then destroys the list of - * object pointers for this instance of Csound. - */ - void module_destroy(CSOUND *csound) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - for (int i = 0, n = objects_for_csound_.size(); i < n; ++i) { - delete objects_for_csound_[i]; - objects_for_csound_[i] = nullptr; - } - objects_for_csound_.clear(); - objects().erase(csound); - } -}; - -#else -#pragma message("Not defining heap_manager_t.") -#endif - -} diff --git a/6.x/src/faustcsound/CMakeLists.txt b/6.x/src/faustcsound/CMakeLists.txt deleted file mode 100644 index 45b9d3dd..00000000 --- a/6.x/src/faustcsound/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Build faustcsound opcodes -option(BUILD_FAUST_OPCODES "Build the Faust opcodes" ON) - -find_package(FAUST) -check_deps(BUILD_FAUST_OPCODES FAUST_FOUND) - -if(BUILD_FAUST_OPCODES AND FAUST_FOUND) - make_plugin(faustcsound faustgen.cpp) - - if(APPLE) - set_target_properties(faustcsound PROPERTIES - INSTALL_RPATH_USE_LINK_PATH TRUE - ) - endif() - - target_include_directories(faustcsound PRIVATE ${CSOUND_INCLUDE_DIRS}) - target_link_libraries(faustcsound ${PTHREAD_LIBRARY}) - target_compile_definitions(faustcsound PRIVATE "-DFAUSTFLOAT=MYFLT") - - if(PTHREAD_LIBRARY) - target_compile_definitions(faustcsound PRIVATE "-DHAVE_PTHREAD") - endif() - - if(APPLE) - if(${OSX_VERSION} STREQUAL "10.6") - target_link_libraries(faustcsound ${FAUST_LIBRARIES}) - else() - target_compile_options(faustcsound PRIVATE "-stdlib=libc++") - target_link_libraries(faustcsound ${FAUST_LIBRARIES} -stdlib=libc++) - endif() - else() - target_link_libraries(faustcsound ${FAUST_LIBRARIES}) - endif() - - target_include_directories(faustcsound PRIVATE ${FAUST_INCLUDE_DIR}) - message("-- FAUST INCLUDE DIR: ${FAUST_INCLUDE_DIR}") -endif() diff --git a/6.x/src/faustcsound/README.md b/6.x/src/faustcsound/README.md deleted file mode 100644 index da5dff5e..00000000 --- a/6.x/src/faustcsound/README.md +++ /dev/null @@ -1,29 +0,0 @@ -Faust opcodes -======= - -To build the faust opcodes, you will need the Faust library, which can downloaded -from [https://github.com/grame-cncm/faust/releases] (https://github.com/grame-cncm/faust/releases) -or built from sources (you will also need libcrypto and LLVM -installed). - -If using the pre-built binaries the following CMake variables are -important: - -`FAUST_INCLUDE_DIR_HINT` - -and - -`FAUST_LIB_DIR_HINT` - -They should point to the include and lib directories inside the faust -binary package. For example, if the package (for example, -Faust 2.33.1) is placed at the top-level user directory use the CMake command - -``` -cmake .. -DFAUST_INCLUDE_DIR_HINT=$HOME/faust-2.33.1/include --DFAUST_LIB_DIR_HINT=$HOME/faust-2.33.1/lib -``` - -to correctly find the library and headers. The library will be built -and linked to the installed faust library. - diff --git a/6.x/src/faustcsound/faustgen.cpp b/6.x/src/faustcsound/faustgen.cpp deleted file mode 100644 index bf885305..00000000 --- a/6.x/src/faustcsound/faustgen.cpp +++ /dev/null @@ -1,1115 +0,0 @@ -/* faustgen.cpp - - Copyright (c) Victor Lazzarini, 2013 - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA - - Faust Csound opcodes - - These four opcodes allow Faust to be embedded in Csound code: - - faustcompile: compiles a Faust program - faustaudio: creates a DSP instance from a compiled Faust program - (any number of instances from a single compiled program are - allowed) - faustctl: sets the value of a given control of a Faust DSP instance - - faustgen: compiles and creates a single DSP instance from a Faust program - (convenient for one-off Faust programs) - - -*/ -#include "csdl.h" -#include "faust/dsp/llvm-dsp.h" -#include "faust/gui/UI.h" -#include -#if defined(MACOSX) || defined(linux) || defined(HAIKU) -#include -#endif - -#define MAXARG 40 - -/** - * Faust controls class for Csound - * - **/ -class controls : public UI { - - struct ctl { - FAUSTFLOAT *zone; - char label[65]; - MYFLT min, max; - ctl *nxt; - } anchor; - - void addctl(const char *label, FAUSTFLOAT *zone, FAUSTFLOAT min, - FAUSTFLOAT max) { - ctl *pctl = &anchor; - while (pctl->nxt) - pctl = pctl->nxt; - pctl->nxt = new ctl; - pctl = pctl->nxt; - strncpy(pctl->label, label, 63); - pctl->label[63] = '\n'; pctl->label[64] = '\0'; - pctl->zone = zone; - pctl->min = min; - pctl->max = max; - pctl->nxt = NULL; - } - -public: - controls() { - anchor.nxt = NULL; - anchor.label[0] = '\0'; - } - ~controls() { - ctl *pctl = &anchor, *tmp; - pctl = pctl->nxt; - while (pctl) { - tmp = pctl; - pctl = pctl->nxt; - delete tmp; - } - } - - virtual void openTabBox(const char *label){}; - virtual void openHorizontalBox(const char *label){}; - virtual void openVerticalBox(const char *label){}; - virtual void closeBox(){}; - - virtual void addSoundfile(const char *label, const char *filename, - Soundfile **sf_zone){}; - - virtual void addButton(const char *label, FAUSTFLOAT *zone) { - addctl(label, zone, 0, 0); - } - virtual void addCheckButton(const char *label, FAUSTFLOAT *zone) { - addctl(label, zone, 0, 0); - } - virtual void addVerticalSlider(const char *label, FAUSTFLOAT *zone, - FAUSTFLOAT init, FAUSTFLOAT min, - FAUSTFLOAT max, FAUSTFLOAT step) { - addctl(label, zone, min, max); - } - virtual void addHorizontalSlider(const char *label, FAUSTFLOAT *zone, - FAUSTFLOAT init, FAUSTFLOAT min, - FAUSTFLOAT max, FAUSTFLOAT step) { - addctl(label, zone, min, max); - } - virtual void addNumEntry(const char *label, FAUSTFLOAT *zone, FAUSTFLOAT init, - FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) { - addctl(label, zone, min, max); - } - virtual void addHorizontalBargraph(const char *label, FAUSTFLOAT *zone, - FAUSTFLOAT min, FAUSTFLOAT max){}; - virtual void addVerticalBargraph(const char *label, FAUSTFLOAT *zone, - FAUSTFLOAT min, FAUSTFLOAT max){}; - - FAUSTFLOAT *getZone(char *label) { - ctl *pctl = &anchor; - pctl = pctl->nxt; - while (pctl) { - if (strcmp(pctl->label, label) == 0) - break; - pctl = pctl->nxt; - } - if (pctl) - return pctl->zone; - else - return NULL; - } - MYFLT getMax(char *label) { - ctl *pctl = &anchor; - pctl = pctl->nxt; - while (pctl) { - if (strcmp(pctl->label, label) == 0) - break; - pctl = pctl->nxt; - } - if (pctl) - return pctl->max; - else - return 0; - } - MYFLT getMin(char *label) { - ctl *pctl = &anchor; - pctl = pctl->nxt; - while (pctl) { - if (strcmp(pctl->label, label) == 0) - break; - pctl = pctl->nxt; - } - if (pctl) - return pctl->min; - else - return 0; - } -}; - -/** - * Faust object handle - * - **/ -struct faustobj { - void *obj; - controls *ctls; - faustobj *nxt; - uint64_t cnt; -}; - -/** - * Faust compile opcode - - usage: - ihandle faustcompile Scode, Sargs[,iasync, istacksize] - - ihandle - handle to compiled code - Scode - Faust program - Sargs - Faust compiler args - istacksize - compiler stack size in megabytes (default 1MB). - iasync - async operation (1 = on, 0 = off) default to 1 -**/ -struct faustcompile { - OPDS h; - MYFLT *hptr; - STRINGDAT *code; - STRINGDAT *args; - MYFLT *async; - MYFLT *stacksize; - MYFLT *extra; - llvm_dsp_factory *factory; - uintptr_t thread; - void *lock; -}; - -char **parse_cmd(CSOUND *csound, char *str, int32_t *argc) { - char **argv; - int32_t i = 0, n = 0, end = strlen(str); - while (str[i] == ' ') - i++; - if (str[i] != '\0') - *argc = 1; - while (str[i] != '\0') { - if (str[i] == ' ') { - while (str[++i] == ' ') - ; - if (str[i] == '\0') - break; - (*argc)++; - } - i++; - } - argv = (char **)csound->Calloc(csound, sizeof(char *) * (*argc)); - i = 0; - while (str[i] == ' ') - i++; - for (n = 0; n < *argc && i < end; n++) { - argv[n] = &(str[i]); - while (str[++i] != ' ' && i < end) - ; - if (i >= end) - break; - str[i] = '\0'; - while (str[++i] == ' ' && i < end) - ; - } - return argv; -} - -int32_t delete_faustcompile(CSOUND *csound, void *p) { - - faustcompile *pp = ((faustcompile *)p); - faustobj *fobj, *prv, **pfobj; - csound->JoinThread((void *) pp->thread); - pfobj = (faustobj **)csound->QueryGlobalVariable(csound, "::factory"); - if(pfobj != NULL) { - fobj = *pfobj; - prv = fobj; - while (fobj != NULL) { - if (fobj->obj == (void *)pp->factory) { - prv->nxt = fobj->nxt; - break; - } - prv = fobj; - fobj = fobj->nxt; - } - if (fobj != NULL) { - if (*pfobj == fobj) - *pfobj = fobj->nxt; - deleteDSPFactory(pp->factory); - csound->Free(csound, fobj); - } - } - csound->DestroyMutex(pp->lock); - return OK; -} - -struct hdata { - faustcompile *p; - CSOUND *csound; -}; - -void *init_faustcompile_thread(void *pp) { - - faustcompile *p = ((hdata *)pp)->p; - faustobj **pffactory, *ffactory; - CSOUND *csound = ((hdata *)pp)->csound; - llvm_dsp_factory *factory; - int32_t argc = 0; - std::string err_msg; - char *cmd = (char *) csound->Calloc(csound, p->args->size + 9); - char *ccode = csound->Strdup(csound, p->code->data); - char *extra; - MYFLT test = *p->extra; - int32_t ret; - strcpy(cmd, p->args->data); -#ifdef USE_DOUBLE - strcat(cmd, " -double"); -#endif - const char **argv = (const char **) parse_cmd(csound, cmd, &argc); - const char *varname = "::factory"; - - if(test) - extra = ((STRINGDAT *) p->extra)->data; - else - extra = (char *) ""; - - // Need to protect this - csound->LockMutex((void *) p->lock); - // csound->Message(csound, "lock %p\n", p->lock); - factory = createDSPFactoryFromString("faustop", (const char *) ccode, - argc, argv, extra, err_msg, 3); - // csound->Message(csound, "unlock %p\n", p->lock); - csound->UnlockMutex((void *) p->lock); - - if (factory == NULL) { - csound->Message(csound, Str("\nFaust compilation problem:\nline %s\n"), - err_msg.c_str()); - *(p->hptr) = FL(-2.0); // error code. - csound->Free(csound, argv); - csound->Free(csound, cmd); - csound->Free(csound, ccode); - csound->Free(csound, pp); - ret = -1; - return NULL; - } - - pffactory = (faustobj **)csound->QueryGlobalVariable(csound, varname); - if (pffactory == NULL) { - csound->CreateGlobalVariable(csound, varname, sizeof(faustobj *)); - pffactory = (faustobj **)csound->QueryGlobalVariable(csound, varname); - ffactory = (faustobj *)csound->Calloc(csound, sizeof(faustobj)); - ffactory->obj = factory; - ffactory->nxt = NULL; - ffactory->cnt = 0ul; - *pffactory = ffactory; - } else { - ffactory = *pffactory; - while (ffactory->nxt) { - ffactory = ffactory->nxt; - } - ffactory->nxt = (faustobj *) csound->Calloc(csound, sizeof(faustobj)); - ffactory->nxt->cnt = ffactory->cnt+1ul; - ffactory = ffactory->nxt; - ffactory->obj = factory; - } - p->factory = factory; - if(p->hptr) - *p->hptr = FL(ffactory->cnt); - csound->Free(csound, argv); - csound->Free(csound, cmd); - csound->Free(csound, ccode); - csound->Free(csound, pp); - - //csound->Message(csound, "Successfully compiled faust code\n"); - return NULL; -} - -#define MBYTE 1048576 -int32_t init_faustcompile(CSOUND *csound, faustcompile *p) { - uintptr_t thread; - hdata *data = (hdata *)csound->Malloc(csound, sizeof(hdata)); - data->csound = csound; - data->p = p; - *p->hptr = -1.0; - p->lock = csound->Create_Mutex(0); - - /* New API function allows thread stack to be defined - new in Csound 6.17 */ - thread = (uintptr_t) - csound->CreateThread2((uintptr_t (*)(void *))init_faustcompile_thread, *p->stacksize * MBYTE, data); - - p->thread = thread; - if(!(int)*p->async) { - csound->JoinThread((void *) thread); - return OK; - } - else csound->RegisterResetCallback(csound, p, delete_faustcompile); - return OK; -} - -struct faustdsp { - OPDS h; - MYFLT *ohptr; - MYFLT *code; /* faust compiled code handle */ - llvm_dsp *engine; /* faust DSP */ - llvm_dsp_factory *factory; /* DSP factory */ -}; - -/* deinit function - delete faust dsp objects -*/ -int32_t delete_faustdsp(CSOUND *csound, void *p) { - faustdsp *pp = (faustdsp *)p; - faustobj *fobj, *prv, **pfobj; - pfobj = (faustobj **)csound->QueryGlobalVariable(csound, "::dsp"); - fobj = *pfobj; - prv = fobj; - while (fobj != NULL) { - if (fobj->obj == (void *)pp->engine) { - prv->nxt = fobj->nxt; - break; - } - prv = fobj; - fobj = fobj->nxt; - } - if (fobj != NULL) { - if (*pfobj == fobj) - *pfobj = fobj->nxt; - csound->Free(csound, fobj); - delete pp->engine; - } else - csound->Warning(csound, Str("could not find DSP %p for deletion"), - pp->engine); - if (pp->factory) - deleteDSPFactory(pp->factory); - - return OK; -} - -int32_t init_faustdsp(CSOUND *csound, faustdsp *p) { - int32_t factory; - faustobj *fobj, **fobjp, **pfdsp, *fdsp; - llvm_dsp *dsp; - controls *ctls = new controls(); - const char *varname = "::dsp"; - int timout = 0; - while (*((MYFLT *)p->code) == -1.0) { - csound->Sleep(1); - timout++; - if(timout > 1000) { - return csound->InitError( - csound, "%s", Str("Faust code was not ready. Try compiling it \n" - "in a separate instrument prior to running it here\n")); - } - } - - factory = (int32_t)*((MYFLT *)p->code); - - if (factory == -2) - return csound->InitError( - csound, "%s", Str("Faust code did not compile properly.\n" - "Check above messages for Faust compiler errors\n")); - - fobjp = (faustobj **)csound->QueryGlobalVariable(csound, "::factory"); - if (fobjp == NULL) - return csound->InitError(csound, "%s", Str("no factory available\n")); - fobj = *fobjp; - while ((int32_t)fobj->cnt != factory) { - fobj = fobj->nxt; - if (fobj == NULL) - return csound->InitError(csound, Str("factory not found %d\n"), - (int32_t)factory); - } - - dsp = ((llvm_dsp_factory *)fobj->obj)->createDSPInstance(); - if (dsp == NULL) - return csound->InitError(csound, "%s", Str("Faust instantiation problem\n")); - - dsp->buildUserInterface(ctls); - pfdsp = (faustobj **)csound->QueryGlobalVariable(csound, varname); - if (pfdsp == NULL) { - csound->CreateGlobalVariable(csound, varname, sizeof(faustobj *)); - pfdsp = (faustobj **)csound->QueryGlobalVariable(csound, varname); - fdsp = (faustobj *)csound->Calloc(csound, sizeof(faustobj)); - fdsp->obj = dsp; - fdsp->ctls = ctls; - fdsp->nxt = NULL; - fdsp->cnt = 0; - *pfdsp = fdsp; - } else { - fdsp = *pfdsp; - if (fdsp != NULL) { - while (fdsp->nxt) { - fdsp = fdsp->nxt; - } - fdsp->nxt = (faustobj *)csound->Calloc(csound, sizeof(faustobj)); - fdsp->nxt->cnt = fdsp->cnt + 1; - fdsp = fdsp->nxt; - fdsp->obj = dsp; - fdsp->ctls = ctls; - } else { - fdsp = (faustobj *)csound->Calloc(csound, sizeof(faustobj)); - fdsp->obj = dsp; - fdsp->ctls = ctls; - fdsp->nxt = NULL; - fdsp->cnt = 0; - *pfdsp = fdsp; - } - } - - p->factory = NULL; // this opcode does not own the factory - p->engine = (llvm_dsp *)fdsp->obj; - p->engine->init(csound->GetSr(csound)); - csound->RegisterDeinitCallback(csound, p, delete_faustdsp); - *p->ohptr = (MYFLT)fdsp->cnt; - return OK; - -} - -struct faustplay { - OPDS h; - MYFLT *outs[MAXARG]; /* outputs */ - MYFLT *inst; - MYFLT *ins[VARGMAX]; /* inputs */ - llvm_dsp *engine; /* faust DSP */ - llvm_dsp_factory *factory; /* DSP factory */ - AUXCH memin; - AUXCH memout; -#ifndef USE_DOUBLE - AUXCH buffin; - AUXCH buffout; -#endif -}; - - -int32_t init_faustplay(CSOUND *csound, faustplay *p) { - faustobj *fobj, **fobjp; - OPARMS parms; - int32_t instance = (int32_t)*p->inst; - - fobjp = (faustobj **)csound->QueryGlobalVariable(csound, "::dsp"); - if (fobjp == NULL) - return csound->InitError(csound, "%s", Str("no dsp instances available\n")); - fobj = *fobjp; - - while ((int32_t)fobj->cnt != instance) { - fobj = fobj->nxt; - if (fobj == NULL) - return csound->InitError(csound, Str("dsp instance not found %d\n"), - (int32_t)*p->inst); - } - - p->engine = (llvm_dsp *)fobj->obj; - p->engine->init(csound->GetSr(csound)); - - if (p->engine->getNumInputs() != p->INCOUNT - 1) { - delete p->engine; - return csound->InitError(csound, "%s", Str("wrong number of input args\n")); - } - if (p->engine->getNumOutputs() != p->OUTCOUNT) { - delete p->engine; - return csound->InitError(csound, "%s", Str("wrong number of output args\n")); - } - - /* memory for sampAccurate offsets */ - csound->GetOParms(csound, &parms); - if (parms.sampleAccurate) { - size_t size; - size = p->engine->getNumInputs() * sizeof(MYFLT *); - if (p->memin.auxp == NULL || p->memin.size < size) - csound->AuxAlloc(csound, size, &p->memin); - size = p->engine->getNumOutputs() * sizeof(MYFLT *); - if (p->memout.auxp == NULL || p->memout.size < size) - csound->AuxAlloc(csound, size, &p->memout); - } - -#ifndef USE_DOUBLE - { - size_t size; - size = CS_KSMPS * p->engine->getNumInputs() * sizeof(double); - if (p->buffin.auxp == NULL || p->buffin.size < size) - csound->AuxAlloc(csound, size, &p->buffin); - size = CS_KSMPS * p->engine->getNumOutputs() * sizeof(double); - if (p->buffout.auxp == NULL || p->buffout.size < size) - csound->AuxAlloc(csound, size, &p->buffout); - } -#endif - return OK; -} - -int32_t perf_faustplay(CSOUND *csound, faustplay *p) { - int32_t nsmps = CS_KSMPS, i; - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - MYFLT **in_tmp = (MYFLT **)p->memin.auxp; - MYFLT **out_tmp = (MYFLT **)p->memout.auxp; - AVOIDDENORMALS; - - if (UNLIKELY(early)) { - for (i = 0; i < p->OUTCOUNT - 1; i++) - memset(p->outs[i], '\0', nsmps * sizeof(MYFLT)); - nsmps -= early; - } - if (UNLIKELY(offset)) { - /* offset pointers, save current pos */ - for (i = 0; i < p->OUTCOUNT; i++) { - memset(p->outs[i], '\0', nsmps * sizeof(MYFLT)); - out_tmp[i] = p->outs[i]; - p->outs[i] = &(p->outs[i][offset]); - } - for (i = 0; i < p->INCOUNT - 1; i++) { - in_tmp[i] = p->ins[i]; - p->ins[i] = &(p->ins[i][offset]); - } - nsmps -= offset; - } - -#ifdef USE_DOUBLE - p->engine->compute(nsmps, p->ins, p->outs); -#else - { - int n; - double *buffin, **buffinp = (double **) p->buffin.auxp; - double *buffout, **buffoutp = (double **) p->buffout.auxp; - for (i = 0; i < p->INCOUNT - 1; i++) { - buffin = ((double *)p->buffin.auxp) + CS_KSMPS*i; - if(UNLIKELY(offset)) - memset(buffin, '\0', offset * sizeof(MYFLT)); - for(n = offset; n < nsmps; n++) - buffin[n] = p->ins[i][n]; - } - p->engine->compute(nsmps,buffinp, buffoutp); - for (i = 0; i < p->OUTCOUNT - 1; i++) { - buffout = ((double *)p->buffout.auxp) + CS_KSMPS*i; - for(n = offset; n < nsmps; n++) - p->ins[i][n] = buffout[n]; - } - } -#endif - - if (UNLIKELY(offset)) { - /* restore pos */ - for (i = 0; i < p->OUTCOUNT; i++) - p->outs[i] = out_tmp[i]; - for (i = 0; i < p->INCOUNT - 1; i++) - p->ins[i] = in_tmp[i]; - } - return OK; -} - - -/** - * faustgen and faustaudio opcodes - - usage: - ihandle[,asig1,...] faustgen Scode[,ain1,...] - ihandle[,asig1,...] faustaudio ifactory,[,ain1,...] - - Scode - Faust program - ifactory - handle pointing to compiled code from faustcompile - asig1 ... - audio outputs from Faust program - ain1 ... - audio inputs to Faust program - - ihandle - handle identifying this Faust DSP instance - -**/ -struct faustgen { - OPDS h; - MYFLT *ohptr; - MYFLT *outs[MAXARG]; /* outputs */ - STRINGDAT *code; /* faust code as string */ - MYFLT *ins[VARGMAX]; /* inputs */ - llvm_dsp *engine; /* faust DSP */ - llvm_dsp_factory *factory; /* DSP factory */ - controls *ctls; - AUXCH memin; - AUXCH memout; -#ifndef USE_DOUBLE - AUXCH buffin; - AUXCH buffout; -#endif -}; - -struct hdata2 { - faustgen *p; - CSOUND *csound; -}; - - -/* deinit function - delete faust objects -*/ -int32_t delete_faustgen(CSOUND *csound, void *p) { - faustgen *pp = (faustgen *)p; - faustobj *fobj, *prv, **pfobj; - if((pfobj = (faustobj **)csound->QueryGlobalVariable(csound, "::dsp")) - != NULL) { - fobj = *pfobj; - prv = fobj; - while (fobj != NULL) { - if (fobj->obj == (void *)pp->engine) { - prv->nxt = fobj->nxt; - break; - } - prv = fobj; - fobj = fobj->nxt; - } - if (fobj != NULL) { - if (*pfobj == fobj) - *pfobj = fobj->nxt; - csound->Free(csound, fobj); - delete pp->ctls; - delete pp->engine; - } /*else - csound->Warning(csound, Str("could not find DSP %p for deletion"), - pp->engine);*/ - } - if (pp->factory) - deleteDSPFactory(pp->factory); - - return OK; -} - - -int32_t init_faustaudio(CSOUND *csound, faustgen *p) { - int32_t factory; - OPARMS parms; - faustobj *fobj, **fobjp, **pfdsp, *fdsp; - llvm_dsp *dsp; - controls *ctls = new controls(); - const char *varname = "::dsp"; - int timout = 0; - while (*((MYFLT *)p->code) == -1.0) { - csound->Sleep(1); - timout++; - if(timout > 1000) { - return csound->InitError( - csound, "%s", Str("Faust code was not ready. Try compiling it \n" - "in a separate instrument prior to running it here\n")); - } - } - - - factory = (int32_t)*((MYFLT *)p->code); - - if (factory == -2) - return csound->InitError( - csound, "%s", Str("Faust code did not compile properly.\n" - "Check above messages for Faust compiler errors\n")); - - fobjp = (faustobj **)csound->QueryGlobalVariable(csound, "::factory"); - if (fobjp == NULL) - return csound->InitError(csound, "%s", Str("no factory available\n")); - fobj = *fobjp; - while ((int32_t)fobj->cnt != factory) { - fobj = fobj->nxt; - if (fobj == NULL) - return csound->InitError(csound, Str("factory not found %d\n"), - (int32_t)factory); - } - - dsp = ((llvm_dsp_factory *)fobj->obj)->createDSPInstance(); - if (dsp == NULL) - return csound->InitError(csound, "%s", Str("Faust instantiation problem\n")); - - dsp->buildUserInterface(ctls); - pfdsp = (faustobj **)csound->QueryGlobalVariable(csound, varname); - if (pfdsp == NULL) { - csound->CreateGlobalVariable(csound, varname, sizeof(faustobj *)); - pfdsp = (faustobj **)csound->QueryGlobalVariable(csound, varname); - fdsp = (faustobj *)csound->Calloc(csound, sizeof(faustobj)); - fdsp->obj = dsp; - fdsp->ctls = ctls; - fdsp->nxt = NULL; - fdsp->cnt = 0; - *pfdsp = fdsp; - } else { - fdsp = *pfdsp; - if (fdsp != NULL) { - while (fdsp->nxt) { - fdsp = fdsp->nxt; - } - fdsp->nxt = (faustobj *)csound->Calloc(csound, sizeof(faustobj)); - fdsp->nxt->cnt = fdsp->cnt + 1; - fdsp = fdsp->nxt; - fdsp->obj = dsp; - fdsp->ctls = ctls; - } else { - fdsp = (faustobj *)csound->Calloc(csound, sizeof(faustobj)); - fdsp->obj = dsp; - fdsp->ctls = ctls; - fdsp->nxt = NULL; - fdsp->cnt = 0; - *pfdsp = fdsp; - } - } - - p->factory = NULL; // this opcode does not own the factory - p->engine = (llvm_dsp *)fdsp->obj; - p->engine->init(csound->GetSr(csound)); - - if (p->engine->getNumInputs() != p->INCOUNT - 1) { - delete p->engine; - p->engine = NULL; - return csound->InitError(csound, "%s", Str("wrong number of input args\n")); - } - if (p->engine->getNumOutputs() != p->OUTCOUNT - 1) { - delete p->engine; - p->engine = NULL; - return csound->InitError(csound, "%s", Str("wrong number of output args\n")); - } - - /* memory for sampAccurate offsets */ - csound->GetOParms(csound, &parms); - if (parms.sampleAccurate) { - size_t size; - size = p->engine->getNumInputs() * sizeof(MYFLT *); - if (p->memin.auxp == NULL || p->memin.size < size) - csound->AuxAlloc(csound, size, &p->memin); - size = p->engine->getNumOutputs() * sizeof(MYFLT *); - if (p->memout.auxp == NULL || p->memout.size < size) - csound->AuxAlloc(csound, size, &p->memout); - } - -#ifndef USE_DOUBLE - { - size_t size; - size = CS_KSMPS * p->engine->getNumInputs() * sizeof(double); - if (p->buffin.auxp == NULL || p->buffin.size < size) - csound->AuxAlloc(csound, size, &p->buffin); - size = CS_KSMPS * p->engine->getNumOutputs() * sizeof(double); - if (p->buffout.auxp == NULL || p->buffout.size < size) - csound->AuxAlloc(csound, size, &p->buffout); - } -#endif - - p->ctls = ctls; - csound->RegisterDeinitCallback(csound, p, delete_faustgen); - *p->ohptr = (MYFLT)fdsp->cnt; - return OK; -} - -void *init_faustgen_thread(void *pp) { - CSOUND *csound = ((hdata2 *)pp)->csound; - faustgen *p = ((hdata2 *)pp)->p; - OPARMS parms; - std::string err_msg; -#ifdef USE_DOUBLE - int32_t argc = 4; - const char *argv[] = {"-vec", "-lv", " 1", "-double"}; -#else - int32_t argc = 3; - const char *argv[] = {"-vec", "-lv", " 1"}; -#endif - faustobj **pfdsp, *fdsp; - llvm_dsp *dsp; - controls *ctls = new controls(); - const char *varname = "::dsp"; - p->engine = NULL; - p->factory = createDSPFactoryFromString( - "faustop", (const char *)p->code->data, argc, argv, "", err_msg, 3); - if (p->factory == NULL) { - int32_t ret = csound->InitError(csound, Str("Faust compilation problem: %s\n"), - err_msg.c_str()); - csound->Free(csound, pp); - return NULL; - } - - dsp = p->factory->createDSPInstance(); - if (dsp == NULL) { - int32_t ret = csound->InitError(csound, "%s", - Str("Faust instantiation problem\n")); - csound->Free(csound, pp); - return NULL; - } - - dsp->buildUserInterface(ctls); - - pfdsp = (faustobj **)csound->QueryGlobalVariable(csound, varname); - if (pfdsp == NULL || *pfdsp == NULL) { - csound->CreateGlobalVariable(csound, varname, sizeof(faustobj *)); - pfdsp = (faustobj **)csound->QueryGlobalVariable(csound, varname); - fdsp = (faustobj *)csound->Calloc(csound, sizeof(faustobj)); - fdsp->obj = dsp; - fdsp->ctls = ctls; - fdsp->nxt = NULL; - fdsp->cnt = 0; - *pfdsp = fdsp; - } else { - fdsp = *pfdsp; - while (fdsp->nxt) { - fdsp = fdsp->nxt; - } - fdsp->nxt = (faustobj *)csound->Calloc(csound, sizeof(faustobj)); - fdsp->nxt->cnt = fdsp->cnt++; - fdsp = fdsp->nxt; - fdsp->obj = dsp; - fdsp->ctls = ctls; - } - - p->engine = dsp; - dsp->buildUserInterface(ctls); - dsp->init(csound->GetSr(csound)); - if (p->engine->getNumInputs() != p->INCOUNT - 1) { - int32_t ret; - ret = csound->InitError(csound, "%s", Str("wrong number of input args\n")); - delete p->engine; - deleteDSPFactory(p->factory); - p->factory = NULL; - p->engine = NULL; - csound->Free(csound, pp); - return NULL; - } - if (p->engine->getNumOutputs() != p->OUTCOUNT - 1) { - int32_t ret; - ret = csound->InitError(csound, - Str("wrong number of output args: need %d had %d\n"), - p->engine->getNumOutputs(), - p->OUTCOUNT - 1 - ); - delete p->engine; - deleteDSPFactory(p->factory); - csound->Free(csound, pp); - p->engine = NULL; - p->factory = NULL; - return NULL; - } - - /* memory for sampAccurate offsets */ - csound->GetOParms(csound, &parms); - if (parms.sampleAccurate) { - size_t size; - size = p->engine->getNumInputs() * sizeof(MYFLT *); - if (p->memin.auxp == NULL || p->memin.size < size) - csound->AuxAlloc(csound, size, &p->memin); - size = p->engine->getNumOutputs() * sizeof(MYFLT *); - if (p->memout.auxp == NULL || p->memout.size < size) - csound->AuxAlloc(csound, size, &p->memout); - } - p->ctls = ctls; - *p->ohptr = (MYFLT)fdsp->cnt; - csound->Free(csound, pp); - return NULL; -} - -int32_t init_faustgen(CSOUND *csound, faustgen *p) { - uintptr_t thread; - int32_t *ret; - hdata2 *data = (hdata2 *)csound->Malloc(csound, sizeof(hdata2)); - data->csound = csound; - data->p = p; - /* New API function allows for threads to be given a stack */ - thread = (uintptr_t) - csound->CreateThread2((uintptr_t (*)(void *))init_faustgen_thread, MBYTE, data); - csound->RegisterDeinitCallback(csound, p, delete_faustgen); - csound->JoinThread((void *)thread); - csound->RegisterDeinitCallback(csound, p, delete_faustgen); - return OK; -} - -int32_t perf_faust(CSOUND *csound, faustgen *p) { - int32_t nsmps = CS_KSMPS, i; - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - MYFLT **in_tmp = (MYFLT **)p->memin.auxp; - MYFLT **out_tmp = (MYFLT **)p->memout.auxp; - AVOIDDENORMALS; - - if (UNLIKELY(early)) { - for (i = 0; i < p->OUTCOUNT - 1; i++) - memset(p->outs[i], '\0', nsmps * sizeof(MYFLT)); - nsmps -= early; - } - if (UNLIKELY(offset)) { - /* offset pointers, save current pos */ - for (i = 0; i < p->OUTCOUNT - 1; i++) { - memset(p->outs[i], '\0', nsmps * sizeof(MYFLT)); - out_tmp[i] = p->outs[i]; - p->outs[i] = &(p->outs[i][offset]); - } - for (i = 0; i < p->INCOUNT - 1; i++) { - in_tmp[i] = p->ins[i]; - p->ins[i] = &(p->ins[i][offset]); - } - nsmps -= offset; - } - -#ifdef USE_DOUBLE - p->engine->compute(nsmps, p->ins, p->outs); -#else - { - int n; - double *buffin, **buffinp = (double **) p->buffin.auxp; - double *buffout, **buffoutp = (double **) p->buffout.auxp; - for (i = 0; i < p->INCOUNT - 1; i++) { - buffin = ((double *)p->buffin.auxp) + CS_KSMPS*i; - if(UNLIKELY(offset)) - memset(buffin, '\0', offset * sizeof(MYFLT)); - for(n = offset; n < nsmps; n++) - buffin[n] = p->ins[i][n]; - } - p->engine->compute(nsmps,buffinp, buffoutp); - for (i = 0; i < p->OUTCOUNT - 1; i++) { - buffout = ((double *)p->buffout.auxp) + CS_KSMPS*i; - for(n = offset; n < nsmps; n++) - p->ins[i][n] = buffout[n]; - } - } -#endif - - if (UNLIKELY(offset)) { - /* restore pos -- coud be memcpy?*/ - for (i = 0; i < p->OUTCOUNT - 1; i++) - p->outs[i] = out_tmp[i]; - for (i = 0; i < p->INCOUNT - 1; i++) - p->ins[i] = in_tmp[i]; - } - return OK; -} - -#define MAXPARAM 128 - -/** - * faustctl opcode - - usage: - faustctl idsp, Slabel, kval[, Slabel1, kval1 ...] - - idsp - handle from an existing Faust DSP instance - Slabel - name of control (in Faust program) - kval - value to be sent to control - -**/ -struct faustctl { - OPDS h; - MYFLT *inst; - STRINGDAT *label; - MYFLT *val; - MYFLT *extraparam[MAXPARAM]; - FAUSTFLOAT *zone; - MYFLT min, max; - MYFLT minextra[MAXPARAM/2], maxextra[MAXPARAM/2]; - FAUSTFLOAT *zonextra[MAXPARAM/2]; -}; - -int32_t init_faustctl(CSOUND *csound, faustctl *p) { - - faustobj *fobj, **fobjp; - int32_t instance = (int32_t)*p->inst; - - /* checks that extra parameter count is even */ - if((p->INCOUNT - 3)%2) - return csound->InitError(csound, "unbalanced parameter count \n"); - - fobjp = (faustobj **)csound->QueryGlobalVariable(csound, "::dsp"); - if (fobjp == NULL) - return csound->InitError(csound, "%s", Str("no dsp instances available\n")); - fobj = *fobjp; - - while ((int32_t)fobj->cnt != instance) { - fobj = fobj->nxt; - if (fobj == NULL) - return csound->InitError(csound, Str("dsp instance not found %d\n"), - (int32_t)*p->inst); - } - - p->zone = fobj->ctls->getZone(p->label->data); - if (p->zone == NULL) - return csound->InitError(csound, Str("dsp control %s not found\n"), - p->label->data); - p->max = fobj->ctls->getMax(p->label->data); - p->min = fobj->ctls->getMin(p->label->data); - { - MYFLT val = *p->val; - if (p->min != p->max) - val = val < p->min ? p->min : (val > p->max ? p->max : val); - *p->zone = val; - } - - - /* implementation of extra optional parameters */ - for(int n = 0; n < p->INCOUNT - 3; n+=2) { - char *name = ((STRINGDAT *)p->extraparam[n])->data; - p->zonextra[n/2] = fobj->ctls->getZone(name); - if (p->zonextra[n/2] == NULL) - return csound->InitError(csound, Str("dsp control %s not found\n"), - name); - p->maxextra[n/2] = fobj->ctls->getMax(name); - p->minextra[n/2] = fobj->ctls->getMin(name); - { - MYFLT val = *(p->extraparam[n+1]); - MYFLT min = p->minextra[n/2]; - MYFLT max = p->maxextra[n/2]; - if (min != max) - val = val < min ? min : (val > max ? max : val); - *(p->zonextra[n/2]) = val; - } - } - - return OK; -} - -int32_t perf_faustctl(CSOUND *csound, faustctl *p) { - MYFLT val = *p->val; - if (p->min != p->max) - val = val < p->min ? p->min : (val > p->max ? p->max : val); - *p->zone = val; - - /* implementation of extra optional parameters */ - for(int n = 0; n < p->INCOUNT - 3; n+=2) { - MYFLT val = *(p->extraparam[n+1]); - MYFLT min = p->minextra[n/2]; - MYFLT max = p->maxextra[n/2]; - if (min != max) - val = val < min ? min : (val > max ? max : val); - *(p->zonextra[n/2]) = val; - } - return OK; -} - -#define S(x) sizeof(x) - -static OENTRY localops[] = { - {(char *)"faustgen", S(faustgen), 0, 3, - (char *)"immmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", (char *)"SM", - (SUBR)init_faustgen, (SUBR)perf_faust}, - {(char *)"faustcompile", S(faustcompile), 0, 1, (char *)"i", (char *)"SSppo", - (SUBR)init_faustcompile, NULL, NULL}, - {(char *)"faustaudio", S(faustgen), 0, 3, - (char *)"immmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", (char *)"iM", - (SUBR)init_faustaudio, (SUBR)perf_faust}, - {(char *)"faustdsp", S(faustdsp), 0, 1, - (char *)"i", (char *)"i", - (SUBR)init_faustdsp}, - {(char *)"faustplay", S(faustplay), 0, 3, - (char *)"mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", (char *)"iM", - (SUBR)init_faustplay, (SUBR)perf_faustplay}, - {(char *)"faustctl.i", S(faustgen), 0, 1, (char *)"", (char *)"iSiN", - (SUBR)init_faustctl}, - {(char *)"faustctl.k ", S(faustgen), 0, 3, (char *)"", (char *)"iSkN", - (SUBR)init_faustctl, (SUBR)perf_faustctl}}; - -PUBLIC int64_t csound_opcode_init(CSOUND *csound, OENTRY **ep) { - IGN(csound); - *ep = localops; - return (int64_t)sizeof(localops); -} - -PUBLIC int32_t csoundModuleInfo(void) { - return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int32_t)sizeof(MYFLT)); -} diff --git a/6.x/src/fluidOpcodes/Android/.gitignore b/6.x/src/fluidOpcodes/Android/.gitignore deleted file mode 100644 index 91e378c9..00000000 --- a/6.x/src/fluidOpcodes/Android/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -*DS_Store -obj -libs -bin -gen -src/csnd* -*swp -jni/csound_orc* -jni/csound_prelex.c -jni/java_interface* diff --git a/6.x/src/fluidOpcodes/Android/build.sh b/6.x/src/fluidOpcodes/Android/build.sh deleted file mode 100644 index 6d91356b..00000000 --- a/6.x/src/fluidOpcodes/Android/build.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -export ANDROID_NDK_ROOT=$NDK -export NDK_MODULE_PATH=../../../../android - -$ANDROID_NDK_ROOT/ndk-build TARGET_PLATFORM=android-9 $@ - - - diff --git a/6.x/src/fluidOpcodes/Android/jni/Android.mk b/6.x/src/fluidOpcodes/Android/jni/Android.mk deleted file mode 100644 index da9404ba..00000000 --- a/6.x/src/fluidOpcodes/Android/jni/Android.mk +++ /dev/null @@ -1,24 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LIBSNDFILE_SRC_DIR := $(NDK_MODULE_PATH)/libsndfile-android/jni/ -LIBFLUIDSYNTH_SRC_DIR := $(NDK_MODULE_PATH)/fluidsynth-android/jni/ - -LOCAL_MODULE := fluidOpcodes - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../H $(LOCAL_PATH)/../../../../include $(LOCAL_PATH)/../../../.. $(LOCAL_PATH)/../../../ $(LIBSNDFILE_SRC_DIR) $(LIBFLUIDSYNTH_SRC_DIR)/include $(LOCAL_PATH)/../.. $(LOCAL_PATH)/../../../CsoundAndroid/jni -LOCAL_CFLAGS := -O3 -D__BUILDING_LIBCSOUND -DENABLE_NEW_PARSER -DLINUX -DHAVE_DIRENT_H -DHAVE_FCNTL_H -DHAVE_UNISTD_H -DHAVE_STDINT_H -DHAVE_SYS_TIME_H -DHAVE_SYS_TYPES_H -DHAVE_TERMIOS_H -LOCAL_CPPFLAGS :=$(LOCAL_CFLAGS) -LOCAL_CPPFLAGS += -std=c++11 -pthread -frtti -fexceptions -### - -LOCAL_SRC_FILES := ../../fluidOpcodes.cpp - -LOCAL_LDLIBS += -ldl - -LOCAL_STATIC_LIBRARIES := fluidsynth-android - -include $(BUILD_SHARED_LIBRARY) - -$(call import-module,fluidsynth-android/jni) diff --git a/6.x/src/fluidOpcodes/Android/jni/Application.mk b/6.x/src/fluidOpcodes/Android/jni/Application.mk deleted file mode 100644 index f343179d..00000000 --- a/6.x/src/fluidOpcodes/Android/jni/Application.mk +++ /dev/null @@ -1,8 +0,0 @@ -APP_ABI := armeabi-v7a arm64-v8a -APP_CPPFLAGS += -fexceptions -frtti -APP_OPTIM := release -APP_PLATFORM := android-21 -#APP_STL := gnustl_shared -#NDK_TOOLCHAIN_VERSION := 4.9 -APP_STL := c++_shared -NDK_TOOLCHAIN_VERSION := clang diff --git a/6.x/src/fluidOpcodes/CMakeLists.txt b/6.x/src/fluidOpcodes/CMakeLists.txt deleted file mode 100644 index 0e6caa37..00000000 --- a/6.x/src/fluidOpcodes/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -option(BUILD_FLUID_OPCODES "Build the fluidsynth opcodes" ON) - -find_package(FLUIDSYNTH) -check_deps(BUILD_FLUID_OPCODES FLUIDSYNTH_FOUND) - -if(BUILD_FLUID_OPCODES AND FLUIDSYNTH_FOUND) - make_plugin(fluidOpcodes fluidOpcodes.cpp) - target_include_directories(fluidOpcodes PRIVATE ${FLUIDSYNTH_INCLUDE_DIR}) - target_include_directories(fluidOpcodes PRIVATE ${CSOUND_INCLUDE_DIR}) - target_link_libraries(fluidOpcodes ${FLUIDSYNTH_LIBRARIES}) -endif() diff --git a/6.x/src/fluidOpcodes/OpcodeBase.hpp b/6.x/src/fluidOpcodes/OpcodeBase.hpp deleted file mode 100644 index 21ca8a0c..00000000 --- a/6.x/src/fluidOpcodes/OpcodeBase.hpp +++ /dev/null @@ -1,492 +0,0 @@ -/* - OpcodeBase.hpp: - - Copyright (C) 2005, 2009, 2017 by Istva Varga, Victor Lazzarini and - Michael Gogins - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ -#pragma once - -/** - * There is a conflict between the preprocessor definition "_CR" in the - * standard C++ library and in Csound. To work around this, undefine "_CR" and - * include ALL standard library include files BEFORE including ANY Csound - * include files. - */ -#if defined(_CR) -#undef _CR -#endif - -#include -#include -#include -#if !(defined(__wasi__)) -#include -#endif -#include -#include -#include -#include - -/** - * Template base class, or pseudo-virtual base class, - * for writing Csound opcodes in C++. - * Derive opcode implementation classes like this: - * - * DerivedClass : public OpcodeBase - * { - * public: - * // All output fields must be declared first as MYFLT *: - * MYFLT *aret1; - * // All input fields must be declared next as MYFLT *: - * MYFLT *iarg1; - * MYFLT *karg2; - * MYFLT *aarg3; - * // All internal state variables must be declared after that: - * size_t state1; - * double state2; - * MYFLT state3; - * // If the opcode shares data protect it by creating one or more void - * // *mutex member pointers: - * void *mutex1; - * void *mutex2; - * // and create them usind csound->Create_Mutex() in csoundModuleCreate - * // and destroy them using csound->DeleteMutex(mutex) - * // csoundModuleDestroy, and lock them using LockGuard guard(mutex). - * int init(); - * int kontrol(); - * int audio; - * int noteoff(); - * void deinit(); - * }; - */ - -namespace csound { - -static bool diagnostics_enabled = false; - -/** - * Use this to guard against data races in opcode functions. The mutex should - * be created by csound->Create_Mutex() in csoundModuleCreate(), and should - * be destroyed by csound->DeleteMutex() in csoundModuleDestroy(). - * - * If data is shared between opcode instances, the mutex should be global to - * the opcode library; if data is shared between threads for a single instance, - * the mutex should belong to the opcode instance. - */ -struct LockGuard { - LockGuard(CSOUND *csound_, void *mutex_) : csound(csound_), mutex(mutex_) - { - csound->LockMutex(mutex); - } - ~LockGuard() - { - csound->UnlockMutex(mutex); - } - CSOUND *csound; - void *mutex; -}; - -/** - * Use this to store a pointer to a global heap-allocated object, e.g. one - * used to manage state between opcode instances. - */ - -template int CreateGlobalPointer(CSOUND *csound, const char *name, T *pointer) -{ - T **pointer_to_pointer = 0; - int result = csound->CreateGlobalVariable(csound, name, sizeof(pointer_to_pointer)); - pointer_to_pointer = static_cast(csound->QueryGlobalVariable(csound, name)); - *pointer_to_pointer = pointer; - return result; -} - -/** - * Retrieve a pointer to a global heap-allocated object, e.g. one - * used to manage state between opcode instances. - */ -template T *QueryGlobalPointer(CSOUND *csound, const char *name, T*& pointer) -{ - T **pointer_to_pointer = static_cast(csound->QueryGlobalVariableNoCheck(csound, name)); - if (pointer_to_pointer != 0) { - pointer = *pointer_to_pointer; - } else { - pointer = 0; - } - return pointer; -} - -template -class OpcodeBase -{ -public: - int init(CSOUND *csound) - { - return NOTOK; - } - static int init_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->init(csound); - } - int kontrol(CSOUND *csound) - { - return NOTOK; - } - static int kontrol_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->kontrol(csound); - } - int audio(CSOUND *csound) - { - return NOTOK; - } - static int audio_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->audio(csound); - } - /** - This is how to compute audio signals for normal opcodes: - (1) Zero all frames from 0 up to but not including Offset. - (2) Compute all frames from ksmps_offset up to but not including End. - (3) Zero all frames from End up to but not including ksmps. - Example from a C opcode: - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); - } - for (n = offset; n < nsmps; n++) { - input1 = MYFLT2LRND(p->a[n]); - p->r[n] = (MYFLT) (input1 >> input2); - } - So in C++ it should look like this (which is much easier to understand): - int frameIndex = 0; - for( ; frameIndex < kperiodOffset(); ++frameIndex) { - asignal[frameIndex] = 0; - } - for( ; frameIndex < kperiodEnd(); ++frameIndex) { - asignal[frameIndex] = compute(); - } - for( ; frameIndex < ksmps(); ++frameIndex) { - asignal[frameIndex] = 0; - } - */ - uint32_t kperiodOffset() const - { - return opds.insdshead->ksmps_offset; - } - uint32_t kperiodEnd() const - { - uint32_t end = opds.insdshead->ksmps_no_end; - if (end) { - return end; - } else { - return ksmps(); - } - } - uint32_t ksmps() const - { - return opds.insdshead->ksmps; - } - uint32_t output_arg_count() - { - return (uint32_t)opds.optext->t.outArgCount; - } - uint32_t input_arg_count() - { - return (uint32_t)opds.optext->t.inArgCount; - } - void log(CSOUND *csound, const char *format,...) - { - va_list args; - va_start(args, format); - if(csound) { - csound->MessageV(csound, 0, format, args); - } else { - vfprintf(stdout, format, args); - } - va_end(args); - } - void warn(CSOUND *csound, const char *format,...) - { - if(csound) { - if(csound->GetMessageLevel(csound) & CS_WARNMSG) { - va_list args; - va_start(args, format); - csound->MessageV(csound, CSOUNDMSG_WARNING, format, args); - va_end(args); - } - } else { - va_list args; - va_start(args, format); - vfprintf(stdout, format, args); - va_end(args); - } - } - OPDS opds; -}; - -template -class OpcodeNoteoffBase -{ -public: - int init(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int init_(CSOUND *csound, void *opcode) - { - if (!csound->GetReinitFlag(csound) && !csound->GetTieFlag(csound)) { - csound->RegisterDeinitCallback(csound, opcode, - &OpcodeNoteoffBase::noteoff_); - } - return reinterpret_cast(opcode)->init(csound); - } - int kontrol(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int kontrol_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->kontrol(csound); - } - int audio(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int audio_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->audio(csound); - } - /** - This is how to compute audio signals for normal opcodes: - (1) Zero all frames from 0 up to but not including Offset. - (2) Compute all frames from ksmps_offset up to but not including End. - (3) Zero all frames from End up to but not including ksmps. - Example from a C opcode: - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); - } - for (n = offset; n < nsmps; n++) { - input1 = MYFLT2LRND(p->a[n]); - p->r[n] = (MYFLT) (input1 >> input2); - } - So in C++ it should look like this (which is much easier to understand): - int frameIndex = 0; - for( ; frameIndex < kperiodOffset(); ++frameIndex) { - asignal[frameIndex] = 0; - } - for( ; frameIndex < kperiodEnd(); ++frameIndex) { - asignal[frameIndex] = compute(); - } - for( ; frameIndex < ksmps(); ++frameIndex) { - asignal[frameIndex] = 0; - } - */ - uint32_t kperiodOffset() const - { - return opds.insdshead->ksmps_offset; - } - uint32_t kperiodEnd() const - { - uint32_t end = opds.insdshead->ksmps_no_end; - if (end) { - return end; - } else { - return ksmps(); - } - } - uint32_t ksmps() const - { - return opds.insdshead->ksmps; - } - uint32_t output_arg_count() - { - return (uint32_t)opds.optext->t.outArgCount; - } - uint32_t input_arg_count() - { - return (uint32_t)opds.optext->t.inArgCount; - } - void log(CSOUND *csound, const char *format,...) - { - va_list args; - va_start(args, format); - if(csound) { - csound->MessageV(csound, 0, format, args); - } else { - vfprintf(stdout, format, args); - } - va_end(args); - } - void warn(CSOUND *csound, const char *format,...) - { - if(csound) { - if(csound->GetMessageLevel(csound) & CS_WARNMSG) { - va_list args; - va_start(args, format); - csound->MessageV(csound, CSOUNDMSG_WARNING, format, args); - va_end(args); - } - } else { - va_list args; - va_start(args, format); - vfprintf(stdout, format, args); - va_end(args); - } - } - int noteoff(CSOUND *csound) - { - return OK; - } - static int noteoff_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->noteoff(csound); - } - OPDS opds; -}; - -#if (__cplusplus >= 201103L) && !(defined(__wasi__)) -#pragma message("Defining heap_object_manager_t.") - -/** - * The memory of non-POD C++ or C objects allocated on the heap by Csound - * plugins is managed not by Csound, but by the plugin module. This class - * performs that function. - * - * As long as all memory is allocated in or after csoundModuleCreate and - * de-allocated in csoundModuleDestroy, all will be well. The danger however - * is that memory leaks will occur if allocations are not matched with - * de-allocations, or worse, that crashes will occur if any objects are - * deleted twice or de-referenced after deletion. - * - * So, the plugin should manage a collection of all heap-allocated objects, - * keyed first off the Csound instance, and second off an object handle; and - * all such objects must be accessed only by handle, from this collection. - * - * In csoundModuleDestroy, all objects for the calling instance of Csound - * should be de-allocated, and the sub-collection for that instance should - * also be de-allocated. - * - * If then there are no more sub-collections for other instances of Csound, - * the entire contents of the collection should be de-allocated. - * - * This should be done as a singleton, and in a thread-safe way. - * - * There might still be a problem if any of the heap-allocated objects, - * themselves, have global static members, perhaps created by some external - * dependency. - * - * Please note, objects O in the declaration below must not be std::shared_ptr - * objects. Deletion of objects herein must be unconditional. Rather, the - * objects passed are raw pointers to instances of class O. - */ - template class heap_object_manager_t { - private: - std::map> objects_; - std::recursive_mutex mutex; - heap_object_manager_t(){}; - ~heap_object_manager_t(){}; - public: - static heap_object_manager_t &instance() { - static heap_object_manager_t singleton; - return singleton; - } - std::map> &objects() { - std::lock_guard lock(mutex); - return objects_; - } - /** - * Returns a list of pointers to all objects allocated for this - * instance of Csound. - */ - std::vector &objects_for_csound(CSOUND *csound) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects()[csound]; - return objects_for_csound_; - } - /** - * Returns the handle for the object; if the object has not yet been - * stored, inserts it into the list of object pointers for this - * instance of Csound; otherwise, returns the handle of the stored - * object pointer. - */ - int handle_for_object(CSOUND *csound, O *object) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - auto iterator = std::find(objects_for_csound_.begin(), objects_for_csound_.end(), object); - if (iterator == objects_for_csound_.end()) { - int handle = objects_for_csound_.size(); - objects_for_csound_.push_back(object); - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::handle_for_object %p: new object handle: %d (of %ld)\n", object, handle, objects_for_csound_.size()); - return handle; - } else { - int handle = static_cast(iterator - objects_for_csound_.begin()); - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::handle_for_object: existing object handle: %d\n", handle); - return handle; - } - } - /** - * Returns the object pointer for the handle; - * if the object pointer has not been stored by - * handle, returns a null pointer. - */ - O *object_for_handle(CSOUND *csound, int handle) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - if (handle >= objects_for_csound_.size()) { - return nullptr; - } - O *object = objects_for_csound_[handle]; - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::object_for_handle: %p %d (of %ld)\n", object, handle, objects_for_csound_.size()); - return object; - } - /** - * First destroys all objects created by the calling - * instance of Csound, then destroys the list of - * object pointers for this instance of Csound. - */ - void module_destroy(CSOUND *csound) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - for (int i = 0, n = objects_for_csound_.size(); i < n; ++i) { - delete objects_for_csound_[i]; - objects_for_csound_[i] = nullptr; - } - objects_for_csound_.clear(); - objects().erase(csound); - } -}; - -#else -#pragma message("Not defining heap_manager_t.") -#endif - -} diff --git a/6.x/src/fluidOpcodes/fluidOpcodes.cpp b/6.x/src/fluidOpcodes/fluidOpcodes.cpp deleted file mode 100644 index c7bf668b..00000000 --- a/6.x/src/fluidOpcodes/fluidOpcodes.cpp +++ /dev/null @@ -1,748 +0,0 @@ -/** - * FLUID SYNTH OPCODES - * - * Adapts Fluidsynth to use global engines, soundFonts, and outputs - * - * Based on work by Michael Gogins and Steven Yi. License is identical to - * SOUNDFONTS VST License (listed below) - * - * Copyright (c) 2003 by Steven Yi. All rights reserved. - * - * [ORIGINAL INFORMATION BELOW] - * - * S O U N D F O N T S V S T - * - * Adapts Fluidsynth to be both a VST plugin instrument - * and a Csound plugin opcode. - * Copyright (c) 2001-2003 by Michael Gogins. All rights reserved. - * - * L I C E N S E - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include "OpcodeBase.hpp" -#include "csdl.h" -#include -#include - -static std::vector &fluidsynths_for_ids() { - static std::vector fluidsynths_for_ids_; - return fluidsynths_for_ids_; -} - -static void tof(fluid_synth_t *f, MYFLT *a) { - auto &instances = fluidsynths_for_ids(); - instances.push_back(f); - *a = instances.size() - 1; -}; - -static void toa(MYFLT *f, fluid_synth_t *&a) { - auto &instances = fluidsynths_for_ids(); - int index = *f; - a = instances[index]; -}; - -class FluidEngine : public csound::OpcodeBase { - // Outputs. - MYFLT *iFluidSynth; - // Inputs. - MYFLT *iChorusEnabled; - MYFLT *iReverbEnabled; - MYFLT *iChannelCount; - MYFLT *iVoiceCount; - // State. - // fluid_synth_t *fluidSynth; - // fluid_settings_t *fluidSettings; - int32_t chorusEnabled; - int32_t reverbEnabled; - int32_t channelCount; - int32_t voiceCount; - void *mutex; - -public: - int32_t init(CSOUND *csound) { - mutex = csound->Create_Mutex(0); - csound::LockGuard guard(csound, mutex); - int32_t result = OK; - fluid_synth_t *fluidSynth = 0; - fluid_settings_t *fluidSettings = 0; - chorusEnabled = (int32_t)*iChorusEnabled; - reverbEnabled = (int32_t)*iReverbEnabled; - channelCount = (int32_t)*iChannelCount; - voiceCount = (int32_t)*iVoiceCount; - if (channelCount <= 0) { - channelCount = 256; - } else if (channelCount < 16) { - channelCount = 16; - } else if (channelCount > 256) { - channelCount = 256; - } - if (voiceCount <= 0) { - voiceCount = 4096; - } else if (voiceCount < 16) { - voiceCount = 16; - } else if (voiceCount > 4096) { - voiceCount = 4096; - } - fluidSettings = new_fluid_settings(); - if (fluidSettings != NULL) { - fluid_settings_setnum(fluidSettings, (char *)"synth.sample-rate", - (double)csound->GetSr(csound)); - fluid_settings_setint(fluidSettings, (char *)"synth.midi-channels", - channelCount); - fluid_settings_setint(fluidSettings, (char *)"synth.polyphony", - voiceCount); - fluidSynth = new_fluid_synth(fluidSettings); - } - if (!fluidSynth) { - if (fluidSettings) { - delete_fluid_settings(fluidSettings); - } - result = - csound->InitError(csound, "%s", Str("error allocating fluid engine\n")); - } else { -#if (FLUIDSYNTH_VERSION_MAJOR >= 2 && FLUIDSYNTH_VERSION_MINOR >= 2) - // TODO: Change -1 to a configurable FX group? - fluid_synth_chorus_on(fluidSynth, -1, chorusEnabled); - fluid_synth_reverb_on(fluidSynth, -1, reverbEnabled); -#else - fluid_synth_set_chorus_on(fluidSynth, chorusEnabled); - fluid_synth_set_reverb_on(fluidSynth, reverbEnabled); -#endif - log(csound, "Created fluidEngine 0x%p with sampling rate = %f, " - "chorus %s, reverb %s, channels %d, voices %d.\n", - fluidSynth, (double)csound->GetSr(csound), - chorusEnabled ? "on" : "off", reverbEnabled ? "on" : "off", - channelCount, voiceCount); - tof(fluidSynth, iFluidSynth); - { - void *fluid_synths_mutex = 0; - csound::QueryGlobalPointer(csound, "fluid_synths_mutex", - fluid_synths_mutex); - csound::LockGuard synthsGuard(csound, fluid_synths_mutex); - std::vector *fluid_synths = 0; - csound::QueryGlobalPointer(csound, "fluid_synths", fluid_synths); - fluid_synths->push_back(fluidSynth); - } - } - return result; - } -}; - -class FluidLoad : public csound::OpcodeBase { - // Outputs. - MYFLT *iInstrumentNumber; - // Inputs. - MYFLT *iFilename; - MYFLT *iFluidSynth; - MYFLT *iListPresets; - // State. - char *filename; - char *filepath; - fluid_synth_t *fluidSynth; - int32_t soundFontId; - int32_t listPresets; - void *mutex; - -public: - int32_t init(CSOUND *csound) { - mutex = csound->Create_Mutex(0); - csound::LockGuard guard(csound, mutex); - int32_t result = OK; - soundFontId = -1; - toa(iFluidSynth, fluidSynth); - listPresets = (int32_t)*iListPresets; - CS_TYPE *argType = csound->GetTypeForArg(iFilename); - if (strcmp("S", argType->varTypeName) == 0) { - filename = csound->Strdup(csound, ((STRINGDAT *)iFilename)->data); - } else - filename = csound->strarg2name( - csound, (char *)NULL, - (std::isnan(*iFilename) ? csound->GetString(csound, *iFilename) - : (char *)iFilename), - (char *)"fluid.sf2.", std::isnan(*iFilename)); - - filepath = csound->FindInputFile(csound, filename, "SFDIR;SSDIR"); - if (filepath && fluid_is_soundfont(filepath)) { - log(csound, "Loading SoundFont: %s.\n", filepath); - soundFontId = fluid_synth_sfload(fluidSynth, filepath, 0); - log(csound, "fluidSynth: 0x%p soundFontId: %d.\n", fluidSynth, - soundFontId); - } - *iInstrumentNumber = (MYFLT)soundFontId; - if (UNLIKELY(soundFontId < 0)) { - return csound->InitError(csound, Str("fluid: unable to load %s"), - filename); - } - csound->NotifyFileOpened(csound, filepath, CSFTYPE_SOUNDFONT, 0, 0); - if (soundFontId < 0) { - result = NOTOK; - } else if (listPresets) { - fluid_sfont_t *fluidSoundfont = - fluid_synth_get_sfont_by_id(fluidSynth, soundFontId); -#if FLUIDSYNTH_VERSION_MAJOR < 2 - fluid_preset_t fluidPreset; - fluidSoundfont->iteration_start(fluidSoundfont); - OPARMS oparms; - csound->GetOParms(csound, &oparms); - if (oparms.msglevel & 0x7) - while (fluidSoundfont->iteration_next(fluidSoundfont, &fluidPreset)) - { - log(csound, "SoundFont: %3d Bank: %3d Preset: %3d %s\n", - soundFontId, fluidPreset.get_banknum(&fluidPreset), - fluidPreset.get_num(&fluidPreset), - fluidPreset.get_name(&fluidPreset)); -#else - fluid_preset_t *fluidPreset; - fluid_sfont_iteration_start(fluidSoundfont); - OPARMS oparms; - csound->GetOParms(csound, &oparms); - if (oparms.msglevel & 0x7) - while ((fluidPreset = fluid_sfont_iteration_next(fluidSoundfont))) - { - log(csound, "SoundFont: %3d Bank: %3d Preset: %3d %s\n", - soundFontId, fluid_preset_get_banknum(fluidPreset), - fluid_preset_get_num(fluidPreset), - fluid_preset_get_name(fluidPreset)); -#endif - } - } - return result; - } -}; - -#include "arrays.h" - -//Rory Walsh 2018 -class FluidInfo : public csound::OpcodeBase { - // Outputs. - ARRAYDAT *outArr; - // Inputs. - MYFLT *iFluidSynth; - // State. - fluid_synth_t *fluidSynth; - void *mutex; - -public: - int32_t init(CSOUND *csound) { - std::vector programs; - char *program; - mutex = csound->Create_Mutex(0); - csound::LockGuard guard(csound, mutex); - int32_t result = OK; - toa(iFluidSynth, fluidSynth); - fluid_sfont_t *fluidSoundfont = fluid_synth_get_sfont(fluidSynth, 0); -#if FLUIDSYNTH_VERSION_MAJOR < 2 - fluid_preset_t fluidPreset; - fluidSoundfont->iteration_start(fluidSoundfont); - OPARMS oparms; - csound->GetOParms(csound, &oparms); - if (oparms.msglevel & 0x7) - while (fluidSoundfont->iteration_next(fluidSoundfont, &fluidPreset)) - { - std::stringstream ss; - ss << "Bank: " << fluidPreset.get_banknum(&fluidPreset) << - " Preset: " << fluidPreset.get_num(&fluidPreset) << - " Name: " << fluidPreset.get_name(&fluidPreset); -#else - fluid_preset_t *fluidPreset; - fluid_sfont_iteration_start(fluidSoundfont); - OPARMS oparms; - csound->GetOParms(csound, &oparms); - if (oparms.msglevel & 0x7) - while ((fluidPreset = fluid_sfont_iteration_next(fluidSoundfont))) - { - std::stringstream ss; - ss << "Bank: " << fluid_preset_get_banknum(fluidPreset) << - " Preset: " << fluid_preset_get_num(fluidPreset) << - " Name: " << fluid_preset_get_name(fluidPreset); -#endif - programs.push_back(ss.str()); - } - - tabinit(csound, outArr, programs.size()); - STRINGDAT *strings = (STRINGDAT *)outArr->data; - - for (unsigned int i = 0; i < programs.size(); i++) { - program = &programs[i][0u]; - strings[i].size = strlen(program) + 1; - strings[i].data = csound->Strdup(csound, program); - } - - programs.clear(); - - return result; - } -}; - -class FluidProgramSelect : public csound::OpcodeBase -{ - // Inputs. - MYFLT *iFluidSynth; - MYFLT *iChannelNumber; - MYFLT *iInstrumentNumber; - MYFLT *iBankNumber; - MYFLT *iPresetNumber; - // State. - fluid_synth_t *fluidSynth; - int32_t channel; - uint32_t instrument; - uint32_t bank; - uint32_t preset; - void *mutex; -public: - int32_t init(CSOUND *csound) - { - mutex = csound->Create_Mutex(0); - csound::LockGuard guard(csound, mutex); - toa(iFluidSynth, fluidSynth); - channel = (int32_t) *iChannelNumber; - instrument = (uint32_t) *iInstrumentNumber; - bank = (uint32_t) *iBankNumber; - preset = (uint32_t) *iPresetNumber; - fluid_synth_program_select(fluidSynth, - channel, - instrument, - bank, - preset); - return OK; - } -}; - -class FluidCCI : public csound::OpcodeBase { - // Inputs. - MYFLT *iFluidSynth; - MYFLT *iChannelNumber; - MYFLT *iControllerNumber; - MYFLT *kVal; - // State. - fluid_synth_t *fluidSynth; - int32_t channel; - int32_t controller; - int32_t value; - void *mutex; - -public: - int32_t init(CSOUND *csound) { - mutex = csound->Create_Mutex(0); - csound::LockGuard guard(csound, mutex); - toa(iFluidSynth, fluidSynth); - channel = (int32_t)*iChannelNumber; - controller = (int32_t)*iControllerNumber; - value = (int32_t)*kVal; - fluid_synth_cc(fluidSynth, channel, controller, value); - return OK; - } -}; - -class FluidCCK : public csound::OpcodeBase { - // Inputs. - MYFLT *iFluidSynth; - MYFLT *iChannelNumber; - MYFLT *iControllerNumber; - MYFLT *kVal; - // State. - fluid_synth_t *fluidSynth; - int32_t channel; - int32_t controller; - int32_t value; - int32_t priorValue; - void *mutex; - -public: - int32_t init(CSOUND *csound) { - mutex = csound->Create_Mutex(0); - csound::LockGuard guard(csound, mutex); - toa(iFluidSynth, fluidSynth); - priorValue = -1; - return OK; - } - int32_t kontrol(CSOUND *csound) { - csound::LockGuard guard(csound, mutex); - value = (int32_t)*kVal; - if (value != priorValue) { - priorValue = value; - channel = (int32_t)*iChannelNumber; - controller = (int32_t)*iControllerNumber; - fluid_synth_cc(fluidSynth, channel, controller, value); - } - return OK; - } -}; - -class FluidNote : public csound::OpcodeNoteoffBase { - // Inputs. - MYFLT *iFluidSynth; - MYFLT *iChannelNumber; - MYFLT *iMidiKeyNumber; - MYFLT *iVelocity; - // State. - fluid_synth_t *fluidSynth; - int32_t channel; - int32_t key; - int32_t velocity; - void *mutex; - -public: - int32_t init(CSOUND *csound) { - mutex = csound->Create_Mutex(0); - csound::LockGuard guard(csound, mutex); - toa(iFluidSynth, fluidSynth); - channel = (int32_t)*iChannelNumber; - key = (int32_t)*iMidiKeyNumber; - velocity = (int32_t)*iVelocity; - fluid_synth_noteon(fluidSynth, channel, key, velocity); - return OK; - } - int32_t noteoff(CSOUND *csound) { - csound::LockGuard guard(csound, mutex); - fluid_synth_noteoff(fluidSynth, channel, key); - return OK; - } -}; - -class FluidOut : public csound::OpcodeBase { - // Outputs. - MYFLT *aLeftOut; - MYFLT *aRightOut; - // Inputs. - MYFLT *iFluidSynth; - // State. - fluid_synth_t *fluidSynth; - float leftSample; - float rightSample; - int32_t frame; - int32_t ksmps; - void *mutex; - -public: - int32_t init(CSOUND *csound) { - mutex = csound->Create_Mutex(0); - csound::LockGuard guard(csound, mutex); - toa(iFluidSynth, fluidSynth); - ksmps = opds.insdshead->ksmps; - return OK; - } - int32_t audio(CSOUND *csound) { - csound::LockGuard guard(csound, mutex); - uint32_t offset = opds.insdshead->ksmps_offset; - uint32_t early = opds.insdshead->ksmps_no_end; - if (UNLIKELY(offset)) { - memset(aLeftOut, '\0', offset * sizeof(MYFLT)); - memset(aRightOut, '\0', offset * sizeof(MYFLT)); - } - if (UNLIKELY(early)) { - ksmps -= early; - memset(&aLeftOut[ksmps], '\0', early * sizeof(MYFLT)); - memset(&aRightOut[ksmps], '\0', early * sizeof(MYFLT)); - } - for (frame = offset; frame < ksmps; frame++) { - leftSample = 0.0f; - rightSample = 0.0f; - fluid_synth_write_float(fluidSynth, 1, &leftSample, 0, 1, &rightSample, 0, - 1); - aLeftOut[frame] = leftSample /* * csound->e0dbfs */; - aRightOut[frame] = rightSample /* * csound->e0dbfs */; - } - return OK; - } -}; - -class FluidAllOut : public csound::OpcodeBase { - // Outputs. - MYFLT *aLeftOut; - MYFLT *aRightOut; - // State. - float leftSample; - float rightSample; - int32_t frame; - int32_t ksmps; - void *mutex; - -public: - int32_t init(CSOUND *csound) { - mutex = csound->Create_Mutex(0); - csound::LockGuard guard(csound, mutex); - ksmps = opds.insdshead->ksmps; - return OK; - } - int32_t audio(CSOUND *csound) { - csound::LockGuard guard(csound, mutex); - uint32_t offset = opds.insdshead->ksmps_offset; - uint32_t early = opds.insdshead->ksmps_no_end; - if (UNLIKELY(offset)) { - memset(aLeftOut, '\0', offset * sizeof(MYFLT)); - memset(aRightOut, '\0', offset * sizeof(MYFLT)); - } - if (UNLIKELY(early)) { - ksmps -= early; - memset(&aLeftOut[ksmps], '\0', early * sizeof(MYFLT)); - memset(&aRightOut[ksmps], '\0', early * sizeof(MYFLT)); - } - std::vector *fluid_synths = 0; - csound::QueryGlobalPointer(csound, "fluid_synths", fluid_synths); - void *fluid_synths_mutex = 0; - csound::QueryGlobalPointer(csound, "fluid_synths_mutex", - fluid_synths_mutex); - csound::LockGuard synthsGuard(csound, fluid_synths_mutex); - for (frame = offset; frame < ksmps; frame++) { - aLeftOut[frame] = FL(0.0); - aRightOut[frame] = FL(0.0); - for (size_t i = 0, n = fluid_synths->size(); i < n; i++) { - fluid_synth_t *fluidSynth = (*fluid_synths)[i]; - leftSample = FL(0.0); - rightSample = FL(0.0); - fluid_synth_write_float(fluidSynth, 1, &leftSample, 0, 1, &rightSample, - 0, 1); - aLeftOut[frame] += (MYFLT)leftSample /* * csound->e0dbfs */; - aRightOut[frame] += (MYFLT)rightSample /* * csound->e0dbfs */; - } - } - return OK; - } -}; - -class FluidControl : public csound::OpcodeBase { - // Inputs. - MYFLT *iFluidSynth; - MYFLT *kMidiStatus; - MYFLT *kMidiChannel; - MYFLT *kMidiData1; - MYFLT *kMidiData2; - MYFLT *imsgs; - // State. - fluid_synth_t *fluidSynth; - int32_t midiStatus; - int32_t midiChannel; - int32_t midiData1; - int32_t midiData2; - int32_t priorMidiStatus; - int32_t priorMidiChannel; - int32_t priorMidiData1; - int32_t priorMidiData2; - int32_t printMsgs; - void *mutex; - -public: - int32_t init(CSOUND *csound) { - mutex = csound->Create_Mutex(0); - csound::LockGuard guard(csound, mutex); - toa(iFluidSynth, fluidSynth); - priorMidiStatus = -1; - priorMidiChannel = -1; - priorMidiData1 = -1; - priorMidiData2 = -1; - OPARMS oparms; - csound->GetOParms(csound, &oparms); - printMsgs = (*imsgs == 0 ? 0 : 1); - return OK; - } - int32_t kontrol(CSOUND *csound) { - csound::LockGuard guard(csound, mutex); - midiStatus = 0xF0 & (int32_t)*kMidiStatus; - midiChannel = (int32_t)*kMidiChannel; - midiData1 = (int32_t)*kMidiData1; - midiData2 = (int32_t)*kMidiData2; - int32_t result = -1; - - if (midiData2 != priorMidiData2 || midiData1 != priorMidiData1 || - midiChannel != priorMidiChannel || midiStatus != priorMidiStatus) { - switch (midiStatus) { - case (int32_t)0x80: - noteOff: - result = fluid_synth_noteoff(fluidSynth, midiChannel, midiData1); - if (printMsgs) - csound->Message(csound, Str("result: %d\n Note off: c:%3d k:%3d\n"), - result, midiChannel, midiData1); - break; - case (int32_t)0x90: - if (!midiData2) { - goto noteOff; - } - result = - fluid_synth_noteon(fluidSynth, midiChannel, midiData1, midiData2); - if (printMsgs) - log(csound, "result: %d\nNote on: c:%3d k:%3d v:%3d\n", result, - midiChannel, midiData1, midiData2); - break; - case (int32_t)0xA0: - if (printMsgs) - log(csound, "Key pressure (not handled): " - "c:%3d k:%3d v:%3d\n", - midiChannel, midiData1, midiData2); - break; - case (int32_t)0xB0: - result = fluid_synth_cc(fluidSynth, midiChannel, midiData1, midiData2); - if (printMsgs) - log(csound, "Result: %d Control change: c:%3d c:%3d v:%3d\n", result, - midiChannel, midiData1, midiData2); - break; - case (int32_t)0xC0: - result = fluid_synth_program_change(fluidSynth, midiChannel, midiData1); - if (printMsgs) - log(csound, "Result: %d Program change: c:%3d p:%3d\n", result, - midiChannel, midiData1); - break; - case (int32_t)0xD0: - if (printMsgs) - log(csound, "After touch (not handled): c:%3d v:%3d\n", midiChannel, - midiData1); - break; - case (int32_t)0xE0: { - int32_t pbVal = midiData1 + (midiData2 << 7); - fluid_synth_pitch_bend(fluidSynth, midiChannel, pbVal); - if (printMsgs) - log(csound, "Result: %d, Pitch bend: c:%d b:%d\n", result, - midiChannel, pbVal); - } break; - case (int32_t)0xF0: - if (printMsgs) - log(csound, "System exclusive (not handled): " - "c:%3d v1:%3d v2:%3d\n", - midiChannel, midiData1, midiData2); - break; - } - priorMidiStatus = midiStatus; - priorMidiChannel = midiChannel; - priorMidiData1 = midiData1; - priorMidiData2 = midiData2; - } - return OK; - } -}; - -class FluidSetInterpMethod : public csound::OpcodeBase { - // Inputs. - MYFLT *iFluidSynth; - MYFLT *iChannelNumber; - MYFLT *iInterpMethod; - // State. - fluid_synth_t *fluidSynth; - int32_t channel; - int32_t interpolationMethod; - void *mutex; - -public: - int32_t init(CSOUND *csound) { - mutex = csound->Create_Mutex(0); - csound::LockGuard guard(csound, mutex); - toa(iFluidSynth, fluidSynth); - channel = (int32_t)*iChannelNumber; - interpolationMethod = (int32_t)*iInterpMethod; - if (UNLIKELY(interpolationMethod != 0 && interpolationMethod != 1 && - interpolationMethod != 4 && interpolationMethod != 7)) { - return csound->InitError(csound, "%s", - Str("Illegal Interpolation Method: Must be " - "either 0, 1, 4, or 7.\n")); - } else { - fluid_synth_set_interp_method(fluidSynth, channel, interpolationMethod); - } - return OK; - } -}; - -static OENTRY localops[] = { - {(char *)"fluidEngine", sizeof(FluidEngine), 0, 1, (char *)"i", - (char *)"ppoo", (SUBR)&FluidEngine::init_, (SUBR)0, (SUBR)0}, - {(char *)"fluidLoad", sizeof(FluidLoad), 0, 1, (char *)"i", (char *)"Tio", - (SUBR)&FluidLoad::init_, (SUBR)0, (SUBR)0}, - {(char *)"fluidInfo", sizeof(FluidInfo), 0, 1, (char *)"S[]", (char *)"i", - (SUBR)&FluidInfo::init_, (SUBR)0, (SUBR)0}, - {(char *)"fluidProgramSelect", sizeof(FluidProgramSelect), 0, 1, (char *)"", - (char *)"iiiii", (SUBR)&FluidProgramSelect::init_, (SUBR)0, (SUBR)0}, - {(char *)"fluidCCi", sizeof(FluidCCI), 0, 1, (char *)"", (char *)"iiii", - (SUBR)&FluidCCI::init_, (SUBR)0, (SUBR)0}, - {(char *)"fluidCCk", sizeof(FluidCCK), 0, 3, (char *)"", (char *)"ikkk", - (SUBR)&FluidCCK::init_, (SUBR)&FluidCCK::kontrol_, (SUBR)0}, - {(char *)"fluidNote", sizeof(FluidNote), 0, 3, (char *)"", (char *)"iiii", - (SUBR)&FluidNote::init_, (SUBR)&FluidNote::kontrol_, (SUBR)0}, - {(char *)"fluidOut", sizeof(FluidOut), 0, 3, (char *)"aa", (char *)"i", - (SUBR)&FluidOut::init_, (SUBR)&FluidOut::audio_}, - {(char *)"fluidAllOut", sizeof(FluidAllOut), 0, 3, (char *)"aa", (char *)"", - (SUBR)&FluidAllOut::init_, (SUBR)&FluidAllOut::audio_}, - {(char *)"fluidControl", sizeof(FluidControl), 0, 3, (char *)"", - (char *)"ikkkkp", (SUBR)FluidControl::init_, (SUBR)FluidControl::kontrol_, - (SUBR)0}, - {(char *)"fluidSetInterpMethod", sizeof(FluidSetInterpMethod), 0, 1, - (char *)"", (char *)"iii", (SUBR)&FluidSetInterpMethod::init_, (SUBR)0, - (SUBR)0}, - {0, 0, 0, 0, 0, 0, (SUBR)0, (SUBR)0, (SUBR)0}}; - -PUBLIC int32_t csoundModuleCreate(CSOUND *csound) { - std::vector *fluid_synths = - new std::vector(); - int32_t result = 0; - result = csound::CreateGlobalPointer(csound, "fluid_synths", fluid_synths); - void *fluid_synths_mutex = csound->Create_Mutex(0); - result = csound::CreateGlobalPointer(csound, "fluid_synths_mutex", - fluid_synths_mutex); - return result; -} - -PUBLIC int32_t csoundModuleInit(CSOUND *csound) { - // printf("csoundModuleInit: %p\n", csound); - OENTRY *ep; - int32_t err = 0; - - for (ep = (OENTRY *)&(localops[0]); ep->opname != NULL; ep++) { - err |= csound->AppendOpcode(csound, ep->opname, ep->dsblksiz, ep->flags, - ep->thread, ep->outypes, ep->intypes, - (int32_t (*)(CSOUND *, void *))ep->iopadr, - (int32_t (*)(CSOUND *, void *))ep->kopadr, - (int32_t (*)(CSOUND *, void *))ep->aopadr); - } - return err; -} - -/** - * Called by Csound to de-initialize the opcode - * just before destroying it. - */ -PUBLIC int32_t csoundModuleDestroy(CSOUND *csound) { - // printf("csoundModuleDestroy: %p\n", csound); - void *fluid_synths_mutex = 0; - csound::QueryGlobalPointer(csound, "fluid_synths_mutex", fluid_synths_mutex); - if (fluid_synths_mutex) { - std::vector *fluid_synths = 0; - csound::QueryGlobalPointer(csound, "fluid_synths", fluid_synths); - csound->LockMutex(fluid_synths_mutex); - if (fluid_synths) { - for (size_t i = 0, n = fluid_synths->size(); i < n; i++) { - fluid_synth_t *fluidSynth = (*fluid_synths)[i]; - // printf("deleting engine: %p\n", fluidSynth); - fluid_settings_t *fluidSettings = fluid_synth_get_settings(fluidSynth); - delete_fluid_synth(fluidSynth); - delete_fluid_settings(fluidSettings); - } - fluid_synths->clear(); - delete fluid_synths; - fluid_synths = 0; - } - csound->UnlockMutex(fluid_synths_mutex); - csound->DestroyMutex(fluid_synths_mutex); - fluid_synths_mutex = 0; - } - return 0; -} - -PUBLIC int32_t csoundModuleInfo(void) { - return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int32_t)sizeof(MYFLT)); -} diff --git a/6.x/src/fluidOpcodes/fluidOpcodes.h b/6.x/src/fluidOpcodes/fluidOpcodes.h deleted file mode 100644 index 4441ded0..00000000 --- a/6.x/src/fluidOpcodes/fluidOpcodes.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * FLUID SYNTH OPCODES - * - * Adapts Fluidsynth to use global engines, soundFonts, and outputs - * - * Based on work by Michael Gogins. License is identical to - * SOUNDFONTS VST License (listed below) - * - * Copyright (c) 2003 by Steven Yi. All rights reserved. - * - * [ORIGINAL INFORMATION BELOW] - * - * S O U N D F O N T S V S T - * - * Adapts Fluidsynth to be both a VST plugin instrument - * and a Csound plugin opcode. - * Copyright (c) 2001-2003 by Michael Gogins. All rights reserved. - * - * L I C E N S E - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef FLUIDOPCODE_H -#define FLUIDOPCODE_H - -#include "csdl.h" -#include - -typedef struct { - OPDS h; - /* OUTPUTS */ - MYFLT *iEngineNum; - MYFLT *iReverbEnabled; - MYFLT *iChorusEnabled; - MYFLT *iNumChannels; - MYFLT *iPolyphony; -} FLUIDENGINE; - -typedef struct { - OPDS h; - /* INPUTS */ - MYFLT *iEngineNumber, *iChannelNumber, *iInterpMethod; -} FLUID_SET_INTERP_METHOD; - -typedef struct { - OPDS h; - /* OUTPUTS */ - MYFLT *iInstrumentNumber; - /* INPUTS */ - MYFLT *filename, *iEngineNum, *iListPresets; -} FLUIDLOAD; - -typedef struct { - OPDS h; - /* INPUTS */ - MYFLT *iEngineNumber, *iChannelNumber, *iInstrumentNumber, *iBankNumber; - MYFLT *iPresetNumber; -} FLUID_PROGRAM_SELECT; - -typedef struct { - OPDS h; - /* INPUTS */ - MYFLT *iEngineNumber, *iChannelNumber, *iControllerNumber, *kVal; - int32_t priorMidiValue; - fluid_synth_t *fluidEngine; -} FLUID_CC; - -typedef struct { - OPDS h; - /* INPUTS */ - MYFLT *iEngineNumber, *iChannelNumber, *iMidiKeyNumber, *iVelocity; - int32_t initDone, iChn, iKey; - fluid_synth_t *fluidEngine; -} FLUID_NOTE; - -typedef struct { - OPDS h; - MYFLT *aLeftOut, *aRightOut; - MYFLT *iEngineNum; - fluid_synth_t *fluidEngine; -} FLUIDOUT; - -typedef struct { - OPDS h; - MYFLT *aLeftOut, *aRightOut; - void *fluidGlobals; -} FLUIDALLOUT; - -typedef struct { - OPDS h; - /* Inputs. */ - MYFLT *iFluidEngine; - MYFLT *kMidiStatus; - MYFLT *kMidiChannel; - MYFLT *kMidiData1; - MYFLT *kMidiData2; - /* No outputs. */ - /* Internal state. */ - int32_t priorMidiStatus; - int32_t priorMidiChannel; - int32_t priorMidiData1; - int32_t priorMidiData2; - fluid_synth_t *fluidEngine; -} FLUIDCONTROL; - -#endif - diff --git a/6.x/src/fluidOpcodes/fluidOpcodes.html b/6.x/src/fluidOpcodes/fluidOpcodes.html deleted file mode 100644 index 72d3db4e..00000000 --- a/6.x/src/fluidOpcodes/fluidOpcodes.html +++ /dev/null @@ -1,80 +0,0 @@ - - -fluidOpcodes - - - -

fluidOpcodes

-
fluidEngine - creates a fluid engine
- fluidLoad - loads a soundfont into a fluid engine
- fluidProgramSelect - assign a bank and preset of a soundFont to a midi channel - as well as select
- fluidCC - send midi controller data to fluid
- fluidPlay - plays a note on a channel
- fluidOut - outputs sound from a fluid engine
-
-

Description

-

This family of opcodes are meant to be used together to load and play SoundFonts - using Peter Hannape's Fluidsynth. Use global engines, soundFonts, and outputs.
-
- Based on work by Michael Gogins.

- -
-
-

Syntax

-

iEngineNumber fluidEngine
-
- iInstrumentNumber fluidLoad sfilename, iEngineNumber
-
- fluidProgramSelect iEngineNumber, iChannelNumber, iInstrumentNumber, - iBankNumber, iPresetNumber
-
- fluidCC iEngineNumber, iChannelNumber, iControllerNumber, - kValue
-
- fluidNote iEngineNumber, iInstrumentNumber, iMidiKeyNumber, - iVelocity
-
- aLeft, aRight fluidOut iEngineNum

-

 

-
-

Initialization

-

iEngineNumber - engine number assigned from fluid_engine
-
- iInstrumentNumber - instrument number assigned from fluid_load
-
- sfilename - String specifying a SoundFont filename
-
- aLeft - left channel audio output.

-

aRight - right channel audio output.
-
- iMidiKeyNumber - midi key number to play (0-127)
-
- iVelocity - midi velocity to play at (0-127)
-
- iBankNum - bank number on soundfont to play
-
- iPresetNum - preset number on soundfont to play
-
- iprogram - Number of the fluidsynth program to be assigned to a MIDI channel.

-
-

Performance

-

In this implementation, SoundFont effects such as chorus or reverb are used - if and only if they are defaults for the preset. There is no means of turning - such effects on or off, or of changing their parameters, from Csound.

- -

 

-
-

Examples

-
-

 

-
-
-
-

Credits

-

Opcode library created by Steven Yi, based on fluid opcode - plugin by Michael Gogins.

-

 

-
- - diff --git a/6.x/src/fluidOpcodes/test.csd b/6.x/src/fluidOpcodes/test.csd deleted file mode 100644 index f6f8fd05..00000000 --- a/6.x/src/fluidOpcodes/test.csd +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - -sr=44100 -kr=441 -ksmps=100 -nchnls=2 - -giFluidEngine fluid_engine - -giSF_piano fluid_load "sf2/Piano Grand Steinway V1.0b (29,651KB).SF2", giFluidEngine -giSF_mutedViolin fluid_load "sf2/MutedViolin.sf2", giFluidEngine - -fluid_program_select giFluidEngine, 0, giSF_piano, 0, 0 -fluid_program_select giFluidEngine, 1, giSF_mutedViolin, 0, 0 - - instr 1 ;untitled - - fluid_play giFluidEngine, 0, p4, p5 - - endin - - instr 2 - - fluid_play giFluidEngine, 1, p4, p5 - - endin - - instr 10 ; fluid out instrument - -aleft, aright fluid_out giFluidEngine - - outs aleft * 0dbfs, aright * 0dbfs - endin - - - - - -i1 0 2 60 110 -i1 0 2 64 110 -i1 0 2 67 110 - -i2 0 1 72 110 -i2 0 1 76 70 -i2 0 1 79 80 - -i10 0 6 - -e - - - - diff --git a/6.x/src/hdf5/CMakeLists.txt b/6.x/src/hdf5/CMakeLists.txt deleted file mode 100644 index 7ea0f1a9..00000000 --- a/6.x/src/hdf5/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -option(BUILD_HDF5_OPCODES "Build the hdf5 read/write opcodes" ON) - -find_package(HDF5) -check_deps(BUILD_HDF5_OPCODES HDF5_FOUND) - -if(BUILD_HDF5_OPCODES AND HDF5_FOUND) - # split version string, as cmake doesn't do this automatically - string(REPLACE "." ";" VERSION_LIST ${HDF5_VERSION}) - list(GET VERSION_LIST 0 HDF5_VERSION_MAJOR) - list(GET VERSION_LIST 1 HDF5_VERSION_MINOR) - list(GET VERSION_LIST 2 HDF5_VERSION_PATCH) - - make_plugin(hdf5ops HDF5IO.c) - - target_compile_definitions(hdf5ops PRIVATE - -DHDF5_VERSION_MAJOR=${HDF5_VERSION_MAJOR} - -DHDF5_VERSION_MINOR=${HDF5_VERSION_MINOR} - -DHDF5_VERSION_PATCH=${HDF5_VERSION_PATCH} - ) - - if(USE_VCPKG) - target_include_directories(hdf5ops PRIVATE ${HDF5_INCLUDE_DIRS} ${CSOUND_INCLUDE_DIRS}) - target_link_libraries(hdf5ops PRIVATE hdf5::hdf5-static hdf5::hdf5_hl-static) - else() - message(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}") - message(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}") - - target_include_directories(hdf5ops PRIVATE ${HDF5_INCLUDE_DIRS} ${CSOUND_INCLUDE_DIRS}) - target_link_libraries(hdf5ops ${HDF5_LIBRARIES}) - endif() -endif() diff --git a/6.x/src/hdf5/HDF5IO.c b/6.x/src/hdf5/HDF5IO.c deleted file mode 100644 index 8d45ef5f..00000000 --- a/6.x/src/hdf5/HDF5IO.c +++ /dev/null @@ -1,1404 +0,0 @@ -/* - * Copyright (C) 2014 Edward Costello - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "HDF5IO.h" -#include -#ifdef _MSC_VER -#include -#else -#include -#endif - -#define HDF5ERROR(x) if (UNLIKELY((x) == -1)) \ - {csound->Die(csound, #x" error\nExiting\n");} - -// Type strings to match the enum types -static const char typeStrings[8][12] = { - "STRING_VAR", - "ARATE_VAR", - "KRATE_VAR", - "IRATE_VAR", - "ARATE_ARRAY", - "KRATE_ARRAY", - "IRATE_ARRAY", - "UNKNOWN" -}; - -// Get the argument enum type from the opcode argument pointer -// -// Get the csound type from the argument -// Get the variable type name -// Do a string comparison and match the type to the enum type - -ArgumentType HDF5IO_getArgumentTypeFromArgument(CSOUND *csound, MYFLT *argument) -{ - const CS_TYPE *csoundType = csound->GetTypeForArg((void *)argument); - const char *type = csoundType->varTypeName; - ArgumentType argumentType = UNKNOWN; - - if (strcmp("S", type) == 0) { - - argumentType = STRING_VAR; - } - else if (strcmp("a", type) == 0) { - - argumentType = ARATE_VAR; - } - else if (strcmp("k", type) == 0) { - - argumentType = KRATE_VAR; - } - else if (strcmp("i", type) == 0) { - - argumentType = IRATE_VAR; - } - else if (strcmp("[", type) == 0) { - - ARRAYDAT *array = (ARRAYDAT *)argument; - - if (strcmp("k", array->arrayType->varTypeName) == 0) { - - argumentType = KRATE_ARRAY; - } - else if (strcmp("a", array->arrayType->varTypeName) == 0) { - - argumentType = ARATE_ARRAY; - } - else if (strcmp("i", array->arrayType->varTypeName) == 0) { - - argumentType = IRATE_ARRAY; - } - } - - return argumentType; -} - -// Get the matching argument enum type from a string -// -// Do a string comparison and assign the corresponding enum type to the string - -ArgumentType HDF5IO_getArgumentTypeFromString(CSOUND *csound, const char *string) -{ - IGN(csound); - ArgumentType type = UNKNOWN; - - if (strcmp("STRING_VAR", string) == 0) { - - type = STRING_VAR; - } - else if (strcmp("ARATE_VAR", string) == 0) { - - type = ARATE_VAR; - } - else if (strcmp("KRATE_VAR", string) == 0) { - - type = KRATE_VAR; - } - else if (strcmp("IRATE_VAR", string) == 0) { - - type = IRATE_VAR; - } - else if (strcmp("ARATE_ARRAY", string) == 0) { - - type = ARATE_ARRAY; - } - else if (strcmp("KRATE_ARRAY", string) == 0) { - - type = KRATE_ARRAY; - } - else if (strcmp("IRATE_ARRAY", string) == 0) { - - type = IRATE_ARRAY; - } - - return type; -} - -// Create or open a hdf5 file -// -// Allocate the memory for a hdf5 file struct -// Assign the path string to the file name in the struct -// Check if the file exists -// If it doesn't and this function is being called by the hdf5 write function, -// create the file -// If it exists, open the file for appending -// Find out what size the MYFLT floating point type is and assign the correct -// hdf5 type to it -// Return the pointer to the hdf5 file struct - -HDF5File *HDF5IO_newHDF5File(CSOUND *csound, AUXCH *hdf5FileMemory, - STRINGDAT *path, bool openForWriting) -{ - csound->AuxAlloc(csound, sizeof(HDF5File), hdf5FileMemory); - HDF5File *hdf5File = hdf5FileMemory->auxp; - - hdf5File->fileName = path->data; - - int32_t fileExists = access(hdf5File->fileName, 0); - - if (UNLIKELY(fileExists == -1)) { - - if (LIKELY(openForWriting == true)) { - - hdf5File->fileHandle = H5Fcreate(hdf5File->fileName, H5F_ACC_TRUNC, - H5P_DEFAULT, H5P_DEFAULT); - HDF5ERROR(hdf5File->fileHandle); - } - else { - - csound->Die(csound, "hdf5read: Error, file does not exist"); - } - } - else { - - hdf5File->fileHandle = H5Fopen(hdf5File->fileName, H5F_ACC_RDWR, H5P_DEFAULT); - HDF5ERROR(hdf5File->fileHandle); - } - -#ifdef USE_DOUBLE - hdf5File->floatSize = H5T_NATIVE_DOUBLE; -#else - hdf5File->floatSize = H5T_NATIVE_FLOAT; -#endif - //else { - - //csound->Die(csound,"HDF5IO: Illegal size for floating point type, exiting"); - //} - - return hdf5File; -} - -// Write a string attribute to a hdf5 file dataset -// -// Create a new attribute of type C string -// Set the size of the string to 11 characters, this is the longest string -// length of the argument type strings -// Set the string to be null terminated -// Create the attribute in the hdf5 file -// Write the string to the attribute -// Close the open handles - -void HDF5IO_writeStringAttribute(CSOUND *csound, HDF5File *self, - HDF5Dataset *dataset, - const char *attributeName, - const char *attributeString) -{ - IGN(self); - hid_t attributeID = H5Screate(H5S_SCALAR); - HDF5ERROR(attributeID); - hid_t attributeType = H5Tcopy(H5T_C_S1); - HDF5ERROR(attributeType); - HDF5ERROR(H5Tset_size(attributeType, 11)); - HDF5ERROR(H5Tset_strpad(attributeType,H5T_STR_NULLTERM)); - hid_t attributeHandle = H5Acreate2(dataset->datasetID, - attributeName, attributeType, attributeID, - H5P_DEFAULT, H5P_DEFAULT); - HDF5ERROR(attributeHandle); - HDF5ERROR(H5Awrite(attributeHandle, attributeType, attributeString)); - HDF5ERROR(H5Sclose(attributeID)); - HDF5ERROR(H5Tclose(attributeType)); - HDF5ERROR(H5Aclose(attributeHandle)); -} - -// Read a string attribute from the hdf5 file -// -// Open the data set and get the info structure -// Get the attribute at index 0, this should probably be more general, needs -// more work -// Get the type of the attribute -// Read the attribute into memory and close all the handles - -void HDF5IO_readStringAttribute(CSOUND *csound, HDF5File *self, - char *datasetName, char *attributeString) -{ - hid_t dataSetID = H5Dopen2(self->fileHandle, datasetName, H5P_DEFAULT); - H5O_info_t oinfo; -#if HDF5_VERSION_MAJOR == 1 && HDF5_VERSION_MINOR >= 12 - HDF5ERROR(H5Oget_info1(dataSetID, &oinfo)); -#else - HDF5ERROR(H5Oget_info(dataSetID, &oinfo)); -#endif - hid_t attributeID = H5Aopen_by_idx(dataSetID, ".", H5_INDEX_CRT_ORDER, - H5_ITER_INC, 0, H5P_DEFAULT, H5P_DEFAULT); - HDF5ERROR(attributeID); - hid_t attributeType = H5Aget_type(attributeID); - HDF5ERROR(attributeType); - hid_t attributeTypeMemory = H5Tget_native_type(attributeType, H5T_DIR_ASCEND); - HDF5ERROR(attributeTypeMemory); - HDF5ERROR(H5Aread(attributeID, attributeTypeMemory, attributeString)); - HDF5ERROR(H5Aclose(attributeID)); - HDF5ERROR(H5Tclose(attributeType)); - HDF5ERROR(H5Tclose(attributeTypeMemory)); - HDF5ERROR(H5Dclose(dataSetID)); -} - -// Find if csound is running in sample accurate mode -// -// Get the argument parameters passed to run csound -// Find the sample accurate parameter and return it - -bool HDF5IO_getSampleAccurate(CSOUND *csound) -{ - OPARMS parameters = {0}; - csound->GetOParms(csound, ¶meters); - return parameters.sampleAccurate; -} - - -// Set everything up so datasets can be written from the opcodes input variables, -// i-rate datasets are written at initialisation all others are written on the -// performance pass. -// -// Get the amount of samples in a control pass -// Get the amount of arguments to the opcode, this doesn't include the first -// argument which is for the filename. -// Check that the first argument is a string for the filename, check others -// are not strings -// Register the callback to close the hdf5 file when performance finishes -// Get the path argument and open a hdf5 file, if it doesn't exist create it -// Create the datasets in the file so they can be written - -int32_t HDF5Write_initialise(CSOUND *csound, HDF5Write *self) -{ - self->ksmps = csound->GetKsmps(csound); - self->inputArgumentCount = self->INOCOUNT - 1; - HDF5Write_checkArgumentSanity(csound, self); - csound->RegisterDeinitCallback(csound, self, HDF5Write_finish); - - STRINGDAT *path = (STRINGDAT *)self->arguments[0]; - self->hdf5File = HDF5IO_newHDF5File(csound, &self->hdf5FileMemory, path, true); - HDF5Write_createDatasets(csound, self); - - return OK; -} - -// Write the input data to the associated dataset -// -// Enlarge the dataset first then get the file space -// Select a hyperslab with the necessary offset and size -// Create a memory space where the data is written to -// Write the data to the memory space -// Close the file space - -void HDF5Write_writeData(CSOUND *csound, HDF5Write *self, - HDF5Dataset *dataset, MYFLT *data) -{ - HDF5ERROR(H5Dset_extent(dataset->datasetID, dataset->datasetSize)); - hid_t filespace = H5Dget_space(dataset->datasetID); - HDF5ERROR(filespace); - HDF5ERROR(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, dataset->offset, - NULL, dataset->chunkDimensions, NULL)); - hid_t memspace = H5Screate_simple(dataset->rank, dataset->chunkDimensions, - NULL); - HDF5ERROR(memspace); - HDF5ERROR(H5Dwrite(dataset->datasetID, self->hdf5File->floatSize, memspace, - filespace, H5P_DEFAULT, data)); - HDF5ERROR(H5Sclose(filespace)); -} - -// Write a-rate variables and arrays to the specified data set -// -// For sample accurate mode, get the offset and early variables -// Calculate the size of the incoming vector -// If the vector is 0 return, no more data to write -// Expand the dataset size by ksmps, because data is written in chunks -// For sample accurate mode the exact dataset size is set when writing is finished -// Write the data to the dataset -// Increment the offset by the size of the vector that was just written - -void HDF5Write_writeAudioData(CSOUND *csound, HDF5Write *self, - HDF5Dataset *dataset, MYFLT *dataPointer) -{ - size_t offset = self->h.insdshead->ksmps_offset; - size_t early = self->h.insdshead->ksmps_no_end; - - int32_t vectorSize = (int32_t)(self->ksmps - offset - early); - - if (UNLIKELY(vectorSize == 0)) { - return; - } - - dataset->datasetSize[0] += self->ksmps; - - HDF5Write_writeData(csound, self, dataset, &dataPointer[offset]); - - dataset->offset[0] += vectorSize; -} - -// Write k-rate variables and arrays to the specified data set -// -// Increment the data set size by 1 -// Write the data to the dataset -// Increment the offset by 1 - -void HDF5Write_writeControlData(CSOUND *csound, HDF5Write *self, - HDF5Dataset *dataset, MYFLT *dataPointer) -{ - dataset->datasetSize[0]++; - - HDF5Write_writeData(csound, self, dataset, dataPointer); - - dataset->offset[0]++; -} - -// Send each input argument to the necessary writing function -// -// Iterate through the dataset array, select the current -// Depending on the dataset type send to the necessary write function - -int32_t HDF5Write_process(CSOUND *csound, HDF5Write *self) -{ - int32_t i; - for (i = 0; i < self->inputArgumentCount; ++i) { - - HDF5Dataset *currentDataset = &self->datasets[i]; - - switch (currentDataset->writeType) { - - case ARATE_ARRAY: { - - HDF5Write_writeAudioData(csound, self, currentDataset, - ((ARRAYDAT *)currentDataset->argumentPointer)->data); - break; - } - case KRATE_ARRAY: { - - HDF5Write_writeControlData(csound, self, currentDataset, - ((ARRAYDAT *)currentDataset->argumentPointer)->data); - break; - } - case ARATE_VAR: { - - HDF5Write_writeAudioData(csound, self, currentDataset, - currentDataset->argumentPointer); - break; - } - case KRATE_VAR: { - - HDF5Write_writeControlData(csound, self, currentDataset, - currentDataset->argumentPointer); - break; - } - default: { - - break; - } - } - } - return OK; -} - -// Close the hdf5 file and set the a-rate dataset extents for sample accurate mode -// -// Check that the datasets exist -// Iterate through the datasets, if a-rate, set the size to be the same as -// current offset -// Set the set extent of the dataset to the size -// Close the datasets, then close the file - -int32_t HDF5Write_finish(CSOUND *csound, void *inReference) -{ - HDF5Write *self = inReference; - - if (LIKELY(self->datasets != NULL)) { - int32_t i; - for (i = 0; i < self->inputArgumentCount; ++i) { - - HDF5Dataset *dataset = &self->datasets[i]; - - switch (dataset->writeType) { - - case ARATE_ARRAY: { - - dataset->datasetSize[0] = - dataset->offset[0]; - HDF5ERROR(H5Dset_extent(dataset->datasetID, dataset->datasetSize)); - break; - } - case ARATE_VAR: { - - dataset->datasetSize[0] = - dataset->offset[0]; - HDF5ERROR(H5Dset_extent(dataset->datasetID, dataset->datasetSize)); - break; - } - default: { - - break; - } - } - - HDF5ERROR(H5Dclose(dataset->datasetID)); - } - } - - HDF5ERROR(H5Fclose(self->hdf5File->fileHandle)); - - return OK; -} - -// Check that the correct types of inputs have been used in the opcode -// -// Get the argument type for the first input -// If it is not a string stop csound -// Iterate over the rest of the input arguments, if any are strings stop csound - -void HDF5Write_checkArgumentSanity(CSOUND *csound, const HDF5Write *self) -{ - int32_t i; - ArgumentType type = HDF5IO_getArgumentTypeFromArgument(csound, - self->arguments[0]); - - if (UNLIKELY(type != STRING_VAR)) { - - csound->Die(csound, "%s", Str("hdf5write: Error, first argument does not " - "appear to be a string, exiting")); - } - - for (i = 0; i < self->inputArgumentCount; ++i) { - - type = HDF5IO_getArgumentTypeFromArgument(csound, self->arguments[i + 1]); - - if (UNLIKELY(type == STRING_VAR - || - type == UNKNOWN)) { - - csound->Die(csound, Str("hdf5write: Error, unable to identify type " - "of argument %d"), i); - } - } -} - -// Create, or delete and create again a dataset in an hdf5 file -// -// Check to see if the dataset exists -// If it exists delete it -// Create the data space, set the writing chunk size and the empty space fill value -// Create the data set in the data space and write the argument type as a string -// attribute - -void HDF5Write_initialiseHDF5Dataset(CSOUND *csound, HDF5Write *self, - HDF5Dataset *dataset) -{ - htri_t result = H5Lexists(self->hdf5File->fileHandle, - dataset->datasetName, H5P_DEFAULT); - - if (result == 1) { - - HDF5ERROR(H5Ldelete(self->hdf5File->fileHandle, - dataset->datasetName, H5P_DEFAULT)); - } - - hid_t dataspaceID = H5Screate_simple(dataset->rank, dataset->chunkDimensions, - dataset->maxDimensions); - HDF5ERROR(dataspaceID); - hid_t cparams = H5Pcreate(H5P_DATASET_CREATE); - HDF5ERROR(cparams); - - HDF5ERROR(H5Pset_chunk(cparams, dataset->rank, dataset->chunkDimensions)); - - MYFLT zero = 0; - - HDF5ERROR(H5Pset_fill_value(cparams, self->hdf5File->floatSize, &zero)); - - dataset->datasetID = H5Dcreate2(self->hdf5File->fileHandle, - dataset->datasetName, - self->hdf5File->floatSize, - dataspaceID, H5P_DEFAULT, cparams, H5P_DEFAULT); - HDF5ERROR(dataset->datasetID); - HDF5IO_writeStringAttribute(csound, self->hdf5File, dataset, - "Variable Type", typeStrings[dataset->writeType]); - -} - -// Set up the variables for writing an array dataset -// -// Get the array from the argument pointer -// If its an i-rate array the rank is copied, if not we add a dimension -// Allocate arrays for the chunk sizes, maximum sizes, data set sizes and -// offset sizes -// Copy the sizes from the input array variables to the allocated size arrays -// If it's an a-rate array set the last chunk dimension to ksmps, last max -// dimension to unlimited and dataset size to 0 -// If it's a k-rate array set the last chunk dimension to 1 and last max -// dimension to unlimited -// If it's an i-rate array just return - -void HDF5Write_newArrayDataset(CSOUND *csound, HDF5Write *self, - HDF5Dataset *dataset) -{ - ARRAYDAT *array = (ARRAYDAT *)dataset->argumentPointer; - int32_t i; - if (dataset->writeType == IRATE_ARRAY) { - - dataset->rank = array->dimensions; - } - else { - - dataset->rank = array->dimensions + 1; - } - - csound->AuxAlloc(csound, dataset->rank * sizeof(hsize_t), - &dataset->chunkDimensionsMemory); - dataset->chunkDimensions = dataset->chunkDimensionsMemory.auxp; - - csound->AuxAlloc(csound, dataset->rank * sizeof(hsize_t), - &dataset->maxDimensionsMemory); - dataset->maxDimensions = dataset->maxDimensionsMemory.auxp; - - csound->AuxAlloc(csound, dataset->rank * sizeof(hsize_t), - &dataset->datasetSizeMemory); - dataset->datasetSize = dataset->datasetSizeMemory.auxp; - - csound->AuxAlloc(csound, dataset->rank * sizeof(hsize_t), - &dataset->offsetMemory); - dataset->offset = dataset->offsetMemory.auxp; - - for (i = 0; i < array->dimensions; ++i) { - - dataset->chunkDimensions[i + 1] = array->sizes[i]; - dataset->maxDimensions[i + 1] = array->sizes[i]; - dataset->datasetSize[i + 1] = array->sizes[i]; - } - - switch (dataset->writeType) { - - case ARATE_ARRAY: { - - dataset->chunkDimensions[0] = self->ksmps; - dataset->maxDimensions[0] = H5S_UNLIMITED; - dataset->datasetSize[0] = 0; - - break; - } - case KRATE_ARRAY: { - - dataset->chunkDimensions[0] = 1; - dataset->maxDimensions[0] = H5S_UNLIMITED; - break; - } - case IRATE_ARRAY: { - - return; - } - default: { - - csound->Die(csound, "%s", Str("This should not happen, exiting")); - break; - } - } -} - -// Set up variables for writing a scalar dataset -// -// Set the rank to 1 -// Allocate memory for chunk sizes, maximum sizes, dataset sizes and offsets -// If the argument is not an i-rate variable: -// Set the chunk dimensions to ksmps if a-rate, 1 if k-rate -// Set maximum dimensions to unlimited -// Set the data size to 0 -// If it is an i-rate variable: -// Set the data set size to 1 -// Set the chunk dimensions to 1 -// Set the maximum dimensions to 1 -// Set the offset to 0 - -void HDF5Write_newScalarDataset(CSOUND *csound, HDF5Write *self, - HDF5Dataset *dataset) -{ - dataset->rank = 1; - csound->AuxAlloc(csound, sizeof(hsize_t), &dataset->chunkDimensionsMemory); - dataset->chunkDimensions = dataset->chunkDimensionsMemory.auxp; - - csound->AuxAlloc(csound, sizeof(hsize_t), &dataset->maxDimensionsMemory); - dataset->maxDimensions = dataset->maxDimensionsMemory.auxp; - - csound->AuxAlloc(csound, sizeof(hsize_t), &dataset->datasetSizeMemory); - dataset->datasetSize = dataset->datasetSizeMemory.auxp; - - csound->AuxAlloc(csound, sizeof(hsize_t), &dataset->offsetMemory); - dataset->offset = dataset->offsetMemory.auxp; - - if (dataset->writeType != IRATE_VAR) { - - dataset->chunkDimensions[0] = - dataset->writeType == ARATE_VAR ? self->ksmps : 1; - dataset->maxDimensions[0] = H5S_UNLIMITED; - dataset->datasetSize[0] = 0; - } - else { - dataset->datasetSize[0] = 1; - dataset->chunkDimensions[0] = 1; - dataset->maxDimensions[0] = 1; - } - - dataset->offset[0] = 0; -} - -// Create the datasets for each argument to be written -// -// Allocate the memory for the datasets array -// Get the current empty dataset from the array -// Set it's dataset name as the input arguments name + 1 which is after the -// file path string -// Get the argument pointer from the arguments + 1 after the file path string -// Get the enum write type from the argument pointer -// Depending on the write type set up the variables in the correct way for -// writing during performance -// If the variables are i-rate set up the variables and write them - -void HDF5Write_createDatasets(CSOUND *csound, HDF5Write *self) -{ - int32_t i; - csound->AuxAlloc(csound, sizeof(HDF5Dataset) * self->inputArgumentCount, - &self->datasetsMemory); - self->datasets = self->datasetsMemory.auxp; - - for (i = 0; i < self->inputArgumentCount; ++i) { - - HDF5Dataset *currentDataset = &self->datasets[i]; - currentDataset->datasetName = csound->GetInputArgName(self, (int32_t)i + 1); - currentDataset->argumentPointer = self->arguments[i + 1]; - currentDataset->writeType = - HDF5IO_getArgumentTypeFromArgument(csound, currentDataset->argumentPointer); - - switch (currentDataset->writeType) { - - case ARATE_ARRAY: { - - HDF5Write_newArrayDataset(csound, self, currentDataset); - HDF5Write_initialiseHDF5Dataset(csound, self, currentDataset); - break; - } - case KRATE_ARRAY: { - - HDF5Write_newArrayDataset(csound, self, currentDataset); - HDF5Write_initialiseHDF5Dataset(csound, self, currentDataset); - break; - } - case IRATE_ARRAY: { - - HDF5Write_newArrayDataset(csound, self, currentDataset); - HDF5Write_initialiseHDF5Dataset(csound, self, currentDataset); - HDF5Write_writeData(csound, self, currentDataset, - ((ARRAYDAT *)currentDataset->argumentPointer)->data); - break; - } - case ARATE_VAR: { - - HDF5Write_newScalarDataset(csound, self, currentDataset); - HDF5Write_initialiseHDF5Dataset(csound, self, currentDataset); - break; - } - case KRATE_VAR: { - - HDF5Write_newScalarDataset(csound, self, currentDataset); - HDF5Write_initialiseHDF5Dataset(csound, self, currentDataset); - break; - } - case IRATE_VAR: { - - HDF5Write_newScalarDataset(csound, self, currentDataset); - HDF5Write_initialiseHDF5Dataset(csound, self, currentDataset); - HDF5Write_writeData(csound, self, currentDataset, - currentDataset->argumentPointer); - break; - } - default: { - - break; - } - } - } -} - -// Open datasets in a hdf5 file so they can be read by the opcode -// -// Get the amount of samples in a control pass -// Get the amount of input arguments minus the file path argument -// Get the amount of output arguments -// Check that input == output arguments and input arguments are strings, -// output not strings -// Register the finish callback to close the hdf5 file when performance -// is finished -// Check csound is running in sample accurate mode -// Get the path string from the first argument -// Open the hdf5 file then open the hdf5 datasets - -int32_t HDF5Read_initialise(CSOUND *csound, HDF5Read *self) -{ - self->ksmps = csound->GetKsmps(csound); - self->inputArgumentCount = self->INOCOUNT - 1; - self->outputArgumentCount = self->OUTOCOUNT; - HDF5Read_checkArgumentSanity(csound, self); - csound->RegisterDeinitCallback(csound, self, HDF5Read_finish); - self->isSampleAccurate = HDF5IO_getSampleAccurate(csound); - //STRINGDAT *path = (STRINGDAT *)self->arguments[self->outputArgumentCount]; - self->hdf5File = HDF5IO_newHDF5File(csound, &self->hdf5FileMemory, self->path, false); - HDF5Read_openDatasets(csound, self); - - return OK; -} - -// Copy data from the a-rate variable read sample buffer to the output array data -// -// This function is used to copy data from a sample buffer each hdf5 -// struct to an array data member, this is because in sample accurate -// mode the stride of the data read from the hdf5 file isn't correct -// and must be offset properly before it is written to the array data - -void HDF5Read_copySampleBufferToArray(size_t channelCount, MYFLT *sampleBuffer, - MYFLT *arrayData, size_t vectorSize, - size_t offset, size_t ksmps) -{ - size_t channel; - for (channel = 0; channel < channelCount; ++channel) { - - memcpy(&arrayData[ksmps * channel + offset], - &sampleBuffer[vectorSize * channel], - sizeof(MYFLT) * vectorSize); - } -} - -// Read data from an hdf5 file dataset -// -// Get the specified file space -// Select the hyperslab at the specified offset and chunk dimension -// Create a memory space from where the data is read -// Read the data from the memory space -// Close the open file and memory spaces - -void HDF5Read_readData(CSOUND *csound, HDF5Read *self, HDF5Dataset *dataset, - hsize_t *offset, hsize_t *chunkDimensions, - MYFLT *dataPointer) -{ - uint64_t kCount = csound->GetKcounter(csound); - - if (kCount > dataset->datasetSize[0]) { - - return; - } - - hid_t filespace = H5Dget_space(dataset->datasetID); - HDF5ERROR(filespace); - HDF5ERROR(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, - NULL, chunkDimensions, NULL)); - hid_t memspace = H5Screate_simple(dataset->rank, chunkDimensions, NULL); - HDF5ERROR(memspace); - HDF5ERROR(H5Dread(dataset->datasetID, self->hdf5File->floatSize, - memspace, filespace, H5P_DEFAULT, dataPointer)); - HDF5ERROR(H5Sclose(filespace)); - HDF5ERROR(H5Sclose(memspace)); - - -} - -// Read data at audio rate from a hdf5 file dataset -// -// If the offset is larger than the size of the dataset there is no more -// data to read so return -// Get the offset and early variables and work out the size of data to read -// If the read vector size plus the offset is larger than the dataset size -// reduce the vector size accordingly -// If the vector size is less than the ksmps value, use the sample -// buffer to store read data so the stride can be corrected before -// writing it to the array data, if not just point directly to array -// data -// Create the chunk dimensions variable, set the required size -// Read data from the hdf5 file -// If the vector size is not equal to ksmps correct the stride of data -// Increment the offset by the vector size - -void HDF5Read_readAudioData(CSOUND *csound, HDF5Read *self, - HDF5Dataset *dataset, MYFLT *inputDataPointer) -{ - if (dataset->offset[0] >= - dataset->datasetSize[0]) { - return; - } - - size_t offset = self->h.insdshead->ksmps_offset; - size_t early = self->h.insdshead->ksmps_no_end; - - size_t vectorSize = (int32_t)(self->ksmps - offset - early); - - if (vectorSize + dataset->offset[0] > - dataset->datasetSize[0]) { - - vectorSize = (int32_t)(dataset->datasetSize[0] - - dataset->offset[0]); - } - MYFLT *dataPointer = - vectorSize != self->ksmps ? dataset->sampleBuffer : inputDataPointer; - // FIXME if this is called frequently or on the audio thread then this won't - // work and will need a different solution -#ifdef _MSC_VER - //hsize_t* chunkDimensions = malloc (dataset->rank * sizeof (hsize_t)); - hsize_t chunkDimensions[16]; -#else - hsize_t chunkDimensions[dataset->rank]; -#endif - memcpy(&chunkDimensions[1], &dataset->datasetSize[1], - sizeof(hsize_t) * (dataset->rank-1)); // Reads too much - chunkDimensions[0] = vectorSize; - - // memcpy (chunkDimensions, dataset->datasetSize, - // sizeof (hsize_t)/* * dataset->rank */ - // ); - //chunkDimensions[dataset->rank - 1] = vectorSize; - - HDF5Read_readData (csound, self, dataset, dataset->offset, - chunkDimensions, dataPointer); - - if (vectorSize != self->ksmps) { - - HDF5Read_copySampleBufferToArray(dataset->elementCount, - dataset->sampleBuffer, inputDataPointer, - vectorSize, offset, self->ksmps); - } - - dataset->offset[0] += vectorSize; - -#ifdef _MSC_VER - //free (chunkDimensions); -#endif - -} - -// Read data at control rate from a hdf5 dataset -// -// If the offset of the dataset is larger than the data set size, no -// more data to read to return -// Create chunk dimension variable and set the appropriate size -// Read the data from the dataset -// Increment the offset variable - -void HDF5Read_readControlData(CSOUND *csound, HDF5Read *self, - HDF5Dataset *dataset, MYFLT *dataPointer) -{ - if (dataset->offset[0] >= - dataset->datasetSize[0]) { - - return; - } - - // FIXME if this is called frequently or on the audio thread then this won't - // work and will need a different solution -#ifndef _MSC_VER - hsize_t chunkDimensions[dataset->rank]; -#else - hsize_t* chunkDimensions = malloc (dataset->rank * sizeof (hsize_t)); -#endif - memcpy(&chunkDimensions[1], &dataset->datasetSize[1], - sizeof(hsize_t) * (dataset->rank - 1)); - chunkDimensions[0] = 1; - - HDF5Read_readData(csound, self, dataset, dataset->offset, - chunkDimensions, dataPointer); - dataset->offset[0]++; -#ifdef _MSC_VER - free (chunkDimensions); -#endif - -} - -// Read dataset variables during performance time -// -// Iterate through each of the opened datasets, -// Depending on the dataset read type use the appropriate read function -// to read the data - -int32_t HDF5Read_process(CSOUND *csound, HDF5Read *self) -{ - int32_t i; - for (i = 0; i < self->inputArgumentCount; ++i) { - - HDF5Dataset *dataset = &self->datasets[i]; - - if (dataset->readAll == true) { - - continue; - } - - switch (dataset->readType) { - - case ARATE_ARRAY: { - - HDF5Read_readAudioData(csound, self, dataset, - ((ARRAYDAT *)dataset->argumentPointer)->data); - break; - } - case KRATE_ARRAY: { - - HDF5Read_readControlData(csound, self, dataset, - ((ARRAYDAT *)dataset->argumentPointer)->data); - break; - } - case ARATE_VAR: { - - HDF5Read_readAudioData(csound, self, dataset, dataset->argumentPointer); - break; - } - case KRATE_VAR: { - - HDF5Read_readControlData(csound, self, dataset, dataset->argumentPointer); - break; - } - - default: { - - break; - } - } - } - return OK; -} - -// Close the necessary variables when reading has finished -// -// Iterate through open datasets closing them in the hdf5 file -// Close the hdf5 file - -int32_t HDF5Read_finish(CSOUND *csound, void *inReference) -{ - HDF5Read *self = inReference; - int32_t i; - for (i = 0; i < self->inputArgumentCount; ++i) { - - HDF5Dataset *dataset = &self->datasets[i]; - - HDF5ERROR(H5Dclose(dataset->datasetID)); - } - - HDF5ERROR(H5Fclose(self->hdf5File->fileHandle)); - - return OK; -} - -// Check the input and output arguments for validity -// -// Check to see that if the amount of input arguments matches output arguments -// Check that the input arguments are strings, and the output arguments are -// not strings - -void HDF5Read_checkArgumentSanity(CSOUND *csound, const HDF5Read *self) -{ - int32_t i; - if (UNLIKELY(self->inputArgumentCount != self->outputArgumentCount)) { - - if (self->inputArgumentCount > self->outputArgumentCount) { - - csound->Die(csound, "%s", Str("hdf5read: Error, more input arguments than " - "output arguments, exiting")); - } - else { - - csound->Die(csound, "%s", Str("hdf5read: Error, more output arguments than " - "input arguments, exiting")); - } - } - - for (i = 0; i < self->inputArgumentCount; ++i) { - - ArgumentType outputType = - HDF5IO_getArgumentTypeFromArgument(csound, self->arguments[i]); - - if (UNLIKELY(outputType == STRING_VAR)) { - - csound->Die(csound, Str("hdf5read: Error, output argument %d appears " - "to be a string, exiting"), i + 1); - } - else if (UNLIKELY(outputType == UNKNOWN)) { - - csound->Die(csound, Str("hdf5read: Error, output argument %d type " - "is unknown, exiting"), i + 1); - } - } -} - -// Open the specified dataset in the hdf5 file -// -// Check that the hdf5 dataset exists in the file, if it doesn't stop csound -// If it does then open it - -void HDF5Read_initialiseHDF5Dataset(CSOUND *csound, HDF5Read *self, - HDF5Dataset *dataset) -{ - htri_t result = H5Lexists(self->hdf5File->fileHandle, - dataset->datasetName, H5P_DEFAULT); - - if (UNLIKELY(result <= 0)) { - - csound->Die(csound, "%s", Str("hdf5read: Error, dataset does not exist or " - "cannot be found in file")); - } - - dataset->datasetID = H5Dopen2(self->hdf5File->fileHandle, - dataset->datasetName, H5P_DEFAULT); - HDF5ERROR(dataset->datasetID); -} - -// Check opcode read types are compatible with the types written to the hdf5 dataset -// -// Get the written type from the hdf5 file -// If the opcode read type for the dataset is an array and the write type is -// an array or a-rate or k-rate variable return -// If the opcode read type is an a-rate or k-rate variable and the write type -// is an a-rate or k-rate vairable return -// If the opcode read type is an i-reate variable and the write type is an -// i-rate variable return -// Otherwise stop csound - -void HDF5Read_checkReadTypeSanity(CSOUND *csound, HDF5Read *self, - HDF5Dataset *dataset) -{ - char attributeString[12] = {"UNKNOWN\0"}; - HDF5IO_readStringAttribute(csound, self->hdf5File, - dataset->datasetName, attributeString); - dataset->writeType = HDF5IO_getArgumentTypeFromString(csound, attributeString); - - if (dataset->readType == ARATE_ARRAY - || - dataset->readType == KRATE_ARRAY - || - dataset->readType == IRATE_ARRAY) { - - if (dataset->writeType == ARATE_ARRAY - || - dataset->writeType == KRATE_ARRAY - || - dataset->writeType == IRATE_ARRAY - || - dataset->writeType == ARATE_VAR - || - dataset->writeType == KRATE_VAR) { - - return; - } - } - else if (dataset->readType == ARATE_VAR - || - dataset->readType == KRATE_VAR) { - - if (dataset->writeType == ARATE_VAR - || - dataset->writeType == KRATE_VAR) { - - return; - } - } - else if (dataset->readType == IRATE_VAR) { - - if (dataset->writeType == IRATE_VAR) { - - return; - } - } - else { - - csound->Die(csound, "%s", Str("hdf5read: Unable to read saved type of " - "dataset, exiting")); - } -} - -// Allocate the memory for an output array from the opcode -// -// Get the pointer to the output argument and cast to array -// Get the rank and allocate the dimension sizes memory -// Assign first dimension size to array sizes and dataset element count -// If the rank is greater than 1, multiply dimensions to get element count -// Allocate data space for the array using the element count - -void HDF5Read_allocateArray(CSOUND *csound, HDF5Dataset *dataset, - hsize_t rank, hsize_t *dimensions) -{ - ARRAYDAT *array = dataset->argumentPointer; - array->dimensions = (int32_t)rank; - array->sizes = csound->Calloc(csound, sizeof(int32_t) * rank); - - array->sizes[0] = (int32_t)dimensions[0]; - dataset->elementCount = dimensions[0]; - - if (rank > 1) { - size_t i; - for (i = 1; i < rank; ++i) { - - array->sizes[i] = (int32_t)dimensions[i]; - dataset->elementCount *= array->sizes[i]; - - } - } - - CS_VARIABLE *arrayVariable = array->arrayType->createVariable(csound, NULL); - array->arrayMemberSize = arrayVariable->memBlockSize; - array->data = - csound->Calloc(csound, - arrayVariable->memBlockSize * dataset->elementCount); -} - - -// Initialise the dataset and prepare for reading an a-rate, k-rate or i-rate -// array during performance time -// -// Get the data space from the dataset in the hdf5 file -// Get the rank from the data space -// Allocate the size array for specified rank -// Get the dimensions of the dataset and copy to dataset size array -// If requested output type for dataset is not an i-rate array: -// Create the dimensions variable and copy the dataset size minus the last -// dimension to the array -// Then allocate the array data for the output argument -// Allocate the memory for the offset variable -// If it's an a-rate array and sample accurate allocate data for the sample buffer -// Else if it's an i-rate array copy the array dimensions including the last one -// Then allocate the array data for the output argument -// Cast the argument pointer to an array, then read the data into the array from -// the hdf5 file - -void HDF5Read_initialiseArrayOutput(CSOUND *csound, HDF5Read *self, - HDF5Dataset *dataset) -{ - - hid_t dataspaceID = H5Dget_space(dataset->datasetID); - HDF5ERROR(dataspaceID); - dataset->rank = H5Sget_simple_extent_ndims(dataspaceID); - - csound->AuxAlloc(csound, sizeof(hsize_t) * dataset->rank, - &dataset->datasetSizeMemory); - dataset->datasetSize = dataset->datasetSizeMemory.auxp; - - H5Sget_simple_extent_dims(dataspaceID, dataset->datasetSize, NULL); - HDF5ERROR(H5Sclose(dataspaceID)); - - if (dataset->readType != IRATE_ARRAY && dataset->readAll == false) { - // FIXME if this is called frequently or on the audio thread then this won't - // work and will need a different solution -#ifdef _MSC_VER - hsize_t* arrayDimensions = malloc ((dataset->rank - 1) * sizeof (hsize_t)); -#else - hsize_t arrayDimensions[dataset->rank - 1]; -#endif - memcpy(arrayDimensions, &dataset->datasetSize[1], - (dataset->rank - 1) * sizeof(hsize_t)); - - HDF5Read_allocateArray(csound, dataset, (dataset->rank - 1), arrayDimensions); - - csound->AuxAlloc(csound, sizeof(hsize_t) * dataset->rank, - &dataset->offsetMemory); - dataset->offset = dataset->offsetMemory.auxp; - - if (dataset->readType == ARATE_ARRAY - || - self->isSampleAccurate == true) { - - csound->AuxAlloc(csound, - dataset->elementCount * self->ksmps * sizeof(MYFLT), - &dataset->sampleBufferMemory); - dataset->sampleBuffer = dataset->sampleBufferMemory.auxp; - } -#ifdef _MSC_VER - free (arrayDimensions); -#endif - } - else { -#ifdef _MSC_VER - hsize_t* arrayDimensions = malloc ((dataset->rank) * sizeof (hsize_t)); -#else - hsize_t arrayDimensions[dataset->rank]; -#endif - memcpy(arrayDimensions, dataset->datasetSize, - dataset->rank * sizeof(hsize_t)); - HDF5Read_allocateArray(csound, dataset, dataset->rank, arrayDimensions); - ARRAYDAT *array = dataset->argumentPointer; -#ifdef _MSC_VER - hsize_t* offset = malloc ((dataset->rank) * sizeof (hsize_t)); -#else - hsize_t offset[dataset->rank]; -#endif - memset(offset, 0, sizeof(hsize_t) * dataset->rank); - HDF5Read_readData(csound, self, dataset, offset, - arrayDimensions, array->data); -#ifdef _MSC_VER - free (offset); -#endif - } -} - -// Initialise the dataset and prepare for reading an a-rate, k-rate or i-rate -// variable during performance time -// -// Get the data space from the dataset in the hdf5 file -// Set the rank as 1, the variable is a scalar -// If the dataset read type is a-rate or k-rate: -// Allocate the dataset size memory, get the size of the dataset and copy to -// the size memory -// Allocate offset memory and set to 0 -// If the dataset is to be read at a-rate and we are running sample accurate -// allocate the sample buffer -// Otherwise create array dimesions variable, set to 1, create offset variable, -// set to 0 and read the i-rate variable - -void HDF5Read_initialiseScalarOutput(CSOUND *csound, HDF5Read *self, - HDF5Dataset *dataset) -{ - hid_t dataspaceID = H5Dget_space(dataset->datasetID); - HDF5ERROR(dataspaceID); - dataset->rank = 1; - - if (dataset->readType == ARATE_VAR - || - dataset->readType == KRATE_VAR - || - dataset->readType == IRATE_VAR) { - - csound->AuxAlloc(csound, sizeof(hsize_t) * dataset->rank, - &dataset->datasetSizeMemory); - dataset->datasetSize = dataset->datasetSizeMemory.auxp; - - H5Sget_simple_extent_dims(dataspaceID, dataset->datasetSize, NULL); - HDF5ERROR(H5Sclose(dataspaceID)); - - csound->AuxAlloc(csound, sizeof(hsize_t), &dataset->offsetMemory); - dataset->offset = dataset->offsetMemory.auxp; - memset(dataset->offset, 0, sizeof(hsize_t)); - - if (dataset->readType == ARATE_VAR - && - self->isSampleAccurate == true) { - - csound->AuxAlloc(csound, self->ksmps * sizeof(MYFLT), - &dataset->sampleBufferMemory); - dataset->sampleBuffer = dataset->sampleBufferMemory.auxp; - dataset->elementCount = 1; - } - - if (dataset->readType == IRATE_VAR) { - - hsize_t arrayDimensions[1] = {1}; - hsize_t offset[1] = {0}; - HDF5Read_readData(csound, self, dataset, offset, arrayDimensions, - dataset->argumentPointer); - } - } - -} - -// Open the datasets in an hdf5 file for reading -// -// Allocate memory for the datasets array -// Iterate through the datasets in the array -// Assign the input argument name to the dataset name -// Get the read type from the arguments -// Assign the argument data pointer -// Check that the read type and write type are compatiblea -// Initialise the data set using the corresponding function for read type specified - -void HDF5Read_openDatasets(CSOUND *csound, HDF5Read *self) -{ - int32_t i; - csound->AuxAlloc(csound, sizeof(HDF5Dataset) * self->inputArgumentCount, - &self->datasetsMemory); - self->datasets = self->datasetsMemory.auxp; - - for (i = 0; i < self->inputArgumentCount; ++i) { - - HDF5Dataset *currentDataset = &self->datasets[i]; - STRINGDAT *inputArgument = (STRINGDAT *)self->names[i]; - - csound->AuxAlloc(csound, sizeof(char) * strlen(inputArgument->data)+1, - ¤tDataset->datasetNameMemory); - currentDataset->datasetName = currentDataset->datasetNameMemory.auxp; - strcpy(currentDataset->datasetName, inputArgument->data); - - if (currentDataset->datasetName[strlen(inputArgument->data) - 1] == '*') { - - currentDataset->readAll = true; - currentDataset->datasetName[strlen(inputArgument->data) - 1] = '\0'; - } - currentDataset->readType = - HDF5IO_getArgumentTypeFromArgument(csound, self->arguments[i]); - currentDataset->argumentPointer = self->arguments[i]; - HDF5Read_checkReadTypeSanity(csound, self, currentDataset); - HDF5Read_initialiseHDF5Dataset(csound, self, currentDataset); - - switch (currentDataset->readType) { - case ARATE_ARRAY: { - - HDF5Read_initialiseArrayOutput(csound, self, currentDataset); - break; - } - case KRATE_ARRAY: { - - HDF5Read_initialiseArrayOutput(csound, self, currentDataset); - break; - } - case IRATE_ARRAY: { - - HDF5Read_initialiseArrayOutput(csound, self, currentDataset); - break; - } - case ARATE_VAR: { - - HDF5Read_initialiseScalarOutput(csound, self, currentDataset); - break; - } - case KRATE_VAR: { - - HDF5Read_initialiseScalarOutput(csound, self, currentDataset); - break; - } - case IRATE_VAR: { - - HDF5Read_initialiseScalarOutput(csound, self, currentDataset); - break; - } - default: - break; - - } - } - -} - - -static OENTRY localops[] = { - - { - .opname = "hdf5write", - .dsblksiz = sizeof(HDF5Write), - .thread = 3, - .outypes = "", - .intypes = "*", - .iopadr = (SUBR)HDF5Write_initialise, - .kopadr = (SUBR)HDF5Write_process, - .aopadr = NULL - }, - { - .opname = "hdf5read", - .dsblksiz = sizeof(HDF5Read), - .thread = 3, - .outypes = "********************", - .intypes = "SW", - .iopadr = (SUBR)HDF5Read_initialise, - .kopadr = (SUBR)HDF5Read_process, - .aopadr = NULL - } -}; - -LINKAGE diff --git a/6.x/src/hdf5/HDF5IO.h b/6.x/src/hdf5/HDF5IO.h deleted file mode 100644 index 5b7a55a3..00000000 --- a/6.x/src/hdf5/HDF5IO.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2014 Edward Costello - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "csdl.h" -#include "hdf5.h" -#include - -typedef enum ArgumentType -{ - STRING_VAR, - ARATE_VAR, - KRATE_VAR, - IRATE_VAR, - ARATE_ARRAY, - KRATE_ARRAY, - IRATE_ARRAY, - UNKNOWN -} ArgumentType; - -typedef struct _fft { - OPDS h; - ARRAYDAT *out; - ARRAYDAT *in, *in2; - MYFLT *f; - MYFLT b; - int32_t n; - void *setup; - AUXCH mem; -} nFFT; - - - -typedef struct HDF5Dataset -{ - char *datasetName; - AUXCH datasetNameMemory; - void *argumentPointer; - ArgumentType writeType; - ArgumentType readType; - int32_t rank; - hsize_t *chunkDimensions; - AUXCH chunkDimensionsMemory; - hsize_t *maxDimensions; - AUXCH maxDimensionsMemory; - hsize_t *offset; - AUXCH offsetMemory; - hsize_t *datasetSize; - AUXCH datasetSizeMemory; - - hid_t datasetID; - - size_t elementCount; - MYFLT *sampleBuffer; - AUXCH sampleBufferMemory; - - bool readAll; - -} HDF5Dataset; - -typedef struct HDF5File -{ - hid_t fileHandle; - char *fileName; - hid_t floatSize; - -} HDF5File; - - -HDF5File *HDF5IO_newHDF5File(CSOUND *csound, AUXCH *hdf5FileMemory, - STRINGDAT *path, bool openForWriting); - -void HDF5IO_deleteHDF5File(CSOUND *csound, HDF5File *hdf5File); - -typedef struct HDF5Write -{ - OPDS h; - MYFLT *arguments[20]; - int32_t inputArgumentCount; - size_t ksmps; - HDF5File *hdf5File; - AUXCH hdf5FileMemory; - HDF5Dataset *datasets; - AUXCH datasetsMemory; - -} HDF5Write; - -int32_t HDF5Write_initialise(CSOUND *csound, HDF5Write *self); - -int32_t HDF5Write_process(CSOUND *csound, HDF5Write *self); - -int32_t HDF5Write_finish(CSOUND *csound, void *inReference); - -void HDF5Write_checkArgumentSanity(CSOUND *csound, const HDF5Write *self); - -void HDF5Write_createDatasets(CSOUND *csound, HDF5Write *self); - -void HDF5Write_newArrayDataset(CSOUND *csound, HDF5Write *self, - HDF5Dataset *dataset); - -void HDF5Write_deleteArrayDataset(CSOUND *csound, HDF5Dataset *dataset); - - -typedef struct HDF5Read -{ - OPDS h; - MYFLT *arguments[20]; - STRINGDAT *path; - STRINGDAT *names[20]; - int32_t inputArgumentCount; - int32_t outputArgumentCount; - size_t ksmps; - HDF5File *hdf5File; - AUXCH hdf5FileMemory; - HDF5Dataset *datasets; - AUXCH datasetsMemory; - bool isSampleAccurate; - -} HDF5Read; - -int32_t HDF5Read_initialise(CSOUND *csound, HDF5Read *self); - -int32_t HDF5Read_process(CSOUND *csound, HDF5Read *self); - -int32_t HDF5Read_finish(CSOUND *csound, void *inReference); - -void HDF5Read_checkArgumentSanity(CSOUND *csound, const HDF5Read *self); - -void HDF5Read_openDatasets(CSOUND *csound, HDF5Read *self); diff --git a/6.x/src/image/CMakeLists.txt b/6.x/src/image/CMakeLists.txt deleted file mode 100644 index 76123b24..00000000 --- a/6.x/src/image/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# Build image opcodes -option(BUILD_IMAGE_OPCODES "Build the image opcodes" ON) - -if(${BUILD_IMAGE_OPCODES}) - find_package(PNG) - check_deps(BUILD_IMAGE_OPCODES PNG_FOUND) - - if(BUILD_IMAGE_OPCODES) - make_plugin(image imageOpcodes.c) - target_include_directories(image PRIVATE ${CSOUND_INCLUDE_DIRS}) - target_include_directories(image PRIVATE ${PNG_INCLUDE_DIR}) - target_link_libraries(image ${PNG_LIBRARIES}) - target_compile_definitions(image PRIVATE ${PNG_DEFINITIONS}) - endif() -endif() diff --git a/6.x/src/image/README.md b/6.x/src/image/README.md deleted file mode 100644 index 4a58a5a4..00000000 --- a/6.x/src/image/README.md +++ /dev/null @@ -1,6 +0,0 @@ -Image opcodes -======= - -To build the image opcodes, you will need the libpng library, which can be easily built -and installed from sources using CMake, see [http://www.libpng.org/pub/png/libpng.html](http://www.libpng.org/pub/png/libpng.html) - diff --git a/6.x/src/image/imageOpcodes.c b/6.x/src/image/imageOpcodes.c deleted file mode 100644 index d383e179..00000000 --- a/6.x/src/image/imageOpcodes.c +++ /dev/null @@ -1,659 +0,0 @@ - -/** - * IMAGE OPCODES - * - * imageOpcodes.c - * - * Copyright (c) 2007 by Cesare Marilungo. All rights reserved. - * - * L I C E N S E - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * C S O U N D M A N P A G E - * - * imageload - opens an image (in PNG format) - * imagesave - saves an image (in PNG format) - * imagecreate - create an empty image - * imagesize - gets the size of an image - * imagegetpixel - gets the rgb values of a pixel - * imagesetpixel - sets the rgb values of a pixel - * imagefree - free memory from a previously loaded or created image. - * - * SYNTAX - * - * iImageNumber imageload sFilename - * - * imageSave iImageNumber, sFilename - * - * iImageNumber imagecreate iWidth, iHeight - * - * iWidth, iHeight imagesize iImageNumber - * - * kred, kgreen, kblue imagegetpixel iImageNumber, kX, kY - * ared, agreen, ablue imagegetpixel iImageNumber, aX, aY - * - * imagesetpixel iImageNumber, kX, kY, kred, kgreen, kblue - * imagesetpixel iImageNumber, aX, aY, ared, agreen, ablue - * - * imageFree iImageNumber - * - */ - -#define USE_LIBPNG - -#ifdef USE_LIBPNG -#include -#else -#include -#include -#endif - -/* #include */ -/* #include */ - -#include "csdl.h" -#include "imageOpcodes.h" - -/* - __doOpenImage and __doSaveImage are the only two functions that deal - with the actual image loading saving library. - - imageData stores the image content as an array of RGB bytes for each - row (l->r t->b) so a pixel value in imageData is located at: (w*y+x)*3. -*/ - -/* #undef CS_KSMPS */ -/* #define CS_KSMPS (csound->GetKsmps(csound)) */ - -static Image * __doOpenImage(char * filename, CSOUND *csound) -{ -#ifdef USE_LIBPNG -#define HS (8) - FILE *fp; - void *fd; - unsigned char header[HS]; - png_structp png_ptr; - png_infop info_ptr; - /* png_infop end_ptr; */ - int32_t is_png; - png_uint_32 width, height, rowbytes; - int32_t bit_depth; - int32_t color_type; - unsigned char *image_data; - png_bytepp row_pointers; - uint32_t i; - - Image *img; - - fd = csound->FileOpen2(csound, &fp, CSFILE_STD, filename, "rb", - "SFDIR;SSDIR", CSFTYPE_IMAGE_PNG, 0); - if (UNLIKELY(fd == NULL)) { - csound->InitError(csound, - Str("imageload: cannot open image %s.\n"), filename); - return NULL; - } - - if (UNLIKELY(HS!=fread(header, 1, HS, fp))) { - csound->InitError(csound, - Str("imageload: file %s is not in PNG format.\n"), - filename); - return NULL; - } - is_png = !png_sig_cmp(header, 0, HS); - - if (UNLIKELY(!is_png)) { - csound->InitError(csound, - Str("imageload: file %s is not in PNG format.\n"), - filename); - csound->FileClose(csound, fd); - return NULL; - } - - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (UNLIKELY(!png_ptr)) { - csound->InitError(csound, "%s", Str("imageload: out of memory.\n")); - csound->FileClose(csound, fd); - return NULL; - } - info_ptr = png_create_info_struct(png_ptr); - if (UNLIKELY(!info_ptr)) { - png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL); - csound->InitError(csound, "%s", Str("imageload: out of memory.\n")); - csound->FileClose(csound, fd); - return NULL; - } - - /* end_ptr = png_create_info_struct(png_ptr); */ - /* if (UNLIKELY(!end_ptr)) { */ - /* png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); */ - /* csound->InitError(csound, "%s", Str("imageload: out of memory.\n")); */ - /* csound->FileClose(csound, fd); */ - /* return NULL; */ - /* } */ - - png_init_io(png_ptr, fp); - png_set_sig_bytes(png_ptr, HS); - - png_read_info(png_ptr, info_ptr); - { - - png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, - &color_type, NULL, NULL, NULL); - } - if (color_type & PNG_COLOR_MASK_ALPHA) - png_set_strip_alpha(png_ptr); - if (bit_depth == 16) - png_set_strip_16(png_ptr); - if (bit_depth < 8) - png_set_packing(png_ptr); - if (color_type == PNG_COLOR_TYPE_GRAY || - color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - png_set_gray_to_rgb(png_ptr); - if (color_type == PNG_COLOR_TYPE_PALETTE) - png_set_palette_to_rgb(png_ptr); - - png_read_update_info(png_ptr, info_ptr); - rowbytes = png_get_rowbytes(png_ptr, info_ptr); - - if (UNLIKELY((image_data = - (unsigned char *)csound->Malloc(csound,rowbytes*height))==NULL)) { - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - csound->InitError(csound, "%s", Str("imageload: out of memory.\n")); - return NULL; - } - - row_pointers = (png_bytepp) csound->Malloc(csound, height*sizeof(png_bytep)); - if (UNLIKELY(row_pointers == NULL)) { - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - csound->Free(csound,image_data); - image_data = NULL; - csound->InitError(csound, "%s", Str("imageload: out of memory.\n")); - return NULL; - } - - for (i = 0; i < height; i++) - row_pointers[i] = image_data + i*rowbytes; - - png_read_image(png_ptr, row_pointers); - csound->Free(csound,row_pointers); - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - csound->FileClose(csound, fd); - - img = csound->Malloc(csound, sizeof(Image)); - if (UNLIKELY(!img)) { - csound->Free(csound,image_data); - csound->InitError(csound, "%s", Str("imageload: out of memory.\n")); - return NULL; - } - - img->w = width; - img->h = height; - img->imageData = image_data; - - return img; - -#else - - Display *disp; - ImlibData *id; - ImlibImage *im; - Image *img; - size_t datasize; - - disp=XOpenDisplay(NULL); - id=Imlib_init(disp); - im=Imlib_load_image(id, filename); - - img = csound->Malloc(csound, sizeof(Image)); - img->w = im->rgb_width; - img->h = im->rgb_height; - datasize = img->w*img->h*3 * sizeof(unsigned char); - img->imageData = csound->Malloc(csound, datasize); - memcpy(img->imageData, im->rgb_data, datasize); - - return img; -#endif - - /* SDL */ -/* Image *img; - size_t datasize; - SDL_Surface *srfc; - int32_t x,y; - int32_t bpp; - int32_t indcount = 0; - Uint32 *pixel; - Uint8 r, g, b; - - srfc = IMG_Load(filename); - if (srfc) { - SDL_LockSurface(srfc); - img = csound->Malloc(csound, sizeof(Image)); - img->w = srfc->w; - img->h = srfc->h; - bpp = srfc->format->BitsPerPixel; - - datasize = img->w*img->h*3 * sizeof(unsigned char); - img->imageData = csound->Malloc(csound, datasize); - - for(y = 0; y < img->h; y++) { - for(x = 0; x < img->w; x++) { - if (bpp<=8) //need to test on other platforms - pixel = srfc->pixels + y * srfc->pitch + x * bpp; - else - pixel = srfc->pixels + y * srfc->pitch + x * bpp / 8; - SDL_GetRGB(*pixel,srfc->format, &r, &g, &b); - img->imageData[indcount]= r; - img->imageData[indcount+1]= g; - img->imageData[indcount+2]= b; - indcount += 3; - } - } - SDL_UnlockSurface(srfc); - SDL_FreeSurface ( srfc ); - return img; - } - - return NULL; -*/ - -} - - -static int32_t __doSaveImage(Image *image, char *filename, CSOUND *csound) -{ -#ifdef USE_LIBPNG - - png_structp png_ptr; - png_infop info_ptr; - png_bytepp row_pointers; - uint32_t rowbytes; - int32_t i; - - FILE *fp; - void *fd; - - fd = csound->FileOpen2(csound, &fp, CSFILE_STD, filename, "wb", - "", CSFTYPE_IMAGE_PNG, 0); - if (UNLIKELY(fd == NULL)) { - return - csound->InitError(csound, - Str("imageload: cannot open image %s for writing.\n"), - filename); - } - - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - - if (UNLIKELY(!png_ptr)){ - csound->FileClose(csound, fd); - return csound->InitError(csound, "%s", Str("imageload: out of memory.\n")); - } - - info_ptr = png_create_info_struct(png_ptr); - if (UNLIKELY(!info_ptr)) { - png_destroy_write_struct(&png_ptr, (png_infopp)NULL); - csound->FileClose(csound, fd); - return csound->InitError(csound, "%s", Str("imageload: out of memory.\n")); - } - - png_init_io(png_ptr, fp); - png_set_IHDR(png_ptr, info_ptr, image->w, image->h, - 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - - png_write_info(png_ptr, info_ptr); - - row_pointers = (png_bytepp)csound->Malloc(csound, image->h*sizeof(png_bytep)); - if (UNLIKELY(row_pointers == NULL)) { - png_destroy_write_struct(&png_ptr, &info_ptr); - return csound->InitError(csound, "%s", Str("imageload: out of memory.\n")); - } - - rowbytes = png_get_rowbytes(png_ptr, info_ptr); - - for (i = 0; i < image->h; i++) - row_pointers[i] = image->imageData + i*rowbytes; - - png_write_image(png_ptr, row_pointers); - png_write_end(png_ptr, info_ptr); - - csound->Free(csound,row_pointers); - png_destroy_write_struct(&png_ptr, &info_ptr); - csound->FileClose(csound, fd); - - return OK; -#else - Display *disp; - ImlibData *id; - ImlibImage *im; - - disp=XOpenDisplay(NULL); - id=Imlib_init(disp); - - im = Imlib_create_image_from_data(id, image->imageData, - NULL, image->w, image->h); - Imlib_save_image(id, im, filename, NULL); - Imlib_kill_image(id, im); - - return OK; -#endif -} - - -static Image * createImage(CSOUND *csound, int32_t w, int32_t h) -{ - Image *img; - size_t datasize; - - img = csound->Malloc(csound, sizeof(Image)); - img->w = w; - img->h = h; - - datasize = img->w*img->h*3 * sizeof(unsigned char); - img->imageData = csound->Malloc(csound, datasize); - - return img; -} - - -static Images * getImages(CSOUND *csound) -{ - Images *pimages; - pimages = (Images*)csound->QueryGlobalVariable(csound, - "imageOpcodes.images"); - if (pimages==NULL) { /* first call */ - csound->CreateGlobalVariable(csound, "imageOpcodes.images", - sizeof(Images)); - pimages = (Images*)csound->QueryGlobalVariable(csound, - "imageOpcodes.images"); - pimages->images = (Image **) NULL; - pimages->cnt = (size_t) 0; - } - return pimages; -} - -static int32_t imagecreate (CSOUND *csound, IMGCREATE * p) -{ - Images *pimages; - Image *img; - - pimages = getImages(csound); - - pimages->cnt++; - pimages->images = - (Image **) csound->ReAlloc(csound, pimages->images, - sizeof(Image *) * pimages->cnt); - - img = createImage(csound, *p->kw, *p->kh); - - if (UNLIKELY(img==NULL)) { - return csound->InitError(csound, "%s", Str("Cannot allocate memory.\n")); - } - else { - pimages->images[pimages->cnt-1] = img; - *(p->kn) = (MYFLT) pimages->cnt; - return OK; - } -} - -static int32_t imageload (CSOUND *csound, IMGLOAD * p) -{ - char filename[256]; - Images *pimages; - Image *img; - - pimages = getImages(csound); - - pimages->cnt++; - pimages->images = - (Image **) csound->ReAlloc(csound, pimages->images, - sizeof(Image *) * pimages->cnt); - - strncpy(filename, (char*) (p->ifilnam->data), 255); filename[255]='\0'; - - img = __doOpenImage(filename, csound); - - if (LIKELY(img)) { - pimages->images[pimages->cnt-1] = img; - *(p->kn) = (MYFLT) pimages->cnt; - return OK; - } - else { - return csound->InitError(csound, - Str("imageload: cannot open image %s.\n"), - filename); - } -} - - -static int32_t imagesize (CSOUND *csound, IMGSIZE * p) -{ - Images *pimages; - Image *img; - - pimages = (Images *) csound->QueryGlobalVariable(csound, - "imageOpcodes.images"); - img = pimages->images[(int32_t)(*p->kn)-1]; - - *(p->kw) = (MYFLT) img->w; - *(p->kh) = (MYFLT) img->h; - return OK; -} - - -static int32_t imagegetpixel (CSOUND *csound, IMGGETPIXEL * p) -{ - Images *pimages; - Image *img; - int32_t w, h, x, y; - - pimages = (Images *) csound->QueryGlobalVariable(csound, - "imageOpcodes.images"); - img = pimages->images[(int32_t)(*p->kn)-1]; - - w = img->w; - h = img->h; - - x = *p->kx*w; - y = *p->ky*h; - - if (x >= 0 && x < w && y >= 0 && y < h ) { - int32_t pixel = (w*y+x)*3; - *p->kr = img->imageData[pixel]/FL(255.0); - *p->kg = img->imageData[pixel+1]/FL(255.0); - *p->kb = img->imageData[pixel+2]/FL(255.0); - } - else { - *p->kr = FL(0.0); - *p->kg = FL(0.0); - *p->kb = FL(0.0); - } - - return OK; -} - -static int32_t imagegetpixel_a (CSOUND *csound, IMGGETPIXEL * p) -{ - Images *pimages; - Image *img; - - MYFLT *r = p->kr; - MYFLT *g = p->kg; - MYFLT *b = p->kb; - - MYFLT *tx = p->kx; - MYFLT *ty = p->ky; - - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t i, nsmps = CS_KSMPS; - int32_t w, h, x, y, pixel; - - pimages = (Images *) csound->QueryGlobalVariable(csound, - "imageOpcodes.images"); - img = pimages->images[(int32_t)(*p->kn)-1]; - w = img->w; - h = img->h; - - - if (UNLIKELY(offset)) { - memset(r, '\0', offset*sizeof(MYFLT)); - memset(g, '\0', offset*sizeof(MYFLT)); - memset(b, '\0', offset*sizeof(MYFLT)); - } - if (UNLIKELY(early)) { - nsmps -= early; - memset(&r[nsmps], '\0', early*sizeof(MYFLT)); - memset(&g[nsmps], '\0', early*sizeof(MYFLT)); - memset(&b[nsmps], '\0', early*sizeof(MYFLT)); - } - for (i = 0; i < nsmps; i++) { - - x = tx[i]*w; - y = ty[i]*h; - - if ( x >= 0 && x < w && y >= 0 && y < h ) { - pixel = (w*y+x)*3; - r[i] = img->imageData[pixel]/FL(255.0); - g[i] = img->imageData[pixel+1]/FL(255.0); - b[i] = img->imageData[pixel+2]/FL(255.0); - } - else { - r[i] = FL(0.0); - g[i] = FL(0.0); - b[i] = FL(0.0); - } - } - - return OK; -} - -static int32_t imagesetpixel_a (CSOUND *csound, IMGSETPIXEL * p) -{ - Images *pimages; - Image *img; - - MYFLT *r = p->kr; - MYFLT *g = p->kg; - MYFLT *b = p->kb; - - MYFLT *tx = p->kx; - MYFLT *ty = p->ky; - - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t i, nsmps = CS_KSMPS; - int32_t h,w,x, y, pixel; - - pimages = (Images *) csound->QueryGlobalVariable(csound, - "imageOpcodes.images"); - img = pimages->images[(int32_t)(*p->kn)-1]; - - w = img->w; - h = img->h; - - if (UNLIKELY(early)) nsmps -= early; - for (i = offset; i < nsmps; i++) { - - x = tx[i]*w; - y = ty[i]*h; - - if (x >= 0 && x < w && y >= 0 && y < h ) { - pixel = (w*y+x)*3; - img->imageData[pixel] = (unsigned char)(r[i]*255) % 256; - img->imageData[pixel+1] = (unsigned char)(g[i]*255) % 256; - img->imageData[pixel+2] = (unsigned char)(b[i]*255) % 256; - } - - } - - return OK; -} - -static int32_t imagesetpixel (CSOUND *csound, IMGSETPIXEL * p) -{ - Images *pimages; - Image *img; - int32_t w, h, x, y, pixel; - - pimages = (Images *) csound->QueryGlobalVariable(csound, - "imageOpcodes.images"); - img = pimages->images[(int32_t)(*p->kn)-1]; - - w = img->w; - h = img->h; - - x = *p->kx*w; - y = *p->ky*h; - - if (x >= 0 && x < w && y >= 0 && y < h ) { - pixel = (w*y+x)*3; - img->imageData[pixel] = (unsigned char)((*p->kr)*255) % 256; - img->imageData[pixel+1] = (unsigned char)((*p->kg)*255) % 256; - img->imageData[pixel+2] = (unsigned char)((*p->kb)*255) % 256; - } - return OK; -} - -static int32_t imagesave (CSOUND *csound, IMGSAVE * p) -{ - Images *pimages; - Image *img; - char filename[256]; - - strncpy(filename, (char*) (p->ifilnam->data), 254); filename[255]='\0'; - - pimages = (Images *) csound->QueryGlobalVariable(csound, - "imageOpcodes.images"); - img = pimages->images[(int32_t)(*p->kn)-1]; - - return __doSaveImage(img, filename, csound); -} - -static int32_t imagefree (CSOUND *csound, IMGSAVE * p) -{ - Images *pimages; - Image *img; - - pimages = (Images *) csound->QueryGlobalVariable(csound, - "imageOpcodes.images"); - img = pimages->images[(int32_t - )(*p->kn)-1]; - csound->Free(csound,img->imageData); - csound->Free(csound,img); - - return OK; -} - -#define S(x) sizeof(x) - -static OENTRY image_localops[] = { - { "imageload", S(IMGLOAD), 0, 1, "i", "S", (SUBR)imageload, NULL, NULL }, - { "imagecreate",S(IMGCREATE),0, 1, "i", "ii", (SUBR)imagecreate, NULL, NULL }, - { "imagesize", S(IMGSIZE), 0, 1, "ii", "i", (SUBR)imagesize, NULL, NULL }, - { "imagegetpixel", S(IMGGETPIXEL), 0, 3, "kkk", "ixx", - (SUBR)imagegetpixel, (SUBR)imagegetpixel, }, - { "imagegetpixel", S(IMGGETPIXEL), 0, 3, "aaa", "ixx", - (SUBR)imagegetpixel, (SUBR)imagegetpixel_a }, - { "imagesetpixel", S(IMGSETPIXEL), 0, 3, "", "ikkkkk", - (SUBR)imagesetpixel, (SUBR)imagesetpixel, (SUBR)imagesetpixel_a }, - { "imagesetpixel", S(IMGSETPIXEL), 0, 3, "", "iaaaaa", - (SUBR)imagesetpixel, (SUBR)imagesetpixel_a }, - { "imagesave", S(IMGSAVE), 0, 1, "", "iS", (SUBR)imagesave, NULL, NULL }, - { "imagefree", S(IMGFREE), 0, 1, "", "i", (SUBR)imagefree, NULL, NULL }, -}; - - -LINKAGE_BUILTIN(image_localops) diff --git a/6.x/src/image/imageOpcodes.h b/6.x/src/image/imageOpcodes.h deleted file mode 100644 index a1b9febd..00000000 --- a/6.x/src/image/imageOpcodes.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - * IMAGE OPCODES - * - * imageOpcodes.h - * - * Copyright (c) 2007 by Cesare Marilungo. All rights reserved. - * - * L I C E N S E - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -typedef struct -{ - unsigned char *imageData; - int32_t - w,h; -} Image; - -typedef struct -{ - Image **images; - size_t cnt; -} Images; - -typedef struct -{ - OPDS h; - MYFLT *kn; - STRINGDAT *ifilnam ; -} IMGLOAD; - -typedef struct -{ - OPDS h; - MYFLT *kn, *kw, *kh ; -} IMGCREATE; - -typedef struct -{ - OPDS h; - MYFLT *kw, *kh, *kn; -} IMGSIZE; - -typedef struct -{ - OPDS h; - MYFLT *kr,*kg,*kb, *kn, *kx,*ky; -} IMGGETPIXEL; - -typedef struct -{ - OPDS h; - MYFLT *kn,*kx,*ky,*kr,*kg,*kb; -} IMGSETPIXEL; -typedef struct -{ - OPDS h; - MYFLT *kn; - STRINGDAT *ifilnam; -} IMGSAVE; - -typedef struct -{ - OPDS h; - MYFLT *kn; -} IMGFREE; diff --git a/6.x/src/jackops/CMakeLists.txt b/6.x/src/jackops/CMakeLists.txt deleted file mode 100644 index c5ff8411..00000000 --- a/6.x/src/jackops/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -option(BUILD_JACK_OPCODES "Build the JACK related opcodes" ON) - -find_library(JACK_LIB NAMES jack) -find_path (JACK_INCLUDE_DIR jack/jack.h HINTS /usr/local/include) - -check_deps(BUILD_JACK_OPCODES JACK_LIB) - -if(BUILD_JACK_OPCODES AND JACK_LIB) - - list(APPEND jack_LIBS ${JACK_LIB}) - - make_plugin(jacko jacko.cpp "${jack_LIBS}") - target_include_directories(jacko PRIVATE ${CSOUND_INCLUDE_DIRS}) - target_include_directories(jacko PRIVATE ${JACK_INCLUDE_DIR}) - set_property(TARGET jacko PROPERTY CXX_STANDARD 20) - set_property(TARGET jacko PROPERTY CXX_STANDARD_REQUIRED On) - set_property(TARGET jacko PROPERTY CXX_EXTENSIONS Off) - - make_plugin(jackTransport jackTransport.c "${jack_LIBS}") - target_include_directories(jackTransport PRIVATE ${CSOUND_INCLUDE_DIRS}) - target_include_directories(jackTransport PRIVATE ${JACK_INCLUDE_DIR}) - -endif() diff --git a/6.x/src/jackops/OpcodeBase.hpp b/6.x/src/jackops/OpcodeBase.hpp deleted file mode 100644 index 21ca8a0c..00000000 --- a/6.x/src/jackops/OpcodeBase.hpp +++ /dev/null @@ -1,492 +0,0 @@ -/* - OpcodeBase.hpp: - - Copyright (C) 2005, 2009, 2017 by Istva Varga, Victor Lazzarini and - Michael Gogins - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ -#pragma once - -/** - * There is a conflict between the preprocessor definition "_CR" in the - * standard C++ library and in Csound. To work around this, undefine "_CR" and - * include ALL standard library include files BEFORE including ANY Csound - * include files. - */ -#if defined(_CR) -#undef _CR -#endif - -#include -#include -#include -#if !(defined(__wasi__)) -#include -#endif -#include -#include -#include -#include - -/** - * Template base class, or pseudo-virtual base class, - * for writing Csound opcodes in C++. - * Derive opcode implementation classes like this: - * - * DerivedClass : public OpcodeBase - * { - * public: - * // All output fields must be declared first as MYFLT *: - * MYFLT *aret1; - * // All input fields must be declared next as MYFLT *: - * MYFLT *iarg1; - * MYFLT *karg2; - * MYFLT *aarg3; - * // All internal state variables must be declared after that: - * size_t state1; - * double state2; - * MYFLT state3; - * // If the opcode shares data protect it by creating one or more void - * // *mutex member pointers: - * void *mutex1; - * void *mutex2; - * // and create them usind csound->Create_Mutex() in csoundModuleCreate - * // and destroy them using csound->DeleteMutex(mutex) - * // csoundModuleDestroy, and lock them using LockGuard guard(mutex). - * int init(); - * int kontrol(); - * int audio; - * int noteoff(); - * void deinit(); - * }; - */ - -namespace csound { - -static bool diagnostics_enabled = false; - -/** - * Use this to guard against data races in opcode functions. The mutex should - * be created by csound->Create_Mutex() in csoundModuleCreate(), and should - * be destroyed by csound->DeleteMutex() in csoundModuleDestroy(). - * - * If data is shared between opcode instances, the mutex should be global to - * the opcode library; if data is shared between threads for a single instance, - * the mutex should belong to the opcode instance. - */ -struct LockGuard { - LockGuard(CSOUND *csound_, void *mutex_) : csound(csound_), mutex(mutex_) - { - csound->LockMutex(mutex); - } - ~LockGuard() - { - csound->UnlockMutex(mutex); - } - CSOUND *csound; - void *mutex; -}; - -/** - * Use this to store a pointer to a global heap-allocated object, e.g. one - * used to manage state between opcode instances. - */ - -template int CreateGlobalPointer(CSOUND *csound, const char *name, T *pointer) -{ - T **pointer_to_pointer = 0; - int result = csound->CreateGlobalVariable(csound, name, sizeof(pointer_to_pointer)); - pointer_to_pointer = static_cast(csound->QueryGlobalVariable(csound, name)); - *pointer_to_pointer = pointer; - return result; -} - -/** - * Retrieve a pointer to a global heap-allocated object, e.g. one - * used to manage state between opcode instances. - */ -template T *QueryGlobalPointer(CSOUND *csound, const char *name, T*& pointer) -{ - T **pointer_to_pointer = static_cast(csound->QueryGlobalVariableNoCheck(csound, name)); - if (pointer_to_pointer != 0) { - pointer = *pointer_to_pointer; - } else { - pointer = 0; - } - return pointer; -} - -template -class OpcodeBase -{ -public: - int init(CSOUND *csound) - { - return NOTOK; - } - static int init_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->init(csound); - } - int kontrol(CSOUND *csound) - { - return NOTOK; - } - static int kontrol_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->kontrol(csound); - } - int audio(CSOUND *csound) - { - return NOTOK; - } - static int audio_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->audio(csound); - } - /** - This is how to compute audio signals for normal opcodes: - (1) Zero all frames from 0 up to but not including Offset. - (2) Compute all frames from ksmps_offset up to but not including End. - (3) Zero all frames from End up to but not including ksmps. - Example from a C opcode: - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); - } - for (n = offset; n < nsmps; n++) { - input1 = MYFLT2LRND(p->a[n]); - p->r[n] = (MYFLT) (input1 >> input2); - } - So in C++ it should look like this (which is much easier to understand): - int frameIndex = 0; - for( ; frameIndex < kperiodOffset(); ++frameIndex) { - asignal[frameIndex] = 0; - } - for( ; frameIndex < kperiodEnd(); ++frameIndex) { - asignal[frameIndex] = compute(); - } - for( ; frameIndex < ksmps(); ++frameIndex) { - asignal[frameIndex] = 0; - } - */ - uint32_t kperiodOffset() const - { - return opds.insdshead->ksmps_offset; - } - uint32_t kperiodEnd() const - { - uint32_t end = opds.insdshead->ksmps_no_end; - if (end) { - return end; - } else { - return ksmps(); - } - } - uint32_t ksmps() const - { - return opds.insdshead->ksmps; - } - uint32_t output_arg_count() - { - return (uint32_t)opds.optext->t.outArgCount; - } - uint32_t input_arg_count() - { - return (uint32_t)opds.optext->t.inArgCount; - } - void log(CSOUND *csound, const char *format,...) - { - va_list args; - va_start(args, format); - if(csound) { - csound->MessageV(csound, 0, format, args); - } else { - vfprintf(stdout, format, args); - } - va_end(args); - } - void warn(CSOUND *csound, const char *format,...) - { - if(csound) { - if(csound->GetMessageLevel(csound) & CS_WARNMSG) { - va_list args; - va_start(args, format); - csound->MessageV(csound, CSOUNDMSG_WARNING, format, args); - va_end(args); - } - } else { - va_list args; - va_start(args, format); - vfprintf(stdout, format, args); - va_end(args); - } - } - OPDS opds; -}; - -template -class OpcodeNoteoffBase -{ -public: - int init(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int init_(CSOUND *csound, void *opcode) - { - if (!csound->GetReinitFlag(csound) && !csound->GetTieFlag(csound)) { - csound->RegisterDeinitCallback(csound, opcode, - &OpcodeNoteoffBase::noteoff_); - } - return reinterpret_cast(opcode)->init(csound); - } - int kontrol(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int kontrol_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->kontrol(csound); - } - int audio(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int audio_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->audio(csound); - } - /** - This is how to compute audio signals for normal opcodes: - (1) Zero all frames from 0 up to but not including Offset. - (2) Compute all frames from ksmps_offset up to but not including End. - (3) Zero all frames from End up to but not including ksmps. - Example from a C opcode: - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); - } - for (n = offset; n < nsmps; n++) { - input1 = MYFLT2LRND(p->a[n]); - p->r[n] = (MYFLT) (input1 >> input2); - } - So in C++ it should look like this (which is much easier to understand): - int frameIndex = 0; - for( ; frameIndex < kperiodOffset(); ++frameIndex) { - asignal[frameIndex] = 0; - } - for( ; frameIndex < kperiodEnd(); ++frameIndex) { - asignal[frameIndex] = compute(); - } - for( ; frameIndex < ksmps(); ++frameIndex) { - asignal[frameIndex] = 0; - } - */ - uint32_t kperiodOffset() const - { - return opds.insdshead->ksmps_offset; - } - uint32_t kperiodEnd() const - { - uint32_t end = opds.insdshead->ksmps_no_end; - if (end) { - return end; - } else { - return ksmps(); - } - } - uint32_t ksmps() const - { - return opds.insdshead->ksmps; - } - uint32_t output_arg_count() - { - return (uint32_t)opds.optext->t.outArgCount; - } - uint32_t input_arg_count() - { - return (uint32_t)opds.optext->t.inArgCount; - } - void log(CSOUND *csound, const char *format,...) - { - va_list args; - va_start(args, format); - if(csound) { - csound->MessageV(csound, 0, format, args); - } else { - vfprintf(stdout, format, args); - } - va_end(args); - } - void warn(CSOUND *csound, const char *format,...) - { - if(csound) { - if(csound->GetMessageLevel(csound) & CS_WARNMSG) { - va_list args; - va_start(args, format); - csound->MessageV(csound, CSOUNDMSG_WARNING, format, args); - va_end(args); - } - } else { - va_list args; - va_start(args, format); - vfprintf(stdout, format, args); - va_end(args); - } - } - int noteoff(CSOUND *csound) - { - return OK; - } - static int noteoff_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->noteoff(csound); - } - OPDS opds; -}; - -#if (__cplusplus >= 201103L) && !(defined(__wasi__)) -#pragma message("Defining heap_object_manager_t.") - -/** - * The memory of non-POD C++ or C objects allocated on the heap by Csound - * plugins is managed not by Csound, but by the plugin module. This class - * performs that function. - * - * As long as all memory is allocated in or after csoundModuleCreate and - * de-allocated in csoundModuleDestroy, all will be well. The danger however - * is that memory leaks will occur if allocations are not matched with - * de-allocations, or worse, that crashes will occur if any objects are - * deleted twice or de-referenced after deletion. - * - * So, the plugin should manage a collection of all heap-allocated objects, - * keyed first off the Csound instance, and second off an object handle; and - * all such objects must be accessed only by handle, from this collection. - * - * In csoundModuleDestroy, all objects for the calling instance of Csound - * should be de-allocated, and the sub-collection for that instance should - * also be de-allocated. - * - * If then there are no more sub-collections for other instances of Csound, - * the entire contents of the collection should be de-allocated. - * - * This should be done as a singleton, and in a thread-safe way. - * - * There might still be a problem if any of the heap-allocated objects, - * themselves, have global static members, perhaps created by some external - * dependency. - * - * Please note, objects O in the declaration below must not be std::shared_ptr - * objects. Deletion of objects herein must be unconditional. Rather, the - * objects passed are raw pointers to instances of class O. - */ - template class heap_object_manager_t { - private: - std::map> objects_; - std::recursive_mutex mutex; - heap_object_manager_t(){}; - ~heap_object_manager_t(){}; - public: - static heap_object_manager_t &instance() { - static heap_object_manager_t singleton; - return singleton; - } - std::map> &objects() { - std::lock_guard lock(mutex); - return objects_; - } - /** - * Returns a list of pointers to all objects allocated for this - * instance of Csound. - */ - std::vector &objects_for_csound(CSOUND *csound) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects()[csound]; - return objects_for_csound_; - } - /** - * Returns the handle for the object; if the object has not yet been - * stored, inserts it into the list of object pointers for this - * instance of Csound; otherwise, returns the handle of the stored - * object pointer. - */ - int handle_for_object(CSOUND *csound, O *object) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - auto iterator = std::find(objects_for_csound_.begin(), objects_for_csound_.end(), object); - if (iterator == objects_for_csound_.end()) { - int handle = objects_for_csound_.size(); - objects_for_csound_.push_back(object); - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::handle_for_object %p: new object handle: %d (of %ld)\n", object, handle, objects_for_csound_.size()); - return handle; - } else { - int handle = static_cast(iterator - objects_for_csound_.begin()); - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::handle_for_object: existing object handle: %d\n", handle); - return handle; - } - } - /** - * Returns the object pointer for the handle; - * if the object pointer has not been stored by - * handle, returns a null pointer. - */ - O *object_for_handle(CSOUND *csound, int handle) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - if (handle >= objects_for_csound_.size()) { - return nullptr; - } - O *object = objects_for_csound_[handle]; - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::object_for_handle: %p %d (of %ld)\n", object, handle, objects_for_csound_.size()); - return object; - } - /** - * First destroys all objects created by the calling - * instance of Csound, then destroys the list of - * object pointers for this instance of Csound. - */ - void module_destroy(CSOUND *csound) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - for (int i = 0, n = objects_for_csound_.size(); i < n; ++i) { - delete objects_for_csound_[i]; - objects_for_csound_[i] = nullptr; - } - objects_for_csound_.clear(); - objects().erase(csound); - } -}; - -#else -#pragma message("Not defining heap_manager_t.") -#endif - -} diff --git a/6.x/src/jackops/cs_jack.h b/6.x/src/jackops/cs_jack.h deleted file mode 100644 index c79836a4..00000000 --- a/6.x/src/jackops/cs_jack.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - .h: - - Copyright (C) 2008 by Cesare Marilungo - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#define MAX_NAME_LEN 32 /* for client and port name */ - -typedef struct RtJackBuffer_ { -#ifdef LINUX - pthread_mutex_t csndLock; /* signaled by process callback */ - pthread_mutex_t jackLock; /* signaled by audio thread */ -#else - void *csndLock; /* signaled by process callback */ - void *jackLock; /* signaled by audio thread */ -#endif - jack_default_audio_sample_t **inBufs; /* 'nChannels' capture buffers */ - jack_default_audio_sample_t **outBufs; /* 'nChannels' playback buffers */ -} RtJackBuffer; - -typedef struct RtJackGlobals_ { - CSOUND *csound; /* Csound instance pointer */ - int jackState; /* 0: OK, 1: sr changed, 2: quit */ - char clientName[MAX_NAME_LEN + 1]; /* client name */ - char inputPortName[MAX_NAME_LEN + 1]; /* input port name prefix */ - char outputPortName[MAX_NAME_LEN + 1]; /* output port name prefix */ - int sleepTime; /* sleep time in us (deprecated) */ - char *inDevName; /* device name for -i adc */ - char *outDevName; /* device name for -o dac */ - int sampleRate; /* sample rate in Hz */ - int nChannels; /* number of channels */ - int nChannels_i; /* number of in channels */ - int bufSize; /* buffer size in sample frames */ - int nBuffers; /* number of buffers (>= 2) */ - int inputEnabled; /* non-zero if capture (adc) is on */ - int outputEnabled; /* non-zero if playback (dac) is on */ - int csndBufCnt; /* current buffer in Csound thread */ - int csndBufPos; /* buffer position in Csound thread */ - int jackBufCnt; /* current buffer in JACK callback */ - int jackBufPos; /* buffer position in JACK callback */ - jack_client_t *client; /* JACK client pointer */ - jack_port_t **inPorts; /* 'nChannels' ports for capture */ - jack_default_audio_sample_t **inPortBufs; - jack_port_t **outPorts; /* 'nChannels' ports for playback */ - jack_default_audio_sample_t **outPortBufs; - RtJackBuffer **bufs; /* 'nBuffers' I/O buffers */ - int xrunFlag; /* non-zero if an xrun has occured */ - jack_client_t *listclient; - int outDevNum, inDevNum; /* select devs by number */ -} RtJackGlobals; diff --git a/6.x/src/jackops/jackTransport.c b/6.x/src/jackops/jackTransport.c deleted file mode 100644 index 03d0e79c..00000000 --- a/6.x/src/jackops/jackTransport.c +++ /dev/null @@ -1,98 +0,0 @@ -/** - * jack_transport.c - * - * Copyright (c) 2008 by Cesare Marilungo. All rights reserved. - * - * L I C E N S E - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * U S A G E - * - * jack_transport 1 - to start jack transport - * - * jack_transport 0 - to stop - * - * the second optional parameter tells where the transport should be located - * - */ - -#include -#include -#include - -#include "cs_jack.h" - -enum { STOP, START }; - -typedef struct -{ - OPDS h; - MYFLT *command; - MYFLT *location; -} JACKTRANSPORT; - -static int32_t jack_transport (CSOUND *csound, JACKTRANSPORT * p) -{ - RtJackGlobals *rtjack; - jack_client_t *client; - - rtjack = (RtJackGlobals*) - csound->QueryGlobalVariableNoCheck(csound, - "_rtjackGlobals"); - client = rtjack->client; - - if (UNLIKELY(client == NULL)) { - return csound->InitError(csound, "%s", Str("Cannot find Jack client.\n")); - } - else { - //move to specified location (in seconds) - if ((int32_t)(*p->location)>=0) { - MYFLT loc_sec = *p->location; - MYFLT loc_sec_per_sr = loc_sec*csound->GetSr(csound); - jack_transport_locate(client, loc_sec_per_sr); - csound->Warning(csound, - Str("jacktransport: playback head moved " - "at %f seconds\n"), loc_sec); - } - //start or stop - switch ((int32_t - )(*p->command)) { - case START: - csound->Warning(csound, "%s", Str("jacktransport: playing.\n")); - jack_transport_start(client); - break; - case STOP: - csound->Warning(csound, "%s", Str("jacktransport: stopped.\n")); - jack_transport_stop(client); - break; - default: - csound->Warning(csound, "%s", Str("jacktransport: invalid parameter.\n")); - break; - } - } - - return OK; -} - -#define S(x) sizeof(x) - -static OENTRY jackTransport_localops[] = { - - { "jacktransport", S(JACKTRANSPORT), 0, 1, "", "ij", - (SUBR)jack_transport, NULL, NULL }, -}; - -LINKAGE_BUILTIN(jackTransport_localops) diff --git a/6.x/src/jackops/jacko.cpp b/6.x/src/jackops/jacko.cpp deleted file mode 100644 index 14021b43..00000000 --- a/6.x/src/jackops/jacko.cpp +++ /dev/null @@ -1,1468 +0,0 @@ -/* -jacko.cpp: - -Copyright (C) 2010, 2023 by Michael Gogins - -This file is part of Csound. - -The Csound Library is free software; you can redistribute it -and/or modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -Csound is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with Csound; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA -02110-1301 USA -*/ - -/** -* T H E J A C K O O P C O D E S -* Michael Gogins -* -* The Jacko opcodes can be used to connect any number of Csound instances, -* instruments, or user-defined opcodes to any number of Jack ports in any -* number of external Jack servers. Both audio and MIDI signal types are -* supported. -* -* Sending MIDI and/or audio to external Jack clients, such as synthesizers, -* and receiving audio and/or MIDI back from them, is supported. -* -* Receiving MIDI and/or audio from external Jack clients, such as sequencers, -* and sending MIDI and/or audio back to them, is supported. -* -* Other uses also are supported. -* -* The Jacko opcodes do not read or write the Csound input or output buffers; -* the opcodes read Jack inputs to Csound audio rate variables, and write -* audio rate variables to Jack outputs. This provides increased flexibility. -* -* NOTE: Using Jacko with `-+rtaudio=jack`is not advisable. -* -* O P C O D E S -* -* JackoInit -- Initializes Csound as a Jack client. -* -* Description -* -* Initializes this instance of Csound as a Jack client. -* -* Csound's sr must be equal to the Jack daemon's -* frames per second. -* -* Csound's ksmps must be equal to the Jack daemon's -* frames per period. -* -* Frames per period must not only (a) be a power of 2, -* but also (b) go evenly into the frames per second, -* e.g. 128 frames per period goes into 48000 -* frames per second 375 times, for a latency or -* MIDI time granularity of about 2.7 milliseconds -* (as good as or better than the absolute best -* human performers). -* -* The order of processing of all signals that pass -* from Jack input ports, through Csound processing, -* and to Jack output ports, must be properly -* determined by sequence of instrument and -* opcode definition within the Csound orchestra. -* -* Syntax -* -* JackoInit SclientName, ServerName -* -* Initialization -* -* SclientName -- The name of the Jack client; -* normally, should be "csound". -* -* ServerName -- The name of the Jack daemon; -* normally, will be "default". -* -* This opcode must be called once and only once in the -* orchestra header, and before any other Jack opcodes. -* If more than one instance of Csound is using the Jack -* opcodes at the same time, then each instance of Csound -* must use a different client name. -* -* -* JackoInfo -- Prints information about the Jack system. -* -* Description -* -* Prints the Jack daemon and client names, the -* sampling rate and frames per period, -* and all active Jack port names, -* types, states, and connections. -* -* Syntax -* -* JackoInfo -* -* Initialization -* -* May be called any number of times in the orchestra header, -* for example both before and after creating Jack ports -* in the Csound orchestra header. -* -* -* JackoFreewheel -- Turns freewheeling mode on or off. -* -* Description -* -* Turns Jack's freewheeling mode on or off. -* -* When freewheeling is on, if supported by the rest -* of the Jack system, Csound will run as fast as possible, -* which may be either faster or slower than real time. -* -* This is essential for rendering scores that are too -* dense for real-time jacko_is_driving to a soundfile, -* without xruns or dropouts. -* -* Syntax -* -* JackoFreewheel [ienabled] -* -* Initialization -* -* ienabled -- Turns freewheeling on (the default) or off. -* -* -* JackoAudioInConnect -- Creates an audio connection -* from a Jack port to Csound. -* -* Description -* -* In the orchestra header, creates an audio connection -* from an external Jack audio output port to a -* Jack audio input port inside this instance of Csound. -* -* Syntax -* -* JackoAudioInConnect SexternalPortName, ScsoundPortName -* -* Initialization -* -* SexternalPortName -- The full name ("clientname:portname") -* of an external Jack audio output port. -* -* ScsoundPortName -- The short name ("portname") -* of the internal Jack audio input port. -* -* Performance -* -* The actual audio must be read with the JackoAudioIn opcode. -* -* -* JackoAudioOutConnect -- Creates an audio connection -* from Csound to a Jack port. -* -* Description -* -* In the orchestra header, creates an audio connection -* from a Jack audio output port inside this instance -* of Csound to an external Jack audio input port. -* -* Syntax -* -* JackoAudioOutConnect ScsoundPortName, SexternalPortName -* -* Initialization -* -* ScsoundPortName -- The short name ("portname") -* of the internal Jack audio input port. -* -* SexternalPortName -- The full name ("clientname:portname") -* of an external Jack audio output port. -* -* Performance -* -* The actual audio must be written with the JackoAudioOut -* opcode. -* -* -* JackoMidiInConnect -- Creates a MIDI connection from -* Jack to Csound. -* -* Description -* -* Creates a MIDI connection from an external Jack MIDI -* output port to this instance of Csound. -* -* Syntax -* -* JackoMidiInConnect SexternalPortName, ScsoundPortName -* -* Initialization -* -* SexternalPortName -- The full name ("clientname:portname") -* of an external Jack MIDI output port. -* -* ScsoundPortName -- The short name ("portname") -* of the internal Jack MIDI input port. -* -* Must be used in conjunction with the -* -M0 -+rtmidi=null Csound command-line options. -* Can be used in with the MIDI inter-operability -* command-line options and/or opcodes to enable the -* use of ordinary Csound instrument definitions to -* render external scores or MIDI sequences. -* -* Note that Csound can connect to ALSA ports through Jack, -* but in this case you will have to identify the port by -* its alias in the JackInfo printout. -* -* Performance -* -* The actual MIDI events will be received in the -* regular Csound way, i.e. through a MIDI driver -* and the sensevents mechanism, rather than through -* a Jack input port opcode. -* -* The granularity of timing is Csound's kperiod. -* -* -* JackoMidiOutConnect -- Creates a MIDI connection from -* Csound to Jack. -* -* Description -* -* In the orchestra header, creates a connection -* from a Jack MIDI output port inside this instance -* of Csound to an external Jack MIDI input port. -* -* Syntax -* -* JackoMidiOutConnect ScsoundPortName, SexternalPortName -* -* Initialization -* -* ScsoundPortName -- The short name ("portname") -* of the internal Jack audio input port. -* -* SexternalPortName -- The full name ("clientname:portname") -* of an external Jack audio output port. -* -* Performance -* -* The actual MIDI data must be written with the JackoMidiOut -* or JackoNoteOut opcodes. -* -* -* JackoOn -- Enables or disables all Jack ports. -* -* Description -* -* After all Jack connections have been created, enables -* or disables all Jack input and output opcodes -* inside this instance of Csound to read or write data. -* -* Syntax -* -* JackoOn [iactive] -* -* Initialization -* -* iactive -- A flag that turns the ports on (the default) -* or off. -* -* -* JackoAudioIn -- Receives an audio signal from a Jack port. -* -* Description -* -* Receives an audio signal from a Jack audio input port -* inside this instance of Csound, which in turn has -* received the signal from its connected external Jack -* audio output port. -* -* Syntax -* -* asignal JackoAudioIn ScsoundPortName -* -* Initialization -* -* ScsoundPortName -- The short name ("portname") -* of the internal Jack audio input port. -* -* Performance -* -* asignal -- Audio received from the external Jack -* output port to which ScsoundPortName is connected. -* -* -* JackoAudioOut -- Sends an audio signal to a Jack port. -* -* Description -* -* Sends an audio signal to an internal Jack audio -* output port, and in turn to its connected external -* Jack audio input port. -* -* Note that it is possible to send audio out via Jack -* to the system audio interface, while at the same time -* rendering to a regular Csound output soundfile. -* -* Syntax -* -* JackoAudioOut ScsoundPortName, asignal -* -* Initialization -* -* ScsoundPortName -- The short name ("portname") -* of the internal Jack audio output port. -* -* Performance -* -* asignal -- Audio to be sent to the external Jack audio -* input port to which CsoundPortName is connected. -* -* Audio from multiple instances of the opcode sending -* to the same Jack port is summed before sending. -* -* -* JackoMidiOut -- Sends a MIDI channel message to a -* Jack port. -* -* Description -* -* Sends a MIDI channel message to a Jack MIDI output port -* inside this instance of Csound, and in turn to its -* connected external Jack MIDI input port. -* -* Syntax -* -* JackoMidiOut ScsoundPortName, kstatus, kchannel, kdata1[, kdata2] -* -* Initialization -* -* ScsoundPortName -- The short name ("portname") -* of the internal Jack MIDI input port. -* -* Performance -* -* kstatus -- MIDI status byte; must indicate a MIDI channel -* message. -* -* kchannel -- MIDI channel (from 0 through 15). -* -* kdata1 -- First data byte of a MIDI channel message. -* -* kdata2 -- Optional second data byte of a MIDI channel message. -* -* This opcode can be called any number of times -* in the same kperiod. Messages from multiple instances -* of the opcode sending to the same port are collected -* before sending. -* -* Running status, system exclusive messages, and -* real-time messages are not supported. -* -* The granularity of timing is Csound's kperiod. -* -* -* JackoNoteOut -- Send one note to a Jack MIDI port. -* -* Description -* -* Sends one note to a Jack MIDI output port inside this -* instance of Csound, and in turn to the connected external -* Jack MIDI input port, with a duration -* specified by the score instrument statement. -* The matching MIDI note off message is generated -* and scheduled for later transmission. -* -* Notes from multiple instances of the opcode -* sending to the same output port are collected -* before sending. -* -* The granularity of timing is Csound's kperiod. -* -* Syntax -* -* JackoNoteOut ScsoundPortName, ichannel, ikey, ivelocity -* -* Initialization -* -* ScsoundPortName -- The short name ("portname") of the -* Jack MIDI output port created by jackmidioutconnect. -* -* ichannel -- The MIDI channel (from 0 through 15) to -* receive the note. -* -* ikey -- The MIDI key number (from 0 through 127, 60 is -* middle C) of the note. -* -* ivelocity -- The MIDI velocity number (from 0 through 127) -* of the note. -* -* -* JackoTransport -- Control the Jack transport. -* -* Description -* -* Starts, stops, or repositions the Jack transport. -* This is useful, e.g., for starting an external sequencer -* playing to send MIDI messages to Csound. -* -* Syntax -* -* JackoTransport kcommand, [kposition] -* -* Performance -* -* kcommand -- 0 means "no action", 1 starts the transport, -* 2 stops the transport, and 3 positions the transport -* to kposition seconds from the beginning of jacko_is_driving -* (i.e. time 0 in the score). -* -* This opcode can be used at init time or during jacko_is_driving. -* -* The granularity of timing is Csound's kperiod. -* -* -* I M P L E M E N T A T I O N -* -* Processing is done according to the callback model: -* -* 1. The jackinit opcode: -* 1.1. Creates a Jack client, -* which is associated with the -* running instance of Csound. -* 1.2. Registers a JackProcessCallback with Jack. -* 1.3. Registers a SenseEventCallback with Csound. -* 1.4. Installs a MIDI driver callback to consume -* MIDI events coming from Jack input ports. -* 1.5. Puts the Csound processing thread to sleep. -* 1.6. Activates the client. -* 2. The ports are created and connected in the orchestra header. -* 3. After all ports are connected, they are turned on in the -* orchestra header. -* 4. Every time the Jack callback fires: -* 4.1. Any MIDI events pending in the input ports are enqueued -* for dispatch via the MIDI driver callack through -* Csound's normal sensevents mechanism. -* 4.2. csoundPerformKsmps is called. -* 4.3. When the Csound jacko_is_driving is finished: -* 4.3.1. The Csound processing thread is re-awakened. -* 4.3.2. The Jack processing callback is deactivated. -* 4.3.2. The Jack client is closed. -* 5. At the end of processing, the module deinitialization -* function erases all Jack-related state. -*/ -#include "OpcodeBase.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -/// #include -#include -#include -#include -#include - -using namespace csound; - -struct JackoInit; -struct JackoInfo; -struct JackoFreewheel; -struct JackoAudioIn; -struct JackoAudioOut; -struct JackoMidiOut; -struct JackoNoteOut; -struct JackoTransport; -struct JackoState; - -/** -* There is one and only one JackoState instance per instance of Csound. -* It is created by and only by the JackoInit opcode. -*/ - -static void SenseEventCallback_(CSOUND *csound, void *data); -static int JackProcessCallback_(jack_nframes_t frames, void *data); -static int midiDeviceOpen_(CSOUND *csound, void **userData, - const char *devName); - -static int midiRead_(CSOUND *csound, void *userData, unsigned char *midiData, - int nbytes); - -/** -* Manages all state relevant to the global -* interaction between Jack and Csound for a particular -* client and instance of Csound. The actual reading -* and writing of data is done by the input and output -* opcodes. -*/ -struct JackoState { - CSOUND *csound; - const char *serverName; - const char *clientName; - jack_client_t *jackClient; - std::atomic jacko_is_driving; - std::atomic jacko_has_finished; - jack_nframes_t csoundFramesPerTick; - jack_nframes_t jackFramesPerTick; - jack_nframes_t csoundFramesPerSecond; - jack_nframes_t jackFramesPerSecond; - jack_nframes_t jackFrameTime; - std::map audioInPorts; - std::map audioOutPorts; - std::map midiInPorts; - std::map midiOutPorts; - std::list midiInputQueue; - jack_position_t jack_position; - std::thread *closeThread; - std::mutex csoundPerformanceThreadConditionMutex; - std::condition_variable csoundPerformanceThreadCondition; - size_t sample_size; - JackoState(CSOUND *csound_, const char *serverName_, const char *clientName_) - : csound(csound_), serverName(serverName_), clientName(clientName_), - jacko_is_driving(false), /*jack_active(false),*/ jacko_has_finished(true) { - int result = 0; - csound = csound_; - sample_size = sizeof(jack_default_audio_sample_t); - csoundFramesPerTick = csound->GetKsmps(csound); - csoundFramesPerSecond = csound->GetSr(csound); - std::memset(&jack_position, 0, sizeof(jack_position_t)); - jack_options_t jack_options = - (jack_options_t)(JackServerName | JackNoStartServer | JackUseExactName); - jack_status_t status = jack_status_t(0); - jackClient = - jack_client_open(clientName, jack_options, &status, serverName); - csound->Message(csound, - "jack_client_open: status: %d\n", - status); - if (!jackClient) { - csound->Message(csound, - "Could not create Jack client \"%s\" -- is Jack server \"%s\" running? Status: %d\n", - clientName, serverName, status); - csound->LongJmp(csound, 1); - } else { - csound->Message( - csound, "Created Jack client \"%s\" for Jack server \"%s\". Status: %d\n", - clientName, serverName, status); - } - jackFramesPerTick = jack_get_buffer_size(jackClient); - if (csoundFramesPerTick != jackFramesPerTick) { - csound->Message( - csound, "Jack buffer size %d != Csound ksmps %d, exiting...\n", - jackFramesPerTick, csoundFramesPerTick); - csound->LongJmp(csound, 1); - } - jackFramesPerSecond = jack_get_sample_rate(jackClient); - if (csoundFramesPerSecond != jackFramesPerSecond) { - csound->Message( - csound, "Jack sampling rate %d != Csound sr %d, exiting...\n", - jackFramesPerSecond, csoundFramesPerSecond); - csound->LongJmp(csound, 1); - } - csound->SetExternalMidiInOpenCallback(csound, midiDeviceOpen_); - csound->SetExternalMidiReadCallback(csound, midiRead_); - csound->RegisterSenseEventCallback(csound, SenseEventCallback_, this); - jacko_has_finished = false; - result |= jack_set_process_callback(jackClient, JackProcessCallback_, this); - result |= jack_activate(jackClient); - if (!result) { - csound->Message(csound, "Activated Jack client \"%s\".\n", - jack_get_client_name(jackClient)); - } else { - csound->Message( - csound, "Failed to activate Jack client \"%s\": status %d.\n", - jack_get_client_name(jackClient), result); - return; - } - } - ~JackoState() { - } - int SenseEventCallback() { - int result = 0; - if (jacko_has_finished) { - return result; - } -// Here we must wait once and only once, in order to put -// the original Csound processing thread to sleep -- -// but we must NOT put the Jack processing callback -// to sleep when it comes here! - if (jacko_is_driving.load() == false) { - jacko_is_driving = true; -// While Jack is processing, wait here. -// The Jack process callback will then call csoundPerformKsmps -// until the Csound performance is complete. - csound->Message(csound, - "%s", "Jacko is now driving Csound performance...\n"); - std::unique_lock lock(csoundPerformanceThreadConditionMutex); - while (jacko_is_driving.load() == true) { - csoundPerformanceThreadCondition.wait(lock); - } - jacko_is_driving = false; - lock.unlock(); - csound->Message(csound, - "%s", "Jacko has quit driving Csound performance.\n"); - return 1; - } - return result; - } - int JackProcessCallback(jack_nframes_t frames) { - IGN(frames); - if (frames != csoundFramesPerTick) { - csound->Message(csound, "JackProcessCallback: frames (%d) != csoundFramesPerTick (%d)\n", frames, csoundFramesPerTick); - } - int result = 0; -// We must call PerformKsmps here ONLY after the original -// Csound jacko_is_driving thread is waiting on its condition. - jackFrameTime = jack_last_frame_time(jackClient); - if (jacko_is_driving.load() == true) { -// Enqueue any MIDI messages pending in input ports. - for (std::map::iterator it = - midiInPorts.begin(); - it != midiInPorts.end(); ++it) { - jack_port_t *midiinport = it->second; - void *portbuffer = jack_port_get_buffer(midiinport, jackFramesPerTick); - if (portbuffer) { - jack_nframes_t eventN = jack_midi_get_event_count(portbuffer); - for (jack_nframes_t eventI = 0; eventI < eventN; ++eventI) { - jack_midi_event_t event; - int result = jack_midi_event_get(&event, portbuffer, eventI); - if (result == 0) { - for (size_t i = 0; i < event.size; ++i) { - midiInputQueue.push_back(event.buffer[i]); - } - } - } - } - } -// Clear MIDI output buffers. - for (std::map::iterator it = - midiOutPorts.begin(); - it != midiOutPorts.end(); ++it) { - void *buffer = jack_port_get_buffer(it->second, jackFramesPerTick); - jack_midi_clear_buffer(buffer); - } - int finished = csound->PerformKsmps(csound); -// We break here when the Csound performance is complete, and close -// the Jack connection in a separate thread. - if (finished /* && jack_active */) { - jacko_has_finished = true; - jacko_is_driving = false; - csound->Message(csound, "%s", "Csound performance driven by Jack has finished.\n"); -// Create a thread to run the close routine. - closeThread = new std::thread(&JackoState::closeThreadRoutine, this); - return finished; - } - } - return result; - } - int close() { - jacko_has_finished = true; - csound->Message(csound, "%s", "JackoState::close...\n"); - jacko_is_driving = false; - int result = OK; -// Try not to do thread related operations more than once... - result = jack_deactivate(jackClient); - csound->Message(csound, "%s", "Jack client deactivated.\n"); -// Jack documentation says deactivating the client does the following also: - for (std::map::iterator it = - audioInPorts.begin(); - it != audioInPorts.end(); ++it) { - result = jack_port_unregister(jackClient, it->second); - } - for (std::map::iterator it = - audioOutPorts.begin(); - it != audioOutPorts.end(); ++it) { - result = jack_port_unregister(jackClient, it->second); - } - for (std::map::iterator it = - midiInPorts.begin(); - it != midiInPorts.end(); ++it) { - result = jack_port_unregister(jackClient, it->second); - } - for (std::map::iterator it = - midiOutPorts.begin(); - it != midiOutPorts.end(); ++it) { - result = jack_port_unregister(jackClient, it->second); - } - csound->Message(csound, "%s", "Jack ports unregistered.\n"); - result |= jack_client_close(jackClient); - csound->Message(csound, "%s", "Jack client closed.\n"); - std::unique_lock lock(csoundPerformanceThreadConditionMutex); - csoundPerformanceThreadCondition.notify_one(); - lock.unlock(); - audioOutPorts.clear(); - audioInPorts.clear(); - midiInPorts.clear(); - midiOutPorts.clear(); - csound->Message(csound, "%s", "JackoState::close.\n"); - return result; - } - void *closeThreadRoutine() { - int result = 0; - close(); - void *result_ = 0; - memcpy(&result_, &result, std::min(sizeof(result), sizeof(result_))); - return result_; - } - static void *closeThreadRoutine_(void *userdata) { - void *result = ((JackoState *)userdata)->closeThreadRoutine(); - return result; - } - void startTransport() { - midiInputQueue.clear(); - jack_transport_start(jackClient); - } - void stopTransport() { - jack_transport_stop(jackClient); - } - int positionTransport(double timeSeconds) { - int result = OK; - jack_position.frame_time = timeSeconds; - midiInputQueue.clear(); - result = jack_transport_reposition(jackClient, &jack_position); - return result; - } - /** - * Return a MIDI output buffer, - * clearing it if not yet cleared for this tick. - */ - jack_midi_data_t *getMidiOutBuffer(jack_port_t *csoundPort) { - jack_midi_data_t *buffer = (jack_midi_data_t *)jack_port_get_buffer( - csoundPort, csoundFramesPerTick); - return buffer; - } -}; - -static int JackProcessCallback_(jack_nframes_t frames, void *data) { - return ((JackoState *)data)->JackProcessCallback(frames); -} - -static void SenseEventCallback_(CSOUND *csound, void *data) { - IGN(csound); - ((JackoState *)data)->SenseEventCallback(); -} - -static int midiDeviceOpen_(CSOUND *csound, void **userData, - const char *devName) { - IGN(devName); - JackoState *jackoState; - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - *userData = jackoState; - return 0; -} - -/** -* Dispatch any MIDI channel messages that have -* been read from Jack MIDI input ports. -*/ -static int midiRead_(CSOUND *csound, void *userData, unsigned char *midiData, - int midiN) { - IGN(csound); - JackoState *jackoState_ = (JackoState *)userData; - if (jackoState_->jacko_has_finished == true) { - return 0; - } - int midiI = 0; - while (!jackoState_->midiInputQueue.empty() && midiI < midiN) { - midiData[midiI] = jackoState_->midiInputQueue.front(); - jackoState_->midiInputQueue.pop_front(); - midiI++; - } -// if (midiI) { -// csound->Message(csound, "midiRead_: %d bytes.\n", midiI); -//} - return midiI; -} - -struct JackoInit : public OpcodeBase { - STRINGDAT *ServerName; - STRINGDAT *SclientName; - const char *serverName; - const char *clientName; - int init(CSOUND *csound) { - serverName = csound->strarg2name(csound, (char *)0, ServerName->data, - (char *)"default", (int)1); - clientName = csound->strarg2name(csound, (char *)0, SclientName->data, - (char *)"csound", (int)1); - JackoState *jackoState = new JackoState(csound, serverName, clientName); - int result = csound::CreateGlobalPointer(csound, "jackoState", jackoState); - return result; - } -}; - -struct JackoInfo : public OpcodeBase { - int init(CSOUND *csound) { - JackoState *jackoState = 0; - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - log(csound, "Jack information for client: %s\n", jackoState->clientName); - log(csound, " Daemon name: %s\n", jackoState->serverName); - log(csound, " Frames per second: %d\n", - jackoState->jackFramesPerSecond); - log(csound, " Frames per period: %d\n", - jackoState->jackFramesPerTick); - const char **ports = jack_get_ports(jackoState->jackClient, 0, 0, 0); - if (ports) { - log(csound, " Ports and connections:\n"); - for (size_t i = 0; ports[i]; ++i) { - const char *PortName = ports[i]; - jack_port_t *port = jack_port_by_name(jackoState->jackClient, PortName); - int flags = jack_port_flags(port); - const char *type = jack_port_type(port); - const char *portType = " "; - if ((flags & JackPortIsOutput) == JackPortIsOutput) { - portType = "Output"; - } else if ((flags & JackPortIsInput) == JackPortIsInput) { - portType = "Input "; - } - log(csound, " %3d: %s %-25s %s\n", (i + 1), portType, type, - (PortName ? PortName : "(no name)")); - char alias1[0x100]; - char alias2[0x100]; - char *const aliases[2] = {alias1, alias2}; - size_t aliasN = jack_port_get_aliases(port, aliases); - for (size_t aliasI = 0; aliasI < aliasN; ++aliasI) { - log(csound, " Alias: %s\n", aliases[aliasI]); - } - const char **connections = - jack_port_get_all_connections(jackoState->jackClient, port); - if (connections) { - for (size_t j = 0; connections[j]; ++j) { - if ((jack_port_flags(port) & JackPortIsOutput) == - JackPortIsOutput) { - log(csound, - " Sends to: >> %s\n", - connections[j]); - } else { - log(csound, - " Receives from: << %s\n", - connections[j]); - } - } - } - std::free(connections); - } - std::free(ports); - } - return OK; - } -}; - -struct JackoFreewheel : public OpcodeBase { - MYFLT *ifreewheel; - int init(CSOUND *csound) { - JackoState *jackoState = 0; - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - int freewheel = (int)*ifreewheel; - int result = jack_set_freewheel(jackoState->jackClient, freewheel); - if (result) { - warn(csound, - "Failed to set Jack freewheeling mode to \"%s\": error %d.\n", - (freewheel ? "on" : "off"), result); - } else { - log(csound, "Set Jack freewheeling mode to \"%s\".\n", - (freewheel ? "on" : "off")); - } - return result; - } -}; - -struct JackoOn : public OpcodeBase { - MYFLT *jon; - int init(CSOUND *csound) { - int result = OK; - JackoState *jackoState = 0; - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - log(csound, "JackoOn is deprecated and now is a no-op.\n"); - return result; - } -}; - -struct JackoAudioInConnect : public OpcodeBase { -// Out. -// Ins. - STRINGDAT *SexternalPortName; - STRINGDAT *ScsoundPortName; -// State. - const char *csoundPortName; - char csoundFullPortName[0x100]; - const char *externalPortName; - const char *clientName; - size_t frames; - jack_port_t *csoundPort; - jack_port_t *externalPort; - JackoState *jackoState; - int init(CSOUND *csound) { - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - int result = OK; - frames = opds.insdshead->ksmps; - clientName = jack_get_client_name(jackoState->jackClient); - csoundPortName = csound->strarg2name( - csound, (char *)0, ScsoundPortName->data, (char *)"", (int)1); - std::sprintf(csoundFullPortName, "%s:%s", clientName, csoundPortName); - csoundPort = jack_port_by_name(jackoState->jackClient, csoundFullPortName); - if (csoundPort) { - log(csound, "Found Csound audio in port \"%s\".\n", csoundFullPortName); - } else { - csoundPort = - jack_port_register(jackoState->jackClient, csoundPortName, - JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); - if (csoundPort) { - log(csound, "Created Csound audio in port \"%s\".\n", csoundFullPortName); - } else { - warn(csound, "Could not create Csound audio in port \"%s\".\n", - csoundFullPortName); - } - } - externalPortName = csound->strarg2name( - csound, (char *)0, SexternalPortName->data, (char *)"csound", (int)1); - result = jack_connect(jackoState->jackClient, externalPortName, - csoundFullPortName); - if (result == EEXIST) { - log(csound, "Jack audio connection from \"%s\" to \"%s\" already exists.\n", - csoundFullPortName, externalPortName); - } else if (result) { - warn(csound, - "Could not create Jack audio connection from \"%s\" to \"%s\": " - "status %d %s.\n", - externalPortName, csoundFullPortName, errno, std::strerror(errno)); - return result; - } else { - log(csound, "Created Jack audio connection from \"%s\" to \"%s\".\n", - externalPortName, csoundFullPortName); - } - jackoState->audioInPorts[csoundPortName] = csoundPort; - return result; - } -}; - -struct JackoAudioIn : public OpcodeBase { -// Out. - MYFLT *asignal; -// Ins. - STRINGDAT *ScsoundPortName; -// State. - const char *csoundPortName; - jack_port_t *csoundPort; - jack_nframes_t csoundFramesPerTick; - JackoState *jackoState; - int init(CSOUND *csound) { - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - int result = OK; - csoundFramesPerTick = jackoState->csoundFramesPerTick; - csoundPortName = csound->strarg2name( - csound, (char *)0, ScsoundPortName->data, (char *)"", (int)1); - csoundPort = jackoState->audioInPorts[csoundPortName]; - return result; - } - int audio(CSOUND *csound) { - IGN(csound); - if (jackoState->jacko_has_finished == true) { - return OK; - } - jack_default_audio_sample_t *buffer = - (jack_default_audio_sample_t *)jack_port_get_buffer( - csoundPort, csoundFramesPerTick); - for (size_t frame = 0; frame < csoundFramesPerTick; ++frame) { - asignal[frame] = buffer[frame]; - } - return OK; - } -}; - -struct JackoAudioOutConnect : public OpcodeBase { -// No outs. -// Ins. - STRINGDAT *ScsoundPortName; - STRINGDAT *SexternalPortName; -// State. - const char *csoundPortName; - char csoundFullPortName[0x100]; - const char *externalPortName; - const char *clientName; - size_t frames; - jack_port_t *csoundPort; - jack_port_t *externalPort; - JackoState *jackoState; - int init(CSOUND *csound) { - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - int result = OK; - frames = opds.insdshead->ksmps; - clientName = jack_get_client_name(jackoState->jackClient); - csoundPortName = csound->strarg2name( - csound, (char *)0, ScsoundPortName->data, (char *)"", (int)1); - std::sprintf(csoundFullPortName, "%s:%s", clientName, csoundPortName); - externalPortName = csound->strarg2name( - csound, (char *)0, SexternalPortName->data, (char *)"csound", (int)1); - csoundPort = jack_port_by_name(jackoState->jackClient, csoundFullPortName); - if (!csoundPort) { - csoundPort = - jack_port_register(jackoState->jackClient, csoundPortName, - JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); - if (csoundPort) { - log(csound, "Created Csound audio out port \"%s\".\n", csoundFullPortName); - } else { - warn(csound, "Could not create Csound audio out port \"%s\".\n", - csoundFullPortName); - } - } - externalPort = jack_port_by_name(jackoState->jackClient, externalPortName); - result = jack_connect(jackoState->jackClient, jack_port_name(csoundPort), - jack_port_name(externalPort)); - if (result == EEXIST) { - log(csound, "Connection from \"%s\" to \"%s\" already exists.\n", - csoundFullPortName, externalPortName); - } else if (result) { - warn(csound, - "Could not create Jack connection from \"%s\" to \"%s\": " - "status %d %s.\n", - csoundFullPortName, externalPortName, errno, std::strerror(errno)); - return result; - } else { - log(csound, "Created Jack connection from \"%s\" to \"%s\".\n", - csoundFullPortName, externalPortName); - } - jackoState->audioOutPorts[csoundPortName] = csoundPort; - return result; - } -}; - -struct JackoAudioOut : public OpcodeBase { -// No outs. -// Ins. - STRINGDAT *ScsoundPortName; - MYFLT *asignal; -// State. - const char *csoundPortName; - jack_port_t *csoundPort; - jack_nframes_t csoundFramesPerTick; - JackoState *jackoState; - int init(CSOUND *csound) { - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - int result = OK; - csoundFramesPerTick = jackoState->csoundFramesPerTick; - csoundPortName = csound->strarg2name( - csound, (char *)0, ScsoundPortName->data, (char *)"", (int)1); - csoundPort = jackoState->audioOutPorts[csoundPortName]; - return result; - } - int audio(CSOUND *csound) { - IGN(csound); - if (jackoState->jacko_has_finished == true) { - return OK; - } - jack_default_audio_sample_t *buffer = - (jack_default_audio_sample_t *)jack_port_get_buffer( - csoundPort, csoundFramesPerTick); - for (size_t frame = 0; frame < csoundFramesPerTick; ++frame) { - buffer[frame] = asignal[frame]; - } - return OK; - } -}; - -struct JackoMidiInConnect : public OpcodeBase { -// No outs. -// Ins. - STRINGDAT *SexternalPortName; - STRINGDAT *ScsoundPortName; -// State. - const char *csoundPortName; - char csoundFullPortName[0x100]; - const char *externalPortName; - const char *clientName; - size_t frames; - jack_port_t *csoundPort; - jack_port_t *externalPort; - JackoState *jackoState; - int init(CSOUND *csound) { - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - int result = OK; - frames = opds.insdshead->ksmps; - clientName = jack_get_client_name(jackoState->jackClient); - csoundPortName = csound->strarg2name( - csound, (char *)0, ScsoundPortName->data, (char *)"", (int)1); - std::sprintf(csoundFullPortName, "%s:%s", clientName, csoundPortName); - csoundPort = jack_port_by_name(jackoState->jackClient, csoundFullPortName); - if (csoundPort) { - log(csound, "Found Csound MIDI in port \"%s\".\n", csoundFullPortName); - } else { - csoundPort = - jack_port_register(jackoState->jackClient, csoundPortName, - JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0); - if (csoundPort) { - log(csound, "Created Csound MIDI in port \"%s\".\n", csoundFullPortName); - } else { - warn(csound, "Could not create Csound MIDI in port \"%s\".\n", - csoundFullPortName); - } - } - externalPortName = csound->strarg2name( - csound, (char *)0, SexternalPortName->data, (char *)"csound", (int)1); - result = jack_connect(jackoState->jackClient, externalPortName, csoundFullPortName); - if (result == EEXIST) { - log(csound, "Jack MIDI connection from \"%s\" to \"%s\" already exists.\n", - externalPortName, csoundFullPortName); - } else if (result) { - warn(csound, - "Could not create Jack MIDI connection from \"%s\" to \"%s\": " - "status %d.\n", - externalPortName, csoundFullPortName, result); - return result; - } else { - log(csound, "Created Jack MIDI connection from \"%s\" to \"%s\".\n", - externalPortName, csoundFullPortName); - } - jackoState->midiOutPorts[csoundPortName] = csoundPort; - return result; - } -}; - -struct JackoMidiOutConnect : public OpcodeBase { -// No outs. -// Ins. - STRINGDAT *ScsoundPortName; - STRINGDAT *SexternalPortName; -// State. - const char *csoundPortName; - char csoundFullPortName[0x100]; - const char *externalPortName; - const char *clientName; - size_t frames; - jack_port_t *csoundPort; - jack_port_t *externalPort; - JackoState *jackoState; - int init(CSOUND *csound) { - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - int result = OK; - frames = opds.insdshead->ksmps; - clientName = jack_get_client_name(jackoState->jackClient); - csoundPortName = csound->strarg2name( - csound, (char *)0, ScsoundPortName->data, (char *)"", (int)1); - std::sprintf(csoundFullPortName, "%s:%s", clientName, csoundPortName); - csoundPort = jack_port_by_name(jackoState->jackClient, csoundFullPortName); - if (csoundPort) { - log(csound, "Found Csound MIDI out port \"%s\".\n", csoundFullPortName); - } else { - csoundPort = - jack_port_register(jackoState->jackClient, csoundPortName, - JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0); - if (csoundPort) { - log(csound, "Created Csound MIDI out port \"%s\".\n", csoundFullPortName); - } else { - warn(csound, "Could not create Csound out MIDI port \"%s\".\n", - csoundFullPortName); - } - } - externalPortName = csound->strarg2name( - csound, (char *)0, SexternalPortName->data, (char *)"csound", (int)1); - result = jack_connect(jackoState->jackClient, csoundFullPortName, - externalPortName); - if (result == EEXIST) { - log(csound, "Jack MIDI connection from \"%s\" to \"%s\" already exists.\n", - csoundFullPortName, externalPortName); - } else if (result) { - warn(csound, - "Could not create Jack MIDI connection from \"%s\" to \"%s\": " - "status %d.\n", - csoundFullPortName, externalPortName, result); - return result; - } else { - log(csound, "Created Jack MIDI connection from \"%s\" to \"%s\".\n", - csoundFullPortName, externalPortName); - } - jackoState->midiOutPorts[csoundPortName] = csoundPort; - return result; - } -}; - -struct JackoMidiOut : public OpcodeBase { -// No outs. -// Ins. - STRINGDAT *ScsoundPortName; - MYFLT *kstatus; - MYFLT *kchannel; - MYFLT *kdata1; - MYFLT *kdata2; - char status; - char channel; - char data1; - char data2; - char priorstatus; - char priorchannel; - char priordata1; - char priordata2; -// State. - const char *csoundPortName; - jack_port_t *csoundPort; - jack_nframes_t csoundFramesPerTick; - jack_midi_data_t *buffer; - JackoState *jackoState; - int init(CSOUND *csound) { - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - int result = OK; - csoundFramesPerTick = jackoState->csoundFramesPerTick; - csoundPortName = csound->strarg2name( - csound, (char *)0, ScsoundPortName->data, (char *)"", (int)1); - csoundPort = jackoState->midiOutPorts[csoundPortName]; - priorstatus = -1; - priorchannel = -1; - priordata1 = -1; - priordata2 = -1; - return result; - } - int kontrol(CSOUND *csound) { - IGN(csound); - if (jackoState->jacko_has_finished == true) { - return OK; - } - int result = OK; - status = *kstatus; - channel = *kchannel; - data1 = *kdata1; - data2 = *kdata2; - if (status != priorstatus || channel != priorchannel || - data1 != priordata1 || data2 != priordata2) { - size_t dataSize = 0; - if (data2 == -1) { - dataSize = 2; - } else { - dataSize = 3; - } - buffer = jackoState->getMidiOutBuffer(csoundPort); - jack_midi_data_t *data = jack_midi_event_reserve(buffer, 0, dataSize); - data[0] = (status + channel); - data[1] = data1; - if (data2 != -1) { - data[2] = data2; -// log(csound, "MIDI: %3d %3d %3d\n", data[0], data[1], data[2]); - } else { -// log(csound, "MIDI: %3d %3d\n", data[0], data[1]); - } - } - priorstatus = status; - priorchannel = channel; - priordata1 = data1; - priordata2 = data2; - return result; - } -}; - -struct JackoNoteOut : public OpcodeNoteoffBase { -// No outs. -// Ins. - STRINGDAT *ScsoundPortName; - MYFLT *ichannel; - MYFLT *ikey; - MYFLT *ivelocity; - char status; - char channel; - char key; - char velocity; -// State. - const char *csoundPortName; - jack_port_t *csoundPort; - jack_nframes_t csoundFramesPerTick; - jack_midi_data_t *buffer; - JackoState *jackoState; - int init(CSOUND *csound) { - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - int result = OK; - csoundFramesPerTick = jackoState->csoundFramesPerTick; - csoundPortName = csound->strarg2name( - csound, (char *)0, ScsoundPortName->data, (char *)"", (int)1); - csoundPort = jackoState->midiOutPorts[csoundPortName]; - channel = (char)*ichannel; - key = (char)*ikey; - velocity = (char)*ivelocity; - buffer = jackoState->getMidiOutBuffer(csoundPort); - jack_midi_data_t *data = jack_midi_event_reserve(buffer, 0, 3); - data[0] = (144 + channel); - data[1] = key; - data[2] = velocity; - log(csound, "noteon: %3d %3d %3d\n", data[0], data[1], data[2]); - return result; - } - int noteoff(CSOUND *csound) { - IGN(csound); - if (jackoState->jacko_has_finished == true) { - return OK; - } - int result = OK; - buffer = jackoState->getMidiOutBuffer(csoundPort); - jack_midi_data_t *data = jack_midi_event_reserve(buffer, 0, 3); - data[0] = (128 + channel); - data[1] = key; - data[2] = 0; - log(csound, "noteoff: %3d %3d %3d\n", data[0], data[1], data[2]); - return result; - } -}; - -struct JackoTransport : public OpcodeBase { -// Outs. -// Ins. - MYFLT *kcommand; - MYFLT *Oposition; -// State. - int command; - int priorCommand; - double positionSeconds; - double priorPositionSeconds; - JackoState *jackoState; - int init(CSOUND *csound) { - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - priorCommand = -1; - priorPositionSeconds = 0.0; - return kontrol(csound); - } - int kontrol(CSOUND *csound) { - if (jackoState->jacko_has_finished == true) { - return OK; - } - int result = OK; - command = int(*kcommand); - positionSeconds = double(*Oposition); - if (command) { - if (command != priorCommand) { - priorCommand = command; - switch (command) { - case 1: - result = jackoState->positionTransport(0.0); - jackoState->startTransport(); - log(csound, "Started Jack transport.\n"); - break; - case 2: - jackoState->stopTransport(); - log(csound, "Stopped Jack transport.\n"); - break; - case 3: - if (positionSeconds != priorPositionSeconds) { - priorPositionSeconds = positionSeconds; - result = jackoState->positionTransport(positionSeconds); - jackoState->startTransport(); - if (result) { - log(csound, "Failed to start Jack transport at %f seconds with" - " result: %d\n", - positionSeconds, result); - } else { - log(csound, "Started Jack transport at %f seconds.\n", - positionSeconds); - } - } - break; - }; - } - } - return result; - } -}; - -extern "C" { - static OENTRY oentries[] = { - { (char *)"JackoInit", sizeof(JackoInit), 0, 1, (char *)"", (char *)"SS", - (SUBR)&JackoInit::init_, 0, 0 - }, - { (char *)"JackoInfo", sizeof(JackoInfo), 0, 1, (char *)"", (char *)"", - (SUBR)&JackoInfo::init_, 0, 0 - }, - { (char *)"JackoFreewheel", sizeof(JackoFreewheel), 0, 1, (char *)"", - (char *)"i", (SUBR)&JackoFreewheel::init_, 0, 0 - }, - { (char *)"JackoOn", sizeof(JackoOn), 0, 1, (char *)"", (char *)"j", - (SUBR)&JackoOn::init_, 0, 0 - }, - { - (char *)"JackoAudioInConnect", sizeof(JackoAudioInConnect), 0, 1, - (char *)"", (char *)"SS", (SUBR)&JackoAudioInConnect::init_, 0, 0, - }, - { - (char *)"JackoAudioIn", sizeof(JackoAudioIn), 0, 3, (char *)"a", - (char *)"S", (SUBR)&JackoAudioIn::init_, (SUBR)&JackoAudioIn::audio_, - }, - { - (char *)"JackoAudioOutConnect", sizeof(JackoAudioOutConnect), 0, 1, - (char *)"", (char *)"SS", (SUBR)&JackoAudioOutConnect::init_, 0, 0, - }, - { - (char *)"JackoAudioOut", sizeof(JackoAudioOut), 0, 3, (char *)"", - (char *)"Sa", (SUBR)&JackoAudioOut::init_, - (SUBR)&JackoAudioOut::audio_, - }, - { - (char *)"JackoMidiInConnect", sizeof(JackoMidiInConnect), 0, 1, - (char *)"", (char *)"SS", (SUBR)&JackoMidiInConnect::init_, 0, 0, - }, - { - (char *)"JackoMidiOutConnect", sizeof(JackoMidiOutConnect), 0, 1, - (char *)"", (char *)"SS", (SUBR)&JackoMidiOutConnect::init_, 0, 0, - }, - { - (char *)"JackoMidiOut", sizeof(JackoMidiOut), 0, 3, (char *)"", - (char *)"SkkkO", (SUBR)&JackoMidiOut::init_, - (SUBR)&JackoMidiOut::kontrol_, 0, - }, - { (char *)"JackoNoteOut", sizeof(JackoNoteOut), 0, 3, (char *)"", - (char *)"Siii", (SUBR)&JackoNoteOut::init_, (SUBR)&JackoNoteOut::kontrol_, - 0 - }, - { (char *)"JackoTransport", sizeof(JackoTransport), 0, 3, (char *)"", - (char *)"kO", // O defaults to 0. - (SUBR)&JackoTransport::init_, (SUBR)&JackoTransport::kontrol_, 0 - }, - {0, 0, 0, 0, 0, 0, (SUBR)0, (SUBR)0, (SUBR)0} - }; - - PUBLIC int csoundModuleCreate(CSOUND *csound) { - IGN(csound); - return 0; - } - - PUBLIC int csoundModuleInit(CSOUND *csound) { - - OENTRY *ep = (OENTRY *)&(oentries[0]); - int err = 0; - while (ep->opname != 0) { - err |= csound->AppendOpcode(csound, ep->opname, ep->dsblksiz, ep->flags, - ep->thread, ep->outypes, ep->intypes, - (int (*)(CSOUND *, void *))ep->iopadr, - (int (*)(CSOUND *, void *))ep->kopadr, - (int (*)(CSOUND *, void *))ep->aopadr); - ep++; - } - return err; - } - - PUBLIC int csoundModuleDestroy(CSOUND *csound) { - if (csound->GetDebug(csound)) { - csound->Message(csound, "jacko: csoundModuleDestroy(%p)...\n", - csound); - } - int result = OK; - JackoState *jackoState = 0; - csound::QueryGlobalPointer(csound, "jackoState", jackoState); - if (jackoState) { - if (jackoState->jacko_has_finished == false) { - jackoState->close(); - } - delete jackoState; - jackoState = 0; - } - if (csound->GetDebug(csound)) { - csound->Message(csound, "jacko: csoundModuleDestroy(%p).\n", - csound); - } - return result; - } -} diff --git a/6.x/src/jackops/jacko_test.csd b/6.x/src/jackops/jacko_test.csd deleted file mode 100644 index 4fbfb605..00000000 --- a/6.x/src/jackops/jacko_test.csd +++ /dev/null @@ -1,93 +0,0 @@ - - - -TEST JACKO OPCODES -Michael Gogins - -This csd tests the Jacko opcodes. - -There is a segmentation fault at the end of the performance. This does happen -in the Jacko plugin, but it does not affect the performance. - -Csound not only writes a soundfile using -o, but also sends realtime audio and -MIDI to other Jack clients using Jack connections. - -Before running this piece, in a terminal execute: - -zynaddsubfx --input JACK --output JACK --auto-connect --sample-rate 48000 --buffer-size 128 - - - - - - -; Sampling rate must be the same as Jack's. -sr=48000 -; ksmps must be the same as Jack's frames/period. -ksmps=128 -nchnls=2 -0dbfs=40000 - -ga_audio_out init 0 - -; Initialize the Jack connections. -JackoInit "default", "csound6" -prints "Initial ports and connections:\n" -JackoInfo -JackoAudioInConnect "system:capture_1", "audio_in_left" -JackoAudioInConnect "system:capture_2", "audio_in_right" -JackoAudioOutConnect "audio_out_left", "system:playback_1" -JackoAudioOutConnect "audio_out_right", "system:playback_2" -JackoMidiInConnect "system:midi_capture_1", "midiin" -JackoMidiOutConnect "midiout", "zynaddsubfx:midi_input" -prints "Final ports and connections:\n" -JackoInfo - -instr 1 -print p1, p2, p3, p4, p5 -i_frequency = cpsmidinn(p4) -i_amplitude = ampdb(p5) -print i_frequency, i_amplitude -a_out oscil i_amplitude, i_frequency -ga_audio_out += a_out; -endin - -; Sends notes to an external MIDI synthesizer. -instr 801 -print p1, p2, p3, p4, p5 -JackoNoteOut "midiout", 0, p4, p5 -prints "Sent note to midiout.\n" -endin - -instr 900 -print p1, p2, p3 -outs ga_audio_out, ga_audio_out -; Input test is only to see if connection is created. -audio_in_left_ init 0 -audio_in_right_ init 0 -audio_in_left_ JackoAudioIn "audio_in_left" -audio_in_right_ JackoAudioIn "audio_in_right" -JackoAudioOut "audio_out_left", ga_audio_out -JackoAudioOut "audio_out_right", ga_audio_out -ga_audio_out = 0 -endin - -instr 1000 -print p1, p2, p3 -; Uncomment the following two lines to test if Jacko hangs Csound. -event "e", 0, 0, 0.1 -prints "Ending Csound performance with 'e' event\n" -endin - - - -f 0 60 -i1 5 3 63 10 -i801 10 3 69 100 -i1 15 3 72 10 -i900 0 -1 -i1000 20 1 -e - - - \ No newline at end of file diff --git a/6.x/src/linear_algebra/CMakeLists.txt b/6.x/src/linear_algebra/CMakeLists.txt deleted file mode 100644 index 355d4369..00000000 --- a/6.x/src/linear_algebra/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -option(BUILD_LINEAR_ALGEBRA_OPCODES "Build the linear algebra opcodes" ON) - -find_package(GMM) -check_deps(BUILD_LINEAR_ALGEBRA_OPCODES GMM_FOUND) - -if(BUILD_LINEAR_ALGEBRA_OPCODES AND GMM_FOUND) - make_plugin(linear_algebra linear_algebra.cpp) - target_include_directories(linear_algebra PRIVATE ${GMM_INCLUDE_DIR} ${CSOUND_INCLUDE_DIR}) - target_compile_options(linear_algebra PRIVATE "-DGMM_VERSION") - - if (MSVC) - target_compile_options(linear_algebra PRIVATE "/D_SCL_SECURE_NO_DEPRECATE") - endif() - - message(STATUS "Building linear algebra opcodes") -endif() diff --git a/6.x/src/linear_algebra/OpcodeBase.hpp b/6.x/src/linear_algebra/OpcodeBase.hpp deleted file mode 100644 index 21ca8a0c..00000000 --- a/6.x/src/linear_algebra/OpcodeBase.hpp +++ /dev/null @@ -1,492 +0,0 @@ -/* - OpcodeBase.hpp: - - Copyright (C) 2005, 2009, 2017 by Istva Varga, Victor Lazzarini and - Michael Gogins - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ -#pragma once - -/** - * There is a conflict between the preprocessor definition "_CR" in the - * standard C++ library and in Csound. To work around this, undefine "_CR" and - * include ALL standard library include files BEFORE including ANY Csound - * include files. - */ -#if defined(_CR) -#undef _CR -#endif - -#include -#include -#include -#if !(defined(__wasi__)) -#include -#endif -#include -#include -#include -#include - -/** - * Template base class, or pseudo-virtual base class, - * for writing Csound opcodes in C++. - * Derive opcode implementation classes like this: - * - * DerivedClass : public OpcodeBase - * { - * public: - * // All output fields must be declared first as MYFLT *: - * MYFLT *aret1; - * // All input fields must be declared next as MYFLT *: - * MYFLT *iarg1; - * MYFLT *karg2; - * MYFLT *aarg3; - * // All internal state variables must be declared after that: - * size_t state1; - * double state2; - * MYFLT state3; - * // If the opcode shares data protect it by creating one or more void - * // *mutex member pointers: - * void *mutex1; - * void *mutex2; - * // and create them usind csound->Create_Mutex() in csoundModuleCreate - * // and destroy them using csound->DeleteMutex(mutex) - * // csoundModuleDestroy, and lock them using LockGuard guard(mutex). - * int init(); - * int kontrol(); - * int audio; - * int noteoff(); - * void deinit(); - * }; - */ - -namespace csound { - -static bool diagnostics_enabled = false; - -/** - * Use this to guard against data races in opcode functions. The mutex should - * be created by csound->Create_Mutex() in csoundModuleCreate(), and should - * be destroyed by csound->DeleteMutex() in csoundModuleDestroy(). - * - * If data is shared between opcode instances, the mutex should be global to - * the opcode library; if data is shared between threads for a single instance, - * the mutex should belong to the opcode instance. - */ -struct LockGuard { - LockGuard(CSOUND *csound_, void *mutex_) : csound(csound_), mutex(mutex_) - { - csound->LockMutex(mutex); - } - ~LockGuard() - { - csound->UnlockMutex(mutex); - } - CSOUND *csound; - void *mutex; -}; - -/** - * Use this to store a pointer to a global heap-allocated object, e.g. one - * used to manage state between opcode instances. - */ - -template int CreateGlobalPointer(CSOUND *csound, const char *name, T *pointer) -{ - T **pointer_to_pointer = 0; - int result = csound->CreateGlobalVariable(csound, name, sizeof(pointer_to_pointer)); - pointer_to_pointer = static_cast(csound->QueryGlobalVariable(csound, name)); - *pointer_to_pointer = pointer; - return result; -} - -/** - * Retrieve a pointer to a global heap-allocated object, e.g. one - * used to manage state between opcode instances. - */ -template T *QueryGlobalPointer(CSOUND *csound, const char *name, T*& pointer) -{ - T **pointer_to_pointer = static_cast(csound->QueryGlobalVariableNoCheck(csound, name)); - if (pointer_to_pointer != 0) { - pointer = *pointer_to_pointer; - } else { - pointer = 0; - } - return pointer; -} - -template -class OpcodeBase -{ -public: - int init(CSOUND *csound) - { - return NOTOK; - } - static int init_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->init(csound); - } - int kontrol(CSOUND *csound) - { - return NOTOK; - } - static int kontrol_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->kontrol(csound); - } - int audio(CSOUND *csound) - { - return NOTOK; - } - static int audio_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->audio(csound); - } - /** - This is how to compute audio signals for normal opcodes: - (1) Zero all frames from 0 up to but not including Offset. - (2) Compute all frames from ksmps_offset up to but not including End. - (3) Zero all frames from End up to but not including ksmps. - Example from a C opcode: - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); - } - for (n = offset; n < nsmps; n++) { - input1 = MYFLT2LRND(p->a[n]); - p->r[n] = (MYFLT) (input1 >> input2); - } - So in C++ it should look like this (which is much easier to understand): - int frameIndex = 0; - for( ; frameIndex < kperiodOffset(); ++frameIndex) { - asignal[frameIndex] = 0; - } - for( ; frameIndex < kperiodEnd(); ++frameIndex) { - asignal[frameIndex] = compute(); - } - for( ; frameIndex < ksmps(); ++frameIndex) { - asignal[frameIndex] = 0; - } - */ - uint32_t kperiodOffset() const - { - return opds.insdshead->ksmps_offset; - } - uint32_t kperiodEnd() const - { - uint32_t end = opds.insdshead->ksmps_no_end; - if (end) { - return end; - } else { - return ksmps(); - } - } - uint32_t ksmps() const - { - return opds.insdshead->ksmps; - } - uint32_t output_arg_count() - { - return (uint32_t)opds.optext->t.outArgCount; - } - uint32_t input_arg_count() - { - return (uint32_t)opds.optext->t.inArgCount; - } - void log(CSOUND *csound, const char *format,...) - { - va_list args; - va_start(args, format); - if(csound) { - csound->MessageV(csound, 0, format, args); - } else { - vfprintf(stdout, format, args); - } - va_end(args); - } - void warn(CSOUND *csound, const char *format,...) - { - if(csound) { - if(csound->GetMessageLevel(csound) & CS_WARNMSG) { - va_list args; - va_start(args, format); - csound->MessageV(csound, CSOUNDMSG_WARNING, format, args); - va_end(args); - } - } else { - va_list args; - va_start(args, format); - vfprintf(stdout, format, args); - va_end(args); - } - } - OPDS opds; -}; - -template -class OpcodeNoteoffBase -{ -public: - int init(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int init_(CSOUND *csound, void *opcode) - { - if (!csound->GetReinitFlag(csound) && !csound->GetTieFlag(csound)) { - csound->RegisterDeinitCallback(csound, opcode, - &OpcodeNoteoffBase::noteoff_); - } - return reinterpret_cast(opcode)->init(csound); - } - int kontrol(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int kontrol_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->kontrol(csound); - } - int audio(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int audio_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->audio(csound); - } - /** - This is how to compute audio signals for normal opcodes: - (1) Zero all frames from 0 up to but not including Offset. - (2) Compute all frames from ksmps_offset up to but not including End. - (3) Zero all frames from End up to but not including ksmps. - Example from a C opcode: - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); - } - for (n = offset; n < nsmps; n++) { - input1 = MYFLT2LRND(p->a[n]); - p->r[n] = (MYFLT) (input1 >> input2); - } - So in C++ it should look like this (which is much easier to understand): - int frameIndex = 0; - for( ; frameIndex < kperiodOffset(); ++frameIndex) { - asignal[frameIndex] = 0; - } - for( ; frameIndex < kperiodEnd(); ++frameIndex) { - asignal[frameIndex] = compute(); - } - for( ; frameIndex < ksmps(); ++frameIndex) { - asignal[frameIndex] = 0; - } - */ - uint32_t kperiodOffset() const - { - return opds.insdshead->ksmps_offset; - } - uint32_t kperiodEnd() const - { - uint32_t end = opds.insdshead->ksmps_no_end; - if (end) { - return end; - } else { - return ksmps(); - } - } - uint32_t ksmps() const - { - return opds.insdshead->ksmps; - } - uint32_t output_arg_count() - { - return (uint32_t)opds.optext->t.outArgCount; - } - uint32_t input_arg_count() - { - return (uint32_t)opds.optext->t.inArgCount; - } - void log(CSOUND *csound, const char *format,...) - { - va_list args; - va_start(args, format); - if(csound) { - csound->MessageV(csound, 0, format, args); - } else { - vfprintf(stdout, format, args); - } - va_end(args); - } - void warn(CSOUND *csound, const char *format,...) - { - if(csound) { - if(csound->GetMessageLevel(csound) & CS_WARNMSG) { - va_list args; - va_start(args, format); - csound->MessageV(csound, CSOUNDMSG_WARNING, format, args); - va_end(args); - } - } else { - va_list args; - va_start(args, format); - vfprintf(stdout, format, args); - va_end(args); - } - } - int noteoff(CSOUND *csound) - { - return OK; - } - static int noteoff_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->noteoff(csound); - } - OPDS opds; -}; - -#if (__cplusplus >= 201103L) && !(defined(__wasi__)) -#pragma message("Defining heap_object_manager_t.") - -/** - * The memory of non-POD C++ or C objects allocated on the heap by Csound - * plugins is managed not by Csound, but by the plugin module. This class - * performs that function. - * - * As long as all memory is allocated in or after csoundModuleCreate and - * de-allocated in csoundModuleDestroy, all will be well. The danger however - * is that memory leaks will occur if allocations are not matched with - * de-allocations, or worse, that crashes will occur if any objects are - * deleted twice or de-referenced after deletion. - * - * So, the plugin should manage a collection of all heap-allocated objects, - * keyed first off the Csound instance, and second off an object handle; and - * all such objects must be accessed only by handle, from this collection. - * - * In csoundModuleDestroy, all objects for the calling instance of Csound - * should be de-allocated, and the sub-collection for that instance should - * also be de-allocated. - * - * If then there are no more sub-collections for other instances of Csound, - * the entire contents of the collection should be de-allocated. - * - * This should be done as a singleton, and in a thread-safe way. - * - * There might still be a problem if any of the heap-allocated objects, - * themselves, have global static members, perhaps created by some external - * dependency. - * - * Please note, objects O in the declaration below must not be std::shared_ptr - * objects. Deletion of objects herein must be unconditional. Rather, the - * objects passed are raw pointers to instances of class O. - */ - template class heap_object_manager_t { - private: - std::map> objects_; - std::recursive_mutex mutex; - heap_object_manager_t(){}; - ~heap_object_manager_t(){}; - public: - static heap_object_manager_t &instance() { - static heap_object_manager_t singleton; - return singleton; - } - std::map> &objects() { - std::lock_guard lock(mutex); - return objects_; - } - /** - * Returns a list of pointers to all objects allocated for this - * instance of Csound. - */ - std::vector &objects_for_csound(CSOUND *csound) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects()[csound]; - return objects_for_csound_; - } - /** - * Returns the handle for the object; if the object has not yet been - * stored, inserts it into the list of object pointers for this - * instance of Csound; otherwise, returns the handle of the stored - * object pointer. - */ - int handle_for_object(CSOUND *csound, O *object) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - auto iterator = std::find(objects_for_csound_.begin(), objects_for_csound_.end(), object); - if (iterator == objects_for_csound_.end()) { - int handle = objects_for_csound_.size(); - objects_for_csound_.push_back(object); - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::handle_for_object %p: new object handle: %d (of %ld)\n", object, handle, objects_for_csound_.size()); - return handle; - } else { - int handle = static_cast(iterator - objects_for_csound_.begin()); - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::handle_for_object: existing object handle: %d\n", handle); - return handle; - } - } - /** - * Returns the object pointer for the handle; - * if the object pointer has not been stored by - * handle, returns a null pointer. - */ - O *object_for_handle(CSOUND *csound, int handle) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - if (handle >= objects_for_csound_.size()) { - return nullptr; - } - O *object = objects_for_csound_[handle]; - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::object_for_handle: %p %d (of %ld)\n", object, handle, objects_for_csound_.size()); - return object; - } - /** - * First destroys all objects created by the calling - * instance of Csound, then destroys the list of - * object pointers for this instance of Csound. - */ - void module_destroy(CSOUND *csound) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - for (int i = 0, n = objects_for_csound_.size(); i < n; ++i) { - delete objects_for_csound_[i]; - objects_for_csound_[i] = nullptr; - } - objects_for_csound_.clear(); - objects().erase(csound); - } -}; - -#else -#pragma message("Not defining heap_manager_t.") -#endif - -} diff --git a/6.x/src/linear_algebra/linear_algebra.cpp b/6.x/src/linear_algebra/linear_algebra.cpp deleted file mode 100644 index a37da7c5..00000000 --- a/6.x/src/linear_algebra/linear_algebra.cpp +++ /dev/null @@ -1,4753 +0,0 @@ -/* - linear_algebra.cpp: - - Copyright (C) 2008 by Michael Gogins - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -/** - * L I N E A R A L G E B R A O P C O D E S F O R C S O U N D - * Michael Gogins - * - * These opcodes implement many linear algebra operations, - * from scalar, vector, and matrix arithmetic up to - * and including QR based eigenvalue decompositions. - * The opcodes are designed for digital signal processing, - * and of course other mathematical operations, - * in the Csound orchestra language. - * - * The numerical implementation uses the gmm++ library - * from http://home.gna.org/getfem/gmm_intro. - * - * NOTE: SDFT must be #defined in order to build and use these opcodes. - * - * For applications with f-sig variables, array arithmetic must be - * performed only when the f-sig is "current," because f-rate - * is some fraction of k-rate; currency can be determined with the - * la_k_current_f opcode. - * - * For applications using assignments between real vectors and - * a-rate variables, array arithmetic must be performed only when the - * vectors are "current", because the size of the vector may be - * some integral multiple of ksmps; currency can be determined - * by means of the la_k_current_vr opcode. - * - * Linear Algebra Data Types - * ------------------------- - * - * Mathematical Type Code Corresponding Csound Type or Types - * ----------------- ---- ------------------------------------------------- - * real scalar r i-rate or k-rate variable - * complex scalar c pair of i-rate or k-rate variables, e.g. "kr, ki" - * real vector vr i-rate variable holding address of array - * a a-rate variable - * t function table number - * complex vector vc i-rate variable holding address of array - * f fsig variable - * real matrix mr i-rate variable holding address of array - * complex matrix mc i-rate variable holding address of array - * - * All arrays are 0-based; the first index iterates rows to give columns, - * the second index iterates columns to give elements. - * - * All arrays are general and dense; banded, Hermitian, symmetric - * and sparse routines are not implemented. - * - * An array can be of type code vr, vc, mr, or mc - * and is stored in an i-rate object. - * In orchestra code, an array is passed as a - * MYFLT i-rate variable that contains the address - * of the array object, which is actually stored - * in the allocator opcode instance. - * Although array variables are i-rate, of course - * their values and even shapes may change at i-rate or k-rate. - * - * All operands must be pre-allocated; except for the creation - * opcodes, no opcode ever allocates any arrays. - * This is true even if the array appears on the - * left-hand side of an opcode! However, some operations - * may reshape arrays to hold results. - * - * Arrays are automatically deallocated when their instrument - * is deallocated. - * - * Not only for more efficient performance, - * but also to make it easier to remember opcode names, - * the performance rate, output value types, operation names, - * and input value types are deterministically - * encoded into the opcode name: - * 1. "la" for "linear algebra opcode family". - * 2. "i" or "k" for performance rate. - * 3. Type code(s) (see above table) for output value(s), - * but only if the type is not implicit from the input values. - * 4. Operation name: common mathematical name - * (preferred) or abbreviation. - * 5. Type code(s) for input values, if not implicit. - * - * For details, see the gmm++ documentation at - * http://download.gna.org/getfem/doc/gmmuser.pdf. - * - * Array Creation - * -------------- - * - * ivr la_i_vr_create irows - * ivc la_i_vc_create irows - * imr la_i_mr_create irows, icolumns [, - odiagonal] - * imc la_i_mc_create irows, icolumns - [, odiagonal_r, - odiagonal_i] - * - * Array Introspection - * ------------------- - * - * irows la_i_size_vr ivr - * irows la_i_size_vc ivc - * irows, icolumns la_i_size_mr imr - * irows, icolumns la_i_size_mc imc - * - * kfiscurrent la_k_current_f fsig - * kvriscurrent la_k_current_vr ivr - * - * la_i_print_vr ivr - * la_i_print_vc ivc - * la_i_print_mr imr - * la_i_print_mc imc - * - * Array Assignment and Conversion - * ------------------------------- - * - * ivr la_i_assign_vr ivr - * ivr la_k_assign_vr ivr - * ivc la_i_assign_vc ivc - * ivc la_k_assign_vc ivr - * imr la_i_assign_mr imr - * imr la_k_assign_mr imr - * imc la_i_assign_mc imc - * imc la_k_assign_mc imr - * - * NOTE: Assignments from tables or fsigs will resize vectors. - * Assignments to or from asigs are incremental -- ksmps - * frames are copied each kperiod and the array index - * wraps around as required. - * - * ivr la_k_assign_a asig - * ivr la_i_assign_t itablenumber - * ivr la_k_assign_t itablenumber - * ivc la_k_assign_f fsig - * - * asig la_k_a_assign ivr - * itablenum la_i_t_assign ivr - * itablenum la_k_t_assign ivr - * fsig la_k_f_assign ivc - * - * Fill Arrays with Random Elements - * -------------------------------- - * - * ivr la_i_random_vr [ifill_fraction] - * ivr la_k_random_vr [kfill_fraction] - * ivc la_i_random_vc [ifill_fraction] - * ivc la_k_random_vc [kfill_fraction] - * imr la_i_random_mr [ifill_fraction] - * imr la_k_random_mr [kfill_fraction] - * imc la_i_random_mc [ifill_fraction] - * imc la_k_random_mc [kfill_fraction] - * - * Array Element Access - * -------------------- - * - * ivr la_i_vr_set irow, ivalue - * kvr la_k_vr_set krow, kvalue - * ivc la_i_vc_set irow, ivalue_r, ivalue_i - * kvc la_k_vc_set krow, kvalue_r, kvalue_i - * imr la_i mr_set irow, icolumn, ivalue - * kmr la_k mr_set krow, kcolumn, ivalue - * imc la_i_mc_set irow, icolumn, ivalue_r, - ivalue_i - * kmc la_k_mc_set krow, kcolumn, kvalue_r, - kvalue_i - * - * ivalue la_i_get_vr ivr, irow - * kvalue la_k_get_vr ivr, krow, - * ivalue_r, ivalue_i la_i_get_vc ivc, irow - * kvalue_r, kvalue_i la_k_get_vc ivc, krow - * ivalue la_i_get_mr imr, irow, icolumn - * kvalue la_k_get_mr imr, krow, kcolumn - * ivalue_r, ivalue_i la_i_get_mc imc, irow, icolumn - * kvalue_r, kvalue_i la_k_get_mc imc, krow, kcolumn - * - * Single Array Operations - * ----------------------- - * - * imr la_i_transpose_mr imr - * imr la_k_transpose_mr imr - * imc la_i_transpose_mc imc - * imc la_k_transpose_mc imc - - * ivr la_i_conjugate_vr ivr - * ivr la_k_conjugate_vr ivr - * ivc la_i_conjugate_vc ivc - * ivc la_k_conjugate_vc ivc - * imr la_i_conjugate_mr imr - * imr la_k_conjugate_mr imr - * imc la_i_conjugate_mc imc - * imc la_k_conjugate_mc imc - * - * Scalar Operations - * ----------------- - * - * ir la_i_norm1_vr ivr - * kr la_k_norm1_vr ivc - * ir la_i_norm1_vc ivc - * kr la_k_norm1_vc ivc - * ir la_i_norm1_mr imr - * kr la_k_norm1_mr imr - * ir la_i_norm1_mc imc - * kr la_k_norm1_mc imc - * - * ir la_i_norm_euclid_vr ivr - * kr la_k_norm_euclid_vr ivr - * ir la_i_norm_euclid_vc ivc - * kr la_k_norm_euclid_vc ivc - * ir la_i_norm_euclid_mr mvr - * kr la_k_norm_euclid_mr mvr - * ir la_i_norm_euclid_mc mvc - * kr la_k_norm_euclid_mc mvc - * - * ir la_i_distance_vr ivr - * kr la_k_distance_vr ivr - * ir la_i_distance_vc ivc - * kr la_k_distance_vc ivc - * - * ir la_i_norm_max imr - * kr la_k_norm_max imc - * ir la_i_norm_max imr - * kr la_k_norm_max imc - * - * ir la_i_norm_inf_vr ivr - * kr la_k_norm_inf_vr ivr - * ir la_i_norm_inf_vc ivc - * kr la_k_norm_inf_vc ivc - * ir la_i_norm_inf_mr imr - * kr la_k_norm_inf_mr imr - * ir la_i_norm_inf_mc imc - * kr la_k_norm_inf_mc imc - * - * ir la_i_trace_mr imr - * kr la_k_trace_mr imr - * ir, ii la_i_trace_mc imc - * kr, ki la_k_trace_mc imc - * - * ir la_i_lu_det imr - * kr la_k_lu_det imr - * ir la_i_lu_det imc - * kr la_k_lu_det imc - * - * Elementwise Array-Array Operations - * ---------------------------------- - * - * ivr la_i_add_vr ivr_a, ivr_b - * ivc la_k_add_vc ivc_a, ivc_b - * imr la_i_add_mr imr_a, imr_b - * imc la_k_add_mc imc_a, imc_b - * - * ivr la_i_subtract_vr ivr_a, ivr_b - * ivc la_k_subtract_vc ivc_a, ivc_b - * imr la_i_subtract_mr imr_a, imr_b - * imc la_k_subtract_mc imc_a, imc_b - * - * ivr la_i_multiply_vr ivr_a, ivr_b - * ivc la_k_multiply_vc ivc_a, ivc_b - * imr la_i_multiply_mr imr_a, imr_b - * imc la_k_multiply_mc imc_a, imc_b - * - * ivr la_i_divide_vr ivr_a, ivr_b - * ivc la_k_divide_vc ivc_a, ivc_b - * imr la_i_divide_mr imr_a, imr_b - * imc la_k_divide_mc imc_a, imc_b - * - * Inner Products - * -------------- - * - * ir la_i_dot_vr ivr_a, ivr_b - * kr la_k_dot_vr ivr_a, ivr_b - * ir, ii la_i_dot_vc ivc_a, ivc_b - * kr, ki la_k_dot_vc ivc_a, ivc_b - * - * imr la_i_dot_mr imr_a, imr_b - * imr la_k_dot_mr imr_a, imr_b - * imc la_i_dot_mc imc_a, imc_b - * imc la_k_dot_mc imc_a, imc_b - * - * ivr la_i_dot_mr_vr imr_a, ivr_b - * ivr la_k_dot_mr_vr imr_a, ivr_b - * ivc la_i_dot_mc_vc imc_a, ivc_b - * ivc la_k_dot_mc_vc imc_a, ivc_b - * - * Matrix Inversion - * ---------------- - * - * imr, icondition la_i_invert_mr imr - * imr, kcondition la_k_invert_mr imr - * imc, icondition la_i_invert_mc imc - * imc, kcondition la_k_invert_mc imc - * - * Matrix Decompositions and Solvers - * --------------------------------- - * - * ivr la_i_upper_solve_mr imr [, j_1_diagonal] - * ivr la_k_upper_solve_mr imr [, j_1_diagonal] - * ivc la_i_upper_solve_mc imc [, j_1_diagonal] - * ivc la_k_upper_solve_mc imc [, j_1_diagonal] - * - * ivr la_i_lower_solve_mr imr [, j_1_diagonal] - * ivr la_k_lower_solve_mr imr [, j_1_diagonal] - * ivc la_i_lower_solve_mc imc [, j_1_diagonal] - * ivc la_k_lower_solve_mc imc [, j_1_diagonal] - * - * imr, ivr_pivot, isize la_i_lu_factor_mr imr - * imr, ivr_pivot, ksize la_k_lu_factor_mr imr - * imc, ivr_pivot, isize la_i_lu_factor_mc imc - * imc, ivr_pivot, ksize la_k_lu_factor_mc imc - * - * ivr_x la_i_lu_solve_mr imr, ivr_b - * ivr_x la_k_lu_solve_mr imr, ivr_b - * ivc_x la_i_lu_solve_mc imc, ivc_b - * ivc_x la_k_lu_solve_mc imc, ivc_b - * - * imr_q, imr_r la_i_qr_factor_mr imr - * imr_q, imr_r la_k_qr_factor_mr imr - * imc_q, imc_r la_i_qr_factor_mc imc - * imc_q, imc_r la_k_qr_factor_mc imc - * - * ivr_eig_vals la_i_qr_eigen_mr imr, i_tolerance - * ivr_eig_vals la_k_qr_eigen_mr imr, k_tolerance - * ivr_eig_vals la_i_qr_eigen_mc imc, i_tolerance - * ivr_eig_vals la_k_qr_eigen_mc imc, k_tolerance - * - * NOTE: Matrix must be Hermitian in order to compute eigenvectors. - * - * ivr_eig_vals, imr_eig_vecs la_i_qr_sym_eigen_mr imr, i_tolerance - * ivr_eig_vals, imr_eig_vecs la_k_qr_sym_eigen_mr imr, k_tolerance - * ivc_eig_vals, imc_eig_vecs la_i_qr_sym_eigen_mc imc, i_tolerance - * ivc_eig_vals, imc_eig_vecs la_k_qr_sym_eigen_mc imc, k_tolerance - * - */ - -extern "C" { -// a-rate, k-rate, FUNC, SPECDAT -#include -// PVSDAT -#include -} - -#ifdef ST -#undef ST -#endif - -#ifdef WR -#undef WR -#endif - -#include "OpcodeBase.hpp" -#include -#include -#include -#include - -using namespace csound; - -static std::ostream &operator<<(std::ostream &o, const std::vector &m) { - gmm::write(o, m); - return o; -} - -static std::ostream &operator<<(std::ostream &o, - const std::vector> &m) { - gmm::write(o, m); - return o; -} - -/** - * Template union for safely and efficiently - * typecasting the value of a MYFLT variable - * to the address of an array, and vice versa. - */ -template struct ArrayCaster { - union { - A *a; - F f; - }; -}; - -/** - * Safely and efficiently typecast the address - * of an array to the value of a MYFLT variable. - */ -template void tof(A *a, F *f) { - ArrayCaster arrayCaster; - arrayCaster.a = a; - *f = arrayCaster.f; -}; - -/** - * Safely and efficiently typecast the value of a - * a MYFLT variable to the address of an array. - */ -template void toa(F *f, A *&a) { - ArrayCaster arrayCaster; - arrayCaster.f = *f; - a = arrayCaster.a; -}; - -class la_i_vr_create_t : public OpcodeNoteoffBase { -public: - MYFLT *i_vr; - MYFLT *i_rows; - std::vector vr; - int init(CSOUND *) { - vr.resize(size_t(*i_rows)); - tof(this, i_vr); - return OK; - } - int noteoff(CSOUND *) { - vr.resize(0); - return OK; - } -}; - -class la_i_vc_create_t : public OpcodeNoteoffBase { -public: - MYFLT *i_vc; - MYFLT *i_rows; - std::vector> vc; - int init(CSOUND *) { - vc.resize(size_t(*i_rows)); - tof(this, i_vc); - return OK; - } - int noteoff(CSOUND *) { - vc.resize(0); - return OK; - } -}; - -class la_i_mr_create_t : public OpcodeNoteoffBase { -public: - MYFLT *i_mr; - MYFLT *i_rows; - MYFLT *i_columns; - MYFLT *o_diagonal; - gmm::dense_matrix mr; - int init(CSOUND *) { - gmm::resize(mr, size_t(*i_rows), size_t(*i_columns)); - if (*o_diagonal) { - for (size_t i = 0, n = size_t(*i_rows); i < n; ++i) { - mr(i, i) = *o_diagonal; - } - } - tof(this, i_mr); - return OK; - } - int noteoff(CSOUND *) { - mr.resize(0, 0); - return OK; - } -}; - -class la_i_mc_create_t : public OpcodeNoteoffBase { -public: - MYFLT *i_mc; - MYFLT *i_rows; - MYFLT *i_columns; - MYFLT *o_diagonal_r; - MYFLT *o_diagonal_i; - gmm::dense_matrix> mc; - int init(CSOUND *) { - gmm::resize(mc, size_t(*i_rows), size_t(*i_columns)); - if (*o_diagonal_r || *o_diagonal_i) { - for (size_t i = 0, n = size_t(*i_rows); i < n; ++i) { - mc(i, i) = std::complex(*o_diagonal_r, *o_diagonal_i); - } - } - tof(this, i_mc); - return OK; - } - int noteoff(CSOUND *) { - mc.resize(0, 0); - return OK; - } -}; - -class la_i_size_vr_t : public OpcodeBase { -public: - MYFLT *i_size; - MYFLT *i_vr; - int init(CSOUND *) { - la_i_vr_create_t *array = 0; - toa(i_vr, array); - *i_size = (MYFLT)gmm::vect_size(array->vr); - return OK; - } -}; - -class la_i_size_vc_t : public OpcodeBase { -public: - MYFLT *i_size; - MYFLT *i_vc; - int init(CSOUND *) { - la_i_vc_create_t *array = 0; - toa(i_vc, array); - *i_size = (MYFLT)gmm::vect_size(array->vc); - return OK; - } -}; - -class la_i_size_mr_t : public OpcodeBase { -public: - MYFLT *i_rows; - MYFLT *i_columns; - MYFLT *i_mr; - int init(CSOUND *) { - la_i_mr_create_t *array = 0; - toa(i_mr, array); - *i_rows = (MYFLT)gmm::mat_nrows(array->mr); - *i_columns = (MYFLT)gmm::mat_ncols(array->mr); - return OK; - } -}; - -class la_i_size_mc_t : public OpcodeBase { -public: - MYFLT *i_rows; - MYFLT *i_columns; - MYFLT *i_mc; - int init(CSOUND *) { - la_i_mc_create_t *array = 0; - toa(i_mc, array); - *i_rows = (MYFLT)gmm::mat_nrows(array->mc); - *i_columns = (MYFLT)gmm::mat_ncols(array->mc); - return OK; - } -}; - -/** - * Return 1 if the input f-sig is current - * (i.e., if its value might change in the next kperiod); - * return 0 if the input f-sig is not current. - * - * Example: - * - * kcurrent la_k_current_f fsig - * if (kcurrent == 1.0) then - * ; arithmetic on fsig here... - * endif - */ -class la_k_current_f_t : public OpcodeBase { -public: - MYFLT *k_current; - PVSDAT *f_sig; - size_t last_frame; - int init(CSOUND *) { - last_frame = f_sig->framecount; - return OK; - } - int kontrol(CSOUND *) { - if (last_frame < f_sig->framecount) { - last_frame = f_sig->framecount; - *k_current = 1.0; - } else { - *k_current = 0.0; - } - return OK; - } -}; - -/** - * Return 1 if the real vector is current (i.e., its - * current index equals 0); return 0 if the input - * real vector is not current. A real vector is current - * in the very first kperiod of performance, - * and at each subsequent kperiod where ksmps has - * accumulated past the end of the vector and - * has wrapped back to index 0. For this to be - * possible, the size of the vector must be an integral - * multiple of ksmps. - * - * Example: - * - * ; FIRST, assignments from a-rate variables to vectors. - * kcurrent la_k_current_vr ivr - * if (kcurrent == 1.0) then - * ; SECOND, arithmetic with current vectors. - * endif - * ; THIRD, assignments from vectors to a-rate variables. - */ - -class la_k_current_vr_t : public OpcodeBase { -public: - MYFLT *k_current; - MYFLT *rhs_ivr; - la_i_vr_create_t *rhs; - size_t ksmps; - size_t vector_size; - int init(CSOUND *csound) { - rhs = 0; - toa(rhs_ivr, rhs); - ksmps = opds.insdshead->ksmps; - vector_size = gmm::vect_size(rhs->vr); - return OK; - } - int kontrol(CSOUND *csound) { - size_t frame_count = opds.insdshead->kcounter * ksmps; - size_t index = frame_count % vector_size; - if (index == 0) { - *k_current = 1.0; - } else { - *k_current = 0.0; - } - return OK; - } -}; - -class la_i_print_vr_t : public OpcodeBase { -public: - MYFLT *i_vr; - int init(CSOUND *csound) { - la_i_vr_create_t *array = 0; - toa(i_vr, array); - std::ostringstream stream; - stream << array->vr << std::endl; - csound->Message(csound, "%s", stream.str().c_str()); - return OK; - } -}; - -class la_i_print_vc_t : public OpcodeBase { -public: - MYFLT *i_vc; - int init(CSOUND *csound) { - la_i_vc_create_t *array = 0; - toa(i_vc, array); - std::ostringstream stream; - stream << array->vc << std::endl; - csound->Message(csound, "%s", stream.str().c_str()); - return OK; - } -}; - -class la_i_print_mr_t : public OpcodeBase { -public: - MYFLT *i_mr; - int init(CSOUND *csound) { - la_i_mr_create_t *array = 0; - toa(i_mr, array); - std::ostringstream stream; - stream << array->mr << std::endl; - csound->Message(csound, "%s", stream.str().c_str()); - return OK; - } -}; - -class la_i_print_mc_t : public OpcodeBase { -public: - MYFLT *i_mc; - int init(CSOUND *csound) { - la_i_mc_create_t *array = 0; - toa(i_mc, array); - std::ostringstream stream; - stream << array->mc << std::endl; - csound->Message(csound, "%s", stream.str().c_str()); - return OK; - } -}; - -class la_i_assign_vr_t : public OpcodeBase { -public: - MYFLT *i_vr_lhs; - MYFLT *i_vr_rhs; - la_i_vr_create_t *lhs; - la_i_vr_create_t *rhs; - int init(CSOUND *csound) { - toa(i_vr_lhs, lhs); - toa(i_vr_rhs, rhs); - gmm::copy(rhs->vr, lhs->vr); - return OK; - } -}; - -class la_k_assign_vr_t : public OpcodeBase { -public: - MYFLT *i_vr_lhs; - MYFLT *i_vr_rhs; - la_i_vr_create_t *lhs; - la_i_vr_create_t *rhs; - int init(CSOUND *csound) { - toa(i_vr_lhs, lhs); - toa(i_vr_rhs, rhs); - return OK; - } - int kontrol(CSOUND *csound) { - gmm::copy(rhs->vr, lhs->vr); - return OK; - } -}; - -class la_i_assign_vc_t : public OpcodeBase { -public: - MYFLT *i_vc_lhs; - MYFLT *i_vc_rhs; - la_i_vc_create_t *lhs; - la_i_vc_create_t *rhs; - int init(CSOUND *csound) { - toa(i_vc_lhs, lhs); - toa(i_vc_rhs, rhs); - gmm::copy(rhs->vc, lhs->vc); - return OK; - } -}; - -class la_k_assign_vc_t : public OpcodeBase { -public: - MYFLT *i_vc_lhs; - MYFLT *i_vc_rhs; - la_i_vc_create_t *lhs; - la_i_vc_create_t *rhs; - int init(CSOUND *csound) { - toa(i_vc_lhs, lhs); - toa(i_vc_rhs, rhs); - return OK; - } - int kontrol(CSOUND *csound) { - gmm::copy(rhs->vc, lhs->vc); - return OK; - } -}; - -class la_i_assign_mr_t : public OpcodeBase { -public: - MYFLT *i_mr_lhs; - MYFLT *i_mr_rhs; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs; - int init(CSOUND *csound) { - toa(i_mr_lhs, lhs); - toa(i_mr_rhs, rhs); - gmm::copy(rhs->mr, lhs->mr); - return OK; - } -}; - -class la_k_assign_mr_t : public OpcodeBase { -public: - MYFLT *i_mr_lhs; - MYFLT *i_mr_rhs; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs; - int init(CSOUND *csound) { - toa(i_mr_lhs, lhs); - toa(i_mr_rhs, rhs); - return OK; - } - int kontrol(CSOUND *csound) { - gmm::copy(rhs->mr, lhs->mr); - return OK; - } -}; - -class la_i_assign_mc_t : public OpcodeBase { -public: - MYFLT *i_mc_lhs; - MYFLT *i_mc_rhs; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs; - int init(CSOUND *csound) { - toa(i_mc_lhs, lhs); - toa(i_mc_rhs, rhs); - gmm::copy(rhs->mc, lhs->mc); - return OK; - } -}; - -class la_k_assign_mc_t : public OpcodeBase { -public: - MYFLT *i_mc_lhs; - MYFLT *i_mc_rhs; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs; - int init(CSOUND *csound) { - toa(i_mc_lhs, lhs); - toa(i_mc_rhs, rhs); - return OK; - } - int kontrol(CSOUND *csound) { - gmm::copy(rhs->mc, lhs->mc); - return OK; - } -}; - -class la_k_assign_a_t : public OpcodeBase { -public: - MYFLT *i_vr; - MYFLT *a_a; - la_i_vr_create_t *lhs; - size_t ksmps; - size_t vector_size; - int init(CSOUND *csound) { - toa(i_vr, lhs); - ksmps = opds.insdshead->ksmps; - vector_size = gmm::vect_size(lhs->vr); - return OK; - } - int kontrol(CSOUND *csound) { - uint32_t offset = opds.insdshead->ksmps_offset; - uint32_t early = opds.insdshead->ksmps_no_end; - size_t frame_count = opds.insdshead->ksmps * ksmps; - size_t array_i = frame_count % vector_size; - if (UNLIKELY(early)) - ksmps -= early; - for (size_t i = offset; i < ksmps; ++i, ++array_i) { - lhs->vr[array_i] = a_a[i]; - } - return OK; - } -}; - -class la_i_assign_t_t : public OpcodeBase { -public: - MYFLT *i_vr; - MYFLT *i_tablenumber; - la_i_vr_create_t *lhs; - int tablenumber; - int n; - int init(CSOUND *csound) { - toa(i_vr, lhs); - tablenumber = int(std::floor(*i_tablenumber)); - n = csound->TableLength(csound, tablenumber); - gmm::resize(lhs->vr, n); - for (int i = 0; i < n; ++i) { - lhs->vr[i] = csound->TableGet(csound, tablenumber, i); - } - return OK; - } -}; - -class la_k_assign_t_t : public OpcodeBase { -public: - MYFLT *i_vr; - MYFLT *i_tablenumber; - la_i_vr_create_t *lhs; - int tablenumber; - int n; - int init(CSOUND *csound) { - toa(i_vr, lhs); - tablenumber = int(std::floor(*i_tablenumber)); - n = csound->TableLength(csound, tablenumber); - gmm::resize(lhs->vr, n); - return OK; - } - int kontrol(CSOUND *csound) { - for (int i = 0; i < n; ++i) { - lhs->vr[i] = csound->TableGet(csound, tablenumber, i); - } - return OK; - } -}; - -class la_k_assign_f_t : public OpcodeBase { -public: - MYFLT *i_vc; - PVSDAT *f_fsig; - la_i_vc_create_t *lhs; - int n; - std::complex *f; - int init(CSOUND *csound) { - toa(i_vc, lhs); - n = f_fsig->N; - // std::complex has the same layout as CMPLX. - f = (std::complex *)f_fsig->frame.auxp; - gmm::resize(lhs->vc, n); - return OK; - } - int kontrol(CSOUND *csound) { - for (int i = 0; i < n; ++i) { - lhs->vc[i] = f[i]; - } - return OK; - } -}; - -class la_k_a_assign_t : public OpcodeBase { -public: - MYFLT *a_a; - MYFLT *i_vr; - la_i_vr_create_t *rhs; - size_t ksmps; - int init(CSOUND *csound) { - toa(i_vr, rhs); - ksmps = opds.insdshead->ksmps; - return OK; - } - int kontrol(CSOUND *csound) { - uint32_t offset = opds.insdshead->ksmps_offset; - uint32_t early = opds.insdshead->ksmps_no_end; - memset(a_a, '\0', offset * sizeof(MYFLT)); - size_t frameCount = opds.insdshead->kcounter * opds.insdshead->ksmps; - size_t vectorSize = gmm::vect_size(rhs->vr); - size_t array_i = frameCount % vectorSize; - if (UNLIKELY(early)) - ksmps -= early; - for (size_t i = 0; i < ksmps; ++i, ++array_i) { - a_a[i] = rhs->vr[array_i]; - } - return OK; - } -}; - -class la_i_t_assign_t : public OpcodeBase { -public: - MYFLT *i_tablenumber; - MYFLT *i_vr; - la_i_vr_create_t *rhs; - int tablenumber; - int n; - int init(CSOUND *csound) { - toa(i_vr, rhs); - tablenumber = int(std::floor(*i_tablenumber)); - n = csound->TableLength(csound, tablenumber); - gmm::resize(rhs->vr, n); - for (int i = 0; i < n; ++i) { - csound->TableSet(csound, tablenumber, i, rhs->vr[i]); - } - return OK; - } -}; - -class la_k_t_assign_t : public OpcodeBase { -public: - MYFLT *i_tablenumber; - MYFLT *i_vr; - la_i_vr_create_t *rhs; - int tablenumber; - int n; - int init(CSOUND *csound) { - toa(i_vr, rhs); - tablenumber = int(std::floor(*i_tablenumber)); - n = csound->TableLength(csound, tablenumber); - gmm::resize(rhs->vr, n); - return OK; - } - int kontrol(CSOUND *csound) { - for (int i = 0; i < n; ++i) { - csound->TableSet(csound, tablenumber, i, rhs->vr[i]); - } - return OK; - } -}; - -class la_k_f_assign_t : public OpcodeBase { -public: - PVSDAT *f_fsig; - MYFLT *i_vc; - la_i_vc_create_t *rhs; - int n; - std::complex *f; - int init(CSOUND *csound) { - toa(i_vc, rhs); - n = f_fsig->N; - // std::complex has the same layout as CMPLX. - f = (std::complex *)f_fsig->frame.auxp; - gmm::resize(rhs->vc, n); - return OK; - } - int kontrol(CSOUND *csound) { - for (int i = 0; i < n; ++i) { - f[i] = rhs->vc[i]; - } - return OK; - } -}; - -class la_i_random_vr_t : public OpcodeBase { -public: - MYFLT *i_vr_lhs; - MYFLT *i_fraction; - la_i_vr_create_t *lhs; - int init(CSOUND *csound) { - toa(i_vr_lhs, lhs); - gmm::fill_random(lhs->vr, *i_fraction); - return OK; - } -}; - -class la_k_random_vr_t : public OpcodeBase { -public: - MYFLT *i_vr_lhs; - MYFLT *i_fraction; - la_i_vr_create_t *lhs; - int init(CSOUND *csound) { - toa(i_vr_lhs, lhs); - return OK; - } - int kontrol(CSOUND *csound) { - gmm::fill_random(lhs->vr, *i_fraction); - return OK; - } -}; - -class la_i_random_vc_t : public OpcodeBase { -public: - MYFLT *i_vc_lhs; - MYFLT *i_fraction; - la_i_vc_create_t *lhs; - int init(CSOUND *csound) { - toa(i_vc_lhs, lhs); - gmm::fill_random(lhs->vc, *i_fraction); - return OK; - } -}; - -class la_k_random_vc_t : public OpcodeBase { -public: - MYFLT *i_vc_lhs; - MYFLT *i_fraction; - la_i_vc_create_t *lhs; - int init(CSOUND *csound) { - toa(i_vc_lhs, lhs); - return OK; - } - int kontrol(CSOUND *csound) { - gmm::fill_random(lhs->vc, *i_fraction); - return OK; - } -}; - -class la_i_random_mr_t : public OpcodeBase { -public: - MYFLT *i_mr_lhs; - MYFLT *i_fraction; - la_i_mr_create_t *lhs; - int init(CSOUND *csound) { - toa(i_mr_lhs, lhs); - gmm::fill_random(lhs->mr, *i_fraction); - return OK; - } -}; - -class la_k_random_mr_t : public OpcodeBase { -public: - MYFLT *i_mr_lhs; - MYFLT *i_fraction; - la_i_mr_create_t *lhs; - int init(CSOUND *csound) { - toa(i_mr_lhs, lhs); - return OK; - } - int kontrol(CSOUND *csound) { - gmm::fill_random(lhs->mr, *i_fraction); - return OK; - } -}; - -class la_i_random_mc_t : public OpcodeBase { -public: - MYFLT *i_mc_lhs; - MYFLT *i_fraction; - la_i_mc_create_t *lhs; - int init(CSOUND *csound) { - toa(i_mc_lhs, lhs); - gmm::fill_random(lhs->mc, *i_fraction); - return OK; - } -}; - -class la_k_random_mc_t : public OpcodeBase { -public: - MYFLT *i_mc_lhs; - MYFLT *i_fraction; - la_i_mc_create_t *lhs; - int init(CSOUND *csound) { - toa(i_mc_lhs, lhs); - return OK; - } - int kontrol(CSOUND *csound) { - gmm::fill_random(lhs->mc, *i_fraction); - return OK; - } -}; - -class la_i_vr_set_t : public OpcodeBase { -public: - MYFLT *i_vr; - MYFLT *i_row; - MYFLT *i_value; - la_i_vr_create_t *vr; - int init(CSOUND *) { - toa(i_vr, vr); - vr->vr[size_t(*i_row)] = *i_value; - return OK; - } -}; - -class la_k_vr_set_t : public OpcodeBase { -public: - MYFLT *i_vr; - MYFLT *k_row; - MYFLT *k_value; - la_i_vr_create_t *vr; - int init(CSOUND *) { - toa(i_vr, vr); - return OK; - } - int kontrol(CSOUND *) { - vr->vr[size_t(*k_row)] = *k_value; - return OK; - } -}; - -class la_i_vc_set_t : public OpcodeBase { -public: - MYFLT *i_vc; - MYFLT *i_row; - MYFLT *i_value_r; - MYFLT *i_value_i; - la_i_vc_create_t *vc; - int init(CSOUND *) { - toa(i_vc, vc); - vc->vc[size_t(*i_row)] = std::complex(*i_value_r, *i_value_i); - return OK; - } -}; - -class la_k_vc_set_t : public OpcodeBase { -public: - MYFLT *i_vc; - MYFLT *k_row; - MYFLT *k_value_r; - MYFLT *k_value_i; - la_i_vc_create_t *vc; - int init(CSOUND *) { - toa(i_vc, vc); - return OK; - } - int kontrol(CSOUND *) { - vc->vc[size_t(*k_row)] = std::complex(*k_value_r, *k_value_i); - return OK; - } -}; - -class la_i_mr_set_t : public OpcodeBase { -public: - MYFLT *i_mr; - MYFLT *i_row; - MYFLT *i_column; - MYFLT *i_value; - la_i_mr_create_t *mr; - int init(CSOUND *) { - toa(i_mr, mr); - mr->mr(size_t(*i_row), size_t(*i_column)) = *i_value; - return OK; - } -}; - -class la_k_mr_set_t : public OpcodeBase { -public: - MYFLT *i_mr; - MYFLT *k_row; - MYFLT *k_column; - MYFLT *k_value; - la_i_mr_create_t *mr; - int init(CSOUND *) { - toa(i_mr, mr); - return OK; - } - int kontrol(CSOUND *) { - mr->mr(size_t(*k_row), size_t(*k_column)) = *k_value; - return OK; - } -}; - -class la_i_mc_set_t : public OpcodeBase { -public: - MYFLT *i_mc; - MYFLT *i_row; - MYFLT *i_column; - MYFLT *i_value_r; - MYFLT *i_value_i; - la_i_mc_create_t *mc; - int init(CSOUND *) { - toa(i_mc, mc); - mc->mc(size_t(*i_row), size_t(*i_column)) = - std::complex(*i_value_r, *i_value_i); - return OK; - } -}; - -class la_k_mc_set_t : public OpcodeBase { -public: - MYFLT *i_mc; - MYFLT *k_row; - MYFLT *k_column; - MYFLT *k_value_r; - MYFLT *k_value_i; - la_i_mc_create_t *mc; - int init(CSOUND *) { - toa(i_mc, mc); - return OK; - } - int kontrol(CSOUND *) { - mc->mc(size_t(*k_row), size_t(*k_column)) = - std::complex(*k_value_r, *k_value_i); - return OK; - } -}; - -class la_i_get_vr_t : public OpcodeBase { -public: - MYFLT *i_value; - MYFLT *i_vr; - MYFLT *i_row; - la_i_vr_create_t *vr; - int init(CSOUND *) { - toa(i_vr, vr); - *i_value = vr->vr[size_t(*i_row)]; - return OK; - } -}; - -class la_k_get_vr_t : public OpcodeBase { -public: - MYFLT *k_value; - MYFLT *i_vr; - MYFLT *k_row; - la_i_vr_create_t *vr; - int init(CSOUND *) { - toa(i_vr, vr); - return OK; - } - int kontrol(CSOUND *) { - *k_value = vr->vr[size_t(*k_row)]; - return OK; - } -}; - -class la_i_get_vc_t : public OpcodeBase { -public: - MYFLT *i_value_r; - MYFLT *i_value_i; - MYFLT *i_vc; - MYFLT *i_row; - la_i_vc_create_t *vc; - int init(CSOUND *) { - toa(i_vc, vc); - const std::complex &lhs = vc->vc[size_t(*i_row)]; - *i_value_r = lhs.real(); - *i_value_i = lhs.imag(); - return OK; - } -}; - -class la_k_get_vc_t : public OpcodeBase { -public: - MYFLT *k_value_r; - MYFLT *k_value_i; - MYFLT *i_vc; - MYFLT *k_row; - la_i_vc_create_t *vc; - int init(CSOUND *) { - toa(i_vc, vc); - return OK; - } - int kontrol(CSOUND *) { - const std::complex &lhs = vc->vc[size_t(*k_row)]; - *k_value_r = lhs.real(); - *k_value_i = lhs.imag(); - return OK; - } -}; - -class la_i_get_mr_t : public OpcodeBase { -public: - MYFLT *i_value; - MYFLT *i_mr; - MYFLT *i_row; - MYFLT *i_column; - la_i_mr_create_t *mr; - int init(CSOUND *) { - toa(i_mr, mr); - *i_value = mr->mr(size_t(*i_row), size_t(*i_column)); - return OK; - } -}; - -class la_k_get_mr_t : public OpcodeBase { -public: - MYFLT *k_value; - MYFLT *i_mr; - MYFLT *k_row; - MYFLT *k_column; - la_i_mr_create_t *mr; - int init(CSOUND *) { - toa(i_mr, mr); - return OK; - } - int kontrol(CSOUND *) { - *k_value = mr->mr(size_t(*k_row), size_t(*k_column)); - return OK; - } -}; - -class la_i_get_mc_t : public OpcodeBase { -public: - MYFLT *i_value_r; - MYFLT *i_value_i; - MYFLT *i_mc; - MYFLT *i_row; - MYFLT *i_column; - la_i_mc_create_t *mc; - int init(CSOUND *) { - toa(i_mc, mc); - const std::complex &lhs = mc->mc(size_t(*i_row), size_t(*i_column)); - *i_value_r = lhs.real(); - *i_value_i = lhs.imag(); - return OK; - } -}; - -class la_k_get_mc_t : public OpcodeBase { -public: - MYFLT *k_value_r; - MYFLT *k_value_i; - MYFLT *i_mc; - MYFLT *k_row; - MYFLT *k_column; - la_i_mc_create_t *mc; - int init(CSOUND *) { - toa(i_mc, mc); - return OK; - } - int kontrol(CSOUND *) { - const std::complex &lhs = mc->mc(size_t(*k_row), size_t(*k_column)); - *k_value_r = lhs.real(); - *k_value_i = lhs.imag(); - return OK; - } -}; - -class la_i_transpose_mr_t : public OpcodeBase { -public: - MYFLT *imr_lhs; - MYFLT *imr_rhs; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(imr_lhs, lhs); - toa(imr_rhs, rhs); - gmm::copy(gmm::transposed(rhs->mr), lhs->mr); - return OK; - } -}; - -class la_k_transpose_mr_t : public OpcodeBase { -public: - MYFLT *imr_lhs; - MYFLT *imr_rhs; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(imr_lhs, lhs); - toa(imr_rhs, rhs); - return OK; - } - int kontrol(CSOUND *) { - gmm::copy(gmm::transposed(rhs->mr), lhs->mr); - return OK; - } -}; - -class la_i_transpose_mc_t : public OpcodeBase { -public: - MYFLT *imc_lhs; - MYFLT *imc_rhs; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(imc_lhs, lhs); - toa(imc_rhs, rhs); - gmm::copy(gmm::transposed(rhs->mc), lhs->mc); - return OK; - } -}; - -class la_k_transpose_mc_t : public OpcodeBase { -public: - MYFLT *imc_lhs; - MYFLT *imc_rhs; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(imc_lhs, lhs); - toa(imc_rhs, rhs); - return OK; - } - int kontrol(CSOUND *) { - gmm::copy(gmm::transposed(rhs->mc), lhs->mc); - return OK; - } -}; - -class la_i_conjugate_vr_t : public OpcodeBase { -public: - MYFLT *ivr_lhs; - MYFLT *ivr_rhs; - la_i_vr_create_t *lhs; - la_i_vr_create_t *rhs; - int init(CSOUND *) { - toa(ivr_lhs, lhs); - toa(ivr_rhs, rhs); - gmm::copy(gmm::conjugated(rhs->vr), lhs->vr); - return OK; - } -}; - -class la_k_conjugate_vr_t : public OpcodeBase { -public: - MYFLT *ivr_lhs; - MYFLT *ivr_rhs; - la_i_vr_create_t *lhs; - la_i_vr_create_t *rhs; - int init(CSOUND *) { - toa(ivr_lhs, lhs); - toa(ivr_rhs, rhs); - return OK; - } - int kontrol(CSOUND *) { - gmm::copy(gmm::conjugated(rhs->vr), lhs->vr); - return OK; - } -}; - -class la_i_conjugate_vc_t : public OpcodeBase { -public: - MYFLT *ivc_lhs; - MYFLT *ivc_rhs; - la_i_vc_create_t *lhs; - la_i_vc_create_t *rhs; - int init(CSOUND *) { - toa(ivc_lhs, lhs); - toa(ivc_rhs, rhs); - gmm::copy(gmm::conjugated(rhs->vc), lhs->vc); - return OK; - } -}; - -class la_k_conjugate_vc_t : public OpcodeBase { -public: - MYFLT *ivc_lhs; - MYFLT *ivc_rhs; - la_i_vc_create_t *lhs; - la_i_vc_create_t *rhs; - int init(CSOUND *) { - toa(ivc_lhs, lhs); - toa(ivc_rhs, rhs); - return OK; - } - int kontrol(CSOUND *) { - gmm::copy(gmm::conjugated(rhs->vc), lhs->vc); - return OK; - } -}; - -class la_i_conjugate_mr_t : public OpcodeBase { -public: - MYFLT *imr_lhs; - MYFLT *imr_rhs; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(imr_lhs, lhs); - toa(imr_rhs, rhs); - gmm::copy(gmm::conjugated(rhs->mr), lhs->mr); - return OK; - } -}; - -class la_k_conjugate_mr_t : public OpcodeBase { -public: - MYFLT *imr_lhs; - MYFLT *imr_rhs; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(imr_lhs, lhs); - toa(imr_rhs, rhs); - return OK; - } - int kontrol(CSOUND *) { - gmm::copy(gmm::conjugated(rhs->mr), lhs->mr); - return OK; - } -}; - -class la_i_conjugate_mc_t : public OpcodeBase { -public: - MYFLT *imc_lhs; - MYFLT *imc_rhs; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(imc_lhs, lhs); - toa(imc_rhs, rhs); - gmm::copy(gmm::conjugated(rhs->mc), lhs->mc); - return OK; - } -}; - -class la_k_conjugate_mc_t : public OpcodeBase { -public: - MYFLT *imc_lhs; - MYFLT *imc_rhs; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(imc_lhs, lhs); - toa(imc_rhs, rhs); - return OK; - } - int kontrol(CSOUND *) { - gmm::copy(gmm::conjugated(rhs->mc), lhs->mc); - return OK; - } -}; - -class la_i_norm1_vr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_vr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::vect_norm1(rhs->vr); - return OK; - } -}; - -class la_k_norm1_vr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_vr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::vect_norm1(rhs->vr); - return OK; - } -}; - -class la_i_norm1_vc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_vc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::vect_norm1(rhs->vc); - return OK; - } -}; - -class la_k_norm1_vc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_vc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::vect_norm1(rhs->vc); - return OK; - } -}; - -class la_i_norm1_mr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_norm1(rhs->mr); - return OK; - } -}; - -class la_k_norm1_mr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_norm1(rhs->mr); - return OK; - } -}; - -class la_i_norm1_mc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_norm1(rhs->mc); - return OK; - } -}; - -class la_k_norm1_mc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_norm1(rhs->mc); - return OK; - } -}; - -class la_i_norm_euclid_vr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_vr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::vect_norm2(rhs->vr); - return OK; - } -}; - -class la_k_norm_euclid_vr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_vr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::vect_norm2(rhs->vr); - return OK; - } -}; - -class la_i_norm_euclid_vc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_vc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::vect_norm2(rhs->vc); - return OK; - } -}; - -class la_k_norm_euclid_vc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_vc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::vect_norm2(rhs->vc); - return OK; - } -}; - -class la_i_norm_euclid_mr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_euclidean_norm(rhs->mr); - return OK; - } -}; - -class la_k_norm_euclid_mr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_euclidean_norm(rhs->mr); - return OK; - } -}; - -class la_i_norm_euclid_mc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_euclidean_norm(rhs->mc); - return OK; - } -}; - -class la_k_norm_euclid_mc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_euclidean_norm(rhs->mc); - return OK; - } -}; - -class la_i_distance_vr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_1_; - MYFLT *rhs_2_; - la_i_vr_create_t *rhs_1; - la_i_vr_create_t *rhs_2; - int init(CSOUND *) { - toa(rhs_1_, rhs_1); - toa(rhs_2_, rhs_2); - *lhs = gmm::vect_dist2(rhs_1->vr, rhs_2->vr); - return OK; - } -}; - -class la_k_distance_vr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_1_; - MYFLT *rhs_2_; - la_i_vr_create_t *rhs_1; - la_i_vr_create_t *rhs_2; - int init(CSOUND *) { - toa(rhs_1_, rhs_1); - toa(rhs_2_, rhs_2); - return OK; - } - int kontrol(CSOUND *) { - *lhs = gmm::vect_dist2(rhs_1->vr, rhs_2->vr); - return OK; - } -}; - -class la_i_distance_vc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_1_; - MYFLT *rhs_2_; - la_i_vc_create_t *rhs_1; - la_i_vc_create_t *rhs_2; - int init(CSOUND *) { - toa(rhs_1_, rhs_1); - toa(rhs_2_, rhs_2); - *lhs = gmm::vect_dist2(rhs_1->vc, rhs_2->vc); - return OK; - } -}; - -class la_k_distance_vc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_1_; - MYFLT *rhs_2_; - la_i_vc_create_t *rhs_1; - la_i_vc_create_t *rhs_2; - int init(CSOUND *) { - toa(rhs_1_, rhs_1); - toa(rhs_2_, rhs_2); - return OK; - } - int kontrol(CSOUND *) { - *lhs = gmm::vect_dist2(rhs_1->vc, rhs_2->vc); - return OK; - } -}; - -class la_i_norm_max_mr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_maxnorm(rhs->mr); - return OK; - } -}; - -class la_k_norm_max_mr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_maxnorm(rhs->mr); - return OK; - } -}; - -class la_i_norm_max_mc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_maxnorm(rhs->mc); - return OK; - } -}; - -class la_k_norm_max_mc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_maxnorm(rhs->mc); - return OK; - } -}; - -class la_i_norm_inf_vr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_vr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::vect_norminf(rhs->vr); - return OK; - } -}; - -class la_k_norm_inf_vr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_vr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::vect_norminf(rhs->vr); - return OK; - } -}; - -class la_i_norm_inf_vc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_vc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::vect_norminf(rhs->vc); - return OK; - } -}; - -class la_k_norm_inf_vc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_vc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::vect_norminf(rhs->vc); - return OK; - } -}; - -class la_i_norm_inf_mr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_norminf(rhs->mr); - return OK; - } -}; - -class la_k_norm_inf_mr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_norminf(rhs->mr); - return OK; - } -}; - -class la_i_norm_inf_mc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_norminf(rhs->mc); - return OK; - } -}; - -class la_k_norm_inf_mc_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_norminf(rhs->mc); - return OK; - } -}; - -class la_i_trace_mr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_trace(rhs->mr); - return OK; - } -}; - -class la_k_trace_mr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::mat_trace(rhs->mr); - return OK; - } -}; - -class la_i_trace_mc_t : public OpcodeBase { -public: - MYFLT *lhs_r; - MYFLT *lhs_i; - MYFLT *rhs_; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - const std::complex &lhs = gmm::mat_trace(rhs->mc); - *lhs_r = lhs.real(); - *lhs_i = lhs.imag(); - return OK; - } -}; - -class la_k_trace_mc_t : public OpcodeBase { -public: - MYFLT *lhs_r; - MYFLT *lhs_i; - MYFLT *rhs_; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - const std::complex &lhs = gmm::mat_trace(rhs->mc); - *lhs_r = lhs.real(); - *lhs_i = lhs.imag(); - return OK; - } -}; - -class la_i_lu_det_mr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::lu_det(rhs->mr); - return OK; - } -}; - -class la_k_lu_det_mr_t : public OpcodeBase { -public: - MYFLT *lhs; - MYFLT *rhs_; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - *lhs = gmm::lu_det(rhs->mr); - return OK; - } -}; - -class la_i_lu_det_mc_t : public OpcodeBase { -public: - MYFLT *lhs_r; - MYFLT *lhs_i; - MYFLT *rhs_; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - const std::complex &lhs = gmm::lu_det(rhs->mc); - *lhs_r = lhs.real(); - *lhs_i = lhs.imag(); - return OK; - } -}; - -class la_k_lu_det_mc_t : public OpcodeBase { -public: - MYFLT *lhs_r; - MYFLT *lhs_i; - MYFLT *rhs_; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - toa(rhs_, rhs); - const std::complex &lhs = gmm::lu_det(rhs->mc); - *lhs_r = lhs.real(); - *lhs_i = lhs.imag(); - return OK; - } -}; - -/** - * Elementwise addition. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a += b. - */ -class la_i_add_vr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vr_create_t *lhs; - la_i_vr_create_t *rhs_a; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - for (size_t i = 0, n = rhs_a->vr.size(); i < n; ++i) { - lhs->vr[i] = rhs_a->vr[i] + rhs_b->vr[i]; - } - return OK; - } -}; - -/** - * Elementwise addition. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a += b. - */ -class la_k_add_vr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vr_create_t *lhs; - la_i_vr_create_t *rhs_a; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - for (size_t i = 0, n = rhs_a->vr.size(); i < n; ++i) { - lhs->vr[i] = rhs_a->vr[i] + rhs_b->vr[i]; - } - return OK; - } -}; - -/** - * Elementwise addition. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a += b. - */ -class la_i_add_vc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vc_create_t *lhs; - la_i_vc_create_t *rhs_a; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - for (size_t i = 0, n = rhs_a->vc.size(); i < n; ++i) { - lhs->vc[i] = rhs_a->vc[i] + rhs_b->vc[i]; - } - return OK; - } -}; - -/** - * Elementwise addition. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a += b. - */ -class la_k_add_vc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vc_create_t *lhs; - la_i_vc_create_t *rhs_a; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - for (size_t i = 0, n = rhs_a->vc.size(); i < n; ++i) { - lhs->vc[i] = rhs_a->vc[i] + rhs_b->vc[i]; - } - return OK; - } -}; - -/** - * Elementwise addition. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A += B. - */ -class la_i_add_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs_a; - la_i_mr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - size_t rowN = gmm::mat_nrows(rhs_a->mr); - size_t columnN = gmm::mat_ncols(rhs_a->mr); - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mr(rowI, columnI) = - rhs_a->mr(rowI, columnI) + rhs_b->mr(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise addition. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A += B. - */ -class la_k_add_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs_a; - la_i_mr_create_t *rhs_b; - size_t rowN; - size_t columnN; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - rowN = gmm::mat_nrows(rhs_a->mr); - columnN = gmm::mat_ncols(rhs_a->mr); - return OK; - } - int kontrol(CSOUND *) { - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mr(rowI, columnI) = - rhs_a->mr(rowI, columnI) + rhs_b->mr(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise addition. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A += B. - */ -class la_i_add_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs_a; - la_i_mc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - size_t rowN = gmm::mat_nrows(rhs_a->mc); - size_t columnN = gmm::mat_ncols(rhs_a->mc); - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mc(rowI, columnI) = - rhs_a->mc(rowI, columnI) + rhs_b->mc(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise addition. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A += B. - */ -class la_k_add_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs_a; - la_i_mc_create_t *rhs_b; - size_t rowN; - size_t columnN; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - rowN = gmm::mat_nrows(rhs_a->mc); - columnN = gmm::mat_ncols(rhs_a->mc); - return OK; - } - int kontrol(CSOUND *) { - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mc(rowI, columnI) = - rhs_a->mc(rowI, columnI) + rhs_b->mc(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise subtraction. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a -= b. - */ -class la_i_subtract_vr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vr_create_t *lhs; - la_i_vr_create_t *rhs_a; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - for (size_t i = 0, n = rhs_a->vr.size(); i < n; ++i) { - lhs->vr[i] = rhs_a->vr[i] - rhs_b->vr[i]; - } - return OK; - } -}; - -/** - * Elementwise subtraction. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a -= b. - */ -class la_k_subtract_vr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vr_create_t *lhs; - la_i_vr_create_t *rhs_a; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - for (size_t i = 0, n = rhs_a->vr.size(); i < n; ++i) { - lhs->vr[i] = rhs_a->vr[i] - rhs_b->vr[i]; - } - return OK; - } -}; - -/** - * Elementwise subtraction. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a -= b. - */ -class la_i_subtract_vc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vc_create_t *lhs; - la_i_vc_create_t *rhs_a; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - for (size_t i = 0, n = rhs_a->vc.size(); i < n; ++i) { - lhs->vc[i] = rhs_a->vc[i] - rhs_b->vc[i]; - } - return OK; - } -}; - -/** - * Elementwise subtraction. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a -= b. - */ -class la_k_subtract_vc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vc_create_t *lhs; - la_i_vc_create_t *rhs_a; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - for (size_t i = 0, n = rhs_a->vc.size(); i < n; ++i) { - lhs->vc[i] = rhs_a->vc[i] - rhs_b->vc[i]; - } - return OK; - } -}; - -/** - * Elementwise subtraction. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A -= B. - */ -class la_i_subtract_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs_a; - la_i_mr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - size_t rowN = gmm::mat_nrows(rhs_a->mr); - size_t columnN = gmm::mat_ncols(rhs_a->mr); - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mr(rowI, columnI) = - rhs_a->mr(rowI, columnI) - rhs_b->mr(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise subtraction. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A -= B. - */ -class la_k_subtract_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs_a; - la_i_mr_create_t *rhs_b; - size_t rowN; - size_t columnN; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - rowN = gmm::mat_nrows(rhs_a->mr); - columnN = gmm::mat_ncols(rhs_a->mr); - return OK; - } - int kontrol(CSOUND *) { - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mr(rowI, columnI) = - rhs_a->mr(rowI, columnI) - rhs_b->mr(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise subtraction. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A -= B. - */ -class la_i_subtract_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs_a; - la_i_mc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - size_t rowN = gmm::mat_nrows(rhs_a->mc); - size_t columnN = gmm::mat_ncols(rhs_a->mc); - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mc(rowI, columnI) = - rhs_a->mc(rowI, columnI) - rhs_b->mc(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise subtraction. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A -= B. - */ -class la_k_subtract_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs_a; - la_i_mc_create_t *rhs_b; - size_t rowN; - size_t columnN; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - rowN = gmm::mat_nrows(rhs_a->mc); - columnN = gmm::mat_ncols(rhs_a->mc); - return OK; - } - int kontrol(CSOUND *) { - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mc(rowI, columnI) = - rhs_a->mc(rowI, columnI) - rhs_b->mc(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise multiplication. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a *= b. - */ -class la_i_multiply_vr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vr_create_t *lhs; - la_i_vr_create_t *rhs_a; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - for (size_t i = 0, n = rhs_a->vr.size(); i < n; ++i) { - lhs->vr[i] = rhs_a->vr[i] * rhs_b->vr[i]; - } - return OK; - } -}; - -/** - * Elementwise multiplication. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a *= b. - */ -class la_k_multiply_vr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vr_create_t *lhs; - la_i_vr_create_t *rhs_a; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - for (size_t i = 0, n = rhs_a->vr.size(); i < n; ++i) { - lhs->vr[i] = rhs_a->vr[i] * rhs_b->vr[i]; - } - return OK; - } -}; - -/** - * Elementwise multiplication. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a *= b. - */ -class la_i_multiply_vc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vc_create_t *lhs; - la_i_vc_create_t *rhs_a; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - for (size_t i = 0, n = rhs_a->vc.size(); i < n; ++i) { - lhs->vc[i] = rhs_a->vc[i] * rhs_b->vc[i]; - } - return OK; - } -}; - -/** - * Elementwise multiplication. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a *= b. - */ -class la_k_multiply_vc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vc_create_t *lhs; - la_i_vc_create_t *rhs_a; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - for (size_t i = 0, n = rhs_a->vc.size(); i < n; ++i) { - lhs->vc[i] = rhs_a->vc[i] * rhs_b->vc[i]; - } - return OK; - } -}; - -/** - * Elementwise multiplication. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A *= B. - */ -class la_i_multiply_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs_a; - la_i_mr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - size_t rowN = gmm::mat_nrows(rhs_a->mr); - size_t columnN = gmm::mat_ncols(rhs_a->mr); - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mr(rowI, columnI) = - rhs_a->mr(rowI, columnI) * rhs_b->mr(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise multiplication. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A *= B. - */ -class la_k_multiply_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs_a; - la_i_mr_create_t *rhs_b; - size_t rowN; - size_t columnN; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - rowN = gmm::mat_nrows(rhs_a->mr); - columnN = gmm::mat_ncols(rhs_a->mr); - return OK; - } - int kontrol(CSOUND *) { - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mr(rowI, columnI) = - rhs_a->mr(rowI, columnI) * rhs_b->mr(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise multiplication. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A *= B. - */ -class la_i_multiply_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs_a; - la_i_mc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - size_t rowN = gmm::mat_nrows(rhs_a->mc); - size_t columnN = gmm::mat_ncols(rhs_a->mc); - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mc(rowI, columnI) = - rhs_a->mc(rowI, columnI) * rhs_b->mc(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise multiplication. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A *= B. - */ -class la_k_multiply_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs_a; - la_i_mc_create_t *rhs_b; - size_t rowN; - size_t columnN; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - rowN = gmm::mat_nrows(rhs_a->mc); - columnN = gmm::mat_ncols(rhs_a->mc); - return OK; - } - int kontrol(CSOUND *) { - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mc(rowI, columnI) = - rhs_a->mc(rowI, columnI) * rhs_b->mc(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise division. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a /= b. - */ -class la_i_divide_vr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vr_create_t *lhs; - la_i_vr_create_t *rhs_a; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - for (size_t i = 0, n = rhs_a->vr.size(); i < n; ++i) { - lhs->vr[i] = rhs_a->vr[i] / rhs_b->vr[i]; - } - return OK; - } -}; - -/** - * Elementwise division. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a /= b. - */ -class la_k_divide_vr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vr_create_t *lhs; - la_i_vr_create_t *rhs_a; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - for (size_t i = 0, n = rhs_a->vr.size(); i < n; ++i) { - lhs->vr[i] = rhs_a->vr[i] / rhs_b->vr[i]; - } - return OK; - } -}; - -/** - * Elementwise division. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a /= b. - */ -class la_i_divide_vc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vc_create_t *lhs; - la_i_vc_create_t *rhs_a; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - for (size_t i = 0, n = rhs_a->vc.size(); i < n; ++i) { - lhs->vc[i] = rhs_a->vc[i] / rhs_b->vc[i]; - } - return OK; - } -}; - -/** - * Elementwise division. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a /= b. - */ -class la_k_divide_vc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vc_create_t *lhs; - la_i_vc_create_t *rhs_a; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - for (size_t i = 0, n = rhs_a->vc.size(); i < n; ++i) { - lhs->vc[i] = rhs_a->vc[i] / rhs_b->vc[i]; - } - return OK; - } -}; - -/** - * Elementwise division. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A /= B. - */ -class la_i_divide_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs_a; - la_i_mr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - size_t rowN = gmm::mat_nrows(rhs_a->mr); - size_t columnN = gmm::mat_ncols(rhs_a->mr); - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mr(rowI, columnI) = - rhs_a->mr(rowI, columnI) / rhs_b->mr(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise division. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A /= B. - */ -class la_k_divide_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs_a; - la_i_mr_create_t *rhs_b; - size_t rowN; - size_t columnN; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - rowN = gmm::mat_nrows(rhs_a->mr); - columnN = gmm::mat_ncols(rhs_a->mr); - return OK; - } - int kontrol(CSOUND *) { - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mr(rowI, columnI) = - rhs_a->mr(rowI, columnI) / rhs_b->mr(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise division. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A /= B. - */ -class la_i_divide_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs_a; - la_i_mc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - size_t rowN = gmm::mat_nrows(rhs_a->mc); - size_t columnN = gmm::mat_ncols(rhs_a->mc); - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mc(rowI, columnI) = - rhs_a->mc(rowI, columnI) / rhs_b->mc(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise division. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform A /= B. - */ -class la_k_divide_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs_a; - la_i_mc_create_t *rhs_b; - size_t rowN; - size_t columnN; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - rowN = gmm::mat_nrows(rhs_a->mc); - columnN = gmm::mat_ncols(rhs_a->mc); - return OK; - } - int kontrol(CSOUND *) { - for (size_t rowI = 0; rowI < rowN; ++rowI) { - for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mc(rowI, columnI) = - rhs_a->mc(rowI, columnI) / rhs_b->mc(rowI, columnI); - } - } - return OK; - } -}; - -/** - * Elementwise multiplication. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a *= b. - */ -class la_i_dot_vr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vr_create_t *rhs_a; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - *lhs_ = gmm::vect_sp(rhs_a->vr, rhs_b->vr); - return OK; - } -}; - -/** - * Elementwise multiplication. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a *= b. - */ -class la_k_dot_vr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vr_create_t *rhs_a; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - *lhs_ = gmm::vect_sp(rhs_a->vr, rhs_b->vr); - return OK; - } -}; - -/** - * Elementwise multiplication. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a *= b. - */ -class la_i_dot_vc_t : public OpcodeBase { -public: - MYFLT *lhs_r; - MYFLT *lhs_i; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vc_create_t *rhs_a; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - std::complex lhs = gmm::vect_sp(rhs_a->vc, rhs_b->vc); - *lhs_r = lhs.real(); - *lhs_i = lhs.imag(); - return OK; - } -}; - -/** - * Elementwise multiplication. - * The array on the left-hand side can also appear - * on the right-hand side in order to perform a *= b. - */ -class la_k_dot_vc_t : public OpcodeBase { -public: - MYFLT *lhs_r; - MYFLT *lhs_i; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vc_create_t *rhs_a; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - std::complex lhs = gmm::vect_sp(rhs_a->vc, rhs_b->vc); - *lhs_r = lhs.real(); - *lhs_i = lhs.imag(); - return OK; - } -}; - -class la_i_dot_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs_a; - la_i_mr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - gmm::mult(rhs_a->mr, rhs_b->mr, lhs->mr); - return OK; - } -}; - -class la_k_dot_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs_a; - la_i_mr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - gmm::mult(rhs_a->mr, rhs_b->mr, lhs->mr); - return OK; - } - int kontrol(CSOUND *) { - gmm::mult(rhs_a->mr, rhs_b->mr, lhs->mr); - return OK; - } -}; - -class la_i_dot_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs_a; - la_i_mc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - gmm::mult(rhs_a->mc, rhs_b->mc, lhs->mc); - return OK; - } -}; - -class la_k_dot_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs_a; - la_i_mc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - gmm::mult(rhs_a->mc, rhs_b->mc, lhs->mc); - return OK; - } -}; - -class la_i_dot_mr_vr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vr_create_t *lhs; - la_i_mr_create_t *rhs_a; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - gmm::mult(rhs_a->mr, rhs_b->vr, lhs->vr); - return OK; - } -}; - -class la_k_dot_mr_vr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vr_create_t *lhs; - la_i_mr_create_t *rhs_a; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - gmm::mult(rhs_a->mr, rhs_b->vr, lhs->vr); - return OK; - } -}; - -class la_i_dot_mc_vc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vc_create_t *lhs; - la_i_mc_create_t *rhs_a; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - gmm::mult(rhs_a->mc, rhs_b->vc, lhs->vc); - return OK; - } -}; - -class la_k_dot_mc_vc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_a_; - MYFLT *rhs_b_; - la_i_vc_create_t *lhs; - la_i_mc_create_t *rhs_a; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_a_, rhs_a); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - gmm::mult(rhs_a->mc, rhs_b->vc, lhs->vc); - return OK; - } -}; - -class la_i_invert_mr_t : public OpcodeBase { -public: - MYFLT *imr_lhs; - MYFLT *icondition; - MYFLT *imr_rhs; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(imr_lhs, lhs); - toa(imr_rhs, rhs); - gmm::copy(rhs->mr, lhs->mr); - *icondition = gmm::lu_inverse(lhs->mr); - return OK; - } -}; - -class la_k_invert_mr_t : public OpcodeBase { -public: - MYFLT *imr_lhs; - MYFLT *kcondition; - MYFLT *imr_rhs; - la_i_mr_create_t *lhs; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(imr_lhs, lhs); - toa(imr_rhs, rhs); - return OK; - } - int kontrol(CSOUND *) { - gmm::copy(rhs->mr, lhs->mr); - *kcondition = gmm::lu_inverse(lhs->mr); - return OK; - } -}; - -class la_i_invert_mc_t : public OpcodeBase { -public: - MYFLT *imc_lhs; - MYFLT *icondition_r; - MYFLT *icondition_i; - MYFLT *imc_rhs; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(imc_lhs, lhs); - toa(imc_rhs, rhs); - gmm::copy(rhs->mc, lhs->mc); - std::complex condition = gmm::lu_inverse(lhs->mc); - *icondition_r = condition.real(); - *icondition_i = condition.imag(); - return OK; - } -}; - -class la_k_invert_mc_t : public OpcodeBase { -public: - MYFLT *imc_lhs; - MYFLT *kcondition_r; - MYFLT *kcondition_i; - MYFLT *imc_rhs; - la_i_mc_create_t *lhs; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(imc_lhs, lhs); - toa(imc_rhs, rhs); - return OK; - } - int kontrol(CSOUND *) { - gmm::copy(rhs->mc, lhs->mc); - std::complex condition = gmm::lu_inverse(lhs->mc); - *kcondition_r = condition.real(); - *kcondition_i = condition.imag(); - return OK; - } -}; - -class la_i_upper_solve_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_; - MYFLT *is_unit; - la_i_vr_create_t *lhs; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_, rhs); - gmm::upper_tri_solve(rhs->mr, lhs->vr, bool(*is_unit)); - return OK; - } -}; - -class la_k_upper_solve_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_; - MYFLT *is_unit; - la_i_vr_create_t *lhs; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - gmm::upper_tri_solve(rhs->mr, lhs->vr, bool(*is_unit)); - return OK; - } -}; - -class la_i_upper_solve_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_; - MYFLT *is_unit; - la_i_vc_create_t *lhs; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_, rhs); - gmm::upper_tri_solve(rhs->mc, lhs->vc, bool(*is_unit)); - return OK; - } -}; - -class la_k_upper_solve_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_; - MYFLT *is_unit; - la_i_vc_create_t *lhs; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - gmm::upper_tri_solve(rhs->mc, lhs->vc, bool(*is_unit)); - return OK; - } -}; - -class la_i_lower_solve_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_; - MYFLT *is_unit; - la_i_vr_create_t *lhs; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_, rhs); - gmm::lower_tri_solve(rhs->mr, lhs->vr, bool(*is_unit)); - return OK; - } -}; - -class la_k_lower_solve_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_; - MYFLT *is_unit; - la_i_vr_create_t *lhs; - la_i_mr_create_t *rhs; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - gmm::lower_tri_solve(rhs->mr, lhs->vr, bool(*is_unit)); - return OK; - } -}; - -class la_i_lower_solve_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_; - MYFLT *is_unit; - la_i_vc_create_t *lhs; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_, rhs); - gmm::lower_tri_solve(rhs->mc, lhs->vc, bool(*is_unit)); - return OK; - } -}; - -class la_k_lower_solve_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *rhs_; - MYFLT *is_unit; - la_i_vc_create_t *lhs; - la_i_mc_create_t *rhs; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - gmm::lower_tri_solve(rhs->mc, lhs->vc, bool(*is_unit)); - return OK; - } -}; - -class la_i_lu_factor_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *pivot_; - MYFLT *isize; - MYFLT *rhs_; - la_i_mr_create_t *lhs; - la_i_vr_create_t *pivot; - la_i_mr_create_t *rhs; -#if defined(GMM_VERSION) - gmm::lapack_ipvt pivot__; -#else - std::vector pivot__; -#endif - size_t pivot_size; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_, pivot); - toa(rhs_, rhs); - pivot_size = gmm::mat_nrows(rhs->mr); - pivot__.resize(pivot_size); - gmm::copy(rhs->mr, lhs->mr); - *isize = gmm::lu_factor(lhs->mr, pivot__); - for (size_t i = 0; i < pivot_size; ++i) { -#if defined(GMM_VERSION) - pivot->vr[i] = pivot__.get(i); -#else - pivot->vr[i] = pivot__[i]; -#endif - } - return OK; - } -}; - -class la_k_lu_factor_mr_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *pivot_; - MYFLT *ksize; - MYFLT *rhs_; - la_i_mr_create_t *lhs; - la_i_vr_create_t *pivot; - la_i_mr_create_t *rhs; -#if defined(GMM_VERSION) - gmm::lapack_ipvt pivot__; -#else - std::vector pivot__; -#endif - size_t pivot_size; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_, pivot); - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - pivot_size = gmm::mat_nrows(rhs->mr); - pivot__.resize(pivot_size); - gmm::copy(rhs->mr, lhs->mr); - *ksize = gmm::lu_factor(lhs->mr, pivot__); - for (size_t i = 0; i < pivot_size; ++i) { -#if defined(GMM_VERSION) - pivot->vr[i] = pivot__.get(i); -#else - pivot->vr[i] = pivot__[i]; -#endif - } - return OK; - } -}; - -class la_i_lu_factor_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *pivot_; - MYFLT *isize; - MYFLT *rhs_; - la_i_mc_create_t *lhs; - la_i_vr_create_t *pivot; - la_i_mc_create_t *rhs; -#if defined(GMM_VERSION) - gmm::lapack_ipvt pivot__; -#else - std::vector pivot__; -#endif - size_t pivot_size; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_, pivot); - toa(rhs_, rhs); - pivot_size = gmm::mat_nrows(rhs->mc); - pivot__.resize(pivot_size); - gmm::copy(rhs->mc, lhs->mc); - *isize = gmm::lu_factor(lhs->mc, pivot__); - for (size_t i = 0; i < pivot_size; ++i) { -#if defined(GMM_VERSION) - pivot->vr[i] = pivot__.get(i); -#else - pivot->vr[i] = pivot__[i]; -#endif - } - return OK; - } -}; - -class la_k_lu_factor_mc_t : public OpcodeBase { -public: - MYFLT *lhs_; - MYFLT *pivot_; - MYFLT *ksize; - MYFLT *rhs_; - la_i_mc_create_t *lhs; - la_i_vr_create_t *pivot; - la_i_mc_create_t *rhs; -#if defined(GMM_VERSION) - gmm::lapack_ipvt pivot__; -#else - std::vector pivot__; -#endif - size_t pivot_size; - int init(CSOUND *) { - toa(lhs_, lhs); - toa(rhs_, pivot); - toa(rhs_, rhs); - return OK; - } - int kontrol(CSOUND *) { - pivot_size = gmm::mat_nrows(rhs->mc); - pivot__.resize(pivot_size); - gmm::copy(rhs->mc, lhs->mc); - *ksize = gmm::lu_factor(lhs->mc, pivot__); - for (size_t i = 0; i < pivot_size; ++i) { -#if defined(GMM_VERSION) - pivot->vr[i] = pivot__.get(i); -#else - pivot->vr[i] = pivot__[i]; -#endif - } - return OK; - } -}; - -class la_i_lu_solve_mr_t : public OpcodeBase { -public: - MYFLT *lhs_x_; - MYFLT *rhs_A_; - MYFLT *rhs_b_; - la_i_vr_create_t *lhs_x; - la_i_mr_create_t *rhs_A; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_x_, lhs_x); - toa(rhs_A_, rhs_A); - toa(rhs_b_, rhs_b); - gmm::lu_solve(rhs_A->mr, lhs_x->vr, rhs_b->vr); - return OK; - } -}; - -class la_k_lu_solve_mr_t : public OpcodeBase { -public: - MYFLT *lhs_x_; - MYFLT *rhs_A_; - MYFLT *rhs_b_; - la_i_vr_create_t *lhs_x; - la_i_mr_create_t *rhs_A; - la_i_vr_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_x_, lhs_x); - toa(rhs_A_, rhs_A); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - gmm::lu_solve(rhs_A->mr, lhs_x->vr, rhs_b->vr); - return OK; - } -}; - -class la_i_lu_solve_mc_t : public OpcodeBase { -public: - MYFLT *lhs_x_; - MYFLT *rhs_A_; - MYFLT *rhs_b_; - la_i_vc_create_t *lhs_x; - la_i_mc_create_t *rhs_A; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_x_, lhs_x); - toa(rhs_A_, rhs_A); - toa(rhs_b_, rhs_b); - gmm::lu_solve(rhs_A->mc, lhs_x->vc, rhs_b->vc); - return OK; - } -}; - -class la_k_lu_solve_mc_t : public OpcodeBase { -public: - MYFLT *lhs_x_; - MYFLT *rhs_A_; - MYFLT *rhs_b_; - la_i_vc_create_t *lhs_x; - la_i_mc_create_t *rhs_A; - la_i_vc_create_t *rhs_b; - int init(CSOUND *) { - toa(lhs_x_, lhs_x); - toa(rhs_A_, rhs_A); - toa(rhs_b_, rhs_b); - return OK; - } - int kontrol(CSOUND *) { - gmm::lu_solve(rhs_A->mc, lhs_x->vc, rhs_b->vc); - return OK; - } -}; - -class la_i_qr_factor_mr_t : public OpcodeBase { -public: - MYFLT *lhs_Q_; - MYFLT *lhs_R_; - MYFLT *rhs_A_; - la_i_mr_create_t *lhs_Q; - la_i_mr_create_t *lhs_R; - la_i_mr_create_t *rhs_A; - int init(CSOUND *) { - toa(lhs_Q_, lhs_Q); - toa(lhs_R_, lhs_R); - toa(rhs_A_, rhs_A); - gmm::qr_factor(rhs_A->mr, lhs_Q->mr, lhs_R->mr); - return OK; - } -}; - -class la_k_qr_factor_mr_t : public OpcodeBase { -public: - MYFLT *lhs_Q_; - MYFLT *lhs_R_; - MYFLT *rhs_A_; - la_i_mr_create_t *lhs_Q; - la_i_mr_create_t *lhs_R; - la_i_mr_create_t *rhs_A; - int init(CSOUND *) { - toa(lhs_Q_, lhs_Q); - toa(lhs_R_, lhs_R); - toa(rhs_A_, rhs_A); - return OK; - } - int kontrol(CSOUND *) { - gmm::qr_factor(rhs_A->mr, lhs_Q->mr, lhs_R->mr); - return OK; - } -}; - -class la_i_qr_factor_mc_t : public OpcodeBase { -public: - MYFLT *lhs_Q_; - MYFLT *lhs_R_; - MYFLT *rhs_A_; - la_i_mc_create_t *lhs_Q; - la_i_mc_create_t *lhs_R; - la_i_mc_create_t *rhs_A; - int init(CSOUND *) { - toa(lhs_Q_, lhs_Q); - toa(lhs_R_, lhs_R); - toa(rhs_A_, rhs_A); - gmm::qr_factor(rhs_A->mc, lhs_Q->mc, lhs_R->mc); - return OK; - } -}; - -class la_k_qr_factor_mc_t : public OpcodeBase { -public: - MYFLT *lhs_Q_; - MYFLT *lhs_R_; - MYFLT *rhs_A_; - la_i_mc_create_t *lhs_Q; - la_i_mc_create_t *lhs_R; - la_i_mc_create_t *rhs_A; - int init(CSOUND *) { - toa(lhs_Q_, lhs_Q); - toa(lhs_R_, lhs_R); - toa(rhs_A_, rhs_A); - return OK; - } - int kontrol(CSOUND *) { - gmm::qr_factor(rhs_A->mc, lhs_Q->mc, lhs_R->mc); - return OK; - } -}; - -class la_i_qr_eigen_mr_t : public OpcodeBase { -public: - MYFLT *lhs_eigenvalues_; - MYFLT *rhs_A_; - MYFLT *itolerance; - la_i_vr_create_t *lhs_eigenvalues; - la_i_mr_create_t *rhs_A; - int init(CSOUND *) { - toa(lhs_eigenvalues_, lhs_eigenvalues); - toa(rhs_A_, rhs_A); - gmm::implicit_qr_algorithm(rhs_A->mr, lhs_eigenvalues->vr, - double(*itolerance)); - return OK; - } -}; - -class la_k_qr_eigen_mr_t : public OpcodeBase { -public: - MYFLT *lhs_eigenvalues_; - MYFLT *rhs_A_; - MYFLT *ktolerance; - la_i_vr_create_t *lhs_eigenvalues; - la_i_mr_create_t *rhs_A; - int init(CSOUND *) { - toa(lhs_eigenvalues_, lhs_eigenvalues); - toa(rhs_A_, rhs_A); - return OK; - } - int kontrol(CSOUND *) { - gmm::implicit_qr_algorithm(rhs_A->mr, lhs_eigenvalues->vr, - double(*ktolerance)); - return OK; - } -}; - -class la_i_qr_eigen_mc_t : public OpcodeBase { -public: - MYFLT *lhs_eigenvalues_; - MYFLT *rhs_A_; - MYFLT *itolerance; - la_i_vc_create_t *lhs_eigenvalues; - la_i_mc_create_t *rhs_A; - int init(CSOUND *) { - toa(lhs_eigenvalues_, lhs_eigenvalues); - toa(rhs_A_, rhs_A); - gmm::implicit_qr_algorithm(rhs_A->mc, lhs_eigenvalues->vc, - double(*itolerance)); - return OK; - } -}; - -class la_k_qr_eigen_mc_t : public OpcodeBase { -public: - MYFLT *lhs_eigenvalues_; - MYFLT *rhs_A_; - MYFLT *ktolerance; - la_i_vc_create_t *lhs_eigenvalues; - la_i_mc_create_t *rhs_A; - int init(CSOUND *) { - toa(lhs_eigenvalues_, lhs_eigenvalues); - toa(rhs_A_, rhs_A); - return OK; - } - int kontrol(CSOUND *) { - gmm::implicit_qr_algorithm(rhs_A->mc, lhs_eigenvalues->vc, - double(*ktolerance)); - return OK; - } -}; - -class la_i_qr_sym_eigen_mr_t : public OpcodeBase { -public: - MYFLT *lhs_eigenvalues_; - MYFLT *lhs_eigenvectors_; - MYFLT *rhs_A_; - MYFLT *itolerance; - la_i_vr_create_t *lhs_eigenvalues; - la_i_mr_create_t *lhs_eigenvectors; - la_i_mr_create_t *rhs_A; - int init(CSOUND *) { - toa(lhs_eigenvalues_, lhs_eigenvalues); - toa(lhs_eigenvectors_, lhs_eigenvectors); - toa(rhs_A_, rhs_A); - gmm::implicit_qr_algorithm(rhs_A->mr, lhs_eigenvalues->vr, - lhs_eigenvectors->mr, double(*itolerance)); - return OK; - } -}; - -class la_k_qr_sym_eigen_mr_t : public OpcodeBase { -public: - MYFLT *lhs_eigenvalues_; - MYFLT *lhs_eigenvectors_; - MYFLT *rhs_A_; - MYFLT *ktolerance; - la_i_vr_create_t *lhs_eigenvalues; - la_i_mr_create_t *lhs_eigenvectors; - la_i_mr_create_t *rhs_A; - int init(CSOUND *) { - toa(lhs_eigenvalues_, lhs_eigenvalues); - toa(lhs_eigenvectors_, lhs_eigenvectors); - toa(rhs_A_, rhs_A); - return OK; - } - int kontrol(CSOUND *) { - gmm::implicit_qr_algorithm(rhs_A->mr, lhs_eigenvalues->vr, - lhs_eigenvectors->mr, double(*ktolerance)); - return OK; - } -}; - -class la_i_qr_sym_eigen_mc_t : public OpcodeBase { -public: - MYFLT *lhs_eigenvalues_; - MYFLT *lhs_eigenvectors_; - MYFLT *rhs_A_; - MYFLT *itolerance; - la_i_vc_create_t *lhs_eigenvalues; - la_i_mc_create_t *lhs_eigenvectors; - la_i_mc_create_t *rhs_A; - int init(CSOUND *) { - toa(lhs_eigenvalues_, lhs_eigenvalues); - toa(lhs_eigenvectors_, lhs_eigenvectors); - toa(rhs_A_, rhs_A); - gmm::implicit_qr_algorithm(rhs_A->mc, lhs_eigenvalues->vc, - lhs_eigenvectors->mc, double(*itolerance)); - return OK; - } -}; - -class la_k_qr_sym_eigen_mc_t : public OpcodeBase { -public: - MYFLT *lhs_eigenvalues_; - MYFLT *lhs_eigenvectors_; - MYFLT *rhs_A_; - MYFLT *ktolerance; - la_i_vc_create_t *lhs_eigenvalues; - la_i_mc_create_t *lhs_eigenvectors; - la_i_mc_create_t *rhs_A; - int init(CSOUND *) { - toa(lhs_eigenvalues_, lhs_eigenvalues); - toa(lhs_eigenvectors_, lhs_eigenvectors); - toa(rhs_A_, rhs_A); - return OK; - } - int kontrol(CSOUND *) { - gmm::implicit_qr_algorithm(rhs_A->mc, lhs_eigenvalues->vc, - lhs_eigenvectors->mc, double(*ktolerance)); - return OK; - } -}; - -extern "C" { - -PUBLIC int csoundModuleCreate(CSOUND *csound) { return 0; } - -PUBLIC int csoundModuleInit(CSOUND *csound) { - int status = 0; - status |= csound->AppendOpcode( - csound, "la_i_vr_create", sizeof(la_i_vr_create_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_vr_create_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_vc_create", sizeof(la_i_vr_create_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_vc_create_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_mr_create", sizeof(la_i_mr_create_t), 0, 1, "i", "iio", - (int (*)(CSOUND *, void *)) & la_i_mr_create_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_mc_create", sizeof(la_i_mc_create_t), 0, 1, "i", "iioo", - (int (*)(CSOUND *, void *)) & la_i_mc_create_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_size_vr", sizeof(la_i_size_vr_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_size_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_size_vc", sizeof(la_i_size_vc_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_size_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_size_mr", sizeof(la_i_size_mr_t), 0, 1, "ii", "i", - (int (*)(CSOUND *, void *)) & la_i_size_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_size_mc", sizeof(la_i_size_mc_t), 0, 1, "ii", "i", - (int (*)(CSOUND *, void *)) & la_i_size_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_current_f", sizeof(la_k_current_f_t), 0, 3, "k", "f", - (int (*)(CSOUND *, void *)) & la_k_current_f_t::init_, - (int (*)(CSOUND *, void *)) & la_k_current_f_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_current_vr", sizeof(la_k_current_vr_t), 0, 3, "k", "i", - (int (*)(CSOUND *, void *)) & la_k_current_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_current_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_print_vr", sizeof(la_i_print_vr_t), 0, 1, "", "i", - (int (*)(CSOUND *, void *)) & la_i_print_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_print_vc", sizeof(la_i_print_vc_t), 0, 1, "", "i", - (int (*)(CSOUND *, void *)) & la_i_print_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_print_mr", sizeof(la_i_print_mr_t), 0, 1, "", "i", - (int (*)(CSOUND *, void *)) & la_i_print_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_print_mc", sizeof(la_i_print_mc_t), 0, 1, "", "i", - (int (*)(CSOUND *, void *)) & la_i_print_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_assign_vr", sizeof(la_i_assign_vr_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_assign_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_assign_vr", sizeof(la_k_assign_vr_t), 0, 3, "i", "k", - (int (*)(CSOUND *, void *)) & la_k_assign_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_assign_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_assign_vc", sizeof(la_i_assign_vc_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_assign_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_assign_vc", sizeof(la_k_assign_vc_t), 0, 3, "i", "k", - (int (*)(CSOUND *, void *)) & la_k_assign_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_assign_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_assign_mr", sizeof(la_i_assign_mr_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_assign_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_assign_mr", sizeof(la_k_assign_mr_t), 0, 3, "i", "k", - (int (*)(CSOUND *, void *)) & la_k_assign_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_assign_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_assign_mc", sizeof(la_i_assign_mc_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_assign_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_assign_mc", sizeof(la_k_assign_mc_t), 0, 3, "i", "k", - (int (*)(CSOUND *, void *)) & la_k_assign_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_assign_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_assign_a", sizeof(la_k_assign_a_t), 0, 3, "i", "a", - (int (*)(CSOUND *, void *)) & la_k_assign_a_t::init_, - (int (*)(CSOUND *, void *)) & la_k_assign_a_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_assign_t", sizeof(la_i_assign_t_t), TR, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_assign_t_t::init_, - (int (*)(CSOUND *, void *)) & la_i_assign_t_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_assign_t", sizeof(la_k_assign_t_t), TR, 3, "i", "k", - (int (*)(CSOUND *, void *)) & la_k_assign_t_t::init_, - (int (*)(CSOUND *, void *)) & la_k_assign_t_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_assign_f", sizeof(la_k_assign_f_t), 0, 3, "i", "f", - (int (*)(CSOUND *, void *)) & la_k_assign_f_t::init_, - (int (*)(CSOUND *, void *)) & la_k_assign_f_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_a_assign", sizeof(la_k_a_assign_t), 0, 3, "a", "k", - (int (*)(CSOUND *, void *)) & la_k_a_assign_t::init_, - (int (*)(CSOUND *, void *)) & la_k_a_assign_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_t_assign", sizeof(la_i_t_assign_t), TW, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_t_assign_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_t_assign", sizeof(la_k_t_assign_t), TW, 3, "i", "k", - (int (*)(CSOUND *, void *)) & la_k_t_assign_t::init_, - (int (*)(CSOUND *, void *)) & la_k_t_assign_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_f_assign", sizeof(la_k_f_assign_t), 0, 3, "f", "p", - (int (*)(CSOUND *, void *)) & la_k_f_assign_t::init_, - (int (*)(CSOUND *, void *)) & la_k_f_assign_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_random_vr", sizeof(la_i_random_vr_t), 0, 1, "i", "p", - (int (*)(CSOUND *, void *)) & la_i_random_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_random_vr", sizeof(la_k_random_vr_t), 0, 3, "i", "p", - (int (*)(CSOUND *, void *)) & la_k_random_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_random_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_random_vc", sizeof(la_i_random_vc_t), 0, 1, "i", "p", - (int (*)(CSOUND *, void *)) & la_i_random_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_random_vc", sizeof(la_k_random_vc_t), 0, 3, "i", "p", - (int (*)(CSOUND *, void *)) & la_k_random_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_random_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_random_mr", sizeof(la_i_random_mr_t), 0, 1, "i", "p", - (int (*)(CSOUND *, void *)) & la_i_random_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_random_mr", sizeof(la_k_random_mr_t), 0, 3, "i", "p", - (int (*)(CSOUND *, void *)) & la_k_random_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_random_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_random_mc", sizeof(la_i_random_mc_t), 0, 1, "i", "p", - (int (*)(CSOUND *, void *)) & la_i_random_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_random_mc", sizeof(la_k_random_mc_t), 0, 3, "i", "p", - (int (*)(CSOUND *, void *)) & la_k_random_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_random_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_vr_set", sizeof(la_i_vr_set_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_vr_set_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_vr_set", sizeof(la_k_vr_set_t), 0, 3, "i", "kk", - (int (*)(CSOUND *, void *)) & la_k_vr_set_t::init_, - (int (*)(CSOUND *, void *)) & la_k_vr_set_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_vc_set", sizeof(la_i_vc_set_t), 0, 1, "i", "iii", - (int (*)(CSOUND *, void *)) & la_i_vc_set_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_vc_set", sizeof(la_k_vc_set_t), 0, 3, "i", "kkk", - (int (*)(CSOUND *, void *)) & la_k_vc_set_t::init_, - (int (*)(CSOUND *, void *)) & la_k_vc_set_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_mr_set", sizeof(la_i_mr_set_t), 0, 1, "i", "iii", - (int (*)(CSOUND *, void *)) & la_i_mr_set_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_mr_set", sizeof(la_k_mr_set_t), 0, 3, "i", "kkk", - (int (*)(CSOUND *, void *)) & la_k_mr_set_t::init_, - (int (*)(CSOUND *, void *)) & la_k_mr_set_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_mc_set", sizeof(la_i_mc_set_t), 0, 1, "i", "iiii", - (int (*)(CSOUND *, void *)) & la_i_mc_set_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_mc_set", sizeof(la_k_mc_set_t), 0, 3, "i", "kkkk", - (int (*)(CSOUND *, void *)) & la_k_mc_set_t::init_, - (int (*)(CSOUND *, void *)) & la_k_mc_set_t::kontrol_, - (int (*)(CSOUND *, void *))0); - - status |= csound->AppendOpcode( - csound, "la_i_get_vr", sizeof(la_i_get_vr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_get_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_get_vr", sizeof(la_k_get_vr_t), 0, 3, "k", "ik", - (int (*)(CSOUND *, void *)) & la_k_get_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_get_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_get_vc", sizeof(la_i_get_vc_t), 0, 1, "ii", "ii", - (int (*)(CSOUND *, void *)) & la_i_get_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_get_vc", sizeof(la_k_get_vc_t), 0, 3, "kk", "ik", - (int (*)(CSOUND *, void *)) & la_k_get_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_get_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_get_mr", sizeof(la_i_get_mr_t), 0, 1, "i", "iii", - (int (*)(CSOUND *, void *)) & la_i_get_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_get_mr", sizeof(la_k_get_mr_t), 0, 3, "k", "ikk", - (int (*)(CSOUND *, void *)) & la_k_get_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_get_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_get_mc", sizeof(la_i_get_mc_t), 0, 1, "ii", "iii", - (int (*)(CSOUND *, void *)) & la_i_get_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_get_mc", sizeof(la_k_get_mc_t), 0, 3, "kk", "ikk", - (int (*)(CSOUND *, void *)) & la_k_get_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_get_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_transpose_mr", sizeof(la_i_transpose_mr_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_transpose_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_transpose_mr", sizeof(la_k_transpose_mr_t), 0, 3, "i", "k", - (int (*)(CSOUND *, void *)) & la_k_transpose_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_transpose_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_transpose_mc", sizeof(la_i_transpose_mc_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_transpose_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_transpose_mc", sizeof(la_k_transpose_mc_t), 0, 2, "i", "i", - (int (*)(CSOUND *, void *)) & la_k_transpose_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_transpose_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_conjugate_vr", sizeof(la_i_conjugate_vr_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_conjugate_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_conjugate_vr", sizeof(la_k_conjugate_vr_t), 0, 3, "i", "i", - (int (*)(CSOUND *, void *)) & la_k_conjugate_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_conjugate_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_conjugate_vc", sizeof(la_i_conjugate_vc_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_conjugate_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_conjugate_vc", sizeof(la_k_conjugate_vc_t), 0, 3, "i", "i", - (int (*)(CSOUND *, void *)) & la_k_conjugate_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_conjugate_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_conjugate_mr", sizeof(la_i_conjugate_mr_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_conjugate_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_conjugate_mr", sizeof(la_k_conjugate_mr_t), 0, 3, "i", "i", - (int (*)(CSOUND *, void *)) & la_k_conjugate_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_conjugate_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_conjugate_mc", sizeof(la_i_conjugate_mc_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_conjugate_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_conjugate_mc", sizeof(la_k_conjugate_mc_t), 0, 3, "i", "i", - (int (*)(CSOUND *, void *)) & la_k_conjugate_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_conjugate_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm1_vr", sizeof(la_i_norm1_vr_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_norm1_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm1_vr", sizeof(la_k_norm1_vr_t), 0, 3, "k", "i", - (int (*)(CSOUND *, void *)) & la_k_norm1_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm1_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm1_vc", sizeof(la_i_norm1_vc_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_norm1_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm1_vc", sizeof(la_k_norm1_vc_t), 0, 3, "k", "i", - (int (*)(CSOUND *, void *)) & la_k_norm1_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm1_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm1_mr", sizeof(la_i_norm1_mr_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_norm1_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm1_mr", sizeof(la_k_norm1_mr_t), 0, 3, "k", "i", - (int (*)(CSOUND *, void *)) & la_k_norm1_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm1_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm1_mc", sizeof(la_i_norm1_mc_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_norm1_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm1_mc", sizeof(la_k_norm1_mc_t), 0, 3, "k", "i", - (int (*)(CSOUND *, void *)) & la_k_norm1_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm1_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm_euclid_vr", sizeof(la_i_norm_euclid_vr_t), 0, 1, "i", - "i", (int (*)(CSOUND *, void *)) & la_i_norm_euclid_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm_euclid_vr", sizeof(la_k_norm_euclid_vr_t), 0, 3, "k", - "i", (int (*)(CSOUND *, void *)) & la_k_norm_euclid_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm_euclid_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm_euclid_vc", sizeof(la_i_norm_euclid_vc_t), 0, 1, "i", - "i", (int (*)(CSOUND *, void *)) & la_i_norm_euclid_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm_euclid_vc", sizeof(la_k_norm_euclid_vc_t), 0, 3, "k", - "i", (int (*)(CSOUND *, void *)) & la_k_norm_euclid_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm_euclid_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm_euclid_mr", sizeof(la_i_norm_euclid_mr_t), 0, 1, "i", - "i", (int (*)(CSOUND *, void *)) & la_i_norm_euclid_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm_euclid_mr", sizeof(la_k_norm_euclid_mr_t), 0, 3, "k", - "i", (int (*)(CSOUND *, void *)) & la_k_norm_euclid_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm_euclid_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm_euclid_mc", sizeof(la_i_norm_euclid_mc_t), 0, 1, "i", - "i", (int (*)(CSOUND *, void *)) & la_i_norm_euclid_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm_euclid_mc", sizeof(la_k_norm_euclid_mc_t), 0, 3, "k", - "i", (int (*)(CSOUND *, void *)) & la_k_norm_euclid_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm_euclid_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_distance_vr", sizeof(la_i_distance_vr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_distance_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_distance_vr", sizeof(la_k_distance_vr_t), 0, 3, "k", "ii", - (int (*)(CSOUND *, void *)) & la_k_distance_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_distance_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_distance_vc", sizeof(la_i_distance_vc_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_distance_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_distance_vc", sizeof(la_k_distance_vc_t), 0, 3, "k", "ii", - (int (*)(CSOUND *, void *)) & la_k_distance_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_distance_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm_max_mr", sizeof(la_i_norm_max_mr_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_norm_max_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm_max_mr", sizeof(la_k_norm_max_mr_t), 0, 3, "k", "i", - (int (*)(CSOUND *, void *)) & la_k_norm_max_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm_max_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm_max_mc", sizeof(la_i_norm_max_mc_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_norm_max_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm_max_mc", sizeof(la_k_norm_max_mc_t), 0, 3, "k", "i", - (int (*)(CSOUND *, void *)) & la_k_norm_max_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm_max_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm_inf_vr", sizeof(la_i_norm_inf_vr_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_norm_inf_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm_inf_vr", sizeof(la_k_norm_inf_vr_t), 0, 3, "k", "i", - (int (*)(CSOUND *, void *)) & la_k_norm_inf_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm_inf_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm_inf_vc", sizeof(la_i_norm_inf_vc_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_norm_inf_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm_inf_vc", sizeof(la_k_norm_inf_vc_t), 0, 3, "k", "i", - (int (*)(CSOUND *, void *)) & la_k_norm_inf_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm_inf_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm_inf_mr", sizeof(la_i_norm_inf_mr_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_norm_inf_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm_inf_mr", sizeof(la_k_norm_inf_mr_t), 0, 3, "k", "i", - (int (*)(CSOUND *, void *)) & la_k_norm_inf_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm_inf_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_norm_inf_mc", sizeof(la_i_norm_inf_mc_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_norm_inf_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_norm_inf_mc", sizeof(la_k_norm_inf_mc_t), 0, 3, "k", "i", - (int (*)(CSOUND *, void *)) & la_k_norm_inf_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_norm_inf_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_trace_mr", sizeof(la_i_trace_mr_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_trace_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_trace_mr", sizeof(la_k_trace_mr_t), 0, 3, "k", "i", - (int (*)(CSOUND *, void *)) & la_k_trace_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_trace_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_trace_mc", sizeof(la_i_trace_mc_t), 0, 1, "ii", "i", - (int (*)(CSOUND *, void *)) & la_i_trace_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_trace_mc", sizeof(la_k_trace_mc_t), 0, 3, "kk", "i", - (int (*)(CSOUND *, void *)) & la_k_trace_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_trace_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_lu_det_mr", sizeof(la_i_lu_det_mr_t), 0, 1, "i", "i", - (int (*)(CSOUND *, void *)) & la_i_lu_det_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_lu_det_mr", sizeof(la_k_lu_det_mr_t), 0, 3, "k", "i", - (int (*)(CSOUND *, void *)) & la_k_lu_det_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_lu_det_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_lu_det_mc", sizeof(la_i_lu_det_mc_t), 0, 1, "ii", "i", - (int (*)(CSOUND *, void *)) & la_i_lu_det_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_lu_det_mc", sizeof(la_k_lu_det_mc_t), 0, 3, "kk", "i", - (int (*)(CSOUND *, void *)) & la_k_lu_det_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_lu_det_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_add_vr", sizeof(la_i_add_vr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_add_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_add_vr", sizeof(la_k_add_vr_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_add_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_add_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_add_vc", sizeof(la_i_add_vc_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_add_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_add_vc", sizeof(la_k_add_vc_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_add_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_add_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_add_mr", sizeof(la_i_add_mr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_add_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_add_mr", sizeof(la_k_add_mr_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_add_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_add_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_add_mc", sizeof(la_i_add_mc_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_add_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_add_mc", sizeof(la_k_add_mc_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_add_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_add_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_subtract_vr", sizeof(la_i_subtract_vr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_subtract_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_subtract_vr", sizeof(la_k_subtract_vr_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_subtract_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_subtract_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_subtract_vc", sizeof(la_i_subtract_vc_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_subtract_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_subtract_vc", sizeof(la_k_subtract_vc_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_subtract_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_subtract_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_subtract_mr", sizeof(la_i_subtract_mr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_subtract_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_subtract_mr", sizeof(la_k_subtract_mr_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_subtract_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_subtract_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_subtract_mc", sizeof(la_i_subtract_mc_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_subtract_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_subtract_mc", sizeof(la_k_subtract_mc_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_subtract_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_subtract_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_multiply_vr", sizeof(la_i_multiply_vr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_multiply_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_multiply_vr", sizeof(la_k_multiply_vr_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_multiply_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_multiply_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_multiply_vc", sizeof(la_i_multiply_vc_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_multiply_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_multiply_vc", sizeof(la_k_multiply_vc_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_multiply_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_multiply_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_multiply_mr", sizeof(la_i_multiply_mr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_multiply_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_multiply_mr", sizeof(la_k_multiply_mr_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_multiply_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_multiply_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_multiply_mc", sizeof(la_i_multiply_mc_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_multiply_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_multiply_mc", sizeof(la_k_multiply_mc_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_multiply_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_multiply_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - - status |= csound->AppendOpcode( - csound, "la_i_divide_vr", sizeof(la_i_divide_vr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_divide_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_divide_vr", sizeof(la_k_divide_vr_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_divide_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_divide_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_divide_vc", sizeof(la_i_divide_vc_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_divide_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_divide_vc", sizeof(la_k_divide_vc_t), 0, 3, "i", "kk", - (int (*)(CSOUND *, void *)) & la_k_divide_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_divide_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_divide_mr", sizeof(la_i_divide_mr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_divide_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_divide_mr", sizeof(la_k_divide_mr_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_divide_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_divide_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_divide_mc", sizeof(la_i_divide_mc_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_divide_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_divide_mc", sizeof(la_k_divide_mc_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_divide_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_divide_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_dot_vr", sizeof(la_i_dot_vr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_dot_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_dot_vr", sizeof(la_k_dot_vr_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_dot_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_dot_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_dot_vc", sizeof(la_i_dot_vc_t), 0, 1, "ii", "ii", - (int (*)(CSOUND *, void *)) & la_i_dot_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_dot_vc", sizeof(la_k_dot_vc_t), 0, 3, "ii", "ii", - (int (*)(CSOUND *, void *)) & la_k_dot_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_dot_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_dot_mr", sizeof(la_i_dot_mr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_dot_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_dot_mr", sizeof(la_k_dot_mr_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_dot_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_dot_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_dot_mc", sizeof(la_i_dot_mc_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_dot_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_dot_mc", sizeof(la_k_dot_mc_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_dot_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_dot_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_dot_mr_vr", sizeof(la_i_dot_mr_vr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_dot_mr_vr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_dot_mr_vr", sizeof(la_k_dot_mr_vr_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_dot_mr_vr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_dot_mr_vr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_dot_mc_vc", sizeof(la_i_dot_mc_vc_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_dot_mc_vc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_dot_mc_vc", sizeof(la_k_dot_mc_vc_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_dot_mc_vc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_dot_mc_vc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_invert_mr", sizeof(la_i_invert_mr_t), 0, 1, "ii", "i", - (int (*)(CSOUND *, void *)) & la_i_invert_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_invert_mr", sizeof(la_k_invert_mr_t), 0, 3, "ik", "i", - (int (*)(CSOUND *, void *)) & la_k_invert_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_invert_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_invert_mc", sizeof(la_i_invert_mc_t), 0, 1, "iii", "i", - (int (*)(CSOUND *, void *)) & la_i_invert_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_invert_mc", sizeof(la_k_invert_mc_t), 0, 3, "ikk", "i", - (int (*)(CSOUND *, void *)) & la_k_invert_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_invert_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_upper_solve_mr", sizeof(la_i_upper_solve_mr_t), 0, 1, "i", - "io", (int (*)(CSOUND *, void *)) & la_i_upper_solve_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_upper_solve_mr", sizeof(la_k_upper_solve_mr_t), 0, 3, "i", - "iO", (int (*)(CSOUND *, void *)) & la_k_upper_solve_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_upper_solve_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_upper_solve_mc", sizeof(la_i_upper_solve_mc_t), 0, 1, "i", - "io", (int (*)(CSOUND *, void *)) & la_i_upper_solve_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_upper_solve_mc", sizeof(la_k_upper_solve_mc_t), 0, 3, "i", - "iO", (int (*)(CSOUND *, void *)) & la_k_upper_solve_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_upper_solve_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_lower_solve_mr", sizeof(la_i_lower_solve_mr_t), 0, 1, "i", - "io", (int (*)(CSOUND *, void *)) & la_i_lower_solve_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_lower_solve_mr", sizeof(la_k_lower_solve_mr_t), 0, 3, "i", - "iO", (int (*)(CSOUND *, void *)) & la_k_lower_solve_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_lower_solve_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_lower_solve_mc", sizeof(la_i_lower_solve_mc_t), 0, 1, "i", - "io", (int (*)(CSOUND *, void *)) & la_i_lower_solve_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_lower_solve_mc", sizeof(la_k_lower_solve_mc_t), 0, 3, "i", - "iO", (int (*)(CSOUND *, void *)) & la_k_lower_solve_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_lower_solve_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_lu_factor_mr", sizeof(la_i_lu_factor_mr_t), 0, 1, "iii", - "i", (int (*)(CSOUND *, void *)) & la_i_lu_factor_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_lu_factor_mr", sizeof(la_k_lu_factor_mr_t), 0, 3, "iik", - "i", (int (*)(CSOUND *, void *)) & la_k_lu_factor_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_lu_factor_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_lu_factor_mc", sizeof(la_i_lu_factor_mc_t), 0, 1, "iii", - "i", (int (*)(CSOUND *, void *)) & la_i_lu_factor_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_lu_factor_mc", sizeof(la_k_lu_factor_mc_t), 0, 3, "i", "i", - (int (*)(CSOUND *, void *)) & la_k_lu_factor_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_lu_factor_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_lu_solve_mr", sizeof(la_i_lu_solve_mr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_lu_solve_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_lu_solve_mr", sizeof(la_k_lu_solve_mr_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_lu_solve_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_lu_solve_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_lu_solve_mc", sizeof(la_i_lu_solve_mc_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_lu_solve_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_lu_solve_mc", sizeof(la_k_lu_solve_mc_t), 0, 3, "i", "ii", - (int (*)(CSOUND *, void *)) & la_k_lu_solve_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_lu_solve_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_qr_factor_mr", sizeof(la_i_qr_factor_mr_t), 0, 1, "ii", "i", - (int (*)(CSOUND *, void *)) & la_i_qr_factor_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_qr_factor_mr", sizeof(la_k_qr_factor_mr_t), 0, 3, "ii", "i", - (int (*)(CSOUND *, void *)) & la_k_qr_factor_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_qr_factor_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_qr_factor_mc", sizeof(la_i_qr_factor_mc_t), 0, 1, "ii", "i", - (int (*)(CSOUND *, void *)) & la_i_qr_factor_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_qr_factor_mc", sizeof(la_k_qr_factor_mc_t), 0, 3, "ii", "i", - (int (*)(CSOUND *, void *)) & la_k_qr_factor_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_qr_factor_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_qr_eigen_mr", sizeof(la_i_qr_eigen_mr_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_qr_eigen_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_qr_eigen_mr", sizeof(la_k_qr_eigen_mr_t), 0, 3, "i", "ik", - (int (*)(CSOUND *, void *)) & la_k_qr_eigen_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_qr_eigen_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_qr_eigen_mc", sizeof(la_i_qr_eigen_mc_t), 0, 1, "i", "ii", - (int (*)(CSOUND *, void *)) & la_i_qr_eigen_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_qr_eigen_mc", sizeof(la_k_qr_eigen_mc_t), 0, 3, "i", "ik", - (int (*)(CSOUND *, void *)) & la_k_qr_eigen_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_qr_eigen_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_qr_sym_eigen_mr", sizeof(la_i_qr_sym_eigen_mr_t), 0, 1, - "ii", "ii", (int (*)(CSOUND *, void *)) & la_i_qr_sym_eigen_mr_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_qr_sym_eigen_mr", sizeof(la_k_qr_sym_eigen_mr_t), 0, 3, - "ii", "ik", (int (*)(CSOUND *, void *)) & la_k_qr_sym_eigen_mr_t::init_, - (int (*)(CSOUND *, void *)) & la_k_qr_sym_eigen_mr_t::kontrol_, - (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_i_qr_sym_eigen_mc", sizeof(la_i_qr_sym_eigen_mc_t), 0, 1, - "ii", "ii", (int (*)(CSOUND *, void *)) & la_i_qr_sym_eigen_mc_t::init_, - (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0); - status |= csound->AppendOpcode( - csound, "la_k_qr_sym_eigen_mc", sizeof(la_k_qr_sym_eigen_mc_t), 0, 3, - "ii", "ik", (int (*)(CSOUND *, void *)) & la_k_qr_sym_eigen_mc_t::init_, - (int (*)(CSOUND *, void *)) & la_k_qr_sym_eigen_mc_t::kontrol_, - (int (*)(CSOUND *, void *))0); - return status; -} - -PUBLIC int csoundModuleDestroy(CSOUND *csound) { return 0; } -} diff --git a/6.x/src/mp3/CMakeLists.txt b/6.x/src/mp3/CMakeLists.txt deleted file mode 100644 index 64f5b074..00000000 --- a/6.x/src/mp3/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -option(BUILD_MP3OUT_OPCODE "Build the mp3out opcode" ON) - -if(USE_VCPKG) - find_package(mp3lame CONFIG REQUIRED) -else() - find_package(LAME) -endif() - -if(BUILD_MP3OUT_OPCODE) - if(LAME_FOUND) - make_plugin(mp3out mp3out.c ${LAME_LIBRARY}) - target_include_directories(mp3out PRIVATE ${LAME_INCLUDE_DIR} ${CSOUND_INCLUDE_DIR}) - elseif(mp3lame_FOUND AND USE_VCPKG) - make_plugin(mp3out mp3out.c mp3lame::mp3lame) - target_include_directories(mp3out PRIVATE ${CSOUND_INCLUDE_DIR}) - endif() - - message(STATUS "Building MP3 opcodes") -endif() diff --git a/6.x/src/mp3/mp3out.c b/6.x/src/mp3/mp3out.c deleted file mode 100644 index f11e4f67..00000000 --- a/6.x/src/mp3/mp3out.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - mp3out.c: - - Copyright (C) 2019 by John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include "csdl.h" -#include - -typedef struct _mp3out { - OPDS h; - MYFLT *al; - MYFLT *ar; - STRINGDAT *filename; - MYFLT *bitrate; - MYFLT *quality; - MYFLT *mode; - lame_global_flags *gfp; - FILE *fout; - AUXCH auxch; - void *mp3buffer; - int mp3buffer_size; - MYFLT *leftpcm; - MYFLT *rightpcm; -} MP3OUT; - -#define DEFAULT_RATE (256) - -#ifdef USE_DOUBLE -#define lame_encode_buffer_ieee_MYFLT lame_encode_buffer_ieee_double -#else -#define lame_encode_buffer_ieee_MYFLT lame_encode_buffer_ieee_float -#endif - -int mp3out_cleanup(CSOUND *csound, MP3OUT *p) -{ - IGN(csound); - int bytes = lame_encode_flush(p->gfp,p->mp3buffer, p->mp3buffer_size); - if (bytes>0) fwrite(p->mp3buffer, 1, bytes, p->fout); - lame_mp3_tags_fid(p->gfp, p->fout); - lame_close(p->gfp); - - p->gfp = NULL; - fclose(p->fout); - return OK; -} - - -int mp3out_init(CSOUND *csound, MP3OUT* p) -{ - int ret_code; - int bitrate, quality, mode; - unsigned int nsmps = csound->GetKsmps(csound); - lame_global_flags *gfp; - gfp = lame_init(); - p->gfp = gfp; - - bitrate = (*p->bitrate<0) ? DEFAULT_RATE : (int)MYFLT2LRND(*p->bitrate); - quality = (*p->quality<0) ? 2 : (int)MYFLT2LRND(*p->quality); - if (quality>9) quality = 9; - mode = MYFLT2LRND(*p->mode); - if (mode>3||mode<0) mode = 1; - lame_set_num_channels(gfp,2); - lame_set_in_samplerate(gfp,csound->GetSr(csound)); - lame_set_brate(gfp,bitrate); - lame_set_mode(gfp,mode); - lame_set_quality(gfp,quality); /* 2=high 5 = medium 7=low */ - - if (UNLIKELY(ret_code = lame_init_params(gfp)) < 0) { - return csound->InitError(csound, - Str("Failed to initialise LAME %d\n"), ret_code); - } - - p->fout = fopen(p->filename->data, "w+b"); - if (p->fout == NULL) { - return csound->InitError(csound, Str("mp3out %s: failed to open file"), p->filename->data); - } - - csound->AuxAlloc(csound, - 2*nsmps*sizeof(MYFLT)+(p->mp3buffer_size=3*nsmps/2+7200), - &p->auxch); - - p->mp3buffer = p->auxch.auxp; - p->leftpcm = (char*)p->auxch.auxp + p->mp3buffer_size; - p->rightpcm = p->leftpcm + nsmps; - - csound->RegisterDeinitCallback(csound, p, - (int32_t (*)(CSOUND*, void*)) mp3out_cleanup); - return OK; -} - -int mp3out_perf(CSOUND *csound, MP3OUT *p) -{ - int bytes; - unsigned int i, nsmps = csound->GetKsmps(csound); - MYFLT zdbfs = csound->Get0dBFS(csound); - - for (i = 0; ileftpcm[i] = p->al[i]/zdbfs; - p->rightpcm[i] = p->ar[i]/zdbfs; - } - - bytes = lame_encode_buffer_ieee_MYFLT(p->gfp, - p->leftpcm, p->rightpcm, - nsmps, p->mp3buffer, p->mp3buffer_size); - - if (bytes >= 0) { - fwrite(p->mp3buffer, 1, bytes, p->fout); - } - else if (bytes < 0) { - return csound->PerfError(csound, &(p->h), - Str("mp3out: write error %d\n"), bytes); - } - - return OK; -} - -#define S(x) sizeof(x) - -static OENTRY localops[] = { - { "mp3out", S(MP3OUT), 0, 3, "", "aaSjjp", (SUBR)mp3out_init, (SUBR)mp3out_perf} -}; - -LINKAGE diff --git a/6.x/src/opencl/CMakeLists.txt b/6.x/src/opencl/CMakeLists.txt deleted file mode 100644 index 16c73b54..00000000 --- a/6.x/src/opencl/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -option(BUILD_OPENCL_OPCODES "Build the OpenCL parallel opcodes" OFF) - -find_library (OpenCL_library NAMES OpenCL) -check_deps(BUILD_OPENCL_OPCODES OpenCL_FOUND) - -if(BUILD_OPENCL_OPCODES AND OpenCL_FOUND) - - function(make_opencl_plugin libname srcs) - if(APPLE) - add_library(${libname} SHARED ${srcs}) - else() - add_library(${libname} MODULE ${srcs}) - endif() - - set(i 2) - while( ${i} LESS ${ARGC} ) - target_link_libraries(${libname} ${ARGV${i}}) - math(EXPR i "${i}+1") - endwhile() - - target_include_directories(${libname} PRIVATE ${CSOUND_INCLUDE_DIRS}) - - install(TARGETS ${libname} - LIBRARY DESTINATION "${PLUGIN_INSTALL_DIR}" ) - endfunction() - - make_opencl_plugin(clop cladsynth.c) - target_link_libraries(clop ${OpenCL_library}) -endif() diff --git a/6.x/src/opencl/build.sh b/6.x/src/opencl/build.sh deleted file mode 100644 index eeb790ec..00000000 --- a/6.x/src/opencl/build.sh +++ /dev/null @@ -1 +0,0 @@ -cc -O3 -dynamiclib -o libclop1.dylib -DUSE_DOUBLE -D_FORTIFY_SOURCE=0 cladsynth.c -I../../include -framework OpenCL -Wno-deprecated-declarations diff --git a/6.x/src/opencl/buildc.sh b/6.x/src/opencl/buildc.sh deleted file mode 100644 index 2bc48d4c..00000000 --- a/6.x/src/opencl/buildc.sh +++ /dev/null @@ -1,2 +0,0 @@ -set -x -c++ -g -O3 -dynamiclib -o libclconv.dylib -std=c++11 -DUSE_DOUBLE -D_FORTIFY_SOURCE=0 clconv.cpp -I../../include -framework OpenCL -Wno-deprecated-declarations diff --git a/6.x/src/opencl/buildcpp.sh b/6.x/src/opencl/buildcpp.sh deleted file mode 100644 index df292a38..00000000 --- a/6.x/src/opencl/buildcpp.sh +++ /dev/null @@ -1,2 +0,0 @@ -set -x -c++ -O3 -dynamiclib -o libclopp.dylib -DUSE_DOUBLE -D_FORTIFY_SOURCE=0 cladsynth2.cpp -I../../include -framework OpenCL -Wno-deprecated-declarations -std=c++11 diff --git a/6.x/src/opencl/cladsyn.csd b/6.x/src/opencl/cladsyn.csd deleted file mode 100644 index f23aba99..00000000 --- a/6.x/src/opencl/cladsyn.csd +++ /dev/null @@ -1,45 +0,0 @@ - - ---opcode-lib=./libclop1.dylib - - - -ksmps = 1 -0dbfs = 1 - - -instr 1 -ifftsize = 2048 -ihopsize = 512 -ibins = 1024 -idev = 1; /* device number */ -asig1 vco2 0.5, 300 -fsig = pvsanal(asig1, ifftsize,ihopsize, ifftsize, 1) -asig = cladsyn(fsig,1,1,ibins,idev) -asig = linenr(asig,0.001,0.01,0.01) - out(asig*0.5) - -endin - -instr 2 -ifftsize = 2048 -ihopsize = 512 -ibins = 1024 -asig1 vco2 0.5, 440 -fsig = pvsanal(asig1, ifftsize,ihopsize, ifftsize, 1) -asig = pvsadsyn(fsig,ibins,1) -asig = linenr(asig,0.001,0.01,0.01) - out(asig*0.5) - -endin - - - - - - - -i1 0 60 - - - diff --git a/6.x/src/opencl/cladsynth.c b/6.x/src/opencl/cladsynth.c deleted file mode 100644 index ab76728d..00000000 --- a/6.x/src/opencl/cladsynth.c +++ /dev/null @@ -1,393 +0,0 @@ -/* - cladsynth.c - - (c) Victor Lazzarini, 2014 - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ -#include -#include - -#ifdef __MACH__ -#include -#else -#include -#endif - - -const char *code = - "#define FMAXLEN ((float)0x40000000) \n" - "#define PHMASK 0x3fffffff \n" - "#define PI 3.1415926f\n" - "inline void AtomicAdd(volatile __global float *source, const float operand) {\n" - " union {\n" - " unsigned int intVal;\n" - " float floatVal;\n" - " } newVal;\n" - " union {\n" - " unsigned int intVal;\n" - " float floatVal;\n" - " } prevVal;\n" - " do {\n" - " prevVal.floatVal = *source;\n" - " newVal.floatVal = prevVal.floatVal + operand;\n" - " } while (atomic_cmpxchg((volatile __global unsigned int *)source, \n" - " prevVal.intVal, newVal.intVal) != prevVal.intVal);\n" - "}\n" - "kernel void sample(global float *out, global float *frame, \n" - " global long *ph,\n" - " global float *amps, float pitch, int bins, \n" - " int vsize, float sr) {\n" - " int t = get_global_id(0);\n" - " int n = t%vsize; /* sample index */\n" - " int h = t/vsize; /* bin index */\n" - " int k = h<<1;\n" - " long lph;\n" - " float a = amps[h], ascl = ((float)n)/vsize;\n" - " float fscal = pitch*FMAXLEN/sr;\n" - " lph = (ph[h] + (long)(n*round(frame[k+1]*fscal))) & PHMASK;\n" - " a += ascl*(frame[k] - a);\n" - " AtomicAdd(&out[n], a*sin((2*PI*lph)/FMAXLEN));\n" - "}\n" - "kernel void update(global float *out, global float *frame,\n" - " global long *ph, global float *amps, float pitch, int bins, \n" - " int vsize, float sr){\n" - " int h = get_global_id(0);\n" - " int k = h << 1,i,j;\n" - " /* update phases and amps */\n" - " ph[h] = (ph[h] + (long)(vsize*round(pitch*frame[k+1]*FMAXLEN/sr))) & PHMASK;\n" - " amps[h] = frame[k];\n" - " if(h >= vsize) return;\n" - " out[h] = 0.f;\n" - "}\n" - " \n"; - -typedef struct cladsyn_ { - OPDS h; - MYFLT *asig; - PVSDAT *fsig; - MYFLT *kamp, *kfreq; - MYFLT *inum, *idev; - cl_mem out; - cl_mem frame; - cl_mem ph; - float *fp; - cl_mem amps; - AUXCH out_; - int bins; - size_t threads; - int count; - int vsamps; - size_t mthreads; - int framecount; - cl_context context; - cl_command_queue commands; - cl_program program; - cl_kernel kernel1, kernel2; - size_t wgs1, wgs2; - float sr; -} CLADSYN; - -char * cl_error_string(int err) { - switch (err) { - case CL_SUCCESS: return "Success!"; - case CL_DEVICE_NOT_FOUND: return "Device not found."; - case CL_DEVICE_NOT_AVAILABLE: return "Device not available"; - case CL_COMPILER_NOT_AVAILABLE: return "Compiler not available"; - case CL_MEM_OBJECT_ALLOCATION_FAILURE: - return "Memory object allocation failure"; - case CL_OUT_OF_RESOURCES: return "Out of resources"; - case CL_OUT_OF_HOST_MEMORY: return "Out of host memory"; - case CL_PROFILING_INFO_NOT_AVAILABLE: - return "Profiling information not available"; - case CL_MEM_COPY_OVERLAP: return "Memory copy overlap"; - case CL_IMAGE_FORMAT_MISMATCH: return "Image format mismatch"; - case CL_IMAGE_FORMAT_NOT_SUPPORTED: return "Image format not supported"; - case CL_BUILD_PROGRAM_FAILURE: return "Program build failure"; - case CL_MAP_FAILURE: return "Map failure"; - case CL_INVALID_VALUE: return "Invalid value"; - case CL_INVALID_DEVICE_TYPE: return "Invalid device type"; - case CL_INVALID_PLATFORM: return "Invalid platform"; - case CL_INVALID_DEVICE: return "Invalid device"; - case CL_INVALID_CONTEXT: return "Invalid context"; - case CL_INVALID_QUEUE_PROPERTIES: return "Invalid queue properties"; - case CL_INVALID_COMMAND_QUEUE: return "Invalid command queue"; - case CL_INVALID_HOST_PTR: return "Invalid host pointer"; - case CL_INVALID_MEM_OBJECT: return "Invalid memory object"; - case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: - return "Invalid image format descriptor"; - case CL_INVALID_IMAGE_SIZE: return "Invalid image size"; - case CL_INVALID_SAMPLER: return "Invalid sampler"; - case CL_INVALID_BINARY: return "Invalid binary"; - case CL_INVALID_BUILD_OPTIONS: return "Invalid build options"; - case CL_INVALID_PROGRAM: return "Invalid program"; - case CL_INVALID_PROGRAM_EXECUTABLE: return "Invalid program executable"; - case CL_INVALID_KERNEL_NAME: return "Invalid kernel name"; - case CL_INVALID_KERNEL_DEFINITION: return "Invalid kernel definition"; - case CL_INVALID_KERNEL: return "Invalid kernel"; - case CL_INVALID_ARG_INDEX: return "Invalid argument index"; - case CL_INVALID_ARG_VALUE: return "Invalid argument value"; - case CL_INVALID_ARG_SIZE: return "Invalid argument size"; - case CL_INVALID_KERNEL_ARGS: return "Invalid kernel arguments"; - case CL_INVALID_WORK_DIMENSION: return "Invalid work dimension"; - case CL_INVALID_WORK_GROUP_SIZE: return "Invalid work group size"; - case CL_INVALID_WORK_ITEM_SIZE: return "Invalid work item size"; - case CL_INVALID_GLOBAL_OFFSET: return "Invalid global offset"; - case CL_INVALID_EVENT_WAIT_LIST: return "Invalid event wait list"; - case CL_INVALID_EVENT: return "Invalid event"; - case CL_INVALID_OPERATION: return "Invalid operation"; - case CL_INVALID_GL_OBJECT: return "Invalid OpenGL object"; - case CL_INVALID_BUFFER_SIZE: return "Invalid buffer size"; - case CL_INVALID_MIP_LEVEL: return "Invalid mip-map level"; - default: return "Unknown error"; - } -} - -static int destroy_cladsyn(CSOUND *csound, void *pp); - -static int init_cladsyn(CSOUND *csound, CLADSYN *p){ - - int asize, ipsize, fpsize, err; - cl_device_id device_ids[32], device_id; - cl_context context; - cl_command_queue commands; - cl_program program; - cl_kernel kernel1, kernel2; - cl_uint num = 0, nump = 0; - cl_platform_id platforms[16]; - uint32_t i; - - if(p->fsig->overlap > 1024) - return csound->InitError(csound, "overlap is too large\n"); - - - - err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 32, device_ids, &num); - if (err != CL_SUCCESS){ - clGetPlatformIDs(16, platforms, &nump); - int devs = 0; - for(i=0; i < nump && devs < 32; i++){ - char name[128]; - clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 128, name, NULL); - csound->Message(csound, "available platform[%d] %s\n",i, name); - err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, - 32-devs, &device_ids[devs], &num); - if (err != CL_SUCCESS) - csound->InitError(csound, "failed to find an OpenCL device! %s \n", - cl_error_string(err)); - } - devs += num; - } - - - for(i=0; i < num; i++){ - char name[128]; - cl_device_type type; - clGetDeviceInfo(device_ids[i], CL_DEVICE_NAME, 128, name, NULL); - clGetDeviceInfo(device_ids[i], CL_DEVICE_TYPE, sizeof(cl_device_type), - &type, NULL); - if(type & CL_DEVICE_TYPE_CPU) - csound->Message(csound, "available CPU[device %d] %s\n",i, name); - else if(type & CL_DEVICE_TYPE_GPU) - csound->Message(csound, "available GPU[device %d] %s\n",i, name); - else if(type & CL_DEVICE_TYPE_ACCELERATOR) - csound->Message(csound, "available ACCELLERATOR[device %d] %s\n",i, name); - else - csound->Message(csound, "available generic [device %d] %s\n",i, name);; - } - - // SELECT THE GPU HERE - if(*p->idev < num) - device_id = device_ids[(int)*p->idev]; - else - device_id = device_ids[num-1]; - - context = clCreateContext(0, 1, &device_id, NULL, NULL, &err); - if (!context) - return csound->InitError(csound, "Failed to create a compute context! %s\n", - cl_error_string(err)); - - // Create a command commands - // - commands = clCreateCommandQueue(context, device_id, 0, &err); - if (!commands) - return csound->InitError(csound, "Failed to create a command commands! %s\n", - cl_error_string(err)); - // Create the compute program from the source buffer - // - program = clCreateProgramWithSource(context, 1, (const char **) &code, - NULL, &err); - if (!program) - return csound->InitError(csound, "Failed to create compute program! %s\n", - cl_error_string(err)); - - err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL); - if (err != CL_SUCCESS) - { - size_t len; - char buffer[2048]; - csound->Message(csound, "Failed to build program executable! %s\n", - cl_error_string(err)); - clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, - sizeof(buffer), buffer, &len); - return csound->InitError(csound, "%s\n", buffer); - } - - kernel1 = clCreateKernel(program, "sample", &err); - if (!kernel1 || err != CL_SUCCESS) - return csound->InitError(csound, - "Failed to create sample compute kernel! %s\n", - cl_error_string(err)); - - kernel2 = clCreateKernel(program, "update", &err); - if (!kernel2 || err != CL_SUCCESS) - return csound->InitError(csound, - "Failed to create update compute kernel! %s\n", - cl_error_string(err)); - - char name[128]; - clGetDeviceInfo(device_id, CL_DEVICE_NAME, 128, name, NULL); - csound->Message(csound, "using device: %s\n",name); - - p->bins = (p->fsig->N)/2; - - if(*p->inum > 0 && *p->inum < p->bins) p->bins = *p->inum; - - p->vsamps = p->fsig->overlap; - p->threads = p->bins*p->vsamps; - p->mthreads = (p->bins > p->vsamps ? p->bins : p->vsamps); - - asize = p->vsamps*sizeof(cl_float); - ipsize = p->mthreads*sizeof(cl_long); - fpsize = p->fsig->N*sizeof(cl_float); - - p->out = clCreateBuffer(context,0, asize, NULL, NULL); - p->frame = clCreateBuffer(context, CL_MEM_READ_ONLY, fpsize, NULL, NULL); - p->ph = clCreateBuffer(context,0, ipsize, NULL, NULL); - p->amps = clCreateBuffer(context,0,p->mthreads*sizeof(cl_float), NULL, NULL); - - // memset needed? - - asize = p->vsamps*sizeof(float); - if(p->out_.auxp == NULL || - p->out_.size < (unsigned long) asize) - csound->AuxAlloc(csound, asize , &p->out_); - - csound->RegisterDeinitCallback(csound, p, destroy_cladsyn); - p->count = 0; - p->context = context; - p->program = program; - p->commands = commands; - p->kernel1 = kernel1; - p->kernel2 = kernel2; - - clGetKernelWorkGroupInfo(p->kernel1, - device_id, CL_KERNEL_WORK_GROUP_SIZE, sizeof(p->wgs1), &p->wgs1, NULL); - clGetKernelWorkGroupInfo(p->kernel2, - device_id, CL_KERNEL_WORK_GROUP_SIZE, sizeof(p->wgs2), &p->wgs2, NULL); - - p->sr = csound->GetSr(csound); - clSetKernelArg(p->kernel1, 0, sizeof(cl_mem), &p->out); - clSetKernelArg(p->kernel1, 1, sizeof(cl_mem), &p->frame); - clSetKernelArg(p->kernel1, 2, sizeof(cl_mem), &p->ph); - clSetKernelArg(p->kernel1, 3, sizeof(cl_mem), &p->amps); - clSetKernelArg(p->kernel1, 5, sizeof(cl_int), &p->bins); - clSetKernelArg(p->kernel1, 6, sizeof(cl_int), &p->vsamps); - clSetKernelArg(p->kernel1, 7, sizeof(cl_float), &p->sr); - - clSetKernelArg(p->kernel2, 0, sizeof(cl_mem), &p->out); - clSetKernelArg(p->kernel2, 1, sizeof(cl_mem), &p->frame); - clSetKernelArg(p->kernel2, 2, sizeof(cl_mem), &p->ph); - clSetKernelArg(p->kernel2, 3, sizeof(cl_mem), &p->amps); - clSetKernelArg(p->kernel2, 5, sizeof(cl_int), &p->bins); - clSetKernelArg(p->kernel2, 6, sizeof(cl_int), &p->vsamps); - clSetKernelArg(p->kernel2, 7, sizeof(cl_float), &p->sr); - - return OK; -} - -static int perf_cladsyn(CSOUND *csound, CLADSYN *p){ - - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - float *out_ = (float *) p->out_.auxp; - MYFLT *asig = p->asig; - int count = p->count, vsamps = p->vsamps; - p->fp = (float *) (p->fsig->frame.auxp); - - if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); - } - - for(n=offset; n < nsmps; n++){ - if(count == 0) { - int err; - float freq = *p->kfreq; - clSetKernelArg(p->kernel1, 4, sizeof(cl_float), &freq); - clSetKernelArg(p->kernel2, 4, sizeof(cl_float), &freq); - - clEnqueueWriteBuffer(p->commands,p->frame, CL_TRUE, 0, - sizeof(cl_float)*p->bins*2, - p->fp, 0, NULL, NULL); - - err = clEnqueueNDRangeKernel(p->commands,p->kernel1, 1, NULL, &p->threads, - &p->wgs1, 0, NULL, NULL); - if(err) - csound->Message(csound,"Error: Failed to compute sample kernel! %s\n", - cl_error_string(err)); - clFinish(p->commands); - clEnqueueReadBuffer(p->commands,p->out, - CL_TRUE, 0,vsamps*sizeof(cl_float),out_, 0, NULL, NULL); - err = clEnqueueNDRangeKernel(p->commands,p->kernel2, 1, NULL, &p->mthreads, - &p->wgs2, 0, NULL, NULL); - if(err) - csound->Message(csound,"Error: Failed to compute update kernel!%s\n", - cl_error_string(err)); - count = vsamps; - } - asig[n] = (MYFLT) out_[vsamps - count]; - count--; - } - p->count = count; - return OK; -} - -static int destroy_cladsyn(CSOUND *csound, void *pp){ - CLADSYN *p = (CLADSYN *) pp; - clReleaseMemObject(p->out); - clReleaseMemObject(p->ph); - clReleaseMemObject(p->frame); - clReleaseMemObject(p->amps); - clReleaseProgram(p->program); - clReleaseKernel(p->kernel1); - clReleaseKernel(p->kernel2); - clReleaseCommandQueue(p->commands); - clReleaseContext(p->context); - - return OK; -} - -static OENTRY localops[] = { - {"cladsyn", sizeof(CLADSYN),0, 3, "a", "fkkoo", (SUBR) init_cladsyn, - (SUBR) perf_cladsyn} -}; - -LINKAGE diff --git a/6.x/src/opencl/cladsynth.cpp b/6.x/src/opencl/cladsynth.cpp deleted file mode 100644 index 8cc4c120..00000000 --- a/6.x/src/opencl/cladsynth.cpp +++ /dev/null @@ -1,404 +0,0 @@ -/* - cladsynth.cpp - - (c) Victor Lazzarini, 2019 - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include -#include -#include -#include - -#ifdef __MACH__ -#include -#else -#include -#endif - -const char *code = R"( -#define FMAXLEN ((float)0x40000000) -#define PHMASK 0x3fffffff -#define PI 3.1415926f - -inline void AtomicAdd(volatile __global float *source, const float operand) { - union { - unsigned int intVal; - float floatVal; - } newVal; - union { - unsigned int intVal; - float floatVal; - } prevVal; - do { - prevVal.floatVal = *source; - newVal.floatVal = prevVal.floatVal + operand; - } while (atomic_cmpxchg((volatile __global unsigned int *)source, - prevVal.intVal, newVal.intVal) != prevVal.intVal); -} - -kernel void sample(global float *out, global float *frame, - global long *ph, - global float *amps, float pitch, int bins, - int vsize, float sr) { - int t = get_global_id(0); - int n = t%vsize; /* sample index */ - int h = t/vsize; /* bin index */ - int k = h<<1; - long lph; - float a = amps[h], ascl = ((float)n)/vsize; - float fscal = pitch*FMAXLEN/sr; - lph = (ph[h] + (long)(n*round(frame[k+1]*fscal))) & PHMASK; - a += ascl*(frame[k] - a); - AtomicAdd(&out[n], a*sin((2*PI*lph)/FMAXLEN)); -} - -kernel void update(global float *out, global float *frame, - global long *ph, global float *amps, float pitch, int bins, - int vsize, float sr){ - int h = get_global_id(0); - int k = h << 1,i,j; - /* update phases and amps */ - ph[h] = (ph[h] + (long)(vsize*round(pitch*frame[k+1]*FMAXLEN/sr))) & PHMASK; - amps[h] = frame[k]; - if(h >= vsize) return; - out[h] = 0.f; -} - -)"; - - -const char * cl_error_string(int err) { - switch (err) { - case CL_SUCCESS: return "Success!"; - case CL_DEVICE_NOT_FOUND: return "Device not found."; - case CL_DEVICE_NOT_AVAILABLE: return "Device not available"; - case CL_COMPILER_NOT_AVAILABLE: return "Compiler not available"; - case CL_MEM_OBJECT_ALLOCATION_FAILURE: - return "Memory object allocation failure"; - case CL_OUT_OF_RESOURCES: return "Out of resources"; - case CL_OUT_OF_HOST_MEMORY: return "Out of host memory"; - case CL_PROFILING_INFO_NOT_AVAILABLE: - return "Profiling information not available"; - case CL_MEM_COPY_OVERLAP: return "Memory copy overlap"; - case CL_IMAGE_FORMAT_MISMATCH: return "Image format mismatch"; - case CL_IMAGE_FORMAT_NOT_SUPPORTED: return "Image format not supported"; - case CL_BUILD_PROGRAM_FAILURE: return "Program build failure"; - case CL_MAP_FAILURE: return "Map failure"; - case CL_INVALID_VALUE: return "Invalid value"; - case CL_INVALID_DEVICE_TYPE: return "Invalid device type"; - case CL_INVALID_PLATFORM: return "Invalid platform"; - case CL_INVALID_DEVICE: return "Invalid device"; - case CL_INVALID_CONTEXT: return "Invalid context"; - case CL_INVALID_QUEUE_PROPERTIES: return "Invalid queue properties"; - case CL_INVALID_COMMAND_QUEUE: return "Invalid command queue"; - case CL_INVALID_HOST_PTR: return "Invalid host pointer"; - case CL_INVALID_MEM_OBJECT: return "Invalid memory object"; - case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: - return "Invalid image format descriptor"; - case CL_INVALID_IMAGE_SIZE: return "Invalid image size"; - case CL_INVALID_SAMPLER: return "Invalid sampler"; - case CL_INVALID_BINARY: return "Invalid binary"; - case CL_INVALID_BUILD_OPTIONS: return "Invalid build options"; - case CL_INVALID_PROGRAM: return "Invalid program"; - case CL_INVALID_PROGRAM_EXECUTABLE: return "Invalid program executable"; - case CL_INVALID_KERNEL_NAME: return "Invalid kernel name"; - case CL_INVALID_KERNEL_DEFINITION: return "Invalid kernel definition"; - case CL_INVALID_KERNEL: return "Invalid kernel"; - case CL_INVALID_ARG_INDEX: return "Invalid argument index"; - case CL_INVALID_ARG_VALUE: return "Invalid argument value"; - case CL_INVALID_ARG_SIZE: return "Invalid argument size"; - case CL_INVALID_KERNEL_ARGS: return "Invalid kernel arguments"; - case CL_INVALID_WORK_DIMENSION: return "Invalid work dimension"; - case CL_INVALID_WORK_GROUP_SIZE: return "Invalid work group size"; - case CL_INVALID_WORK_ITEM_SIZE: return "Invalid work item size"; - case CL_INVALID_GLOBAL_OFFSET: return "Invalid global offset"; - case CL_INVALID_EVENT_WAIT_LIST: return "Invalid event wait list"; - case CL_INVALID_EVENT: return "Invalid event"; - case CL_INVALID_OPERATION: return "Invalid operation"; - case CL_INVALID_GL_OBJECT: return "Invalid OpenGL object"; - case CL_INVALID_BUFFER_SIZE: return "Invalid buffer size"; - case CL_INVALID_MIP_LEVEL: return "Invalid mip-map level"; - default: return "Unknown error"; - } -} - -struct Cladsyn : csnd::Plugin<1, 5> { - - cl_mem out; - cl_mem frame; - cl_mem ph; - cl_mem amps; - int bins; - size_t threads; - int count; - int vsamps; - size_t mthreads; - int framecount; - cl_context context; - cl_command_queue commands; - cl_program program; - cl_kernel kernel1, kernel2; - size_t wgs1, wgs2; - csnd::AuxMem mix; - float cs_sr; - - - int init() { - int asize, ipsize, fpsize, err; - cl_device_id device_ids[32], device_id; - cl_uint num = 0, nump = 0; - cl_platform_id platforms[16]; - uint32_t i; - csnd::pv_frame &fsig = inargs.fsig_data(0); - int inum = (int) inargs[3]; - int idev = (int) inargs[4]; - - if(fsig.hop_size() > 1024) - return csound->init_error("hopsize is too large\n"); - - err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 32, device_ids, &num); - if (err != CL_SUCCESS){ - int devs = 0; - clGetPlatformIDs(16, platforms, &nump); - for(i=0; i < nump && devs < 32; i++){ - char name[128]; - std::stringstream msg; - clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 128, name, NULL); - msg << "available platform[" << i << "]: " << name << std::endl; - csound->message(msg.str()); - err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, - 32-devs, &device_ids[devs], &num); - if (err != CL_SUCCESS) { - std::stringstream emsg; - emsg << "failed to find an OpenCL device!" << - cl_error_string(err) << std::endl; - csound->init_error(emsg.str()); - } - } - devs += num; - } - - for(i=0; i < num; i++){ - char name[128]; - cl_device_type type; - clGetDeviceInfo(device_ids[i], CL_DEVICE_NAME, 128, name, NULL); - clGetDeviceInfo(device_ids[i], CL_DEVICE_TYPE, sizeof(cl_device_type), - &type, NULL); - if(type & CL_DEVICE_TYPE_CPU) { - std::stringstream msg; - msg << "available CPU[device " << i << "] " << name << std::endl; - csound->message(msg.str()); - } - else if(type & CL_DEVICE_TYPE_GPU) { - std::stringstream msg; - msg << "available GPU[device " << i << "] " << name << std::endl; - csound->message(msg.str()); - } - else if(type & CL_DEVICE_TYPE_ACCELERATOR) { - std::stringstream msg; - msg << "available ACCELLERATOR[device " << i << "] " << name - << std::endl; - csound->message(msg.str()); - } - else { - std::stringstream msg; - msg << "available GENERIC[device " << i << "] " << name << std::endl; - csound->message(msg.str()); - } - } - - // SELECT THE DEVICE HERE - if(idev < num) - device_id = device_ids[idev]; - else - device_id = device_ids[num-1]; - - context = clCreateContext(0, 1, &device_id, NULL, NULL, &err); - if (!context) { - std::stringstream msg; - msg << "Failed to create a compute context! " << cl_error_string(err) - << std::endl; - return csound->init_error(msg.str()); - } - - // Create commands - commands = clCreateCommandQueue(context, device_id, 0, &err); - if (!commands) { - std::stringstream msg; - msg << "Failed to create commands! " << cl_error_string(err) - << std::endl; - return csound->init_error(msg.str()); - } - // Create the compute program from the source buffer - program = clCreateProgramWithSource(context, 1, (const char **) &code, - NULL, &err); - if (!program){ - std::stringstream msg; - msg << "Failed to create program! " << cl_error_string(err) - << std::endl; - return csound->init_error(msg.str()); - } - - err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL); - if (err != CL_SUCCESS) - { - size_t len; - char buffer[2048]; - std::stringstream msg; - clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, - sizeof(buffer), buffer, &len); - msg << "Failed to build program executable! " << cl_error_string(err) - << std::endl << buffer << std::endl; - return csound->init_error(msg.str()); - } - - kernel1 = clCreateKernel(program, "sample", &err); - if (!kernel1 || err != CL_SUCCESS) { - std::stringstream msg; - msg << "Failed to create sample compute kernel! " << cl_error_string(err) - << std::endl; - return csound->init_error(msg.str()); - } - - kernel2 = clCreateKernel(program, "update", &err); - if (!kernel2 || err != CL_SUCCESS) { - std::stringstream msg; - msg << "Failed to create update compute kernel! " << cl_error_string(err) - << std::endl; - return csound->init_error(msg.str()); - } - - { - char name[128]; - std::stringstream msg; - clGetDeviceInfo(device_id, CL_DEVICE_NAME, 128, name, NULL); - msg << "using device: " << name << std::endl; - csound->message(msg.str()); - } - - bins = fsig.nbins() - 1; - if(inum > 0 && inum < bins) bins = inum; - vsamps = fsig.hop_size(); - threads = bins*vsamps; - mthreads = bins > vsamps ? bins : vsamps; - asize = vsamps*sizeof(cl_float); - ipsize = mthreads*sizeof(cl_long); - fpsize = fsig.dft_size()*sizeof(cl_float); - - out = clCreateBuffer(context,0, asize, NULL, NULL); - frame = clCreateBuffer(context, CL_MEM_READ_ONLY, fpsize, NULL, NULL); - ph = clCreateBuffer(context,0, ipsize, NULL, NULL); - amps = clCreateBuffer(context,0, mthreads*sizeof(cl_float), NULL, NULL); - - // memset needed? - asize = vsamps*sizeof(float); - mix.allocate(csound, asize); - csound->plugin_deinit(this); - count = 0; - cs_sr = csound->sr(); - - clGetKernelWorkGroupInfo(kernel1, - device_id, CL_KERNEL_WORK_GROUP_SIZE, sizeof(wgs1), &wgs1, NULL); - clGetKernelWorkGroupInfo(kernel2, - device_id, CL_KERNEL_WORK_GROUP_SIZE, sizeof(wgs2), &wgs2, NULL); - - clSetKernelArg(kernel1, 0, sizeof(cl_mem), &out); - clSetKernelArg(kernel1, 1, sizeof(cl_mem), &frame); - clSetKernelArg(kernel1, 2, sizeof(cl_mem), &ph); - clSetKernelArg(kernel1, 3, sizeof(cl_mem), &s); - clSetKernelArg(kernel1, 5, sizeof(cl_int), &bins); - clSetKernelArg(kernel1, 6, sizeof(cl_int), &vsamps); - clSetKernelArg(kernel1, 7, sizeof(cl_float), &cs_sr); - - clSetKernelArg(kernel2, 0, sizeof(cl_mem), &out); - clSetKernelArg(kernel2, 1, sizeof(cl_mem), &frame); - clSetKernelArg(kernel2, 2, sizeof(cl_mem), &ph); - clSetKernelArg(kernel2, 3, sizeof(cl_mem), &s); - clSetKernelArg(kernel2, 5, sizeof(cl_int), &bins); - clSetKernelArg(kernel2, 6, sizeof(cl_int), &vsamps); - clSetKernelArg(kernel2, 7, sizeof(cl_float), &cs_sr); - - return OK; - } - - int deinit() { - clReleaseMemObject(out); - clReleaseMemObject(ph); - clReleaseMemObject(frame); - clReleaseMemObject(amps); - clReleaseProgram(program); - clReleaseKernel(kernel1); - clReleaseKernel(kernel2); - clReleaseCommandQueue(commands); - clReleaseContext(context); - return OK; - } - - int aperf() { - - uint32_t n; - csnd::AudioSig asig(this, outargs(0)); - float *fp = inargs.fsig_data(0).data(); - - for (auto &s : asig) { - if(count == 0) { - int err; - float freq = inargs[2]; - clSetKernelArg(kernel1, 4, sizeof(cl_float), &freq); - clSetKernelArg(kernel2, 4, sizeof(cl_float), &freq); - - clEnqueueWriteBuffer(commands,frame, CL_TRUE, 0, sizeof(cl_float)*bins*2, - fp, 0, NULL, NULL); - err = clEnqueueNDRangeKernel(commands, kernel1, 1, NULL, &threads, &wgs1, - 0, NULL, NULL); - if(err) { - std::stringstream msg; - msg << "Error: Failed to compute sample kernel!" << cl_error_string(err) - << std::endl; - csound->message(msg.str()); - } - clFinish(commands); - clEnqueueReadBuffer(commands, out, - CL_TRUE, 0,vsamps*sizeof(cl_float), mix.data(), 0, NULL, NULL); - err = clEnqueueNDRangeKernel(commands,kernel2, 1, NULL, &mthreads, - &wgs2, 0, NULL, NULL); - if(err) { - std::stringstream msg; - msg << "Error: Failed to compute update kernel!" << cl_error_string(err) - << std::endl; - csound->message(msg.str()); - } - count = vsamps; - } - - s = mix[vsamps - count]*inargs[1]; - count--; - } - - return OK; - } -}; - -#include -void csnd::on_load(Csound *csound) { - csnd::plugin(csound, "cladsyn", "a", "fkkii", csnd::thread::ia); -} - - diff --git a/6.x/src/opencl/cladsynth2.cpp b/6.x/src/opencl/cladsynth2.cpp deleted file mode 100644 index 410518ed..00000000 --- a/6.x/src/opencl/cladsynth2.cpp +++ /dev/null @@ -1,412 +0,0 @@ -/* - cladsynth.cpp - - (c) Victor Lazzarini, 2019 - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include -#include -#include -#include - -#ifdef __MACH__ -#include -#else -#include -#endif - -const char *code = R"( -#define FMAXLEN ((float)0x40000000) -#define PHMASK 0x3fffffff -#define PI 3.1415926f - -inline void AtomicAdd(volatile __global float *source, const float operand) { - union { - unsigned int intVal; - float floatVal; - } newVal; - union { - unsigned int intVal; - float floatVal; - } prevVal; - do { - prevVal.floatVal = *source; - newVal.floatVal = prevVal.floatVal + operand; - } while (atomic_cmpxchg((volatile __global unsigned int *)source, - prevVal.intVal, newVal.intVal) != prevVal.intVal); -} - -kernel void sample(global float *out, global const float *frame, - global const long *ph, - global const float *amps, float pitch, int bins, - int vsize, float sr) { - int t = get_global_id(0); - int n = t%vsize; /* sample index */ - int h = t/vsize; /* bin index */ - int k = h<<1; - long lph; - float a = amps[h], ascl = ((float)n)/vsize; - float fscal = pitch*FMAXLEN/sr; - lph = (ph[h] + (long)(n*round(frame[k+1]*fscal))) & PHMASK; - a += ascl*(frame[k] - a); - AtomicAdd(&out[n], a*sin((2*PI*lph)/FMAXLEN)); -} - -kernel void update(global float *out, global float *frame, - global long *ph, global float *amps, float pitch, int bins, - int vsize, float sr){ - int h = get_global_id(0); - int k = h << 1,i,j; - /* update phases and amps */ - ph[h] = (ph[h] + (long)(vsize*round(pitch*frame[k+1]*FMAXLEN/sr))) & PHMASK; - amps[h] = frame[k]; - if(h >= vsize) return; - out[h] = 0.f; -} - -)"; - - -const char * cl_error_string(int err) { - switch (err) { - case CL_SUCCESS: return "Success!"; - case CL_DEVICE_NOT_FOUND: return "Device not found."; - case CL_DEVICE_NOT_AVAILABLE: return "Device not available"; - case CL_COMPILER_NOT_AVAILABLE: return "Compiler not available"; - case CL_MEM_OBJECT_ALLOCATION_FAILURE: - return "Memory object allocation failure"; - case CL_OUT_OF_RESOURCES: return "Out of resources"; - case CL_OUT_OF_HOST_MEMORY: return "Out of host memory"; - case CL_PROFILING_INFO_NOT_AVAILABLE: - return "Profiling information not available"; - case CL_MEM_COPY_OVERLAP: return "Memory copy overlap"; - case CL_IMAGE_FORMAT_MISMATCH: return "Image format mismatch"; - case CL_IMAGE_FORMAT_NOT_SUPPORTED: return "Image format not supported"; - case CL_BUILD_PROGRAM_FAILURE: return "Program build failure"; - case CL_MAP_FAILURE: return "Map failure"; - case CL_INVALID_VALUE: return "Invalid value"; - case CL_INVALID_DEVICE_TYPE: return "Invalid device type"; - case CL_INVALID_PLATFORM: return "Invalid platform"; - case CL_INVALID_DEVICE: return "Invalid device"; - case CL_INVALID_CONTEXT: return "Invalid context"; - case CL_INVALID_QUEUE_PROPERTIES: return "Invalid queue properties"; - case CL_INVALID_COMMAND_QUEUE: return "Invalid command queue"; - case CL_INVALID_HOST_PTR: return "Invalid host pointer"; - case CL_INVALID_MEM_OBJECT: return "Invalid memory object"; - case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: - return "Invalid image format descriptor"; - case CL_INVALID_IMAGE_SIZE: return "Invalid image size"; - case CL_INVALID_SAMPLER: return "Invalid sampler"; - case CL_INVALID_BINARY: return "Invalid binary"; - case CL_INVALID_BUILD_OPTIONS: return "Invalid build options"; - case CL_INVALID_PROGRAM: return "Invalid program"; - case CL_INVALID_PROGRAM_EXECUTABLE: return "Invalid program executable"; - case CL_INVALID_KERNEL_NAME: return "Invalid kernel name"; - case CL_INVALID_KERNEL_DEFINITION: return "Invalid kernel definition"; - case CL_INVALID_KERNEL: return "Invalid kernel"; - case CL_INVALID_ARG_INDEX: return "Invalid argument index"; - case CL_INVALID_ARG_VALUE: return "Invalid argument value"; - case CL_INVALID_ARG_SIZE: return "Invalid argument size"; - case CL_INVALID_KERNEL_ARGS: return "Invalid kernel arguments"; - case CL_INVALID_WORK_DIMENSION: return "Invalid work dimension"; - case CL_INVALID_WORK_GROUP_SIZE: return "Invalid work group size"; - case CL_INVALID_WORK_ITEM_SIZE: return "Invalid work item size"; - case CL_INVALID_GLOBAL_OFFSET: return "Invalid global offset"; - case CL_INVALID_EVENT_WAIT_LIST: return "Invalid event wait list"; - case CL_INVALID_EVENT: return "Invalid event"; - case CL_INVALID_OPERATION: return "Invalid operation"; - case CL_INVALID_GL_OBJECT: return "Invalid OpenGL object"; - case CL_INVALID_BUFFER_SIZE: return "Invalid buffer size"; - case CL_INVALID_MIP_LEVEL: return "Invalid mip-map level"; - default: return "Unknown error"; - } -} - -struct Cladsyn : csnd::Plugin<1, 6> { - - cl_mem out; - cl_mem frame; - cl_mem ph; - cl_mem amps; - int bins; - size_t threads; - int count; - int vsamps; - size_t mthreads; - int framecount; - cl_context context; - cl_command_queue commands; - cl_program program; - cl_kernel kernel1, kernel2; - size_t wgs1, wgs2; - csnd::AuxMem mix; - csnd::AuxMem spec; - csnd::Table ftab; - csnd::Table atab; - float cs_sr; - - - int init() { - int asize, ipsize, fpsize, err; - cl_device_id device_ids[32], device_id; - cl_uint num = 0, nump = 0; - cl_platform_id platforms[16]; - uint32_t i; - int idev = (int) inargs[5]; - int updt = (int) inargs[4]; - ftab.init(csound, inargs(3)); - atab.init(csound, inargs(2)); - - if(updt > 1024) - return csound->init_error("update period is too large\n"); - - err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 32, device_ids, &num); - if (err != CL_SUCCESS){ - int devs = 0; - clGetPlatformIDs(16, platforms, &nump); - for(i=0; i < nump && devs < 32; i++){ - char name[128]; - std::stringstream msg; - clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 128, name, NULL); - msg << "available platform[" << i << "]: " << name << std::endl; - csound->message(msg.str()); - err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, - 32-devs, &device_ids[devs], &num); - if (err != CL_SUCCESS) { - std::stringstream emsg; - emsg << "failed to find an OpenCL device!" << - cl_error_string(err) << std::endl; - csound->init_error(emsg.str()); - } - } - devs += num; - } - - for(i=0; i < num; i++){ - char name[128]; - cl_device_type type; - clGetDeviceInfo(device_ids[i], CL_DEVICE_NAME, 128, name, NULL); - clGetDeviceInfo(device_ids[i], CL_DEVICE_TYPE, sizeof(cl_device_type), - &type, NULL); - if(type & CL_DEVICE_TYPE_CPU) { - std::stringstream msg; - msg << "available CPU[device " << i << "] " << name << std::endl; - csound->message(msg.str()); - } - else if(type & CL_DEVICE_TYPE_GPU) { - std::stringstream msg; - msg << "available GPU[device " << i << "] " << name << std::endl; - csound->message(msg.str()); - } - else if(type & CL_DEVICE_TYPE_ACCELERATOR) { - std::stringstream msg; - msg << "available ACCELLERATOR[device " << i << "] " << name - << std::endl; - csound->message(msg.str()); - } - else { - std::stringstream msg; - msg << "available GENERIC[device " << i << "] " << name << std::endl; - csound->message(msg.str()); - } - } - - // SELECT THE DEVICE HERE - if(idev < num) - device_id = device_ids[idev]; - else - device_id = device_ids[num-1]; - - context = clCreateContext(0, 1, &device_id, NULL, NULL, &err); - if (!context) { - std::stringstream msg; - msg << "Failed to create a compute context! " << cl_error_string(err) - << std::endl; - return csound->init_error(msg.str()); - } - - // Create commands - commands = clCreateCommandQueue(context, device_id, 0, &err); - if (!commands) { - std::stringstream msg; - msg << "Failed to create commands! " << cl_error_string(err) - << std::endl; - return csound->init_error(msg.str()); - } - // Create the compute program from the source buffer - program = clCreateProgramWithSource(context, 1, (const char **) &code, - NULL, &err); - if (!program){ - std::stringstream msg; - msg << "Failed to create program! " << cl_error_string(err) - << std::endl; - return csound->init_error(msg.str()); - } - - err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL); - if (err != CL_SUCCESS) - { - size_t len; - char buffer[2048]; - std::stringstream msg; - clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, - sizeof(buffer), buffer, &len); - msg << "Failed to build program executable! " << cl_error_string(err) - << std::endl << buffer << std::endl; - return csound->init_error(msg.str()); - } - - kernel1 = clCreateKernel(program, "sample", &err); - if (!kernel1 || err != CL_SUCCESS) { - std::stringstream msg; - msg << "Failed to create sample compute kernel! " << cl_error_string(err) - << std::endl; - return csound->init_error(msg.str()); - } - - kernel2 = clCreateKernel(program, "update", &err); - if (!kernel2 || err != CL_SUCCESS) { - std::stringstream msg; - msg << "Failed to create update compute kernel! " << cl_error_string(err) - << std::endl; - return csound->init_error(msg.str()); - } - - { - char name[128]; - std::stringstream msg; - clGetDeviceInfo(device_id, CL_DEVICE_NAME, 128, name, NULL); - msg << "using device: " << name << std::endl; - csound->message(msg.str()); - } - - bins = atab.len() < ftab.len() ? atab.len() : ftab.len(); - vsamps = updt; - threads = bins*vsamps; - mthreads = bins > vsamps ? bins : vsamps; - asize = vsamps*sizeof(cl_float); - ipsize = mthreads*sizeof(cl_long); - fpsize = 2*bins*sizeof(cl_float); - - out = clCreateBuffer(context,0, asize, NULL, NULL); - frame = clCreateBuffer(context, CL_MEM_READ_ONLY, fpsize, NULL, NULL); - ph = clCreateBuffer(context,0, ipsize, NULL, NULL); - amps = clCreateBuffer(context,0, mthreads*sizeof(cl_float), NULL, NULL); - - // memset needed? - asize = vsamps*sizeof(float); - mix.allocate(csound, asize); - spec.allocate(csound, bins*2); - csound->plugin_deinit(this); - count = 0; - cs_sr = csound->sr(); - - clGetKernelWorkGroupInfo(kernel1, - device_id, CL_KERNEL_WORK_GROUP_SIZE, sizeof(wgs1), &wgs1, NULL); - clGetKernelWorkGroupInfo(kernel2, - device_id, CL_KERNEL_WORK_GROUP_SIZE, sizeof(wgs2), &wgs2, NULL); - - clSetKernelArg(kernel1, 0, sizeof(cl_mem), &out); - clSetKernelArg(kernel1, 1, sizeof(cl_mem), &frame); - clSetKernelArg(kernel1, 2, sizeof(cl_mem), &ph); - clSetKernelArg(kernel1, 3, sizeof(cl_mem), &s); - clSetKernelArg(kernel1, 5, sizeof(cl_int), &bins); - clSetKernelArg(kernel1, 6, sizeof(cl_int), &vsamps); - clSetKernelArg(kernel1, 7, sizeof(cl_float), &cs_sr); - - clSetKernelArg(kernel2, 0, sizeof(cl_mem), &out); - clSetKernelArg(kernel2, 1, sizeof(cl_mem), &frame); - clSetKernelArg(kernel2, 2, sizeof(cl_mem), &ph); - clSetKernelArg(kernel2, 3, sizeof(cl_mem), &s); - clSetKernelArg(kernel2, 5, sizeof(cl_int), &bins); - clSetKernelArg(kernel2, 6, sizeof(cl_int), &vsamps); - clSetKernelArg(kernel2, 7, sizeof(cl_float), &cs_sr); - - return OK; - } - - int deinit() { - clReleaseMemObject(out); - clReleaseMemObject(ph); - clReleaseMemObject(frame); - clReleaseMemObject(amps); - clReleaseProgram(program); - clReleaseKernel(kernel1); - clReleaseKernel(kernel2); - clReleaseCommandQueue(commands); - clReleaseContext(context); - return OK; - } - - int aperf() { - - uint32_t n; - csnd::AudioSig asig(this, outargs(0)); - - for (auto &s : asig) { - if(count == 0) { - int err = 0; - float freq = inargs[1]; - clSetKernelArg(kernel1, 4, sizeof(cl_float), &freq); - clSetKernelArg(kernel2, 4, sizeof(cl_float), &freq); - - float *specf = spec.data(); - for (int k = 0, j = 0; k < bins; k++, j+=2) { - specf[j] = atab[k]; - specf[j+1] = ftab[k]; - } - - clEnqueueWriteBuffer(commands,frame, CL_TRUE, 0, sizeof(cl_float)*bins*2, - specf, 0, NULL, NULL); - err = clEnqueueNDRangeKernel(commands, kernel1, 1, NULL, &threads, &wgs1, - 0, NULL, NULL); - if(err) { - std::stringstream msg; - msg << "Error: Failed to compute sample kernel!" << cl_error_string(err) - << std::endl; - csound->message(msg.str()); - } - clFinish(commands); - clEnqueueReadBuffer(commands, out, - CL_TRUE, 0,vsamps*sizeof(cl_float), mix.data(), 0, NULL, NULL); - err = clEnqueueNDRangeKernel(commands,kernel2, 1, NULL, &mthreads, - &wgs2, 0, NULL, NULL); - if(err) { - std::stringstream msg; - msg << "Error: Failed to compute update kernel!" << cl_error_string(err) - << std::endl; - csound->message(msg.str()); - } - count = vsamps; - } - s = mix[vsamps - count]*inargs[0]; - count--; - } - - return OK; - } -}; - -#include -void csnd::on_load(Csound *csound) { - csnd::plugin(csound, "cladsyn", "a", "kkiiii", csnd::thread::ia); -} - - diff --git a/6.x/src/opencl/clconv.csd b/6.x/src/opencl/clconv.csd deleted file mode 100644 index 0de5c297..00000000 --- a/6.x/src/opencl/clconv.csd +++ /dev/null @@ -1,28 +0,0 @@ - - ---opcode-lib=./libclconv.dylib - - - -ksmps = 1 -0dbfs = 1 - -gift ftgen 0, 0, 0, 1, "pianoc2.wav", 0,0,1 -;tablew 1, 0, gift - -instr 1 -ipsize = 512 -idev = 1; /* device number */ -ain mpulse 1, 7 -asig clconv ain, gift, ipsize, idev - out(asig) - -endin - - - - -i1 0 10 - - - diff --git a/6.x/src/opencl/libcl.dylib b/6.x/src/opencl/libcl.dylib deleted file mode 100644 index fb005909..00000000 Binary files a/6.x/src/opencl/libcl.dylib and /dev/null differ diff --git a/6.x/src/opencl/libclconv.dylib b/6.x/src/opencl/libclconv.dylib deleted file mode 100644 index 49784317..00000000 Binary files a/6.x/src/opencl/libclconv.dylib and /dev/null differ diff --git a/6.x/src/opencl/libclconv.dylib.dSYM/Contents/Info.plist b/6.x/src/opencl/libclconv.dylib.dSYM/Contents/Info.plist deleted file mode 100644 index 44c27ad0..00000000 --- a/6.x/src/opencl/libclconv.dylib.dSYM/Contents/Info.plist +++ /dev/null @@ -1,20 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleIdentifier - com.apple.xcode.dsym.libclconv.dylib - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - dSYM - CFBundleSignature - ???? - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - - diff --git a/6.x/src/opencl/libclconv.dylib.dSYM/Contents/Resources/DWARF/libclconv.dylib b/6.x/src/opencl/libclconv.dylib.dSYM/Contents/Resources/DWARF/libclconv.dylib deleted file mode 100644 index 2b1d979f..00000000 Binary files a/6.x/src/opencl/libclconv.dylib.dSYM/Contents/Resources/DWARF/libclconv.dylib and /dev/null differ diff --git a/6.x/src/opencl/openclop.cpp b/6.x/src/opencl/openclop.cpp deleted file mode 100644 index b8b74085..00000000 --- a/6.x/src/opencl/openclop.cpp +++ /dev/null @@ -1,271 +0,0 @@ -#ifdef __MACH__ -#include -#else -#include -#endif - -#include -#include -#include - -const char *cl_error_string(int err); - -class OCl { - int cl_err; - cl_context context; - cl_command_queue commands; - cl_program program; - std::vector kernel; - std::vector data; - void (*err)(std::string s, void *d); - void *userData; - - static void msg(std::string str, void *userData) { - if (userData == NULL) - std::cout << str << std::endl; - } - -public: - - OCl(cl_device_id device_id, int kernels, int arrays, const char *code, - void (*errs)(std::string s, void *d), void *uData) : - context(NULL), commands(NULL), program(NULL), kernel(kernels), - data(arrays), err(errs == NULL ? this->msg : errs), - userData(uData) { - - context = clCreateContext(0, 1, &device_id, NULL, NULL, &cl_err); - if (!context) { - err(cl_error_string(cl_err), userData); - return; - } - commands = clCreateCommandQueue(context, device_id, 0, &cl_err); - if (!commands) { - err(cl_error_string(cl_err), userData); - return; - } - program = clCreateProgramWithSource(context, 1, (const char **)&code, - NULL, &cl_err); - if (!program) { - err("error creating opencl program\n", userData); - err(cl_error_string(cl_err), userData); - return; - } - cl_err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL); - if (cl_err) { - char log[2048]; - size_t llen; - clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, sizeof(log), - log, &llen); - err("error building opencl program\n", userData); - err(cl_error_string(cl_err), userData); - err(log, userData); - return; - } - } - - ~OCl() { - for(cl_mem i : data) clReleaseMemObject(i); - for(cl_kernel i : kernel) clReleaseKernel(i); - clReleaseProgram(program); - clReleaseCommandQueue(commands); - clReleaseContext(context); - } - - int execute(int kern, size_t threads) { - return clEnqueueNDRangeKernel(commands, kernel[kern], 1, NULL, &threads, NULL, - 0, NULL, NULL); - } - - int setKernel(int n, const char *name) { - kernel[n] = clCreateKernel(program, name, &cl_err); - return cl_err; - } - - int alloc(int array, size_t bytes) { - data[array] = clCreateBuffer(context, 0, bytes, NULL, &cl_err); - return cl_err; - } - - int setArg(int kern, int arg, int num) { - return clSetKernelArg(kernel[kern], num, sizeof(cl_int), &arg); - } - - int setArg(int kern, float arg, int num) { - return clSetKernelArg(kernel[kern], num, sizeof(cl_float), &arg); - } - - int setArg(int kern, double arg, int num) { - return clSetKernelArg(kernel[kern], num, sizeof(cl_double), &arg); - } - - int setArg(int kern, cl_mem *arg, int num) { - return clSetKernelArg(kernel[kern], num, sizeof(cl_mem), arg); - } - - int setArg(int kern, int *arg, int size, int array, int num) { - cl_err = clEnqueueWriteBuffer(commands, data[array], 0, 0, size*sizeof(cl_int), arg, 0, - NULL, NULL); - if (cl_err != CL_SUCCESS) - return cl_err; - else - return clSetKernelArg(kernel[kern], num, sizeof(cl_mem), &data[array]); - } - - int setArg(int kern, float *arg, int size, int array, int num) { - cl_err = clEnqueueWriteBuffer(commands, data[array], 0, 0, size*sizeof(cl_float), arg, 0, - NULL, NULL); - if (cl_err != CL_SUCCESS) - return cl_err; - else - return clSetKernelArg(kernel[kern], num, sizeof(cl_mem), &data[array]); - } - - int setArg(int kern, double *arg, int size, int array, int num) { - cl_err = clEnqueueWriteBuffer(commands, data[array], 0, 0, size*sizeof(cl_float), arg, 0, - NULL, NULL); - if (cl_err != CL_SUCCESS) - return cl_err; - else - return clSetKernelArg(kernel[kern], num, sizeof(cl_mem), &data[array]); - } - - int getData(float *out, int size, int array) { - return clEnqueueReadBuffer(commands, data[array], CL_TRUE, 0, size*sizeof(cl_float), - out, 0, NULL, NULL); - } - - int getData(double *out, int size, int array) { - return clEnqueueReadBuffer(commands, data[array], CL_TRUE, 0, size*sizeof(cl_double), - out, 0, NULL, NULL); - } - - int getData(int *out, int size, int array) { - return clEnqueueReadBuffer(commands, data[array], CL_TRUE, 0, size*sizeof(cl_int), - out, 0, NULL, NULL); - } - - cl_mem *getData(int array) { - return &data[array]; - } - - int setData(float *out, int size, int array) { - return clEnqueueWriteBuffer(commands, data[array], 0, 0, size*sizeof(cl_float), - out, 0, NULL, NULL); - } - - int setData(double *out, int size, int array) { - return clEnqueueWriteBuffer(commands, data[array], 0, 0, size*sizeof(cl_double), - out, 0, NULL, NULL); - } - - int setData(int *out, int size, int array) { - return clEnqueueWriteBuffer(commands, data[array], 0, 0, size*sizeof(cl_int), - out, 0, NULL, NULL); - } - - int copyData(int array1, int array2, int bytes, - int offs1 = 0, int offs2 = 0) { - return clEnqueueCopyBuffer(commands, data[array1], data[array2], offs1, offs2, - bytes, 0, NULL, NULL); - } - -}; - -const char *cl_error_string(int err) { - switch (err) { - case CL_SUCCESS: - return "Success!"; - case CL_DEVICE_NOT_FOUND: - return "Device not found."; - case CL_DEVICE_NOT_AVAILABLE: - return "Device not available"; - case CL_COMPILER_NOT_AVAILABLE: - return "Compiler not available"; - case CL_MEM_OBJECT_ALLOCATION_FAILURE: - return "Memory object allocation failure"; - case CL_OUT_OF_RESOURCES: - return "Out of resources"; - case CL_OUT_OF_HOST_MEMORY: - return "Out of host memory"; - case CL_PROFILING_INFO_NOT_AVAILABLE: - return "Profiling information not available"; - case CL_MEM_COPY_OVERLAP: - return "Memory copy overlap"; - case CL_IMAGE_FORMAT_MISMATCH: - return "Image format mismatch"; - case CL_IMAGE_FORMAT_NOT_SUPPORTED: - return "Image format not supported"; - case CL_BUILD_PROGRAM_FAILURE: - return "Program build failure"; - case CL_MAP_FAILURE: - return "Map failure"; - case CL_INVALID_VALUE: - return "Invalid value"; - case CL_INVALID_DEVICE_TYPE: - return "Invalid device type"; - case CL_INVALID_PLATFORM: - return "Invalid platform"; - case CL_INVALID_DEVICE: - return "Invalid device"; - case CL_INVALID_CONTEXT: - return "Invalid context"; - case CL_INVALID_QUEUE_PROPERTIES: - return "Invalid queue properties"; - case CL_INVALID_COMMAND_QUEUE: - return "Invalid command queue"; - case CL_INVALID_HOST_PTR: - return "Invalid host pointer"; - case CL_INVALID_MEM_OBJECT: - return "Invalid memory object"; - case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: - return "Invalid image format descriptor"; - case CL_INVALID_IMAGE_SIZE: - return "Invalid image size"; - case CL_INVALID_SAMPLER: - return "Invalid sampler"; - case CL_INVALID_BINARY: - return "Invalid binary"; - case CL_INVALID_BUILD_OPTIONS: - return "Invalid build options"; - case CL_INVALID_PROGRAM: - return "Invalid program"; - case CL_INVALID_PROGRAM_EXECUTABLE: - return "Invalid program executable"; - case CL_INVALID_KERNEL_NAME: - return "Invalid kernel name"; - case CL_INVALID_KERNEL_DEFINITION: - return "Invalid kernel definition"; - case CL_INVALID_KERNEL: - return "Invalid kernel"; - case CL_INVALID_ARG_INDEX: - return "Invalid argument index"; - case CL_INVALID_ARG_VALUE: - return "Invalid argument value"; - case CL_INVALID_ARG_SIZE: - return "Invalid argument size"; - case CL_INVALID_KERNEL_ARGS: - return "Invalid kernel arguments"; - case CL_INVALID_WORK_DIMENSION: - return "Invalid work dimension"; - case CL_INVALID_WORK_GROUP_SIZE: - return "Invalid work group size"; - case CL_INVALID_WORK_ITEM_SIZE: - return "Invalid work item size"; - case CL_INVALID_GLOBAL_OFFSET: - return "Invalid global offset"; - case CL_INVALID_EVENT_WAIT_LIST: - return "Invalid event wait list"; - case CL_INVALID_EVENT: - return "Invalid event"; - case CL_INVALID_OPERATION: - return "Invalid operation"; - case CL_INVALID_GL_OBJECT: - return "Invalid OpenGL object"; - case CL_INVALID_BUFFER_SIZE: - return "Invalid buffer size"; - case CL_INVALID_MIP_LEVEL: - return "Invalid mip-map level"; - default: - return "Unknown error"; - } -} diff --git a/6.x/src/p5glove/CMakeLists.txt b/6.x/src/p5glove/CMakeLists.txt deleted file mode 100644 index 8e6dcc49..00000000 --- a/6.x/src/p5glove/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -option(BUILD_P5GLOVE_OPCODES "Build the P5Glove opcodes" ON) - -if (NOT APPLE) - find_path(P5GLOVE_INCLUDE_DIR p5glove.h /usr/local/include) - find_library(P5GLOVE_LIB p5glove) - check_deps(BUILD_P5GLOVE_OPCODES P5GLOVE_LIB) - - if(BUILD_P5GLOVE_OPCODES) - make_plugin(p5g p5glove.c ${P5GLOVE_LIB}) - target_include_directories(p5g PRIVATE ${P5GLOVE_INCLUDE_DIR}) - target_include_directories(p5g PRIVATE ${CSOUND_INCLUDE_DIR}) - endif() -else() - if(BUILD_P5GLOVE_OPCODES) - make_plugin(p5g "p5glove.c;libp5glove/p5glove.c;libp5glove/usb_hid_macosx.c") - target_link_libraries(p5g "-framework IOKit" "-framework CoreFoundation") - target_include_directories(p5g PRIVATE ./libp5glove ${CSOUND_INCLUDE_DIR}) - endif() -endif() diff --git a/6.x/src/p5glove/libp5glove/p5glove.c b/6.x/src/p5glove/libp5glove/p5glove.c deleted file mode 100644 index 5abc3111..00000000 --- a/6.x/src/p5glove/libp5glove/p5glove.c +++ /dev/null @@ -1,690 +0,0 @@ -/* - * $Id$ - * - * Copyright (c) 2003 Jason McMullan - * Windows patch (c) 2004 Ross Bencina - * MacOSX patch (c) 2004 Tim Kreger - * - * USB P5 Data Glove support - */ - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include /* for calloc */ -#include -#include /* for memcpy */ -#include - -#include "usb_hid.h" -#include -#include "p5glove.h" - -#define DEBUG -#ifdef DEBUG -#define DPRINTF(fmt,args...) fprintf(stderr,"p5: " fmt , ##args ) -#else -#define DPRINTF(fmt,args...) do { } while (0) -#endif - -struct p5glove { - USBHID usb; - - char name[128]; - - /* Calibration data from Report 12 & 6 */ - struct p5glove_cal { - int id; /* Device id */ - struct { - double v; /* in Radians */ - double h; /* in Radians */ - } head[2]; - double head_dist; /* in Meters */ - double led[10][3]; - } cal; - - struct p5glove_data { - struct timeval sampled; /* Time sampled at */ - uint32_t valid; /* Which data items are valid (mask) */ - - int buttons; /* Button bitmask */ - int finger[5]; /* Finger clench values (0-63) */ - - /* Raw glove data */ - struct p5glove_ir { - int visible; /* Was the sensor visible? */ - int v1,v2,h; - } ir[8]; /* IR Sensors values. (-511 - 511) */ - - /* Computed from p5g_process_sample - */ - double position[3]; /* Position */ - - /* Rotation information */ - struct { - double axis[3]; /* Rotation axis (normalized) */ - double angle; /* In degrees */ - } rotation; - } data,prev; -}; - -static uint32_t get_bits(uint8_t *data,int pos,int len) -{ - int index = (pos>>3); - uint32_t value = 0; - - pos &= 0x7; - if (pos != 0) { - value |= (data[index] & (0xff >> pos)) << (len-(8-pos)); - len -= (8-pos); - index++; - } - - for (; len >= 8; len-=8) { - value |= data[index] << (len-8); - index++; - } - - if (len > 0) - value |= (data[index] & (0xff << (8-len))) >> (8-len); - - return value; -} - -static int32_t get_bits_signed(uint8_t *data,int pos,int len) -{ - uint32_t value,mask=0; - - value = get_bits(data,pos,len); - if (value & (1 << (len-1))) - mask = 0xffffffff << (len - 32); - return value | mask; -} - -static void p5g_unpack_sample(struct p5glove *p5, uint8_t data[24]) -{ - unsigned char tmp[24]; - int visible=1; - int i; - - /* Decode data. - * Format (nibbles from LSB to MSB) - * 11111111111111112222222222222222 - * 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF - * 01ddddddddBCCCCVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVxxx - * 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 - * 1 1 1 1 1 1 1 1 - * (bytes from LSB to MSB) - * - * d - Packed 6-bit bend sensor data (Index, Middle, Ring, Pinky, Thumb) - * B - Button data. A=1, B=2, C=4 - * C - IR sensor report index - * V - Packed 30 bit signed IR info (10 bits X, 10 bits Y, 10 bits Z), x4 - */ - - if (data[0] != 1) { -printf("Odd. Sample [0]=%d\n",data[0]); - return; - } - - for (i=0; i < 5; i++) { - int value; - - switch (i) { - case 0: value = data[1] >> 2; break; - case 1: value = ((data[1] & 0x3) << 4) | (data[2] >> 4); break; - case 2: value = ((data[2] & 0xF) << 2) | (data[3] >> 6); break; - case 3: value = (data[3] & 0x3F); break; - case 4: value = data[4] >> 2; break; - default: value = 0; break; - } - - p5->data.finger[i]=get_bits(data,8+6*i,6); - } - - p5->data.buttons=get_bits(data,40,4); - - /* Clear visibility */ - for (i=0 ; i <8; i++) - p5->data.ir[i].visible=0; - - for (i=0; i < 4; i++) { - int axis; - int value; - - axis = get_bits(data,44+4*i,4); - if (axis & 0x8) - continue; - - p5->data.ir[axis].v2=get_bits_signed(data,60+(i*30),10); - p5->data.ir[axis].v1=get_bits_signed(data,60+(i*30)+10,10); - p5->data.ir[axis].h=get_bits_signed(data,60+(i*30)+20,10); - p5->data.ir[axis].visible=visible++; - } -} - -void p5g_process_led(P5Glove p5,int led,double pos[3]) -{ - double v1,v2,h,d,zprime; - - v1 = atan(p5->data.ir[led].v1/512.0)+p5->cal.head[0].v; - v2 = atan(p5->data.ir[led].v2/512.0)+p5->cal.head[1].v; - h = atan(p5->data.ir[led].h/512.0); - d = p5->cal.head_dist; - - zprime = d/(tan(v1)-tan(v2)); - - pos[0]=-sin(h)*zprime; - pos[1]=tan(v1)*zprime-d/2.0; /* Places 0 in the center */ - pos[2]=cos(h)*zprime-d*2.0; /* A reasonable Z center */ -} - -int p5glove_reference_led(P5Glove p5, int led, double pos[3]) -{ - if (led < 0 || led > 7) - return -EINVAL; - - memcpy(pos,p5->cal.led[led],sizeof(double)*3); - return 0; -} - -#ifdef CHECK_ACUTE_TRIANGLES -static int p5glove_check_triangle(P5Glove p5,int led1,int led2,int led3) -{ - double c; - int led[3]; - int i; - - led[0]=led1; - led[1]=led2; - led[2]=led3; - - for (i=0; i < 3; i++) { - c=p5glove_angle(p5->cal.led[led[i]], - p5->cal.led[led[(i+1)%3]], - p5->cal.led[led[(i+2)%3]])*180.0/M_PI; - - /* At too acute/obtune an angle? */ - DPRINTF("Angle %d-%d-%d is %.4lf\n",led[i],led[(i+1)%3],led[(i+2)%3],c); - if (c < 7.0) - return -EINVAL; - } - - return 0; -} -#endif - -/* Determine the 'best' leds to use form the data. - * Return the # of good leds - */ -static int p5g_best_leds(P5Glove p5,int led[4],double pos[4][3]) -{ - int leds; - int i,j; - int error[4]={0,0,0,0}; - - for (i=0; i < 4; i++) - led[i]=-1; - - /* Get the position from the 'best led' */ - for (i = 0 ; i < 8; i++) - if (p5->data.ir[i].visible) - led[p5->data.ir[i].visible-1]=i; - - /* Hmm. No 'best' led. - */ - if (led[0] < 0) - return -ENOENT; - p5g_process_led(p5,led[0],pos[0]); - - if (led[1] < 0) - return 1; - p5g_process_led(p5,led[1],pos[1]); - - if (led[2] < 0) - return 2; - - p5g_process_led(p5,led[2],pos[2]); - - /* If we have more than 2, we need to verify the data */ - if (led[3] < 0) - leds=3; - else { - p5g_process_led(p5,led[3],pos[3]); - leds=4; - } - - /* For each led-led pair, determine the error % versus the - * reference distances - */ - DPRINTF("Distances: %d - %d - %d - %d\n",led[0],led[1],led[2],led[3]); - for (i=0; i < leds; i++) { - for (j=i+1 ;j < leds; j++) { - double ref_dist = p5glove_dist(p5->cal.led[led[i]],p5->cal.led[led[j]]); - double dist = p5glove_dist(pos[i],pos[j]); - double err = fabs(dist-ref_dist)/ref_dist; - - DPRINTF("%d - %d: %.4lf ",led[i],led[j],ref_dist); - DPRINTF("(%.4lf) [%.4lf]\n",led[i],led[j],dist,err); - - /* Max 9% error margin on distance */ - if (err > 0.20) { - error[i]++; - error[j]++; - } - } - } - - /* Mark as dead anything with an error index of leds-1 */ - j=leds-1; - for (i=0; i < leds; i++) { - if (error[i] != j) - continue; - - DPRINTF("Dead: Led %d\n",led[i]); - leds--; - if (i != leds) { - memcpy(&error[i],&error[i+1],sizeof(int)*(leds-i)); - memcpy(&led[i],&led[i+1],sizeof(double)*(leds-i)); - memcpy(pos[i],pos[i+1],sizeof(double)*3*(leds-i)); - } - i--; - if (leds == 1) - return leds; - } - -#ifdef CHECK_ACUTE_TRIANGLES - /* Not enough left for rotation. Darn. */ - if (leds < 3) - return leds; - - /* Check all triangles for obtusity */ - if (leds == 3) { - int err; - err=p5glove_check_triangle(p5,led[0],led[1],led[2]); - if (err < 0) - return 1; - return 3; - } - - /* Leds == 4 */ - for (i=0; i < leds; i++) - error[i]=0; - - for (i=0; i < leds; i++) { - int err; - int l[3]; - - err = p5glove_check_triangle(p5,led[i],led[(i+1)%4],led[(i+2)%4]); - if (err < 0) { - error[i]++; - error[(i+1)%4]++; - error[(i+2)%4]++; - } - } - - for (i=0; i < leds; i++) - DPRINTF("%d: error=%d\n",led[i],error[i]); - - - /* Mark as dead anything with an error index of leds-1 */ - j=leds-1; - for (i=0; i < leds; i++) { - if (error[i] != j) - continue; - - DPRINTF("Dead: Led %d\n",led[i]); - leds--; - if (i != leds) { - memcpy(&error[i],&error[i+1],sizeof(int)*(leds-i)); - memcpy(&led[i],&led[i+1],sizeof(double)*(leds-i)); - memcpy(pos[i],pos[i+1],sizeof(double)*3*(leds-i)); - } - i--; - if (leds == 1) - return leds; - } -#endif /* CHECK_ACUTE_TRIANGES */ - - return leds; -} - -/* Calculate delta, then store in 'prev' - */ -static int p5g_delta(P5Glove p5,int have_pos, int have_rot) -{ - int mask=0; - int i; - - if (p5->prev.buttons != p5->data.buttons) - mask |= P5GLOVE_DELTA_BUTTONS; - - for (i=0; i < 5; i++) - if (p5->prev.finger[i] != p5->data.finger[i]) { - mask |= P5GLOVE_DELTA_FINGERS; - break; - } - - if (have_pos && (! memcmp(p5->data.position,p5->prev.position,sizeof(double)*3))) - have_pos=0; - - if (have_rot && (! memcmp(&p5->data.rotation,&p5->prev.rotation,sizeof(p5->data.rotation)))) - have_rot=0; - - memcpy(&p5->prev,&p5->data,sizeof(p5->data)); - return mask | - (have_pos ? P5GLOVE_DELTA_POSITION : 0) | - (have_rot ? P5GLOVE_DELTA_ROTATION : 0); -} - - -static int p5g_process_sample(P5Glove p5) -{ - int i,j,leds; - int led[4] = {-1,-1,-1,-1}; - double pos[4][3]; - double pos_plane[3],ref_plane[3]; - double rot_matrix[4][4]; - double c,s,t; - double x,y,z; - const double zero[3]={0.0,0.0,0.0}; - const double y_up[3]={0.0,1.0,0.0}; - - /* Get the best leds from the data */ - leds=p5g_best_leds(p5,led,pos); - if (leds < 1) - return p5g_delta(p5,0,0); - - p5g_process_led(p5,led[0],pos[0]); - - /* Less than 3 leds. Can't calculate rotation info. - */ - if (leds < 3) - return p5g_delta(p5,1,0); - - /* Calculate reference normal of the leds */ - p5glove_plane(p5->cal.led[led[0]], - p5->cal.led[led[1]], - p5->cal.led[led[2]],ref_plane); - - /* Calculate actual normal of the leds */ - p5glove_plane(pos[0],pos[1],pos[2],pos_plane); - - /* Calculate cos(theta) from the dot product of the ref and actual */ - c=p5glove_dot(ref_plane,pos_plane); - p5->data.rotation.angle=acos(c)*180.0/M_PI; - /* Calculate the rotation axis normal */ - p5glove_plane(ref_plane,zero,pos_plane,p5->data.rotation.axis); - -DPRINTF("Position: %d - %d - %d\n",led[0],led[1],led[2]); -DPRINTF("Position: [%.4lf, %.4lf,%.4lf]\n",pos[0][0],pos[0][1],pos[0][2]); -DPRINTF("Reference normal: [%.4lf, %.4lf, %.4lf]\n",ref_plane[0],ref_plane[1],ref_plane[2]); -DPRINTF("Position normal: [%.4lf, %.4lf, %.4lf]\n",pos_plane[0],pos_plane[1],pos_plane[2]); -DPRINTF("Reference angle: %.4lf\n",p5glove_dot(ref_plane,y_up)*180.0/M_PI); -DPRINTF("Normal up angle: %.4lf\n",p5glove_dot(pos_plane,y_up)*180.0/M_PI); -DPRINTF("Rotation angle: %.4lf\n",p5->data.rotation.angle); -DPRINTF("Rotation axis : [%.4lf, %.4lf, %.4lf]\n",p5->data.rotation.axis[0],p5->data.rotation.axis[1],p5->data.rotation.axis[2]); - - c=cos(p5->data.rotation.angle*M_PI/180.0); - s=sin(p5->data.rotation.angle*M_PI/180.0); - t=1.0-c; - - /* Calculate transformation matrix, in column major order */ - x=p5->data.rotation.axis[0]; - y=p5->data.rotation.axis[1]; - z=p5->data.rotation.axis[2]; - - /* Column 0 */ - rot_matrix[0][0]=t*x*x+c; - rot_matrix[0][1]=t*x*y-s*z; - rot_matrix[0][2]=t*x*z+s*y; - rot_matrix[0][3]=0; - - /* Column 1 */ - rot_matrix[1][0]=t*x*y+s*z; - rot_matrix[1][1]=t*y*y+c; - rot_matrix[1][2]=t*y*z-s*x; - rot_matrix[1][3]=0; - - /* Column 2 */ - rot_matrix[2][0]=t*x*z-s*y; - rot_matrix[2][1]=t*y*z+s*x; - rot_matrix[2][2]=t*z*z+c; - rot_matrix[2][3]=0; - - /* Column 3 */ - rot_matrix[3][0]=0; - rot_matrix[3][1]=0; - rot_matrix[3][2]=0; - rot_matrix[3][3]=1; - - /* Now, apply the rotation angle to the position */ - p5glove_vec_mat(p5->cal.led[led[0]],rot_matrix,pos[1]); - - /* Then simply subtract the difference from the - * reference position to get the *real* point */ - for (i=0; i<3; i++) - p5->data.position[i] = pos[0][i] - pos[1][i]; - - /* There! The position is corrected, the rotation matrix is complete - we're done! */ - return p5g_delta(p5,1,1); -} - -static int p5g_parse_report6(struct p5glove *p5,int8_t *buff) -{ - /* We are given 32nds of a degree, so: */ -#define REPORT6_TO_RAD(x) ((x)/32.0*M_PI/180.0) - p5->cal.head[0].v += REPORT6_TO_RAD(buff[1]); - p5->cal.head[0].h += REPORT6_TO_RAD(buff[2]); - p5->cal.head[1].v += REPORT6_TO_RAD(buff[3]); - p5->cal.head[1].h += REPORT6_TO_RAD(buff[4]); - - /* The following is in 10ths of an inch. Convert to meters */ -#define REPORT6_TO_METERS(x) ((x)/393.70039) - p5->cal.head_dist = REPORT6_TO_METERS(buff[5]); - - return 0; -} - -static int p5g_parse_report12(struct p5glove *p5,uint8_t *buff) -{ - int led,axis; - - p5->cal.id = get_bits(buff,8,8); - switch (p5->cal.id) { - case 0: - p5->cal.head[0].v += 17.0 * (M_PI/180.0); - p5->cal.head[1].v += -10.0 * (M_PI/180.0); - break; - default: fprintf(stderr,"libp5glove: unknown glove type %d\n",p5->cal.id); - return -EINVAL; - } - /* The following is in 100ths of an inch. Convert to meters */ -#define REPORT12_TO_METERS(x) ((x)/3937.0039) - for (led = 0; led < 10; led++) { - for (axis = 0; axis < 3; axis++) { - int16_t val; - val = get_bits(buff,16+(48*led)+(16*axis),16); - p5->cal.led[led][axis]=REPORT12_TO_METERS(val); - if (axis == 0) - p5->cal.led[led][axis] *= -1.0; - } - } - -#ifdef DEBUG_CAL -for (led=0; led < 12; led++) { - DPRINTF("%d %.4lf %.4lf %.4lf\n",led, - p5->cal.led[led][0], - p5->cal.led[led][1], - p5->cal.led[led][2]); -} -#endif - - return 0; -} - -static int p5glove_calibrate(struct p5glove *p5) -{ - int8_t report6_buff[6]; - int8_t report12_buff[255]; - int err; - - memset(&p5->cal,0,sizeof(p5->cal)); - report12_buff[0]=12; - err=GetUSBHIDFeature(p5->usb,report12_buff,sizeof(report12_buff)); - if (err < 0) goto end; - - err=p5g_parse_report12(p5,report12_buff); - if (err < 0) goto end; - - report6_buff[0]=6; - err=GetUSBHIDFeature(p5->usb,report6_buff,sizeof(report6_buff)); - if (err < 0) goto end; - - err=p5g_parse_report6(p5,report6_buff); - -#ifdef DEBUG_CALIB -DPRINTF("Cal results:\n"); -{ int i; for (i=0;i<2;i++) { -DPRINTF("\tHead %d.v = %.2f deg\n",i,p5->cal.head[i].v * 180.0/M_PI); -DPRINTF("\tHead %d.h = %.2f deg\n",i,p5->cal.head[i].h * 180.0/M_PI);} } -DPRINTF("\tHead Distance = %.2f meters\n",p5->cal.head_dist); -#endif - -end: - return err; -} - -/*********** Public API **************/ - -P5Glove p5glove_open(int glove_number) -{ - struct p5glove *p5 = NULL; - USBHID usb; - int err; - - usb = OpenUSBHID ( - glove_number, /* nth matching device */ - 0x0d7f, /* vendor id */ - 0x0100, /* product id */ - 0, /* version number (not used) */ - SELECT_VENDOR_ID_FLAG | SELECT_PRODUCT_ID_FLAG ); /* selection flags */ - if ( usb == INVALID_USBHID_VALUE ) - return NULL; - - p5=calloc(1,sizeof(*p5)); - p5->usb=usb; - err = p5glove_calibrate(p5); - if (err < 0) { - if (err == -EBUSY) { - fprintf(stderr,"libp5glove: Can't get feature reports.\n"); - fprintf(stderr,"libp5glove: If you have the 'usbmouse' module loaded, please unload it.\n"); - } - free(p5); - CloseUSBHID(usb); - return NULL; - } - - return p5; -} - -void p5glove_close(P5Glove p5) -{ - if (p5->usb != NULL) { - CloseUSBHID(p5->usb); - } - p5->usb=NULL; - free(p5); -} - -int p5glove_sample(P5Glove p5,int timeout) -{ - int err; - uint8_t data[24]; - - if ( ReadUSBHID( p5->usb, data, 24 ) == 24 && data[0]==1) { - p5g_unpack_sample(p5, data); - err=p5g_process_sample(p5); - } else { - errno = EACCES; - err = -1; - } - - return err; -} - -int p5glove_get_buttons(P5Glove p5,uint32_t *buttons) -{ - *buttons = p5->data.buttons; - return 0; -} - -int p5glove_get_finger(P5Glove p5,int finger,double *clench) -{ - *clench = p5->data.finger[finger]/63.0; - return 0; -} - -int p5glove_get_position(P5Glove p5,double pos[3]) -{ - memcpy(pos,p5->data.position,sizeof(double)*3); - return 0; -} - -int p5glove_get_rotation(P5Glove p5,double *angle,double axis[3]) -{ - memcpy(axis,p5->data.rotation.axis,sizeof(double)*3); - *angle = p5->data.rotation.angle; - return 0; -} - -void p5glove_begin_calibration(P5Glove p5) -{ - char report[2] = { 0x01, 0x01 }; - SetUSBHIDFeature( p5->usb, report, 2 ); -} - -void p5glove_end_calibration(P5Glove p5) -{ - char report[2] = { 0x01, 0x00 }; - SetUSBHIDFeature( p5->usb, report, 2 ); -} - -int p5glove_get_mouse_mode(P5Glove p5) -{ - char report[2] = { 0x05, 0x00 }; - GetUSBHIDFeature( p5->usb, report, 2 ); - - return (report[1] == 0x01)? 1 : 0; -} - -void p5glove_mouse_mode_on(P5Glove p5) -{ - char report[2] = { 0x05, 0x01 }; - SetUSBHIDFeature( p5->usb, report, 2 ); -} - -void p5glove_mouse_mode_off(P5Glove p5) -{ - char report[2] = { 0x05, 0xFF }; - SetUSBHIDFeature( p5->usb, report, 2 ); -} - diff --git a/6.x/src/p5glove/libp5glove/usb_hid_macosx.c b/6.x/src/p5glove/libp5glove/usb_hid_macosx.c deleted file mode 100644 index 6359fd6e..00000000 --- a/6.x/src/p5glove/libp5glove/usb_hid_macosx.c +++ /dev/null @@ -1,365 +0,0 @@ -/* - Copyright (c) 2004 Tim Kreger - - Macintosh OS X USB HID I/O routines - - Created by Tim Kreger on Wed Mar 17 2004. -*/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - - -#include -#include -#include - - -// Mac Headers - -#include -#include -#include -#include -#include - - -#include "macosx_usb_hid.h" - - - -USBHIDHandle OpenUSBHID( int index, int idVendor, int idProduct, int versionNumber, int flags ) -{ - // todo: index and flags are currently ignored, see win32 for example implementation. - - IOUSBDeviceInterface **dev; - IOCFPlugInInterface **iodev; - kern_return_t err; - CFMutableDictionaryRef matchingDictionary = 0; // requires - CFNumberRef numberRef; - UInt8 inPipeRef; - io_service_t usbDeviceRef; - io_iterator_t iterator = 0; - - SInt32 score; - - UInt8 numConf; - IOUSBConfigurationDescriptorPtr confDesc; - io_service_t usbInterfaceRef; - IOUSBFindInterfaceRequest interfaceRequest; - IOUSBInterfaceInterface183 **intf = 0; - UInt8 numPipes; - UInt8 direction, number, transferType, interval; - int i; - UInt16 maxPacketSize; - - mach_port_t masterPort; // requires - - - err = IOMasterPort(MACH_PORT_NULL, &masterPort); - if (err) - { - fprintf( stderr, "USBSimpleExample: could not create master port, err = %08x\n", err); - return 0; - } - - // configure matching dictionary - - matchingDictionary = IOServiceMatching(kIOUSBDeviceClassName); // requires - if (!matchingDictionary) - { - fprintf( stderr, "USBSimpleExample: could not create matching dictionary\n"); - return 0; - } - - if( 1 ){ //todo: use flag to decide whether to add vendor id - - numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &idVendor); - if (!numberRef) - { - fprintf( stderr, "USBSimpleExample: could not create CFNumberRef for vendor\n"); - return 0; - } - - CFDictionaryAddValue(matchingDictionary, CFSTR(kUSBVendorID), numberRef); - CFRelease(numberRef); - numberRef = 0; - } - - if( 1 ){ // todo: use flag to decide whether to add product id - numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &idProduct); - if (!numberRef) - { - fprintf( stderr, "USBSimpleExample: could not create CFNumberRef for product\n"); - return 0; - } - - CFDictionaryAddValue(matchingDictionary, CFSTR(kUSBProductID), numberRef); - CFRelease(numberRef); - numberRef = 0; - } - - // get iterator to matching devices - - err = IOServiceGetMatchingServices(masterPort, matchingDictionary, &iterator); - matchingDictionary = 0; - - // get first matching device - - if((usbDeviceRef = IOIteratorNext(iterator))) - { - // open device - - err = IOCreatePlugInInterfaceForService(usbDeviceRef, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &iodev, &score); - if (err || !iodev) - { - fprintf( stderr, "dealWithDevice: unable to create plugin. ret = %08x, iodev = %p\n", err, iodev); - return 0; - } - - err = (*iodev)->QueryInterface(iodev, CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID), (LPVOID)&dev); - (*iodev)->Release(iodev); // done with this - if (err || !dev) - { - fprintf( stderr, "dealWithDevice: unable to create a device interface. ret = %08x, dev = %p\n", err, dev); - return 0; - } - - err = (*dev)->USBDeviceOpen(dev); - if (err) - { - fprintf( stderr, "dealWithDevice: unable to open device. ret = %08x\n", err); - return 0; - } - - err = (*dev)->GetNumberOfConfigurations(dev, &numConf); - if (err || !numConf) - { - fprintf( stderr, "dealWithDevice: unable to obtain the number of configurations. ret = %08x\n", err); - (*dev)->USBDeviceClose(dev); - (*dev)->Release(dev); - return 0; - } - - fprintf( stderr, "dealWithDevice: found %d configurations\n", numConf); - - err = (*dev)->GetConfigurationDescriptorPtr(dev, 0, &confDesc); // get the first config desc (index 0) - if (err) - { - fprintf( stderr, "dealWithDevice:unable to get config descriptor for index 0\n"); - (*dev)->USBDeviceClose(dev); - (*dev)->Release(dev); - return 0; - } - - err = (*dev)->SetConfiguration(dev, confDesc->bConfigurationValue); - if (err) - { - fprintf( stderr, "dealWithDevice: unable to set the configuration\n"); - (*dev)->USBDeviceClose(dev); - (*dev)->Release(dev); - return 0; - } - - }else{ - return intf; - } - - // set criteria for interface iterator - - interfaceRequest.bInterfaceClass = 3; // requested class (3==hid class) - interfaceRequest.bInterfaceSubClass = 0; // requested subclass - interfaceRequest.bInterfaceProtocol = kIOUSBFindInterfaceDontCare; // requested protocol - interfaceRequest.bAlternateSetting = kIOUSBFindInterfaceDontCare; // requested alt setting - - err = (*dev)->CreateInterfaceIterator(dev, &interfaceRequest, &iterator); - if (err) - { - fprintf( stderr, "dealWithDevice: unable to create interface iterator\n"); - (*dev)->USBDeviceClose(dev); - (*dev)->Release(dev); - return 0; - } - - // get first interface matching criteria - - if( (usbInterfaceRef = IOIteratorNext(iterator)) ) - { - // open interface - - fprintf( stderr, "found interface: %u\n", usbInterfaceRef); - - err = IOCreatePlugInInterfaceForService(usbInterfaceRef, kIOUSBInterfaceUserClientTypeID, kIOCFPlugInInterfaceID, &iodev, &score); - if (err || !iodev) - { - fprintf( stderr, "dealWithInterface: unable to create plugin. ret = %08x, iodev = %p\n", err, iodev); - return 0; - } - - err = (*iodev)->QueryInterface(iodev, CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID183), (LPVOID)&intf); - (*iodev)->Release(iodev); // done with this - if (err || !intf) - { - fprintf( stderr, "dealWithInterface: unable to create a device interface. ret = %08x, intf = %p\n", err, intf); - return 0; - } - - err = (*intf)->USBInterfaceOpenSeize(intf); - if (err) - { - (*intf)->Release( intf ); - fprintf( stderr, "dealWithInterface: unable to open interface. ret = %08x, score = %d \n", err, (int)score); - return 0; - } - - }else{ - return 0; - } - - - err = (*intf)->GetNumEndpoints(intf, &numPipes); - if (err) - { - fprintf( stderr, "dealWithInterface: unable to get number of endpoints. ret = %08x\n", err); - (*intf)->USBInterfaceClose(intf); - (*intf)->Release(intf); - return 0; - } - - fprintf( stderr, "dealWithInterface: found %d pipes\n", numPipes); - - // find pipe with transfer type kUSBInterrupt and direction kUSBIn - // store pipe number in inPipeRef - - for (i=1; i <= numPipes; i++) - { - err = (*intf)->GetPipeProperties(intf, i, &direction, &number, &transferType, &maxPacketSize, &interval); - if (err) - { - (*intf)->USBInterfaceClose(intf); - (*intf)->Release(intf); - fprintf( stderr, "dealWithPipes: unable to get pipe properties for pipe %d, err = %08x\n", i, err); - return 0; - } - - if (transferType != kUSBInterrupt) - { - fprintf( stderr, "dealWithPipes: skipping pipe %d because it is not an interupt pipe\n", i); - fprintf( stderr, "Pipe is type %d\n", transferType); - - continue; - } - - if (direction == kUSBIn) - { - fprintf( stderr, "dealWithPipes: grabbing BULK IN pipe index %d, number %d, inteveral %d \n",i, number, interval); - inPipeRef = i; - } - } - - return intf; -} - - - - -void CloseUSBHID( USBHIDHandle usbHidHandle ) -{ - IOUSBInterfaceInterface183 **intf = usbHidHandle; - - (*intf)->USBInterfaceClose(intf); - (*intf)->Release(intf); -} - - - -int ReadUSBHID( USBHIDHandle usbHidHandle, void *data, int count ) -{ - IOUSBInterfaceInterface183 **intf = usbHidHandle; - UInt32 readSize = count; - - (*intf)->ReadPipe(intf, 1, data, &readSize ); // 1 should be inPipeRef - - return readSize; -} - - -int HIrequest(void *usbHidHandle, UInt8 RequestType, UInt16 Request, UInt16 ReportId, int index, unsigned char *raw_buf, int ReportSize ) -{ - IOUSBDevRequest request; - IOUSBInterfaceInterface183 **intf = usbHidHandle; - IOUSBDeviceInterface **device; - io_service_t usbDeviceRef; - IOReturn success = 0 ; - char test[2]; - - // 0x21 for set, 0xA1for get - request.bmRequestType = RequestType; - request.bRequest = Request; - request.wValue = ReportId; - request.wIndex = index; - request.wLength = ReportSize; - request.pData = raw_buf; - - // (*theDev)->DeviceRequest(theDev, &request); - success = (*intf)->ControlRequest(intf, 0, &request); - - if(success != kIOReturnSuccess) - printf("Hi Request Failed \n"); - return success; - -} - - -int usb_get_report(void *usbHidHandle,int ReportId, unsigned char *raw_buf, int ReportSize ) -{ - int err; - - err = HIrequest(usbHidHandle, - 0xA1, /* Request Type */ - 0x01, /* HID_REPORT_GET */ - ReportId+(0x03<<8), /* HID_REPORT_TYPE_FEATURE */ - 1, /* Index */ - raw_buf, ReportSize); -// if (err == -EPIPE) -// goto retry; - return err; -} - - -int usb_set_report(void *usbHidHandle,int ReportId, unsigned char *raw_buf, int ReportSize ) -{ - return HIrequest(usbHidHandle, - 0x21, /* Request Type */ - 0x09, /* HID_REPORT_SET */ - ReportId+(0x03<<8), /* HID_REPORT_TYPE_FEATURE */ - 1, /* Index */ - raw_buf, ReportSize); - -} - -int SetUSBHIDFeature( USBHIDHandle handle, char *report, int count ) -{ - return usb_set_report(handle, report[0]&0xf, (unsigned char*) report, count ); - -} - -int GetUSBHIDFeature( USBHIDHandle handle, char *report, int count ) -{ - return usb_get_report(handle, report[0]&0xf, (unsigned char*) report, count ); - -} - diff --git a/6.x/src/p5glove/libp5glove/usb_hid_win32.c b/6.x/src/p5glove/libp5glove/usb_hid_win32.c deleted file mode 100644 index 6987acf4..00000000 --- a/6.x/src/p5glove/libp5glove/usb_hid_win32.c +++ /dev/null @@ -1,346 +0,0 @@ -/* - Copyright (c) 2003 Alan Macek - (c) 2004 Ross Bencina - - Win32 USB HID I/O routines - - Based on usb.c code be Alan Macek -*/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "usb_hid.h" -#include -#include -#include - -#ifdef HAVE_HIDSDI_DDK_HEADERS - -/* - hidsdi.h and the files it includes are part of the Windows DDK. If you - don't have the DDK header files, define HAVE_HIDSDI_DDK_HEADERS, otherwise - the definitions in the #else block will be used. -*/ - -# include - -#else - -#include - -void __stdcall -HidD_GetHidGuid ( - OUT LPGUID HidGuid - ); - -typedef struct _HIDD_ATTRIBUTES { - ULONG Size; // = sizeof (struct _HIDD_ATTRIBUTES) - - // - // Vendor ids of this hid device - // - USHORT VendorID; - USHORT ProductID; - USHORT VersionNumber; - - // - // Additional fields will be added to the end of this structure. - // -} HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES; - -BOOLEAN __stdcall -HidD_GetAttributes ( - IN HANDLE HidDeviceObject, - OUT PHIDD_ATTRIBUTES Attributes - ); - -BOOLEAN __stdcall -HidD_GetSerialNumberString ( - IN HANDLE HidDeviceObject, - OUT PVOID Buffer, - IN ULONG BufferLength - ); - - -BOOLEAN __stdcall -HidD_SetFeature( - IN HANDLE HidDeviceObject, - IN PVOID ReportBuffer, - IN ULONG ReportBufferLength - ); - -BOOLEAN __stdcall -HidD_GetFeature( - IN HANDLE HidDeviceObject, - OUT PVOID ReportBuffer, - IN ULONG ReportBufferLength - ); - -#include - -#endif - -/* - typedef for enumeration function called by EnumHidDevices for every - USB HID device. Return non-zero to continue enumeration -*/ -typedef BOOL HidEnumProc( PSP_DEVICE_INTERFACE_DATA deviceInterfaceData, - PSP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData, - void *userData ); - - -/* - call enumProc with enumProcData for every UDB HID device until enumProc - returns zero or all devices have been enumerated. -*/ -void EnumHidDevices( HidEnumProc* enumProc, void *enumProcData ) -{ - GUID hidGUID; - HDEVINFO hardwareDeviceInfoSet; - SP_DEVICE_INTERFACE_DATA deviceInterfaceData; - PSP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData; - ULONG requiredSize; - DWORD index; - DWORD result; - BOOL enumOk; - BOOL continueEnumerating = TRUE; - - /* Get the HID GUID value - used as mask to get list of devices */ - HidD_GetHidGuid( &hidGUID ); - - /* Get a list of devices matching the criteria (hid interface, present) */ - hardwareDeviceInfoSet = SetupDiGetClassDevs( &hidGUID, - NULL, /* no enumerator (global) */ - NULL, /* no top level window */ - (DIGCF_PRESENT | /* Only Devices present */ - DIGCF_DEVICEINTERFACE) ); /* Function class devices. */ - - if( hardwareDeviceInfoSet != INVALID_HANDLE_VALUE ){ - - deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); - - index = 0; - do{ - // enumerate the list and get the interface data - enumOk = SetupDiEnumDeviceInterfaces( hardwareDeviceInfoSet, - NULL, /* infoData */ - &hidGUID, /* interfaceClassGuid */ - index, - &deviceInterfaceData ); - - /* - regarding SetupDiEnumDeviceInterfaces msdn says: - You should first call this function with the MemberIndex parameter set - to zero to obtain the first interface. Then, repeatedly increment - MemberIndex and retrieve an interface until this function fails and - GetLastError returns ERROR_NO_MORE_ITEMS. - - Rather than checking for ERROR_NO_MORE_ITEMS we halt on any error. - */ - - if( enumOk ){ - - /* Get the details with null values to get the required size of the buffer */ - requiredSize = 0; - SetupDiGetDeviceInterfaceDetail( hardwareDeviceInfoSet, - &deviceInterfaceData, - NULL, /* interfaceDetail */ - 0, /* interfaceDetailSize */ - &requiredSize, - 0 ); /* infoData */ - if( requiredSize != 0 ){ - /* Allocate the buffer */ - deviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(requiredSize); - - if( deviceInterfaceDetailData != NULL ){ - deviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); - - /* Fill the buffer with the device details */ - result = SetupDiGetDeviceInterfaceDetail( hardwareDeviceInfoSet, - &deviceInterfaceData, - deviceInterfaceDetailData, - requiredSize, - &requiredSize, - NULL ); - if( result != 0 ){ - - /* call the enumProc */ - continueEnumerating = enumProc( &deviceInterfaceData, deviceInterfaceDetailData, enumProcData ); - - } - - free (deviceInterfaceDetailData); - } - } - - ++index; - } - - }while( enumOk && continueEnumerating ); - - SetupDiDestroyDeviceInfoList (hardwareDeviceInfoSet); - } -} - - -typedef struct{ - DWORD currentIndex; - DWORD deviceIndex; - USHORT vendorId, productId, versionNumber; - int flags; - HANDLE deviceHandle; -} FindHidDeviceEnumData; - - -BOOL FindHidDeviceEnumProc( PSP_DEVICE_INTERFACE_DATA deviceInterfaceData, - PSP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData, - void *userData ) -{ - HANDLE deviceHandle; - HIDD_ATTRIBUTES deviceAttributes; - FindHidDeviceEnumData *data = (FindHidDeviceEnumData*)userData; - - (void) deviceInterfaceData; /* unused parameter */ - - /* Open file on the device */ - deviceHandle = CreateFile( deviceInterfaceDetailData->DevicePath, - GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, /* no SECURITY_ATTRIBUTES structure */ - OPEN_EXISTING, /* No special create flags */ - 0, - NULL ); /* No template file */ - - if( deviceHandle != INVALID_HANDLE_VALUE ){ - - deviceAttributes.Size = sizeof(HIDD_ATTRIBUTES); - if( HidD_GetAttributes( deviceHandle, &deviceAttributes ) == TRUE - && ( !(data->flags & SELECT_VENDOR_ID_FLAG) || deviceAttributes.VendorID == data->vendorId ) - && ( !(data->flags & SELECT_PRODUCT_ID_FLAG) || deviceAttributes.ProductID == data->productId ) - && ( !(data->flags & SELECT_VERSION_NUMBER_FLAG) || deviceAttributes.VersionNumber == data->versionNumber ) ){ - - /* found a device which matches the selection criteria */ - - if( data->currentIndex == data->deviceIndex ){ - - /* found the requested device */ - - data->deviceHandle = deviceHandle; - return FALSE; /* stop enumerating */ - - }else{ - CloseHandle( deviceHandle ); - } - - ++data->currentIndex; - - }else{ - CloseHandle( deviceHandle ); - } - } - - return TRUE; /* continue enumerating */ -} - - -USBHID OpenUSBHID( int index, int vendorId, int productId, int versionNumber, int flags ) -{ - FindHidDeviceEnumData data; - - data.currentIndex = 0; - data.deviceIndex = index; - data.vendorId = (USHORT)vendorId; - data.productId = (USHORT)productId; - data.versionNumber = (USHORT)versionNumber; - data.flags = flags; - data.deviceHandle = INVALID_HANDLE_VALUE; - - EnumHidDevices( FindHidDeviceEnumProc, &data ); - - if( data.deviceHandle == INVALID_HANDLE_VALUE ) - return INVALID_USBHID_VALUE; - else - return (USBHID)data.deviceHandle; -} - - -BOOL DumpHidDeviceInfoEnumProc( PSP_DEVICE_INTERFACE_DATA deviceInterfaceData, - PSP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData, - void *userData ) -{ - HANDLE deviceHandle; - HIDD_ATTRIBUTES deviceAttributes; - wchar_t s[128]; - - (void) deviceInterfaceData; /* unused parameter */ - (void) userData; - - printf( "Device Path: %s\n", deviceInterfaceDetailData->DevicePath ); - - deviceHandle = CreateFile( deviceInterfaceDetailData->DevicePath, - GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, /* no SECURITY_ATTRIBUTES structure */ - OPEN_EXISTING, /* No special create flags */ - 0, - NULL ); /* No template file */ - - if( deviceHandle != INVALID_HANDLE_VALUE ){ - - deviceAttributes.Size = sizeof(HIDD_ATTRIBUTES); - if( HidD_GetAttributes( deviceHandle, &deviceAttributes ) ){ - - printf( "Vendor ID: %d\n", deviceAttributes.VendorID ); - printf( "Product ID: %d\n", deviceAttributes.ProductID ); - printf( "Version Number: %d\n", deviceAttributes.VersionNumber ); - } - - if( HidD_GetSerialNumberString( deviceHandle, s, 128 ) ) - printf( "Serial Number: `%ls' (len:%d, 1st char:%d)\n", s, wcslen(s), s[0] ); - - - CloseHandle( deviceHandle ); - } - - printf( "\n" ); - - return TRUE; /* continue enumerating */ -} - - -void CloseUSBHID( USBHID handle ) -{ - CloseHandle( (HANDLE)handle ); -} - -int ReadUSBHID( USBHID handle, void *dest, int count ) -{ - DWORD bytesRead; - - ReadFile( (HANDLE)handle, dest, count, &bytesRead, 0 ); - - return bytesRead; -} - -int SetUSBHIDFeature( USBHID handle, char *report, int count ) -{ - return HidD_SetFeature( handle, report, count ) == TRUE ? 0 : -EINVAL; -} - -void GetUSBHIDFeature( USBHID handle, char *report, int count ) -{ - return HidD_GetFeature( handle, report, count ) == TRUE ? 0 : -EINVAL; -} diff --git a/6.x/src/p5glove/p5g_mac b/6.x/src/p5glove/p5g_mac deleted file mode 100644 index 14970924..00000000 --- a/6.x/src/p5glove/p5g_mac +++ /dev/null @@ -1,24 +0,0 @@ -#define P5G_BUTTONS #0# -#define P5G_BUTTON_A #1# -#define P5G_BUTTON_B #2# -#define P5G_BUTTON_C #4# -#define P5G_JUSTPUSH #8# -#define P5G_JUSTPU_A #9# -#define P5G_JUSTPU_B #10# -#define P5G_JUSTPU_C #12# -#define P5G_RELEASED #16# -#define P5G_RELSED_A #17# -#define P5G_RELSED_B #18# -#define P5G_RELSED_C #20# -#define P5G_FINGER_INDEX #32# -#define P5G_FINGER_MIDDLE #33# -#define P5G_FINGER_RING #34# -#define P5G_FINGER_PINKY #35# -#define P5G_FINGER_THUMB #36# -#define P5G_DELTA_X #37# -#define P5G_DELTA_Y #38# -#define P5G_DELTA_Z #39# -#define P5G_DELTA_XR #40# -#define P5G_DELTA_YR #41# -#define P5G_DELTA_ZR #42# -#define P5G_ANGLES #43# diff --git a/6.x/src/p5glove/p5glove.c b/6.x/src/p5glove/p5glove.c deleted file mode 100644 index 41a1bab6..00000000 --- a/6.x/src/p5glove/p5glove.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - p5glove.c: - - Copyright (C) 2009 by John ffitch, - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - - /* p5glove.c */ -#include "csdl.h" -#include -#include - -typedef struct { - OPDS h; - /* ------------------------------------- */ - void *thread; - int32_t on; -} P5GLOVEINIT; - -typedef struct { - OPDS h; - MYFLT *res; - MYFLT *kControl; - MYFLT *num; - /* ------------------------------------- */ - uint32_t last; -} P5GLOVE; - -typedef struct { - OPDS h; - MYFLT *iControl; - MYFLT *iMin; - MYFLT *iMax; - MYFLT *num; -} P5GRANGE; - -#define P5G_BUTTONS 0 -#define P5G_BUTTON_A 1 -#define P5G_BUTTON_B 2 -#define P5G_BUTTON_C 4 -#define P5G_JUSTPUSH 8 -#define P5G_JUSTPU_A 9 -#define P5G_JUSTPU_B 10 -#define P5G_JUSTPU_C 12 -#define P5G_RELEASED 16 -#define P5G_RELSED_A 17 -#define P5G_RELSED_B 18 -#define P5G_RELSED_C 20 -#define P5G_FINGER_INDEX 32 -#define P5G_FINGER_MIDDLE 33 -#define P5G_FINGER_RING 34 -#define P5G_FINGER_PINKY 35 -#define P5G_FINGER_THUMB 36 -#define P5G_DELTA_X 37 -#define P5G_DELTA_Y 38 -#define P5G_DELTA_Z 39 -#define P5G_DELTA_XR 40 -#define P5G_DELTA_YR 41 -#define P5G_DELTA_ZR 42 -#define P5G_ANGLES 43 - -//P5Glove myGlove; - - -uintptr_t runp5thread(void *g) -{ - P5Glove *glove = (P5Glove *)g; - while (*glove) { - p5glove_sample(*glove, 0); - } - return 0; -} - -int32_t p5g_deinit(CSOUND *csound, P5GLOVEINIT *p) -{ - p->on = 0; - return pthread_cancel((pthread_t)(p->thread)); -} - -int32_t p5glove_find(CSOUND *csound, P5GLOVEINIT *p) -{ - P5Glove *glove = (P5Glove*)csound->QueryGlobalVariable(csound, "p5glove"); - if (glove == NULL) { - csound->CreateGlobalVariable(csound, "p5glove", sizeof(P5Glove)); - glove = (P5Glove*)csound->QueryGlobalVariable(csound, "p5glove"); - } - *glove = p5glove_open(0); - if (UNLIKELY(*glove==NULL)) { - return csound->InitError(csound, "%s", Str("unable to open p5glove\n")); - } - p->on = 1; - csound->RegisterDeinitCallback(csound, p, - (int32_t (*)(CSOUND *, void *)) p5g_deinit); - p->thread = csound->CreateThread(runp5thread, glove); - return OK; -} - -int32_t p5glove_poll(CSOUND *csound, P5GLOVE *p) -{ - /* P5Glove *glove = (P5Glove*)csound->QueryGlobalVariable(csound,"p5glove"); */ - /* int32_t res; */ - /* if (glove == NULL) */ - /* return csound->PerfError(csound, &p->h, */ - /* Str("No glove open")); */ - /* res = p5glove_sample(*glove, -1); */ - /* if (res < 0 && errno == EAGAIN) return OK; */ - /* //res = p5glove_sample(*glove, -1); */ - /* if (UNLIKELY(res < 0)) */ - /* return csound->PerfError(csound, &p->h, */ - /* Str("P5Glove failure")); */ - return OK; -} - -int32_t p5glove_closer(CSOUND *csound, P5GLOVE *p) -{ - P5Glove *glove = (P5Glove*)csound->QueryGlobalVariable(csound, "p5glove"); - if (glove==NULL) return NOTOK; - printf("Closer called\n"); - p5glove_close(*glove); - *glove = NULL; - csound->DestroyGlobalVariable(csound, "p5glove"); - return OK; -} - -int32_t p5g_data_init(CSOUND *csound, P5GLOVE *p) -{ - /* P5Glove p5g; */ - /* p5g = (P5Glove)csound->QueryGlobalVariable(csound, "p5glove"); */ - /* if (UNLIKELY(p5g==NULL)) */ - /* return csound->InitError(csound, Str("No p5glove open")); */ - p->last = 0; - return OK; -} - -int32_t p5g_data(CSOUND *csound, P5GLOVE *p) -{ - P5Glove *glove = (P5Glove*)csound->QueryGlobalVariable(csound, "p5glove"); - int32_t kontrol = (int)(*p->kControl+FL(0.5)); - uint32_t buttons, just, rels; - if (glove==NULL) - csound->PerfError(csound, &p->h, "%s", Str("No open glove")); - p5glove_get_buttons(*glove,&buttons); - just = ((!p->last) & buttons); - rels = (p->last & !buttons); - p->last = buttons; - if (kontrol<0) { - printf("debug:\n"); - *p->res = FL(0.0); - return OK; - } - else if (kontrolres = (MYFLT)(buttons); - return OK; - case P5G_BUTTON_A: - *p->res = (MYFLT)(buttons & P5GLOVE_BUTTON_A); - return OK; - case P5G_BUTTON_B: - *p->res = (MYFLT)(buttons & P5GLOVE_BUTTON_B); - return OK; - case P5G_BUTTON_C: - *p->res = (MYFLT)(buttons & P5GLOVE_BUTTON_C); - return OK; - case P5G_JUSTPUSH: - *p->res = (MYFLT)just; - return OK; - case P5G_JUSTPU_A: - *p->res = (MYFLT)(just & P5GLOVE_BUTTON_A); - return OK; - case P5G_JUSTPU_B: - *p->res = (MYFLT)(just & P5GLOVE_BUTTON_B); - return OK; - case P5G_JUSTPU_C: - *p->res = (MYFLT)(just & P5GLOVE_BUTTON_C); - return OK; - case P5G_RELEASED: - *p->res = (MYFLT)rels; - return OK; - case P5G_RELSED_A: - *p->res = (MYFLT)(rels & P5GLOVE_BUTTON_A); - return OK; - case P5G_RELSED_B: - *p->res = (MYFLT)(rels & P5GLOVE_BUTTON_B); - return OK; - case P5G_RELSED_C: - *p->res = (MYFLT)(rels & P5GLOVE_BUTTON_C); - return OK; - default: - *p->res = 0.0; - return NOTOK; - } - } - else if (kontrol<=P5G_FINGER_THUMB) { - double clench; - p5glove_get_finger(*glove,kontrol-P5G_FINGER_INDEX,&clench); - *p->res = (MYFLT)clench; - /* *p->res = (MYFLT)(p5->data.finger[finger]/63.0); */ - return OK; - } - else { - double pos[3], axis[3], angle; - p5glove_get_position(*glove, pos); - p5glove_get_rotation(*glove, &angle, axis); - /* printf("pos: %f %f %f\n", pos[0], pos[1], pos[2]); */ - /* printf("axis: %f %f %f\n", axis[0], axis[1], axis[2]); */ - /* printf("angle: %f\n", angle); */ - switch (kontrol) { - case P5G_DELTA_X: - *p->res = (MYFLT)pos[0]; - return OK; - case P5G_DELTA_Y: - *p->res = (MYFLT)pos[1]; - return OK; - case P5G_DELTA_Z: - *p->res = (MYFLT)pos[2]; - return OK; - case P5G_DELTA_XR: - *p->res = (MYFLT)axis[0]; - return OK; - case P5G_DELTA_YR: - *p->res = (MYFLT)axis[1]; - return OK; - case P5G_DELTA_ZR: - *p->res = (MYFLT)axis[2]; - return OK; - case P5G_ANGLES: - *p->res = (MYFLT)angle; - return OK; - default: - break; - } - } - return NOTOK; -} - -#define S(x) sizeof(x) - -static OENTRY p5g_localops[] = { - {"p5gconnect", S(P5GLOVEINIT), 0, 3, "", "", - (SUBR)p5glove_find, (SUBR)p5glove_poll, NULL, (SUBR)p5glove_closer }, - {"p5gdata", S(P5GLOVE), 0, 3, "k", "k", (SUBR)p5g_data_init, (SUBR)p5g_data } -}; - -LINKAGE_BUILTIN(p5g_localops) diff --git a/6.x/src/py/examples/cabrera/python0.csd b/6.x/src/py/examples/cabrera/python0.csd deleted file mode 100644 index f30512c2..00000000 --- a/6.x/src/py/examples/cabrera/python0.csd +++ /dev/null @@ -1,23 +0,0 @@ - - - -odac - - - -sr=44100 -ksmps=128 -nchnls=2 - -pyinit ;Start python interpreter - -pyruni "print(44100)" - -instr 1 -endin - - - - -i 1 0 0.1 - - \ No newline at end of file diff --git a/6.x/src/py/examples/cabrera/python1.csd b/6.x/src/py/examples/cabrera/python1.csd deleted file mode 100644 index d083c380..00000000 --- a/6.x/src/py/examples/cabrera/python1.csd +++ /dev/null @@ -1,37 +0,0 @@ - - - -odac - - - -sr=44100 -ksmps=128 -nchnls=2 - -pyinit ;Start python interpreter - -pyruni {{ -a = 2 -b = 3 -print("a + b = " + str(a+b)) -}} ;Execute a python script on the header - -instr 1 -pyruni {{a = 6 -b = 5 -print("a + b = " + str(a+b))}} -endin - - -instr 2 -pyruni {{print("a + b = " + str(a+b))}} -endin - - - - - -i 1 0 0.1 -i 2 1 0.1 - - \ No newline at end of file diff --git a/6.x/src/py/examples/cabrera/python2.csd b/6.x/src/py/examples/cabrera/python2.csd deleted file mode 100644 index 60c2398d..00000000 --- a/6.x/src/py/examples/cabrera/python2.csd +++ /dev/null @@ -1,34 +0,0 @@ - - - -odac - - - -sr=44100 -kr=100 -nchnls=2 - -pyinit - -pyruni "a = 0" - -instr 1 - pyrun "a = a + 1" -endin - - -instr 2 - pyruni {{print("a = " + str(a))}} -endin - - - - - -i 1 0 1 ;Adds to a for 1 second -i 2 1 0.1 ;Prints a -i 1 2 1 ;Adds to a for another second -i 2 3 0.1 ;Prints a - - - \ No newline at end of file diff --git a/6.x/src/py/examples/cabrera/python3.csd b/6.x/src/py/examples/cabrera/python3.csd deleted file mode 100644 index 6c393d39..00000000 --- a/6.x/src/py/examples/cabrera/python3.csd +++ /dev/null @@ -1,35 +0,0 @@ - - - -odac - - - -sr=44100 -kr=100 -nchnls=2 - -pyinit - -pyruni "a = 0.0" - -instr 1 - pyrun "a = a + 1" -endin - - -instr 2 -ival pyevali "a" -prints "a = %i\\n", ival -endin - - - - - -i 1 0 1 ;Adds to a for 1 second -i 2 1 0.1 ;Prints a -i 1 2 1 ;Adds to a for another second -i 2 3 0.1 ;Prints a - - - \ No newline at end of file diff --git a/6.x/src/py/examples/cabrera/python4.csd b/6.x/src/py/examples/cabrera/python4.csd deleted file mode 100644 index 252a6250..00000000 --- a/6.x/src/py/examples/cabrera/python4.csd +++ /dev/null @@ -1,35 +0,0 @@ - - - -odac - - - -sr=44100 -kr=100 -nchnls=2 - -pyinit - -pyassigni "a", 0 - -instr 1 - pyrun "a = a + 1" -endin - - -instr 2 -ival pyevali "a" -prints "a = %i\\n", ival -endin - - - - - -i 1 0 1 ;Adds to a for 1 second -i 2 1 0.1 ;Prints a -i 1 2 1 ;Adds to a for another second -i 2 3 0.1 ;Prints a - - - \ No newline at end of file diff --git a/6.x/src/py/examples/cabrera/python5.csd b/6.x/src/py/examples/cabrera/python5.csd deleted file mode 100644 index 3f651170..00000000 --- a/6.x/src/py/examples/cabrera/python5.csd +++ /dev/null @@ -1,32 +0,0 @@ - - - -odac - - - -sr=44100 -kr=100 -nchnls=2 - -pyinit - -pyruni {{ -def average(a,b): - ave = (a + b)/2 - return ave -}} ;Define function "average" - -instr 1 -iave pycall1i "average", p4, p5 -prints "a = %i\\n", iave -endin - - - - - -i 1 0 1 100 200 -i 1 1 1 1000 2000 - - - \ No newline at end of file diff --git a/6.x/src/py/examples/cabrera/pythonlocal.csd b/6.x/src/py/examples/cabrera/pythonlocal.csd deleted file mode 100644 index 915b25e2..00000000 --- a/6.x/src/py/examples/cabrera/pythonlocal.csd +++ /dev/null @@ -1,32 +0,0 @@ - - - -odac - - - -gkprint init 0 - -instr 1 -ivalue init p4 -ktrig changed gkprint -if (ktrig == 1) then - printk 0.5, ivalue -endif -endin - -instr 2 -gkprint init 1 -endin - - - - -; p4 -i 1 0 5 100 -i 1 1 5 200 -i 1 2 5 300 -i 1 3 5 400 - -i 2 3 1 - - diff --git a/6.x/src/py/examples/cabrera/pythonlocal2.csd b/6.x/src/py/examples/cabrera/pythonlocal2.csd deleted file mode 100644 index b31793fa..00000000 --- a/6.x/src/py/examples/cabrera/pythonlocal2.csd +++ /dev/null @@ -1,39 +0,0 @@ - - - -odac - - - -pyinit - -gkprint init 0 - -instr 1 -;assign 4th p-field to local python variable "value" -pylassigni "value", p4 -ktrig changed gkprint - -; If gkprint has changed (i.e. instr 2 was triggered) -; print the value of the local python variable "value" -if (ktrig == 1) then - kvalue pyleval "value" - printk 0.5, kvalue -endif -endin - -instr 2 -gkprint init 1 -endin - - - - -; p4 -i 1 0 5 100 -i 1 1 5 200 -i 1 2 5 300 -i 1 3 5 400 - -i 2 3 1 - - diff --git a/6.x/src/py/examples/ievent.orc b/6.x/src/py/examples/ievent.orc deleted file mode 100644 index 7afac326..00000000 --- a/6.x/src/py/examples/ievent.orc +++ /dev/null @@ -1,33 +0,0 @@ -sr=44100 -kr=4410 -ksmps=10 -nchnls=2 - -giSinusoid ftgen 0, 0, 8192, 10, 1 - -pyinit - -pyruni {{ -import ctcsound -import sys -from random import random -p = _CSOUND_ -print("\\n --> Python version number: {}\\n".format(sys.version_info[0])) -cs = ctcsound.Csound(pointer_=p) -for i in range(800): - cs.scoreEvent('i', [1, i * .2, 0.05, 6.8 + random() * 3, 70.0]) - cs.scoreEvent('i', [1, i * .2, 0.05, 8.8 + random() * 3, 70.0]) -}} - -instr 1 - - iDuration = p3 - iFrequency = cpsoct(p4) - iAmplitude = ampdb(p5) - - aAmplitude linseg iAmplitude, iDuration - 0.01, iAmplitude, 0.002 ,0, 1,0 - aOutput oscili aAmplitude, iFrequency, giSinusoid - - outs aOutput, aOutput - -endin diff --git a/6.x/src/py/examples/pyexect1.py b/6.x/src/py/examples/pyexect1.py deleted file mode 100644 index 4473b85a..00000000 --- a/6.x/src/py/examples/pyexect1.py +++ /dev/null @@ -1 +0,0 @@ -print 'zum' diff --git a/6.x/src/py/examples/pyexect2.py b/6.x/src/py/examples/pyexect2.py deleted file mode 100644 index 5f3789fb..00000000 --- a/6.x/src/py/examples/pyexect2.py +++ /dev/null @@ -1 +0,0 @@ -print 'pa' diff --git a/6.x/src/py/examples/pyexect3.py b/6.x/src/py/examples/pyexect3.py deleted file mode 100644 index 01dd4b78..00000000 --- a/6.x/src/py/examples/pyexect3.py +++ /dev/null @@ -1 +0,0 @@ -print 'zi' diff --git a/6.x/src/py/examples/pyexect4.py b/6.x/src/py/examples/pyexect4.py deleted file mode 100644 index edc17a14..00000000 --- a/6.x/src/py/examples/pyexect4.py +++ /dev/null @@ -1 +0,0 @@ -print 'zut' diff --git a/6.x/src/py/src/pycall-gen.py b/6.x/src/py/src/pycall-gen.py deleted file mode 100644 index 2246c5d6..00000000 --- a/6.x/src/py/src/pycall-gen.py +++ /dev/null @@ -1,249 +0,0 @@ -# -*- coding: utf-8 -*- - -''' -Copyright (C) 2002 Maurizio Umberto Puxeddu, Michael Gogins - -This file is part of Csound. - -The Csound Library is free software; you can redistribute it -and/or modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -Csound is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with Csound; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA -02110-1301 USA - -Modification from BSD sources for strNcpy -Copyright (c) 1998 Todd C. Miller - -Modified for speed -- JPff - -Adapted for Python3 -- François Pinot, 2019 - -Automatically generate opcode structures, methods [and table entries]. Just run it. -''' - -def generate_pycall_common_init_code(f, n, pre, post, rate, triggered=0): - if triggered: - t, T = 't', 'T' - else: - t, T = '', '' - name = 'py%scall%d%s%s_%srate' % (pre, n, post, t, rate) - s = 'static int %s(CSOUND *csound, PYCALL%d%s *p)\n' % (name, n, T) - s += '{\n' - s += ' char command[1024];\n' - s += ' PyObject *result;\n' - s += ' int *py_initialize_done;\n' - s += ' if (UNLIKELY((py_initialize_done =\n' - s += ' csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL ||\n' - s += ' *py_initialize_done == 0)) {\n' - s += ' return NOTOK;\n' - s += ' }\n' - if triggered: - s += ' if (!*p->trigger) {\n' - if n == 0: - pass - if n == 1: - s += ' *p->result = p->oresult;\n' - elif n > 1: - for i in range(n): - s += ' *p->result%d = p->oresult%d;\n' % (i+1, i+1) - s += ' return OK;\n' - s += ' }\n' - print(s, file=f) - -def generate_pycall_common_call_code(f, context, withinit, triggered): - if triggered: - skip = 2 - else: - skip = 1 - s = ' format_call_statement(command, (char*) p->function->data,\n' - s += ' p->INOCOUNT, p->args, %d);\n\n' % skip - if context == 'private': - s += ' result = eval_string_in_given_context(command, 0);\n' - else: - if withinit: - s += ' create_private_namespace_if_needed(&p->h);\n' - s += ' result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead));\n' - print(s, file=f) - -def generate_pycall_exception_handling_code(f, n, pre, post, rate, triggered=0): - s = ' if (UNLIKELY(result == NULL)) {\n' - s += ' return pyErrMsg(p, "python exception");\n' - s += ' }\n' - print(s, file=f) - -def generate_pycall_result_conversion_code(f, n, pre, post, rate, triggered=0): - if triggered: - t, T = 't', 'T' - else: - t, T = '', '' - s = "" - if n == 0: - s += ' if (UNLIKELY(result != Py_None)) {\n' - s += ' return errMsg(p, "callable must return None");\n' - s += ' }\n' - elif n == 1: - s += ' if (UNLIKELY(!PyFloat_Check(result))) {\n' - s += ' return errMsg(p, "callable must return a float");\n' - s += ' }\n' - s += ' else {\n' - s += ' *p->result = PyFloat_AsDouble(result);\n' - if triggered: - s += ' p->oresult = *p->result;\n' - s += ' }\n' - s += ' return OK;\n' - else: - name = 'py%scall%d%s%s_%srate' % (pre, n, post, t, rate) - s += ' if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != %d)) {\n' % n - s += ' return errMsg(p, "callable must return %d values");\n' % n - s += ' }\n' - s += ' else {\n' - for i in range(n): - s += ' *p->result%d = PyFloat_AsDouble(PyTuple_GET_ITEM(result, %d));\n' % (i+1, i) - if triggered: - s += ' p->oresult%d = *p->result%d;\n' % (i+1, i+1) - s += ' }\n' - s += '\n' - s += ' Py_DECREF(result);\n' - s += ' return OK;\n' - s += '}\n' - print(s, file=f) - -def generate_pycall_krate_method(f, n, triggered=0): - generate_pycall_common_init_code(f, n, '', '', 'k', triggered) - generate_pycall_common_call_code(f, 'private', 1, triggered) - generate_pycall_exception_handling_code(f, n, '', '', 'k', triggered) - generate_pycall_result_conversion_code(f, n, '', '', 'k', triggered) - -def generate_pylcall_irate_method(f, n, triggered=0): - if triggered: - t, T = 't', 'T' - else: - t, T = '', '' - name = 'pylcall%d%s_irate' % (n, t) - s = 'static int %s(CSOUND *csound, PYCALL%d%s *p)\n' % (name, n, T) - s += '{\n' - s += ' int *py_initialize_done;\n' - s += ' if (UNLIKELY((py_initialize_done =\n' - s += ' csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL ||\n' - s += ' *py_initialize_done == 0)) {\n' - s += ' return NOTOK;\n' - s += ' }\n' - s += ' create_private_namespace_if_needed(&p->h);\n' - s += ' return OK;\n' - s += '}\n' - print(s, file=f) - -def generate_pylcall_krate_method(f, n, triggered=0): - generate_pycall_common_init_code(f, n, 'l', '', 'k', triggered) - generate_pycall_common_call_code(f, 'global', 0, triggered) - generate_pycall_exception_handling_code(f, n, 'l', '', 'k', triggered) - generate_pycall_result_conversion_code(f, n, 'l', '', 'k', triggered) - -def generate_pylcalli_irate_method(f, n): - generate_pycall_common_init_code(f, n, 'l', 'i', 'i') - generate_pycall_common_call_code(f, 'global', 1, 0) - generate_pycall_exception_handling_code(f, n, 'l', 'i', 'i') - generate_pycall_result_conversion_code(f, n, 'l', 'i', 'i') - -# ---------- - -def generate_pycall_opcode_struct(f, n, triggered=0): - if triggered: - T = 'T' - else: - T = '' - s = 'typedef struct {\n' - s += ' OPDS h;\n' - if n == 1: - s += ' MYFLT *result;\n' - else: - for i in range(n): - s += ' MYFLT *result%d;\n' % (i+1) - if triggered: - s += ' MYFLT *trigger;\n' - s += ' STRINGDAT *function;\n' - s += ' MYFLT *args[VARGMAX-3];\n' - if triggered: - if n == 1: - s += ' MYFLT oresult\n;' - else: - for i in range(n): - s += ' MYFLT oresult%d;\n' % (i+1) - s += '} PYCALL%d%s;\n' % (n, T) - print(s, file=f) - -# -------- - -f = open('pycall.auto.c', 'w') -s = '''/* - * pyx.auto.c - * - * Copyright (C) 2002 Maurizio Umberto Puxeddu, Michael Gogins - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Don't modify this file, it's automatically genetated by pyx-gen.py - */ -''' -print(s, file=f) -for n in range(9): - generate_pycall_krate_method(f, n) - generate_pylcall_irate_method(f, n) - generate_pylcall_krate_method(f, n) - generate_pylcalli_irate_method(f, n) - - generate_pycall_krate_method(f, n, 1) - generate_pylcall_irate_method(f, n, 1) - generate_pylcall_krate_method(f, n, 1) -f.close() - -f = open('pycall.auto.h', 'w') -s = '''/* - * pyx.auto.h - * - * Copyright (C) 2002 Maurizio Umberto Puxeddu, Michael Gogins - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Don't modify this file. It's automatically generated by pyx-gen.py - */ -''' -print(s, file=f) -for n in range(9): - generate_pycall_opcode_struct(f, n) - generate_pycall_opcode_struct(f, n, 1) -f.close() - diff --git a/6.x/src/py/src/pycall.auto.h b/6.x/src/py/src/pycall.auto.h deleted file mode 100644 index 81935c6b..00000000 --- a/6.x/src/py/src/pycall.auto.h +++ /dev/null @@ -1,247 +0,0 @@ -/* - * pyx.auto.h - * - * Copyright (C) 2002 Maurizio Umberto Puxeddu, Michael Gogins - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Don't modify this file. It's automatically generated by pyx-gen.py - */ - -typedef struct { - OPDS h; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; -} PYCALL0; - -typedef struct { - OPDS h; - MYFLT *trigger; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; -} PYCALL0T; - -typedef struct { - OPDS h; - MYFLT *result; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; -} PYCALL1; - -typedef struct { - OPDS h; - MYFLT *result; - MYFLT *trigger; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; - MYFLT oresult -;} PYCALL1T; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; -} PYCALL2; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - MYFLT *trigger; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; - MYFLT oresult1; - MYFLT oresult2; -} PYCALL2T; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - MYFLT *result3; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; -} PYCALL3; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - MYFLT *result3; - MYFLT *trigger; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; - MYFLT oresult1; - MYFLT oresult2; - MYFLT oresult3; -} PYCALL3T; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - MYFLT *result3; - MYFLT *result4; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; -} PYCALL4; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - MYFLT *result3; - MYFLT *result4; - MYFLT *trigger; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; - MYFLT oresult1; - MYFLT oresult2; - MYFLT oresult3; - MYFLT oresult4; -} PYCALL4T; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - MYFLT *result3; - MYFLT *result4; - MYFLT *result5; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; -} PYCALL5; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - MYFLT *result3; - MYFLT *result4; - MYFLT *result5; - MYFLT *trigger; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; - MYFLT oresult1; - MYFLT oresult2; - MYFLT oresult3; - MYFLT oresult4; - MYFLT oresult5; -} PYCALL5T; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - MYFLT *result3; - MYFLT *result4; - MYFLT *result5; - MYFLT *result6; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; -} PYCALL6; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - MYFLT *result3; - MYFLT *result4; - MYFLT *result5; - MYFLT *result6; - MYFLT *trigger; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; - MYFLT oresult1; - MYFLT oresult2; - MYFLT oresult3; - MYFLT oresult4; - MYFLT oresult5; - MYFLT oresult6; -} PYCALL6T; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - MYFLT *result3; - MYFLT *result4; - MYFLT *result5; - MYFLT *result6; - MYFLT *result7; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; -} PYCALL7; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - MYFLT *result3; - MYFLT *result4; - MYFLT *result5; - MYFLT *result6; - MYFLT *result7; - MYFLT *trigger; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; - MYFLT oresult1; - MYFLT oresult2; - MYFLT oresult3; - MYFLT oresult4; - MYFLT oresult5; - MYFLT oresult6; - MYFLT oresult7; -} PYCALL7T; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - MYFLT *result3; - MYFLT *result4; - MYFLT *result5; - MYFLT *result6; - MYFLT *result7; - MYFLT *result8; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; -} PYCALL8; - -typedef struct { - OPDS h; - MYFLT *result1; - MYFLT *result2; - MYFLT *result3; - MYFLT *result4; - MYFLT *result5; - MYFLT *result6; - MYFLT *result7; - MYFLT *result8; - MYFLT *trigger; - STRINGDAT *function; - MYFLT *args[VARGMAX-3]; - MYFLT oresult1; - MYFLT oresult2; - MYFLT oresult3; - MYFLT oresult4; - MYFLT oresult5; - MYFLT oresult6; - MYFLT oresult7; - MYFLT oresult8; -} PYCALL8T; - diff --git a/6.x/src/py/src/pythonhelper.h b/6.x/src/py/src/pythonhelper.h deleted file mode 100644 index 79de5dea..00000000 --- a/6.x/src/py/src/pythonhelper.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * pythonhelper.h - * - * Copyright (C) 2002 Maurizio Umberto Puxeddu - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _pycsound_pythonhelper_h_ -#define _pycsound_pythonhelper_h_ - -#ifdef _DEBUG -# undef _DEBUG -# include -# define _DEBUG -#else -# include -#endif - -/* - I do it because I can't #include in "csoundCore.h". - */ - -#define GETPYLOCAL(ids) ((PyObject *)ids->pylocal) -#define SETPYLOCAL(ids, p) { ids->pylocal = (void *)p; } - -#endif diff --git a/6.x/src/py/src/pythonopcodes.c b/6.x/src/py/src/pythonopcodes.c deleted file mode 100644 index b4796ec0..00000000 --- a/6.x/src/py/src/pythonopcodes.c +++ /dev/null @@ -1,435 +0,0 @@ -/* - * pythonopcodes.c - * - * Copyright (C) 2002 Maurizio Umberto Puxeddu - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifdef _DEBUG -# undef _DEBUG -# include -# define _DEBUG -#else -# include -#endif -#include -#include "csdl.h" -#include "pythonopcodes.h" -#include "pythonhelper.h" - -/* HELPERS */ - -static CS_NOINLINE void create_private_namespace_if_needed(OPDS *o) -{ - if (GETPYLOCAL(o->insdshead) == 0) { - SETPYLOCAL(o->insdshead, PyDict_New()); -#ifdef DEBUG_PY_NAMESPACES - printf("Creating private namespace %p for %p\n", - (void*) GETPYLOCAL(o->insdshead), (void*) o->insdshead); -#endif - } -#ifdef DEBUG_PY_NAMESPACES - else { - printf("Private namespace for %p already allocated at %p\n", - (void*) o->insdshead, (void*) GETPYLOCAL(o->insdshead)); - } -#endif -} - -static void format_call_statement2(char *statement, char *callable, - int argc, MYFLT *argv[], long skip) -{ - int i; - - statement[0] = '\0'; - if (argc-skip > 0) { - snprintf(statement, 1024, "%s(%0.6f", callable, *(argv[skip])); - for (i = skip+1; i < argc; ++i) { - snprintf(statement + strlen(statement), 1024 - strlen(statement), - ", %f", *(argv[i])); - } - // MKG 2014 Jan 29: No linkage for strlcat in py.dll on MinGW. - //strlcat(statement, ")", 1024); - strncat(statement, ")", 1023 - strlen(statement)); statement[1023] = '\0'; - } - else { - snprintf(statement, 1024, "%s()", callable); - } - -} - -static void format_call_statement(char *statement, char *callable, - int argc, MYFLT *argv[], int skip) -{ - int i; - - statement[0] = '\0'; - if (argc > 0) { - snprintf(statement, 1024, "%s(%0.6f", callable, *(argv[0])); - for (i = 1; i < argc - skip; ++i) { - snprintf(statement + strlen(statement), 1024-strlen(statement), - ", %f", *(argv[i])); - } - // MKG 2014 Jan 29: No linkage for strlcat in py.dll on MinGW. - //strlcat(statement, ")", 1024); - strncat(statement, ")", 1023-strlen(statement)); statement[1023] = '\0'; - } - else { - snprintf(statement, 1024, "%s()", callable); - } -} - - -static PyObject * -run_statement_in_given_context(char *string, PyObject *private) -{ - PyObject *module, *public; - - module = PyImport_AddModule("__main__"); - if (module == NULL) { - PyErr_SetString(PyExc_RuntimeError, "couldn't find module __main__"); - return NULL; - } - public = PyModule_GetDict(module); - return PyRun_String(string, Py_file_input, - public, private ? private : public); -} - -static PyObject * -eval_string_in_given_context(char *string, PyObject *private) -{ - PyObject *module, *public; - - module = PyImport_AddModule("__main__"); - if (module == NULL) { - PyErr_SetString(PyExc_RuntimeError, "couldn't find module __main__"); - return NULL; - } - public = PyModule_GetDict(module); - return PyRun_String(string, Py_eval_input, - public, private ? private : public); -} - -static PyObject * -exec_file_in_given_context(CSOUND* cs, char *filename, PyObject *private) -{ - PyObject *result, *module, *public; - char *fullpath; - - fullpath = cs->FindInputFile(cs, filename, NULL); - - module = PyImport_AddModule("__main__"); - if (module == NULL) { - PyErr_SetString(PyExc_RuntimeError, "couldn't find module __main__"); - return NULL; - } - public = PyModule_GetDict(module); - FILE *fd = fopen(fullpath, "r"); - if (!fd) { - PyErr_Format(PyExc_RuntimeError, - "couldn't open script file %s", filename); - return NULL; - } - result = PyRun_File(fd, fullpath, Py_file_input, - public, private ? private : public); - fclose(fd); - return result; -} - -/* ------ OPCODES ------ */ - -static CS_NOINLINE int errMsg(void *p, const char *msg) -{ - CSOUND *csound = ((OPDS*) p)->insdshead->csound; - const char *opname = csound->GetOpcodeName(p); - csound->ErrorMsg(csound, "%s: %s", opname, msg); - - return NOTOK; -} - -static CS_NOINLINE int pyErrMsg(void *p, const char *msg) -{ - CSOUND *csound = ((OPDS*) p)->insdshead->csound; - const char *opname = csound->GetOpcodeName(p); - csound->ErrorMsg(csound, "%s: %s", opname, msg); - PyErr_Print(); - - return NOTOK; -} - -static int pyinit(CSOUND *csound, PYINIT *p) -{ - (void) csound; - (void) p; - int *py_initialize_done; - - if((py_initialize_done = csound->QueryGlobalVariable(csound, - "PY_INITIALIZE")) == NULL){ - csound->CreateGlobalVariable(csound, "PY_INITIALIZE", sizeof(int)); - py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE"); - *py_initialize_done = 0; - } - - if (*py_initialize_done == 0) { - Py_Initialize(); - *py_initialize_done = 1; - } - - PyObject *module = PyImport_AddModule("__main__"); - if (module == NULL) { - PyErr_SetString(PyExc_RuntimeError, "couldn't find module __main__"); - return NOTOK; - } - PyObject *public = PyModule_GetDict(module); - PyObject *csobj = Py_BuildValue("l", (uintptr_t) csound); - PyDict_SetItemString(public, "_CSOUND_", csobj); - return OK; -} - -#include "pyx.auto.c" -#include "pycall.auto.c" - -static int pycalln_krate(CSOUND *csound, PYCALLN *p) -{ - IGN(csound); - int i; - char command[1024]; - PyObject *result; - - - format_call_statement2(command, p->function->data, - p->INOCOUNT-2, p->args, *p->nresult); - result = eval_string_in_given_context(command, 0); - if (result != NULL && PyTuple_Check(result) && - PyTuple_Size(result) == (int) *p->nresult) { - for (i = 0; i < *p->nresult; ++i) - *p->args[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(result, i)); - Py_DECREF(result); - } - else { - return pyErrMsg(p, "ERROR"); - } - return OK; -} - -static int pylcalln_irate(CSOUND *csound, PYCALLN *p) -{ - IGN(csound); - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcalln_krate(CSOUND *csound, PYCALLN *p) -{ - IGN(csound); - int i; - char command[1024]; - PyObject *result; - - format_call_statement2(command, p->function->data, - p->INOCOUNT-2, p->args, *p->nresult); - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result != NULL && PyTuple_Check(result) && - PyTuple_Size(result) == (int) *p->nresult) { - for (i = 0; i < *p->nresult; ++i) - *p->args[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(result, i)); - Py_DECREF(result); - } - else { - return pyErrMsg(p, "ERROR"); - } - return OK; -} - -static int pylcallni_irate(CSOUND *csound, PYCALLN *p) -{ - IGN(csound); - int i; - char command[1024]; - PyObject *result; - - create_private_namespace_if_needed(&p->h); - format_call_statement2(command, p->function->data, - p->INOCOUNT-2, p->args, *p->nresult); - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result != NULL && PyTuple_Check(result) && - PyTuple_Size(result) == (int) *p->nresult) { - for (i = 0; i < *p->nresult; ++i) - *p->args[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(result, i)); - Py_DECREF(result); - } - else { - return pyErrMsg(p, "ERROR"); - } - return OK; -} - - /* PYTHON OPCODES */ - -OENTRY python_localops[] = { - - /* INITIALIZATION */ - -{ "pyinit", sizeof(PYINIT), 0, 1, "", "", (SUBR)pyinit, NULL }, - - /* RUN GROUP */ -{ "pyrun", sizeof(PYRUN), 0, 2, "", "S", NULL, (SUBR)pyrun_krate }, -{ "pyruni", sizeof(PYRUN), 0, 1, "", "S", (SUBR)pyruni_irate }, -{ "pylrun", sizeof(PYRUN), 0, 3, "", "S", - (SUBR)pylrun_irate, (SUBR)pylrun_krate }, -{ "pylruni", sizeof(PYRUN), 0, 1, "", "S", (SUBR)pylruni_irate }, - -{ "pyrunt", sizeof(PYRUNT), 0, 2, "", "kS", NULL, (SUBR)pyrunt_krate }, -{ "pylrunt", sizeof(PYRUNT), 0, 3, "", "kS", - (SUBR)pylrunt_irate, (SUBR)pylrunt_krate }, - - /* EXEC GROUP */ - -{ "pyexec", sizeof(PYEXEC), 0, 2, "", "S", NULL, (SUBR)pyexec_krate }, -{ "pyexeci", sizeof(PYEXEC), 0, 1, "", "S", (SUBR)pyexec_krate }, -{ "pylexec", sizeof(PYEXEC), 0, 3, "", "S", - (SUBR)pylexec_irate, (SUBR)pylexec_krate }, -{ "pylexeci", sizeof(PYEXEC), 0, 1, "", "S", (SUBR)pylexeci_irate }, - -{ "pyexect", sizeof(PYEXECT), 0, 2, "", "kS", NULL, (SUBR)pyexect_krate }, -{ "pylexect", sizeof(PYEXECT), 0, 3, "", "kS", - (SUBR)pylexect_irate, (SUBR)pylexect_krate }, - - /* CALL GROUP */ - -{ "pycall", sizeof(PYCALL0), 0, 2, "" , "Sz", NULL, (SUBR)pycall0_krate }, -{ "pycall1", sizeof(PYCALL1), 0, 2, "k", "Sz", NULL, (SUBR)pycall1_krate }, -{ "pycall2", sizeof(PYCALL2), 0, 2, "kk", "Sz", NULL, (SUBR)pycall2_krate }, -{ "pycall3", sizeof(PYCALL3), 0, 2, "kkk", "Sz", NULL, (SUBR)pycall3_krate }, -{ "pycall4", sizeof(PYCALL4), 0, 2, "kkkk", "Sz", NULL, (SUBR)pycall4_krate }, -{ "pycall5", sizeof(PYCALL5), 0, 2, "kkkkk", "Sz", NULL, (SUBR)pycall5_krate }, -{ "pycall6", sizeof(PYCALL6), 0, 2, "kkkkkk", "Sz", NULL, (SUBR)pycall6_krate }, -{ "pycall7", sizeof(PYCALL7), 0, 2, "kkkkkkk", "Sz", NULL, (SUBR)pycall7_krate }, -{ "pycall8", sizeof(PYCALL8), 0, 2, "kkkkkkkk", "Sz", NULL,(SUBR)pycall8_krate }, - -{ "pycalln", sizeof(PYCALLN), 0, 2, "", "Siz", NULL, (SUBR)pycalln_krate }, - -{ "pycallt", sizeof(PYCALL0T), 0, 2, "" , "kSz", NULL, (SUBR)pycall0t_krate }, -{ "pycall1t", sizeof(PYCALL1T), 0, 2, "k", "kSz", NULL, (SUBR)pycall1t_krate }, -{ "pycall2t", sizeof(PYCALL2T), 0, 2, "kk", "kSz", NULL, (SUBR)pycall2t_krate }, -{ "pycall3t", sizeof(PYCALL3T),0, 2, "kkk", "kSz", NULL, (SUBR)pycall3t_krate }, -{ "pycall4t", sizeof(PYCALL4T), 0, 2, "kkkk", "kSz", NULL, (SUBR)pycall4t_krate }, -{ "pycall5t", sizeof(PYCALL5T), 0, 2, "kkkkk", "kSz", NULL, (SUBR)pycall5t_krate }, -{ "pycall6t", sizeof(PYCALL6T), 0, 2, "kkkkkk", "kSz", NULL,(SUBR)pycall6t_krate }, -{ "pycall7t", sizeof(PYCALL7T), 0, 2, "kkkkkkk","kSz", NULL,(SUBR)pycall7t_krate }, -{ "pycall8t", sizeof(PYCALL8T), 0, 2, "kkkkkkkk","kSz",NULL,(SUBR)pycall8t_krate }, - -#if 0 -{ "pycallnt", sizeof(PYCALLNT), 0, 2, "", "Siz", NULL, (SUBR)pycallnt_krate }, -#endif - -{ "pycalli", sizeof(PYCALL0), 0, 1, "", "Sm", (SUBR)pycall0_krate }, -{ "pycall1i", sizeof(PYCALL1), 0, 1, "i", "Sm", (SUBR)pycall1_krate }, -{ "pycall2i", sizeof(PYCALL2), 0, 1, "ii", "Sm", (SUBR)pycall2_krate }, -{ "pycall3i", sizeof(PYCALL3), 0, 1, "iii", "Sm", (SUBR)pycall3_krate }, -{ "pycall4i", sizeof(PYCALL4), 0, 1, "iiii", "Sm", (SUBR)pycall4_krate }, -{ "pycall5i", sizeof(PYCALL5), 0, 1, "iiiii", "Sm", (SUBR)pycall5_krate }, -{ "pycall6i", sizeof(PYCALL6), 0, 1, "iiiiii", "Sm", (SUBR)pycall6_krate }, -{ "pycall7i", sizeof(PYCALL7), 0, 1, "iiiiiii", "Sm", (SUBR)pycall7_krate }, -{ "pycall8i", sizeof(PYCALL8), 0, 1, "iiiiiiii", "Sm", (SUBR)pycall8_krate }, - -{ "pycallni", sizeof(PYCALLN), 0, 1, "", "Sim", (SUBR)pycalln_krate }, - -{ "pylcall", sizeof(PYCALL0), 0, 3, "" , "Sz", - (SUBR)pylcall0_irate, (SUBR)pylcall0_krate }, -{ "pylcall1", sizeof(PYCALL1), 0, 3, "k", "Sz", - (SUBR)pylcall1_irate, (SUBR)pylcall1_krate }, -{ "pylcall2", sizeof(PYCALL2), 0, 3, "kk", "Sz", - (SUBR)pylcall2_irate, (SUBR)pylcall2_krate }, -{ "pylcall3", sizeof(PYCALL3), 0, 3, "kkk", "Sz", - (SUBR)pylcall3_irate, (SUBR)pylcall3_krate }, -{ "pylcall4", sizeof(PYCALL4), 0, 3, "kkkk", "Sz", - (SUBR)pylcall4_irate, (SUBR)pylcall4_krate }, -{ "pylcall5", sizeof(PYCALL5), 0, 3, "kkkkk", "Sz", - (SUBR)pylcall5_irate, (SUBR)pylcall5_krate }, -{ "pylcall6", sizeof(PYCALL6), 0, 3, "kkkkkk", "Sz", - (SUBR)pylcall6_irate, (SUBR)pylcall6_krate }, -{ "pylcall7", sizeof(PYCALL7), 0, 3, "kkkkkkk", "Sz", - (SUBR)pylcall7_irate, (SUBR)pylcall7_krate }, -{ "pylcall8", sizeof(PYCALL8), 0, 3, "kkkkkkkk", "Sz", - (SUBR)pylcall8_irate, (SUBR)pylcall8_krate }, - -{ "pylcalln", sizeof(PYCALLN), 0, 3, "", "Siz", - (SUBR)pylcalln_irate, (SUBR)pylcalln_krate }, - -{ "pylcallt", sizeof(PYCALL0T), 0, 3, "" , "kSz", - (SUBR)pylcall0t_irate, (SUBR)pylcall0t_krate }, -{ "pylcall1t", sizeof(PYCALL1T), 0, 3, "k", "kSz", - (SUBR)pylcall1t_irate, (SUBR)pylcall1t_krate }, -{ "pylcall2t", sizeof(PYCALL2T), 0, 3, "kk", "kSz", - (SUBR)pylcall2t_irate, (SUBR)pylcall2t_krate }, -{ "pylcall3t", sizeof(PYCALL3T), 0, 3, "kkk", "kSz", - (SUBR)pylcall3t_irate, (SUBR)pylcall3t_krate }, -{ "pylcall4t", sizeof(PYCALL4T), 0, 3, "kkkk", "kSz", - (SUBR)pylcall4t_irate, (SUBR)pylcall4t_krate }, -{ "pylcall5t", sizeof(PYCALL5T), 0, 3, "kkkkk", "kSz", - (SUBR)pylcall5t_irate, (SUBR)pylcall5t_krate }, -{ "pylcall6t", sizeof(PYCALL6T), 0, 3, "kkkkkk", "kSz", - (SUBR)pylcall6t_irate, (SUBR)pylcall6t_krate }, -{ "pylcall7t", sizeof(PYCALL7T), 0, 3, "kkkkkkk", "kSz", - (SUBR)pylcall7t_irate, (SUBR)pylcall7t_krate }, -{ "pylcall8t", sizeof(PYCALL8T), 0, 3, "kkkkkkkk", "kSz", - (SUBR)pylcall8t_irate, (SUBR)pylcall8t_krate }, - -#if 0 -{ "pylcallnt", sizeof(PYCALLNT), 0, 3, "", "Siz", - (SUBR)pylcalln_irate, (SUBR)pylcallnt_krate }, -#endif - -{ "pylcalli", sizeof(PYCALL0), 0, 1, "", "Sm", (SUBR)pylcall0i_irate }, -{ "pylcall1i", sizeof(PYCALL1), 0, 1, "i", "Sm", (SUBR)pylcall1i_irate }, -{ "pylcall2i", sizeof(PYCALL2), 0, 1, "ii", "Sm", (SUBR)pylcall2i_irate }, -{ "pylcall3i", sizeof(PYCALL3), 0, 1, "iii", "Sm", (SUBR)pylcall3i_irate }, -{ "pylcall4i", sizeof(PYCALL4), 0, 1, "iiii", "Sm", (SUBR)pylcall4i_irate }, -{ "pylcall5i", sizeof(PYCALL5), 0, 1, "iiiii", "Sm", (SUBR)pylcall5i_irate }, -{ "pylcall6i", sizeof(PYCALL6), 0, 1, "iiiiii", "Sm", (SUBR)pylcall6i_irate }, -{ "pylcall7i", sizeof(PYCALL7), 0, 1, "iiiiiii", "Sm", (SUBR)pylcall7i_irate }, -{ "pylcall8i", sizeof(PYCALL8), 0, 1, "iiiiiiii", "Sm", (SUBR)pylcall8i_irate }, - -{ "pylcallni", sizeof(PYCALLN), 0, 1, "", "Sim", (SUBR)pylcallni_irate }, - - /* EVAL GROUP */ - -{ "pyeval", sizeof(PYEVAL), 0, 2, "k", "S", NULL, (SUBR)pyeval_krate }, -{ "pyevali", sizeof(PYEVAL), 0, 1, "i", "S", (SUBR)pyeval_krate }, -{ "pyleval", sizeof(PYEVAL), 0, 3, "k", "S", - (SUBR)pyleval_irate, (SUBR)pyleval_krate }, -{ "pylevali", sizeof(PYEVAL), 0, 1, "i", "S", (SUBR)pylevali_irate }, - -{ "pyevalt", sizeof(PYEVALT), 0, 2, "k", "S", NULL, (SUBR)pyevalt_krate }, -{ "pylevalt", sizeof(PYEVALT), 0, 3, "k", "S", - (SUBR)pylevalt_irate, (SUBR)pylevalt_krate }, - - /* ASSIGN GROUP */ - -{ "pyassign", sizeof(PYASSIGN), 0, 2, "", "Sz", NULL, (SUBR)pyassign_krate }, -{ "pyassigni", sizeof(PYASSIGN), 0, 1, "", "Sz", (SUBR)pyassign_krate }, -{ "pylassign", sizeof(PYASSIGN), 0, 3, "", "Sz", - (SUBR)pylassign_irate, (SUBR)pylassign_krate }, -{ "pylassigni", sizeof(PYASSIGN), 0, 1, "", "Sz", (SUBR)pylassigni_irate }, - -{ "pyassignt", sizeof(PYASSIGNT), 0, 2, "", "Sz", NULL, (SUBR)pyassignt_krate }, -{ "pylassignt", sizeof(PYASSIGNT), 0, 3, "", "Sz", - (SUBR)pylassignt_irate, (SUBR)pylassignt_krate }, - -}; - -LINKAGE_BUILTIN(python_localops) diff --git a/6.x/src/py/src/pythonopcodes.h b/6.x/src/py/src/pythonopcodes.h deleted file mode 100644 index 82d7d216..00000000 --- a/6.x/src/py/src/pythonopcodes.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * pythonopcodes.h - * - * Copyright (C) 2002 Maurizio Umberto Puxeddu - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _pycsound_pythonopcodes_h_ -#define _pycsound_pythonopcodes_h_ - -#ifdef _DEBUG -# undef _DEBUG -# include -# define _DEBUG -#else -# include -#endif -#include "csdl.h" -#include "pyx.auto.h" -#include "pycall.auto.h" - -typedef struct { - OPDS h; -} PYINIT; - -typedef struct { - OPDS h; - STRINGDAT *function; - MYFLT *nresult; - MYFLT *args[VARGMAX]; -} PYCALLN; - -#endif /* _pycsound_pythonopcodes_h_ */ - diff --git a/6.x/src/py/src/pyx-gen.py b/6.x/src/py/src/pyx-gen.py deleted file mode 100644 index d1e54ce9..00000000 --- a/6.x/src/py/src/pyx-gen.py +++ /dev/null @@ -1,257 +0,0 @@ -# -*- coding: utf-8 -*- - -''' -Copyright (C) 2002 Maurizio Umberto Puxeddu, Michael Gogins - -This file is part of Csound. - -The Csound Library is free software; you can redistribute it -and/or modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -Csound is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with Csound; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA -02110-1301 USA - -Modification from BSD sources for strNcpy -Copyright (c) 1998 Todd C. Miller - -Modified for speed -- JPff - -Adapted for Python3 -- François Pinot, 2019 - -Automatically generate opcode structures, methods [and table entries]. Just run it. -''' - -def generate_x_method(f, action, context, rate0, triggered): - if rate0 != 'k': - rate = rate0 - else: - rate = '' - - if action in ('exec', 'assign', 'eval'): - size = 1024 - elif action == 'run': - size = 40960 - else: - raise 'undefined action %s' % action - - if action in ('run', 'assign'): - helper = 'run_statement' - elif action == 'exec': - helper = 'exec_file' - elif action == 'eval': - helper = 'eval_string' - else: - raise 'undefined action %s' % action - - if context == 'private': - prefix = 'l' - ns = 'GETPYLOCAL(p->h.insdshead)' - elif context == 'global': - prefix = '' - ns = '0' - prepare = '' - else: - raise 'undefined context %s' % context - - if triggered: - if rate == 'i': raise 'cannot be triggered at i-rate' - t, T = 't', 'T' - else: - t, T = '', '' - - ACTION = action.upper() - RATE = rate.upper() - - name = 'py%(prefix)s%(action)s%(rate)s%(t)s_%(rate0)srate' % locals() - - s = 'static int %(name)s(CSOUND *csound, PY%(ACTION)s%(T)s *p)\n' % locals() - s += '{\n' - s += ' char source[%d];\n' % size - s += ' PyObject *result;\n' - s += ' int *py_initialize_done;\n' - s += ' if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||\n' - s += ' *py_initialize_done == 0) {\n' - s += ' return NOTOK;\n' - s += ' }\n\n' - - if triggered: - if action == 'eval': - s += ' if (!*p->trigger) {\n' - s += ' *p->result = p->oresult;\n' - s += ' return OK;\n' - s += ' }\n' - else: - s += ' if (!*p->trigger) {\n' - s += ' return OK;\n' - s += ' }\n' - - if context == 'private' and rate0 == 'i': - s += ' create_private_namespace_if_needed(&p->h);\n\n' - - if action == 'assign': - s += ' snprintf(source, %d, "%%s = %%f", (char*) p->string->data, *p->value);\n' % size - else: - s += " strNcpy(source, (char*) p->string->data, %d); // source[%d] = '\\0'\n\n" % (size, size-1) - - if action == 'exec': - s += ' result = %(helper)s_in_given_context(csound, source, %(ns)s);\n' % locals() - else: - s += ' result = %(helper)s_in_given_context(source, %(ns)s);\n' % locals() - s += ' if (result == NULL) {\n' - s += ' return pyErrMsg(p, "python exception");\n' - s += ' }\n' - - if action == 'eval': - s += ' else if (!PyFloat_Check(result)) {\n' - s += ' errMsg(p, "expression must evaluate in a float");\n' - s += ' }\n' - s += ' else {\n' - s += ' *p->result = PyFloat_AsDouble(result);\n' - if triggered: - s += ' p->oresult = *p->result;\n' - s += ' }\n' - - s += ' Py_DECREF(result);\n' - s += ' return OK;\n' - s += '}\n' - print(s, file=f) - -def generate_init_method(f, action, triggered): - ACTION = action.upper() - if triggered: - t, T = 't', 'T' - else: - t, T = '', '' - s = 'static int pyl%(action)s%(t)s_irate(CSOUND *csound, PY%(ACTION)s%(T)s *p)\n' % locals() - s += '{\n' - s += ' int *py_initialize_done;\n' - s += ' if((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||\n' - s += ' *py_initialize_done == 0) {\n' - s += ' return NOTOK;\n' - s += ' }\n' - s += ' create_private_namespace_if_needed(&p->h);\n' - s += ' return OK;\n' - s += '}\n' - print(s, file=f) - -# ---------------- - -def generate_pycall_opcode_struct(f, action, triggered): - ACTION = action.upper() - if triggered: - T = 'T' - else: - T = '' - s = 'typedef struct {\n' - s += ' OPDS h;\n' - if action == 'eval': - s += ' MYFLT *result;\n' - if triggered: - s += ' MYFLT *trigger;\n' - s += ' STRINGDAT *string;\n' - if action == 'assign': - s += ' MYFLT *value;\n' - if action == 'eval' and triggered: - s += ' MYFLT oresult;\n' - s += '} PY%(ACTION)s%(T)s;\n' % locals() - print(s, file=f) - -f = open('pyx.auto.c', 'w') -s = '''/* - * pyx.auto.c - * - * Copyright (C) 2002 Maurizio Umberto Puxeddu, Michael Gogins - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Don't modify this file, it's automatically genetated by pyx-gen.py - */ - -char *strNcpy(char *dst, const char *src, size_t siz) -{ - char *d = dst; - const char *s = src; - size_t n = siz; - - /* Copy as many bytes as will fit or until NULL */ - if (n != 0) { - while (--n != 0) { - if ((*d++ = *s++) == '\\0') - break; - } - } - - /* Not enough room in dst, add NUL */ - if (n == 0) { - if (siz != 0) - *d = '\\0'; /* NUL-terminate dst */ - - //while (*s++) ; - } - return dst; /* count does not include NUL */ -} -''' -print(s, file=f) -for action in ['exec', 'run', 'eval', 'assign']: - generate_x_method(f, action, 'global', 'k', 0) - generate_x_method(f, action, 'global', 'i', 0) - - generate_init_method(f, action, 0) - generate_x_method(f, action, 'private', 'k', 0) - generate_x_method(f, action, 'private', 'i', 0) - - generate_x_method(f, action, 'global', 'k', 1) - generate_init_method(f, action, 1) - generate_x_method(f, action, 'private', 'k', 1) -f.close() - -f = open('pyx.auto.h', 'w') -s = '''/* - * pyx.auto.h - * - * Copyright (C) 2002 Maurizio Umberto Puxeddu, Michael Gogins - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Don't modify this file. It's automatically generated by pyx-gen.py - */ -''' -print(s, file=f) -for action in ['exec', 'run', 'eval', 'assign']: - for triggered in [0, 1]: - generate_pycall_opcode_struct(f, action, triggered) -f.close() - diff --git a/6.x/src/py/src/pyx.auto.h b/6.x/src/py/src/pyx.auto.h deleted file mode 100644 index 4744dcfd..00000000 --- a/6.x/src/py/src/pyx.auto.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * pyx.auto.h - * - * Copyright (C) 2002 Maurizio Umberto Puxeddu, Michael Gogins - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Don't modify this file. It's automatically generated by pyx-gen.py - */ - -typedef struct { - OPDS h; - STRINGDAT *string; -} PYEXEC; - -typedef struct { - OPDS h; - MYFLT *trigger; - STRINGDAT *string; -} PYEXECT; - -typedef struct { - OPDS h; - STRINGDAT *string; -} PYRUN; - -typedef struct { - OPDS h; - MYFLT *trigger; - STRINGDAT *string; -} PYRUNT; - -typedef struct { - OPDS h; - MYFLT *result; - STRINGDAT *string; -} PYEVAL; - -typedef struct { - OPDS h; - MYFLT *result; - MYFLT *trigger; - STRINGDAT *string; - MYFLT oresult; -} PYEVALT; - -typedef struct { - OPDS h; - STRINGDAT *string; - MYFLT *value; -} PYASSIGN; - -typedef struct { - OPDS h; - MYFLT *trigger; - STRINGDAT *string; - MYFLT *value; -} PYASSIGNT; - diff --git a/6.x/src/stk/Android/jni/Android.mk b/6.x/src/stk/Android/jni/Android.mk deleted file mode 100644 index 71dfc3bb..00000000 --- a/6.x/src/stk/Android/jni/Android.mk +++ /dev/null @@ -1,106 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -CSOUND_SRC_ROOT := ../../../.. - -LOCAL_MODULE := libstk - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../stk/include $(LOCAL_PATH)/../../stk/src $(LOCAL_PATH)/../../../../Engine $(LOCAL_PATH)/../../../../H $(LOCAL_PATH)/../../../../include $(LOCAL_PATH)/../../../.. $(LOCAL_PATH)/../../../ $(NDK_MODULE_PATH)/libsndfile-android/jni $(LOCAL_PATH)/../../../CsoundAndroid/jni -LOCAL_CFLAGS := -O3 -D__BUILDING_LIBCSOUND -DENABLE_NEW_PARSER -DLINUX -DHAVE_DIRENT_H -DHAVE_FCNTL_H -DHAVE_UNISTD_H -DHAVE_STDINT_H -DHAVE_SYS_TIME_H -DHAVE_SYS_TYPES_H -DHAVE_TERMIOS_H -# Might need this: -DDEFAULT_RAWWAVE_PATH=${DEFAULT_STK_RAWWAVE_PATH} -LOCAL_CPPFLAGS :=$(LOCAL_CFLAGS) -LOCAL_CPPFLAGS += -std=c++11 -pthread -frtti -fexceptions -LOCAL_LDFLAGS += -Wl,--export-dynamic -### - -# OMIT: -# src/InetWvIn.cpp src/InetWvOut.cpp -# src/Mutex.cpp src/RtAudio.cpp -# src/RtMidi.cpp -# src/RtWvIn.cpp src/RtWvOut.cpp -# src/Socket.cpp src/TcpClient.cpp -# src/TcpServer.cpp src/Thread.cpp -# src/UdpSocket.cpp) - -LOCAL_SRC_FILES := $(CSOUND_SRC_ROOT)/Opcodes/stk/stkOpcodes.cpp \ - ../../stk/src/ADSR.cpp \ - ../../stk/src/Asymp.cpp \ - ../../stk/src/BandedWG.cpp \ - ../../stk/src/BeeThree.cpp \ - ../../stk/src/BiQuad.cpp \ - ../../stk/src/Blit.cpp \ - ../../stk/src/BlitSaw.cpp \ - ../../stk/src/BlitSquare.cpp \ - ../../stk/src/BlowBotl.cpp \ - ../../stk/src/BlowHole.cpp \ - ../../stk/src/Bowed.cpp \ - ../../stk/src/Brass.cpp \ - ../../stk/src/Chorus.cpp \ - ../../stk/src/Clarinet.cpp \ - ../../stk/src/DelayA.cpp \ - ../../stk/src/Delay.cpp \ - ../../stk/src/DelayL.cpp \ - ../../stk/src/Drummer.cpp \ - ../../stk/src/Echo.cpp \ - ../../stk/src/Envelope.cpp \ - ../../stk/src/FileLoop.cpp \ - ../../stk/src/FileRead.cpp \ - ../../stk/src/FileWrite.cpp \ - ../../stk/src/FileWvIn.cpp \ - ../../stk/src/FileWvOut.cpp \ - ../../stk/src/Fir.cpp \ - ../../stk/src/Flute.cpp \ - ../../stk/src/FM.cpp \ - ../../stk/src/FMVoices.cpp \ - ../../stk/src/FormSwep.cpp \ - ../../stk/src/FreeVerb.cpp \ - ../../stk/src/Granulate.cpp \ - ../../stk/src/Guitar.cpp \ - ../../stk/src/HevyMetl.cpp \ - ../../stk/src/Iir.cpp \ - ../../stk/src/JCRev.cpp \ - ../../stk/src/LentPitShift.cpp \ - ../../stk/src/Mandolin.cpp \ - ../../stk/src/Mesh2D.cpp \ - ../../stk/src/Messager.cpp \ - ../../stk/src/MidiFileIn.cpp \ - ../../stk/src/ModalBar.cpp \ - ../../stk/src/Modal.cpp \ - ../../stk/src/Modulate.cpp \ - ../../stk/src/Moog.cpp \ - ../../stk/src/Noise.cpp \ - ../../stk/src/NRev.cpp \ - ../../stk/src/OnePole.cpp \ - ../../stk/src/OneZero.cpp \ - ../../stk/src/PercFlut.cpp \ - ../../stk/src/Phonemes.cpp \ - ../../stk/src/PitShift.cpp \ - ../../stk/src/Plucked.cpp \ - ../../stk/src/PoleZero.cpp \ - ../../stk/src/PRCRev.cpp \ - ../../stk/src/Resonate.cpp \ - ../../stk/src/Rhodey.cpp \ - ../../stk/src/Sampler.cpp \ - ../../stk/src/Saxofony.cpp \ - ../../stk/src/Shakers.cpp \ - ../../stk/src/Simple.cpp \ - ../../stk/src/SineWave.cpp \ - ../../stk/src/SingWave.cpp \ - ../../stk/src/Sitar.cpp \ - ../../stk/src/Skini.cpp \ - ../../stk/src/Sphere.cpp \ - ../../stk/src/StifKarp.cpp \ - ../../stk/src/Stk.cpp \ - ../../stk/src/TapDelay.cpp \ - ../../stk/src/TubeBell.cpp \ - ../../stk/src/Twang.cpp \ - ../../stk/src/TwoPole.cpp \ - ../../stk/src/TwoZero.cpp \ - ../../stk/src/Voicer.cpp \ - ../../stk/src/VoicForm.cpp \ - ../../stk/src/Whistle.cpp \ - ../../stk/src/Wurley.cpp - -include $(BUILD_SHARED_LIBRARY) - diff --git a/6.x/src/stk/Android/jni/Application.mk b/6.x/src/stk/Android/jni/Application.mk deleted file mode 100644 index a3c7dd41..00000000 --- a/6.x/src/stk/Android/jni/Application.mk +++ /dev/null @@ -1,9 +0,0 @@ -APP_ABI := armeabi-v7a arm64-v8a -APP_CPPFLAGS += -fexceptions -frtti -APP_OPTIM := release -APP_PLATFORM := android-21 -#APP_STL := gnustl_shared -#NDK_TOOLCHAIN_VERSION := 4.9 -APP_STL := c++_shared -NDK_TOOLCHAIN_VERSION := clang -APP_MODULES := stk diff --git a/6.x/src/stk/CMakeLists.txt b/6.x/src/stk/CMakeLists.txt deleted file mode 100644 index 24d006db..00000000 --- a/6.x/src/stk/CMakeLists.txt +++ /dev/null @@ -1,96 +0,0 @@ -option(BUILD_STK_OPCODES "Build the stk opcodes" ON) - -if(BUILD_STK_OPCODES) - if(DEFAULT_STK_RAWWAVE_PATH) - set(rawwave_path "-DDEFAULT_RAWWAVE_PATH=\"${DEFAULT_STK_RAWWAVE_PATH}\"") - endif() - - if(USE_VCPKG) - make_plugin(stkops stkOpcodes.cpp) - find_package(unofficial-libstk CONFIG REQUIRED) - target_link_libraries(stkops PRIVATE unofficial::libstk::libstk) - target_include_directories(stkops PRIVATE ${CSOUND_INCLUDE_DIRS}) - message(STATUS "Building STK opcodes for MSVC") - else() - find_package(STK) - - if(STK_LIBRARY) - find_path(STK_INCLUDE_DIR Stk.h - /usr/include/stk - /usr/local/include/stk) - - check_deps(BUILD_STK_OPCODES STK_INCLUDE_DIR) - - if(STK_INCLUDE_DIR) - make_plugin(stkops stkOpcodes.cpp) - target_include_directories(stkops PRIVATE ${CSOUND_INCLUDE_DIRS} ${STK_INCLUDE_DIR}) - message(STATUS "Building STK opcodes.") - - if(BUILD_STATIC_LIBRARY) - if(WIN32) - add_library(stk STATIC IMPORTED) - set_target_properties(stk PROPERTIES IMPORTED_LOCATION ${STK_LIBRARY}) - target_link_libraries(stkops stk) - else() - target_link_libraries(stkops ${STK_LIBRARY}) - endif() - else() - target_link_libraries(stkops ${STK_LIBRARIES} ${PTHREAD_LIBRARY}) - endif() - - target_compile_definitions(stkops PRIVATE ${rawwave_path}) - endif() - else() - set(stk_remove_srcs - src/InetWvIn.cpp src/InetWvOut.cpp - src/Mutex.cpp src/RtAudio.cpp - src/RtMidi.cpp src/Messager.cpp - src/RtWvIn.cpp src/RtWvOut.cpp - src/Socket.cpp src/TcpClient.cpp - src/TcpServer.cpp src/Thread.cpp - src/UdpSocket.cpp - ) - - file(GLOB stk_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*) - list(REMOVE_ITEM stk_srcs ${stk_remove_srcs}) - list(APPEND stk_srcs stkOpcodes.cpp) - - # Assume that if this file exists, then we have the sources - find_file(STK_FOUND - NAMES src/InetWvIn.cpp - HINTS ${CMAKE_CURRENT_SOURCE_DIR} - ) - - find_path(STK_INCLUDE_DIR Stk.h ./include) - check_deps(BUILD_STK_OPCODES STK_FOUND STK_INCLUDE_DIR) - - make_plugin(stkops "${stk_srcs}") - target_include_directories(stkops PRIVATE - ${CSOUND_INCLUDE_DIRS} - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_CURRENT_SOURCE_DIR}/include/stk - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - set(stkdefs "-D__STK_REALTIME__") - - if(APPLE) - list(APPEND stkdefs "-D__OS_MACOSX__") - list(REMOVE_ITEM stkdefs "-D__STK_REALTIME__") - elseif(LINUX) - list(APPEND stkdefs "-D__OS_LINUX__") - list(APPEND stkdefs "-D__LINUX_ALSA__") - elseif(WIN32) - list(APPEND stkdefs "-D__OS_WINDOWS__") - endif() - - if(BIG_ENDIAN) - list(APPEND stkdefs "-D__BIG_ENDIAN__") - else() - list(APPEND stkdefs "-D__LITTLE_ENDIAN__") - endif() - - target_compile_definitions(stkops PRIVATE ${stkdefs} ${rawwave_path}) - endif() - endif() -endif() - diff --git a/6.x/src/stk/OpcodeBase.hpp b/6.x/src/stk/OpcodeBase.hpp deleted file mode 100644 index 21ca8a0c..00000000 --- a/6.x/src/stk/OpcodeBase.hpp +++ /dev/null @@ -1,492 +0,0 @@ -/* - OpcodeBase.hpp: - - Copyright (C) 2005, 2009, 2017 by Istva Varga, Victor Lazzarini and - Michael Gogins - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ -#pragma once - -/** - * There is a conflict between the preprocessor definition "_CR" in the - * standard C++ library and in Csound. To work around this, undefine "_CR" and - * include ALL standard library include files BEFORE including ANY Csound - * include files. - */ -#if defined(_CR) -#undef _CR -#endif - -#include -#include -#include -#if !(defined(__wasi__)) -#include -#endif -#include -#include -#include -#include - -/** - * Template base class, or pseudo-virtual base class, - * for writing Csound opcodes in C++. - * Derive opcode implementation classes like this: - * - * DerivedClass : public OpcodeBase - * { - * public: - * // All output fields must be declared first as MYFLT *: - * MYFLT *aret1; - * // All input fields must be declared next as MYFLT *: - * MYFLT *iarg1; - * MYFLT *karg2; - * MYFLT *aarg3; - * // All internal state variables must be declared after that: - * size_t state1; - * double state2; - * MYFLT state3; - * // If the opcode shares data protect it by creating one or more void - * // *mutex member pointers: - * void *mutex1; - * void *mutex2; - * // and create them usind csound->Create_Mutex() in csoundModuleCreate - * // and destroy them using csound->DeleteMutex(mutex) - * // csoundModuleDestroy, and lock them using LockGuard guard(mutex). - * int init(); - * int kontrol(); - * int audio; - * int noteoff(); - * void deinit(); - * }; - */ - -namespace csound { - -static bool diagnostics_enabled = false; - -/** - * Use this to guard against data races in opcode functions. The mutex should - * be created by csound->Create_Mutex() in csoundModuleCreate(), and should - * be destroyed by csound->DeleteMutex() in csoundModuleDestroy(). - * - * If data is shared between opcode instances, the mutex should be global to - * the opcode library; if data is shared between threads for a single instance, - * the mutex should belong to the opcode instance. - */ -struct LockGuard { - LockGuard(CSOUND *csound_, void *mutex_) : csound(csound_), mutex(mutex_) - { - csound->LockMutex(mutex); - } - ~LockGuard() - { - csound->UnlockMutex(mutex); - } - CSOUND *csound; - void *mutex; -}; - -/** - * Use this to store a pointer to a global heap-allocated object, e.g. one - * used to manage state between opcode instances. - */ - -template int CreateGlobalPointer(CSOUND *csound, const char *name, T *pointer) -{ - T **pointer_to_pointer = 0; - int result = csound->CreateGlobalVariable(csound, name, sizeof(pointer_to_pointer)); - pointer_to_pointer = static_cast(csound->QueryGlobalVariable(csound, name)); - *pointer_to_pointer = pointer; - return result; -} - -/** - * Retrieve a pointer to a global heap-allocated object, e.g. one - * used to manage state between opcode instances. - */ -template T *QueryGlobalPointer(CSOUND *csound, const char *name, T*& pointer) -{ - T **pointer_to_pointer = static_cast(csound->QueryGlobalVariableNoCheck(csound, name)); - if (pointer_to_pointer != 0) { - pointer = *pointer_to_pointer; - } else { - pointer = 0; - } - return pointer; -} - -template -class OpcodeBase -{ -public: - int init(CSOUND *csound) - { - return NOTOK; - } - static int init_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->init(csound); - } - int kontrol(CSOUND *csound) - { - return NOTOK; - } - static int kontrol_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->kontrol(csound); - } - int audio(CSOUND *csound) - { - return NOTOK; - } - static int audio_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->audio(csound); - } - /** - This is how to compute audio signals for normal opcodes: - (1) Zero all frames from 0 up to but not including Offset. - (2) Compute all frames from ksmps_offset up to but not including End. - (3) Zero all frames from End up to but not including ksmps. - Example from a C opcode: - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); - } - for (n = offset; n < nsmps; n++) { - input1 = MYFLT2LRND(p->a[n]); - p->r[n] = (MYFLT) (input1 >> input2); - } - So in C++ it should look like this (which is much easier to understand): - int frameIndex = 0; - for( ; frameIndex < kperiodOffset(); ++frameIndex) { - asignal[frameIndex] = 0; - } - for( ; frameIndex < kperiodEnd(); ++frameIndex) { - asignal[frameIndex] = compute(); - } - for( ; frameIndex < ksmps(); ++frameIndex) { - asignal[frameIndex] = 0; - } - */ - uint32_t kperiodOffset() const - { - return opds.insdshead->ksmps_offset; - } - uint32_t kperiodEnd() const - { - uint32_t end = opds.insdshead->ksmps_no_end; - if (end) { - return end; - } else { - return ksmps(); - } - } - uint32_t ksmps() const - { - return opds.insdshead->ksmps; - } - uint32_t output_arg_count() - { - return (uint32_t)opds.optext->t.outArgCount; - } - uint32_t input_arg_count() - { - return (uint32_t)opds.optext->t.inArgCount; - } - void log(CSOUND *csound, const char *format,...) - { - va_list args; - va_start(args, format); - if(csound) { - csound->MessageV(csound, 0, format, args); - } else { - vfprintf(stdout, format, args); - } - va_end(args); - } - void warn(CSOUND *csound, const char *format,...) - { - if(csound) { - if(csound->GetMessageLevel(csound) & CS_WARNMSG) { - va_list args; - va_start(args, format); - csound->MessageV(csound, CSOUNDMSG_WARNING, format, args); - va_end(args); - } - } else { - va_list args; - va_start(args, format); - vfprintf(stdout, format, args); - va_end(args); - } - } - OPDS opds; -}; - -template -class OpcodeNoteoffBase -{ -public: - int init(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int init_(CSOUND *csound, void *opcode) - { - if (!csound->GetReinitFlag(csound) && !csound->GetTieFlag(csound)) { - csound->RegisterDeinitCallback(csound, opcode, - &OpcodeNoteoffBase::noteoff_); - } - return reinterpret_cast(opcode)->init(csound); - } - int kontrol(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int kontrol_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->kontrol(csound); - } - int audio(CSOUND *csound) - { - IGN(csound); - return NOTOK; - } - static int audio_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->audio(csound); - } - /** - This is how to compute audio signals for normal opcodes: - (1) Zero all frames from 0 up to but not including Offset. - (2) Compute all frames from ksmps_offset up to but not including End. - (3) Zero all frames from End up to but not including ksmps. - Example from a C opcode: - uint32_t offset = p->h.insdshead->ksmps_offset; - uint32_t early = p->h.insdshead->ksmps_no_end; - uint32_t n, nsmps = CS_KSMPS; - if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); - if (UNLIKELY(early)) { - nsmps -= early; - memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); - } - for (n = offset; n < nsmps; n++) { - input1 = MYFLT2LRND(p->a[n]); - p->r[n] = (MYFLT) (input1 >> input2); - } - So in C++ it should look like this (which is much easier to understand): - int frameIndex = 0; - for( ; frameIndex < kperiodOffset(); ++frameIndex) { - asignal[frameIndex] = 0; - } - for( ; frameIndex < kperiodEnd(); ++frameIndex) { - asignal[frameIndex] = compute(); - } - for( ; frameIndex < ksmps(); ++frameIndex) { - asignal[frameIndex] = 0; - } - */ - uint32_t kperiodOffset() const - { - return opds.insdshead->ksmps_offset; - } - uint32_t kperiodEnd() const - { - uint32_t end = opds.insdshead->ksmps_no_end; - if (end) { - return end; - } else { - return ksmps(); - } - } - uint32_t ksmps() const - { - return opds.insdshead->ksmps; - } - uint32_t output_arg_count() - { - return (uint32_t)opds.optext->t.outArgCount; - } - uint32_t input_arg_count() - { - return (uint32_t)opds.optext->t.inArgCount; - } - void log(CSOUND *csound, const char *format,...) - { - va_list args; - va_start(args, format); - if(csound) { - csound->MessageV(csound, 0, format, args); - } else { - vfprintf(stdout, format, args); - } - va_end(args); - } - void warn(CSOUND *csound, const char *format,...) - { - if(csound) { - if(csound->GetMessageLevel(csound) & CS_WARNMSG) { - va_list args; - va_start(args, format); - csound->MessageV(csound, CSOUNDMSG_WARNING, format, args); - va_end(args); - } - } else { - va_list args; - va_start(args, format); - vfprintf(stdout, format, args); - va_end(args); - } - } - int noteoff(CSOUND *csound) - { - return OK; - } - static int noteoff_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->noteoff(csound); - } - OPDS opds; -}; - -#if (__cplusplus >= 201103L) && !(defined(__wasi__)) -#pragma message("Defining heap_object_manager_t.") - -/** - * The memory of non-POD C++ or C objects allocated on the heap by Csound - * plugins is managed not by Csound, but by the plugin module. This class - * performs that function. - * - * As long as all memory is allocated in or after csoundModuleCreate and - * de-allocated in csoundModuleDestroy, all will be well. The danger however - * is that memory leaks will occur if allocations are not matched with - * de-allocations, or worse, that crashes will occur if any objects are - * deleted twice or de-referenced after deletion. - * - * So, the plugin should manage a collection of all heap-allocated objects, - * keyed first off the Csound instance, and second off an object handle; and - * all such objects must be accessed only by handle, from this collection. - * - * In csoundModuleDestroy, all objects for the calling instance of Csound - * should be de-allocated, and the sub-collection for that instance should - * also be de-allocated. - * - * If then there are no more sub-collections for other instances of Csound, - * the entire contents of the collection should be de-allocated. - * - * This should be done as a singleton, and in a thread-safe way. - * - * There might still be a problem if any of the heap-allocated objects, - * themselves, have global static members, perhaps created by some external - * dependency. - * - * Please note, objects O in the declaration below must not be std::shared_ptr - * objects. Deletion of objects herein must be unconditional. Rather, the - * objects passed are raw pointers to instances of class O. - */ - template class heap_object_manager_t { - private: - std::map> objects_; - std::recursive_mutex mutex; - heap_object_manager_t(){}; - ~heap_object_manager_t(){}; - public: - static heap_object_manager_t &instance() { - static heap_object_manager_t singleton; - return singleton; - } - std::map> &objects() { - std::lock_guard lock(mutex); - return objects_; - } - /** - * Returns a list of pointers to all objects allocated for this - * instance of Csound. - */ - std::vector &objects_for_csound(CSOUND *csound) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects()[csound]; - return objects_for_csound_; - } - /** - * Returns the handle for the object; if the object has not yet been - * stored, inserts it into the list of object pointers for this - * instance of Csound; otherwise, returns the handle of the stored - * object pointer. - */ - int handle_for_object(CSOUND *csound, O *object) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - auto iterator = std::find(objects_for_csound_.begin(), objects_for_csound_.end(), object); - if (iterator == objects_for_csound_.end()) { - int handle = objects_for_csound_.size(); - objects_for_csound_.push_back(object); - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::handle_for_object %p: new object handle: %d (of %ld)\n", object, handle, objects_for_csound_.size()); - return handle; - } else { - int handle = static_cast(iterator - objects_for_csound_.begin()); - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::handle_for_object: existing object handle: %d\n", handle); - return handle; - } - } - /** - * Returns the object pointer for the handle; - * if the object pointer has not been stored by - * handle, returns a null pointer. - */ - O *object_for_handle(CSOUND *csound, int handle) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - if (handle >= objects_for_csound_.size()) { - return nullptr; - } - O *object = objects_for_csound_[handle]; - if (diagnostics_enabled) std::fprintf(stderr, "heap_object_manager_t::object_for_handle: %p %d (of %ld)\n", object, handle, objects_for_csound_.size()); - return object; - } - /** - * First destroys all objects created by the calling - * instance of Csound, then destroys the list of - * object pointers for this instance of Csound. - */ - void module_destroy(CSOUND *csound) { - std::lock_guard lock(mutex); - auto &objects_for_csound_ = objects_for_csound(csound); - for (int i = 0, n = objects_for_csound_.size(); i < n; ++i) { - delete objects_for_csound_[i]; - objects_for_csound_[i] = nullptr; - } - objects_for_csound_.clear(); - objects().erase(csound); - } -}; - -#else -#pragma message("Not defining heap_manager_t.") -#endif - -} diff --git a/6.x/src/stk/stkOpcodes.cpp b/6.x/src/stk/stkOpcodes.cpp deleted file mode 100644 index f244969b..00000000 --- a/6.x/src/stk/stkOpcodes.cpp +++ /dev/null @@ -1,597 +0,0 @@ -/* - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ -/* - * CSOUND 5/6 OPCODES FOR PERRY COOK'S SYNTHESIS TOOLKIT IN C++ (STK) INSTRUMENT - * - * This code is copyright (C) 2005 by Michael Gogins. It is licensed under the - * same terms as the Synthesis Tookit in C++ by Perry R. Cook and Gary P. - * Scavone. - * - * To compile these opcodes, copy the STK include, src, and rawwaves directories - * to the csound6/Opcodes/stk directory as follows: - * - * csound6/Opcodes/stk/include - * csound6/Opcodes/stk/src - * csound6/Opcodes/stk/rawwaves - * - * To use these opcodes, define a RAWWAVE_PATH environment variable that points - * to your rawwaves directory, which contains raw soundfiles with function table - * data. - * - * All these opcodes are named "STK" + the STK classname, - * e.g. "STKBowed" for the Bowed instrument. - * - * All the STK opcodes have the same signature: - * - * aout STKName ifrequency igain {kcontroller0, kvalue1,...,kcontroller3, - * kvalue3} - * - * They take a frequency in Hertz and a gain parameter in the range [0, 1], - * plus up to four optional krate controller-value pairs, and return an arate - * signal that should be more or less in the range [-1, +1]. - * See the STK class documentation to determine the controller numbers - * used by each instrument. - */ -#if defined(_MSC_VER) -#include "stk\BandedWG.h" -#include "stk\BeeThree.h" -#include "stk\BlowBotl.h" -#include "stk\BlowHole.h" -#include "stk\Bowed.h" -#include "stk\Brass.h" -#include "stk\Clarinet.h" -#include "stk\Drummer.h" -#include "stk\FMVoices.h" -#include "stk\Flute.h" -#include "stk\HevyMetl.h" -#include "stk\Mandolin.h" -#include "stk\Stk.h" - //#include "stk\Mesh2D.h" -#include "stk\ModalBar.h" -#include "stk\Moog.h" -#include "stk\PercFlut.h" -#include "stk\Plucked.h" -#include "stk\Resonate.h" -#include "stk\Rhodey.h" -#include "stk\Saxofony.h" -#include "stk\Shakers.h" -#include "stk\Simple.h" -#include "stk\Sitar.h" -#include "stk\StifKarp.h" -#include "stk\TubeBell.h" -#include "stk\VoicForm.h" -#include "stk\Whistle.h" -#include "stk\Wurley.h" -#else -#include "BandedWG.h" -#include "BeeThree.h" -#include "BlowBotl.h" -#include "BlowHole.h" -#include "Bowed.h" -#include "Brass.h" -#include "Clarinet.h" -#include "Drummer.h" -#include "FMVoices.h" -#include "Flute.h" -#include "HevyMetl.h" -#include "Mandolin.h" -#include "Stk.h" -//#include "Mesh2D.h" -#include "ModalBar.h" -#include "Moog.h" -#include "PercFlut.h" -#include "Plucked.h" -#include "Resonate.h" -#include "Rhodey.h" -#include "Saxofony.h" -#include "Shakers.h" -#include "Simple.h" -#include "Sitar.h" -#include "StifKarp.h" -#include "TubeBell.h" -#include "VoicForm.h" -#include "Whistle.h" -#include "Wurley.h" -#endif -using namespace stk; - -#define __BUILDING_LIBCSOUND -#include -#include - -using namespace csound; - -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace csound; - -template -class STKInstrumentAdapter : public OpcodeBase> { -public: - // Outputs. - MYFLT *aoutput; - // Inputs. - MYFLT *ifrequency; - MYFLT *igain; - MYFLT *kcontroller0; - MYFLT *kvalue0; - MYFLT *kcontroller1; - MYFLT *kvalue1; - MYFLT *kcontroller2; - MYFLT *kvalue2; - MYFLT *kcontroller3; - MYFLT *kvalue3; - MYFLT *kcontroller4; - MYFLT *kvalue4; - MYFLT *kcontroller5; - MYFLT *kvalue5; - MYFLT *kcontroller6; - MYFLT *kvalue6; - MYFLT *kcontroller7; - MYFLT *kvalue7; - // State. - T *instrument; - size_t ksmps; - bool released; - MYFLT oldkcontroller0; - MYFLT oldkvalue0; - MYFLT oldkcontroller1; - MYFLT oldkvalue1; - MYFLT oldkcontroller2; - MYFLT oldkvalue2; - MYFLT oldkcontroller3; - MYFLT oldkvalue3; - MYFLT oldkcontroller4; - MYFLT oldkvalue4; - MYFLT oldkcontroller5; - MYFLT oldkvalue5; - MYFLT oldkcontroller6; - MYFLT oldkvalue6; - MYFLT oldkcontroller7; - MYFLT oldkvalue7; - STKInstrumentAdapter() : instrument(0) {} - int32_t init(CSOUND *csound) { - if (!instrument) { - Stk::setSampleRate(csound->GetSr(csound)); - instrument = new T(); - } - ksmps = OpcodeBase>::opds.insdshead->ksmps; - instrument->noteOn(*ifrequency, *igain); - released = false; - oldkcontroller0 = -1.0; - oldkvalue0 = -1.0; - oldkcontroller1 = -1.0; - oldkvalue1 = -1.0; - oldkcontroller2 = -1.0; - oldkvalue2 = -1.0; - oldkcontroller3 = -1.0; - oldkvalue3 = -1.0; - oldkcontroller4 = -1.0; - oldkvalue4 = -1.0; - oldkcontroller5 = -1.0; - oldkvalue5 = -1.0; - oldkcontroller6 = -1.0; - oldkvalue6 = -1.0; - oldkcontroller7 = -1.0; - oldkvalue7 = -1.0; - return OK; - } - int32_t kontrol(CSOUND *csound) { - uint32_t offset = - OpcodeBase>::opds.insdshead->ksmps_offset; - if (!released) { - if (*kcontroller0 != oldkcontroller0 || *kvalue0 != oldkvalue0) { - instrument->controlChange(static_cast(*kcontroller0), *kvalue0); - oldkcontroller0 = *kcontroller0; - oldkvalue0 = *kvalue0; - } - if (*kcontroller1 != oldkcontroller1 || *kvalue1 != oldkvalue1) { - instrument->controlChange(static_cast(*kcontroller1), *kvalue1); - oldkcontroller1 = *kcontroller1; - oldkvalue1 = *kvalue1; - } - if (*kcontroller2 != oldkcontroller2 || *kvalue2 != oldkvalue2) { - instrument->controlChange(static_cast(*kcontroller2), *kvalue2); - oldkcontroller2 = *kcontroller2; - oldkvalue2 = *kvalue2; - } - if (*kcontroller3 != oldkcontroller3 || *kvalue3 != oldkvalue3) { - instrument->controlChange(static_cast(*kcontroller3), *kvalue3); - oldkcontroller3 = *kcontroller3; - oldkvalue3 = *kvalue3; - } - if (*kcontroller4 != oldkcontroller4 || *kvalue4 != oldkvalue4) { - instrument->controlChange(static_cast(*kcontroller4), *kvalue4); - oldkcontroller4 = *kcontroller4; - oldkvalue4 = *kvalue4; - } - if (*kcontroller5 != oldkcontroller5 || *kvalue5 != oldkvalue5) { - instrument->controlChange(static_cast(*kcontroller5), *kvalue5); - oldkcontroller5 = *kcontroller5; - oldkvalue5 = *kvalue5; - } - if (*kcontroller6 != oldkcontroller6 || *kvalue6 != oldkvalue6) { - instrument->controlChange(static_cast(*kcontroller6), *kvalue6); - oldkcontroller6 = *kcontroller6; - oldkvalue6 = *kvalue6; - } - if (*kcontroller7 != oldkcontroller7 || *kvalue7 != oldkvalue7) { - instrument->controlChange(static_cast(*kcontroller7), *kvalue7); - oldkcontroller7 = *kcontroller7; - oldkvalue7 = *kvalue7; - } - memset(aoutput, '\0', offset * sizeof(MYFLT)); - for (size_t i = offset; i < ksmps; i++) { - aoutput[i] = instrument->tick(); - } - } else { - // memset(aoutput, 0, ksmps*sizeof(MYFLT)); - for (size_t i = 0; i < ksmps; i++) { - aoutput[i] = 0; - } - } - return OK; - } -}; - -template -class STKInstrumentAdapter1 : public OpcodeBase> { -public: - // Outputs. - MYFLT *aoutput; - // Inputs. - MYFLT *ifrequency; - MYFLT *igain; - MYFLT *kcontroller0; - MYFLT *kvalue0; - MYFLT *kcontroller1; - MYFLT *kvalue1; - MYFLT *kcontroller2; - MYFLT *kvalue2; - MYFLT *kcontroller3; - MYFLT *kvalue3; - MYFLT *kcontroller4; - MYFLT *kvalue4; - MYFLT *kcontroller5; - MYFLT *kvalue5; - MYFLT *kcontroller6; - MYFLT *kvalue6; - MYFLT *kcontroller7; - MYFLT *kvalue7; - // State. - T *instrument; - size_t ksmps; - bool released; - MYFLT oldkcontroller0; - MYFLT oldkvalue0; - MYFLT oldkcontroller1; - MYFLT oldkvalue1; - MYFLT oldkcontroller2; - MYFLT oldkvalue2; - MYFLT oldkcontroller3; - MYFLT oldkvalue3; - MYFLT oldkcontroller4; - MYFLT oldkvalue4; - MYFLT oldkcontroller5; - MYFLT oldkvalue5; - MYFLT oldkcontroller6; - MYFLT oldkvalue6; - MYFLT oldkcontroller7; - MYFLT oldkvalue7; - STKInstrumentAdapter1() : instrument(0) {} - int32_t init(CSOUND *csound) { - if (!instrument) { - Stk::setSampleRate(csound->GetSr(csound)); - instrument = new T((StkFloat)10.0); - } - ksmps = OpcodeBase>::opds.insdshead->ksmps; - instrument->noteOn(*ifrequency, *igain); - released = false; - oldkcontroller0 = -1.0; - oldkvalue0 = -1.0; - oldkcontroller1 = -1.0; - oldkvalue1 = -1.0; - oldkcontroller2 = -1.0; - oldkvalue2 = -1.0; - oldkcontroller3 = -1.0; - oldkvalue3 = -1.0; - oldkcontroller4 = -1.0; - oldkvalue4 = -1.0; - oldkcontroller5 = -1.0; - oldkvalue5 = -1.0; - oldkcontroller6 = -1.0; - oldkvalue6 = -1.0; - oldkcontroller7 = -1.0; - oldkvalue7 = -1.0; - return OK; - } - int32_t kontrol(CSOUND *csound) { - uint32_t offset = - OpcodeBase>::opds.insdshead->ksmps_offset; - if (!released) { - if (*kcontroller0 != oldkcontroller0 || *kvalue0 != oldkvalue0) { - instrument->controlChange(static_cast(*kcontroller0), *kvalue0); - oldkcontroller0 = *kcontroller0; - oldkvalue0 = *kvalue0; - } - if (*kcontroller1 != oldkcontroller1 || *kvalue1 != oldkvalue1) { - instrument->controlChange(static_cast(*kcontroller1), *kvalue1); - oldkcontroller1 = *kcontroller1; - oldkvalue1 = *kvalue1; - } - if (*kcontroller2 != oldkcontroller2 || *kvalue2 != oldkvalue2) { - instrument->controlChange(static_cast(*kcontroller2), *kvalue2); - oldkcontroller2 = *kcontroller2; - oldkvalue2 = *kvalue2; - } - if (*kcontroller3 != oldkcontroller3 || *kvalue3 != oldkvalue3) { - instrument->controlChange(static_cast(*kcontroller3), *kvalue3); - oldkcontroller3 = *kcontroller3; - oldkvalue3 = *kvalue3; - } - if (*kcontroller4 != oldkcontroller4 || *kvalue4 != oldkvalue4) { - instrument->controlChange(static_cast(*kcontroller4), *kvalue4); - oldkcontroller4 = *kcontroller4; - oldkvalue4 = *kvalue4; - } - if (*kcontroller5 != oldkcontroller5 || *kvalue5 != oldkvalue5) { - instrument->controlChange(static_cast(*kcontroller5), *kvalue5); - oldkcontroller5 = *kcontroller5; - oldkvalue5 = *kvalue5; - } - if (*kcontroller6 != oldkcontroller6 || *kvalue6 != oldkvalue6) { - instrument->controlChange(static_cast(*kcontroller6), *kvalue6); - oldkcontroller6 = *kcontroller6; - oldkvalue6 = *kvalue6; - } - if (*kcontroller7 != oldkcontroller7 || *kvalue7 != oldkvalue7) { - instrument->controlChange(static_cast(*kcontroller7), *kvalue7); - oldkcontroller7 = *kcontroller7; - oldkvalue7 = *kvalue7; - } - memset(aoutput, '\0', offset * sizeof(MYFLT)); - for (size_t i = offset; i < ksmps; i++) { - aoutput[i] = instrument->tick(); - } - } else { - // memset(aoutput, 0, ksmps*sizef(MYFLT)); - for (size_t i = 0; i < ksmps; i++) { - aoutput[i] = 0; - } - } - return OK; - } -}; - -extern "C" { -OENTRY oentries[] = { - { - (char *)"STKBandedWG", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKBeeThree", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKBlowBotl", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKBlowHole", sizeof(STKInstrumentAdapter1), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter1::init_, - (SUBR)STKInstrumentAdapter1::kontrol_, 0, - }, - { - (char *)"STKBowed", sizeof(STKInstrumentAdapter1), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter1::init_, - (SUBR)STKInstrumentAdapter1::kontrol_, 0, - }, - { - (char *)"STKBrass", sizeof(STKInstrumentAdapter1), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter1::init_, - (SUBR)STKInstrumentAdapter1::kontrol_, 0, - }, - { - (char *)"STKClarinet", sizeof(STKInstrumentAdapter1), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter1::init_, - (SUBR)STKInstrumentAdapter1::kontrol_, 0, - }, - { - (char *)"STKDrummer", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKFlute", sizeof(STKInstrumentAdapter1), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter1::init_, - (SUBR)STKInstrumentAdapter1::kontrol_, 0, - }, - { - (char *)"STKFMVoices", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKHevyMetl", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKMandolin", sizeof(STKInstrumentAdapter1), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter1::init_, - (SUBR)STKInstrumentAdapter1::kontrol_, 0, - }, - { - (char *)"STKModalBar", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKMoog", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKPercFlut", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKPlucked", sizeof(STKInstrumentAdapter1), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter1::init_, - (SUBR)STKInstrumentAdapter1::kontrol_, 0, - }, - { - (char *)"STKResonate", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKRhodey", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKSaxofony", sizeof(STKInstrumentAdapter1), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter1::init_, - (SUBR)STKInstrumentAdapter1::kontrol_, 0, - }, - { - (char *)"STKShakers", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKSimple", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKSitar", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKStifKarp", sizeof(STKInstrumentAdapter1), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter1::init_, - (SUBR)STKInstrumentAdapter1::kontrol_, 0, - }, - { - (char *)"STKTubeBell", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKVoicForm", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKWhistle", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - (char *)"STKWurley", sizeof(STKInstrumentAdapter), 0, 3, - (char *)"a", (char *)"iiJJJJJJJJJJJJJJJJ", - (SUBR)STKInstrumentAdapter::init_, - (SUBR)STKInstrumentAdapter::kontrol_, 0, - }, - { - 0, 0, 0, 0, 0, 0, 0, 0, - }}; - -PUBLIC int32_t csoundModuleCreate(CSOUND *csound) { return 0; } - -PUBLIC int32_t csoundModuleInit(CSOUND *csound) { - const char *path = csound->GetEnv(csound, "RAWWAVE_PATH"); -#ifdef DEFAULT_RAWWAVE_PATH - if (!path) - path = DEFAULT_RAWWAVE_PATH; -#endif - if (path == NULL) { - if (UNLIKELY(csound->GetDebug(csound))) - csound->Warning(csound, - "%s", Str("STK opcodes not available: define environment " - "variable RAWWAVE_PATH\n(points " - "to rawwaves directory) to use STK opcodes.")); - return 0; - } else { -#if !defined(MACOSX) - if (path) { - path = std::getenv("RAWWAVE_PATH"); - } -#endif - - if (path != NULL && strlen(path) != 0) { - Stk::setRawwavePath(path); - } - // csound->DebugMsg(csound, - // "%s", Str("RAWWAVE_PATH: %s\n"), Stk::rawwavePath().c_str()); - } - int32_t status = 0; - for (OENTRY *oentry = &oentries[0]; oentry->opname; oentry++) { - status |= csound->AppendOpcode(csound, oentry->opname, oentry->dsblksiz, - oentry->flags, oentry->thread, - oentry->outypes, oentry->intypes, - (int32_t (*)(CSOUND *, void *))oentry->iopadr, - (int32_t (*)(CSOUND *, void *))oentry->kopadr, - (int32_t (*)(CSOUND *, void *))oentry->aopadr); - } - return status; -} - -PUBLIC int32_t csoundModuleDestroy(CSOUND *csound) { return 0; } -} diff --git a/6.x/src/websockets/CMakeLists.txt b/6.x/src/websockets/CMakeLists.txt deleted file mode 100644 index 2438a8c3..00000000 --- a/6.x/src/websockets/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -option(BUILD_WEBSOCKET_OPCODE "Build the websocket opcode" ON) - -if(USE_VCPKG) - find_package(libuv CONFIG) - find_package(libwebsockets CONFIG) -else() - find_path(WEBSOCKETS_H libwebsockets.h /usr/local/include /usr/include) - find_library(websockets_library NAMES websockets) -endif() - -if(APPLE) - find_library(ssl_library NAMES ssl) - find_library(crypto_library NAMES crypto) - - check_deps(BUILD_WEBSOCKET_OPCODE websockets_library ssl_library crypto_library WEBSOCKETS_H) -endif() - -if(BUILD_WEBSOCKET_OPCODE) - make_plugin(websocketIO WebSocketOpcode.c) - target_include_directories(websocketIO PRIVATE ${CSOUND_INCLUDE_DIRS}) - - if(USE_VCPKG) - target_link_libraries(websocketIO websockets uv_a) - else() - target_link_libraries(websocketIO ${websockets_library}) - target_include_directories(websocketIO PRIVATE ${WEBSOCKETS_H}) - endif() - - if(APPLE) - target_link_libraries(websocketIO ${ssl_library} ${crypto_library} z) - endif() -endif() diff --git a/6.x/src/websockets/WebSocketOpcode.c b/6.x/src/websockets/WebSocketOpcode.c deleted file mode 100644 index a0964943..00000000 --- a/6.x/src/websockets/WebSocketOpcode.c +++ /dev/null @@ -1,712 +0,0 @@ -/* - WebSocketOpcode.c - WebSocketOpcode - - Copyright (C) 2015, 2016 - Edward Costello - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA - */ - -#include "WebSocketOpcode.h" -#ifndef _MSC_VER -# include -#endif -#include -#include -#include - -typedef enum ArgumentType -{ - STRING_VAR, - ARATE_VAR, - KRATE_VAR, - IRATE_VAR, - ARATE_ARRAY, - KRATE_ARRAY, - IRATE_ARRAY, - UNKNOWN -} ArgumentType; - - -struct OpcodeArgument{ - - void *dataPointer; - MYFLT *argumentPointer; - bool receivedData; - ArgumentType argumentType; - AUXCH auxillaryMemory; - void *circularBuffer; - char *name; - void *readBuffer; - int32_t itemsCount; - uint32_t bytesCount; - uint32_t bytesWritten; - bool iRateVarSent; -}; - -struct WebSocket{ - - struct lws_context *context; - struct lws *websocket; - struct lws_protocols *protocols; - void *processThread; - unsigned char *messageBuffer; - struct lws_context_creation_info info; -}; - -typedef enum ArgumentOffset { - - OUTPUT_OFFSET = 1000, INPUT_OFFSET = 2000 -} ArgumentOffset; - -static const size_t writeBufferBytesCount = 2048; -static const size_t stringVarMaximumBytesCount = 4096; -static const size_t ringBufferItemsCount = 2048 * 16; - -void WebSocketOpcode_initialiseWebSocket(WebSocketOpcode *self, CSOUND *csound); -int32_t WebSocketOpcode_finish(CSOUND *csound, void *opaqueReference); -void WebSocketOpcode_initialiseArguments(WebSocketOpcode *self, CSOUND *csound); -ArgumentType WebSocketOpcode_getArgumentType(CSOUND *csound, MYFLT *argument); - -int32_t WebSocketOpcode_initialise(CSOUND *csound, WebSocketOpcode *self) -{ - self->inputArgumentCount = self->INOCOUNT - 1; - self->outputArgumentCount = self->OUTOCOUNT; - self->csound = csound; - WebSocketOpcode_initialiseArguments(self, csound); - WebSocketOpcode_initialiseWebSocket(self, csound); - csound->RegisterDeinitCallback(csound, self, WebSocketOpcode_finish); - return OK; -} - -void WebSocketOpcode_sendInputArgumentData(CSOUND *csound, WebSocketOpcode *self) -{ - int32_t i; - for (i = 0; i < self->inputArgumentCount; ++i) { - - OpcodeArgument *currentArgument = &self->inputArguments[i]; - - if (currentArgument->iRateVarSent == true) { - - continue; - } - - int32_t itemsWritten = - csound->WriteCircularBuffer(csound, - currentArgument->circularBuffer, - currentArgument->dataPointer, - currentArgument->itemsCount); - - if (UNLIKELY(itemsWritten != currentArgument->itemsCount)) { - - csound->Message(csound, - Str("websocket: variable %s data not sent, " - "buffer overrrun\n"), currentArgument->name); - } - } -} - -void WebSocketOpcode_receiveOutputArgumentData(CSOUND *csound, - WebSocketOpcode *self) -{ - int32_t i; - for (i = 0; i < self->outputArgumentCount; ++i) { - - OpcodeArgument *currentArgument = &self->outputArguments[i]; - - if (currentArgument->receivedData == true) { - - if (currentArgument->iRateVarSent == true) { - - continue; - } - - csound->ReadCircularBuffer(csound, currentArgument->circularBuffer, - currentArgument->dataPointer, - currentArgument->itemsCount); - - if (currentArgument->argumentType == STRING_VAR) { - - STRINGDAT *string = (STRINGDAT *)currentArgument->argumentPointer; - string->size = (int32_t)strlen(currentArgument->dataPointer); - } - - currentArgument->receivedData = false; - } - - } -} - -int32_t WebSocketOpcode_process(CSOUND *csound, WebSocketOpcode *self) -{ - WebSocketOpcode_sendInputArgumentData(csound, self); - WebSocketOpcode_receiveOutputArgumentData(csound, self); - return OK; -} - -int32_t WebSocketOpcode_finish(CSOUND *csound, void *opaqueReference) -{ - int32_t i; - WebSocketOpcode *self = opaqueReference; - self->isRunning = false; - - csound->JoinThread(self->webSocket->processThread); - - lws_cancel_service(self->webSocket->context); - lws_context_destroy(self->webSocket->context); - - for (i = 0; i < self->outputArgumentCount; ++i) { - - csound->DestroyCircularBuffer(csound, self->outputArguments[i].circularBuffer); - } - - for (i = 0; i < self->inputArgumentCount; ++i) { - - csound->DestroyCircularBuffer(csound, self->inputArguments[i].circularBuffer); - } - - csound->Free(csound, self->webSocket->protocols); - csound->Free(csound, self->webSocket->messageBuffer); - csound->Free(csound, self->webSocket); - if (self->inputArgumentCount > 0) { - - csound->Free(csound, self->inputArguments); - } - if (self->outputArgumentCount > 0) { - - csound->Free(csound, self->outputArguments); - } - return OK; -} - -int32_t WebSocketOpcode_getArrayElementCount(ARRAYDAT *array) -{ - int32_t elementCount = array->sizes[0]; - int32_t i; - for (i = 1; i < array->dimensions; ++i) { - - elementCount *= array->sizes[i]; - } - - return elementCount; -} - - -void WebSocketOpcode_allocateStringArgument(MYFLT *argument, - OpcodeArgument *argumentArrayItem, - CSOUND *csound, bool isInputArgument) -{ - STRINGDAT *string = (STRINGDAT *)argument; - - if (UNLIKELY(isInputArgument == true)) { - - csound->Die(csound, - "%s", Str("websocket: this opcode does not send strings, only " - "receiving them is supported\nExiting")); - } - else { - - if (UNLIKELY(string->size != 0)) { - - csound->Die(csound, - Str("websocket: error output string variable %s must not " - "be initialised\nExiting"), - argumentArrayItem->name); - } - else { - - argumentArrayItem->itemsCount = stringVarMaximumBytesCount; - string->data = csound->ReAlloc(csound, string->data, - stringVarMaximumBytesCount); - memset(string->data, 0, stringVarMaximumBytesCount); - } - } - - argumentArrayItem->dataPointer = string->data; - argumentArrayItem->bytesCount = sizeof(char) * stringVarMaximumBytesCount; - argumentArrayItem->circularBuffer = - csound->CreateCircularBuffer(csound, - argumentArrayItem->itemsCount * - ringBufferItemsCount + 1, - sizeof(char)); - csound->AuxAlloc(csound, argumentArrayItem->bytesCount, - &argumentArrayItem->auxillaryMemory); - argumentArrayItem->readBuffer = argumentArrayItem->auxillaryMemory.auxp; -} - -void WebSocketOpcode_allocateArrayArgument(MYFLT *argument, - OpcodeArgument *argumentArrayItem, - CSOUND *csound) -{ - ARRAYDAT *array = (ARRAYDAT *)argument; - - if (UNLIKELY(array->dimensions == 0)) { - - csound->Die(csound, - Str("websocket: error array variable %s has not been " - "initialised\nExiting"), - argumentArrayItem->name); - } - - argumentArrayItem->dataPointer = array->data; - argumentArrayItem->itemsCount = WebSocketOpcode_getArrayElementCount(array); - argumentArrayItem->bytesCount = - array->arrayMemberSize * argumentArrayItem->itemsCount; - argumentArrayItem->circularBuffer = - csound->CreateCircularBuffer(csound, - argumentArrayItem->itemsCount * - ringBufferItemsCount + 1, - array->arrayMemberSize); - csound->AuxAlloc(csound, argumentArrayItem->bytesCount, - &argumentArrayItem->auxillaryMemory); - argumentArrayItem->readBuffer = argumentArrayItem->auxillaryMemory.auxp; -} - -void WebSocketOpcode_allocateVariableArgument(MYFLT *argument, - OpcodeArgument *argumentArrayItem, - CSOUND *csound, int32_t bytesCount) -{ - argumentArrayItem->dataPointer = argument; - argumentArrayItem->itemsCount = 1; - argumentArrayItem->bytesCount = bytesCount; - argumentArrayItem->circularBuffer = - csound->CreateCircularBuffer(csound, ringBufferItemsCount + 1, - argumentArrayItem->bytesCount); - csound->AuxAlloc(csound, argumentArrayItem->bytesCount, - &argumentArrayItem->auxillaryMemory); - argumentArrayItem->readBuffer = argumentArrayItem->auxillaryMemory.auxp; -} - -void WebSocketOpcode_initialiseArgumentsArray(CSOUND *csound, - WebSocketOpcode *self, - OpcodeArgument *argumentsArray, - size_t argumentsCount, - MYFLT **arguments, - bool areInputArguments) -{ - uint32_t i; - for (i = 0; i < argumentsCount; ++i) { - - OpcodeArgument *argumentArrayItem = &argumentsArray[i]; - argumentArrayItem->argumentPointer = arguments[i]; - argumentArrayItem->argumentType = - WebSocketOpcode_getArgumentType(csound, arguments[i]); - argumentArrayItem->name = - areInputArguments ? csound->GetInputArgName((void *)self, i + 1) - : csound->GetOutputArgName((void *)self, i); - - switch (argumentsArray[i].argumentType) { - - case IRATE_ARRAY: - case ARATE_ARRAY: - case KRATE_ARRAY: { - - WebSocketOpcode_allocateArrayArgument(arguments[i], - argumentArrayItem, csound); - break; - } - case STRING_VAR: { - - WebSocketOpcode_allocateStringArgument(arguments[i], - argumentArrayItem, csound, - areInputArguments); - break; - } - case ARATE_VAR: { - - WebSocketOpcode_allocateVariableArgument(arguments[i], - argumentArrayItem, csound, - sizeof(MYFLT) * csound->GetKsmps(csound)); - break; - } - case IRATE_VAR: - case KRATE_VAR: { - - WebSocketOpcode_allocateVariableArgument(arguments[i], argumentArrayItem, - csound, sizeof(MYFLT)); - break; - } - default: { - - csound->Die(csound, "%s", Str("websocket: error, incompatible argument " - "detected\nExiting")); - break; - } - } - } -} - -void WebSocketOpcode_initialiseArguments(WebSocketOpcode *self, CSOUND *csound) -{ - self->inputArguments = - csound->Calloc(csound, sizeof(OpcodeArgument) * self->inputArgumentCount); - self->outputArguments = - csound->Calloc(csound, sizeof(OpcodeArgument) * self->outputArgumentCount); - - WebSocketOpcode_initialiseArgumentsArray(csound, self, self->inputArguments, - self->inputArgumentCount, - &self->arguments[self->outputArgumentCount + 1], - true); - WebSocketOpcode_initialiseArgumentsArray(csound, self, self->outputArguments, - self->outputArgumentCount, - self->arguments, false); -} - -void WebSocketOpcode_writeOnce(WebSocketOpcode *self, OpcodeArgument *inputArgument, - void *messageBuffer, struct lws *websocket) -{ - IGN(self); - unsigned char *inputData = (unsigned char *)inputArgument->readBuffer; - memcpy(messageBuffer, inputData, inputArgument->bytesCount); - lws_write(websocket, messageBuffer, inputArgument->bytesCount, - LWS_WRITE_BINARY); -} - -void WebSocketOpcode_writeFragments(WebSocketOpcode *self, - OpcodeArgument *inputArgument, - void *messageBuffer, struct lws *websocket) -{ - IGN(self); - unsigned char *inputData = - &((unsigned char *)inputArgument->readBuffer)[inputArgument->bytesWritten]; - - // *** FIXME *** signed/usigned comparison - if (inputArgument->bytesWritten + writeBufferBytesCount < - inputArgument->bytesCount) { - - int32_t writeFlags = LWS_WRITE_NO_FIN; - writeFlags |= - inputArgument->bytesWritten==0 ? LWS_WRITE_BINARY : LWS_WRITE_CONTINUATION; - memcpy(messageBuffer, inputData, writeBufferBytesCount); - inputArgument->bytesWritten += lws_write(websocket, messageBuffer, - writeBufferBytesCount, writeFlags); - } - else { - - size_t fragmentBytesCount = - inputArgument->bytesCount - inputArgument->bytesWritten; - memcpy(messageBuffer, inputData, fragmentBytesCount); - lws_write(websocket, messageBuffer, fragmentBytesCount, - LWS_WRITE_CONTINUATION); - inputArgument->bytesWritten = 0; - } -} - -void WebSocketOpcode_writeMessage(WebSocketOpcode *self, - OpcodeArgument *inputArgument, - void *messageBuffer, struct lws *websocket) -{ - if (inputArgument->bytesCount <= writeBufferBytesCount) { - - WebSocketOpcode_writeOnce(self, inputArgument, messageBuffer, websocket); - } - else { - - WebSocketOpcode_writeFragments(self, inputArgument, messageBuffer, websocket); - } -} - -void WebSocketOpcode_handleServerWritable(struct lws *websocket, - WebSocketOpcode *self, CSOUND *csound, - void *messageBuffer) -{ - const struct lws_protocols *protocol = lws_get_protocol(websocket); - - if (protocol->id / OUTPUT_OFFSET == 1) { // If it's an output argument - - usleep(100); - return; - } - - int32_t inputIndex = 0; - - OpcodeArgument *argument = &self->inputArguments[inputIndex]; - - int32_t readItems = 0; - - if (argument->bytesWritten == 0) { - - readItems = csound->ReadCircularBuffer(csound, argument->circularBuffer, - argument->readBuffer, - argument->itemsCount); - } - if (readItems != 0 || argument->bytesWritten != 0) { - - WebSocketOpcode_writeMessage(self, argument, messageBuffer, websocket); - - if (argument->argumentType == IRATE_VAR || - argument->argumentType == IRATE_ARRAY) { - - argument->iRateVarSent = true; - } - } - - usleep(100); - - if (argument->iRateVarSent == false) { - - lws_callback_on_writable(websocket); - } -} - -void WebSocketOpcode_handleReceive(struct lws *websocket, WebSocketOpcode *self, - CSOUND *csound, size_t inputDataSize, - void *inputData) -{ - const struct lws_protocols *protocol = lws_get_protocol(websocket); - - if (protocol->id / OUTPUT_OFFSET != 1) { - - return; - } - - OpcodeArgument *argument = &self->outputArguments[protocol->id - OUTPUT_OFFSET]; - - if (argument->iRateVarSent == true) { - - return; - } - - // *** FIXME *** signed/unsigned comparison - if (UNLIKELY(argument->bytesCount != inputDataSize - && - argument->argumentType != STRING_VAR)) { - - csound->Message(csound, Str("websocket: received message from is not " - "correct size for variable %s, message dumped"), - protocol->name); - return; - } - - if (UNLIKELY(argument->argumentType == STRING_VAR - && - argument->bytesCount > stringVarMaximumBytesCount)) { - - csound->Message(csound, Str("websocket: received string message from " - "%s is too large, message dumped"), - protocol->name); - - return; - } - - int32_t writtenItems = - csound->WriteCircularBuffer(csound, argument->circularBuffer, - inputData, argument->itemsCount); - argument->receivedData = true; - - if (UNLIKELY(writtenItems == 0)) { - - csound->Message(csound, Str("websocket: received message from %s " - "dumped, buffer overrrun"), argument->name); - } - else { - - if (argument->argumentType == IRATE_VAR - || - argument->argumentType == IRATE_ARRAY) { - - argument->iRateVarSent = true; - } - } -} - - -static int32_t Websocket_callback(struct lws *websocket, - enum lws_callback_reasons reason, - void *user, void *inputData, size_t inputDataSize) -{ - - IGN(user); - - if (reason != LWS_CALLBACK_ESTABLISHED && - reason != LWS_CALLBACK_SERVER_WRITEABLE && reason != LWS_CALLBACK_RECEIVE) { - return OK; - } - - const struct lws_protocols *protocol = lws_get_protocol(websocket); - WebSocketOpcode *self = lws_get_protocol(websocket)->user; - CSOUND *csound = self->csound; - - switch (reason) { - - case LWS_CALLBACK_ESTABLISHED: { - - - csound->Message(csound, Str("websocket: connection established for %s\n"), - protocol->name); - break; - } - case LWS_CALLBACK_SERVER_WRITEABLE: { - - void *messageBuffer = - (void *)&self->webSocket->messageBuffer[LWS_SEND_BUFFER_PRE_PADDING]; - - WebSocketOpcode_handleServerWritable(websocket, self, csound, messageBuffer); - break; - } - case LWS_CALLBACK_RECEIVE: { - - WebSocketOpcode_handleReceive(websocket, self, csound, - inputDataSize, inputData); - break; - } - case LWS_CALLBACK_CLOSED: { - - printf("closed\n"); /* Why not sound->Message ? */ - } - default: { - - break; - } - } - - return OK; -} - -uintptr_t WebSocketOpcode_processThread(void *opaquePointer) -{ - WebSocketOpcode *self = opaquePointer; - - while (self->isRunning == 1) { - - - lws_service(self->webSocket->context, 10); - lws_callback_on_writable_all_protocol(self->webSocket->context, - &self->webSocket->protocols[0]); - } - - return 0; -} - -void WebSocketOpcode_initialiseWebSocket(WebSocketOpcode *self, CSOUND *csound) -{ - int32_t i; - size_t argumentsCount = self->inputArgumentCount + self->outputArgumentCount; - - self->webSocket = csound->Calloc(csound, sizeof(WebSocket)); - self->webSocket->protocols = //Last protocol is null - csound->Calloc(csound, sizeof(struct lws_protocols) * (argumentsCount + 1)); - size_t argumentIndex = 0; - - for (i = 0; i < self->inputArgumentCount; ++i, argumentIndex++) { - - self->webSocket->protocols[argumentIndex].name = self->inputArguments[i].name; - self->webSocket->protocols[argumentIndex].callback = Websocket_callback; - self->webSocket->protocols[argumentIndex].id = INPUT_OFFSET + i; - self->webSocket->protocols[argumentIndex].user = self; - self->webSocket->protocols[argumentIndex].per_session_data_size = - sizeof(WebSocketOpcode *); - } - - for (i = 0; i < self->outputArgumentCount; ++i, ++argumentIndex) { - - self->webSocket->protocols[argumentIndex].name = - self->outputArguments[i].name; - self->webSocket->protocols[argumentIndex].callback = Websocket_callback; - self->webSocket->protocols[argumentIndex].id = OUTPUT_OFFSET + i; - self->webSocket->protocols[argumentIndex].user = self; - self->webSocket->protocols[argumentIndex].per_session_data_size = - sizeof(WebSocketOpcode *); - } - - - self->webSocket->info.port = *self->arguments[self->outputArgumentCount]; - self->webSocket->info.protocols = self->webSocket->protocols; - self->webSocket->info.gid = -1; - self->webSocket->info.uid = -1; - - lws_set_log_level(LLL_DEBUG, NULL); - self->webSocket->context = lws_create_context(&self->webSocket->info); - self->webSocket->messageBuffer = - csound->Calloc(csound, LWS_SEND_BUFFER_PRE_PADDING + - (sizeof(char) * writeBufferBytesCount) + - LWS_SEND_BUFFER_POST_PADDING); - if (UNLIKELY(self->webSocket->context == NULL)) { - - csound->Die(csound, - "%s", Str("websocket: could not initialise websocket, Exiting")); - } - - - self->isRunning = true; - self->webSocket->processThread = - csound->CreateThread(WebSocketOpcode_processThread, self); -} - -ArgumentType WebSocketOpcode_getArgumentType(CSOUND *csound, MYFLT *argument) -{ - const CS_TYPE *csoundType = csound->GetTypeForArg((void *)argument); - const char *type = csoundType->varTypeName; - ArgumentType argumentType = UNKNOWN; - - if (strcmp("S", type) == 0) { - - argumentType = STRING_VAR; - } - else if (strcmp("a", type) == 0) { - - argumentType = ARATE_VAR; - } - else if (strcmp("k", type) == 0) { - - argumentType = KRATE_VAR; - } - else if (strcmp("i", type) == 0) { - - argumentType = IRATE_VAR; - } - else if (strcmp("[", type) == 0) { - - ARRAYDAT *array = (ARRAYDAT *)argument; - - if (strcmp("k", array->arrayType->varTypeName) == 0) { - - argumentType = KRATE_ARRAY; - } - else if (strcmp("a", array->arrayType->varTypeName) == 0) { - - argumentType = ARATE_ARRAY; - } - else if (strcmp("i", array->arrayType->varTypeName) == 0) { - - argumentType = IRATE_ARRAY; - } - } - - - return argumentType; -} - -static OENTRY localops[] = { - - { - .opname = "websocket", - .dsblksiz = sizeof(WebSocketOpcode), - .thread = 3, - .outypes = "*", - .intypes = "i.", - .iopadr = (SUBR)WebSocketOpcode_initialise, - .kopadr = (SUBR)WebSocketOpcode_process, - .aopadr = NULL - } - -}; - - -LINKAGE diff --git a/6.x/src/websockets/WebSocketOpcode.h b/6.x/src/websockets/WebSocketOpcode.h deleted file mode 100644 index 0747cfe2..00000000 --- a/6.x/src/websockets/WebSocketOpcode.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - - WebSocketOpcode.h - WebSockets - - Created by Edward Costello on 10/06/2015. - Copyright (c) 2015 Edward Costello. - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA - */ - - -#include -#include "csdl.h" -//#include "csound.h" - -#ifdef WIN32 - -#define WIN32_LEAN_AND_MEAN -#include - -void usleep(unsigned int usec) -{ - HANDLE timer; - LARGE_INTEGER ft; - - ft.QuadPart = -(10 * (__int64)usec); - - timer = CreateWaitableTimer(NULL, TRUE, NULL); - SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); - WaitForSingleObject(timer, INFINITE); - CloseHandle(timer); -} - -#endif - - -#ifdef __cplusplus -extern "C" -{ -#endif - typedef struct OpcodeArgument OpcodeArgument; - typedef struct WebSocket WebSocket; - - typedef struct WebSocketOpcode - { - OPDS h; - MYFLT *arguments[20]; - int32_t inputArgumentCount; - int32_t outputArgumentCount; - WebSocket *webSocket; - OpcodeArgument *inputArguments; - OpcodeArgument *outputArguments; - bool isRunning; - CSOUND *csound; - } WebSocketOpcode; - - int32_t WebSocketOpcode_initialise(CSOUND *csound, WebSocketOpcode *self); - int32_t WebSocketOpcode_process(CSOUND *csound, WebSocketOpcode *self); -#ifdef __cplusplus -} -#endif diff --git a/6.x/src/widgets/CMakeLists.txt b/6.x/src/widgets/CMakeLists.txt deleted file mode 100644 index 4dda233a..00000000 --- a/6.x/src/widgets/CMakeLists.txt +++ /dev/null @@ -1,57 +0,0 @@ -option(USE_FLTK "Use FLTK for graphs and widget opcodes" ON) - -set(FLTK_SKIP_OPENGL true) - -if(USE_VCPKG) - find_package(FLTK CONFIG) -else() - find_package(FLTK) -endif() - -find_path(CAIRO_INCLUDE_DIR cairo.h PATH_SUFFIXES cairo) - -check_deps(USE_FLTK FLTK_FOUND) - -if(USE_FLTK) - set(widgets_SRCS FL_graph.cpp winFLTK.c widgets.cpp) - - make_plugin(widgets "${widgets_SRCS}" "${FLTK_LIBRARIES}") - target_include_directories(widgets PRIVATE ${CSOUND_INCLUDE_DIRS} ${FLTK_INCLUDE_DIR}) - - if(USE_VCPKG) - target_link_libraries(widgets PRIVATE fltk fltk_gl fltk_forms fltk_images) - else() - target_link_libraries(widgets PRIVATE - ${FLTK_BASE_LIBRARY} ${FLTK_FORMS_LIBRARY} ${FLTK_IMAGES_LIBRARY} - ) - endif() -endif() - -if(USE_FLTK) - set(virtual_SRCS - virtual_keyboard/FLTKKeyboard.cpp - virtual_keyboard/FLTKKeyboardWindow.cpp - virtual_keyboard/FLTKKeyboardWidget.cpp - virtual_keyboard/virtual_keyboard.cpp - virtual_keyboard/Bank.cpp - virtual_keyboard/KeyboardMapping.cpp - virtual_keyboard/Program.cpp - virtual_keyboard/SliderBank.cpp - virtual_keyboard/SliderData.cpp) - - make_plugin(virtual "${virtual_SRCS}" "${FLTK_LIBRARIES}") - target_include_directories(virtual PRIVATE ${CSOUND_INCLUDE_DIRS} ${FLTK_INCLUDE_DIR} ".") - - if (USE_VCPKG) - target_link_libraries(virtual PRIVATE fltk fltk_gl fltk_forms fltk_images) - else() - target_link_libraries(virtual PRIVATE - ${FLTK_BASE_LIBRARY} ${FLTK_FORMS_LIBRARY} ${FLTK_IMAGES_LIBRARY} - ) - endif() -endif() - -if(USE_FLTK AND CAIRO_INCLUDE_DIR) - target_include_directories(widgets PRIVATE ${CAIRO_INCLUDE_DIR}) - target_include_directories(virtual PRIVATE ${CAIRO_INCLUDE_DIR}) -endif() diff --git a/6.x/src/widgets/FL_graph.cpp b/6.x/src/widgets/FL_graph.cpp deleted file mode 100644 index a2674ec3..00000000 --- a/6.x/src/widgets/FL_graph.cpp +++ /dev/null @@ -1,504 +0,0 @@ - -/* - FL_graph.cpp: code for drawing graphs using FLTK library - - Copyright (C) 2003 John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include -#include -#include -#include -#include - -#ifdef _MSC_VER -#include -#endif -#include "csdl.h" -#include "cwindow.h" -#include "winFLTK.h" -#include - -#define NUMOFWINDOWS (30) -#define XINIT 10 /* set default window location */ -#define YINIT 50 -#define WIDTH 450 /* start off small - user resizes */ -#define HEIGHT 150 -#define BDR 5 -#define BORDERW 10 /* inset from L & R edge */ -#define TXHGHT 14 /* baseline offset for text */ -#define MAXLSEGS 4096 /* X can only deal with so many linesegs .. */ - -class graph_box : public Fl_Window { - void draw(); -public: - int curr; - int last; - CSOUND *csound; - graph_box(void *cs, int x, int y, int w, int h, const char *l = 0) - : Fl_Window(x, y, w, h, l) - { - curr = last = -1; - csound = (CSOUND*)cs; - } - //void add_graph(WINDAT *wdptr); -}; - -typedef struct { - - Fl_Choice *choice; - Fl_Button *end; - Fl_Menu_Item *menu; - graph_box *graph; - int graph_created; - Fl_Window *form; -} FLGRAPH_GLOBALS; - -#define ST(x) ((flgraphGlobals)->x) - -/*void printouts(CSOUND *csound){ - csound->Message(csound, "menu object: %p\n", ST(menu)); - csound->Message(csound, "form object: %p\n", ST(form)); - csound->Message(csound, "graph object: %p\n", ST(graph)); - csound->Message(csound, "choice object: %p\n", ST(choice)); - csound->Message(csound, "globals %p\n", csound->flgraphGlobals); -}*/ - -void flgraph_init(CSOUND *csound) -{ - - FLGRAPH_GLOBALS *flgraphGlobals = - (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, - "FLGRAPH_GLOBALS"); - if (flgraphGlobals==NULL) { - csound->CreateGlobalVariable(csound, "FLGRAPH_GLOBALS", - sizeof(FLGRAPH_GLOBALS)); - flgraphGlobals = - (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, - "FLGRAPH_GLOBALS"); - //csound->flgraphGlobals = - //(FLGRAPH_GLOBALS*) csound->Malloc(csound,sizeof(FLGRAPH_GLOBALS)); - } - ST(form) = (Fl_Window *) 0; - ST(choice) = (Fl_Choice *) 0; - ST(end) = (Fl_Button *) 0; - ST(graph) = (graph_box *) 0; - ST(menu) = (Fl_Menu_Item *) 0; - ST(graph_created) = 0; - - - /*ST(menu) = (Fl_Menu_Item*) csound->Calloc(csound, - sizeof(Fl_Menu_Item)*(1+NUMOFWINDOWS));*/ - /* VL: moved menu object to be built at each new compilation */ - -} - -/* static graph_box *graph = (graph_box *) 0; */ - -void graph_box::draw() -{ - FLGRAPH_GLOBALS *flgraphGlobals = - (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, - "FLGRAPH_GLOBALS"); - Fl_Window::draw(); - fl_color(0, 0, 0); - fl_line_style(FL_SOLID); - fl_rect(0, 0, w(), h()); - if (curr >= 0) { - WINDAT *win = (WINDAT*) ST(menu)[curr].user_data_; - if (!win) - return; - MYFLT *fdata = win->fdata; - int32 npts = win->npts; - char *msg = win->caption; - short win_x, win_y, win_h; /* window rect */ - short gra_x, gra_y, gra_w, gra_h; /* graph rect is inset */ - short y_axis; - int lsegs, pts_pls; - int pol; - char string[400]; - - pol = win->polarity; - - win_x = 0; win_y = 0; /* window pixels addressed relative */ - win_h = h(); - - /* set new width and height so we leave a 20% border around the plot */ - gra_w = w() - 2*BORDERW; - gra_h = h(); - gra_x = win_x + BORDERW; - gra_y = win_y; - /* figure height of Y axis - top, middle or bottom */ - if (pol == (short)BIPOL) - y_axis = gra_y + (gra_h/2); - else if (pol == (short)NEGPOL) - y_axis = gra_y; - else /* POSPOL */ - y_axis = gra_y + gra_h; - - if (npts < MAXLSEGS) { - lsegs = npts; /* one lineseg per datum */ - pts_pls = 1; - } - else { - pts_pls = npts/MAXLSEGS; - if (npts%MAXLSEGS) pts_pls++; - lsegs = npts/pts_pls; - } - fl_begin_line(); - { /* take scale factors out of for-loop for faster run-time */ - MYFLT x_scale = gra_w / (MYFLT) (lsegs - 1); - MYFLT y_scale = gra_h / win->oabsmax; /* unipolar default */ - MYFLT f, ma, mi, *fdptr = fdata; - int c, i = 0, j = lsegs; - - if (pol == (short) BIPOL) - y_scale /= 2.0; /* max data scales to h/2 */ - /* put x-y pairs into a point list for XDraw */ - while (j--) { - int x = gra_x + (short) ((MYFLT) i++ * x_scale); - int y; - if (pts_pls == 1) - f = *fdptr++; - else { - ma = mi = *fdptr++; - for (c = 1; c < pts_pls; ++c) - if ((f = *fdptr++) > ma) ma = f; - else if ( f 0) f = ma; - else if (ma > -mi) f = ma; - else f = mi; - } - y = y_axis - (short) (f * y_scale); - fl_vertex(x, y); - } - } - fl_end_line(); - - /* now draw axes: y-axis is always on the left edge, - x-axis height is determined by the case we're in */ - fl_line(gra_x, y_axis, (gra_x + gra_w), y_axis); - fl_line(gra_x, y_axis, (gra_x + gra_w), y_axis); - - - fl_line(gra_x, gra_y, gra_x, (gra_y + gra_h)); - if (win->danflag) { /* flag to add dotted divider */ - fl_line_style(FL_DOT); - fl_line(win_x+w()/2, win_y, win_x+w()/2, win_y+win_h); - } - if (pol != NEGPOL) - sprintf(string, "%s %" PRIi32 " points, max %5.3f", msg, npts, win->oabsmax); - else - sprintf(string, "%s %" PRIi32 " points, max %5.3f", msg, npts, win->max); - - ST(form)->label(string); - } - fl_line_style(FL_SOLID); -} - - - -void add_graph(CSOUND *csound, WINDAT *wdptr) -{ - FLGRAPH_GLOBALS *flgraphGlobals = - (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, - "FLGRAPH_GLOBALS"); - WINDAT *n = (WINDAT*) malloc(sizeof(WINDAT)); - int m; - WINDAT *old; - int replacing = 0; - - memcpy(n, wdptr, sizeof(WINDAT)); - n->fdata = (MYFLT*) malloc(n->npts * sizeof(MYFLT)); - memcpy(n->fdata, wdptr->fdata, n->npts * sizeof(MYFLT)); - - - for (m = 0; m < NUMOFWINDOWS; m++) { // If text the same use slot - if (ST(menu) != NULL) { - if (ST(menu)[m].text != NULL && strlen(wdptr->caption) == 0){ - if(strcmp(wdptr->caption, ST(menu)[m].text) == 0) { - replacing = 1; - goto replace; - } - } - } - } - // Use a new slot, cycling round - ST(graph)->last++; - m = ST(graph)->last; - if (m >= NUMOFWINDOWS) - m = ST(graph)->last = 0; - replace: - - old = (WINDAT*)ST(menu)[m].user_data_; - if (old) { - free((void*) old->fdata); - free((void*) old); - } - ST(menu)[m].user_data_ = n; - if (replacing == 0) { - if (ST(menu)[m].text != NULL) - free((void*) ST(menu)[m].text); - ST(menu)[m].text = (const char*) malloc(strlen(n->caption) + 1); - strcpy((char*) ST(menu)[m].text, n->caption); - } - - - // ST(graph)->curr = m; - // ST(choice)->value(m); - - ST(graph)->curr = ST(choice)->value(); /* VL: 29.04.09 fix */ - ST(graph)->redraw(); -} - -void do_redraw(Fl_Widget *, void *cs) -{ - CSOUND *csound = (CSOUND*)cs; - FLGRAPH_GLOBALS *flgraphGlobals = - (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, - "FLGRAPH_GLOBALS"); - ST(graph)->curr = ST(choice)->value(); - ST(graph)->redraw(); -} - -void makeWindow(CSOUND *csound, char *name) -{ - FLGRAPH_GLOBALS *flgraphGlobals = - (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, - "FLGRAPH_GLOBALS"); - if (ST(form)) - return; - - ST(form) = new Fl_Window(WIDTH, HEIGHT, name); - ST(menu) = new Fl_Menu_Item[1+NUMOFWINDOWS]; - memset(ST(menu), 0, sizeof(Fl_Menu_Item)*(1+NUMOFWINDOWS)); - ST(choice) = new Fl_Choice(140, 0, 140, 20, "Choose Graph"); - ST(choice)->menu(ST(menu)); - ST(choice)->value(0); - ST(choice)->callback((Fl_Callback*) do_redraw, (void*)csound); - ST(graph) = new graph_box(csound, - BDR, 30 + BDR, WIDTH - 2 * BDR, HEIGHT - 30 - 2 * BDR); - ST(graph)->end(); - ST(end) = new Fl_Button(WIDTH - 40, 0, 35, 20, "Quit"); - ST(end)->hide(); - ST(form)->resizable(ST(graph)); - ST(form)->end(); - ST(graph_created) = 1; - -} - -void graphs_reset(CSOUND * csound){ - IGN(csound); - //if (csound->flgraphGlobals != NULL) - // csound->Free(csound, csound->flgraphGlobals); -} - -extern "C" { - - void DrawGraph_FLTK(CSOUND *csound, WINDAT *wdptr) - { - - add_graph(csound, wdptr); - csound->CheckEvents(csound); - } - - uintptr_t MakeWindow_FLTK(CSOUND *csound, char *name) - { - FLGRAPH_GLOBALS *flgraphGlobals = - (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, - "FLGRAPH_GLOBALS"); - if (ST(form) == NULL) { - makeWindow(csound, name); - ST(form)->show(); - } - - return (uintptr_t) ST(form); - } - - int CsoundYield_FLTK(CSOUND *csound){ - -#ifndef NO_FLTK_THREADS - - /* nothing to do, unless no widget thread is running */ - if (csound->QueryGlobalVariable(csound, "_widgets_globals") != NULL) - return 1; -#endif - Fl_wait_locked(csound, 0.0); - return 1; - } - - void kill_graph(CSOUND *csound, uintptr_t m) - { - FLGRAPH_GLOBALS *flgraphGlobals = - (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, - "FLGRAPH_GLOBALS"); - for (int i = 0; i < NUMOFWINDOWS; i++) { - WINDAT *n = (WINDAT*) ST(menu)[i].user_data_; - if (n != NULL && ((uintptr_t) n == m ||n->windid == m)) { - free(n->fdata); - free(n); - free((void*) ST(menu)[i].text); - ST(menu)[i].user_data_ = (void*) 0; - ST(menu)[i].text = (char*) 0; - return; - } - } - } - - int ExitGraph_FLTK(CSOUND *csound) - { - FLGRAPH_GLOBALS *flgraphGlobals = - (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, - "FLGRAPH_GLOBALS"); - if (flgraphGlobals == 0) { - return OK; - } - if (ST(form) && ST(graph_created) == 1) { - - if (ST(form)->shown() && !(getFLTKFlags(csound) & 256)) { - const char *env = csound->GetEnv(csound, "CSNOSTOP"); - if (env == NULL || strcmp(env, "yes") != 0) { - ST(end)->show(); - // print click-Exit message in most recently active window - while (ST(end)->value() == 0 && ST(form)->shown()) { - Fl_wait_locked(csound, 0.03); - } - } - } - - delete ST(form); - ST(form) = (Fl_Window *) 0; - Fl_wait_locked(csound, 0.0); - - ST(choice) = (Fl_Choice *) 0; - ST(graph) = (graph_box *) 0; - ST(end) = (Fl_Button *) 0; - ST(graph_created) = 0; - - for (int i = 0; i < NUMOFWINDOWS; i++) { - WINDAT *n = (WINDAT*) ST(menu)[i].user_data_; - if (n) - kill_graph(csound, (uintptr_t) ((void*) n)); - } - if (ST(menu)){ - delete[] ST(menu); - ST(menu) = (Fl_Menu_Item *) 0; - } - - - - } - - return 0; - } - -#define GUTTERH 20 /* space for text at top & bottom */ -#define BORDERW 10 /* inset from L & R edge */ - - void MakeXYin_FLTK(CSOUND *csound, XYINDAT *w, MYFLT x, MYFLT y) - { - if (w->windid == (uintptr_t) 0) { - Fl_Window *xyin = new Fl_Window(WIDTH, WIDTH, "XY input"); - short win_x, win_y; - short gra_x, gra_y, gra_w, gra_h; - - win_x = 0; win_y = 0; /* window pixels addressed relative */ - - Fl_lock(csound); - xyin->show(); - Fl_wait(csound, 0.0); - Fl_unlock(csound); - - /* set new width and height so we leave a 20% border around the plot */ - gra_w = xyin->w() - 2*BORDERW; gra_h = xyin->h() - 2*GUTTERH; - gra_x = win_x + BORDERW; gra_y = win_y + GUTTERH; - w->m_x = gra_x + (int) (x * (MYFLT) gra_w); - w->m_y = gra_y + (int) (y * (MYFLT) gra_h); - w->down = 0; - - Fl_lock(csound); - Fl_wait(csound, 0.0); - xyin->make_current(); - fl_color(0, 0, 0); - fl_line_style(FL_DOT); - fl_line(gra_x, w->m_y, (gra_x + gra_w), w->m_y); - fl_line(w->m_x, gra_y, w->m_x, (gra_y + gra_h)); - Fl_unlock(csound); - w->windid = (uintptr_t) xyin; - } - } - - void ReadXYin_FLTK(CSOUND *csound, XYINDAT *wdptr) - { - short win_x, win_y; - short gra_x, gra_y, gra_w, gra_h; - short m_x, m_y; - Fl_Window *xwin = (Fl_Window*) wdptr->windid; - - Fl_lock(csound); - Fl_wait(csound, 0.0); - m_x = Fl::event_x(); - m_y = Fl::event_y(); - wdptr->down = (short) (Fl::event_button1() ? 1 : 0); - Fl_unlock(csound); - - if (!wdptr->down) - return; - - win_x = 0; win_y = 0; /* window pixels addressed relative */ - - /* set new width and height so we leave a 20% border around the plot */ - gra_w = xwin->w() - 2*BORDERW; gra_h = xwin->h() - 2*GUTTERH; - gra_x = win_x + BORDERW; gra_y = win_y + GUTTERH; - - /* clip mouse position */ - if (m_x < gra_x) m_x = gra_x; - else if (m_x > gra_x+gra_w) m_x = gra_x+gra_w; - if (m_y < gra_y) m_y = gra_y; - else if (m_y > gra_y+gra_h) m_y = gra_y+gra_h; - - if (m_x != wdptr->m_x || m_y != wdptr->m_y) { /* only redo if changed */ - Fl_lock(csound); - xwin->make_current(); - /* undraw old crosshairs */ - fl_color(FL_BACKGROUND_COLOR); - fl_line_style(FL_SOLID); - fl_line(gra_x, wdptr->m_y, (gra_x + gra_w), wdptr->m_y); - fl_line(wdptr->m_x, gra_y, wdptr->m_x, (gra_y + gra_h)); - // Draw new - fl_color(0, 0, 0); - fl_line_style(FL_SOLID); - fl_line(gra_x, m_y, (gra_x + gra_w), m_y); - fl_line(m_x, gra_y, m_x, (gra_y + gra_h)); - Fl_unlock(csound); - wdptr->m_x = m_x; wdptr->m_y = m_y; - wdptr->x = ((MYFLT) m_x - gra_x) / (MYFLT) gra_w; - wdptr->y = ((MYFLT) m_y - gra_y) / (MYFLT) gra_h; - } - } - - void KillXYin_FLTK(CSOUND *csound, XYINDAT *wdptr) - { - IGN(csound); - delete ((Fl_Window*) wdptr->windid); - wdptr->windid = (uintptr_t) 0; - } -} diff --git a/6.x/src/widgets/virtual_keyboard/Bank.cpp b/6.x/src/widgets/virtual_keyboard/Bank.cpp deleted file mode 100644 index 44a10aaf..00000000 --- a/6.x/src/widgets/virtual_keyboard/Bank.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* - Bank.cpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include "Bank.hpp" - -static char* gm[] = { - (char *)"Acoustic Grand", - (char *)"Bright Acoustic", - (char *)"Electric Grand", - (char *)"Honky-Tonk", - (char *)"Electric Piano 1", - (char *)"Electric Piano 2", - (char *)"Harpsichord", - (char *)"Clavinet", - - (char *)"Celesta", - (char *)"Glockenspiel", - (char *)"Music Box", - (char *)"Vibraphone", - (char *)"Marimba", - (char *)"Xylophone", - (char *)"Tubular Bells", - (char *)"Dulcimer", - - (char *)"Drawbar Organ", - (char *)"Percussive Organ", - (char *)"Rock Organ", - (char *)"Church Organ", - (char *)"Reed Organ", - (char *)"Accoridan", - (char *)"Harmonica", - (char *)"Tango Accordian", - - (char *)"Nylon String Guitar", - (char *)"Steel String Guitar", - (char *)"Electric Jazz Guitar", - (char *)"Electric Clean Guitar", - (char *)"Electric Muted Guitar", - (char *)"Overdriven Guitar", - (char *)"Distortion Guitar", - (char *)"Guitar Harmonics", - - (char *)"Acoustic Bass", - (char *)"Electric Bass(finger)", - (char *)"Electric Bass(pick)", - (char *)"Fretless Bass", - (char *)"Slap Bass 1", - (char *)"Slap Bass 2", - (char *)"Synth Bass 1", - (char *)"Synth Bass 2", - - (char *)"Violin", - (char *)"Viola", - (char *)"Cello", - (char *)"Contrabass", - (char *)"Tremolo Strings", - (char *)"Pizzicato Strings", - (char *)"Orchestral Strings", - (char *)"Timpani", - - (char *)"String Ensemble 1", - (char *)"String Ensemble 2", - (char *)"SynthStrings 1", - (char *)"SynthStrings 2", - (char *)"Choir Aahs", - (char *)"Voice Oohs", - (char *)"Synth Voice", - (char *)"Orchestra Hit", - - (char *)"Trumpet", - (char *)"Trombone", - (char *)"Tuba", - (char *)"Muted Trumpet", - (char *)"French Horn", - (char *)"Brass Section", - (char *)"SynthBrass 1", - (char *)"SynthBrass 2", - - (char *)"Soprano Sax", - (char *)"Alto Sax", - (char *)"Tenor Sax", - (char *)"Baritone Sax", - (char *)"Oboe", - (char *)"English Horn", - (char *)"Bassoon", - (char *)"Clarinet", - - (char *)"Piccolo", - (char *)"Flute", - (char *)"Recorder", - (char *)"Pan Flute", - (char *)"Blown Bottle", - (char *)"Skakuhachi", - (char *)"Whistle", - (char *)"Ocarina", - - (char *)"Lead 1 (square)", - (char *)"Lead 2 (sawtooth)", - (char *)"Lead 3 (calliope)", - (char *)"Lead 4 (chiff)", - (char *)"Lead 5 (charang)", - (char *)"Lead 6 (voice)", - (char *)"Lead 7 (fifths)", - (char *)"Lead 8 (bass+lead)", - - (char *)"Pad 1 (new age)", - (char *)"Pad 2 (warm)", - (char *)"Pad 3 (polysynth)", - (char *)"Pad 4 (choir)", - (char *)"Pad 5 (bowed)", - (char *)"Pad 6 (metallic)", - (char *)"Pad 7 (halo)", - (char *)"Pad 8 (sweep)", - - (char *)"FX 1 (rain)", - (char *)"FX 2 (soundtrack)", - (char *)"FX 3 (crystal)", - (char *)"FX 4 (atmosphere)", - (char *)"FX 5 (brightness)", - (char *)"FX 6 (goblins)", - (char *)"FX 7 (echoes)", - (char *)"FX 8 (sci-fi)", - - (char *)"Sitar", - (char *)"Banjo", - (char *)"Shamisen", - (char *)"Koto", - (char *)"Kalimba", - (char *)"Bagpipe", - (char *)"Fiddle", - (char *)"Shanai", - - (char *)"Tinkle Bell", - (char *)"Agogo", - (char *)"Steel Drums", - (char *)"Woodblock", - (char *)"Taiko Drum", - (char *)"Melodic Tom", - (char *)"Synth Drum", - (char *)"Reverse Cymbal", - - (char *)"Guitar Fret Noise", - (char *)"Breath Noise", - (char *)"Seashore", - (char *)"Bird Tweet", - (char *)"Telephone Ring", - (char *)"Helicopter", - (char *)"Applause", - (char *)"Gunshot" -}; - -Bank::Bank(CSOUND *csound, char* bankName) : bankNum(0) { - this->name = bankName; - IGN(csound); - currentProgram = 0; - previousProgram = -1; -} - -Bank::~Bank() { - while( !programs.empty() ) { - programs.erase( programs.begin() ); - } -} - -void Bank::initializeGM() { - for(int i = 0; i < 128; i++) { - Program temp(i, gm[i]); - this->programs.push_back(temp); - } -} diff --git a/6.x/src/widgets/virtual_keyboard/Bank.hpp b/6.x/src/widgets/virtual_keyboard/Bank.hpp deleted file mode 100644 index e6e54eb6..00000000 --- a/6.x/src/widgets/virtual_keyboard/Bank.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - Bank.hpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#ifndef BANK_HPP_ -#define BANK_HPP_ - -#include -#include "csdl.h" -#include "Program.hpp" - -using namespace std; - -class Bank -{ -public: - Bank(CSOUND *csound, char *bankName); - virtual ~Bank(); - - char *name; - int bankNum; - - vector programs; - - int previousProgram; - int currentProgram; - - void initializeGM(); -}; - -#endif /*BANK_HPP_*/ diff --git a/6.x/src/widgets/virtual_keyboard/FLTKKeyboard.cpp b/6.x/src/widgets/virtual_keyboard/FLTKKeyboard.cpp deleted file mode 100644 index e56cbb53..00000000 --- a/6.x/src/widgets/virtual_keyboard/FLTKKeyboard.cpp +++ /dev/null @@ -1,547 +0,0 @@ -/* - FLTKKeyboard.cpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include -#include - -#include -#include "FLTKKeyboard.hpp" - -FLTKKeyboard::FLTKKeyboard(CSOUND *csound, SliderBank *sliderBank, - int X, int Y, int W, int H, const char *L) - : Fl_Widget(X, Y, W, H, L) { - - this->csound = csound; - this->sliderBank = sliderBank; - this->mutex = csound->Create_Mutex(0); - - FLTKKeyboard *o = this; - - o->box(FL_FLAT_BOX); - o->color(FL_BACKGROUND_COLOR); - o->selection_color(FL_BACKGROUND_COLOR); - o->labeltype(FL_NO_LABEL); - o->labelfont(0); - o->labelsize(14); - o->labelcolor(FL_FOREGROUND_COLOR); - o->user_data((void*)(this)); - o->align(FL_ALIGN_TOP); - o->when(FL_WHEN_RELEASE); - - for(int i = 0; i < 88; i++) { - keyStates[i] = 0; - changedKeyStates[i] = 0; - } - - lastMidiKey = -1; - - whiteKeys[0] = 0; - whiteKeys[1] = 2; - whiteKeys[2] = 4; - whiteKeys[3] = 5; - whiteKeys[4] = 7; - whiteKeys[5] = 9; - whiteKeys[6] = 11; - - octave = 5; - - aNotesOff = 0; -} - -FLTKKeyboard::~FLTKKeyboard() { - if (mutex) { - csound->DestroyMutex(mutex); - mutex = (void*) 0; - } -} - -void FLTKKeyboard::lock() { - if(mutex) { - csound->LockMutex(mutex); - } -} - -void FLTKKeyboard::unlock() { - if(mutex) { - csound->UnlockMutex(mutex); - } -} - -void FLTKKeyboard::allNotesOff() { - this->lock(); - - for(int i = 0; i < 88; i++) { - this->keyStates[i] = -1; - } - - this->lastMidiKey = -1; - - this->aNotesOff = 1; - - this->unlock(); - - this->redraw(); -} - -int FLTKKeyboard::getMidiValForWhiteKey(int whiteKeyNum) { - if(whiteKeyNum < 2) { - return whiteKeyNum * 2; - } - - int adjusted = whiteKeyNum - 2; - - int oct = adjusted / 7; - int key = adjusted % 7; - - return 3 + (oct * 12) + whiteKeys[key]; -} - -int FLTKKeyboard::getMIDIKey(int xVal, int yVal) { - int x = xVal - this->x(); - int y = yVal - this->y(); - - if(x > this->w()) { - return 87; - } - - if(x < 0) { - return 0; - } - - int whiteKeyHeight = this->h(); - int blackKeyHeight = (int)(whiteKeyHeight * .625); - - float whiteKeyWidth = this->w() / 52.0; - float blackKeyWidth = whiteKeyWidth * .8333333; - - float leftKeyBound = blackKeyWidth / 2.0; - float rightKeyBound = whiteKeyWidth - leftKeyBound; - - - // 52 white keys - int whiteKey = (int)(x / whiteKeyWidth); - - float extra = x - (whiteKey * whiteKeyWidth); - - if(whiteKey < 2) { - if(whiteKey == 0) { - if(y > blackKeyHeight + this->y()) { - return whiteKey; - } else { - if(extra > rightKeyBound) { - return whiteKey + 1; - } - return whiteKey; - } - } else { - if(y > blackKeyHeight) { - return getMidiValForWhiteKey(whiteKey); - } else { - if(extra < leftKeyBound) { - return getMidiValForWhiteKey(whiteKey) - 1; - } - return getMidiValForWhiteKey(whiteKey); - } - } - } - - int adjustedKey = (whiteKey - 2) % 7; - - if(adjustedKey == 0 || adjustedKey == 3) { - - if(y > blackKeyHeight) { - return getMidiValForWhiteKey(whiteKey); - } else { - if(extra > rightKeyBound) { - return getMidiValForWhiteKey(whiteKey) + 1; - } - return getMidiValForWhiteKey(whiteKey); - } - } else if(adjustedKey == 2 || adjustedKey == 6) { - if(y > blackKeyHeight) { - return getMidiValForWhiteKey(whiteKey); - } else { - if(extra < leftKeyBound) { - return getMidiValForWhiteKey(whiteKey) - 1; - } - return getMidiValForWhiteKey(whiteKey); - } - } - - if(y > blackKeyHeight) { - return getMidiValForWhiteKey(whiteKey); - } - - if(extra < leftKeyBound) { - return getMidiValForWhiteKey(whiteKey) - 1; - } - - if(extra > rightKeyBound) { - return getMidiValForWhiteKey(whiteKey) + 1; - } - - return getMidiValForWhiteKey(whiteKey); - -} - -void FLTKKeyboard::handleControl(int key) { - int index; - - switch(key) { - case '1': - index = 0; - break; - case '2': - index = 1; - break; - case '3': - index = 2; - break; - case '4': - index = 3; - break; - case '5': - index = 4; - break; - case '6': - index = 5; - break; - case '7': - index = 6; - break; - case '8': - index = 7; - break; - case '9': - index = 8; - break; - case '0': - index = 9; - break; - default: - return; - } - if(Fl::event_shift()) { - sliderBank->incrementSlider(index, -1); - } else { - sliderBank->incrementSlider(index, 1); - } - return; -} - -void FLTKKeyboard::handleKey(int key, int value) { - int index = -1; - - switch(key) { - case 'z': - index = 0; - break; - case 's': - index = 1; - break; - case 'x': - index = 2; - break; - case 'd': - index = 3; - break; - case 'c': - index = 4; - break; - case 'v': - index = 5; - break; - case 'g': - index = 6; - break; - case 'b': - index = 7; - break; - case 'h': - index = 8; - break; - case 'n': - index = 9; - break; - case 'j': - index = 10; - break; - case 'm': - index = 11; - break; - case 'q': - index = 12; - break; - case '2': - index = 13; - break; - case 'w': - index = 14; - break; - case '3': - index = 15; - break; - case 'e': - index = 16; - break; - case 'r': - index = 17; - break; - case '5': - index = 18; - break; - case 't': - index = 19; - break; - case '6': - index = 20; - break; - case 'y': - index = 21; - break; - case '7': - index = 22; - break; - case 'u': - index = 23; - break; - case 'i': - index = 24; - break; - case '9': - index = 25; - break; - case 'o': - index = 26; - break; - case '0': - index = 27; - break; - case 'p': - index = 28; - break; - default: - return; - } - - if(Fl::event_shift()) { - index += 29; - } - - // This cannot happen - // if(index < 0) { - // return; - //} - - index = ((octave * 12) + index) - 21; - - if(index < 0 || index > 87) { - return; - } - - lock(); - if(keyStates[index] != value) { - keyStates[index] = value; - } - unlock(); -} - -int FLTKKeyboard::handle(int event) { - - int key; - - switch(event) { - case FL_PUSH: - if(Fl::event_button2() || Fl::event_button3()) { - return 1; - } - - key = getMIDIKey(Fl::event_x(), Fl::event_y()); - - this->lock(); - - lastMidiKey = key; - keyStates[key] = 1; - - this->unlock(); - Fl::focus(this); - this->redraw(); - - return 1; - case FL_DRAG: - if(Fl::event_button2() || Fl::event_button3()) { - return 1; - } - key = getMIDIKey(Fl::event_x(), Fl::event_y()); - - if(key != lastMidiKey) { - - this->lock(); - - keyStates[lastMidiKey] = -1; - - if(keyStates[key] != 1) { - keyStates[key] = 1; - } - - lastMidiKey = key; - - this->unlock(); - - this->redraw(); - - } - return 1; - case FL_RELEASE: - if(Fl::event_button1()) { - return 1; - } - - key = getMIDIKey(Fl::event_x(), Fl::event_y()); - - this->lock(); - - keyStates[key] = 0; - - if(lastMidiKey >= -1) { - keyStates[lastMidiKey] = -1; - } - - lastMidiKey = -1; - - this->unlock(); - - this->redraw(); - - return 1; - case FL_MOVE: - if(lastMidiKey >= 0) { - - this->lock(); - keyStates[lastMidiKey] = 0; - lastMidiKey = -1; - this->unlock(); - - } - return 1; - case FL_KEYDOWN: - //csound->Message(csound, "Key Down: Code: %d\n", Fl::event_key()); - if(Fl::event_ctrl() && sliderBank != NULL) { - handleControl(Fl::event_key()); - } else { - handleKey(Fl::event_key(), 1); - } - Fl::focus(this); - this->redraw(); - return 1; - case FL_KEYUP: - if(Fl::focus() == this) { - //csound->Message(csound, "Key Up: Code: %d\n", Fl::event_key()); - handleKey(Fl::event_key(), -1); - this->redraw(); - return 1; - } - /* FALLTHRU */ - default: - return Fl_Widget::handle(event); - } - -} - -int FLTKKeyboard::isWhiteKey(int key) { - if(key < 3) { - return !(key % 2); - } - - int adjustedKey = (key - 3) % 12; - - switch(adjustedKey) { - case 0: - case 2: - case 4: - case 5: - case 7: - case 9: - case 11: - return 1; - } - return 0; - - -} - -void FLTKKeyboard::draw() { - int i; - - int whiteKeyHeight = this->h(); - int blackKeyHeight = (int)(whiteKeyHeight * .625); - float whiteKeyWidth = this->w() / 52.0; - int blackKeyWidth = (int)(whiteKeyWidth * .8333333); - int blackKeyOffset = blackKeyWidth / 2; - - float runningX = (float)this->x(); - int yval = this->y(); - - fl_draw_box(box(), this->x(), this->y(), this->w(), this->h(), FL_WHITE); - fl_rect(this->x(), this->y(), this->w(),this->h(), FL_BLACK); - - int lineHeight = this->y() + whiteKeyHeight - 1; - - // Draw White Keys - for(i = 0; i < 88; i++) { - if(isWhiteKey(i)) { - int newX = int(runningX + 0.5); - - if(keyStates[i] == 1) { - int newW = (int(runningX + whiteKeyWidth + 0.5) - newX); - fl_draw_box(box(), newX, yval, newW, - whiteKeyHeight - 1, FL_BLUE); - } - - runningX += whiteKeyWidth; - - fl_color(FL_BLACK); - - fl_line(newX, this->y(), newX, lineHeight); - } - } - - runningX = (float)this->x(); - - // Draw Black Keys - for(i = 0; i < 88; i++) { - if(isWhiteKey(i)) { - runningX += whiteKeyWidth; - } else { - if(keyStates[i] == 1) { - fl_draw_box(box(), (int)(runningX - blackKeyOffset), yval, - blackKeyWidth, blackKeyHeight, FL_BLUE); - } else { - fl_draw_box(box(), (int)(runningX - blackKeyOffset), yval, - blackKeyWidth, blackKeyHeight, FL_BLACK); - } - fl_rect((int)(runningX - blackKeyOffset), yval, - blackKeyWidth, blackKeyHeight, FL_BLACK); - } - } -} diff --git a/6.x/src/widgets/virtual_keyboard/FLTKKeyboard.hpp b/6.x/src/widgets/virtual_keyboard/FLTKKeyboard.hpp deleted file mode 100644 index 59d9b8bf..00000000 --- a/6.x/src/widgets/virtual_keyboard/FLTKKeyboard.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - FLTKKeyboard.hpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#ifndef FLTKKEYBOARD_HPP_ -#define FLTKKEYBOARD_HPP_ - -#include -#include -#include "csdl.h" -#include "SliderBank.hpp" - -class FLTKKeyboard : public Fl_Widget { -public: - FLTKKeyboard(CSOUND *csound, SliderBank *sliderBank, - int X, int Y, int W, int H, const char *L); - ~FLTKKeyboard(); - int handle(int event); - void draw(); - int keyStates[88]; - int changedKeyStates[88]; - int whiteKeys[7]; - void lock(); - void unlock(); - void allNotesOff(); - int aNotesOff; - int octave; -private: - int getMIDIKey(int x, int y); - int lastMidiKey; - int isWhiteKey(int key); - int getMidiValForWhiteKey(int whiteKeyNum); - void handleKey(int key, int value); - void handleControl(int key); - - CSOUND *csound; - void * mutex; - SliderBank *sliderBank; -}; - -#endif /*FLTKKEYBOARD_HPP_*/ diff --git a/6.x/src/widgets/virtual_keyboard/FLTKKeyboardWidget.cpp b/6.x/src/widgets/virtual_keyboard/FLTKKeyboardWidget.cpp deleted file mode 100644 index f5a13af1..00000000 --- a/6.x/src/widgets/virtual_keyboard/FLTKKeyboardWidget.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* - FLTKKeyboardWidget.hpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include "FLTKKeyboardWidget.hpp" - -static void allNotesOff(Fl_Widget *widget, void * v) { - IGN(widget); - FLTKKeyboardWidget *win = (FLTKKeyboardWidget *)v; - win->keyboard->allNotesOff(); -} - -static void channelChange(Fl_Widget *widget, void * v) { - Fl_Spinner *spinner = (Fl_Spinner *)widget; - FLTKKeyboardWidget *win = (FLTKKeyboardWidget *)v; - - win->lock(); - - int channel = (int)spinner->value() - 1; - - win->keyboardMapping->setCurrentChannel(channel); - - win->bankChoice->value(win->keyboardMapping->getCurrentBank()); - - win->setProgramNames(); - - win->unlock(); -} - -static void bankChange(Fl_Widget *widget, void * v) { - Fl_Choice *choice = (Fl_Choice *)widget; - FLTKKeyboardWidget *win = (FLTKKeyboardWidget *)v; - - win->lock(); - - win->keyboardMapping->setCurrentBank((int)choice->value()); - - win->setProgramNames(); - - win->unlock(); -} - -static void programChange(Fl_Widget *widget, void * v) { - Fl_Choice *choice = (Fl_Choice *)widget; - FLTKKeyboardWidget *win = (FLTKKeyboardWidget *)v; - - win->lock(); - - win->keyboardMapping->setCurrentProgram((int)choice->value()); - - win->unlock(); -} - -static void octaveChange(Fl_Widget *widget, void * v) { - Fl_Choice *choice = (Fl_Choice *)widget; - FLTKKeyboardWidget *win = (FLTKKeyboardWidget *)v; - - win->lock(); - - win->keyboard->octave = (int)choice->value() + 1; - - win->unlock(); -} - -FLTKKeyboardWidget::FLTKKeyboardWidget(CSOUND *csound, - const char *deviceMap, - int X, int Y, int w, int h) - : Fl_Group(X, Y, w, h) -{ - char octave[2]; - octave[1] = 0; - - this->csound = csound; - this->mutex = csound->Create_Mutex(0); - - this->keyboardMapping = new KeyboardMapping(csound, deviceMap); - - this->begin(); - - int baseX = this->x(); - int baseY = this->y(); - - int row1 = baseY; - int row2 = row1 + 20; - int row3 = row2 + 20; - - int x1 = (int)(baseX + ((60 / 754.0) * w)); - int x2 = (int)(baseX + ((180 / 754.0) * w)); - int x3 = (int)(baseX + ((420 / 754.0) * w)); - int x4 = (int)(baseX + ((670 / 754.0) * w)); - - int w1 = (int)((80 / 754.0) * w); - int w2 = (int)((180 / 754.0) * w); - int w3 = (int)((200 / 754.0) * w); - int w4 = (int)((80 / 754.0) * w); - - - //624, 120 - - this->channelSpinner = new Fl_Spinner(x1, row1, w1, 20, "Channel"); - channelSpinner->maximum(16); - channelSpinner->minimum(1); - this->channelSpinner->callback((Fl_Callback*) channelChange, this); - - this->bankChoice = new Fl_Choice(x2, row1, w2, 20, "Bank"); - this->programChoice = new Fl_Choice(x3, row1, w3, 20, "Program"); - this->octaveChoice = new Fl_Choice(x4, row1, w4, 20, "Octave"); - - bankChoice->clear(); - - for(unsigned int i = 0; i < keyboardMapping->banks.size(); i++) { - bankChoice->add(keyboardMapping->banks[i]->name); - } - - bankChoice->value(0); - - setProgramNames(); - - octaveChoice->clear(); - - for(unsigned int i = 1; i < 8; i++) { - octave[0] = i + 48; - octaveChoice->add(octave); - } - - octaveChoice->value(4); - - this->bankChoice->callback((Fl_Callback*)bankChange, this); - this->programChoice->callback((Fl_Callback*)programChange, this); - this->octaveChoice->callback((Fl_Callback*)octaveChange, this); - - this->allNotesOffButton = new Fl_Button(baseX, row2, w, 20, "All Notes Off"); - this->allNotesOffButton->callback((Fl_Callback*) allNotesOff, this); - - this->keyboard = new FLTKKeyboard(csound, NULL, baseX, row3, w, h - 40, - "Keyboard"); - - this->end(); - -} - -FLTKKeyboardWidget::~FLTKKeyboardWidget() { - if (mutex) { - csound->DestroyMutex(mutex); - mutex = (void*) 0; - } - delete keyboardMapping; -} - -void FLTKKeyboardWidget::setProgramNames() { - - Bank* bank = keyboardMapping->banks[keyboardMapping->getCurrentBank()]; - - programChoice->clear(); - - for( vector::iterator iter = bank->programs.begin(); - iter != bank->programs.end(); iter++ ) { - programChoice->add((*iter).name); - } - - programChoice->value(bank->currentProgram); -} - -int FLTKKeyboardWidget::handle(int event) { - switch(event) { - case FL_KEYDOWN: - return this->keyboard->handle(event); - case FL_KEYUP: - return this->keyboard->handle(event); -// case FL_DEACTIVATE: -// this->keyboard->allNotesOff(); -// csound->Message(csound, "Deactivate\n"); -// return 1; - default: -// this->csound->Message(this->csound, "Keyboard event: %d\n", event); - return Fl_Group::handle(event); - } - -} - -void FLTKKeyboardWidget::lock() { - if(mutex) { - csound->LockMutex(mutex); - } -} - -void FLTKKeyboardWidget::unlock() { - if(mutex) { - csound->UnlockMutex(mutex); - } -} diff --git a/6.x/src/widgets/virtual_keyboard/FLTKKeyboardWidget.hpp b/6.x/src/widgets/virtual_keyboard/FLTKKeyboardWidget.hpp deleted file mode 100644 index 442a7607..00000000 --- a/6.x/src/widgets/virtual_keyboard/FLTKKeyboardWidget.hpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - FLTKKeyboardWidget.hpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#ifndef FLTKKEYBOARDWIDGET_HPP_ -#define FLTKKEYBOARDWIDGET_HPP_ - -#include -#include -#include -#include -#include -#include "FLTKKeyboard.hpp" -#include "KeyboardMapping.hpp" -#include "csdl.h" - -class FLTKKeyboardWidget : public Fl_Group { -public: - FLTKKeyboardWidget(CSOUND * csound, const char *deviceMap, - int x, int y, int w, int h); - ~FLTKKeyboardWidget(); - - FLTKKeyboard *keyboard; - Fl_Button *allNotesOffButton; - Fl_Spinner *channelSpinner; - Fl_Choice *bankChoice; - Fl_Choice *programChoice; - Fl_Choice *octaveChoice; - - KeyboardMapping *keyboardMapping; - - int handle(int event); - - void lock(); - void unlock(); - - void setSelectedBank(); - void setProgramNames(); - -private: - CSOUND* csound; - void * mutex; - -}; - - -#endif /*FLTKKEYBOARDWIDGET_HPP_*/ diff --git a/6.x/src/widgets/virtual_keyboard/FLTKKeyboardWindow.cpp b/6.x/src/widgets/virtual_keyboard/FLTKKeyboardWindow.cpp deleted file mode 100644 index 1a9c18c0..00000000 --- a/6.x/src/widgets/virtual_keyboard/FLTKKeyboardWindow.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/* - FLTKKeyboardWindow.hpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include "FLTKKeyboardWindow.hpp" - -static void allNotesOff(Fl_Widget *widget, void * v) { - IGN(widget); - FLTKKeyboardWindow *win = (FLTKKeyboardWindow *)v; - win->keyboard->allNotesOff(); -} - -static void channelChange(Fl_Widget *widget, void * v) { - Fl_Spinner *spinner = (Fl_Spinner *)widget; - FLTKKeyboardWindow *win = (FLTKKeyboardWindow *)v; - - win->lock(); - - int channel = (int)spinner->value() - 1; - - win->keyboardMapping->setCurrentChannel(channel); - - win->bankChoice->value(win->keyboardMapping->getCurrentBank()); - - win->setProgramNames(); - - win->sliderBank->setChannel(channel); - - win->unlock(); -} - -static void bankChange(Fl_Widget *widget, void * v) { - Fl_Choice *choice = (Fl_Choice *)widget; - FLTKKeyboardWindow *win = (FLTKKeyboardWindow *)v; - - win->lock(); - - win->keyboardMapping->setCurrentBank((int)choice->value()); - - win->setProgramNames(); - - win->unlock(); -} - -static void programChange(Fl_Widget *widget, void * v) { - Fl_Choice *choice = (Fl_Choice *)widget; - FLTKKeyboardWindow *win = (FLTKKeyboardWindow *)v; - - win->lock(); - - win->keyboardMapping->setCurrentProgram((int)choice->value()); - - win->unlock(); -} - -static void octaveChange(Fl_Widget *widget, void * v) { - Fl_Choice *choice = (Fl_Choice *)widget; - FLTKKeyboardWindow *win = (FLTKKeyboardWindow *)v; - - win->lock(); - - win->keyboard->octave = (int)choice->value() + 1; - - win->unlock(); -} - -FLTKKeyboardWindow::FLTKKeyboardWindow(CSOUND *csound, - const char *deviceMap, - int W, int H, const char *L = 0) - : Fl_Double_Window(W, H, L) -{ - char octave[2]; - octave[1] = 0; - - this->csound = csound; - this->mutex = csound->Create_Mutex(0); - - this->keyboardMapping = new KeyboardMapping(csound, deviceMap); - - this->begin(); - - int row1 = 0; - int row2 = row1 + 150; - int row3 = row2 + 20; - int row4 = row3 + 20; - - this->sliderBank = new SliderBank(csound, 0, row1, W, 150); - - this->channelSpinner = new Fl_Spinner(60, row2, 80, 20, "Channel"); - channelSpinner->maximum(16); - channelSpinner->minimum(1); - this->channelSpinner->callback((Fl_Callback*) channelChange, this); - - this->bankChoice = new Fl_Choice(180, row2, 180, 20, "Bank"); - this->programChoice = new Fl_Choice(420, row2, 200, 20, "Program"); - this->octaveChoice = new Fl_Choice(670, row2, 80, 20, "Octave"); - - bankChoice->clear(); - - for(unsigned int i = 0; i < keyboardMapping->banks.size(); i++) { - bankChoice->add(keyboardMapping->banks[i]->name); - } - - bankChoice->value(0); - - setProgramNames(); - - octaveChoice->clear(); - - for(unsigned int i = 1; i < 8; i++) { - octave[0] = i + 48; - octaveChoice->add(octave); - } - - octaveChoice->value(4); - - this->bankChoice->callback((Fl_Callback*)bankChange, this); - this->programChoice->callback((Fl_Callback*)programChange, this); - this->octaveChoice->callback((Fl_Callback*)octaveChange, this); - - this->allNotesOffButton = new Fl_Button(0, row3, W, 20, "All Notes Off"); - this->allNotesOffButton->callback((Fl_Callback*) allNotesOff, this); - - this->keyboard = new FLTKKeyboard(csound, this->sliderBank, 0, row4, W, 80, - "Keyboard"); - - this->end(); - -} - -FLTKKeyboardWindow::~FLTKKeyboardWindow() { - if (mutex) { - csound->DestroyMutex(mutex); - mutex = (void*) 0; - } - delete keyboardMapping; -} - -void FLTKKeyboardWindow::setProgramNames() { - - Bank* bank = keyboardMapping->banks[keyboardMapping->getCurrentBank()]; - - programChoice->clear(); - - for( vector::iterator iter = bank->programs.begin(); - iter != bank->programs.end(); iter++ ) { - programChoice->add((*iter).name); - } - - programChoice->value(bank->currentProgram); -} - -int FLTKKeyboardWindow::handle(int event) { - //this->csound->Message(this->csound, "Keyboard event: %d\n", event); - - switch(event) { - case FL_KEYDOWN: - return this->keyboard->handle(event); - case FL_KEYUP: - return this->keyboard->handle(event); -// case FL_DEACTIVATE: -// this->keyboard->allNotesOff(); -// csound->Message(csound, "Deactivate\n"); -// return 1; - default: - return Fl_Double_Window::handle(event); - } - -} - -void FLTKKeyboardWindow::lock() { - if(mutex) { - csound->LockMutex(mutex); - } -} - -void FLTKKeyboardWindow::unlock() { - if(mutex) { - csound->UnlockMutex(mutex); - } -} diff --git a/6.x/src/widgets/virtual_keyboard/FLTKKeyboardWindow.hpp b/6.x/src/widgets/virtual_keyboard/FLTKKeyboardWindow.hpp deleted file mode 100644 index 7c5ce910..00000000 --- a/6.x/src/widgets/virtual_keyboard/FLTKKeyboardWindow.hpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - FLTKKeyboardWindow.hpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#ifndef FLTKKEYBOARDWINDOW_HPP_ -#define FLTKKEYBOARDWINDOW_HPP_ - -#include -#include -#include -#include -#include -#include "FLTKKeyboard.hpp" -#include "KeyboardMapping.hpp" -#include "SliderBank.hpp" -#include "csdl.h" - -class FLTKKeyboardWindow : public Fl_Double_Window { -public: - FLTKKeyboardWindow(CSOUND * csound, const char *deviceMap, - int w, int h, const char* t); - ~FLTKKeyboardWindow(); - - FLTKKeyboard *keyboard; - Fl_Button *allNotesOffButton; - Fl_Spinner *channelSpinner; - Fl_Choice *bankChoice; - Fl_Choice *programChoice; - Fl_Choice *octaveChoice; - - KeyboardMapping *keyboardMapping; - SliderBank *sliderBank; - - int handle(int event); - - void lock(); - void unlock(); - - void setSelectedBank(); - void setProgramNames(); - -private: - CSOUND* csound; - void * mutex; - -}; - - -#endif /*FLTKKEYBOARDWINDOW_HPP_*/ diff --git a/6.x/src/widgets/virtual_keyboard/KeyboardMapping.cpp b/6.x/src/widgets/virtual_keyboard/KeyboardMapping.cpp deleted file mode 100644 index a188da72..00000000 --- a/6.x/src/widgets/virtual_keyboard/KeyboardMapping.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/* - KeyboardMapping.cpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include "KeyboardMapping.hpp" -#include -#include - -#define LINELENGTH (300) - -static char *my_fgets(char *s, int n, FILE *stream) -{ - char *a = s; - if (n <= 1) return NULL; /* best of a bad deal */ - do { - int ch = getc(stream); - if (ch == EOF) { /* error or EOF */ - if (s == a) return NULL; /* no chars -> leave */ - if (ferror(stream)) a = NULL; - break; /* add NULL even if ferror(), spec says 'indeterminate' */ - } - if (ch == '\n' || ch == '\r') { /* end of line ? */ - *(s++) = '\n'; /* convert */ - if (ch == '\r') { - ch = getc(stream); - if (ch != '\n') /* Mac format */ - ungetc(ch, stream); - } - break; - } - *(s++) = ch; - } while (--n > 1); - *s = '\0'; - return a; -} - - -KeyboardMapping::KeyboardMapping(CSOUND *csound, const char *mapFileName) -{ - FILE *mapFile; - - char *mapf = strdup(mapFileName); - - void *fd = csound->FileOpen2(csound, &mapFile, CSFILE_STD, mapf, - (void *)"r", "INCDIR", CSFTYPE_OTHER_TEXT, 0); - - if (fd == NULL) { - initializeDefaults(csound); - } else { - initializeMap(csound, mapFile); - csound->FileClose(csound, fd); - } - - - - currentChannel = 0; - previousChannel = 0; - - - for(int i = 0; i < 16; i++) { - currentBank[i] = 0; - previousBank[i] = -1; - } - previousProgram = -1; -} - -KeyboardMapping::~KeyboardMapping() -{ - for(unsigned int i = 0; i < banks.size(); i++) { - delete banks[i]; - } -} - -void KeyboardMapping::initializeMap(CSOUND * csound, FILE *file) { - char buff[LINELENGTH]; - char *p; - - /* 0 = general search - * 1 = bank found but error in bank def, ignore all until next bank - */ - int state = 0; - - Bank *bank = NULL; - - while (my_fgets(buff, LINELENGTH, file)!=NULL) { - p = buff; - while (*p == ' ' || *p == '\t') p++; - - if(*p == '#') { // line comment - continue; - } if(*p == '[') { - p++; - - // cleanup current bank - if(bank != NULL) { - if(bank->programs.size() == 0) { - bank->initializeGM(); - } - } - - char *q = strstr(p, "="); - char *z = strstr(p, "]"); - - if(q == NULL || z == NULL) { - state = 1; - continue; - } - - *q = '\0'; - *z = '\0'; - - int bankNum = atoi(p) - 1; - - char *name = (char *)csound->Calloc(csound, strlen(q +1) + 1); - memcpy(name, q + 1, strlen(q + 1) + 1); - - if(bankNum >= 0 && bankNum < 16384) { - bank = new Bank(csound, name); - bank->bankNum = bankNum; - banks.push_back(bank); - - //bank->initializeGM(); - state = 0; - } else { - state = 1; - } - - } else { - if(state == 1 || bank == NULL) { - continue; - } - - char *q = strstr(p, "="); - - if(q == NULL) { - continue; - } - - *q = '\0'; - - int programNum = atoi(p) - 1; - - char *name = (char *)csound->Calloc(csound, strlen(q +1) + 1); - memcpy(name, q + 1, strlen(q + 1) + 1); - - if(programNum >= 0 && programNum < 128) { - Program program(programNum, name); - bank->programs.push_back(program); - } - } - } - -} - -void KeyboardMapping::initializeDefaults(CSOUND *csound) { - for(int i = 0; i < 128; i++) { - - char * name = (char *)csound->Calloc(csound, 9); - - sprintf(name, "Bank %d", i + 1); - - Bank *temp = new Bank(csound, name); - temp->initializeGM(); - - banks.push_back(temp); - - } -} - -int KeyboardMapping::getCurrentChannel() { - return currentChannel; -} - -int KeyboardMapping::getCurrentBank() { - return currentBank[currentChannel]; -} - -int KeyboardMapping::getPreviousBank() { - return previousBank[currentChannel]; -} - -int KeyboardMapping::getCurrentProgram() { - return banks[getCurrentBank()]->currentProgram; -} - -int KeyboardMapping::getPreviousProgram() { - return banks[getCurrentBank()]->previousProgram; -} - - -void KeyboardMapping::setCurrentChannel(int index) { - currentChannel = index; -} - -void KeyboardMapping::setCurrentBank(int index) { - currentBank[currentChannel] = index; -} - -void KeyboardMapping::setPreviousBank(int index) { - previousBank[currentChannel] = index; -} - -void KeyboardMapping::setCurrentProgram(int index) { - banks[currentBank[currentChannel]]->currentProgram = index; -} - -void KeyboardMapping::setPreviousProgram(int index) { - banks[currentBank[currentChannel]]->previousProgram = index; -} - - -int KeyboardMapping::getCurrentBankMIDINumber() { - return banks[getCurrentBank()]->bankNum; -} diff --git a/6.x/src/widgets/virtual_keyboard/KeyboardMapping.hpp b/6.x/src/widgets/virtual_keyboard/KeyboardMapping.hpp deleted file mode 100644 index 6f64c959..00000000 --- a/6.x/src/widgets/virtual_keyboard/KeyboardMapping.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - KeyboardMapping.hpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#ifndef KEYBOARDMAPPING_HPP_ -#define KEYBOARDMAPPING_HPP_ - -#include "csdl.h" -#include "Bank.hpp" -#include -#include -#include - -using namespace std; - -class KeyboardMapping { -public: - KeyboardMapping(CSOUND *csound, const char *mapFileName); - ~KeyboardMapping(); - vector banks; - - int getCurrentChannel(); - int getCurrentBank(); - int getPreviousBank(); - int getCurrentProgram(); - int getPreviousProgram(); - - void setCurrentChannel(int index); - void setCurrentBank(int index); - void setPreviousBank(int index); - void setCurrentProgram(int index); - void setPreviousProgram(int index); - - int getCurrentBankMIDINumber(); - - int previousChannel; - int previousProgram; - -private: - void initializeDefaults(CSOUND *); - void initializeMap(CSOUND *, FILE *); - - int currentChannel; - int previousBank[16]; - int currentBank[16]; -}; - -#endif /*KEYBOARDMAPPING_HPP_*/ diff --git a/6.x/src/widgets/virtual_keyboard/Program.cpp b/6.x/src/widgets/virtual_keyboard/Program.cpp deleted file mode 100644 index 6292cef4..00000000 --- a/6.x/src/widgets/virtual_keyboard/Program.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - Program.cpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include "Program.hpp" - -Program::Program(int num, char *programName) -{ - this->programNum = num; - this->name = programName; -} - diff --git a/6.x/src/widgets/virtual_keyboard/Program.hpp b/6.x/src/widgets/virtual_keyboard/Program.hpp deleted file mode 100644 index ccf6f612..00000000 --- a/6.x/src/widgets/virtual_keyboard/Program.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - Program.hpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#ifndef PROGRAM_HPP_ -#define PROGRAM_HPP_ - -class Program -{ -public: - Program(int num, char * programName); - int programNum; - char * name; -}; - -#endif /*PROGRAM_HPP_*/ diff --git a/6.x/src/widgets/virtual_keyboard/SliderBank.cpp b/6.x/src/widgets/virtual_keyboard/SliderBank.cpp deleted file mode 100644 index 921ea481..00000000 --- a/6.x/src/widgets/virtual_keyboard/SliderBank.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - SliderBank.cpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include "SliderBank.hpp" - -#include -#include - -int WheelSlider::handle(int event) { - int res = Fl_Value_Slider::handle(event); - if (event == FL_MOUSEWHEEL) { - int dy = Fl::event_dy(); - value(clamp(round(increment(value(), -dy)))); - return 1; - } - return res; -} - -static void spinnerCallback(Fl_Widget *widget, void *v) { - Fl_Spinner *spinner = (Fl_Spinner *)widget; - SliderBank *sliderBank = (SliderBank *)v; - - for(int i = 0; i < 10; i++) { - if(sliderBank->spinners[i] == spinner) { - sliderBank->lock(); - SliderData* data = sliderBank->getSliderData(); - data->controllerNumber[i] = (int)spinner->value(); - sliderBank->unlock(); - } - } -} - -static void sliderCallback(Fl_Widget *widget, void *v) { - Fl_Slider *slider = (Fl_Slider *)widget; - SliderBank *sliderBank = (SliderBank *)v; - - for(int i = 0; i < 10; i++) { - if(sliderBank->sliders[i] == slider) { - sliderBank->lock(); - SliderData* data = sliderBank->getSliderData(); - data->controllerValue[i] = (int)slider->value(); - sliderBank->unlock(); - } - } -} - -SliderBank::SliderBank(CSOUND *csound, - int X, int Y, int W, int H) - : Fl_Group(X, Y, W, H) -{ - - this->csound = csound; - this->mutex = csound->Create_Mutex(0); - - this->channel = 0; - - this->begin(); - - for(int i = 0; i < 10; i++) { - int x, y; - - if(i < 5) { - x = 10; - y = 10 + (i * 25); - } else { - x = 382; - y = 10 + ((i - 5) * 25); - } - - Fl_Spinner *spinner = new Fl_Spinner(x, y, 60, 20); - spinners[i] = spinner; - spinner->maximum(127); - spinner->minimum(0); - spinner->step(1); - spinner->value(i + 1); - spinner->callback((Fl_Callback*)spinnerCallback, this); - - - WheelSlider *slider = new WheelSlider(x + 70, y, 292, 20); - sliders[i] = slider; - slider->type(FL_HOR_SLIDER); - slider->maximum(127); - slider->minimum(0); - slider->step(1); - slider->value(0); - slider->callback((Fl_Callback*)sliderCallback, this); - } - - - this->end(); - -} - -SliderBank::~SliderBank() -{ - if (mutex) { - csound->DestroyMutex(mutex); - mutex = (void*) 0; - } -} - -void SliderBank::setChannel(int channel) { - this->channel = channel; - - SliderData data = sliderData[channel]; - - lock(); - for(int i = 0; i < 10; i++) { - spinners[i]->value(data.controllerNumber[i]); - sliders[i]->value(data.controllerValue[i]); - } - unlock(); -} - -SliderData * SliderBank::getSliderData() { - return &sliderData[channel]; -} - -void SliderBank::incrementSlider(int index, int n) { - Fl_Slider* slider = sliders[index]; - slider->value(slider->clamp(slider->round(slider->increment(slider->value(), n)))); -} - -void SliderBank::lock() { - if(mutex) { - csound->LockMutex(mutex); - } -} - -void SliderBank::unlock() { - if(mutex) { - csound->UnlockMutex(mutex); - } -} diff --git a/6.x/src/widgets/virtual_keyboard/SliderBank.hpp b/6.x/src/widgets/virtual_keyboard/SliderBank.hpp deleted file mode 100644 index b9e3c914..00000000 --- a/6.x/src/widgets/virtual_keyboard/SliderBank.hpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - SliderBank.hpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#ifndef SLIDERBANK_HPP_ -#define SLIDERBANK_HPP_ - -#include -#include -#include -#include -#include "csdl.h" -#include "SliderData.hpp" - -class WheelSlider: public Fl_Value_Slider -{ - int handle(int); -public: - WheelSlider(int x, int y, int w, int h, const char *l=0) : - Fl_Value_Slider (x,y,w,h,l) {} -}; - -class SliderBank : public Fl_Group -{ -public: - SliderBank(CSOUND *csound, int X, int Y, int W, int H); - virtual ~SliderBank(); - - CSOUND *csound; - void * mutex; - - void setChannel(int channel); - SliderData *getSliderData(); - - void incrementSlider(int index, int n); - - void lock(); - void unlock(); - - WheelSlider* sliders[10]; - Fl_Spinner* spinners[10]; - -private: - int channel; - SliderData sliderData[16]; -}; -#endif /*SLIDERBANK_HPP_*/ diff --git a/6.x/src/widgets/virtual_keyboard/SliderData.cpp b/6.x/src/widgets/virtual_keyboard/SliderData.cpp deleted file mode 100644 index a8e61423..00000000 --- a/6.x/src/widgets/virtual_keyboard/SliderData.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - SliderData.hpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include "SliderData.hpp" - -SliderData::SliderData() -{ - for(int i = 0; i < 10; i++) { - controllerNumber[i] = (i + 1); - previousControllerNumber[i] = -1; - controllerValue[i] = 0; - previousControllerValue[i] = -1; - } -} - -SliderData::~SliderData() -{ -} diff --git a/6.x/src/widgets/virtual_keyboard/SliderData.hpp b/6.x/src/widgets/virtual_keyboard/SliderData.hpp deleted file mode 100644 index 22b699be..00000000 --- a/6.x/src/widgets/virtual_keyboard/SliderData.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - SliderData.hpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#ifndef SLIDERDATA_HPP_ -#define SLIDERDATA_HPP_ - -class SliderData -{ -public: - SliderData(); - virtual ~SliderData(); - - int controllerNumber[10]; - int previousControllerNumber[10]; - int controllerValue[10]; - int previousControllerValue[10]; -}; - -#endif /*SLIDERDATA_HPP_*/ diff --git a/6.x/src/widgets/virtual_keyboard/keyboard.map b/6.x/src/widgets/virtual_keyboard/keyboard.map deleted file mode 100644 index 1bd80658..00000000 --- a/6.x/src/widgets/virtual_keyboard/keyboard.map +++ /dev/null @@ -1,41 +0,0 @@ -# Custom Keyboard Map for Virtual Keyboard -# Steven Yi -# -# USAGE -# -# When using the Virtual Keyboard, you can supply a filename for a mapping -# of banks and programs via the -M flag, for example: -# -# csound -+rtmidi=virtual -Mkeyboard.map my_project.csd -# -# INFORMATION ON THE FORMAT -# -# -lines that start with '#' are comments -# -lines that have [] start new bank definitions, -# the contents are bankNum=bankName, with bankNum=[1,16384] -# -lines following bank statements are program definitions -# in the format programNum=programName, with programNum=[1,128] -# -bankNumbers and programNumbers are defined in this file -# starting with 1, but are converted to midi values (starting -# with 0) when read -# -# NOTES -# -# -if an invalid bank definition is found, all program -# defintions that follow will be ignored until a new -# valid bank definition is found -# -if a valid bank is defined by no valid programs found -# for that bank, it will default to General MIDI program -# definitions -# -if an invalid program definition is found, it will be -# ignored - -[1=My Bank] -1=My Test Patch 1 -2=My Test Patch 2 -30=My Test Patch 30 - -[2=My Bank2] -1=My Test Patch 1(bank2) -2=My Test Patch 2(bank2) -30=My Test Patch 30(bank3) diff --git a/6.x/src/widgets/virtual_keyboard/virtual_keyboard.cpp b/6.x/src/widgets/virtual_keyboard/virtual_keyboard.cpp deleted file mode 100644 index 69176a73..00000000 --- a/6.x/src/widgets/virtual_keyboard/virtual_keyboard.cpp +++ /dev/null @@ -1,473 +0,0 @@ -/* - virtual_keyboard.cpp: - - Copyright (C) 2006 Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include "csdl.h" -#include "winFLTK.h" -#include "FLTKKeyboardWindow.hpp" -#include "FLTKKeyboardWidget.hpp" -#include "KeyboardMapping.hpp" -#include "SliderData.hpp" -#include - -static std::map keyboardWidgets; - -static FLTKKeyboardWindow *createWindow(CSOUND *csound, const char *dev) { - return new FLTKKeyboardWindow(csound, dev, - 754, 270, "Csound Virtual Keyboard"); -} - -static FLTKKeyboardWidget *createWidget(CSOUND *csound, const char *dev, - int w, int h, int x, int y) { - return new FLTKKeyboardWidget(csound, dev, x, y, w, h); -} - -static void deleteWindow(CSOUND *csound, FLTKKeyboardWindow * keyWin) { - if(keyWin == NULL) { - return; - } - Fl_lock(csound); - - keyWin->hide(); - delete keyWin; - - Fl_awake(csound); - Fl_wait(csound, 0.0); - Fl_unlock(csound); -} - -extern "C" -{ - -typedef struct { - OPDS h; - STRINGDAT *mapFileName; - MYFLT *iwidth, *iheight, *ix, *iy; -} FLVKEYBD; - - -static int OpenMidiInDevice_(CSOUND *csound, void **userData, const char *dev) -{ - - if(keyboardWidgets.find(csound) != keyboardWidgets.end()) { - return 0; - } - - FLTKKeyboardWindow *keyboard = createWindow(csound, dev); - *userData = (void *)keyboard; - - Fl_lock(csound); - keyboard->show(); - Fl_wait(csound, 0.0); - Fl_unlock(csound); - - /* report success */ - return 0; -} - -static int OpenMidiOutDevice_(CSOUND *csound, void **userData, const char *dev) -{ - IGN(csound); IGN(userData); IGN(dev); - /* report success */ - return 0; -} - -static int ReadMidiWindow(CSOUND *csound, FLTKKeyboardWindow *keyWin, - unsigned char *mbuf, int nbytes) -{ - IGN(nbytes); - int i; - Fl_lock(csound); - Fl_awake(csound); - Fl_wait(csound, 0.0); - Fl_unlock(csound); - - if(!keyWin->visible()) { - return 0; - } - - int count = 0; - - - keyWin->lock(); - - KeyboardMapping* keyboardMapping = keyWin->keyboardMapping; - - int channel = keyboardMapping->getCurrentChannel(); - - if(keyboardMapping->getCurrentBank() != - keyboardMapping->getPreviousBank()) { - - int bankNum = keyboardMapping->getCurrentBankMIDINumber(); - unsigned char msb = (unsigned char)(bankNum >> 7) & - (unsigned char)0x7F; - unsigned char lsb = (unsigned char)bankNum & - (unsigned char)0x7F; - - *mbuf++ = (unsigned char)(0xB0 + channel); // MSB - *mbuf++ = (unsigned char)0; - *mbuf++ = msb; - - *mbuf++ = (unsigned char)(0xB0 + channel); // LSB - *mbuf++ = (unsigned char)32; - *mbuf++ = lsb; - - *mbuf++ = (unsigned char)(0xC0 + channel); // Program Change - *mbuf++ = (unsigned char)keyboardMapping->getCurrentProgram(); - - count += 8; - - keyboardMapping->setPreviousBank(keyboardMapping->getCurrentBank()); - keyboardMapping->setPreviousProgram(keyboardMapping->getCurrentProgram()); - - } else if(keyboardMapping->getCurrentProgram() != - keyboardMapping->getPreviousProgram()) { - - *mbuf++ = (unsigned char)(0xC0 + channel); // Program Change - *mbuf++ = (unsigned char)keyboardMapping->getCurrentProgram(); - - count += 2; - - keyboardMapping->setPreviousProgram(keyboardMapping->getCurrentProgram()); - } - - keyWin->sliderBank->lock(); - SliderData *sliderData = keyWin->sliderBank->getSliderData(); - - for(i = 0; i < 10; i++) { - if(sliderData->controllerNumber[i] != - sliderData->previousControllerNumber[i]) { - - *mbuf++ = (unsigned char)(0xB0 + channel); - *mbuf++ = (unsigned char)sliderData->controllerNumber[i]; - *mbuf++ = (unsigned char)sliderData->controllerValue[i]; - - count += 3; - - sliderData->previousControllerNumber[i] = - sliderData->controllerNumber[i]; - - sliderData->previousControllerValue[i] = - sliderData->controllerValue[i]; - - - } else if(sliderData->controllerValue[i] != - sliderData->previousControllerValue[i]) { - - *mbuf++ = (unsigned char)(0xB0 + channel); - *mbuf++ = (unsigned char)sliderData->controllerNumber[i]; - *mbuf++ = (unsigned char)sliderData->controllerValue[i]; - - count += 3; - - sliderData->previousControllerValue[i] = - sliderData->controllerValue[i]; - } - - } - - keyWin->sliderBank->unlock(); - keyWin->unlock(); - - - keyWin->keyboard->lock(); - - int *changedKeyStates = keyWin->keyboard->changedKeyStates; - int *keyStates = keyWin->keyboard->keyStates; - - - - for(i = 0; i < 88; i++) { - if(keyStates[i] == -1) { - *mbuf++ = (unsigned char)0x90 + channel; - *mbuf++ = (unsigned char)i + 21; - *mbuf++ = (unsigned char)0; - - count += 3; - keyStates[i] = 0; - } else if(changedKeyStates[i] != keyStates[i]) { - - if(keyStates[i] == 1) { - *mbuf++ = (unsigned char)0x90 + channel; - *mbuf++ = (unsigned char)i + 21; - *mbuf++ = (unsigned char)127; - - count += 3; - - } else { - *mbuf++ = (unsigned char)0x90 + channel; - *mbuf++ = (unsigned char)i + 21; - *mbuf++ = (unsigned char)0; - - count += 3; - } - } - - changedKeyStates[i] = keyStates[i]; - } - - if(keyWin->keyboard->aNotesOff == 1) { - keyWin->keyboard->aNotesOff = 0; - *mbuf++ = (unsigned char)0xB0; - *mbuf++ = (unsigned char)123; - *mbuf++ = (unsigned char)0; - - count += 3; - } - - keyWin->keyboard->unlock(); - - return count; -} - -static int ReadMidiWidget(CSOUND *csound, FLTKKeyboardWidget *widget, - unsigned char *mbuf, int nbytes) -{ - - IGN(csound); - IGN(nbytes); - int i; - - if(!widget->visible()) { - return 0; - } - - int count = 0; - - widget->lock(); - - KeyboardMapping* keyboardMapping = widget->keyboardMapping; - - int channel = keyboardMapping->getCurrentChannel(); - - if(keyboardMapping->getCurrentBank() != - keyboardMapping->getPreviousBank()) { - - int bankNum = keyboardMapping->getCurrentBankMIDINumber(); - unsigned char msb = (unsigned char)(bankNum >> 7) & - (unsigned char)0x7F; - unsigned char lsb = (unsigned char)bankNum & - (unsigned char)0x7F; - - *mbuf++ = (unsigned char)(0xB0 + channel); // MSB - *mbuf++ = (unsigned char)0; - *mbuf++ = msb; - - *mbuf++ = (unsigned char)(0xB0 + channel); // LSB - *mbuf++ = (unsigned char)32; - *mbuf++ = lsb; - - *mbuf++ = (unsigned char)(0xC0 + channel); // Program Change - *mbuf++ = (unsigned char)keyboardMapping->getCurrentProgram(); - - count += 8; - - keyboardMapping->setPreviousBank(keyboardMapping->getCurrentBank()); - keyboardMapping->setPreviousProgram(keyboardMapping->getCurrentProgram()); - - } else if(keyboardMapping->getCurrentProgram() != - keyboardMapping->getPreviousProgram()) { - - *mbuf++ = (unsigned char)(0xC0 + channel); // Program Change - *mbuf++ = (unsigned char)keyboardMapping->getCurrentProgram(); - - count += 2; - - keyboardMapping->setPreviousProgram(keyboardMapping->getCurrentProgram()); - } - - widget->unlock(); - - widget->keyboard->lock(); - - int *changedKeyStates = widget->keyboard->changedKeyStates; - int *keyStates = widget->keyboard->keyStates; - - - - for(i = 0; i < 88; i++) { - if(keyStates[i] == -1) { - *mbuf++ = (unsigned char)0x90 + channel; - *mbuf++ = (unsigned char)i + 21; - *mbuf++ = (unsigned char)0; - - count += 3; - keyStates[i] = 0; - } else if(changedKeyStates[i] != keyStates[i]) { - - if(keyStates[i] == 1) { - *mbuf++ = (unsigned char)0x90 + channel; - *mbuf++ = (unsigned char)i + 21; - *mbuf++ = (unsigned char)127; - - count += 3; - - } else { - *mbuf++ = (unsigned char)0x90 + channel; - *mbuf++ = (unsigned char)i + 21; - *mbuf++ = (unsigned char)0; - - count += 3; - } - } - - changedKeyStates[i] = keyStates[i]; - } - - if(widget->keyboard->aNotesOff == 1) { - widget->keyboard->aNotesOff = 0; - *mbuf++ = (unsigned char)0xB0; - *mbuf++ = (unsigned char)123; - *mbuf++ = (unsigned char)0; - - count += 3; - } - - widget->keyboard->unlock(); - - return count; -} - -static int ReadMidiData_(CSOUND *csound, void *userData, - unsigned char *mbuf, int nbytes) -{ - - if(keyboardWidgets.find(csound) == keyboardWidgets.end()) { - return ReadMidiWindow(csound, - (FLTKKeyboardWindow *)userData, mbuf, nbytes); - } - - return ReadMidiWidget(csound, - keyboardWidgets[csound], mbuf, nbytes); -} - -static int WriteMidiData_(CSOUND *csound, void *userData, - const unsigned char *mbuf, int nbytes) -{ - IGN(csound);IGN(userData);IGN(mbuf);IGN(nbytes); - /* return the number of bytes written */ - return 0; -} - -static int CloseMidiInDevice_(CSOUND *csound, void *userData) -{ - - deleteWindow(csound, (FLTKKeyboardWindow *)userData); - - return 0; -} - -static int CloseMidiOutDevice_(CSOUND *csound, void *userData) -{ - IGN(csound);IGN(userData); - return 0; -} - -/* FLvkeybd Opcode */ - -static int fl_vkeybd(CSOUND *csound, FLVKEYBD *p) { - if(keyboardWidgets.find(csound) != keyboardWidgets.end()) { - csound->ErrorMsg(csound, - "FLvkeybd may only be used once in a project.\n"); - return -1; - } - - char *mapFileName = new char[MAXNAME]; - - strncpy(mapFileName, p->mapFileName->data, MAXNAME-1); - - FLTKKeyboardWidget *widget = createWidget(csound, mapFileName, - (int)*p->iwidth, (int)*p->iheight, (int)*p->ix, (int)*p->iy); - - keyboardWidgets[csound] = widget; - - delete[] mapFileName; - return OK; -} - -#define S(x) sizeof(x) - -const OENTRY widgetOpcodes_[] = { - { (char*)"FLvkeybd", S(FLVKEYBD), 0, 1, (char*)"", (char*)"Siiii", - (SUBR) fl_vkeybd, (SUBR) NULL, (SUBR) NULL }, - { NULL, 0, 0, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL,(SUBR) NULL } -}; - - -/* module interface functions */ - -PUBLIC int csoundModuleCreate(CSOUND *csound) -{ - IGN(csound); - /* nothing to do, report success */ - //csound->Message(csound, "virtual_keyboard real time MIDI plugin for Csound\n"); - return 0; -} - -PUBLIC int csoundModuleInit(CSOUND *csound) -{ - char *drv; - const OENTRY *ep = &(widgetOpcodes_[0]); - - if (csound->QueryGlobalVariable(csound, - "FLTK_Flags") == (void*) 0) { - if (csound->CreateGlobalVariable(csound, - "FLTK_Flags", sizeof(int)) != 0) - csound->Die(csound, "%s", - Str("virtual_keyboard.cpp: error allocating FLTK flags")); - } - - for ( ; ep->opname != NULL; ep++) { - if (csound->AppendOpcode(csound, ep->opname, - (int)ep->dsblksiz, (int)ep->flags, - (int)ep->thread, ep->outypes, ep->intypes, - ep->iopadr, ep->kopadr, ep->aopadr) != 0) { - csound->ErrorMsg(csound, Str("Error registering opcode '%s'"), - ep->opname); - return -1; - } - } - - drv = (char*) (csound->QueryGlobalVariable(csound, "_RTMIDI")); - if (drv == NULL) - return 0; - if (!(strcmp(drv, "virtual") == 0)) - return 0; - csound->Message(csound, "rtmidi: virtual_keyboard module enabled\n"); - csound->SetExternalMidiInOpenCallback(csound, OpenMidiInDevice_); - csound->SetExternalMidiReadCallback(csound, ReadMidiData_); - csound->SetExternalMidiInCloseCallback(csound, CloseMidiInDevice_); - csound->SetExternalMidiOutOpenCallback(csound, OpenMidiOutDevice_); - csound->SetExternalMidiWriteCallback(csound, WriteMidiData_); - csound->SetExternalMidiOutCloseCallback(csound, CloseMidiOutDevice_); - - return 0; -} - -PUBLIC int csoundModuleInfo(void) -{ - /* does not depend on MYFLT type */ - return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8)); -} - -} // END EXTERN C - diff --git a/6.x/src/widgets/widgets.cpp b/6.x/src/widgets/widgets.cpp deleted file mode 100644 index 4e5b001c..00000000 --- a/6.x/src/widgets/widgets.cpp +++ /dev/null @@ -1,6127 +0,0 @@ -/* - widgets.cpp: - - Copyright (C) 2002 Gabriel Maldonado - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#if defined(WIN32) -# include -#endif -#ifndef _MSC_VER -# include -#endif -#if !defined(_MSC_VER) -#include -#endif -#include "widglobals.h" -#include - -Fl_Font FONT_TABLE[] = { FL_HELVETICA, FL_HELVETICA, - FL_HELVETICA_BOLD, FL_HELVETICA_ITALIC, - FL_HELVETICA_BOLD_ITALIC, FL_COURIER, - FL_COURIER_BOLD, FL_COURIER_ITALIC, - FL_COURIER_BOLD_ITALIC, FL_TIMES, - FL_TIMES_BOLD, FL_TIMES_ITALIC, - FL_TIMES_BOLD_ITALIC, FL_SYMBOL, - FL_SCREEN, FL_SCREEN_BOLD, - FL_ZAPF_DINGBATS }; - -Fl_Align ALIGN_TABLE[] = { FL_ALIGN_BOTTOM, FL_ALIGN_CENTER, - FL_ALIGN_TOP, FL_ALIGN_BOTTOM, - FL_ALIGN_LEFT, FL_ALIGN_RIGHT, - FL_ALIGN_TOP_LEFT, FL_ALIGN_TOP_RIGHT, - FL_ALIGN_BOTTOM_LEFT, FL_ALIGN_BOTTOM_RIGHT }; - -Fl_Boxtype BOX_TABLE[] = { FL_FLAT_BOX, FL_FLAT_BOX, - FL_UP_BOX, FL_DOWN_BOX, - FL_THIN_UP_BOX, FL_THIN_DOWN_BOX, - FL_ENGRAVED_BOX, FL_EMBOSSED_BOX, - FL_BORDER_BOX, _FL_SHADOW_BOX, - _FL_ROUNDED_BOX, _FL_RSHADOW_BOX, - _FL_RFLAT_BOX, _FL_ROUND_UP_BOX, - _FL_ROUND_DOWN_BOX, _FL_DIAMOND_UP_BOX, - _FL_DIAMOND_DOWN_BOX,_FL_OVAL_BOX, - _FL_OSHADOW_BOX, _FL_OFLAT_BOX}; - -void widget_init(CSOUND *csound) -{ - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *) csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (widgetGlobals == NULL) { - csound->CreateGlobalVariable(csound, "WIDGET_GLOBALS", - sizeof(WIDGET_GLOBALS)); - widgetGlobals = - (WIDGET_GLOBALS *) csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - - //csound->widgetGlobals = new WIDGET_GLOBALS; - //csound->Calloc(csound, sizeof(WIDGET_GLOBALS)); - // widgetGlobals->indrag = 0; - // widgetGlobals->sldrag = 0; - // widgetGlobals->stack_count) = 0; - - widgetGlobals->FLcontrol_iheight = 15; - widgetGlobals->FLroller_iheight = 18; - widgetGlobals->FLcontrol_iwidth = 400; - widgetGlobals->FLroller_iwidth = 150; - widgetGlobals->FLvalue_iwidth = 100; - - widgetGlobals->FLcolor = -1; - widgetGlobals->FLcolor2 = -1; - // below was commented out, why? VL 24-04-08 - widgetGlobals->FLtext_size = 0; - widgetGlobals->FLtext_color = -1; - widgetGlobals->FLtext_font = -1; - // below was commented out, why? VL 24-04-08 - widgetGlobals->FLtext_align = 0; - - widgetGlobals->FL_ix = 10; - widgetGlobals->FL_iy = 10; - widgetGlobals->currentSnapGroup = 0; - widgetGlobals->last_KEY=0; - widgetGlobals->isKeyDown=0; - } -} - -extern void graphs_reset(CSOUND *csound); - -int widget_reset(CSOUND *csound, void *pp) -{ - (void) pp; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (widgetGlobals != NULL) { - widgetGlobals->AddrStack.~vector(); - widgetGlobals->allocatedStrings.~vector(); - widgetGlobals->fl_windows.~vector(); - csound->DestroyGlobalVariable(csound, "WIDGET_GLOBALS"); - } - graphs_reset(csound); - return OK; -} - -#ifndef NO_FLTK_THREADS -extern "C" { - /* called by sensevents() once in every control period */ - static void evt_callback(CSOUND *csound, widgetsGlobals_t *p) - { - /* flush any pending real time events */ - if (UNLIKELY(p->eventQueue != NULL)) { - csound->LockMutex(p->mutex_); - while (p->eventQueue != NULL) { - rtEvt_t *ep = p->eventQueue; - p->eventQueue = ep->nxt; - ep->evt.pinstance = NULL; - csound->UnlockMutex(p->mutex_); - csound->insert_score_event_at_sample(csound, &(ep->evt), - csound->GetCurrentTimeSamples(csound)); - free(ep); - csound->LockMutex(p->mutex_); - } - csound->UnlockMutex(p->mutex_); - } - /* if all windows have been closed, terminate performance */ - if (UNLIKELY(p->exit_now)) { - EVTBLK e; - memset(&e, 0, sizeof(EVTBLK)); - e.opcod = 'e'; - csound->insert_score_event_at_sample(csound, &e, - csound->GetCurrentTimeSamples(csound)); - } - } -} // extern "C" -#endif // NO_FLTK_THREADS - -// ---- IV - Aug 23 2002 ---- included file: Fl_linux_stubs.cpp - -/* - * this is a file used in the linux distribution to be able to use - * the DirectCsound 5.1 widget code by Gabriel Maldonado on linux - * systems. - * - * This code has been written by Nicola Bernardini (nicb@centrotemporeale.it) - * mostly based on ideas by Dave Phillips (dlphip@bright.net) - */ - -extern "C" { - void ButtonSched(CSOUND *csound, MYFLT *args[], int numargs) - { /* based on code by rasmus */ -#ifndef NO_FLTK_THREADS - widgetsGlobals_t *p; - /* this is still not fully thread safe... */ - /* hope that no global variable is created just while this fn is called */ - p = (widgetsGlobals_t*) csound->QueryGlobalVariable(csound, - "_widgets_globals"); - if (p != NULL) { - rtEvt_t *evt; - int i; - - /* Create the new event */ - evt = (rtEvt_t*) malloc(sizeof(rtEvt_t)); - evt->nxt = NULL; - evt->evt.pinstance = NULL; - evt->evt.strarg = NULL; evt->evt.scnt = 0; - evt->evt.opcod = (char) *args[0]; - if (evt->evt.opcod == '\0') - evt->evt.opcod = 'i'; - evt->evt.pcnt = numargs - 1; - evt->evt.p[1] = evt->evt.p[2] = evt->evt.p[3] = MYFLT(0.0); - for (i = 1; i < numargs; i++) - evt->evt.p[i] = *args[i]; - if (evt->evt.p[2] < MYFLT(0.0)) - evt->evt.p[2] = MYFLT(0.0); - /* queue event for insertion by main Csound thread */ - csound->LockMutex(p->mutex_); - if (p->eventQueue == NULL) - p->eventQueue = evt; - else { - rtEvt_t *ep = p->eventQueue; - while (ep->nxt != NULL) - ep = ep->nxt; - ep->nxt = evt; - } - csound->UnlockMutex(p->mutex_); - } - else -#endif // NO_FLTK_THREADS - { - EVTBLK e; - int i; - /* Create the new event */ - e.strarg = NULL; e.scnt = 0; - e.opcod = (char) *args[0]; - if (e.opcod == '\0') - e.opcod = 'i'; - e.pcnt = numargs - 1; - e.p[1] = e.p[2] = e.p[3] = MYFLT(0.0); - for (i = 1; i < numargs; i++) - e.p[i] = *args[i]; - if (e.p[2] < MYFLT(0.0)) - e.p[2] = MYFLT(0.0); - e.pinstance = NULL; - csound->insert_score_event_at_sample(csound, &e, - csound->GetCurrentTimeSamples(csound)); - } - } -} - -// ---- IV - Aug 23 2002 ---- included file: Fl_Knob.cxx - -// generated by Fast Light User Interface Designer (fluid) version 2.00 - -Fl_Knob::Fl_Knob(CSOUND *cs, int xx,int yy,int ww,int hh,const char *l) - : Fl_Valuator(xx,yy,ww,hh,l) -{ - csound = cs; - a1 = 35; - a2 = 325; - _type = DOTLIN; - _percent = 0.3f; - _scaleticks = 10; -} - -Fl_Knob::~Fl_Knob(void) -{ -} - -void Fl_Knob::draw(void) -{ - int ox,oy,ww,hh,side; - unsigned char rr,gg,bb; - - ox = x(); - oy = y(); - ww = w(); - hh = h(); - draw_label(); - fl_clip(ox,oy,ww,hh); - if (ww > hh) { - side = hh; - ox = ox + (ww - side) / 2; - } - else { - side = ww; - oy = oy + (hh - side) / 2; - } - side = w() > h () ? hh:ww; - int dam = damage(); - if (dam & FL_DAMAGE_ALL) { - int col = parent()->color(); - fl_color(col); - fl_rectf(ox,oy,side,side); - Fl::get_color((Fl_Color)col,rr,gg,bb); - shadow(-60,rr,gg,bb); - fl_pie(ox+9,oy+9,side-12,side-12,0,360); - draw_scale(ox,oy,side); - col = color(); - Fl::get_color((Fl_Color)col,rr,gg,bb); - shadow(15,rr,gg,bb); - fl_pie(ox+6,oy+6,side-12,side-12,40,80); - shadow(30,rr,gg,bb); - fl_pie(ox+6,oy+6,side-12,side-12,80,220); - shadow(-15,rr,gg,bb); - fl_pie(ox+6,oy+6,side-12,side-12,220,260); - shadow(-30,rr,gg,bb); - fl_pie(ox+6,oy+6,side-12,side-12,260,400); - fl_color(FL_BLACK); - fl_arc(ox+6,oy+6,side-11,side-11,0,360); - fl_color(col); - fl_pie(ox+10,oy+10,side-20,side-20,0,360); - } - else { - fl_color(color()); - fl_pie(ox+10,oy+10,side-20,side-20,0,360); - } - Fl::get_color((Fl_Color)color(),rr,gg,bb); - shadow(10,rr,gg,bb); - fl_pie(ox+10,oy+10,side-20,side-20,110,150); - fl_pie(ox+10,oy+10,side-20,side-20,290,330); - shadow(17,rr,gg,bb); - fl_pie(ox+10,oy+10,side-20,side-20,120,140); - fl_pie(ox+10,oy+10,side-20,side-20,300,320); - shadow(25,rr,gg,bb); - fl_pie(ox+10,oy+10,side-20,side-20,127,133); - fl_pie(ox+10,oy+10,side-20,side-20,307,313); - draw_cursor(ox,oy,side); - fl_pop_clip(); -} - -int Fl_Knob::handle(int event) -{ - int ox,oy,ww,hh; - - ox = x() + 10; oy = y() + 10; - ww = w() - 20; - hh = h() - 20; - switch (event) { - case FL_PUSH: - handle_push(); - return 1; // CHECKME ***JPff added this; is that right?*** - case FL_DRAG: - { - int mx = Fl::event_x()-ox-ww/2; - int my = Fl::event_y()-oy-hh/2; - if (!mx && !my) return 1; - double angle = 270-atan2((float)-my, (float)mx)*180.0/PI; - double oldangle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1; - while (angle < oldangle-180) angle += 360.0; - while (angle > oldangle+180) angle -= 360.0; - double val; - if ((a1= a1)) { - val = minimum(); - } - else if ((a1= a2) : (angle <= a2)) { - val = maximum(); - } - else { - val = minimum() + (maximum()-minimum())*(angle-a1)/(a2-a1); - } - handle_drag(clamp(round(val))); - } - return 1; - case FL_RELEASE: - handle_release(); - return 1; - default: - return 0; - } - return 0; -} - -void Fl_Knob::type(int ty) -{ - _type = ty; -} - -void Fl_Knob::shadow(const int offs,const uchar r,uchar g,uchar b) -{ - int rr,gg,bb; - - rr = r + offs; - rr = rr > 255 ? 255 : rr; - rr = rr < 0 ? 0:rr; - gg = g + offs; - gg = gg > 255 ? 255 : gg; - gg = gg < 0 ? 0 :gg ; - bb = b + offs; - bb = bb > 255 ? 255 : bb; - bb = bb < 0 ? 0 : bb; - fl_color((uchar)rr,(uchar)gg,(uchar)bb); -} - -void Fl_Knob::draw_scale(const int ox,const int oy,const int side) -{ - float x1,y1,x2,y2,rds,cx,cy,ca,sa; - - rds = side * 0.5f; - cx = ox + side * 0.5f; - cy = oy + side * 0.5f; - if (!(_type & DOTLOG_3)) { - if (_scaleticks == 0) return; - double a_step = (10.0*PI/6.0) / _scaleticks; - double a_orig = -(PI/3.0); - for (int a = 0; a <= _scaleticks; a++) { - double na = a_orig + a * a_step; - ca = cos(na); - sa = sin(na); - x1 = cx + rds * ca; - y1 = cy - rds * sa; - x2 = cx + (rds-6) * ca; - y2 = cy - (rds-6) * sa; - fl_color(FL_BLACK); - fl_line((int)x1,(int)y1,(int)x2,(int)y2); - fl_color(FL_WHITE); - if (sa*ca >=0) - fl_line((int)x1+1,(int)y1+1,(int)x2+1,(int)y2+1); - else - fl_line((int)x1+1,(int)y1-1,(int)x2+1,(int)y2-1); - } - } - else { - int nb_dec = (_type & DOTLOG_3); - for (int k = 0; k < nb_dec; k++) { - double a_step = (10.0*PI/6.0) / nb_dec; - double a_orig = -(PI/3.0) + k * a_step; - for (int a = (k) ? 2:1; a <= 10; ) { - double na = a_orig + log10((double)a) * a_step; - ca = cos(na); - sa = sin(na); - x1 = cx - rds * ca; - y1 = cy - rds * sa; - x2 = cx - (rds-6) * ca; - y2 = cy - (rds-6) * sa; - fl_color(FL_BLACK); - fl_line((int)x1,(int)y1,(int)x2,(int)y2); - fl_color(FL_WHITE); - if (sa*ca <0) - fl_line((int)x1+1,(int)y1+1,(int)x2+1,(int)y2+1); - else - fl_line((int)x1+1,(int)y1-1,(int)x2+1,(int)y2-1); - if ((a == 1) || (nb_dec == 1)) - a += 1; - else - a += 2; - } - } - } -} - -void Fl_Knob::draw_cursor(const int ox,const int oy,const int side) -{ - float rds,cur,cx,cy; - double angle; - - rds = (side - 20.0f) * 0.5f; - cur = _percent * rds * 0.5f; - cx = ox + side * 0.5f; - cy = oy + side * 0.5f; - angle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1; - fl_push_matrix(); - fl_scale(1,1); - fl_translate(cx,cy); - fl_rotate(-angle); - fl_translate(0,rds-cur-2.0f); - if (_type 1.0f) _percent = 1.0f; - if (visible()) damage(FL_DAMAGE_CHILD); -} - -void Fl_Knob::scaleticks(const int tck) -{ - _scaleticks = tck; - if (_scaleticks < 0) _scaleticks = 0; - if (_scaleticks > 31) _scaleticks = 31; - if (visible()) damage(FL_DAMAGE_ALL); -} - -// ---- IV - Aug 23 2002 ---- included file: Fl_Spin.cpp - -void Fl_Spin::draw() -{ - int sxx = x(), syy = y(), sww = w(), shh = h(); - Fl_Boxtype box1 = (Fl_Boxtype)(box()); - int border_size=Fl::box_dx(box()); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - - if (damage()&~FL_DAMAGE_CHILD) clear_damage(FL_DAMAGE_ALL); - - if (!box1) box1 = (Fl_Boxtype)(box()&-2); - - if ((widgetGlobals->indrag || mouseobj) && deltadir!=0) { - if (deltadir>0) { - draw_box(fl_down(box1),sxx,syy,sww,shh/2,color()); - draw_box(box1,sxx,syy+shh/2,sww,shh/2,color()); - } - else { - draw_box(box1,sxx,syy,sww,shh/2,color()); - draw_box(fl_down(box1),sxx,syy+shh/2,sww,shh/2,color()); - } - } - else { - draw_box(box1,sxx,syy,sww,shh/2,color()); - draw_box(box1,sxx,syy+shh/2,sww,shh/2,color()); - } - sxx+=border_size; - syy+=border_size; - sww-=border_size*2; - shh-=border_size*2; - if (active_r()) { - fl_color(selection_color()); - } - else { - fl_color(selection_color() | 8); - } - int w1 = (sww-1)|1; // use odd sizes only - int X = sxx+w1/2; - int W = w1/3; - int h1 = shh/2-border_size-2; - int Y= syy; - fl_polygon(X, Y, X+W,Y+h1 , X-W, Y+h1); - Y=syy+shh/2+border_size+1+h1; - fl_polygon(X, Y, X-W, Y-h1, X+W, Y-h1); - clear_damage(); -} - -void Fl_Spin::repeat_callback(void* v) -{ - Fl_Spin* b = (Fl_Spin*)v; - if (b->mouseobj) { - Fl::add_timeout(0.1, repeat_callback, b); - b->increment_cb(); - } -} - -void Fl_Spin::increment_cb(void) -{ - if (!mouseobj) return; - delta += deltadir; - double v; - switch (drag) { - case 3: v = increment(value(), deltadir*100); break; - case 2: v = increment(value(), deltadir*10); break; - default:v = increment(value(), deltadir); break; - } - v = round(v); - handle_drag(soft()?softclamp(v):clamp(v)); -} - -int Fl_Spin::handle(int event) -{ - double v; - int olddelta; - int mx = Fl::event_x(); - int my = Fl::event_y(); - int sxx = x(), syy = y(), sww = w(), shh = h(); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - - switch (event) { - case FL_PUSH: - // if (!step()) goto DEFAULT; - iy = my; - ix = mx; - drag = Fl::event_button(); - handle_push(); - widgetGlobals->indrag=1; - mouseobj=1; - Fl::add_timeout(0.5, repeat_callback, this); - delta=0; - if (Fl::event_inside(sxx,syy,sww,shh/2)) { - deltadir=1; - } - else if (Fl::event_inside(sxx,syy+shh/2,sww,shh/2)) { - deltadir=-1; - } - else { - deltadir=0; - } - increment_cb(); - redraw(); - return 1; - case FL_DRAG: - if (mouseobj) { - mouseobj=0; - Fl::remove_timeout(repeat_callback, this); - } - // if (!step()) goto DEFAULT; - olddelta=delta; - delta = - (Fl::event_y()-iy); - if ((delta>5) || (delta<-5)) { - deltadir=((olddelta-delta)>0)?-1:(((olddelta-delta)<0)?1:0); - } - else { - deltadir=0; delta = olddelta; - } - switch (drag) { - case 3: v = increment(value(), deltadir*100); break; - case 2: v = increment(value(), deltadir*10); break; - default:v = increment(value(), deltadir); break; - } - v = round(v); - handle_drag(soft()?softclamp(v):clamp(v)); - widgetGlobals->indrag=1; - return 1; - case FL_RELEASE: - if (mouseobj) { - Fl::remove_timeout(repeat_callback, this); - } - // if (!step()) goto DEFAULT; - widgetGlobals->indrag=0; - delta=0; - deltadir=0; - mouseobj=0; - handle_release(); - redraw(); - return 1; - default: - widgetGlobals->indrag=0; - return Fl_Valuator::handle(event); - } -} - -Fl_Spin::~Fl_Spin(void) -{ - Fl::remove_timeout(repeat_callback, this); -} - -Fl_Spin::Fl_Spin(CSOUND *cs, int x, int y, int w, int h, const char* l) - : Fl_Valuator(x,y,w,h,l) -{ - - csound = cs; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - soft_ = 0; - align(FL_ALIGN_LEFT); - ix=x; - iy=y; - drag=0; - widgetGlobals->indrag=0; - mouseobj = 0; - deltadir=0; - delta=0; - indrag=0; -} - -// ---- IV - Aug 23 2002 ---- included file: Fl_Value_Input_Spin.cpp - -void Fl_Value_Input_Spin::input_cb(Fl_Widget*, void* v) -{ - Fl_Value_Input_Spin& t = *(Fl_Value_Input_Spin*)v; - - CSOUND *csound = t.csound; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - double nv; - if (t.step()>=1.0) nv = strtol(t.input.value(), 0, 0); - else nv = csound->strtod((char*)t.input.value(), 0); - widgetGlobals->hack_o_rama1 = 1; - t.handle_push(); - t.handle_drag(nv); - t.handle_release(); - widgetGlobals->hack_o_rama1 = 0; -} - -void Fl_Value_Input_Spin::draw(void) -{ - int sxx = x(), syy = y(), sww = w(), shh = h(); - sxx += sww - buttonssize(); sww = buttonssize(); - Fl_Boxtype box1 = (Fl_Boxtype)(box()&-2); - int border_size=Fl::box_dx(box()); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - - if (damage()&~FL_DAMAGE_CHILD) input.clear_damage(FL_DAMAGE_ALL); - input.box(box()); - input.color(FL_WHITE, selection_color()); - input.redraw(); - input.clear_damage(); - sxx+=border_size; - syy+=border_size; - sww-=border_size*2; - shh-=border_size*2; - - if (!box1) box1 = (Fl_Boxtype)(box()&-2); - - if ((widgetGlobals->indrag || mouseobj) && deltadir!=0) { - if (deltadir>0) { - draw_box(fl_down(box1),sxx,syy,sww,shh/2,color()); - draw_box(box1,sxx,syy+shh/2,sww,shh/2,color()); - } - else { - draw_box(box1,sxx,syy,sww,shh/2,color()); - draw_box(fl_down(box1),sxx,syy+shh/2,sww,shh/2,color()); - } - } - else { - draw_box(box1,sxx,syy,sww,shh/2,color()); - draw_box(box1,sxx,syy+shh/2,sww,shh/2,color()); - } - sxx+=border_size; - syy+=border_size; - sww-=border_size*2; - shh-=border_size*2; - if (active_r()) { - fl_color(labelcolor()); - } - else { - fl_color(labelcolor() | 8); - } - int w1 = (sww-1)|1; // use odd sizes only - int X = sxx+w1/2; - int W = w1/3; - int h1 = shh/2-border_size-2; - int Y= syy; - fl_polygon(X, Y, X+W,Y+h1 , X-W, Y+h1); - Y=syy+shh/2+border_size+1+h1; - fl_polygon(X, Y, X-W, Y-h1, X+W, Y-h1); - clear_damage(); -} - -void Fl_Value_Input_Spin::resize(int X, int Y, int W, int H) -{ - input.resize(X,Y,W,H); - Fl_Valuator::resize(X,Y,W,H); -} - -void Fl_Value_Input_Spin::value_damage(void) -{ - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (widgetGlobals->hack_o_rama1) return; - char buf[128]; - format(buf); - input.value(buf); - input.mark(input.position()); // turn off selection highlight -} - -void Fl_Value_Input_Spin::repeat_callback(void* v) -{ - Fl_Value_Input_Spin* b = (Fl_Value_Input_Spin*)v; - if (b->mouseobj) { - Fl::add_timeout(.1, repeat_callback, b); - b->increment_cb(); - } -} - -void Fl_Value_Input_Spin::increment_cb(void) -{ - if (!mouseobj) return; - delta+=deltadir; - double v; - switch (drag) { - case 3: v = increment(value(), deltadir*100); break; - case 2: v = increment(value(), deltadir*10); break; - default:v = increment(value(), deltadir); break; - } - v = round(v); - handle_drag(soft()?softclamp(v):clamp(v)); -} - -int Fl_Value_Input_Spin::handle(int event) -{ - double v; - int olddelta; - int mx = Fl::event_x(); - int my = Fl::event_y(); - int sxx = x(), syy = y(), sww = w(), shh = h(); - sxx += sww - buttonssize(); sww = buttonssize(); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - - if (!widgetGlobals->indrag && - ( !widgetGlobals->sldrag || !((mx>=sxx && mx<=(sxx+sww)) && - (my>=syy && my<=(syy+shh)))) ) { - widgetGlobals->indrag=0; - switch(event) { - case FL_PUSH: - case FL_DRAG: - widgetGlobals->sldrag=1; - break; - case FL_FOCUS: - input.take_focus(); - break; - case FL_UNFOCUS: - redraw(); - break; - default: - widgetGlobals->sldrag=0; - } - input.type(step()>=1.0 ? FL_INT_INPUT : FL_FLOAT_INPUT); - return input.handle(event); - } - - switch (event) { - case FL_PUSH: - // if (!step()) goto DEFAULT; - iy = my; - ix = mx; - drag = Fl::event_button(); - handle_push(); - widgetGlobals->indrag=1; - mouseobj=1; - Fl::add_timeout(.5, repeat_callback, this); - delta=0; - if (Fl::event_inside(sxx,syy,sww,shh/2)) { - deltadir=1; - } - else if (Fl::event_inside(sxx,syy+shh/2,sww,shh/2)) { - deltadir=-1; - } - else { - deltadir=0; - } - increment_cb(); - redraw(); - return 1; - case FL_DRAG: - if (mouseobj) { - mouseobj=0; - Fl::remove_timeout(repeat_callback, this); - } - // if (!step()) goto DEFAULT; - olddelta=delta; - delta = - (Fl::event_y()-iy); - if ((delta>5) || (delta<-5) ) { - deltadir=((olddelta-delta)>0)?-1:(((olddelta-delta)<0)?1:0); - } - else { - deltadir=0; delta = olddelta; - } - switch (drag) { - case 3: v = increment(value(), deltadir*100); break; - case 2: v = increment(value(), deltadir*10); break; - default:v = increment(value(), deltadir); break; - } - v = round(v); - handle_drag(soft()?softclamp(v):clamp(v)); - widgetGlobals->indrag=1; - return 1; - case FL_RELEASE: - if (mouseobj) { - Fl::remove_timeout(repeat_callback, this); - } - // if (!step()) goto DEFAULT; - widgetGlobals->indrag=0; - delta=0; - deltadir=0; - mouseobj=0; - handle_release(); - redraw(); - return 1; - case FL_FOCUS: - widgetGlobals->indrag=0; - return input.take_focus(); - default: - widgetGlobals->indrag=0; - input.type(step()>=1.0 ? FL_INT_INPUT : FL_FLOAT_INPUT); - return 1; - } -} - -Fl_Value_Input_Spin::~Fl_Value_Input_Spin(void) -{ - Fl::remove_timeout(repeat_callback, this); -} - -Fl_Value_Input_Spin::Fl_Value_Input_Spin(CSOUND * cs, int x, int y, - int w, int h, const char* l) - : Fl_Valuator(x,y,w,h,l), input(x, y, w, h, 0) -{ - csound = cs; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - soft_ = 0; - // if (input.parent()) // defeat automatic-add - // ((Fl_Group*)input.parent())->remove(input); - // input.parent(this); // kludge! - this->parent()->add(input); - input.callback(input_cb, this); - input.when(FL_WHEN_CHANGED); - selection_color(input.selection_color()); - align(FL_ALIGN_LEFT); - box(input.box()); - value_damage(); - buttonssize(15); - ix = x; - iy = y; - drag = 0; - widgetGlobals->indrag = 0; - widgetGlobals->sldrag = 0; - mouseobj = 0; - deltadir = 0; - delta = 0; -} - -// ---- IV - Aug 23 2002 ---- included file: Fl_Value_Slider_Input.cpp - -void Fl_Value_Slider_Input::input_cb(Fl_Widget*, void* v) { - Fl_Value_Slider_Input& t = *(Fl_Value_Slider_Input*)v; - CSOUND *csound = t.csound; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - double nv; - if (t.step()>=1.0) nv = strtol(t.input.value(), 0, 0); - else nv = csound->strtod((char*)t.input.value(), 0); - widgetGlobals->hack_o_rama2 = 1; - t.handle_push(); - t.handle_drag(nv); - t.handle_release(); - widgetGlobals->hack_o_rama2 = 0; -} - -void Fl_Value_Slider_Input::draw(void) -{ - int sxx = x(), syy = y(), sww = w(), shh = h(); - //int bww = w(); - int X = x(), Y = y(), W = w(), H = h(); - - int border_size=Fl::box_dx(box()); - - if (horizontal()) { - //bww = textboxsize(); - sxx += textboxsize(); sww -= textboxsize(); - input.resize(X,Y,W-sww,shh); - } - else { - fl_font(input.textfont(), input.textsize()); - syy += fl_height()+(border_size+1)*2; shh -= fl_height()+(border_size+1)*2; - input.resize(X,Y,W,H-shh); - } - if (damage()&~FL_DAMAGE_CHILD) input.clear_damage(FL_DAMAGE_ALL); - input.box(box()); - input.color(FL_WHITE, selection_color()); - input.redraw(); - input.resize(X,Y,W,H); - input.clear_damage(); - // if (horizontal()) input.draw(); - clear_damage(); - draw_box(box(),sxx,syy,sww,shh,color()); - sxx+=border_size; - syy+=border_size; - sww-=border_size*2; - shh-=border_size*2; - if (border_size<2) { - sxx++; - syy++; - sww--; - shh--; - } - Fl_Slider::draw(sxx,syy,sww,shh); -} - -void Fl_Value_Slider_Input::resize(int X, int Y, int W, int H) -{ - input.resize(X,Y,W,H); - Fl_Value_Slider::resize(X,Y,W,H); -} - -void Fl_Value_Slider_Input::value_damage() -{ - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (widgetGlobals->hack_o_rama2) return; - char buf[128]; - format(buf); - input.value(buf); - input.mark(input.position()); // turn off selection highlight -} - -int Fl_Value_Slider_Input::handle(int event) -{ - int mx = Fl::event_x(); - int my = Fl::event_y(); - int sxx = x(), syy = y(), sww = w(), shh = h(); - int border_size=Fl::box_dx(box()); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (horizontal()) { - sxx += textboxsize(); sww -= textboxsize(); - } - else { - fl_font(input.textfont(), input.textsize()); - syy += fl_height()+(border_size+1)*2; shh -= fl_height()+(border_size+1)*2; - } - if ( !widgetGlobals->indrag && - ( !widgetGlobals->sldrag || !((mx>=sxx && mx<=(sxx+sww)) && - (my>=syy && my<=(syy+shh)))) ) { - widgetGlobals->indrag=0; - switch(event) { - case FL_PUSH: - case FL_DRAG: - widgetGlobals->sldrag=1; - break; - case FL_FOCUS: - input.take_focus(); - break; - case FL_UNFOCUS: - redraw(); - break; - default: - widgetGlobals->sldrag=0; - } - input.type(step()>=1.0 ? FL_INT_INPUT : FL_FLOAT_INPUT); - return input.handle(event); - } - switch (event) { - case FL_PUSH: - widgetGlobals->ix = mx; - widgetGlobals->drag = Fl::event_button(); - widgetGlobals->indrag=1; - return Fl_Slider::handle(event,sxx,syy,sww,shh); - case FL_DRAG: - widgetGlobals->indrag=1; - return Fl_Slider::handle(event,sxx,syy,sww,shh); - case FL_RELEASE: - // if (!step()) goto DEFAULT; - if (value() != previous_value() || !Fl::event_is_click()) - handle_release(); - else { - input.handle(FL_PUSH); - input.handle(FL_RELEASE); - } - widgetGlobals->indrag=0; - return 1; - case FL_FOCUS: - widgetGlobals->indrag=0; - input.take_focus(); - return Fl_Slider::handle(event,sxx,syy,sww,shh); - default: - widgetGlobals->indrag=0; - input.type(step()>=1.0 ? FL_INT_INPUT : FL_FLOAT_INPUT); - input.handle(event); - return Fl_Slider::handle(event,sxx,syy,sww,shh); - } -} - -Fl_Value_Slider_Input::Fl_Value_Slider_Input(CSOUND *cs, int x, int y, - int w, int h, const char* l) - : Fl_Value_Slider(x,y,w,h,l),input(x, y, w, h, 0) -{ - csound = cs; - soft_ = 0; - // if (input.parent()) // defeat automatic-add - // ((Fl_Group*)input.parent())->remove(input); - // input.parent(this); // kludge! - // input.callback(input_cb, this); - parent()->add(input); - // input.when(FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY); - input.when(FL_WHEN_CHANGED ); - selection_color(input.selection_color()); - input.align(FL_ALIGN_LEFT); - align(FL_ALIGN_LEFT); - textboxsize(35); - value_damage(); -} - -// ---- IV - Aug 23 2002 ---- end of included files - -//static char *GetString(CSOUND *csound, MYFLT *pname, int is_string); - -//--------------- - -static void set_butbank_value(Fl_Group *o, MYFLT value) -{ - int childr = o->children(); - Fl_Button *b; - int ival = (int) value, j, label; - - if (ival < 0 || ival >= childr || (MYFLT) ival != value) - return; - for (j = 0; j < childr; j++) { - b = (Fl_Button *) o->child(j); - label = atoi(b->label()); - if (label == ival) { - b->value(1); - b->do_callback(); - } - else - b->value(0); - } -} - -inline void FLlock() { //gab - Fl::lock(); -} - -inline void FLunlock() { //gab - Fl::unlock(); - Fl::awake((void*) 0); -} - -SNAPSHOT::SNAPSHOT (vector& valuators, int snapGroup) -{ // the constructor captures current values of all widgets - // by copying all current values from "valuators" vector (AddrSetValue) - // to the "fields" vector - is_empty = 0; - FLlock(); //<================= - int i,k; - int vsize = valuators.size(); - for (i = 0, k = 0; i < vsize && k < vsize; i++, k++) { - while (valuators[k].group != snapGroup ) { - k++; - if (UNLIKELY(k >=vsize)) goto err; - } - ADDR_SET_VALUE& v = valuators[k]; - CSOUND *csound = (CSOUND*) (((OPDS *) (v.opcode))->insdshead->csound); - string opcode_name, widg_name; - fields.resize(i+1); - if ((int) fields.size() < i+1) - fields.resize(i+1); - VALUATOR_FIELD* fld = &(fields[i]); - float val, min, max; - opcode_name = fld->opcode_name = ((OPDS *) (v.opcode))->optext->t.opcod; - if (UNLIKELY(opcode_name.c_str() == NULL)) - { - csound->InitError(csound, "%s", - Str("Invalid snapshot. Perhaps you modified " - "orchestra widget code after you saved " - "the snapshot bank.")); - goto err; - } - else if (opcode_name == "FLslider") { - FLSLIDER *p = (FLSLIDER *) (v.opcode); - fld->widg_name = p->name->data; - fld->exp = (int) *p->iexp; - min = fld->min = *p->imin; max = fld->max = *p->imax; - switch (fld->exp) { - case LIN_: - case EXP_: - val = *p->kout; - if (min < max) { - if (val < min) val=min; - else if(val>max) val=max; - } - else { - if (val < max) val=max; - else if(val>min) val=min; - } - break; - default: val = ((Fl_Valuator *)v.WidgAddress)->value(); - } - fld->value = val; - } - else if (opcode_name == "FLslidBnk" || opcode_name == "FLvslidBnk") { - FLSLIDERBANK *p = (FLSLIDERBANK *) (v.opcode); - fld->widg_name = ((STRINGDAT *)p->names)->data; - int numsliders = (int) *p->inumsliders; - fld->sldbnk = p->slider_data; - // fld->sldbnkValues = new MYFLT[numsliders]; - // widgetGlobals->allocatedStrings.push_back((char *) fld->sldbnkValues); - fld->exp = numsliders; // EXCEPTIONAL CASE! fld->exp contains the number - // of sliders and not the exponential flag - for (int j =0; j < numsliders; j++) { - switch (fld->sldbnk[j].exp) { - case LIN_: case EXP_: - val = *fld->sldbnk[j].out; - min = fld->sldbnk[j].min; max = fld->sldbnk[j].max; - if (min < max) { - if (val < min) val=min; - else if(val>max) val=max; - } - else { - if (val < max) val=max; - else if(val>min) val=min; - } - break; - default: - val = ((Fl_Valuator *) ((Fl_Group*)v.WidgAddress)-> - child(j))->value(); - } - fld->set_sldbnk(j, val); - } - } - else if (opcode_name == "FLslidBnk2" || opcode_name == "FLvslidBnk2") { - FLSLIDERBANK2 *p = (FLSLIDERBANK2 *) (v.opcode); - fld->widg_name = ((STRINGDAT *)p->names)->data; - int numsliders = (int) *p->inumsliders; - fld->sldbnk = p->slider_data; - // EXCEPTIONAL CASE! fld->exp contains the number of sliders - // and not the exponential flag - fld->exp = numsliders; - for (int j =0; j < numsliders; j++) { - switch (fld->sldbnk[j].exp) { - case LIN_: case EXP_: - val = *fld->sldbnk[j].out; - min = fld->sldbnk[j].min; max = fld->sldbnk[j].max; - if (min < max) { - if (val < min) val=min; - else if(val>max) val=max; - } - else { - if (val < max) val=max; - else if(val>min) val=min; - } - break; - default: - val = ((Fl_Valuator *) ((Fl_Group*) v.WidgAddress)->child(j))->value(); - } - fld->set_sldbnk(j, val); - } - } - else if (opcode_name == "FLknob") { - FLKNOB *p = (FLKNOB *) (v.opcode); - fld->widg_name = p->name->data; - fld->exp = (int) *p->iexp; - min = fld->min = *p->imin; max = fld->max = *p->imax; - switch (fld->exp) { - case LIN_: - case EXP_: - val = *p->kout; - if (min < max) { - if (val < min) val=min; - else if(val>max) val=max; - } - else { - if (val < max) val=max; - else if(val>min) val=min; - } - break; - default: val = ((Fl_Valuator *)v.WidgAddress)->value(); - } - fld->value = val; - } - else if (opcode_name == "FLroller") { - FLROLLER *p = (FLROLLER *) (v.opcode); - fld->widg_name = p->name->data; - fld->exp = (int) *p->iexp; - min = fld->min = *p->imin; max = fld->max = *p->imax; - switch (fld->exp) { - case LIN_: - case EXP_: - val = *p->kout; - if (min < max) { - if (val < min) val=min; - else if(val>max) val=max; - } - else { - if (val < max) val=max; - else if(val>min) val=min; - } - break; - default: val = ((Fl_Valuator *)v.WidgAddress)->value(); - } - fld->value = val; - } - else if (opcode_name == "FLtext") { - FLTEXT *p = (FLTEXT *) (v.opcode); - fld->widg_name = p->name->data; - val = *p->kout; min = fld->min = *p->imin; max = fld->max = *p->imax; - if (min < max) { - if (val < min) val=min; - else if(val>max) val=max; - } - else { - if (val < max) val=max; - else if(val>min) val=min; - } - fld->value = val; - fld->exp = LIN_; - } - else if (opcode_name == "FLjoy") { - FLJOYSTICK *p = (FLJOYSTICK *) (v.opcode); - fld->widg_name = p->name->data; - fld->exp = (int) *p->iexpx; - min = fld->min = *p->iminx; max = fld->max = *p->imaxx; - switch (fld->exp) { - case LIN_: - case EXP_: - val = *p->koutx; - if (min < max) { - if (val < min) val=min; - else if(val>max) val=max; - } - else { - if (val < max) val=max; - else if(val>min) val=min; - } - break; - default: - val = ((Fl_Positioner *)v.WidgAddress)->xvalue(); - } - fld->value = val; - fld->exp2 = (int) *p->iexpy; - min = fld->min2 = *p->iminy; max = fld->max2 = *p->imaxy; - switch (fld->exp2) { - case LIN_: case EXP_: - val = *p->kouty; - if (min < max) { - if (val < min) val=min; - else if(val>max) val=max; - } - else { - if (val < max) val=max; - else if(val>min) val=min; - } - break; - default: - val = ((Fl_Positioner *)v.WidgAddress)->yvalue(); - } - fld->value2 =val; - } - else if (opcode_name == "FLbutton") { - FLBUTTON *p = (FLBUTTON *) (v.opcode); - fld->widg_name = p->name->data; - fld->value = *p->kout; - fld->min = 0; fld->max = 1; fld->exp = LIN_; - } - else if (opcode_name == "FLbutBank") { - FLBUTTONBANK *p = (FLBUTTONBANK *) (v.opcode); - fld->widg_name = Str("No name for FLbutbank"); - //fld->widg_name = GetString(csound, p->name, p->XSTRCODE); - fld->value = *p->kout; - fld->min = 0; fld->max = 1; fld->exp = LIN_; - } - else if (opcode_name == "FLcount") { - FLCOUNTER *p = (FLCOUNTER *) (v.opcode); - fld->widg_name = p->name->data; - val = *p->kout; min = *p->imin; max =*p->imax; - if (min != max) { - if (val < min) val=min; - else if (val>max) val=max; - } - fld->value = val; - fld->min = *p->imin; fld->max = *p->imax; fld->exp = LIN_; - } - else if (opcode_name == "FLvalue") { - FLVALUE *p = (FLVALUE *) (v.opcode); - fld->widg_name = p->name->data; - } - else if (opcode_name == "FLbox") { - FL_BOX *p = (FL_BOX *) (v.opcode); - fld->widg_name = p->itext->data; - } - } - FLunlock(); - return; - err: - FLunlock(); //<================= - is_empty = 1; -} - -int SNAPSHOT::get(vector& valuators, int snapGroup) -{ - if (UNLIKELY(is_empty == 1)) { - /* FIXME: should have CSOUND* pointer here */ - /* return csound->InitError(csound, "%s", Str("empty snapshot")); */ - //printf("SNAPSHOT IS EMPTY\n"); - return -1; - } - FLlock(); //<================= - int j,k; - int siz =valuators.size(); - for (j = 0, k = 0; j< siz && k < siz; j++, k++) { - // int grp = valuators[k].group; //Not used - while (valuators[k].group != snapGroup) { - k++; - if (k >= (int) valuators.size()) goto end_func; - } - Fl_Widget* o = (Fl_Widget*) (valuators[k].WidgAddress); - void *opcode = valuators[k].opcode; -//CSOUND *csound = (CSOUND*) (((OPDS*) opcode)->insdshead->csound); //Not used - VALUATOR_FIELD* fld = &fields[j]; - string opcode_name = fld->opcode_name; - - MYFLT val = fld->value, valtab = fld->value, min=fld->min, - max=fld->max, range,base; - if (min < max) { - if (val < min) val = min; - else if (val >max) val = max; - } - else { - if (val < max) val=max; - else if(val>min) val=min; - } - - if (opcode_name == "FLjoy") { - switch(fld->exp) { - case LIN_: - ((Fl_Positioner*) o)->xvalue(val); - break; - case EXP_: - range = fld->max - fld->min; - #if defined(sun) - base = ::pow(fld->max / (double)fld->min, 1.0/(double)range); - #else - base = ::pow(fld->max / fld->min, 1.0/(double)range); - #endif - ((Fl_Positioner*) o)->xvalue(log(val/fld->min) / log(base)) ; - break; - default: - ((Fl_Positioner*) o)->xvalue(valtab); - break; - } - val = fld->value2; min = fld->min2; max = fld->max2; - // if (val < min) val = min; - // else if (val >max) val = max; - switch(fld->exp2) { - case LIN_: - ((Fl_Positioner*) o)->yvalue(val); - break; - case EXP_: - range = fld->max2 - fld->min2; - #if defined(sun) - base = ::pow(fld->max2 / (double)fld->min2, 1.0/(double)range); - #else - base = ::pow(fld->max2 / fld->min2, 1.0/(double)range); - #endif - ((Fl_Positioner*) o)->yvalue(log(val/fld->min2) / log(base)) ; - break; - default: - ((Fl_Positioner*) o)->yvalue(valtab); - break; - } - o->do_callback(o, opcode); - } - else if (opcode_name == "FLbutton") { - FLBUTTON *p = (FLBUTTON*) (opcode); - // don't allow to retreive its value if >= 10 or between 21 and 29 - if ((*p->itype < 10) || (*p->itype < 30 && *p->itype > 20)) { - if(fld->value >= *p->ioff - 0.0001 && - fld->value <= *p->ioff + 0.0001) // to avoid eventual math rounding - ((Fl_Button*) o)->value(0); - else - if (fld->value >= *p->ion - 0.0001 && - fld->value <= *p->ion + 0.0001) // to avoid eventual math rounding - ((Fl_Button*) o)->value(1); - else - ((Fl_Button*) o)->value((int)fld->value); - o->do_callback(o, opcode); - } - } - else if (opcode_name == "FLbutBank") { - FLBUTTONBANK *p = (FLBUTTONBANK*) (opcode); - if (*p->itype < 10 || (*p->itype < 30 && *p->itype > 20)) { - // don't allow to retreive its value if >= 10 - //((Fl_Group*) o)->value(fld->value); - set_butbank_value((Fl_Group*) o, fld->value); - //o->do_callback(o, opcode); - *p->kout=fld->value; - if (*p->args[0] >= 0) ButtonSched(p->h.insdshead->csound, - p->args, p->INOCOUNT-7); - } - } - else if (opcode_name == "FLcount") { - FLCOUNTER *p = (FLCOUNTER*) (opcode); - if (*p->itype < 10 || (*p->itype < 30 && *p->itype > 20)) { - // don't allow to retreive its value if >= 10 - ((Fl_Counter*) o)->value(fld->value); - o->do_callback(o, opcode); - } - } - else if (opcode_name == "FLslidBnk" || opcode_name == "FLvslidBnk") { - FLSLIDERBANK *p = (FLSLIDERBANK*) (opcode); - int numsliders = (int) *p->inumsliders; - Fl_Group * grup = (Fl_Group *) o; - for (int j =0; j < numsliders; j++) { - MYFLT val = fld->get_sldbnk(j); - switch (p->slider_data[j].exp) { - case LIN_: - ((Fl_Valuator *) grup->child(j))->value(val); - break; - case EXP_: - range = p->slider_data[j].max - p->slider_data[j].min; - #if defined(sun) - base = ::pow(p->slider_data[j].max / (double)p->slider_data[j].min, - 1.0/(double)range); - #else - base = ::pow(p->slider_data[j].max / p->slider_data[j].min, - 1.0/(double)range); - #endif - ((Fl_Valuator*) grup->child(j))-> - value(log(val/p->slider_data[j].min) / log(base)) ; - break; - default:// TABLE the value must be in the 0 to 1 range... - val = (val - fld->min ) / (fld->max - fld->min); - ((Fl_Valuator *) grup->child(j))->value(val); - break; - } - grup->child(j)->do_callback( grup->child(j), - (void *) &(p->slider_data[j])); - } - } - else if (opcode_name == "FLslidBnk2" || opcode_name == "FLvslidBnk2") { - FLSLIDERBANK2 *p = (FLSLIDERBANK2*) (opcode); - int numsliders = (int) *p->inumsliders; - Fl_Group * grup = (Fl_Group *) o; - for (int j =0; j < numsliders; j++) { - MYFLT val = fld->get_sldbnk(j); - switch (p->slider_data[j].exp) { - case LIN_: - ((Fl_Valuator *) grup->child(j))->value(val); - break; - case EXP_: - range = p->slider_data[j].max - p->slider_data[j].min; - base = pow(p->slider_data[j].max / p->slider_data[j].min, 1/range); - ((Fl_Valuator*) grup->child(j))->value(log(val/p->slider_data[j].min) / - log(base)) ; - break; - default:// TABLE the value must be in the 0 to 1 range... - val = (val - fld->min ) / (fld->max - fld->min); - ((Fl_Valuator *) grup->child(j))->value(val); - break; - } - grup->child(j)->do_callback( grup->child(j), - (void *) &(p->slider_data[j])); - } - } - else { - switch(fld->exp) { - case LIN_: - if (opcode_name == "FLbox" || opcode_name == "FLvalue" ) continue; - else if (opcode_name == "FLtext" && - *((FLTEXT *)opcode)->itype == 1) { - ((Fl_Valuator*) o)->value(val); - continue; - } - ((Fl_Valuator*) o)->value(val); - break; - case EXP_: - range = fld->max - fld->min; - #if defined(sun) - base = ::pow(fld->max / (double)fld->min, 1.0/(double)range); - #else - base = ::pow(fld->max / fld->min, 1.0/(double)range); - #endif - ((Fl_Valuator*) o)->value(log(val/fld->min) / log(base)) ; - break; - default: // TABLE the value must be in the 0 to 1 range... - ((Fl_Valuator*) o)->value(valtab); - break; - } - o->do_callback(o, opcode); - } - } - end_func: - FLunlock(); //<================= - return OK; -} - -extern "C" { - - static int set_snap(CSOUND *csound, FLSETSNAP *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - SNAPSHOT snap(widgetGlobals->AddrSetValue, (int) *p->group ); - int numfields = snap.fields.size(); - int index = (int) *p->index; - int group = (int) *p->group; - SNAPVEC snapvec_init; - SNAPSHOT snap_init; - - snap_init.fields.resize(1,VALUATOR_FIELD()); - snapvec_init.resize(1,snap_init); - if (group+1 > (int) widgetGlobals->snapshots.size()) - widgetGlobals->snapshots.resize(group+1, snapvec_init); - // *p->inum_snap = widgetGlobals->snapshots.size(); - *p->inum_val = numfields; // number of snapshots - if (*p->ifn >= 1) { // if the table number is valid - FUNC *ftp; // store the snapshot into the table - if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) { - MYFLT *table = ftp->ftable; - for (int j = 0; j < numfields; j++) { - table[index*numfields+j] = snap.fields[j].value; - } - } - else return csound->InitError(csound, - "%s", Str("FLsetsnap: invalid table")); - } - else { // else store it into snapshot bank - if ((int) widgetGlobals->snapshots[group].size() < index+1) - widgetGlobals->snapshots[group].resize(index+1); - csound->Message(csound, "%s", Str("setsnap saving\n")); - widgetGlobals->snapshots[group][index]=snap; - *p->inum_snap = widgetGlobals->snapshots[group].size(); - } - return OK; - } - - static int get_snap(CSOUND *csound, FLGETSNAP *p) - { - int index = (int) *p->index; - int group = (int) *p->group; - SNAPVEC snapvec_init; - SNAPSHOT snap_init; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - snap_init.fields.resize(1,VALUATOR_FIELD()); - snapvec_init.resize(1,snap_init); - if (group+1 > (int) widgetGlobals->snapshots.size()) - widgetGlobals->snapshots.resize(group+1, snapvec_init); - if (!widgetGlobals->snapshots[group].empty()) { - if (index >= (int) widgetGlobals->snapshots[group].size()) - index = widgetGlobals->snapshots[group].size()-1; - else if (index < 0) index=0; - if (widgetGlobals->snapshots[group][index].get(widgetGlobals->AddrSetValue, - (int) *p->group)!=OK) { - csound->Warning(csound, "could not get snapshot from group %d index %d \n", - group, index); - return OK; - } - } - *p->inum_el = widgetGlobals->snapshots[group].size(); - return OK; - } - - static int save_snap(CSOUND *csound, FLSAVESNAPS *p) - { - char s[MAXNAME], *s2; - string filename; -#ifdef WIN32 - int id = MessageBox(NULL, Str("Saving could overwrite the old file.\n" - "Are you sure to save ?"), Str("Warning"), - MB_SYSTEMMODAL | MB_ICONWARNING | MB_OKCANCEL); - if (id != IDOK) - return OK; -#else -# if !defined(NO_FLTK_THREADS) - if (!((getFLTKFlags(csound) & 260) ^ 4)) -# endif - { - int n; - Fl_lock(csound); - n = fl_choice("%s", Str("Saving could overwrite the old file.\n" - "Are you sure you want to save ?"), - Str("No"), Str("Yes"), (const char*)""); // used to be NULL - Fl_unlock(csound); - if (!n) - return OK; - } -#endif - csound->strarg2name(csound, s, p->filename->data, "snap.", 1); - s2 = csound->FindOutputFile(csound, s, "SNAPDIR"); - if (UNLIKELY(s2 == NULL)) - return csound->InitError(csound,"%s", - Str("FLsavesnap: cannot open file")); - strncpy(s, s2, MAXNAME-1); - csound->Free(csound, s2); - filename = s; - - fstream file(filename.c_str(), ios::out); - int group = (int) *p->group; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - for (int j =0; j < (int) widgetGlobals->snapshots[group].size(); j++) { - file << "----------- "<< j << " -----------\n"; - int siz = widgetGlobals->snapshots[group][j].fields.size(); - for ( int k = 0; k < siz; k++) { - VALUATOR_FIELD& f = widgetGlobals->snapshots[group][j].fields[k]; - // if (f.group != group) continue; - if (f.opcode_name == "FLjoy") { - file <QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - csound->strarg2name(csound, s, p->filename->data, "snap.", 1); - s2 = csound->FindInputFile(csound, s, "SNAPDIR"); - if (UNLIKELY(s2 == NULL)) - return csound->InitError(csound, - "%s", Str("FLloadsnap: cannot open file")); - strncpy(s, s2, MAXNAME-1); - csound->Free(csound, s2); - filename = s; - - fstream file(filename.c_str(), ios::in); - int group = (int) *p->group; - int j=0,k=-1,q=0; - SNAPVEC snapvec_init; - SNAPSHOT snap_init; - snap_init.fields.resize(1,VALUATOR_FIELD()); - snapvec_init.resize(1,snap_init); - if (group+1 > (int) widgetGlobals->snapshots.size()) - widgetGlobals->snapshots.resize(group+1, snapvec_init); - while (!(file.eof())) { - char buf[MAXNAME]; - file.getline(buf,MAXNAME-1); - - stringstream sbuf; - sbuf << buf; - - string opc, opc_orig; - getline(sbuf, opc, ' '); - const char *ss = opc.c_str(); - if (*ss == '-') { // if it is a separation line - k++; j=0; q=0; - if ((int) widgetGlobals->snapshots[group].size() < k+1) - widgetGlobals->snapshots[group].resize(k+1); - } - else if (*ss != '\0' && *ss != ' ' && *ss != '\n'){ //ignore blank lines - ADDR_SET_VALUE* v = &(widgetGlobals->AddrSetValue[q]); - while (widgetGlobals->AddrSetValue[q].group != group) { - q++; - if (q >= (int) widgetGlobals->AddrSetValue.size()) continue; - v = &(widgetGlobals->AddrSetValue[q]); - } - if (k<0) return NOTOK; - if ((int) widgetGlobals->snapshots[group][k].fields.size() < j+1) - widgetGlobals->snapshots[group][k].fields.resize(j+1); - widgetGlobals->snapshots[group][k].is_empty = 0; - VALUATOR_FIELD& fld = widgetGlobals->snapshots[group][k].fields[j]; - opc_orig = ((OPDS *) (v->opcode))->optext->t.opcod; - - if (UNLIKELY(!(opc_orig == opc))) { - //return csound->InitError(csound, - csound->Message(csound, - "%s", Str("unmatched widget, probably due to a " - "modified orchestra. Modifying an " - "orchestra makes it incompatible with " - "old snapshot files")); - } - else if (opc == "FLjoy") { - fld.opcode_name = opc; - string s; - getline(sbuf,s, ' '); fld.value = atof(s.c_str()); - getline(sbuf,s, ' '); fld.value2 = atof(s.c_str()); - getline(sbuf,s, ' '); fld.min = atof(s.c_str()); - getline(sbuf,s, ' '); fld.max = atof(s.c_str()); - getline(sbuf,s, ' '); fld.min2 = atof(s.c_str()); - getline(sbuf,s, ' '); fld.max2 = atof(s.c_str()); - getline(sbuf,s, ' '); fld.exp = atoi(s.c_str()); - getline(sbuf,s, ' '); fld.exp2 = atoi(s.c_str()); - getline(sbuf,s, '\"'); - getline(sbuf,s, '\"'); fld.widg_name = s; - } - else if (opc == "FLslidBnk" || opc == "FLvslidBnk" - || opc == "FLslidBnk2" || opc == "FLvslidBnk2" ) { - fld.opcode_name = opc; - string s; - getline(sbuf,s, ' '); - // EXCEPTIONAL CASE! fld.exp contains the number of sliders - // and not the exponential flag - fld.exp = atoi(s.c_str()); - // fld.sldbnkValues = new MYFLT[fld.exp]; - // fld.insert_sldbnk(fld.exp); - // allocatedStrings.push_back((char *) fld.sldbnkValues); - // widgetGlobals->allocatedStrings.push_back((char *) fld.sldbnkValues); - - for (int kk =0; kk < fld.exp; kk++) { - getline(sbuf,s, ' '); - // fld.sldbnkValues[kk] = atof(s.c_str()); - fld.set_sldbnk(kk,atof(s.c_str())); - - } - getline(sbuf,s, '\"'); - getline(sbuf,s, '\"'); fld.widg_name = s; - } - else { - fld.opcode_name = opc; - string s; - getline(sbuf,s, ' '); fld.value = atof(s.c_str()); - getline(sbuf,s, ' '); fld.min = atof(s.c_str()); - getline(sbuf,s, ' '); fld.max = atof(s.c_str()); - getline(sbuf,s, ' '); fld.exp = atoi(s.c_str()); - getline(sbuf,s, '\"'); - getline(sbuf,s, '\"'); fld.widg_name = s; - } - j++; q++; - } - } - - file.close(); - return OK; - } - - static int fltkKeyboardCallback(void *, void *, unsigned int); - -} // extern "C" - -// ----------- - -/* unused -static char *GetString(CSOUND *csound, MYFLT *pname, int is_string) -{ - char *Name = new char[MAXNAME]; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - widgetGlobals->allocatedStrings.push_back(Name); - return csound->strarg2name(csound, Name, pname, "", is_string); -} -*/ - -class CsoundFLTKKeyboardBuffer { -private: - CSOUND *csound; - WIDGET_GLOBALS *widgetGlobals; - void *mutex_; - char kbdTextBuf[64]; - int kbdEvtBuf[64]; - int kbdTextBufRPos; - int kbdTextBufWPos; - int kbdEvtBufRPos; - int kbdEvtBufWPos; - std::map keyboardState; - void lockMutex() - { - if (mutex_) - csound->LockMutex(mutex_); - } - void unlockMutex() - { - if (mutex_) - csound->UnlockMutex(mutex_); - } -public: - CsoundFLTKKeyboardBuffer(CSOUND *csound) - { - this->csound = csound; - widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - mutex_ = csound->Create_Mutex(0); - kbdTextBufRPos = 0; - kbdTextBufWPos = 0; - kbdEvtBufRPos = 0; - kbdEvtBufWPos = 0; - } - ~CsoundFLTKKeyboardBuffer() - { - if (mutex_) { - csound->DestroyMutex(mutex_); - mutex_ = (void*) 0; - } - } - CSOUND *GetCsound() - { - return csound; - } - void writeFLEvent(int evt) - { - const char *s; - int keyCode; - keyCode = (int) Fl::event_key() & (int) 0xFFFF; - if (keyCode) { - lockMutex(); - if (evt == FL_KEYDOWN) { - s = Fl::event_text(); - while (*s != (char) 0) { - kbdTextBuf[kbdTextBufWPos] = *(s++); - kbdTextBufWPos = (kbdTextBufWPos + 1) & 63; - } - if (keyboardState[keyCode] == (unsigned char) 0) { - keyboardState[keyCode] = (unsigned char) 1; - kbdEvtBuf[kbdEvtBufWPos] = keyCode; - kbdEvtBufWPos = (kbdEvtBufWPos + 1) & 63; - } - } - else if (keyboardState[keyCode] != (unsigned char) 0) { - keyboardState[keyCode] = (unsigned char) 0; - kbdEvtBuf[kbdEvtBufWPos] = keyCode | (int) 0x10000; - kbdEvtBufWPos = (kbdEvtBufWPos + 1) & 63; - } - unlockMutex(); - } - } - int getKeyboardText() - { - int retval = 0; - lockMutex(); - if (kbdTextBufRPos != kbdTextBufWPos) { - retval = (int) ((unsigned char) kbdTextBuf[kbdTextBufRPos]); - kbdTextBufRPos = (kbdTextBufRPos + 1) & 63; - } - unlockMutex(); - return retval; - } - int getKeyboardEvent() - { - int retval = 0; - lockMutex(); - if (kbdEvtBufRPos != kbdEvtBufWPos) { - retval = kbdEvtBuf[kbdEvtBufRPos]; - kbdEvtBufRPos = (kbdEvtBufRPos + 1) & 63; - } - unlockMutex(); - return retval; - } -}; - -class CsoundFLWindow : public Fl_Double_Window { -public: - CSOUND *csound_; //gab - WIDGET_GLOBALS *widgetGlobals; - CsoundFLTKKeyboardBuffer fltkKeyboardBuffer; - CsoundFLWindow(CSOUND *csound, int w, int h, const char *title = 0) - : Fl_Double_Window(w, h, title), - csound_(csound), - fltkKeyboardBuffer(csound)//gab - { - widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - csound->Set_KeyCallback(csound, fltkKeyboardCallback, (void*) this, - CSOUND_CALLBACK_KBD_EVENT | CSOUND_CALLBACK_KBD_TEXT); - } - CsoundFLWindow(CSOUND *csound, - int x, int y, int w, int h, const char *title = 0) - : Fl_Double_Window(x, y, w, h, title), - csound_(csound), - fltkKeyboardBuffer(csound)//gab - { - widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - csound->Set_KeyCallback(csound, fltkKeyboardCallback, (void*) this, - CSOUND_CALLBACK_KBD_EVENT | CSOUND_CALLBACK_KBD_TEXT); - } - virtual ~CsoundFLWindow() - { - CSOUND *csound = fltkKeyboardBuffer.GetCsound(); - csound->Remove_KeyCallback(csound, fltkKeyboardCallback); - } - virtual int handle(int evt) - { - switch (evt) { - case FL_FOCUS: - Fl::focus(this); - /* FALLTHRU */ - case FL_UNFOCUS: - return 1; - case FL_KEYDOWN: - widgetGlobals->last_KEY = Fl::event_key(); //gab - widgetGlobals->isKeyDown = true; //gab - break; - case FL_KEYUP: - widgetGlobals->last_KEY = Fl::event_key(); //gab - widgetGlobals->isKeyDown = false; //gab - if (Fl::focus() == this) - fltkKeyboardBuffer.writeFLEvent(evt); - break; - } - return Fl_Window::handle(evt); - } -}; - -extern "C" -{ - static int fltkKeyboardCallback(void *userData, void *p, unsigned int type) - { - switch (type) { - case CSOUND_CALLBACK_KBD_EVENT: - *((int*) p) = - ((CsoundFLWindow*) userData)->fltkKeyboardBuffer.getKeyboardEvent(); - break; - case CSOUND_CALLBACK_KBD_TEXT: - *((int*) p) = - ((CsoundFLWindow*) userData)->fltkKeyboardBuffer.getKeyboardText(); - break; - default: - return 1; - } - return 0; - } - - PUBLIC int csoundModuleDestroy(CSOUND *csound) - { - int j; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); -#ifndef NO_FLTK_THREADS - int *fltkflags = getFLTKFlagsPtr(csound); - if (fltkflags) { - if ((*fltkflags & 260) ^ 4) { - widgetsGlobals_t *p = - (widgetsGlobals_t*) csound->QueryGlobalVariable(csound, - "_widgets_globals"); - if (p) { - if (!(*fltkflags & 256)) { - /* if window(s) still open: */ - if (!p->exit_now) { - /* notify GUI thread... */ - p->end_of_perf = -1; - Fl_lock(csound); - Fl_awake(csound); - Fl_unlock(csound); - /* ...and wait for it to close */ - csound->JoinThread(p->threadHandle); - p->threadHandle = NULL; - } - } - /* clean up */ - csound->LockMutex(p->mutex_); - while (p->eventQueue != NULL) { - rtEvt_t *nxt = p->eventQueue->nxt; - free(p->eventQueue); - p->eventQueue = nxt; - } - csound->UnlockMutex(p->mutex_); - csound->DestroyMutex(p->mutex_); - csound->DestroyGlobalVariable(csound, "_widgets_globals"); - } - } - } -#endif // NO_FLTK_THREADS - if(widgetGlobals != NULL) { - for (j = widgetGlobals->allocatedStrings.size() - 1; j >= 0; j--) { - delete[] widgetGlobals->allocatedStrings[j]; - widgetGlobals->allocatedStrings.pop_back(); - } - j = widgetGlobals->fl_windows.size(); - if (j > 0) { - // destroy all opened panels - do { - j--; - if (widgetGlobals->fl_windows[j].is_subwindow == 0) - delete widgetGlobals->fl_windows[j].panel; - // VL: this might leak memory, needs checking. - widgetGlobals->fl_windows.pop_back(); - } while (j); - Fl_wait_locked(csound, 0.0); - } - widgetGlobals->AddrStack.~vector(); - widgetGlobals->allocatedStrings.~vector(); - widgetGlobals->fl_windows.~vector(); - for (size_t si = 0, sn = widgetGlobals->snapshots.size(); si < sn; ++si) { - SNAPVEC &svec = widgetGlobals->snapshots[si]; - int ss = svec.size(); - for (j = 0; j < ss; j++) { - svec[j].fields.erase(svec[j].fields.begin(), - svec[j].fields.end()); - // VL: probably leaks memory, needs checking. - svec.resize(svec.size() + 1); - } - } - widgetGlobals->AddrSetValue.clear(); // VL: leaks memory, needs fixing. - widgetGlobals->stack_count = 0; - widgetGlobals->FLcontrol_iheight = 15; - widgetGlobals->FLroller_iheight = 18; - widgetGlobals->FLcontrol_iwidth = 400; - widgetGlobals->FLroller_iwidth = 150; - widgetGlobals->FLvalue_iwidth = 100; - widgetGlobals->FLcolor = -1; - widgetGlobals->FLcolor2 = -1; - widgetGlobals->FLtext_size = 0; - widgetGlobals->FLtext_color = -1; - widgetGlobals->FLtext_font = -1; - widgetGlobals->FLtext_align = 0; - widgetGlobals->FL_ix = 10; - widgetGlobals->FL_iy = 10; - - //delete (WIDGET_GLOBALS*)csound->widgetGlobals; - csound->DestroyGlobalVariable(csound, "WIDGET_GLOBALS"); - //csound->widgetGlobals = NULL; - } - return 0; - } -} // extern "C" - -//----------- - -#ifndef NO_FLTK_THREADS - -extern "C" { - - static uintptr_t fltkRun(void *userdata) - { - volatile widgetsGlobals_t *p; - CSOUND *csound = (CSOUND*) userdata; - int j; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - p = (widgetsGlobals_t*) csound->QueryGlobalVariable(csound, - "_widgets_globals"); -#ifdef LINUX - { - struct sched_param sp; - // IV - Aug 27 2002: widget thread is always run with normal priority - memset(&sp, 0, sizeof(struct sched_param)); - pthread_setschedparam(pthread_self(), SCHED_OTHER, &sp); - } -#endif - - if (!(p->fltkFlags & 8)) - Fl::lock(); - for (j = 0; j < (int) widgetGlobals->fl_windows.size(); j++) { - widgetGlobals->fl_windows[j].panel->show(); - } -// #ifdef CS_VSTHOST -// for (size_t k=0; k < widgetGlobals->VSTplugEditors.size(); k++) { -// int panelNum = widgetGlobals->VSTplugEditors[k]->targetFLpanel; -// #ifdef WIN32 -// HWND xid = fl_xid(widgetGlobals->fl_windows[panelNum].panel); -// widgetGlobals->VSTplugEditors[k]->SetEditWindow(xid); -// #elif defined (LINUX) || defined(MACOSX) -// // put some appropriate alternative code here -// Fl_Window * xid = -// fl_find(fl_xid(widgetGlobals->fl_windows[panelNum].panel)); -// widgetGlobals->VSTplugEditors[k]->SetEditWindow(xid); -// #endif // WIN32 -// } -// #endif // CS_VSTHOST - if (!(p->fltkFlags & 16)) - Fl::awake(); - if (!(p->fltkFlags & 8)) - Fl::unlock(); - do { - if (!(p->fltkFlags & 8)) - Fl::lock(); - Fl::wait(0.02); - j = (Fl::first_window() != (Fl_Window*) 0); - if (!(p->fltkFlags & 8)) - Fl::unlock(); - } while (j && !p->end_of_perf); - csound->Message(csound, "%s", Str("end of widget thread\n")); - // IV - Jun 07 2005: exit if all windows are closed - p->exit_now = -1; - return (uintptr_t) 0; - } - -} // extern "C" - -#endif // NO_FLTK_THREADS - -extern "C" { - - int CsoundYield_FLTK(CSOUND *csound); - - int FL_run(CSOUND *csound, FLRUN *p) - { - IGN(p); - int *fltkFlags; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - fltkFlags = getFLTKFlagsPtr(csound); - (*fltkFlags) |= 32; -#ifndef NO_FLTK_THREADS - if (((*fltkFlags) & 260) ^ 4) { - widgetsGlobals_t *pp; - - if (UNLIKELY(csound->QueryGlobalVariable(csound, - "_widgets_globals") != NULL)) - return csound->InitError(csound, "%s", Str("FLrun was already called")); - if (UNLIKELY(csound->CreateGlobalVariable(csound, "_widgets_globals", - sizeof(widgetsGlobals_t)) != 0)) - csound->Die(csound, "%s", Str("FL_run: memory allocation failure")); - pp = (widgetsGlobals_t*) csound->QueryGlobalVariable(csound, - "_widgets_globals"); - pp->fltkFlags = *fltkFlags; - /* create thread lock */ - pp->mutex_ = csound->Create_Mutex(0); - /* register callback function to be called by sensevents() */ - csound->RegisterSenseEventCallback(csound, (void (*)(CSOUND *, void *)) - evt_callback, - (void*) pp); - if (!((*fltkFlags) & 256)) { - pp->threadHandle = csound->CreateThread(fltkRun, (void*) csound); - return OK; - } - } -#endif // NO_FLTK_THREADS - { - int j; - - Fl_lock(csound); - for (j = 0; j < (int) widgetGlobals->fl_windows.size(); j++) { - widgetGlobals->fl_windows[j].panel->show(); - } - Fl_wait(csound, 0.0); - Fl_unlock(csound); - - - if (!((*fltkFlags) & 256)) - csound->SetInternalYieldCallback(csound, CsoundYield_FLTK); - } - return OK; - } - - int fl_update(CSOUND *csound, FLRUN *p) - { - IGN(p); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - Fl_lock(csound); - for (int j=0; j< (int) widgetGlobals->AddrSetValue.size()-1; j++) { - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[j]; - Fl_Valuator *o = (Fl_Valuator *) v.WidgAddress; - o->do_callback(o, v.opcode); - } - Fl_unlock(csound); - return OK; - } -} // extern "C" - -//---------------------------------------------- - -static inline void displ(MYFLT val, MYFLT index, CSOUND *csound) -{ - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (index >= 0) { // display current value of valuator - char valString[MAXNAME]; - sprintf(valString, "%.5g", val); - ((Fl_Output*) (widgetGlobals->AddrSetValue[(long) index]).WidgAddress)-> - value(valString); - } -} - -static void fl_callbackButton1(Fl_Button* w, void *a) -{ - IGN(w); - FLBUTTON *p = (FLBUTTON *) a; - *((FLBUTTON*) a)->kout = *p->ion; - if (*p->args[0] >= 0) ButtonSched(p->h.insdshead->csound, - p->args, p->INOCOUNT-8); -} - -static void fl_callbackCloseButton(Fl_Button* w, void *a) -{ - IGN(w); - Fl_Window *p = (Fl_Window *) a; - p->hide(); -} - -static void fl_callbackExecButton(Fl_Button* w, void *a) -{ - IGN(w); - FLEXECBUTTON *p = (FLEXECBUTTON *)a; - CSOUND *csound = p->csound; - char *command = (char *)csound->Malloc(csound, strlen(p->commandString) + 1); - -#if defined(LINUX) || defined (MACOSX) - - - pid_t pId = vfork(); - if (pId == 0) { - char *th; - char *v[40]; - int i = 0; - - strcpy(command, p->commandString); - - char *tok = csound->strtok_r(command,(char *) " ", &th); - - if(tok != NULL) { - v[i++] = tok; - while((tok = csound->strtok_r(NULL,(char *) " ", &th)) != NULL) { - v[i++] = tok; - } - v[i] = NULL; - execvp(v[0], v); - } - - _exit(0); - } else if (UNLIKELY(pId < 0)) { - p->csound->Message(p->csound, - "%s", Str("Error: Unable to fork process\n")); - } - - csound->Free(csound, command); -#elif defined(WIN32) - { -#undef strtok_r // undefine from pthread.h on Windows - char *th; - char *v[40]; - int i = 0; - - strcpy(command, p->commandString); - char *tok = csound->strtok_r(command,(char *) " ", &th); - - if(tok != NULL) { - v[i++] = tok; - while((tok = csound->strtok_r(NULL,(char *) " ", &th)) != NULL) { - v[i++] = tok; - } - v[i] = NULL; - csound->Free(csound, command); // Otherwise will lose space - if (UNLIKELY(csound->RunCommand(v, 1)<0)) - p->csound->Message(p->csound, "%s", - Str("Error: Unable to fork process\n")); - } - } -#endif -} - -static void fl_callbackButton(Fl_Button* w, void *a) -{ - FLBUTTON *p = (FLBUTTON *) a; - *((FLBUTTON*) a)->kout = (w->value()) ? *p->ion : *p->ioff; - if (*p->args[0] >= 0) ButtonSched(p->h.insdshead->csound, - p->args, p->INOCOUNT-8); -} - -static void fl_callbackButtonBank(Fl_Button* w, void *a) -{ - FLBUTTONBANK *p = (FLBUTTONBANK *) a; - *((FLBUTTONBANK*) a)->kout = (MYFLT) atoi(w->label()); - if (*p->args[0] >= 0) ButtonSched(p->h.insdshead->csound, - p->args, p->INOCOUNT-7); -} - -static void fl_callbackCounter(Fl_Counter* w, void *a) -{ - FLCOUNTER *p = (FLCOUNTER *) a; - *((FLCOUNTER*) a)->kout = w->value(); - if (*p->args[0] >= 0) ButtonSched(p->h.insdshead->csound, - p->args, p->INOCOUNT-10); -} - -static void fl_callbackLinearSlider(Fl_Valuator* w, void *a) -{ - FLSLIDER *p = ((FLSLIDER*) a); - displ(*p->kout = w->value(), *p->idisp, p->h.insdshead->csound); -} - -static void fl_callbackExponentialSlider(Fl_Valuator* w, void *a) -{ - FLSLIDER *p = ((FLSLIDER*) a); - #if defined(sun) - displ(*p->kout = p->min * ::pow ((double)p->base, w->value()), - *p->idisp, p->h.insdshead->csound); - #else - displ(*p->kout = p->min * ::pow (p->base, w->value()), - *p->idisp, p->h.insdshead->csound); - #endif -} - -static void fl_callbackInterpTableSlider(Fl_Valuator* w, void *a) -{ - FLSLIDER *p = ((FLSLIDER*) a); - MYFLT ndx = w->value() * (p->tablen-1); - int index = (int) ndx; - MYFLT v1 = p->table[index]; - displ(*p->kout = p->min+ ( v1 + (p->table[index+1] - v1) * - (ndx - index)) * (*p->imax - p->min), - *p->idisp, p->h.insdshead->csound); -} - -static void fl_callbackTableSlider(Fl_Valuator* w, void *a) -{ - FLSLIDER *p = ((FLSLIDER*) a); - displ(*p->kout = p->min+ p->table[(long) (w->value() * p->tablen)] * - (*p->imax - p->min), - *p->idisp, p->h.insdshead->csound); -} - -static void fl_callbackLinearSliderBank(Fl_Valuator* w, void *a) -{ - SLDBK_ELEMENT* p = (SLDBK_ELEMENT*) a; - *p->out = w->value(); -} - -static void fl_callbackExponentialSliderBank(Fl_Valuator* w, void *a) -{ - SLDBK_ELEMENT* p = (SLDBK_ELEMENT*) a; - #if defined(sun) - *p->out = p->min * ::pow ((double)p->base, w->value()); - #else - *p->out = p->min * ::pow (p->base, w->value()); - #endif -} - -static void fl_callbackInterpTableSliderBank(Fl_Valuator* w, void *a) -{ - SLDBK_ELEMENT *p = ((SLDBK_ELEMENT*) a); - - MYFLT ndx = w->value() * (p->tablen-1); - int index = (int) ndx; - MYFLT v1 = p->table[index]; - *p->out = p->min + ( v1 + (p->table[index+1] - v1) * (ndx - index)) * - (p->max - p->min); -} - -static void fl_callbackTableSliderBank(Fl_Valuator* w, void *a) -{ - SLDBK_ELEMENT *p = ((SLDBK_ELEMENT*) a); - *p->out = p->min + p->table[(long)(w->value() * p->tablen)] * - (p->max - p->min); -} - -static void fl_callbackJoystick(Fl_Widget* w, void *a) -{ - FLJOYSTICK *p = (FLJOYSTICK*) a; - Fl_Positioner *j = (Fl_Positioner*) w; - MYFLT val; - int iexpx = (int) *p->iexpx, iexpy = (int) *p->iexpy; - switch (iexpx) { - case LIN_: - val = j->xvalue(); - break; - case EXP_: - #if defined(sun) - val = *p->iminx * ::pow ((double)p->basex, j->xvalue()); - #else - val = *p->iminx * ::pow (p->basex, j->xvalue()); - #endif - break; - default: - if (iexpx > 0) { //interpolated - MYFLT ndx = j->xvalue() * (p->tablenx-1); - int index = (int) ndx; - MYFLT v1 = p->tablex[index]; - val = *p->iminx + ( v1 + (p->tablex[index+1] - v1) * - (ndx - index)) * (*p->imaxx - *p->iminx); - } - else // non-interpolated - val = *p->iminx+ p->tablex[(long) (j->xvalue() * p->tablenx)] * - (*p->imaxx - *p->iminx); - } - displ(*p->koutx = val,*p->idispx, p->h.insdshead->csound); - switch (iexpy) { - case LIN_: - val = j->yvalue(); - break; - case EXP_: - #if defined(sun) - val = *p->iminy * ::pow ((double)p->basey, j->yvalue()); - #else - val = *p->iminy * ::pow (p->basey, j->yvalue()); - #endif - break; - default: - if (iexpy > 0) { //interpolated - MYFLT ndx = j->yvalue() * (p->tableny-1); - long index = (long) ndx; - MYFLT v1 = p->tabley[index]; - val = *p->iminy + ( v1 + (p->tabley[index+1] - v1) * (ndx - index)) - * (*p->imaxy - *p->iminy); - } - else { // non-interpolated - long index = (long) (j->yvalue()* p->tableny); - val = *p->iminy+ p->tabley[index] * (*p->imaxy - *p->iminy); - - } - } - displ(*p->kouty = val, *p->idispy, p->h.insdshead->csound); -} - -static void fl_callbackLinearRoller(Fl_Valuator* w, void *a) -{ - FLROLLER *p = ((FLROLLER*) a); - displ(*p->kout = w->value(),*p->idisp, p->h.insdshead->csound); -} - -static void fl_callbackExponentialRoller(Fl_Valuator* w, void *a) -{ - FLROLLER *p = ((FLROLLER*) a); - #if defined(sun) - displ(*p->kout = ((FLROLLER*) a)->min * ::pow ((double)p->base, w->value()), - *p->idisp, p->h.insdshead->csound); - #else - displ(*p->kout = ((FLROLLER*) a)->min * ::pow (p->base, w->value()), - *p->idisp, p->h.insdshead->csound); - #endif -} - -static void fl_callbackInterpTableRoller(Fl_Valuator* w, void *a) -{ - FLROLLER *p = ((FLROLLER*) a); - MYFLT ndx = w->value() * (p->tablen-1); - int index = (int) ndx; - MYFLT v1 = p->table[index]; - displ(*p->kout = p->min+ ( v1 + (p->table[index+1] - v1) * (ndx - index)) * - (*p->imax - p->min), *p->idisp, p->h.insdshead->csound); -} - -static void fl_callbackTableRoller(Fl_Valuator* w, void *a) -{ - FLROLLER *p = ((FLROLLER*) a); - displ(*p->kout = p->min+ p->table[(long) (w->value() * p->tablen)] * - (*p->imax - p->min), *p->idisp, p->h.insdshead->csound); -} - -static void fl_callbackLinearKnob(Fl_Valuator* w, void *a) -{ - FLKNOB *p = ((FLKNOB*) a); - displ( *p->kout = w->value(), *p->idisp, p->h.insdshead->csound); -} - -static void fl_callbackExponentialKnob(Fl_Valuator* w, void *a) -{ - FLKNOB *p = ((FLKNOB*) a); - #if defined(sun) - displ(*p->kout = ((FLKNOB*) a)->min * ::pow ((double)p->base, w->value()), - *p->idisp, p->h.insdshead->csound); - #else - displ(*p->kout = ((FLKNOB*) a)->min * ::pow (p->base, w->value()), - *p->idisp, p->h.insdshead->csound); - #endif -} - -static void fl_callbackInterpTableKnob(Fl_Valuator* w, void *a) -{ - FLKNOB *p = ((FLKNOB*) a); - MYFLT ndx = w->value() * (p->tablen-1); - int index = (int) ndx; - MYFLT v1 = p->table[index]; - displ(*p->kout = p->min+ ( v1 + (p->table[index+1] - v1) * (ndx - index)) * - (*p->imax - p->min), *p->idisp, p->h.insdshead->csound); -} - -static void fl_callbackTableKnob(Fl_Valuator* w, void *a) -{ - FLKNOB *p = ((FLKNOB*) a); - displ(*p->kout = p->min+ p->table[(long) (w->value() * p->tablen)] * - (*p->imax - p->min), *p->idisp, p->h.insdshead->csound); -} - -static void fl_callbackLinearValueInput(Fl_Valuator* w, void *a) -{ - *((FLTEXT*) a)->kout = w->value(); -} - -//----------- - -static int rand_31_i(CSOUND *csound, int maxVal) -{ - int seed = csound->GetRandSeed(csound,2); - double x = (double) (csound->Rand31(&seed) - 1); - return (int) (x * (double) (maxVal + 1) / 2147483646.0); -} - -static void widget_attributes(CSOUND *csound, Fl_Widget *o) -{ - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (widgetGlobals->FLtext_size == -2 ) { - widgetGlobals->FLtext_size = -1; - widgetGlobals->FLtext_color= -1; - widgetGlobals->FLtext_font = -1; - widgetGlobals->FLtext_align= -1; - widgetGlobals->FLcolor = -1; - } - if (widgetGlobals->FLtext_size > 0) - // if > 0 assign it, else skip, leaving default - o->labelsize(widgetGlobals->FLtext_size); - switch ((int) widgetGlobals->FLtext_color) { - case -2: // random color - o->labelcolor(fl_rgb_color(rand_31_i(csound, 255), rand_31_i(csound, 255), - rand_31_i(csound, 255))); - break; - case -1: - // if FLtext_color is == -1, color assignment is skipped, - // leaving default color - break; - default: - o->labelcolor(widgetGlobals->FLtext_color); - break; - } - if (widgetGlobals->FLtext_font> 0) { - Fl_Font font; - if (widgetGlobals->FLtext_font<0 || - widgetGlobals->FLtext_font>16) font = FL_HELVETICA; - else font = FONT_TABLE[widgetGlobals->FLtext_font]; - // switch (FLtext_font) { - // case 1: font = FL_HELVETICA; break; - // case 2: font = FL_HELVETICA_BOLD; break; - // case 3: font = FL_HELVETICA_ITALIC; break; - // case 4: font = FL_HELVETICA_BOLD_ITALIC; break; - // case 5: font = FL_COURIER; break; - // case 6: font = FL_COURIER_BOLD; break; - // case 7: font = FL_COURIER_ITALIC; break; - // case 8: font = FL_COURIER_BOLD_ITALIC; break; - // case 9: font = FL_TIMES; break; - // case 10: font = FL_TIMES_BOLD; break; - // case 11: font = FL_TIMES_ITALIC; break; - // case 12: font = FL_TIMES_BOLD_ITALIC; break; - // case 13: font = FL_SYMBOL; break; - // case 14: font = FL_SCREEN; break; - // case 15: font = FL_SCREEN_BOLD; break; - // case 16: font = FL_ZAPF_DINGBATS; break; - // default: font = FL_HELVETICA; break; - // } - o->labelfont(font); - } - if (widgetGlobals->FLtext_align > 0) { - Fl_Align type; - if (widgetGlobals->FLtext_align<0 || - widgetGlobals->FLtext_align>9) type = FL_ALIGN_BOTTOM; - else type = ALIGN_TABLE[widgetGlobals->FLtext_align]; - // switch (widgetGlobals->FLtext_align) { - // case 1: type = FL_ALIGN_CENTER; break; - // case 2: type = FL_ALIGN_TOP; break; - // case 3: type = FL_ALIGN_BOTTOM; break; - // case 4: type = FL_ALIGN_LEFT; break; - // case 5: type = FL_ALIGN_RIGHT; break; - // case 6: type = FL_ALIGN_TOP_LEFT; break; - // case 7: type = FL_ALIGN_TOP_RIGHT; break; - // case 8: type = FL_ALIGN_BOTTOM_LEFT; break; - // case 9: type = FL_ALIGN_BOTTOM_RIGHT; break; - // case -1: // What type is this? - // default: type = FL_ALIGN_BOTTOM; break; - // } - o->align(type); - } - switch ((int) widgetGlobals->FLcolor) { // random color - case -2: - o->color(FL_GRAY, - fl_rgb_color(rand_31_i(csound, 255), rand_31_i(csound, 255), - rand_31_i(csound, 255))); - break; - case -1: - // if FLcolor is == -1, color assignment is skipped, - // leaving widget default color - break; - default: - o->color(widgetGlobals->FLcolor, widgetGlobals->FLcolor2); - break; - } -} - -//----------- - -extern "C" { - - // static int FLkeyb(CSOUND *csound, FLKEYB *p) - // { - // (void) csound; - // (void) p; - // return OK; - // } - - //----------- - - void flpanel_cb(Fl_Widget *,void *) { //suppresses the close button - } - - static int StartPanel(CSOUND *csound, FLPANEL *p) - { - char *panelName; - panelName = p->name->data; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - - *(getFLTKFlagsPtr(csound)) |= 32; - int x = (int) *p->ix, y = (int) *p->iy; - int width = (int) *p->iwidth, height = (int) *p->iheight; - if (width < 0) width = 400; // default - if (height < 0) height = 300; - - Fl_Boxtype borderType; - int iborder = (int) *p->border; - if (iborder<0 || iborder>7) borderType = FL_FLAT_BOX; - else borderType = BOX_TABLE[iborder]; - // switch( (int) *p->border ) { - // case 0: borderType = FL_FLAT_BOX; break; - // case 1: borderType = FL_DOWN_BOX; break; - // case 2: borderType = FL_UP_BOX; break; - // case 3: borderType = FL_ENGRAVED_BOX; break; - // case 4: borderType = FL_EMBOSSED_BOX; break; - // case 5: borderType = FL_BORDER_BOX; break; - // case 6: borderType = FL_THIN_DOWN_BOX; break; - // case 7: borderType = FL_THIN_UP_BOX; break; - // default: borderType = FL_FLAT_BOX; - // } - - Fl_Window *o; - if (*(p->ikbdsense) == MYFLT(0.0)) { - if (x < 0) - o = new Fl_Window(width, height, panelName); - else - o = new Fl_Window(x, y, width, height, panelName); - } - else if (x < 0) - o = new CsoundFLWindow(csound, width, height, panelName); - else - o = new CsoundFLWindow(csound, x, y, width, height, panelName); - widget_attributes(csound, o); - o->box(borderType); - o->resizable(o); - if (*p->iclose != 0) - o->callback(flpanel_cb); - widget_attributes(csound, o); - ADDR_STACK adrstk(&p->h, (void *) o, widgetGlobals->stack_count); - widgetGlobals->AddrStack.push_back(adrstk); - PANELS panel(o, (widgetGlobals->stack_count > 0) ? 1 : 0); - widgetGlobals->fl_windows.push_back(panel); - widgetGlobals->stack_count++; - - return OK; - } - - static int EndPanel(CSOUND *csound, FLPANELEND *p) - { - IGN(p); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - widgetGlobals->stack_count--; - ADDR_STACK adrstk = widgetGlobals->AddrStack.back(); - if (UNLIKELY(adrstk.h->optext->t.opcod && - strcmp( adrstk.h->optext->t.opcod, "FLpanel"))) - return csound->InitError(csound, - "%s", Str("FLpanel_end: invalid stack pointer: " - "verify its placement")); - if (UNLIKELY(adrstk.count != widgetGlobals->stack_count)) - return csound->InitError(csound, - "%s", Str("FLpanel_end: invalid stack count: " - "verify FLpanel/FLpanel_end count and" - " placement")); - ((Fl_Window*) adrstk.WidgAddress)->end(); - widgetGlobals->AddrStack.pop_back(); - return OK; - } - - //----------- - static int StartScroll(CSOUND *csound, FLSCROLL *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - Fl_Scroll *o = new Fl_Scroll ((int) *p->ix, (int) *p->iy, - (int) *p->iwidth, (int) *p->iheight); - ADDR_STACK adrstk(&p->h,o,widgetGlobals->stack_count); - widgetGlobals->AddrStack.push_back(adrstk); - widgetGlobals->stack_count++; - return OK; - } - - static int EndScroll(CSOUND *csound, FLSCROLLEND *p) - { - IGN(p); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - widgetGlobals->stack_count--; - ADDR_STACK adrstk = widgetGlobals->AddrStack.back(); - if (UNLIKELY(strcmp( adrstk.h->optext->t.opcod, "FLscroll"))) - return - csound->InitError(csound, - "%s", Str("FLscroll_end: invalid stack pointer: " - "verify its placement")); - if (UNLIKELY(adrstk.count != widgetGlobals->stack_count)) - return csound->InitError(csound, - "%s", Str("FLscroll_end: invalid stack count: " - "verify FLscroll/FLscroll_end count " - "and placement")); - ((Fl_Scroll*) adrstk.WidgAddress)->end(); - - widgetGlobals->AddrStack.pop_back(); - return OK; - } - - //----------- - static int StartTabs(CSOUND *csound, FLTABS *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - Fl_Tabs *o = new Fl_Tabs ((int) *p->ix, (int) *p->iy, - (int) *p->iwidth, (int) *p->iheight); - widget_attributes(csound, o); - // o->box(FL_PLASTIC_UP_BOX); - ADDR_STACK adrstk(&p->h,o,widgetGlobals->stack_count); - widgetGlobals->AddrStack.push_back(adrstk); - widgetGlobals->stack_count++; - return OK; - } - - static int EndTabs(CSOUND *csound, FLTABSEND *p) - { - IGN(p); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - widgetGlobals->stack_count--; - ADDR_STACK adrstk = widgetGlobals->AddrStack.back(); - if (UNLIKELY(strcmp( adrstk.h->optext->t.opcod, "FLtabs"))) - return - csound->InitError(csound, - "%s", Str("FLscroll_end: invalid stack pointer: " - "verify its placement")); - if (UNLIKELY(adrstk.count != widgetGlobals->stack_count)) - return csound->InitError(csound, - "%s", Str("FLtabs_end: invalid stack count: " - "verify FLtabs/FLtabs_end count and " - "placement")); - ((Fl_Scroll*) adrstk.WidgAddress)->end(); - - widgetGlobals->AddrStack.pop_back(); - return OK; - } - - //----------- - static int StartGroup(CSOUND *csound, FLGROUP *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char *Name = p->name->data; - Fl_Group *o = new Fl_Group ((int) *p->ix, (int) *p->iy, - (int) *p->iwidth, (int) *p->iheight,Name); - widget_attributes(csound, o); - Fl_Boxtype borderType; - int iborder = (int)*p->border; - if (iborder<0 || iborder>7) borderType = FL_FLAT_BOX; - else borderType = BOX_TABLE[iborder]; - // switch((int)*p->border ) { - // case 0: borderType = FL_FLAT_BOX; break; - // case 1: borderType = FL_DOWN_BOX; break; - // case 2: borderType = FL_UP_BOX; break; - // case 3: borderType = FL_ENGRAVED_BOX; break; - // case 4: borderType = FL_EMBOSSED_BOX; break; - // case 5: borderType = FL_BORDER_BOX; break; - // case 6: borderType = FL_THIN_DOWN_BOX; break; - // case 7: borderType = FL_THIN_UP_BOX; break; - // default: borderType = FL_FLAT_BOX; - // } - o->box(borderType); - widget_attributes(csound, o); - ADDR_STACK adrstk(&p->h,o,widgetGlobals->stack_count); - widgetGlobals->AddrStack.push_back(adrstk); - widgetGlobals->stack_count++; - return OK; - } - - static int EndGroup(CSOUND *csound, FLGROUPEND *p) - { - IGN(p); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - widgetGlobals->stack_count--; - ADDR_STACK adrstk = widgetGlobals->AddrStack.back(); - if (UNLIKELY(strcmp( adrstk.h->optext->t.opcod, "FLgroup"))) - return csound->InitError(csound, - "%s", Str("FLgroup_end: invalid stack pointer: " - "verify its placement")); - if (UNLIKELY(adrstk.count != widgetGlobals->stack_count)) - return csound->InitError(csound, - "%s", Str("FLgroup_end: invalid stack count: " - "verify FLgroup/FLgroup_end count and" - " placement")); - ((Fl_Scroll*) adrstk.WidgAddress)->end(); - - widgetGlobals->AddrStack.pop_back(); - return OK; - } - - //----------- - - static int StartPack(CSOUND *csound, FLPACK *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - Fl_Pack *o = new Fl_Pack ((int) *p->ix, (int) *p->iy, - (int) *p->iwidth, (int) *p->iheight); - Fl_Boxtype borderType = FL_FLAT_BOX; - int iborder = (int)*p->iborder; - // fl_window->resizable(o); - if (!((iborder<0 || iborder>7))) - borderType = BOX_TABLE[iborder]; - o->box(borderType); // JPff added March 2012 - o->type((int)*p->itype); - o->spacing((int)*p->ispace); - - ADDR_STACK adrstk(&p->h,o,widgetGlobals->stack_count); - widgetGlobals->AddrStack.push_back(adrstk); - widgetGlobals->stack_count++; - return OK; - } - - static int EndPack(CSOUND *csound, FLSCROLLEND *p) - { - IGN(p); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - widgetGlobals->stack_count--; - ADDR_STACK adrstk = widgetGlobals->AddrStack.back(); - if (UNLIKELY(strcmp( adrstk.h->optext->t.opcod, "FLpack"))) - return csound->InitError(csound, - "%s", Str("FLpack_end: invalid stack pointer: " - "verify its placement")); - if (UNLIKELY(adrstk.count != widgetGlobals->stack_count)) - return csound->InitError(csound, - "%s", Str("FLpack_end: invalid stack count: " - "verify FLpack/FLpack_end count and " - "placement")); - ((Fl_Pack*) adrstk.WidgAddress)->end(); - - widgetGlobals->AddrStack.pop_back(); - return OK; - } - - //----------- - - static int fl_widget_color(CSOUND *csound, FLWIDGCOL *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (*p->red1 < 0) { // reset colors to default - widgetGlobals->FLcolor = (int) *p->red1; //when called without arguments - widgetGlobals->FLcolor2 =(int) *p->red1; - } - else { - widgetGlobals->FLcolor = fl_rgb_color((int) *p->red1, - (int) *p->green1, - (int) *p->blue1); - widgetGlobals->FLcolor2 = fl_rgb_color((int) *p->red2, - (int) *p->green2, - (int) *p->blue2); - } - return OK; - } - - static int fl_widget_color2(CSOUND *csound, FLWIDGCOL2 *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (*p->red < 0) { // reset colors to default - widgetGlobals->FLcolor2 =(int) *p->red; - } - else { - widgetGlobals->FLcolor2 = fl_rgb_color((int) *p->red, - (int) *p->green, - (int) *p->blue); - } - return OK; - } - - static int fl_widget_label(CSOUND *csound, FLWIDGLABEL *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (*p->size <= 0) { // reset settings to default - widgetGlobals->FLtext_size = 0; //when called without arguments - widgetGlobals->FLtext_font = -1; - widgetGlobals->FLtext_align = 0; - widgetGlobals->FLtext_color = -1; - } - else { - widgetGlobals->FLtext_size = (int) *p->size; - - if (*p->font > -1) widgetGlobals->FLtext_font = (int) *p->font; - if (*p->align > 0) widgetGlobals->FLtext_align = (int) *p->align; - if (*p->red > -1 && *p->green > -1 && *p->blue > -1) { - widgetGlobals->FLtext_color = fl_rgb_color((int) *p->red, - (int) *p->green, - (int) *p->blue); - } - } - return OK; - } - -} // extern "C" - -// ----------- - -static int fl_getWidgetTypeFromOpcodeName(CSOUND *csound, void *p) -{ - const char *opname = csound->GetOpcodeName(p); - - if (strcmp(opname, "FLbutton") == 0) - return 1; - if (strcmp(opname, "FLbutBank") == 0) - return 2; - if (strcmp(opname, "FLjoy") == 0) - return 3; - if (strcmp(opname, "FLvalue") == 0) - return 4; - if (strcmp(opname, "FLbox") != 0) - return 0; - csound->Warning(csound, "%s", Str("System error: value() method called from " - "non-valuator object")); - return -1; -} - -static void fl_setWidgetValue_(CSOUND *csound, - ADDR_SET_VALUE &v, int widgetType, - MYFLT val, MYFLT log_base) -{ - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - void *p = v.opcode; - bool fltkLockingIsEnabled; - - if ((!widgetType || widgetType > 2) && - (v.exponential == LIN_ || v.exponential == EXP_)) { - if (val < v.min) - val = v.min; - else if (val > v.max) - val = v.max; - if (v.exponential == EXP_) - val = (MYFLT) (log(val / v.min) / log_base); - } - fltkLockingIsEnabled = ((getFLTKFlags(csound) & 8) == 0); - if (fltkLockingIsEnabled) - Fl_lock(csound); - switch (widgetType) { - case 0: // valuator - ((Fl_Valuator *) o)->value(val); - break; - case 1: // FLbutton - if (val == *(((FLBUTTON *) v.opcode)->ion)) - ((Fl_Button *) o)->value(1); - else if (val == *(((FLBUTTON *) v.opcode)->ioff)) - ((Fl_Button *) o)->value(0); - break; - case 2: // FLbutBank - set_butbank_value((Fl_Group *) o, val); - break; - case 3: // FLjoy - { - static int flag = 0; - // FLsetVal always requires two adjacent calls when setting FLjoy - if (!flag) { - ((Fl_Positioner *) o)->xvalue(val); - flag = 1; - } - else { - ((Fl_Positioner *) o)->yvalue(val); - flag = 0; - } - } - break; - default: // invalid - if (fltkLockingIsEnabled) - Fl_unlock(csound); - return; - } - o->do_callback(o, p); - if (fltkLockingIsEnabled) - Fl_unlock(csound); -} - -extern "C" { - - static int fl_setWidgetValuei(CSOUND *csound, FL_SET_WIDGET_VALUE_I *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - MYFLT log_base = MYFLT(1.0); - ADDR_SET_VALUE &v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - int widgetType; - - widgetType = fl_getWidgetTypeFromOpcodeName(csound, v.opcode); - if (UNLIKELY(widgetType == 4)) { - csound->InitError(csound, - "%s", Str("FLvalue cannot be set by FLsetVal.\n")); - return NOTOK; - } - if (widgetType < 0) - return OK; - if (!widgetType || widgetType > 2) { - switch (v.exponential) { - case LIN_: // linear - break; - case EXP_: // exponential - #if defined(sun) - log_base = (MYFLT) log(::pow(v.max / (double)v.min, - 1.0 / (v.max - v.min))); - #else - log_base = (MYFLT) log(::pow(v.max / v.min, 1.0 / (v.max - v.min))); - #endif - break; - default: - csound->Warning(csound, Str("(fl_setWidgetValuei): " - "not fully implemented yet; exp=%d"), - v.exponential); - } - } - fl_setWidgetValue_(csound, v, widgetType, *(p->ivalue), log_base); - return OK; - } - - static int fl_setWidgetValue_set(CSOUND *csound, FL_SET_WIDGET_VALUE *p) - { - p->handle = (int) *(p->ihandle); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - MYFLT log_base = MYFLT(1.0); - ADDR_SET_VALUE &v = widgetGlobals->AddrSetValue[p->handle]; - int widgetType; - - widgetType = fl_getWidgetTypeFromOpcodeName(csound, v.opcode); - if (UNLIKELY(widgetType == 4)) { - csound->InitError(csound, - "%s", Str("FLvalue cannot be set by FLsetVal\n")); - return NOTOK; - } - if (widgetType < 0) - return OK; - if (!widgetType || widgetType > 2) { - switch (v.exponential) { - case LIN_: // linear - break; - case EXP_: // exponential - #if defined(sun) - log_base = (MYFLT) log(::pow(v.max / (double)v.min, - 1.0 / (v.max - v.min))); - #else - log_base = (MYFLT) log(::pow(v.max / v.min, 1.0 / (v.max - v.min))); - #endif - break; - default: - csound->Warning(csound, Str("(fl_setWidgetValue_set): " - "not fully implemented yet; exp=%d"), - v.exponential); - } - } - p->widgetType = widgetType; - p->log_base = log_base; - - return OK; - } - - static int fl_setWidgetValue(CSOUND *csound, FL_SET_WIDGET_VALUE *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (*p->ktrig != MYFLT(0.0)) - fl_setWidgetValue_(csound, - widgetGlobals->AddrSetValue[p->handle], p->widgetType, - *(p->kvalue), p->log_base); - return OK; - } - - //----------- - //----------- - - static int fl_setColor1(CSOUND *csound, FL_SET_COLOR *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - int color = fl_rgb_color((int) *p->red, - (int) *p->green, - (int) *p->blue); - o->color(color); - o->redraw(); - return OK; - } - - static int fl_setColor2(CSOUND *csound, FL_SET_COLOR *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - int color = fl_rgb_color((int) *p->red, (int) *p->green, (int) *p->blue); - o->selection_color(color); - o->redraw(); - return OK; - } - - static int fl_setTextColor(CSOUND *csound, FL_SET_COLOR *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - int color = fl_rgb_color((int) *p->red, (int) *p->green, (int) *p->blue); - o->labelcolor(color); - o->window()->redraw(); - return OK; - } - - static int fl_setTextSize(CSOUND *csound, FL_SET_TEXTSIZE *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - o->labelsize((uchar) *p->ivalue); - return OK; - } - - static int fl_setFont(CSOUND *csound, FL_SET_FONT *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - Fl_Font font; - int ifnt = (int) *p->itype; - if (ifnt<0 || ifnt>16) font = FL_HELVETICA; - else font = FONT_TABLE[ifnt]; - // switch ((int) *p->itype) { - // case 1: font = FL_HELVETICA; break; - // case 2: font = FL_HELVETICA_BOLD; break; - // case 3: font = FL_HELVETICA_ITALIC; break; - // case 4: font = FL_HELVETICA_BOLD_ITALIC; break; - // case 5: font = FL_COURIER; break; - // case 6: font = FL_COURIER_BOLD; break; - // case 7: font = FL_COURIER_ITALIC; break; - // case 8: font = FL_COURIER_BOLD_ITALIC; break; - // case 9: font = FL_TIMES; break; - // case 10: font = FL_TIMES_BOLD; break; - // case 11: font = FL_TIMES_ITALIC; break; - // case 12: font = FL_TIMES_BOLD_ITALIC; break; - // case 13: font = FL_SYMBOL; break; - // case 14: font = FL_SCREEN; break; - // case 15: font = FL_SCREEN_BOLD; break; - // case 16: font = FL_ZAPF_DINGBATS; break; - // default: font = FL_SCREEN; - // } - o->labelfont(font); - return OK; - } - - static int fl_setTextType(CSOUND *csound, FL_SET_FONT *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - Fl_Labeltype type; - switch ((int) *p->itype) { - case 0: type = FL_NORMAL_LABEL; break; - case 1: type = FL_NO_LABEL; break; - case 2: type = FL_SYMBOL_LABEL; break; - case 3: type = FL_SHADOW_LABEL; break; - case 4: type = FL_ENGRAVED_LABEL; break; - case 5: type = FL_EMBOSSED_LABEL; break; - /* case 6: type = _FL_BITMAP_LABEL; break; - case 7: type = _FL_PIXMAP_LABEL; break; - case 8: type = _FL_IMAGE_LABEL; break; - case 9: type = _FL_MULTI_LABEL; break; */ - case 10: type = FL_FREE_LABELTYPE; break; - default: type = FL_NORMAL_LABEL; - } - o->labeltype(type); - o->window()->redraw(); - return OK; - } - - static int fl_box_(CSOUND *csound, FL_BOX *p, char *text) - { - //char *text = p->itext->data; - Fl_Box *o = new Fl_Box((int)*p->ix, (int)*p->iy, - (int)*p->iwidth, (int)*p->iheight, strdup(text)); - widget_attributes(csound, o); - Fl_Boxtype type; - int itype = (int) *p->itype; - if (itype<0 || itype>19) type = FL_FLAT_BOX; - else type = BOX_TABLE[itype]; - // switch ((int) *p->itype) { - // case 1: type = FL_FLAT_BOX; break; - // case 2: type = FL_UP_BOX; break; - // case 3: type = FL_DOWN_BOX; break; - // case 4: type = FL_THIN_UP_BOX; break; - // case 5: type = FL_THIN_DOWN_BOX; break; - // case 6: type = FL_ENGRAVED_BOX; break; - // case 7: type = FL_EMBOSSED_BOX; break; - // case 8: type = FL_BORDER_BOX; break; - // case 9: type = _FL_SHADOW_BOX; break; - // case 10: type = _FL_ROUNDED_BOX; break; - // case 11: type = _FL_RSHADOW_BOX; break; - // case 12: type = _FL_RFLAT_BOX; break; - // case 13: type = _FL_ROUND_UP_BOX; break; - // case 14: type = _FL_ROUND_DOWN_BOX; break; - // case 15: type = _FL_DIAMOND_UP_BOX; break; - // case 16: type = _FL_DIAMOND_DOWN_BOX; break; - // case 17: type = _FL_OVAL_BOX; break; - // case 18: type = _FL_OSHADOW_BOX; break; - // case 19: type = _FL_OFLAT_BOX; break; - // default: type = FL_FLAT_BOX; - // } - o->box(type); - Fl_Font font; - int ifnt = (int) *p->ifont; - if (ifnt<0 || ifnt>16) font = FL_HELVETICA; - else font = FONT_TABLE[ifnt]; - // switch ((int) *p->ifont) { - // case 1: font = FL_HELVETICA; break; - // case 2: font = FL_HELVETICA_BOLD; break; - // case 3: font = FL_HELVETICA_ITALIC; break; - // case 4: font = FL_HELVETICA_BOLD_ITALIC; break; - // case 5: font = FL_COURIER; break; - // case 6: font = FL_COURIER_BOLD; break; - // case 7: font = FL_COURIER_ITALIC; break; - // case 8: font = FL_COURIER_BOLD_ITALIC; break; - // case 9: font = FL_TIMES; break; - // case 10: font = FL_TIMES_BOLD; break; - // case 11: font = FL_TIMES_ITALIC; break; - // case 12: font = FL_TIMES_BOLD_ITALIC; break; - // case 13: font = FL_SYMBOL; break; - // case 14: font = FL_SCREEN; break; - // case 15: font = FL_SCREEN_BOLD; break; - // case 16: font = FL_ZAPF_DINGBATS; break; - // default: font = FL_HELVETICA; - // } - o->labelfont(font); - o->labelsize((unsigned char)*p->isize); - o->align(FL_ALIGN_WRAP); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(0, 0, 0, (void *)o, - (void *)p, - widgetGlobals->currentSnapGroup)); - *p->ihandle = widgetGlobals->AddrSetValue.size()-1; - return OK; - } - - static int fl_box_s(CSOUND *csound, FL_BOX *p) - { - return fl_box_(csound, p, p->itext->data); - } - static int fl_box_i(CSOUND *csound, FL_BOX *p) - { - int i = (int)*((MYFLT*)p->itext); - char* text; - if (i<0 || i>csound->GetStrsmax(csound)) text = (char *) "???"; - else if ((text=csound->GetStrsets(csound,i))==NULL) text = (char *) "???"; - return fl_box_(csound, p, text); - } - - static int fl_setText(CSOUND *csound, FL_SET_TEXT *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char *text = strdup(p->itext->data); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - free((void*)o->label()); - o->label(text); - return OK; - } - - static int fl_setTexti(CSOUND *csound, FL_SET_TEXTi *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - int i = (int)(*p->ndx); - char *text ; - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - if (i<0 || i>csound->GetStrsmax(csound)) text = (char *) "???"; - else if ((text=csound->GetStrsets(csound,i))==NULL) text = (char *) "???"; - free((void*)o->label()); - o->label(strdup(text)); - return OK; - } - - static int fl_setSize(CSOUND *csound, FL_SET_SIZE *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - o->size((short) *p->iwidth, (short) *p->iheight); - return OK; - } - - static int fl_setPosition(CSOUND *csound, FL_SET_POSITION *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - o->position((short) *p->ix, (short) *p->iy); - return OK; - } - - static int fl_hide(CSOUND *csound, FL_WIDHIDE *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - Fl_lock(csound); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - o->hide(); - Fl_unlock(csound); - return OK; - } - - static int fl_show(CSOUND *csound, FL_WIDSHOW *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - Fl_lock(csound); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - o->show(); - Fl_unlock(csound); - return OK; - } - - static int fl_setBox(CSOUND *csound, FL_SETBOX *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - Fl_Boxtype type; - int itype = (int) *p->itype; - if (itype<0||itype>19) type = FL_FLAT_BOX; - else type = BOX_TABLE[itype]; - // switch ((int) *p->itype) { - // case 1: type = FL_FLAT_BOX; break; - // case 2: type = FL_UP_BOX; break; - // case 3: type = FL_DOWN_BOX; break; - // case 4: type = FL_THIN_UP_BOX; break; - // case 5: type = FL_THIN_DOWN_BOX; break; - // case 6: type = FL_ENGRAVED_BOX; break; - // case 7: type = FL_EMBOSSED_BOX; break; - // case 8: type = FL_BORDER_BOX; break; - // case 9: type = FL_SHADOW_BOX; break; - // case 10: type = FL_ROUNDED_BOX; break; - // case 11: type = FL_RSHADOW_BOX; break; - // case 12: type = FL_RFLAT_BOX; break; - // case 13: type = FL_ROUND_UP_BOX; break; - // case 14: type = FL_ROUND_DOWN_BOX; break; - // case 15: type = FL_DIAMOND_UP_BOX; break; - // case 16: type = FL_DIAMOND_DOWN_BOX; break; - // case 17: type = FL_OVAL_BOX; break; - // case 18: type = FL_OSHADOW_BOX; break; - // case 19: type = FL_OFLAT_BOX; break; - // default: type = FL_FLAT_BOX; - // } - o->box(type); - return OK; - } - - static int fl_align(CSOUND *csound, FL_TALIGN *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - Fl_Widget *o = (Fl_Widget *) v.WidgAddress; - Fl_Align type; - int itype= (int) *p->itype; - if (itype<0 || itype>9) type = FL_ALIGN_BOTTOM; - else type = ALIGN_TABLE[itype]; - // switch ((int) *p->itype) { - // case 1: type = FL_ALIGN_CENTER; break; - // case 2: type = FL_ALIGN_TOP; break; - // case 3: type = FL_ALIGN_BOTTOM; break; - // case 4: type = FL_ALIGN_LEFT; break; - // case 5: type = FL_ALIGN_RIGHT; break; - // case 6: type = FL_ALIGN_TOP_LEFT; break; - // case 7: type = FL_ALIGN_TOP_RIGHT; break; - // case 8: type = FL_ALIGN_BOTTOM_LEFT; break; - // case 9: type = FL_ALIGN_BOTTOM_RIGHT; break; - // default: type = FL_ALIGN_BOTTOM; - // } - o->align(type); - return OK; - } - - //----------- - //----------- - - static int fl_value(CSOUND *csound, FLVALUE *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char *controlName = p->name->data; - int ix, iy, iwidth, iheight; - if (*p->ix<0) ix = widgetGlobals->FL_ix; - else widgetGlobals->FL_ix = ix = (int) *p->ix; - if (*p->iy<0) iy = widgetGlobals->FL_iy; - else widgetGlobals->FL_iy = iy = (int) *p->iy; - if (*p->iwidth<0) iwidth = widgetGlobals->FLvalue_iwidth; - else widgetGlobals->FLvalue_iwidth = iwidth = (int) *p->iwidth; - if (*p->iheight<0) iheight = widgetGlobals->FLroller_iheight; - else widgetGlobals->FLroller_iheight = iheight = (int) *p->iheight; - - Fl_Output *o = new Fl_Output(ix, iy, iwidth, iheight,controlName); - o->align(FL_ALIGN_BOTTOM | FL_ALIGN_WRAP); - if (widgetGlobals->FLcolor < 0 ) - o->color(FL_GRAY ); - else - o->color(widgetGlobals->FLcolor, widgetGlobals->FLcolor2); - widget_attributes(csound, o); - //AddrValue.push_back((void *) o); - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(0, 0, 0, (void *) o, - (void *) p, - widgetGlobals->currentSnapGroup)); - //*p->ihandle = AddrValue.size()-1; - *p->ihandle = widgetGlobals->AddrSetValue.size()-1; - return OK; - } - - //----------- - - static int fl_slider(CSOUND *csound, FLSLIDER *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char *controlName = p->name->data; - int ix,iy,iwidth, iheight,itype, iexp; - bool plastic = false; - - if (*p->iy < 0) { - iy = widgetGlobals->FL_iy; - widgetGlobals->FL_iy += widgetGlobals->FLcontrol_iheight + 5; - } - else { - iy = (int) *p->iy; - widgetGlobals->FL_iy = iy + widgetGlobals->FLcontrol_iheight + 5; - } - if (*p->ix < 0) ix = widgetGlobals->FL_ix; // omitted options: set default - else widgetGlobals->FL_ix = ix = (int) *p->ix; - if (*p->iwidth < 0) iwidth = widgetGlobals->FLcontrol_iwidth; - else widgetGlobals->FLcontrol_iwidth = iwidth = (int) *p->iwidth; - if (*p->iheight < 0) iheight = widgetGlobals->FLcontrol_iheight; - else widgetGlobals->FLcontrol_iheight = iheight = (int) *p->iheight; - if (*p->itype < 1) itype = 1; - else itype = (int) *p->itype; - - //if (*p->iexp == LIN_) iexp = LIN_; - //else iexp = (int) *p->iexp; - switch((int) *p->iexp) { - case -1: iexp = EXP_; break; - case 0: iexp = LIN_; break; - default: iexp = (int) *p->iexp; - } - if (itype > 19) { - plastic = true; - itype = itype - 20; - } - if (UNLIKELY(itype > 10 && iexp == EXP_)) { - csound->Warning(csound, - "%s", Str("FLslider exponential, using non-labeled slider")); - itype -= 10; - } - - Fl_Slider *o; - if (itype <= 10) o = new Fl_Slider(ix, iy, iwidth, iheight, controlName); - else { - o = new Fl_Value_Slider_Input(csound, ix, iy, - iwidth, iheight, controlName); - itype -=10; - //o->labelsize(20); - ((Fl_Value_Slider_Input*) o)->textboxsize(50); - ((Fl_Value_Slider_Input*) o)->textsize(13); - o->align(FL_ALIGN_BOTTOM | FL_ALIGN_WRAP); - } - switch (itype) { - case 1: o->type(FL_HOR_FILL_SLIDER); break; - case 2: o->type(FL_VERT_FILL_SLIDER); break; - case 3: o->type(FL_HOR_SLIDER); break; - case 4: o->type(FL_VERT_SLIDER); break; - case 5: o->type(FL_HOR_NICE_SLIDER); o->box(FL_FLAT_BOX); break; - case 6: o->type(FL_VERT_NICE_SLIDER); o->box(FL_FLAT_BOX); break; - default: return csound->InitError(csound, - "%s", Str("FLslider: invalid slider type")); - } - if (plastic) o->box(FL_PLASTIC_DOWN_BOX); - widget_attributes(csound, o); - MYFLT min = p->min = *p->imin, max = *p->imax, range; - switch (iexp) { - case LIN_: //linear - o->range(min,max); - o->callback((Fl_Callback*)fl_callbackLinearSlider,(void *) p); - break; - case EXP_ : //exponential - if (UNLIKELY(min == 0 || max == 0)) - return csound->InitError(csound, - "%s", Str("FLslider: zero is illegal " - "in exponential operations")); - range = max - min; - o->range(0,range); - #if defined(sun) - p->base = ::pow((max / (double)min), 1.0/(double)range); - #else - p->base = ::pow((max / min), 1.0/(double)range); - #endif - o->callback((Fl_Callback*)fl_callbackExponentialSlider,(void *) p); - break; - default: - { - FUNC *ftp; - MYFLT fnum = abs(iexp); - if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) { - p->table = ftp->ftable; - p->tablen = ftp->flen; - } - else return NOTOK; - o->range(0,0.99999999); - if (iexp > 0) //interpolated - o->callback((Fl_Callback*)fl_callbackInterpTableSlider,(void *) p); - else // non-interpolated - o->callback((Fl_Callback*)fl_callbackTableSlider,(void *) p); - } - } - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(iexp, *p->imin, - *p->imax, (void *) o, (void*) p)); - /*widgetGlobals->currentSnapGroup;*/ - *p->ihandle = widgetGlobals->AddrSetValue.size()-1; - return OK; - } - - static int fl_slider_bank_(CSOUND *csound, FLSLIDERBANK *p, int istring) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char s[MAXNAME]; - bool plastic = false; - if (istring) - strncpy(s, ((STRINGDAT*) p->names)->data, MAXNAME-1); - else if ((long) *p->names <= csound->GetStrsmax(csound) && - csound->GetStrsets(csound,(long) *p->names)) { - strncpy(s, csound->GetStrsets(csound,(long) *p->names), MAXNAME-1); - } - string tempname(s); - stringstream sbuf; - sbuf << tempname; - - int width = (int) *p->iwidth; - if (width <=0) width = 100; - - Fl_Group* w = new Fl_Group((int)*p->ix, (int)*p->iy, - width, (int)*p->inumsliders*10); - FUNC *ftp; - MYFLT *minmaxtable = NULL, *typetable = NULL, *outable, *exptable = NULL; - - MYFLT *zkstart; - int zklast = csound->GetZakBounds(csound, &zkstart); - if (*p->ioutable < 1) { - if (LIKELY(zkstart != NULL && - zklast > (long)(*p->inumsliders+*p->ioutablestart_ndx))) - outable = zkstart + (long) *p->ioutablestart_ndx; - else { - return csound->InitError(csound, - "%s", Str("invalid ZAK space allocation")); - } - } - else { - if (LIKELY((ftp = csound->FTnp2Find(csound, p->ioutable)) != NULL)) - outable = ftp->ftable + (long) *p->ioutablestart_ndx; - else - return NOTOK; - } - if ((int) *p->iminmaxtable > 0) { - if (LIKELY((ftp = csound->FTnp2Find(csound, p->iminmaxtable)) != NULL)) - minmaxtable = ftp->ftable; - else return NOTOK; - } - if ((int) *p->iexptable > 0) { - if (LIKELY((ftp = csound->FTnp2Find(csound, p->iexptable)) != NULL)) - exptable = ftp->ftable; - else return NOTOK; - } - if ((int) *p->itypetable > 0) { - if (LIKELY((ftp = csound->FTnp2Find(csound, p->itypetable)) != NULL)) - typetable = ftp->ftable; - else return NOTOK; - } - - for (int j =0; j< *p->inumsliders; j++) { - string stemp; - if (tempname == " ") { - char s[40]; - sprintf(s, "%d", j); - stemp = s; - } - else - getline(sbuf, stemp, '@'); - char *Name = new char[stemp.size()+2]; - strcpy(Name,stemp.c_str()); - widgetGlobals->allocatedStrings.push_back(Name); - - int x = (int) *p->ix, y = (int) *p->iy + j*10; - Fl_Slider *o; - int slider_type; - if ((int) *p->itypetable <= 0) { // no slider type table - if (*p->itypetable >= -7) // all sliders are of the same type - slider_type = -((int) *p->itypetable); - else if (*p->itypetable >= -27 && *p->itypetable < -20) { - slider_type = -((int) *p->itypetable) - 20; - plastic = true; - } - else // random type - slider_type = rand_31_i(csound, 7) | 1; - } - else - slider_type = (int) typetable[j]; - if (slider_type > 20) { - plastic = true; - slider_type -= 20; - } - if (slider_type < 10) - o = new Fl_Slider(x, y, width, 10, Name); - else { - o = new Fl_Value_Slider_Input(csound, x, y, width, 10, Name); - slider_type -=10; - ((Fl_Value_Slider_Input*) o)->textboxsize(50); - ((Fl_Value_Slider_Input*) o)->textsize(13); - } - switch((int) slider_type) { //type - case 1: o->type(FL_HOR_FILL_SLIDER); break; - case 3: o->type(FL_HOR_SLIDER); break; - case 5: o->type(FL_HOR_NICE_SLIDER); o->box(FL_FLAT_BOX); break; - case 7: o->type(FL_HOR_NICE_SLIDER); o->box(FL_DOWN_BOX); break; - default: o->type(FL_HOR_NICE_SLIDER); o->box(FL_FLAT_BOX); break; - } - if (plastic) o->box(FL_PLASTIC_DOWN_BOX); - o->align(FL_ALIGN_LEFT); - widget_attributes(csound, o); - MYFLT min, max, range; - if ((int) *p->iminmaxtable > 0) { - min = minmaxtable[j*2]; - max = minmaxtable[j*2+1]; - } - else { - min = MYFLT(0.0); - max = MYFLT(1.0); - } - int iexp; - - p->slider_data[j].min=min; - p->slider_data[j].max=max; - p->slider_data[j].out=&outable[j]; - - if ((int) *p->iexptable <=0) - // no table, all sliders have the same behaviour - iexp = (int) *p->iexptable; - else - iexp = (int) exptable[j]; - switch (iexp) { - case -1: iexp = EXP_; break; - case 0: iexp = LIN_; break; - } - - MYFLT val = 0; - p->slider_data[j].exp = iexp; - switch (iexp) { - case LIN_: //linear - o->range(min,max); - o->callback((Fl_Callback*)fl_callbackLinearSliderBank, - (void *) &(p->slider_data[j])); - val = outable[j]; - if (val > max) val = max; - else if (val < min) val = min; - break; - case EXP_ : //exponential - if (UNLIKELY(min == 0 || max == 0)) - return - csound->InitError(csound, - "%s", Str("FLslidBnk: zero is illegal " - "in exponential operations")); - range = max - min; - o->range(0,range); - #if defined(sun) - p->slider_data[j].base = ::pow((max / (double)min), 1.0/(double)range); - #else - p->slider_data[j].base = ::pow((max / min), 1.0/(double)range); - #endif - o->callback((Fl_Callback*)fl_callbackExponentialSliderBank, - (void *) &(p->slider_data[j])); - { - val = outable[j]; - MYFLT range = max-min; - #if defined(sun) - MYFLT base = ::pow(max / (double)min, 1.0/(double)range); - #else - MYFLT base = ::pow(max / min, 1.0/(double)range); - #endif - val = (log(val/min) / log(base)) ; - } - break; - default: - { - FUNC *ftp; - MYFLT fnum = abs(iexp); - if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) - p->slider_data[j].table = ftp->ftable; - else return NOTOK; - p->slider_data[j].tablen = ftp->flen; - o->range(0,0.99999999); - if (iexp > 0) //interpolated - o->callback((Fl_Callback*)fl_callbackInterpTableSliderBank, - (void *) &(p->slider_data[j])); - else // non-interpolated - o->callback((Fl_Callback*)fl_callbackTableSliderBank, - (void *) &(p->slider_data[j])); - } - } - o->value(val); - } - w->resizable(w); - if (*p->iwidth <=0 || *p->iheight <=0) {// default width and height - int a,b; - w->size( a= w->parent()->w() -50, b= w->parent()->h()); - w->position(50, 0); - } - else { - w->size( (int)*p->iwidth, (int)*p->iheight); - w->position((int)*p->ix, (int)*p->iy); - } - w->end(); - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(LIN_, 0, 0, (void *) w, - (void *) p, - widgetGlobals->currentSnapGroup)); - //*p->ihandle = widgetGlobals->AddrSetValue.size()-1; - widgetGlobals->last_sldbnk = widgetGlobals->AddrSetValue.size()-1; //gab - return OK; - } - - static int fl_slider_bank(CSOUND *csound, FLSLIDERBANK *p){ - return fl_slider_bank_(csound,p,0); - } - - static int fl_slider_bank_S(CSOUND *csound, FLSLIDERBANK *p){ - return fl_slider_bank_(csound,p,1); - } - - static int fl_joystick(CSOUND *csound, FLJOYSTICK *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char *Name = p->name->data; - int ix,iy,iwidth, iheight, iexpx, iexpy; - - if (*p->ix < 0) ix = 10; // omitted options: set default - else widgetGlobals->FL_ix = ix = (int) *p->ix; - if (*p->iy < 0) iy = 10; // omitted options: set default - else iy = (int) *p->iy; - if (*p->iwidth < 0) iwidth = 130; - else iwidth = (int) *p->iwidth; - if (*p->iheight < 0) iheight = 130; - else iheight = (int) *p->iheight; - - switch((int) *p->iexpx) { - case -1: iexpx = EXP_; break; - case 0: iexpx = LIN_; break; - default: iexpx = (int) *p->iexpx; - } - switch((int) *p->iexpy) { - case -1: iexpy = EXP_; break; - case 0: iexpy = LIN_; break; - default: iexpy = (int) *p->iexpy; - } - /* - if (*p->iexpx == LIN_) iexpx = LIN_; - else iexpx = (int) *p->iexpx; - if (*p->iexpy == LIN_) iexpy = LIN_; - else iexpy = (int) *p->iexpy; - */ - - Fl_Positioner *o = new Fl_Positioner(ix, iy, iwidth, iheight, Name); - widget_attributes(csound, o); - switch (iexpx) { - case LIN_: //linear - o->xbounds(*p->iminx,*p->imaxx); break; - case EXP_: //exponential - { if (UNLIKELY(*p->iminx == 0 || *p->imaxx == 0)) - return csound->InitError(csound, - "%s", Str("FLjoy X axe: zero is illegal " - "in exponential operations")); - MYFLT range = *p->imaxx - *p->iminx; - o->xbounds(0,range); - #if defined(sun) - p->basex = ::pow((*p->imaxx / (double)*p->iminx), 1.0/(double)range); - #else - p->basex = ::pow((*p->imaxx / *p->iminx), 1.0/(double)range); - #endif - } break; - default: - { - FUNC *ftp; - MYFLT fnum = abs(iexpx); - if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) { - p->tablex = ftp->ftable; - p->tablenx = ftp->flen; - } - else return NOTOK; - o->xbounds(0,0.99999999); - /* - if (iexp > 0) //interpolated - o->callback((Fl_Callback*)fl_callbackInterpTableSlider,(void *) p); - else // non-interpolated - o->callback((Fl_Callback*)fl_callbackTableSlider,(void *) p); - */ - } - } - switch (iexpy) { - case LIN_: //linear - o->ybounds(*p->imaxy,*p->iminy); break; - case EXP_ : //exponential - { if (UNLIKELY(*p->iminy == 0 || *p->imaxy == 0)) - return csound->InitError(csound, - "%s", Str("FLjoy X axe: zero is illegal " - "in exponential operations")); - MYFLT range = *p->imaxy - *p->iminy; - o->ybounds(range,0); - #if defined(sun) - p->basey = ::pow((*p->imaxy / (double)*p->iminy), 1.0/(double)range); - #else - p->basey = ::pow((*p->imaxy / *p->iminy), 1.0/(double)range); - #endif - } break; - default: - { - FUNC *ftp; - MYFLT fnum = abs(iexpy); - if (LIKELY((ftp = csound->FTnp2Find(csound, &fnum)) != NULL)) { - p->tabley = ftp->ftable; - p->tableny = ftp->flen; - } - else return NOTOK; - o->ybounds(0,0.99999999); - /* if (iexp > 0) //interpolated - o->callback((Fl_Callback*)fl_callbackInterpTableSlider,(void *) p); - else // non-interpolated - o->callback((Fl_Callback*)fl_callbackTableSlider,(void *) p); - */ - } - } - o->align(FL_ALIGN_BOTTOM | FL_ALIGN_WRAP); - o->callback((Fl_Callback*)fl_callbackJoystick,(void *) p); - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(iexpx, *p->iminx, - *p->imaxx, (void *) o, (void *) p, - widgetGlobals->currentSnapGroup)); - *p->ihandle1 = widgetGlobals->AddrSetValue.size()-1; - ADDR_SET_VALUE *asv = &widgetGlobals->AddrSetValue[(int) *p->ihandle1]; - asv->widg_type = FL_JOY; - asv->joy = JOY_X; - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(iexpy, *p->iminy, - *p->imaxy, (void *) o, (void *) p, - widgetGlobals->currentSnapGroup)); - *p->ihandle2 = widgetGlobals->AddrSetValue.size()-1; - asv = &widgetGlobals->AddrSetValue[(int) *p->ihandle2]; - asv->widg_type = FL_JOY; - asv->joy = JOY_Y; - return OK; - } - - static int fl_knob(CSOUND *csound, FLKNOB *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char *controlName = p->name->data; - int ix, iy, iwidth, itype, iexp; - - if (*p->iy < 0) iy = widgetGlobals->FL_iy; - else widgetGlobals->FL_iy = iy = (int) *p->iy; - if (*p->ix < 0) ix = widgetGlobals->FL_ix; - else widgetGlobals->FL_ix = ix = (int) *p->ix; - if (*p->iwidth < 0) iwidth = widgetGlobals->FLcontrol_iwidth; - else widgetGlobals->FLcontrol_iwidth = iwidth = (int) *p->iwidth; - if (*p->itype < 1) itype = 1; - else itype = (int) *p->itype; - /* - if (*p->iexp < LIN_) iexp = LIN_; - else iexp = (int) *p->iexp; - */ - switch((int) *p->iexp) { - case -1: iexp = EXP_; break; - case 0: iexp = LIN_; break; - default: iexp = (int) *p->iexp; - } - - Fl_Valuator* o; - switch (itype) { - case 1: - o = new Fl_Knob(csound, ix, iy, iwidth, iwidth, controlName); - o->box(FL_NO_BOX); - if (*p->icursorsize > MYFLT(0.5)) - ((Fl_Knob*) o)->cursor((int) (*p->icursorsize + MYFLT(0.5))); - break; - case 2: - o = new Fl_Dial(ix, iy, iwidth, iwidth, controlName); - o->type(FL_FILL_DIAL); - o->box(_FL_OSHADOW_BOX); - ((Fl_Dial*) o)->angles(20, 340); - break; - case 3: - o = new Fl_Dial(ix, iy, iwidth, iwidth, controlName); - o->type(FL_LINE_DIAL); - o->box(_FL_OSHADOW_BOX); - break; - case 4: - o = new Fl_Dial(ix, iy, iwidth, iwidth, controlName); - o->type(FL_NORMAL_DIAL); - o->box(_FL_OSHADOW_BOX); - break; - default: - return csound->InitError(csound, - "%s", Str("FLknob: invalid knob type")); - } - widget_attributes(csound, o); - o->align(FL_ALIGN_BOTTOM | FL_ALIGN_WRAP); - o->range(*p->imin, *p->imax); - switch (iexp) { - case LIN_: //linear - o->range(*p->imin,*p->imax); - o->callback((Fl_Callback*)fl_callbackLinearKnob,(void *) p); - o->step(0.001); - break; - case EXP_ : //exponential - { - MYFLT min = p->min = *p->imin, max = *p->imax; - if (UNLIKELY(min == 0 || max == 0)) - return csound->InitError(csound, - "%s", Str("FLknob: zero is illegal " - "in exponential operations")); - MYFLT range = max - min; - o->range(0,range); - #if defined(sun) - p->base = ::pow((max / (double)min), 1.0/(double)range); - #else - p->base = ::pow((max / min), 1.0/(double)range); - #endif - o->callback((Fl_Callback*)fl_callbackExponentialKnob,(void *) p); - } break; - default: - { - FUNC *ftp; - p->min = *p->imin; - MYFLT fnum = abs(iexp); - if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) { - p->table = ftp->ftable; - p->tablen = ftp->flen; - } - else return OK; - o->range(0,0.99999999); - if (iexp > 0) //interpolated - o->callback((Fl_Callback*)fl_callbackInterpTableKnob,(void *) p); - else // non-interpolated - o->callback((Fl_Callback*)fl_callbackTableKnob,(void *) p); - } - } - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(iexp, *p->imin, *p->imax, - (void *) o, (void *) p)); - *p->ihandle = widgetGlobals->AddrSetValue.size()-1; - return OK; - } - - static int fl_text(CSOUND *csound, FLTEXT *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char *controlName = p->name->data; - int ix,iy,iwidth,iheight,itype; - MYFLT istep; - - if (*p->iy < 0) iy = widgetGlobals->FL_iy; - else widgetGlobals->FL_iy = iy = (int) *p->iy; - if (*p->ix < 0) ix = widgetGlobals->FL_ix; - else widgetGlobals->FL_ix = ix = (int) *p->ix; - if (*p->iwidth < 0) iwidth = widgetGlobals->FLcontrol_iwidth; - else widgetGlobals->FLcontrol_iwidth = iwidth = (int) *p->iwidth; - if (*p->iheight < 0) iheight = widgetGlobals->FLcontrol_iheight; - else widgetGlobals->FLcontrol_iheight = iheight = (int) *p->iheight; - if (*p->itype < 1) itype = 1; - else itype = (int) *p->itype; - if (*p->istep < 0) istep = MYFLT(.1); - else istep = *p->istep; - - Fl_Valuator* o; - switch(itype) { - case 1: - { - o = new Fl_Value_Input(ix, iy, iwidth, iheight, controlName); - ((Fl_Value_Input *) o)->step(istep); - ((Fl_Value_Input *) o)->range(*p->imin,*p->imax); - } - break; - case 2: - { - o = new Fl_Value_Input_Spin(csound, ix, iy, - iwidth, iheight, controlName); - ((Fl_Value_Input *) o)->step(istep); - ((Fl_Value_Input *) o)->range(*p->imin,*p->imax); - } - break; - case 3: - { - o = new Fl_Value_Output(ix, iy, iwidth, iheight, controlName); - ((Fl_Value_Output *) o)->step(istep); - ((Fl_Value_Output *) o)->range(*p->imin,*p->imax); - } - break; - default: - return NOTOK; - } - o->align(FL_ALIGN_BOTTOM | FL_ALIGN_WRAP); - widget_attributes(csound, o); - o->callback((Fl_Callback*)fl_callbackLinearValueInput,(void *) p); - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(1, *p->imin, *p->imax, - (void *) o, (void *) p, - widgetGlobals->currentSnapGroup)); - *p->ihandle = widgetGlobals->AddrSetValue.size()-1; - return OK; - } - - static int fl_button(CSOUND *csound, FLBUTTON *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char *Name = p->name->data; - int type = (int) *p->itype; - bool plastic = false; - if (type > 19) { - type = type - 20; - plastic = true; - } - if (UNLIKELY(type > 9)) { // ignored when getting widgetGlobals->snapshots - csound->Warning(csound, - Str("FLbutton \"%s\" ignoring snapshot capture retrieve"), - Name); - type = type - 10; - } - Fl_Button *w; - *p->kout = *p->ioff; // IV - Aug 27 2002 - - switch (type) { - case 1: - w = new Fl_Button((int)*p->ix, (int)*p->iy, - (int)*p->iwidth, (int)*p->iheight, Name); - if (plastic) { - w->box(FL_PLASTIC_UP_BOX); - w->down_box(FL_PLASTIC_DOWN_BOX); - } - break; - case 2: - w = new Fl_Light_Button((int)*p->ix, (int)*p->iy, - (int)*p->iwidth, (int)*p->iheight, Name); - if (plastic) { - w->box(FL_PLASTIC_UP_BOX); - // w->down_box(FL_PLASTIC_DOWN_BOX); //Doesn't work - } - break; - case 3: - w = new Fl_Check_Button((int)*p->ix, (int)*p->iy, - (int)*p->iwidth, (int)*p->iheight, Name); - if (plastic) { - w->box(FL_PLASTIC_UP_BOX); - w->down_box(FL_PLASTIC_DOWN_BOX); - } - break; - case 4: - w = new Fl_Round_Button((int)*p->ix, (int)*p->iy, - (int)*p->iwidth, (int)*p->iheight, Name); - if (plastic) { - w->box(FL_PLASTIC_UP_BOX); - w->down_box(FL_PLASTIC_DOWN_BOX); - } - break; - default: - return csound->InitError(csound, - "%s", Str("FLbutton: invalid button type")); - } - Fl_Button *o = w; - o->align(FL_ALIGN_WRAP); - widget_attributes(csound, o); - if (type == 1) - o->callback((Fl_Callback*) fl_callbackButton1, (void*) p); - else - o->callback((Fl_Callback*) fl_callbackButton, (void*) p); - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(0, 0, 0, (void *) o, - (void *) p, - widgetGlobals->currentSnapGroup)); - *p->ihandle = widgetGlobals->AddrSetValue.size() - 1; - - return OK; - } - - static int fl_close_button(CSOUND *csound, FLCLOSEBUTTON *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char *Name = p->name->data; - - Fl_Button *w; - - w = new Fl_Button((int)*p->ix, (int)*p->iy, - (int)*p->iwidth, (int)*p->iheight, Name); - - Fl_Button *o = w; - - o->align(FL_ALIGN_WRAP); - widget_attributes(csound, o); - - ADDR_STACK adrstk = widgetGlobals->AddrStack.back(); - if (UNLIKELY(strcmp( adrstk.h->optext->t.opcod, "FLpanel"))) - return csound->InitError(csound, - "%s", Str("FLcloseButton: invalid stack" - " pointer: verify its placement")); - - o->callback((Fl_Callback*) fl_callbackCloseButton, - (void*) adrstk.WidgAddress); - - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(0, 0, 0, (void *) o, - (void *) p)); - *p->ihandle = widgetGlobals->AddrSetValue.size() - 1; - - return OK; - } - - static int fl_exec_button(CSOUND *csound, FLEXECBUTTON *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - p->csound = csound; - Fl_Button *w; - - p->commandString = p->command->data; - - csound->Message(csound, Str("Command Found: %s\n"), p->commandString); - - w = new Fl_Button((int)*p->ix, (int)*p->iy, - (int)*p->iwidth, (int)*p->iheight, Str("About")); - - Fl_Button *o = w; - - o->align(FL_ALIGN_WRAP); - widget_attributes(csound, o); - - o->callback((Fl_Callback*) fl_callbackExecButton, (void*) p); - - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(0, 0, 0, - (void *) o, (void *) p, - widgetGlobals->currentSnapGroup)); - *p->ihandle = widgetGlobals->AddrSetValue.size() - 1; - - return OK; - } - - static int fl_button_bank(CSOUND *csound, FLBUTTONBANK *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char *Name = (char*)"/0"; - int type = (int) *p->itype; - bool plastic = false; - if (type > 20) { - plastic = true; - type = type - 20; - } - if (UNLIKELY(type > 9)) { // ignored when getting widgetGlobals->snapshots - csound->Warning(csound, - Str("FLbutton \"%s\" ignoring snapshot capture retrieve"), - Name); - type = type - 10; - } - Fl_Group* o = new Fl_Group((int)*p->ix, (int)*p->iy, - (int)*p->inumx * 10, (int)*p->inumy*10); - int z = 0; - for (int j = 0; j < *p->inumx; j++) { - for (int k = 0; k < *p->inumy; k++) { - int x = (int) *p->ix + j*10, y = (int) *p->iy + k*10; - Fl_Button *w; - char *btName = new char[30]; - widgetGlobals->allocatedStrings.push_back(btName); - sprintf(btName, "%d", z); - switch (type) { - case 1: - w = new Fl_Button(x, y, 10, 10, btName); - if (plastic) { - w->box(FL_PLASTIC_UP_BOX); - w->down_box(FL_PLASTIC_DOWN_BOX); - } - break; - case 2: - w = new Fl_Light_Button(x, y, 10, 10, btName); - if (plastic) { - w->box(FL_PLASTIC_UP_BOX); - } - break; - case 3: - w = new Fl_Check_Button(x, y, 10, 10, btName); - if (plastic) { - w->box(FL_PLASTIC_UP_BOX); - w->down_box(FL_PLASTIC_DOWN_BOX); - } - break; - case 4: - w = new Fl_Round_Button(x, y, 10, 10, btName); - if (plastic) { - w->box(FL_PLASTIC_UP_BOX); - w->down_box(FL_PLASTIC_DOWN_BOX); - } - break; - default: return csound->InitError(csound, - "%s", Str("FLbuttonBank: " - "invalid button type")); - } - widget_attributes(csound, w); - w->type(FL_RADIO_BUTTON); - w->callback((Fl_Callback*) fl_callbackButtonBank, (void *) p); - if (!z) - w->value(1); - z++; - } - } - o->resizable(o); - //*p->ix, *p->iy, - o->size( (int)*p->iwidth, (int)*p->iheight); - o->position((int)*p->ix, (int)*p->iy); - o->align(FL_ALIGN_BOTTOM | FL_ALIGN_WRAP); - o->end(); - - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(0, 0, 0, - (void *) o, (void *) p, - widgetGlobals->currentSnapGroup)); - *p->kout = MYFLT(0.0); - *p->ihandle = widgetGlobals->AddrSetValue.size()-1; - return OK; - } - - static int fl_counter(CSOUND *csound, FLCOUNTER *p) - { - char *controlName = p->name->data; - // int ix,iy,iwidth,iheight,itype; - // MYFLT istep1, istep2; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - Fl_Counter* o = new Fl_Counter((int)*p->ix, (int)*p->iy, - (int)*p->iwidth, (int)*p->iheight, - controlName); - widget_attributes(csound, o); - int type = (int) *p->itype; - if (UNLIKELY(type >9 )) { // ignored when getting widgetGlobals->snapshots - csound->Warning(csound, - Str("FLcount \"%s\" ignoring snapshot capture retrieve"), - controlName); - type = type-10; - } - switch(type) { - case 1: o->type(FL_NORMAL_COUNTER); break; - case 2: o->type(FL_SIMPLE_COUNTER); break; - default:o->type(FL_NORMAL_COUNTER); break; - } - - o->step(*p->istep1); - o->lstep(*p->istep2); - o->align(FL_ALIGN_BOTTOM | FL_ALIGN_WRAP); - // range is accepted only if min and max are different - if (*p->imin != *p->imax) - o->range(*p->imin,*p->imax); //otherwise no-range - widget_attributes(csound, o); - o->callback((Fl_Callback*)fl_callbackCounter,(void *) p); - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(1, 0, 100000, (void *) o, - (void *) p, - widgetGlobals->currentSnapGroup)); - *p->ihandle = widgetGlobals->AddrSetValue.size()-1; - return OK; - } - - static int fl_roller(CSOUND *csound, FLROLLER *p) - { - char *controlName = p->name->data; - int ix,iy,iwidth, iheight,itype, iexp ; - double istep; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (*p->iy < 0) { - iy = widgetGlobals->FL_iy; - widgetGlobals->FL_iy += widgetGlobals->FLroller_iheight + 15; - } - else { - iy = (int) *p->iy; - widgetGlobals->FL_iy = iy + widgetGlobals->FLroller_iheight + 15; - } - // omitted options: set defaults - if (*p->ix<0) ix = widgetGlobals->FL_ix; - else widgetGlobals->FL_ix = ix = (int) *p->ix; - if (*p->iy<0) iy = widgetGlobals->FL_iy; - else widgetGlobals->FL_iy = iy = (int) *p->iy; - if (*p->iwidth<0) iwidth = widgetGlobals->FLroller_iwidth; - else widgetGlobals->FLroller_iwidth = iwidth = (int) *p->iwidth; - if (*p->iheight<0) iheight = widgetGlobals->FLroller_iheight; - else widgetGlobals->FLroller_iheight = iheight = (int) *p->iheight; - if (*p->itype<1) itype = 1; - else itype = (int) *p->itype; - //if (*p->iexpiexp; - switch((int) *p->iexp) { - case -1: iexp = EXP_; break; - case 0: iexp = LIN_; break; - default: iexp = (int) *p->iexp; - } - - if (*p->istep<0) istep = 1; else istep = *p->istep; - p->min = *p->imin; - Fl_Roller *o; - switch (itype) { - case 1: - o = new Fl_Roller(ix, iy, iwidth, iheight, controlName); - o->type(FL_HORIZONTAL); - break; - case 2: - o = new Fl_Roller(ix, iy, iwidth, iheight, controlName); - o->type(FL_VERTICAL); - break; - default: - return csound->InitError(csound, - "%s", Str("FLroller: invalid roller type")); - } - widget_attributes(csound, o); - o->step(istep); - switch (iexp) { - case LIN_: //linear - o->range(*p->imin,*p->imax); - o->callback((Fl_Callback*)fl_callbackLinearRoller,(void *) p); - break; - case EXP_ : //exponential - { - MYFLT min = p->min, max = *p->imax; - if (UNLIKELY(min == 0 || max == 0)) - return csound->InitError(csound, - "%s", Str("FLslider: zero is illegal " - "in exponential operations")); - MYFLT range = max - min; - o->range(0,range); - #if defined(sun) - p->base = ::pow((max / (double)min), 1.0/(double)range); - #else - p->base = ::pow((max / min), 1.0/(double)range); - #endif - o->callback((Fl_Callback*)fl_callbackExponentialRoller,(void *) p); - } - break; - default: - { - FUNC *ftp; - MYFLT fnum = abs(iexp); - if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) { - p->table = ftp->ftable; - p->tablen = ftp->flen; - } - else return NOTOK; - o->range(0,0.99999999); - if (iexp > 0) //interpolated - o->callback((Fl_Callback*)fl_callbackInterpTableRoller,(void *) p); - else // non-interpolated - o->callback((Fl_Callback*)fl_callbackTableRoller,(void *) p); - } - } - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(iexp, *p->imin, *p->imax, - (void *) o, (void *) p, - widgetGlobals->currentSnapGroup)); - *p->ihandle = widgetGlobals->AddrSetValue.size()-1; - return OK; - } - - static int FLprintkset(CSOUND *csound, FLPRINTK *p) - { - //WIDGET_GLOBALS *widgetGlobals = - //(WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (*p->ptime < MYFLT(1.0) / CS_EKR) - p->ctime = MYFLT(1.0) / CS_EKR; - else p->ctime = *p->ptime; - - p->initime = (MYFLT) csound->GetKcounter(csound) * (1.0/CS_EKR); - p->cysofar = -1; - return OK; - } - - static int FLprintk(CSOUND *csound, FLPRINTK *p) - { - MYFLT timel; - long cycles; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - - timel = ((MYFLT) csound->GetKcounter(csound) * - (1.0/CS_EKR)) - p->initime; - cycles = (long)(timel / p->ctime); - if (p->cysofar < cycles) { - p->cysofar = cycles; - char valString[MAXNAME]; - sprintf(valString,"%.5g", *p->val); - ((Fl_Output*) (widgetGlobals->AddrSetValue[(long) *p->idisp]).WidgAddress)-> - value(valString ); - } - return OK; - } - - static int FLprintk2set(CSOUND *csound, FLPRINTK2 *p) // IV - Aug 27 2002 - { - IGN(csound); - p->oldvalue = MYFLT(-1.12123e35); // hack to force printing first value - return OK; - } - - static int FLprintk2(CSOUND *csound, FLPRINTK2 *p) - { - MYFLT value = *p->val; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (p->oldvalue != value) { - char valString[MAXNAME]; - sprintf(valString,"%.5g", *p->val); - ((Fl_Output*) (widgetGlobals->AddrSetValue[(long) *p->idisp]).WidgAddress)-> - value(valString ); - p->oldvalue = value; - } - return OK; - } - - // New opcodes for Csound5.06 by Gabriel Maldonado, ported by Andres Cabrera - - void skin(CSOUND* csound, Fl_Widget *o, int imgNum, bool isTiled) - { - IGN(csound); IGN(o); IGN(imgNum); IGN(isTiled); - // WIDGET_GLOBALS *widgetGlobals = - // (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); -#ifdef CS_IMAGE - extern void* get_image(CSOUND* csound, int imgNum); - ImageSTRUCT *bmp = (ImageSTRUCT*) get_image(csound, imgNum); - FLlock(); - Fl_RGB_Image *img = new Fl_RGB_Image((BYTE*) (bmp->data), - bmp->xsize,bmp->ysize,bmp->csize); - widgetGlobals->allocatedStrings.push_back((char *) img); - if (isTiled) { - Fl_Tiled_Image *t_img = new Fl_Tiled_Image(img); - o->image(t_img); - widgetGlobals->allocatedStrings.push_back((char *) t_img); - } - else { - o->image(img); - } - o->align(FL_ALIGN_INSIDE); - FLunlock(); -#endif - } - - class HVS_BOX : public Fl_Box{ - int rx,ry,rw,rh; - int red, green, blue; - // Fl_PNG_Image *img; - public: - - int numLinesX,numLinesY; - MYFLT valueX, valueY; - - HVS_BOX(int numLinesX_, int numLinesY_, int x, int y, int w, int h) : - Fl_Box(x,y,w,h) { - numLinesX = numLinesX_ - 1; - numLinesY = numLinesY_ - 1; - valueX = valueY = .5; - rx = rw = ry = rh = 0; - red = green = blue = 0; - // if (filename != NULL) { - // img = new Fl_PNG_Image(filename); - // this->image(img); - // } - } - void draw() { - Fl_Box::draw(); - - fl_color(selection_color()); - MYFLT Xincr = w()/(MYFLT) numLinesX; - MYFLT Yincr = h()/(MYFLT) numLinesY; - fl_color(FL_RED); - for (int j = 1; j < numLinesX; j++) { - fl_yxline((int) (j*Xincr+x()), y(), h()+y()); - } - for (int k = 1; k QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (UNLIKELY(*p->numlinesX < 2 || *p->numlinesY < 2)) - return csound->InitError(csound, - "%s", Str("FLhvsBox: a square area must be" - " delimited by 2 lines at least")); - - HVS_BOX *o = new HVS_BOX((int) *p->numlinesX,(int) *p->numlinesY, - (int) *p->ix,(int) *p->iy, - (int) *p->iwidth, (int) *p->iheight); - widget_attributes(csound,o); - o->box(FL_DOWN_BOX); - if (*p->image >= 0) skin(csound, o, (int) *p->image, false); - - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(0, 0, 0, - (void *) o, (void *) p, - widgetGlobals->currentSnapGroup)); - *p->ihandle = widgetGlobals->AddrSetValue.size()-1; - return OK; - - } - - static int fl_setHvsValue_set(CSOUND *csound,FL_SET_HVS_VALUE *p) - { - IGN(csound); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - ADDR_SET_VALUE v = widgetGlobals->AddrSetValue[(int) *p->ihandle]; - p->WidgAddress = v.WidgAddress; - p->opcode = v.opcode; - return OK; - } - - static int fl_setHvsValue(CSOUND *csound,FL_SET_HVS_VALUE *p) - { - IGN(csound); - if(*p->kx != p->old_x || *p->ky != p->old_y ) { - HVS_BOX *o = (HVS_BOX *) p->WidgAddress; - FLlock(); - o->setXY(*p->kx, *p->ky); - FLunlock(); - p->old_x = *p->kx; - p->old_y = *p->ky; - } - return OK; - } - - - static int fl_keyin_set(CSOUND *csound,FLKEYIN *p) - { - FUNC* ftp; - if (*p->ifn > 0) { // mapping values - p->flag = 1; - - if (LIKELY((ftp = csound->FTnp2Find(csound,p->ifn)) != NULL)) - p->table = ftp->ftable; - else { - return csound->InitError(csound, - "%s", Str("FLkeyIn: invalid table number")); - } - if (UNLIKELY(ftp->flen < 512)) { - return csound->InitError(csound, - "%s", Str("FLkeyIn: table too short!")); - } - } - else p->flag = 0; - return OK; - } - - static int fl_keyin(CSOUND *csound,FLKEYIN *p) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (widgetGlobals->last_KEY) { - int key; - - if ( widgetGlobals->last_KEY > 0 && widgetGlobals->last_KEY < 256) - key = widgetGlobals->last_KEY; - else - key = (widgetGlobals->last_KEY & 0xFF) + 256; // function keys - - if(p->flag) { - if(widgetGlobals->isKeyDown) - p->table[key] = 1; - else - p->table[key] = 0; - } - if (widgetGlobals->isKeyDown) *p->kascii = key; - else *p->kascii = -key; - widgetGlobals->last_KEY = 0; - } - return OK; - } - - static int fl_setSnapGroup(CSOUND *csound, FLSETSNAPGROUP *p) - { - IGN(csound); - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - widgetGlobals->currentSnapGroup = (int) *p->group; - return OK; - } - - static int fl_mouse_set(CSOUND *csound,FLMOUSE *p) - { - IGN(csound); - p->width= Fl::w(); - p->height= Fl::h(); - return OK; - } - - static int fl_mouse(CSOUND *csound,FLMOUSE *p) - { - IGN(csound); - if (*p->flagRaw == 0) { - *p->x = (MYFLT) Fl::event_x_root()/p->width; - *p->y = 1.0 - ((MYFLT) Fl::event_y_root()/p->height); - } - else if (*p->flagRaw == 1) { - *p->x = (MYFLT) Fl::event_x_root(); - *p->y = (MYFLT) Fl::event_y_root(); - } - else if (*p->flagRaw == 2) { - *p->x = (MYFLT) Fl::event_x(); - *p->y = (MYFLT) Fl::event_y(); - } - // *p->b1 = (MYFLT) (Fl::event_button1() >> 56); - // *p->b2 = (MYFLT) (Fl::event_button2() >> 57); - // *p->b3 = (MYFLT) (Fl::event_button3() >> 58); - *p->b1 = (MYFLT) (Fl::event_button1() >> 24); - *p->b2 = (MYFLT) (Fl::event_button2() >> 25); - *p->b3 = (MYFLT) (Fl::event_button3() >> 26); - - return OK; - } - - - static int fl_vertical_slider_bank_(CSOUND *csound, FLSLIDERBANK *p, int istring) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char s[MAXNAME]; - bool plastic = false; - if (istring) - strncpy(s, ((STRINGDAT *)p->names)->data, MAXNAME-1); - else if ((long) *p->names <= csound->GetStrsmax(csound) && - csound->GetStrsets(csound,(long) *p->names)) { - strncpy(s, csound->GetStrsets(csound,(long) *p->names), MAXNAME-1); - } - string tempname(s); - stringstream sbuf; - sbuf << tempname; - - int height = (int) *p->iheight; - if (height <=0) height = 100; - Fl_Group* w = new Fl_Group((int)*p->ix, (int)*p->iy, - (int)*p->inumsliders*10, height); - FUNC *ftp; - MYFLT *minmaxtable = NULL, *typetable = NULL, *outable, *exptable = NULL; - - MYFLT *zkstart; - int zklast = csound->GetZakBounds(csound, &zkstart); - if (*p->ioutable < 1) { - if (LIKELY(zkstart != NULL && - zklast > (long)(*p->inumsliders+*p->ioutablestart_ndx))) - outable = zkstart + (long) *p->ioutablestart_ndx; - else { - return csound->InitError(csound, - "%s", Str("invalid ZAK space allocation")); - } - } - else { - if (LIKELY((ftp = csound->FTnp2Find(csound, p->ioutable)) != NULL)) - outable = ftp->ftable + (long) *p->ioutablestart_ndx; - else - return NOTOK; - } - if ((int) *p->iminmaxtable > 0) { - if (LIKELY((ftp = csound->FTnp2Find(csound, p->iminmaxtable)) != NULL)) - minmaxtable = ftp->ftable; - else return NOTOK; - } - if ((int) *p->iexptable > 0) { - if (LIKELY((ftp = csound->FTnp2Find(csound, p->iexptable)) != NULL)) - exptable = ftp->ftable; - else return NOTOK; - } - if ((int) *p->itypetable > 0) { - if (LIKELY((ftp = csound->FTnp2Find(csound, p->itypetable)) != NULL)) - typetable = ftp->ftable; - else return NOTOK; - } - p->elements = (long) *p->inumsliders; - - for (int j =0; j< p->elements; j++) { - string stemp; - if (tempname == " ") { - char s[40]; - sprintf(s, "%d", j); - stemp = s; - } - else - getline(sbuf, stemp, '@'); - char *Name = new char[stemp.size()+2]; - strcpy(Name,stemp.c_str()); - widgetGlobals->allocatedStrings.push_back(Name); - - int x = (int) *p->ix+j*10, y = (int) *p->iy /*+ j*10*/; - Fl_Slider *o; - int slider_type; - if ((int) *p->itypetable <= 0) { // no slider type table - if (*p->itypetable >= -7) // all sliders are of the same type - slider_type = -((int) *p->itypetable); - else if (*p->itypetable >= -27 && *p->itypetable < -20) { - slider_type = -((int) *p->itypetable) - 20; - plastic = true; - } - else { // random type - slider_type = rand_31_i(csound, 7) | 1; - switch(slider_type) { - case 0: slider_type = 1; break; - case 2: slider_type = 3; break; - case 4: slider_type = 5; break; - case 6: slider_type = 7; break; - default: slider_type = 1; - } - } - } - else - slider_type = (int) typetable[j]; - if (slider_type > 20) { - plastic = true; - slider_type -= 20; - } - if (slider_type < 10) - o = new Fl_Slider(x, y, 10, height, Name); - else { - o = new Fl_Value_Slider_Input(csound, x, y, 10, height, Name); - slider_type -=10; - ((Fl_Value_Slider_Input*) o)->textboxsize(50); - ((Fl_Value_Slider_Input*) o)->textsize(13); - } - switch((int) slider_type) { //type - case 1: o->type(FL_VERT_FILL_SLIDER); break; - case 3: o->type(FL_VERT_SLIDER); break; - case 5: o->type(FL_VERT_NICE_SLIDER); o->box(FL_FLAT_BOX); break; - case 7: o->type(FL_VERT_NICE_SLIDER); o->box(FL_DOWN_BOX); break; - default: o->type(FL_VERT_NICE_SLIDER); o->box(FL_FLAT_BOX); break; - } - o->align(FL_ALIGN_BOTTOM); - if (plastic) o->box(FL_PLASTIC_DOWN_BOX); - widget_attributes(csound, o); - MYFLT min, max, range; - if ((int) *p->iminmaxtable > 0) { - min = minmaxtable[j*2]; - max = minmaxtable[j*2+1]; - } - else { - min = MYFLT(0.0); - max = MYFLT(1.0); - } - int iexp; - - p->slider_data[j].min=min; - p->slider_data[j].max=max; - p->slider_data[j].out=&outable[j]; - - if ((int) *p->iexptable <=0) - // no table, all sliders have the same behaviour - iexp = (int) *p->iexptable; - else - iexp = (int) exptable[j]; - switch (iexp) { - case -1: iexp = EXP_; break; - case 0: iexp = LIN_; break; - } - - MYFLT val = 0; - p->slider_data[j].exp = iexp; - switch (iexp) { - case LIN_: //linear - o->range(min,max); - o->callback((Fl_Callback*)fl_callbackLinearSliderBank, - (void *) &(p->slider_data[j])); - val = outable[j]; - if (val > max) val = max; - else if (val < min) val = min; - break; - case EXP_ : //exponential - if (UNLIKELY(min == 0 || max == 0)) - return - csound->InitError(csound, - "%s", Str("FLvslidBnk: zero is illegal " - "in exponential operations")); - range = max - min; - o->range(range,0); - #if defined(sun) - p->slider_data[j].base = ::pow((max / (double)min), 1.0/(double)range); - #else - p->slider_data[j].base = ::pow((max / min), 1.0/(double)range); - #endif - o->callback((Fl_Callback*)fl_callbackExponentialSliderBank, - (void *) &(p->slider_data[j])); - { - val = outable[j]; - MYFLT range = max-min; - #if defined(sun) - MYFLT base = ::pow(max / (double)min, 1.0/(double)range); - #else - MYFLT base = ::pow(max / min, 1.0/(double)range); - #endif - val = (log(val/min) / log(base)) ; - } - break; - default: - { - FUNC *ftp; - MYFLT fnum = abs(iexp); - if (LIKELY((ftp = csound->FTnp2Find(csound, &fnum)) != NULL)) - p->slider_data[j].table = ftp->ftable; - else return NOTOK; - p->slider_data[j].tablen = ftp->flen; - o->range(.99999999,0); - if (iexp > 0) //interpolated - o->callback((Fl_Callback*)fl_callbackInterpTableSliderBank, - (void *) &(p->slider_data[j])); - else // non-interpolated - o->callback((Fl_Callback*)fl_callbackTableSliderBank, - (void *) &(p->slider_data[j])); - } - } - o->value(val); - p->slider_data[j].widget_addr= (void*) o; - } - w->resizable(w); - if (*p->iwidth <=0 || *p->iheight <=0) {// default width and height - int a,b; - w->size( a= w->parent()->w(), b= w->parent()->h()-50); - w->position(0, 0); - } - else { - w->size( (int)*p->iwidth, (int)*p->iheight); - w->position((int)*p->ix, (int)*p->iy); - } - w->end(); - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(LIN_, 0, 0, (void *) w, - (void *) p, - widgetGlobals->currentSnapGroup)); - widgetGlobals->last_sldbnk = widgetGlobals->AddrSetValue.size()-1; //gab - - return OK; - } - - static int fl_vertical_slider_bank(CSOUND *csound, FLSLIDERBANK *p){ - return fl_vertical_slider_bank_(csound,p,0); - } - - static int fl_vertical_slider_bank_S(CSOUND *csound, FLSLIDERBANK *p){ - return fl_vertical_slider_bank_(csound,p,1); - } - - - static int fl_slider_bank2_(CSOUND *csound, FLSLIDERBANK2 *p, int istring) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char s[MAXNAME]; - bool plastic = false; - if (istring) - strncpy(s, ((STRINGDAT*) p->names)->data, MAXNAME-1); - else if ((long) *p->names <= csound->GetStrsmax(csound) && - csound->GetStrsets(csound,(long) *p->names)) { - strncpy(s, csound->GetStrsets(csound,(long) *p->names), MAXNAME-1); - } - string tempname(s); - stringstream sbuf; - sbuf << tempname; - - int width = (int) *p->iwidth; - if (width <=0) width = 100; - - Fl_Group* w = new Fl_Group((int)*p->ix, (int)*p->iy, - width, (int)*p->inumsliders*10); - FUNC *ftp; - MYFLT *configtable, *outable; - - MYFLT *zkstart; - int zklast = csound->GetZakBounds(csound, &zkstart); - if (*p->ioutable < 1) { - if (LIKELY(zkstart != NULL && - zklast>(long)(*p->inumsliders + *p->ioutablestart_ndx))) - outable = zkstart + (long) *p->ioutablestart_ndx; - else { - return csound->InitError(csound, - "%s", Str("invalid ZAK space allocation")); - } - } - else { - if ((ftp = csound->FTnp2Find(csound, p->ioutable)) != NULL) - outable = ftp->ftable + (long) *p->ioutablestart_ndx; - else - return NOTOK; - } - if((ftp = csound->FTnp2Find(csound, p->iconfigtable)) != NULL) - configtable = ftp->ftable; - else return NOTOK; - - p->elements = (long) *p->inumsliders; - for (int j =0; j< p->elements; j++) { - string stemp; - if (tempname == " ") { - char s[40]; - sprintf(s, "%d", j); - stemp = s; - } - else - getline(sbuf, stemp, '@'); - char *Name = new char[stemp.size()+2]; - strcpy(Name,stemp.c_str()); - widgetGlobals->allocatedStrings.push_back(Name); - - int x = (int) *p->ix, y = (int) *p->iy + j*10; - Fl_Slider *o; - int slider_type = (int) configtable[j*4+3]; - int iexp = (int) configtable[j*4+2]; - - if (slider_type > 19) { - plastic = true; - slider_type = slider_type - 20; - } - if (UNLIKELY(slider_type > 10 && iexp == EXP_)) { - csound->Warning(csound, "%s", - Str("FLslider exponential, using non-labeled slider")); - slider_type -= 10; - } - if (slider_type <= 10) - o = new Fl_Slider(x, y, width, 10, Name); - else { - o = new Fl_Value_Slider_Input( csound, x, y, width, 10, Name); - slider_type -=10; - ((Fl_Value_Slider_Input*) o)->textboxsize(20); - ((Fl_Value_Slider_Input*) o)->textsize(13); - } - switch((int) slider_type) { //type - case 1: o->type(FL_HOR_FILL_SLIDER); break; - case 3: o->type(FL_HOR_SLIDER); break; - case 5: o->type(FL_HOR_NICE_SLIDER); o->box(FL_FLAT_BOX); break; - case 7: o->type(FL_HOR_NICE_SLIDER); o->box(FL_DOWN_BOX); break; - default: o->type(FL_HOR_NICE_SLIDER); o->box(FL_FLAT_BOX); break; - } - o->align(FL_ALIGN_LEFT); - if (plastic) o->box(FL_PLASTIC_DOWN_BOX); - o->step(0.0); - widget_attributes(csound, o); - MYFLT min, max, range; - min = configtable[j*4]; - max = configtable[j*4+1]; - - p->slider_data[j].min=min; - p->slider_data[j].max=max; - p->slider_data[j].out=&outable[j]; - - switch (iexp) { - case -1: iexp = EXP_; break; - case 0: iexp = LIN_; break; - } - - MYFLT val = 0; - p->slider_data[j].exp = iexp; - - switch (iexp) { - case LIN_: //linear - o->range(min,max); - o->callback((Fl_Callback*)fl_callbackLinearSliderBank, - (void *) &(p->slider_data[j])); - val = outable[j]; - if (val > max) val = max; - else if (val < min) val = min; - break; - case EXP_ : //exponential - if (UNLIKELY(min == 0 || max == 0)) - return - csound->InitError(csound, - "%s", Str("FLsliderBank: zero is illegal " - "in exponential operations")); - range = max - min; - o->range(0,range); - #if defined(sun) - p->slider_data[j].base = ::pow((max / (double)min), 1.0/(double)range); - #else - p->slider_data[j].base = ::pow((max / min), 1.0/(double)range); - #endif - o->callback((Fl_Callback*)fl_callbackExponentialSliderBank, - (void *) &(p->slider_data[j])); - { - val = outable[j]; - MYFLT range = max-min; - #if defined(sun) - MYFLT base = ::pow(max / (double)min, 1.0/(double)range); - #else - MYFLT base = ::pow(max / min, 1.0/(double)range); - #endif - val = (log(val/min) / log(base)) ; - } - break; - default: - { - FUNC *ftp; - MYFLT fnum = abs(iexp); - if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) - p->slider_data[j].table = ftp->ftable; - else return NOTOK; - p->slider_data[j].tablen = ftp->flen; - o->range(0,0.99999999); - if (iexp > 0) //interpolated - o->callback((Fl_Callback*)fl_callbackInterpTableSliderBank, - (void *) &(p->slider_data[j])); - else // non-interpolated - o->callback((Fl_Callback*)fl_callbackTableSliderBank, - (void *) &(p->slider_data[j])); - } - } - o->value(val); - p->slider_data[j].widget_addr= (void*) o; - } - w->resizable(w); - if (*p->iwidth <=0 || *p->iheight <=0) {// default width and height - int a,b; - w->size( a= w->parent()->w() -50, b= w->parent()->h()); - w->position(50, 0); - } - else { - w->size( (int)*p->iwidth, (int)*p->iheight); - w->position((int)*p->ix, (int)*p->iy); - } - w->end(); - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(LIN_, 0, 0, (void *) w, - (void *) p, - widgetGlobals->currentSnapGroup)); - //*p->ihandle = widgetGlobals->AddrSetValue.size()-1; - widgetGlobals->last_sldbnk = widgetGlobals->AddrSetValue.size()-1; //gab - - return OK; - } - - static int fl_slider_bank2(CSOUND *csound, FLSLIDERBANK2 *p){ - return fl_slider_bank2_(csound, p,0); - } - - static int fl_slider_bank2_S(CSOUND *csound, FLSLIDERBANK2 *p){ - return fl_slider_bank2_(csound, p,1); - } - - static int fl_vertical_slider_bank2_(CSOUND *csound, - FLSLIDERBANK2 *p, int istring) - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - char s[MAXNAME]; - bool plastic = false; - if (istring) - strncpy(s, ((STRINGDAT*) p->names)->data, MAXNAME-1); - else if ((long) *p->names <= csound->GetStrsmax(csound) && - csound->GetStrsets(csound,(long) *p->names)) { - strncpy(s, csound->GetStrsets(csound,(long) *p->names), MAXNAME-1); - } - string tempname(s); - stringstream sbuf; - sbuf << tempname; - - int height = (int) *p->iheight; - if (height <=0) height = 100; - - Fl_Group* w = new Fl_Group((int)*p->ix, (int)*p->iy, - (int) *p->inumsliders*10, height); - FUNC *ftp; - MYFLT *configtable, *outable; - - MYFLT *zkstart; - int zklast = csound->GetZakBounds(csound, &zkstart); - if (*p->ioutable < 1) { - if (LIKELY(zkstart != NULL && - zklast>(long)(*p->inumsliders + *p->ioutablestart_ndx))) - outable = zkstart + (long) *p->ioutablestart_ndx; - else { - return csound->InitError(csound, - "%s", Str("invalid ZAK space allocation")); - } - } - else { - if ((ftp = csound->FTnp2Find(csound, p->ioutable)) != NULL) - outable = ftp->ftable + (long) *p->ioutablestart_ndx; - else - return NOTOK; - } - if((ftp = csound->FTnp2Find(csound, p->iconfigtable)) != NULL) - configtable = ftp->ftable; - else - return NOTOK; - - p->elements = (long) *p->inumsliders; - for (int j =0; j< p->elements; j++) { - string stemp; - if (tempname == " ") { - char s[40]; - sprintf(s, "%d", j); - stemp = s; - } - else - getline(sbuf, stemp, '@'); - char *Name = new char[stemp.size()+2]; - strcpy(Name,stemp.c_str()); - widgetGlobals->allocatedStrings.push_back(Name); - - int x = (int) *p->ix+j*10, y = (int) *p->iy /*+ j*10*/; - Fl_Slider *o; - int slider_type= (int) configtable[j*4+3]; - int iexp = (int) configtable[j*4+2]; - - if (slider_type > 19) { - plastic = true; - slider_type -= 20; - } - if (UNLIKELY(slider_type > 10 && iexp == EXP_)) { - csound->Warning(csound, - "%s", Str("FLslidBnk2: FLslider exponential, " - "using non-labeled slider")); - slider_type -= 10; - } - if (slider_type <= 10) - o = new Fl_Slider(x, y, 10, height, Name); - else { - o = new Fl_Value_Slider_Input( csound, x, y, 10, height, Name); - slider_type -=10; - ((Fl_Value_Slider_Input*) o)->textboxsize(50); - ((Fl_Value_Slider_Input*) o)->textsize(13); - } - switch((int) slider_type) { //type - case 1: case 2: o->type(FL_VERT_FILL_SLIDER); break; - case 3: case 4: o->type(FL_VERT_SLIDER); break; - case 5: case 6: o->type(FL_VERT_NICE_SLIDER); o->box(FL_FLAT_BOX); break; - case 7: case 8: o->type(FL_VERT_NICE_SLIDER); o->box(FL_DOWN_BOX); break; - default: o->type(FL_VERT_NICE_SLIDER); o->box(FL_FLAT_BOX); break; - } - o->align(FL_ALIGN_BOTTOM); - if (plastic) o->box(FL_PLASTIC_DOWN_BOX); - widget_attributes(csound, o); - MYFLT min, max, range; - min = configtable[j*4]; - max = configtable[j*4+1]; - - p->slider_data[j].min=min; - p->slider_data[j].max=max; - p->slider_data[j].out=&outable[j]; - - switch (iexp) { - case -1: iexp = EXP_; break; - case 0: iexp = LIN_; break; - } - - MYFLT val = 0; - p->slider_data[j].exp = iexp; - - switch (iexp) { - case LIN_: //linear - o->range(min,max); - o->callback((Fl_Callback*)fl_callbackLinearSliderBank, - (void *) &(p->slider_data[j])); - val = outable[j]; - if (val > max) val = max; - else if (val < min) val = min; - break; - case EXP_ : //exponential - if (UNLIKELY(min == 0 || max == 0)) - return - csound->InitError(csound, - "%s", Str("FLsliderBank: zero is illegal " - "in exponential operations")); - range = max - min; - o->range(range,0); - #if defined(sun) - p->slider_data[j].base = ::pow((max / (double)min), 1.0/(double)range); - #else - p->slider_data[j].base = ::pow((max / min), 1.0/(double)range); - #endif - o->callback((Fl_Callback*)fl_callbackExponentialSliderBank, - (void *) &(p->slider_data[j])); - { - val = outable[j]; - MYFLT range = max-min; - #if defined(sun) - MYFLT base = ::pow(max / (double)min, 1.0/(double)range); - #else - MYFLT base = ::pow(max / min, 1.0/(double)range); - #endif - val = (log(val/min) / log(base)) ; - } - break; - default: - { - FUNC *ftp; - MYFLT fnum = abs(iexp); - if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) - p->slider_data[j].table = ftp->ftable; - else return NOTOK; - p->slider_data[j].tablen = ftp->flen; - o->range(.99999999,0); - if (iexp > 0) //interpolated - o->callback((Fl_Callback*)fl_callbackInterpTableSliderBank, - (void *) &(p->slider_data[j])); - else // non-interpolated - o->callback((Fl_Callback*)fl_callbackTableSliderBank, - (void *) &(p->slider_data[j])); - } - } - o->value(val); - p->slider_data[j].widget_addr= (void*) o; - - } - w->resizable(w); - if (*p->iwidth <=0 || *p->iheight <=0) {// default width and height - int a,b; - w->size( a= w->parent()->w(), b= w->parent()->h()-50); - w->position(0, 0); - } - else { - w->size( (int)*p->iwidth, (int)*p->iheight); - w->position((int)*p->ix, (int)*p->iy); - } - w->end(); - widgetGlobals->AddrSetValue.push_back(ADDR_SET_VALUE(LIN_, 0, 0, - (void *) w, (void *) p, - widgetGlobals->currentSnapGroup)); - //*p->ihandle = widgetGlobals->AddrSetValue.size()-1; - widgetGlobals->last_sldbnk = widgetGlobals->AddrSetValue.size()-1; //gab - - return OK; - } - - static int fl_vertical_slider_bank2(CSOUND *csound, FLSLIDERBANK2 *p){ - return fl_vertical_slider_bank2_(csound,p,0); - } - - static int fl_vertical_slider_bank2_S(CSOUND *csound, FLSLIDERBANK2 *p){ - return fl_vertical_slider_bank2_(csound,p,1); - } - - - - static int fl_slider_bank_getHandle(CSOUND *csound, FLSLDBNK_GETHANDLE *p) - //valid only if called immediately after FLslidBnk - { - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - *p->ihandle = widgetGlobals->last_sldbnk; - return OK; - } - - static int fl_slider_bank_setVal(CSOUND *csound, FLSLDBNK_SET *p) - { - FUNC* ftp; - MYFLT *table, *outable; - int numslid = (int)*p->numSlid; - int startInd = (int)*p->startInd; - int startSlid = (int)*p->startSlid; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - - if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) - table = ftp->ftable; - else { - return csound->InitError(csound, - "%s", Str("FLsldBnkSet: invalid table number")); - } - // *startInd, *startSlid, *numSlid - if (UNLIKELY( (int) ftp->flen < startInd + numslid)) { - return csound->InitError(csound, - "%s", Str("FLslidBnkSet: table too short!")); - } - FLSLIDERBANK *q = - (FLSLIDERBANK *)widgetGlobals->AddrSetValue[ (int) *p->ihandle].opcode; - - if (LIKELY((ftp = csound->FTnp2Find(csound, q->ioutable)) != NULL)) - outable = ftp->ftable; - else { - return csound->InitError(csound, - "%s", Str("FLsldBnkSet: invalid outable number")); - } - if (numslid == 0) numslid = (int)(q->elements - *p->startSlid); - if (UNLIKELY( q->elements > startSlid + numslid)) { - return csound->InitError(csound, "%s", - Str("FLslidBnkSet: too many sliders to reset!")); - } - for (int j = startSlid, k = startInd; j< numslid + startSlid; j++, k++) { - - MYFLT val = 0; - // MYFLT base = q->slider_data[j].base; - int iexp = q->slider_data[j].exp; - MYFLT min = q->slider_data[j].min; - MYFLT max = q->slider_data[j].max; - switch (iexp) { - case LIN_: //linear - val = table[k]; - if (val > max) val = max; - else if (val < min) val = min; - break; - case EXP_ : //exponential - { - MYFLT range = max - min; - MYFLT base2 = pow(max / min, 1/range); - val = (log(table[k]/min) / log(base2)) ; - } - break; - default: - return csound->InitError(csound, - "%s", Str("FLslidBnkSet: " - "function mapping not available")); - } - - FLlock(); - ((Fl_Slider*) (q->slider_data[j].widget_addr))->value(val); - FLunlock(); - outable[j] = table[k]; - } - return OK; - } - - static int fl_slider_bank2_setVal(CSOUND *csound, FLSLDBNK_SET *p) - { - FUNC* ftp; - MYFLT *table, *outable; - int numslid = (int)*p->numSlid; - int startInd = (int)*p->startInd; - int startSlid = (int)*p->startSlid; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - - if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) - table = ftp->ftable; - else { - return csound->InitError(csound, - "%s", Str("FLsldBnkSet: invalid table number")); - } - // *startInd, *startSlid, *numSlid - if (UNLIKELY((int) ftp->flen < startInd + numslid)) { - return csound->InitError(csound, - "%s", Str("FLslidBnkSet: table too short!")); - } - FLSLIDERBANK2 *q = - (FLSLIDERBANK2 *)widgetGlobals->AddrSetValue[ (int) *p->ihandle].opcode; - - if (LIKELY((ftp = csound->FTnp2Find(csound, q->ioutable)) != NULL)) - outable = ftp->ftable; - else { - return csound->InitError(csound, - "%s", Str("FLsldBnkSet: invalid outable number")); - } - - if (numslid == 0) numslid = (int)(q->elements - *p->startSlid); - if (UNLIKELY( q->elements > startSlid + numslid)) { - return csound->InitError(csound, "%s", - Str("FLslidBnkSet: too many sliders to reset!")); - } - - for (int j = startSlid, k = startInd; j< numslid + startSlid; j++, k++) { - - MYFLT val = 0; - // MYFLT base = q->slider_data[j].base; - int iexp = q->slider_data[j].exp; - MYFLT min = q->slider_data[j].min; - MYFLT max = q->slider_data[j].max; - switch (iexp) { - case LIN_: //linear - val = table[k]; - if (val > max) val = max; - else if (val < min) val = min; - break; - case EXP_ : //exponential - { - MYFLT range = max - min; - MYFLT base2 = pow(max / min, 1/range); - val = (log(table[k]/min) / log(base2)); - } - break; - default: // table - { - // val = table[k]; - if (UNLIKELY(val < 0 || val > 1)) { // input range must be 0 to 1 - csound->PerfError(csound, &p->h, - "%s", Str("FLslidBnk2Setk: value out of range: " - "function mapping requires a 0 to 1 " - "range for input")); - } - } - //{ - // initerror("FLslidBnkSet: function mapping not available"); - // return; - //} - } - - FLlock(); - ((Fl_Slider*) (q->slider_data[j].widget_addr))->value(val); - FLunlock(); - outable[j] = table[k]; - } - return OK; - } - static int fl_slider_bank2_setVal_k_set(CSOUND *csound, FLSLDBNK2_SETK *p) - { - FUNC* ftp; - - p->numslid = (int)*p->numSlid; - p->startind = (int)*p->startInd; - p->startslid = (int)*p->startSlid; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - - if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) - p->table = ftp->ftable; - else { - return csound->InitError(csound, - "%s", Str("FLsldBnkSetk: invalid table number")); - } - // *startInd, *startSlid, *numSlid - if (UNLIKELY( (int) ftp->flen < p->startind + p->numslid)) { - return csound->InitError(csound, - "%s", Str("FLslidBnkSetk: table too short!")); - } - p->q = (FLSLIDERBANK2 *) - widgetGlobals->AddrSetValue[ (int) *p->ihandle].opcode; - - if (LIKELY((ftp = csound->FTnp2Find(csound, p->q->ioutable)) != NULL)) - p->outable = ftp->ftable; - else { - return csound->InitError(csound, "%s", - Str("FLsldBnkSetk: invalid outable number")); - } - - if (p->numslid == 0) p->numslid = p->q->elements - p->startslid; - if (UNLIKELY( p->q->elements < p->startslid + p->numslid)) { - return csound->InitError(csound, "%s", - Str("FLslidBnkSetk: too many sliders to reset!")); - } - return OK; - } - - - - static int fl_slider_bank2_setVal_k(CSOUND *csound, FLSLDBNK2_SETK *p) - { - //WIDGET_GLOBALS *widgetGlobals = - // (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - - if(*p->kflag) { - FLSLIDERBANK2 *q = p->q; - MYFLT *table=p->table; - for (int j = p->startslid, k = p->startind; - j< p->numslid + p->startslid; - j++, k++) { - - MYFLT val = 0; - // MYFLT base= q->slider_data[j].base; - int iexp = q->slider_data[j].exp; - MYFLT min = q->slider_data[j].min; - MYFLT max = q->slider_data[j].max; - switch (iexp) { - case LIN_: //linear - val = table[k]; - if (val > max) val = max; - else if (val < min) val = min; - break; - case EXP_ : //exponential - { - MYFLT range = max - min; - MYFLT base2 = pow(max / min, 1/range); - val = (log(table[k]/min) / log(base2)); - } - break; - default: // table - { - val = table[k]; - if (UNLIKELY(val < 0 || val > 1)) { // input range must be 0 to 1 - csound->PerfError(csound, &p->h, - "%s", Str("FLslidBnk2Setk: value out of range:" - " function mapping requires a 0 to 1" - " range for input")); - } - } - } - if (val != p->oldValues[j]) { - FLlock(); - ((Fl_Slider*) (q->slider_data[j].widget_addr))->value(val); - ((Fl_Slider*) (q->slider_data[j].widget_addr))->do_callback(); - FLunlock(); - p->oldValues[j] = val; - } - } - } - return OK; - } - - static int fl_slider_bank_setVal_k_set(CSOUND *csound, FLSLDBNK_SETK *p) - { - FUNC* ftp; - WIDGET_GLOBALS *widgetGlobals = - (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - p->numslid = (int)*p->numSlid; - p->startind = (int)*p->startInd; - p->startslid = (int)*p->startSlid; - - if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) - p->table = ftp->ftable; - else { - return csound->InitError(csound, - "%s", Str("FLslidBnkSetk: invalid table number")); - } - // *startInd, *startSlid, *numSlid - if (UNLIKELY( (int) ftp->flen < p->startind + p->numslid)) { - return csound->InitError(csound, - "%s", Str("FLslidBnkSetk: table too short!")); - } - p->q = - (FLSLIDERBANK *) widgetGlobals->AddrSetValue[ (int) *p->ihandle].opcode; - - if (LIKELY((ftp = csound->FTnp2Find(csound, p->q->ioutable)) != NULL)) - p->outable = ftp->ftable; - else { - return csound->InitError(csound, "%s", - Str("FLslidBnkSetk: invalid outable number")); - } - - if (p->numslid == 0) p->numslid = p->q->elements - p->startslid; - if (UNLIKELY( p->q->elements < p->startslid + p->numslid)) { - return csound->InitError(csound, "%s", - Str("FLslidBnkSetk: too many sliders to reset!")); - } - return OK; - } - - - - static int fl_slider_bank_setVal_k(CSOUND *csound, FLSLDBNK_SETK *p) - { - if (*p->kflag) { - FLSLIDERBANK *q = p->q; - MYFLT *table=p->table; - for (int j = p->startslid, k = p->startind; - j< p->numslid + p->startslid; - j++, k++) { - - MYFLT val = 0; - // MYFLT base= q->slider_data[j].base; //Not used - int iexp = q->slider_data[j].exp; - MYFLT min = q->slider_data[j].min; - MYFLT max = q->slider_data[j].max; - switch (iexp) { - case LIN_: //linear - val = table[k]; - if (val > max) val = max; - else if (val < min) val = min; - break; - case EXP_ : //exponential - { - MYFLT range = max - min; - MYFLT base2 = pow(max / min, 1/range); - val = (log(table[k]/min) / log(base2)); - } - break; - default: // table - { - val = table[k]; - if (UNLIKELY(val < 0 || val > 1)) { // input range must be 0 to 1 - csound->PerfError(csound, &p->h, - "%s", Str("FLslidBnk2Setk: value out of range: " - "function mapping requires a 0 to 1 range " - "for input")); - } - } - } - if (val != p->oldValues[j]) { - FLlock(); - ((Fl_Slider*) (q->slider_data[j].widget_addr))->value(val); - ((Fl_Slider*) (q->slider_data[j].widget_addr))->do_callback(); - FLunlock(); - p->oldValues[j] = val; - } - } - } - return OK; - } - - static int FLxyin_set(CSOUND *csound, FLXYIN *p) - { - - *p->koutx = *p->ioutx; //initial values - *p->kouty = *p->iouty; - p->rangex = *p->ioutx_max - *p->ioutx_min; - p->rangey = *p->iouty_max - *p->iouty_min; - - switch((int) *p->iexpx) { - case 0: // LIN - p->expx = LIN_; break; - case -1: // EXP - p->expx = EXP_; - if (UNLIKELY(*p->ioutx_min == 0 || *p->ioutx_max==0)) - return csound->InitError(csound, "%s", - Str("FLxyin: none of X limits can be zero in" - " exponential mode!")); - p->basex = pow((double) (*p->ioutx_max / *p->ioutx_min), - (double) (1/p->rangex)); - - break; - default: // TABLE - p->expx = (int) *p->iexpx; - { - FUNC *ftp; - MYFLT fnum = abs(p->expx); - if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) { - p->tablex = ftp->ftable; - p->tablenx = ftp->flen; - } - else return NOTOK; - } - - } - - switch((int) *p->iexpy) { - case 0: // LIN - p->expy = LIN_; break; - case -1: // EXP - p->expy = EXP_; - if (UNLIKELY(*p->iouty_min == 0 || *p->iouty_max==0)) - return csound->InitError(csound, - "%s", Str("FLxyin: none of Y limits can " - "be zero in exponential mode!")); - p->basey = pow((double) (*p->iouty_max / *p->iouty_min), - (double) (1/p->rangey)); - break; - default: // TABLE - p->expy = (int) *p->iexpy; - { - FUNC *ftp; - MYFLT fnum = abs(p->expy); - if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) { - p->tabley = ftp->ftable; - p->tableny = ftp->flen; - } - else return NOTOK; - } - - } - return OK; - } - - static int FLxyin(CSOUND *csound, FLXYIN *p) - { - IGN(csound); - int windx_min = (int)*p->iwindx_min, windx_max = (int)*p->iwindx_max; - int windy_min = (int)*p->iwindy_min, windy_max = (int)*p->iwindy_max; - MYFLT outx_min = *p->ioutx_min, outy_min = *p->iouty_min; - - MYFLT x=Fl::event_x(); - MYFLT y=Fl::event_y(); - - *p->kinside = 1; - - if (x< windx_min) { x = windx_min; *p->kinside = 0; } - else if (x > windx_max) { x = windx_max; *p->kinside = 0; } - - if (y< windy_min) { y = windy_min; *p->kinside = 0; } - else if (y > windy_max) { y = windy_max; *p->kinside = 0; } - - MYFLT xx = x - windx_min; - xx /= windx_max - windx_min; - - MYFLT yy = windy_max - y; - yy /= windy_max - windy_min; - - switch (p->expx) { - case LIN_: - *p->koutx = outx_min + xx * p->rangex; - break; - case EXP_: - *p->koutx = outx_min * pow (p->basex, xx * p->rangex); - break; - default: // TABLE - if (p->expx > 0) { //interpolated - MYFLT ndx = xx * (p->tablenx-1); - int index = (int) ndx; - MYFLT v1 = p->tablex[index]; - *p->koutx = outx_min + ( v1 + (p->tablex[index+1] - v1) * - (ndx - index)) * p->rangex; - } - else // non-interpolated - *p->koutx = outx_min + p->tablex[(int) (xx*p->tablenx)] * p->rangex; - } - - switch (p->expy) { - case LIN_: - *p->kouty = outy_min + yy * p->rangey; - break; - case EXP_: - *p->kouty = outy_min * pow (p->basey, yy * p->rangey); - break; - default: // TABLE - if (p->expy > 0) { //interpolated - MYFLT ndx = yy * (p->tableny-1); - int index = (int) ndx; - MYFLT v1 = p->tabley[index]; - *p->kouty = outy_min + ( v1 + ( p->tabley[index+1] - v1) * - (ndx - index)) * p->rangey; - } - else // non-interpolated - *p->kouty = outy_min + p->tabley[(int) (yy*p->tableny)] * p->rangey; - } - return OK; - } - - // //FIXME: Should this be defined to 0dbfs? - // #define MAXAMPVU 32767 - // - // //TODO: Implement FLTK meter - // void VuMeter(CSOUND *csound); - // - // static int VuMeter_set(CSOUND *csound, FLTKMETER *p) { - // //isVumeterActive = 1; - // csoundSetVuMeterCallback(csound, VuMeter); - // //OPARMS *O = csound->oparms; - // int nchnls = csound->nchnls; - // Fl_Window *o; - // int iw; - // iw = (csound->oparms->sfread) ? 30 : 15; - // o = new Fl_Window(0,0, 410,nchnls * iw+35, "Meter"); - // Fl_Box *box = new Fl_Box(10,3,260,10,"Outputs"); - // box->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); - // //else o = new Fl_Panel(x,y,width,height, panelName); - // //o->box((Fl_Boxtype) borderType); - // o->resizable(o); - // o->callback(flpanel_cb); - // //o->set_modal(); - // widget_attributes(csound,o); - // - // PANELS panel(o, (widgetGlobals->stack_count>0) ? 1 : 0); - // widgetGlobals->fl_windows.push_back(panel); - // int j; - // - // for ( j = 0; j < nchnls; j++) { - // string stemp; - // char s[10]; - // stemp = itoa(j+1,s,10); - // char *Name = new char[stemp.size()+2]; - // strcpy(Name,stemp.c_str()); - // widgetGlobals->allocatedStrings.push_back(Name); - // - // Fl_Slider *w = new Fl_Slider(20, 18+15*j, 380, 10, Name); - // w->align(FL_ALIGN_LEFT); - // p->widg_address[j] = (unsigned long) w; - // w->type(FL_HOR_FILL_SLIDER); - // w->color(FL_BACKGROUND_COLOR,FL_GREEN); - // w->box(FL_PLASTIC_DOWN_BOX); - // w->range(0,MAXAMPVU); - // } - // - // if (csound->oparms->sfread) { - // box = new Fl_Box(10,18 + 15 * nchnls ,260,10,"Inputs"); - // box->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); - // for ( ; j < nchnls*2; j++) { - // string stemp; - // char s[10]; - // stemp = itoa(j+1- nchnls,s,10); - // char *Name = new char[stemp.size()+2]; - // strcpy(Name,stemp.c_str()); - // widgetGlobals->allocatedStrings.push_back(Name); - // Fl_Slider *w = new Fl_Slider(20, 30+15*j , 380, 10, Name); - // w->align(FL_ALIGN_LEFT); - // p->widg_address[j] = (unsigned long) w; - // w->type(FL_HOR_FILL_SLIDER); - // w->color(FL_BACKGROUND_COLOR,FL_YELLOW); - // w->box(FL_PLASTIC_DOWN_BOX); - // w->range(0,MAXAMPVU); - // } - // } - // o->end(); - // widgetGlobals->p_vumeter = p; - // p->dummycycles = csound->ekr / 16 ; - // p->dummycyc = 0; - // return OK; - // } - // - // //extern "C" MYFLT *spout,*spin; //GAB - // - // void VuMeter(CSOUND *csound){ - // FLTKMETER *p = widgetGlobals->p_vumeter; - // Fl_Slider *w; - // int nchnls = csound->nchnls; - // int n = (csound->oparms->sfread) ? nchnls * 2 : nchnls; - // MYFLT temp[MAXCHNLS]; - // int smps = csound->GetKsmps(csound); - // MYFLT max[MAXCHNLS]; - // MYFLT *spo = csound->spout; - // MYFLT *spi = csound->spin; - // - // static int overfl[MAXCHNLS]; - // int i; - // for (i=0;i max[i] ) - // max[i]= temp[i]; - // } - // if (csound->oparms->sfread) { - // for ( ; i max[i] ) - // max[i]= temp[i]; - // } - // } - // //if ((temp= (MYFLT) fabs(*a++)) > max) max = temp; - // } while (--smps); - // - // for (i=0; i p->max[i]) - // p->max[i] = (overfl[i] = max[i]>MAXAMPVU) ? MAXAMPVU : max[i]; - // } - // p->dummycyc++; - // if (!(p->dummycyc % p->dummycycles)) { - // for (int j=0; jwidg_address[j]; - // - // FLlock(); - // if (overfl[j]) { - // w->selection_color(FL_RED); - // overfl[j] = 0; - // } - // else { - // if (j < nchnls) w->selection_color(FL_GREEN); - // else w->selection_color(FL_YELLOW); - // } - // w->value( p->max[j]); - // w->do_callback(w); - // FLunlock(); - // } - // #ifdef WIN32 - // // PostMessage(callback_target,0,0,0); - // #endif - // for (i=0; imax[i] = 0; - // } - // } - // - -} // extern "C" - -#define S(x) sizeof(x) - -const OENTRY widgetOpcodes_[] = { - { (char*)"FLslider", S(FLSLIDER), 0, 1, (char*)"ki", (char*)"Siijjjjjjj", - (SUBR) fl_slider, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnk", S(FLSLIDERBANK), 0, 1, (char*)"", (char*)"Siooooooooo", - (SUBR) fl_slider_bank_S, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnk.i", S(FLSLIDERBANK), 0, 1, (char*)"", (char*)"iiooooooooo", - (SUBR) fl_slider_bank, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLknob", S(FLKNOB), 0, 1, (char*)"ki", (char*)"Siijjjjjjo", - (SUBR) fl_knob, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLroller", S(FLROLLER), 0, 1, (char*)"ki", (char*)"Siijjjjjjjj", - (SUBR) fl_roller, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLtext", S(FLTEXT), 0, 1, (char*)"ki", (char*)"Siijjjjjj", - (SUBR) fl_text, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLjoy", S(FLJOYSTICK), 0, 1, (char*)"kkii", (char*)"Siiiijjjjjjjj", - (SUBR) fl_joystick, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLcount", S(FLCOUNTER), 0, 1, (char*)"ki", (char*)"Siiiiiiiiiz", - (SUBR) fl_counter, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLbutton", S(FLBUTTON), 0, 1, (char*)"ki", (char*)"Siiiiiiiz", - (SUBR) fl_button, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLbutBank", S(FLBUTTONBANK), 0, 1, (char*)"ki", (char*)"iiiiiiiz", - (SUBR) fl_button_bank, (SUBR) NULL, (SUBR) NULL }, - // { (char*)"FLkeyb", S(FLKEYB), 0, 1, (char*)"k", (char*)"z", - // (SUBR) FLkeyb, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLcolor", S(FLWIDGCOL), 0, 1, (char*)"", (char*)"jjjjjj", - (SUBR) fl_widget_color, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLcolor2", S(FLWIDGCOL2), 0, 1, (char*)"", (char*)"jjj", - (SUBR) fl_widget_color2, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLlabel", S(FLWIDGLABEL), 0, 1, (char*)"", (char*)"ojojjj", - (SUBR) fl_widget_label, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetVal_i", S(FL_SET_WIDGET_VALUE_I), 0, 1, (char*)"", (char*)"ii", - (SUBR) fl_setWidgetValuei, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetVali", S(FL_SET_WIDGET_VALUE_I), 0, 1, (char*)"", (char*)"ii", - (SUBR) fl_setWidgetValuei, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetVal", S(FL_SET_WIDGET_VALUE),0, 3, (char*)"", (char*)"kki", - (SUBR) fl_setWidgetValue_set, (SUBR) fl_setWidgetValue, (SUBR) NULL }, - { (char*)"FLsetColor", S(FL_SET_COLOR), 0, 1, (char*)"", (char*)"iiii", - (SUBR) fl_setColor1, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetColor2", S(FL_SET_COLOR), 0, 1, (char*)"", (char*)"iiii", - (SUBR) fl_setColor2, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetTextSize", S(FL_SET_TEXTSIZE), 0, 1, (char*)"", (char*)"ii", - (SUBR) fl_setTextSize, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetTextColor", S(FL_SET_COLOR), 0, 1, (char*)"", (char*)"iiii", - (SUBR) fl_setTextColor, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetFont", S(FL_SET_FONT), 0, 1, (char*)"", (char*)"ii", - (SUBR) fl_setFont, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetTextType", S(FL_SET_FONT), 0, 1, (char*)"", (char*)"ii", - (SUBR) fl_setTextType, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetText", S(FL_SET_TEXT), 0, 1, (char*)"", (char*)"Si", - (SUBR) fl_setText, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetText", S(FL_SET_TEXTi), 0, 1, (char*)"", (char*)"ii", - (SUBR) fl_setTexti, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetSize", S(FL_SET_SIZE), 0, 1, (char*)"", (char*)"iii", - (SUBR) fl_setSize, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetPosition", S(FL_SET_POSITION), 0, 1, (char*)"", (char*)"iii", - (SUBR) fl_setPosition, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLhide", S(FL_WIDHIDE), 0, 1, (char*)"", (char*)"i", - (SUBR) fl_hide, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLshow", S(FL_WIDSHOW), 0, 1, (char*)"", (char*)"i", - (SUBR) fl_show, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetBox", S(FL_SETBOX), 0, 1, (char*)"", (char*)"ii", - (SUBR) fl_setBox, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetAlign", S(FL_TALIGN), 0, 1, (char*)"", (char*)"ii", - (SUBR) fl_align, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLbox", S(FL_BOX), 0, 1, (char*)"i", (char*)"Siiiiiii", - (SUBR) fl_box_s, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLbox", S(FL_BOX), 0, 1, (char*)"i", (char*)"iiiiiiii", - (SUBR) fl_box_i, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLvalue", S(FLVALUE), 0, 1, (char*)"i", (char*)"Sjjjj", - (SUBR) fl_value, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLpanel", S(FLPANEL), 0, 1, (char*)"", (char*)"Sjjjoooo", - (SUBR) StartPanel, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLpanelEnd", S(FLPANELEND), 0, 1, (char*)"", (char*)"", - (SUBR) EndPanel, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLpanel_end", S(FLPANELEND), 0, 1, (char*)"", (char*)"", - (SUBR) EndPanel, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLscroll", S(FLSCROLL), 0, 1, (char*)"", (char*)"iiii", - (SUBR) StartScroll, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLscrollEnd", S(FLSCROLLEND), 0, 1, (char*)"", (char*)"", - (SUBR) EndScroll, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLscroll_end",S(FLSCROLLEND), 0, 1, (char*)"", (char*)"", - (SUBR) EndScroll, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLpack", S(FLPACK), 0, 1, (char*)"", (char*)"iiiiooo", - (SUBR) StartPack, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLpackEnd", S(FLPACKEND), 0, 1, (char*)"", (char*)"", - (SUBR) EndPack, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLpack_end", S(FLPACKEND), 0, 1, (char*)"", (char*)"", - (SUBR) EndPack, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLtabs", S(FLTABS), 0, 1, (char*)"", (char*)"iiii", - (SUBR) StartTabs, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLtabsEnd", S(FLTABSEND), 0, 1, (char*)"", (char*)"", - (SUBR) EndTabs, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLtabs_end", S(FLTABSEND), 0, 1, (char*)"", (char*)"", - (SUBR) EndTabs, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLgroup", S(FLGROUP), 0, 1, (char*)"", (char*)"Siiiij", - (SUBR) StartGroup, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLgroupEnd", S(FLGROUPEND), 0, 1, (char*)"", (char*)"", - (SUBR) EndGroup, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLgroup_end", S(FLGROUPEND), 0, 1, (char*)"", (char*)"", - (SUBR) EndGroup, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetsnap", S(FLSETSNAP), 0, 1, (char*)"ii", (char*)"ioo", - (SUBR) set_snap, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetSnapGroup", S(FLSETSNAPGROUP), 0, 1, (char*)"", (char*)"i", - (SUBR)fl_setSnapGroup, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLgetsnap", S(FLGETSNAP), 0, 1, (char*)"i", (char*)"io", - (SUBR) get_snap, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsavesnap", S(FLSAVESNAPS), 0, 1, (char*)"", (char*)"So", - (SUBR) save_snap, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLloadsnap", S(FLLOADSNAPS), 0, 1, (char*)"", (char*)"So", - (SUBR) load_snap, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLrun", S(FLRUN), 0, 1, (char*)"", (char*)"", - (SUBR) FL_run, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLupdate", S(FLRUN), 0, 1, (char*)"", (char*)"", - (SUBR) fl_update, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLprintk", S(FLPRINTK), 0, 3, (char*)"", (char*)"iki", - (SUBR) FLprintkset, (SUBR) FLprintk, (SUBR) NULL }, - { (char*)"FLprintk2", S(FLPRINTK2), 0, 3, (char*)"", (char*)"ki", - (SUBR) FLprintk2set, (SUBR) FLprintk2, (SUBR) NULL }, - { (char*)"FLcloseButton", S(FLCLOSEBUTTON), 0, 1, (char*)"i", (char*)"Siiii", - (SUBR) fl_close_button, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLexecButton", S(FLEXECBUTTON), 0, 1, (char*)"i", (char*)"Siiii", - (SUBR) fl_exec_button, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLkeyIn", S(FLKEYIN), 0, 3, (char*)"k", (char*)"o", - (SUBR)fl_keyin_set, (SUBR)fl_keyin, (SUBR) NULL }, - { (char*)"FLxyin", S(FLXYIN), 0, 3, (char*)"kkk",(char*)"iiiiiiiioooo", - (SUBR)FLxyin_set, (SUBR)FLxyin, (SUBR) NULL }, - { (char*)"FLmouse", S(FLMOUSE), 0, 3, (char*)"kkkkk",(char*)"o", - (SUBR)fl_mouse_set, (SUBR)fl_mouse, (SUBR) NULL }, - { (char*)"FLvslidBnk", S(FLSLIDERBANK), 0, 1, (char*)"", (char*)"Siooooooooo", - (SUBR)fl_vertical_slider_bank_S, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLvslidBnk.i", S(FLSLIDERBANK), 0, 1, (char*)"", (char*)"iiooooooooo", - (SUBR)fl_vertical_slider_bank, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnk2", S(FLSLIDERBANK2),0, 1, (char*)"", (char*)"Siiiooooo", - (SUBR)fl_slider_bank2_S , (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnk2.i", S(FLSLIDERBANK2),0, 1, (char*)"", (char*)"iiiiooooo", - (SUBR)fl_slider_bank2 , (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLvslidBnk2", S(FLSLIDERBANK2),0, 1, (char*)"", (char*)"Siiiooooo", - (SUBR)fl_vertical_slider_bank2_S, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLvslidBnk2.i", S(FLSLIDERBANK2),0, 1, (char*)"", (char*)"iiiiooooo", - (SUBR)fl_vertical_slider_bank2, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnkGetHandle",S(FLSLDBNK_GETHANDLE),0, 1, (char*)"i", (char*)"", - (SUBR)fl_slider_bank_getHandle, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnkSet",S(FLSLDBNK_SET), 0, 1, (char*)"", (char*)"iiooo", - (SUBR)fl_slider_bank_setVal, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnkSetk", S(FLSLDBNK2_SETK), 0, 3, (char*)"", (char*)"kiiooo", - (SUBR)fl_slider_bank_setVal_k_set,(SUBR)fl_slider_bank_setVal_k,(SUBR) NULL }, - { (char*)"FLslidBnk2Set", S(FLSLDBNK_SET), 0, 1, (char*)"", (char*)"iiooo", - (SUBR)fl_slider_bank2_setVal, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnk2Setk", S(FLSLDBNK2_SETK), 0, 3, (char*)"", (char*)"kiiooo", - (SUBR)fl_slider_bank2_setVal_k_set, (SUBR)fl_slider_bank2_setVal_k, - (SUBR) NULL }, - { (char*)"FLhvsBox", S(FL_HVSBOX), 0, 1, (char*)"i", (char*)"iiiiiio", - (SUBR)fl_hvsbox, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLhvsBoxSetValue",S(FL_SET_HVS_VALUE), 0, 3, (char*)"", (char*)"kki", - (SUBR)fl_setHvsValue_set, (SUBR)fl_setHvsValue, (SUBR) NULL }, - // { (char*)"FLmeter", S(FLTKMETER), 0, 1, (char*)"", (char*)"", - // (SUBR)VuMeter_set, (SUBR) NULL, (SUBR) NULL }, - { NULL, 0, 0, 0, NULL, NULL, - (SUBR) NULL, (SUBR) NULL, (SUBR) NULL } -}; diff --git a/6.x/src/widgets/widgets.h b/6.x/src/widgets/widgets.h deleted file mode 100644 index 62320aaf..00000000 --- a/6.x/src/widgets/widgets.h +++ /dev/null @@ -1,645 +0,0 @@ -/* - widgets.h: - - Copyright (C) 2002 Gabriel Maldonado - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#ifndef CSOUND_WIDGETS_H -#define CSOUND_WIDGETS_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - OPDS h; - MYFLT *kout, *ihandle; - STRINGDAT *name; - MYFLT *imin, *imax, *iexp; - MYFLT *itype, *idisp, *iwidth, *iheight, *ix, *iy; - MYFLT min, base, *table; - long tablen; -} FLSLIDER; - -#define MAXSLIDERBANK 128 - -typedef struct { - void *widget_addr; //gab - MYFLT min, max, *out; - MYFLT base, *table; - long tablen; - int exp; -} SLDBK_ELEMENT; - -// --------------------------------------------------------------------- - -typedef struct { - OPDS h; - MYFLT *names; - MYFLT *inumsliders, *ioutable, *iwidth, *iheight; - MYFLT *ix, *iy, *itypetable, *iexptable, *ioutablestart_ndx; - MYFLT *iminmaxtable; - SLDBK_ELEMENT slider_data[MAXSLIDERBANK]; - long elements; -} FLSLIDERBANK; - -typedef struct { - OPDS h; - MYFLT *names; - MYFLT *inumsliders, *ioutable, *iconfigtable, *iwidth, - *iheight, *ix, *iy, *ioutablestart_ndx; - SLDBK_ELEMENT slider_data[MAXSLIDERBANK]; - long elements; -} FLSLIDERBANK2; //gab - -// typedef struct { -// OPDS h; -// MYFLT *kout, *args[PMAX+1]; -// } FLKEYB; - -typedef struct { - OPDS h; - MYFLT *kvalue, *ihandle; -} FLBUTTONCALL; - -typedef struct { - OPDS h; - MYFLT *koutx, *kouty, *ihandle1, *ihandle2; - STRINGDAT *name; - MYFLT *iminx, *imaxx, *iminy, *imaxy; - MYFLT *iexpx, *iexpy, *idispx, *idispy, *iwidth, *iheight, *ix, *iy; - MYFLT basex, basey, *tablex, *tabley; - long tablenx, tableny; -} FLJOYSTICK; - -typedef struct { - OPDS h; - MYFLT *kout, *ihandle; - STRINGDAT *name; - MYFLT *imin, *imax, *istep, *iexp; - MYFLT *itype, *idisp, *iwidth, *iheight, *ix, *iy; - MYFLT min, base, *table; - long tablen; -} FLROLLER; - -typedef struct { - OPDS h; - MYFLT *kout, *ihandle; - STRINGDAT *name; - MYFLT *imin, *imax, *iexp, *itype; - MYFLT *idisp, *iwidth, *ix, *iy, *icursorsize; - MYFLT min, base, *table; - long tablen; -} FLKNOB; - -typedef struct { - OPDS h; - MYFLT *kout, *ihandle; - STRINGDAT *name; - MYFLT *imin, *imax, *istep, *itype; - MYFLT *iwidth, *iheight, *ix, *iy; -} FLTEXT; - -// --------------------------------------------------------------------- - -typedef struct { - OPDS h; - MYFLT *red1, *green1, *blue1, *red2, *green2, *blue2; -} FLWIDGCOL; - -typedef struct { - OPDS h; - MYFLT *red, *green, *blue; -} FLWIDGCOL2; - -typedef struct { - OPDS h; - MYFLT *size, *font, *align, *red, *green, *blue; -} FLWIDGLABEL; - -// --------------------------------------------------------------------- - -typedef struct { - OPDS h; - MYFLT *ivalue, *ihandle; -} FL_SET_WIDGET_VALUE_I; - -typedef struct { - OPDS h; - MYFLT *ktrig, *kvalue, *ihandle; - int handle; - int widgetType; - MYFLT log_base; -} FL_SET_WIDGET_VALUE; - -typedef struct { - OPDS h; - MYFLT *red, *green, *blue, *ihandle; -} FL_SET_COLOR; - -typedef struct { - OPDS h; - MYFLT *ivalue, *ihandle; -} FL_SET_TEXTSIZE; - -typedef struct { - OPDS h; - MYFLT *itype, *ihandle; -} FL_SET_FONT; - -typedef struct { - OPDS h; - STRINGDAT *itext; - MYFLT *ihandle; -} FL_SET_TEXT; - -typedef struct { - OPDS h; - MYFLT *ndx; - MYFLT *ihandle; -} FL_SET_TEXTi; - -typedef struct { - OPDS h; - MYFLT *itype, *ihandle; -} FL_TALIGN; - -typedef struct { - OPDS h; - MYFLT *iwidth, *iheight, *ihandle; -} FL_SET_SIZE; - -typedef struct { - OPDS h; - MYFLT *ix, *iy, *ihandle; -} FL_SET_POSITION; - -typedef struct { - OPDS h; - MYFLT *ihandle; -} FL_WIDHIDE; - -typedef struct { - OPDS h; - MYFLT *ihandle; -} FL_WIDSHOW; - -typedef struct { - OPDS h; - MYFLT *itype, *ihandle; -} FL_SETBOX; - -typedef struct { - OPDS h; - MYFLT *ihandle; - STRINGDAT *itext; - MYFLT *itype, *ifont, *isize; - MYFLT *iwidth, *iheight, *ix, *iy; -} FL_BOX; - -// --------------------------------------------------------------------- - -typedef struct { - OPDS h; - MYFLT *ihandle; - STRINGDAT *name; - MYFLT *iwidth, *iheight, *ix, *iy; -} FLVALUE; - -typedef struct { - OPDS h; -} FLRUN; - -typedef struct { - OPDS h; - STRINGDAT *name; - MYFLT *iwidth, *iheight, *ix, *iy, *border, *ikbdsense, *iclose; -} FLPANEL; - -typedef struct { - OPDS h; - MYFLT *inum_snap, *inum_val, *index, *ifn, *group; -} FLSETSNAP; - -typedef struct { - OPDS h; - MYFLT *inum_el, *index, *group; -} FLGETSNAP; - -typedef struct { - OPDS h; - STRINGDAT *filename; - MYFLT *group; -} FLSAVESNAPS; - -typedef struct { - OPDS h; - STRINGDAT *filename; - MYFLT *group; -} FLLOADSNAPS; - -typedef struct { - OPDS h; -} FLPANELEND; - -typedef struct { - OPDS h; - MYFLT *iwidth, *iheight, *ix, *iy; -} FLSCROLL; - -typedef struct { - OPDS h; -} FLSCROLLEND; - -typedef struct { - OPDS h; - MYFLT *iwidth, *iheight, *ix, *iy; -} FLTABS; - -typedef struct { - OPDS h; -} FLTABSEND; - -typedef struct { - OPDS h; - STRINGDAT *name; - MYFLT *iwidth, *iheight, *ix, *iy, *border; -} FLGROUP; - -typedef struct { - OPDS h; -} FLGROUPEND; - -typedef struct { - OPDS h; - MYFLT *iwidth, *iheight, *ix, *iy, *itype, *ispace, *iborder; -} FLPACK; - -typedef struct { - OPDS h; -} FLPACKEND; - -typedef struct { - OPDS h; - MYFLT *kout, *ihandle; - STRINGDAT *name; - MYFLT *ion, *ioff, *itype; - MYFLT *iwidth, *iheight, *ix, *iy, *args[PMAX]; -} FLBUTTON; - -typedef struct { - OPDS h; - MYFLT *kout, *ihandle; /* outs */ - MYFLT *itype, *inumx, *inumy, *iwidth, *iheight, *ix, *iy, *args[PMAX]; -} FLBUTTONBANK; - -typedef struct { - OPDS h; - MYFLT *kout, *ihandle; - STRINGDAT *name; - MYFLT *imin, *imax, *istep1, *istep2, *itype; - MYFLT *iwidth, *iheight, *ix, *iy, *args[PMAX]; -} FLCOUNTER; - -typedef struct { - OPDS h; - MYFLT *ptime, *val, *idisp; - MYFLT initime, ctime; - long cysofar; -} FLPRINTK; - -typedef struct { - OPDS h; - MYFLT *val, *idisp; - MYFLT oldvalue; - /* int pspace; */ -} FLPRINTK2; - -typedef struct { - OPDS h; - MYFLT *ihandle; - STRINGDAT *name; - MYFLT *iwidth, *iheight, *ix, *iy; -} FLCLOSEBUTTON; - -typedef struct { - OPDS h; - MYFLT *ihandle; - STRINGDAT *command; - MYFLT *iwidth, *iheight, *ix, *iy; - char *commandString; - CSOUND *csound; -} FLEXECBUTTON; - -#ifdef __cplusplus -} -#endif - -#if defined(CSOUND_WIDGETS_CPP) - -/* ---- IV - Aug 23 2002 ---- included file: Fl_Ball.H */ - -class Fl_Ball : public Fl_Valuator { -private: - CSOUND *csound; - int ix, iy, drag; - int spinning; - - int ballstacks, ballslices; - float ballsize; - - float curquat[4]; - float lastquat[4]; - float mat[4][4]; - - char soft_; - uchar mouseobj; - - static PUBLIC void repeat_callback(void *); - PUBLIC void increment_cb(); - PUBLIC void vertex_by_matrix(float &x, float &y, float &z); - - PUBLIC void transform_ball_vertex(float &x, float &y, float &z); - PUBLIC void rotate(float &x, float &y, float &z, - float rotx=0.0f, float roty=0.0f, float rotz=0.0f); - PUBLIC void draw_solid_ball(float radius, int slices, int stacks); - PUBLIC void draw_wire_ball(float radius, int slices, int stacks); -public: - PUBLIC void draw(); - PUBLIC void handle_drag(double v=0.0); - PUBLIC void handle_release(); - PUBLIC int handle(int); - PUBLIC Fl_Ball(CSOUND *cs, int x, int y, int w, int h, const char *l = 0); - - void soft(char x) {soft_ = x;} - char soft() const {return soft_;} - - float ballscale() const {return ballsize;} - void ballscale(float s) { ballsize=s;} - - void rotateball(float rotx=0.0f, float roty=0.0f, float rotz=0.0f); - void getrot(float &rotx, float &roty, float &rotz); - - void stacks(int s) { ballstacks=s; } - int stacks() const { return ballstacks; } - - void slices(int s) { ballslices=s; } - int slices() const { return ballslices; } - - ~Fl_Ball(); -}; - -/* ---- IV - Aug 23 2002 ---- included file: Fl_Knob.H */ - -/* generated by Fast Light User Interface Designer (fluid) version 2.00 */ - -class Fl_Knob : public Fl_Valuator { - public: - enum Fl_Knobtype { - DOTLIN=0, - DOTLOG_1, - DOTLOG_2, - DOTLOG_3, - LINELIN, - LINELOG_1, - LINELOG_2, - LINELOG_3 - }; - private: - CSOUND *csound; - int _type; - float _percent; - int _scaleticks; - short a1, a2; - public: - Fl_Knob(CSOUND *cs, int xx, int yy, int ww, int hh, const char *l=0); - ~Fl_Knob(); - private: - void draw(); - int handle(int event); - public: - void type(int ty); - private: - void shadow(const int offs, const uchar r, uchar g, uchar b); - void draw_scale(const int ox, const int oy, const int side); - void draw_cursor(const int ox, const int oy, const int side); - public: - void cursor(const int pc); - void scaleticks(const int tck); -}; - -/* ---- IV - Aug 23 2002 ---- included file: Fl_Spin.H */ - -class Fl_Spin : public Fl_Valuator { - private: - CSOUND * csound; - int ix, iy, drag, indrag; - int delta, deltadir; - char soft_; - uchar mouseobj; - static PUBLIC void repeat_callback(void *); - PUBLIC void increment_cb(); - - public: - PUBLIC void draw(); - PUBLIC int handle(int); - PUBLIC Fl_Spin(CSOUND *cs, int x, int y, int w, int h, const char *l = 0); - - void soft(char x) {soft_ = x;} - char soft() const {return soft_;} - - ~Fl_Spin(); -}; - -/* ---- IV - Aug 23 2002 ---- included file: Fl_Value_Input_Spin.H */ - -class Fl_Value_Input_Spin : public Fl_Valuator { - private: - CSOUND * csound; - int ix, iy, drag; - int delta, deltadir; - char soft_; - uchar mouseobj; - int butsize; - static PUBLIC void input_cb(Fl_Widget*, void*); - // cause damage() due to value() changing - virtual PUBLIC void value_damage(); - static PUBLIC void repeat_callback(void *); - PUBLIC void increment_cb(); - - public: - Fl_Input input; - PUBLIC void draw(); - PUBLIC int handle(int); - PUBLIC void resize(int, int, int, int); - PUBLIC Fl_Value_Input_Spin(CSOUND *csound, int x, int y, int w, int h, - const char *l = 0); - - void soft(char x) {soft_ = x;} - char soft() const {return soft_;} - - Fl_Font textfont() const {return input.textfont();} - void textfont(uchar s) { input.textfont(s);} - uchar textsize() const {return input.textsize();} - void textsize(uchar s) {input.textsize(s);} - Fl_Color textcolor() const {return input.textcolor();} - void textcolor(uchar n) {input.textcolor(n);} - Fl_Color cursor_color() const {return input.cursor_color();} - void cursor_color(uchar n) {input.cursor_color(n);} - int buttonssize() const {return butsize;} - void buttonssize(int s) { butsize=s;} - ~Fl_Value_Input_Spin(); -}; - -/* ---- IV - Aug 23 2002 ---- included file: Fl_Value_Slider_Input.H */ - -class Fl_Value_Slider_Input : public Fl_Value_Slider { - private: - CSOUND *csound; - char soft_; - int txtboxsize; - - static PUBLIC void input_cb(Fl_Widget*, void*); - // cause damage() due to value() changing - virtual PUBLIC void value_damage(); - - public: - Fl_Input input; - PUBLIC void draw(); - PUBLIC int handle(int); - PUBLIC void resize(int, int, int, int); - PUBLIC Fl_Value_Slider_Input(CSOUND * cs, int x, int y, int w, int h, - const char *l = 0); - - void soft(char x) {soft_ = x;} - char soft() const {return soft_;} - - Fl_Font textfont() const {return input.textfont();} - void textfont(uchar s) { input.textfont(s);} - uchar textsize() const {return input.textsize();} - void textsize(uchar s) {input.textsize(s);} - Fl_Color textcolor() const {return input.textcolor();} - void textcolor(uchar n) {input.textcolor(n);} - Fl_Color cursor_color() const {return input.cursor_color();} - void cursor_color(uchar n) {input.cursor_color(n);} - void textboxsize(int s) { txtboxsize=s;} - int textboxsize() const {return txtboxsize;} -}; - - -// New widgets for Csound5.06 by Gabriel Maldonado -// Ported by Andres Cabrera. This section below comes -// from the file newwidgets.h - -typedef struct { - OPDS h; - MYFLT *ihandle; -} FLSLDBNK_GETHANDLE; //gab - -typedef struct { - OPDS h; - MYFLT *ihandle, *ifn, *startInd, *startSlid, *numSlid; - //int oldx, oly; -} FLSLDBNK_SET; //gab - -typedef struct { - OPDS h; - MYFLT *kflag, *ihandle, *ifn, *startInd, *startSlid, *numSlid; - MYFLT oldValues[MAXSLIDERBANK]; - int numslid, startind, startslid; - FLSLIDERBANK2 *q; - MYFLT *table, *outable; - //int oldx, oly; -} FLSLDBNK2_SETK; - -typedef struct { - OPDS h; - MYFLT *kflag, *ihandle, *ifn, *startInd, *startSlid, *numSlid; - MYFLT oldValues[MAXSLIDERBANK]; - int numslid, startind, startslid; - FLSLIDERBANK *q; - MYFLT *table, *outable; - //int oldx, oly; -} FLSLDBNK_SETK; - -typedef struct { - OPDS h; - MYFLT *koutx, *kouty, *kinside; //outs - MYFLT *ioutx_min, *ioutx_max, *iouty_min, *iouty_max, - *iwindx_min, *iwindx_max, *iwindy_min, *iwindy_max, - *iexpx, *iexpy, *ioutx, *iouty; //ins - MYFLT oldx, oldy, *tablex, *tabley; - int expx, expy; - long tablenx, tableny; - double rangex, rangey, basex, basey; - //int pspace; -} FLXYIN; //gab - -typedef struct { - OPDS h; -// MYFLT *ktrig, *kvalue, *ihandle; - MYFLT *chan, *cc, *ihandle; - int ccVal, oldCCval; - MYFLT log_base, min, max, range; - void *WidgAddress, *opcode, *addrSetVal; - int exp, widg_type; -} FL_MIDI_WIDGET_VALUE; - - -typedef struct { - OPDS h; - MYFLT *kascii,*ifn;//, *ifnMap; - MYFLT *table;//, *tableMap; - int flag; -} FLKEYIN; - -typedef struct { - OPDS h; - MYFLT *group; -} FLSETSNAPGROUP; - -typedef struct { - OPDS h; - MYFLT *x,*y, *b1, *b2, *b3, *flagRaw; - MYFLT height,width; -} FLMOUSE; - -typedef struct { - OPDS h; - MYFLT *ihandle, *numlinesX, *numlinesY, *iwidth, *iheight, *ix, *iy,*image; - int width, height; -} FL_HVSBOX; - -typedef struct { - OPDS h; - MYFLT *kx, *ky, *ihandle; - void *WidgAddress, *opcode; - MYFLT old_x, old_y; -} FL_SET_HVS_VALUE; - -typedef struct { - OPDS h; - MYFLT max[MAXCHNLS]; - unsigned long widg_address[MAXCHNLS]; - int dummycycles, dummycyc; -} FLTKMETER; - -#endif /* CSOUND_WIDGETS_CPP */ -#endif /* CSOUND_WIDGETS_H */ diff --git a/6.x/src/widgets/widglobals.h b/6.x/src/widgets/widglobals.h deleted file mode 100644 index 65af7e25..00000000 --- a/6.x/src/widgets/widglobals.h +++ /dev/null @@ -1,272 +0,0 @@ -/* - wdglobals.h: - - Copyright (C) 2007 Andres Cabrera, Michael Gogins - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include -#include -#include - -#if defined(WIN32) -# include -#endif /* defined(WIN32) */ - -#if defined(LINUX) -# include -# include -# include -#endif /* defined(LINUX) */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -using namespace std; - -#include "csdl.h" -#include "winFLTK.h" - -#ifdef CS_IMAGE -# include "stdpch.h" -# include "anydec.h" -# include "anybmp.h" -# include "imagestruct.h" -#endif - -#define CSOUND_WIDGETS_CPP 1 -#include "widgets.h" - -#define LIN_ (0) -#define EXP_ (-1) -#undef min -#undef max - -typedef struct rtEvt_s { - struct rtEvt_s *nxt; - EVTBLK evt; -} rtEvt_t; - -#ifndef NO_FLTK_THREADS -typedef struct widgetsGlobals_s { - rtEvt_t *eventQueue; - void *mutex_; - int exit_now; /* set by GUI when all windows are closed */ - int end_of_perf; /* set by main thread at end of performance */ - void *threadHandle; - int fltkFlags; -} widgetsGlobals_t; -#endif - -struct ADDR { - void *opcode; - void *WidgAddress; -}; - -struct ADDR_STACK { /*: ADDR*/ - OPDS *h; - void *WidgAddress; - int count; - ADDR_STACK(OPDS *new_h,void *new_address, int new_count) - : h(new_h),WidgAddress(new_address), count(new_count) {} - ADDR_STACK() - { - h=NULL; - WidgAddress = NULL; - count=0; - } -}; - -struct VALUATOR_FIELD { - MYFLT value, value2; - MYFLT min,max, min2,max2; - int exp, exp2; - string widg_name; - string opcode_name; - SLDBK_ELEMENT *sldbnk; -private: - vector sldbnkValues; -public: - VALUATOR_FIELD() - { - value = 0; - value2 =0; - widg_name= ""; - opcode_name =""; - min = 0; - max =1; - min2=0; - max2=1; - exp=LIN_; - exp2=LIN_; - sldbnk=0; - } - void set_sldbnk(int ndx, MYFLT val) - { - if (ndx >= (int)sldbnkValues.size()) { - sldbnkValues.resize(ndx+1); - } - sldbnkValues[ndx]= val; - } - MYFLT get_sldbnk(int ndx) - { - return sldbnkValues[ndx]; - } -// ~VALUATOR_FIELD() { if (sldbnk != 0) delete sldbnk; -// if (sldbnkValues !=0) delete sldbnkValues; } -}; - - -enum FL_ENUM {FL_WIDG=0, FL_JOY, JOY_X=128, JOY_Y }; //gab - -struct ADDR_SET_VALUE { /*: ADDR*/ - int exponential; - MYFLT min,max; - void *WidgAddress, *opcode; - FL_ENUM widg_type; //gab - FL_ENUM joy; //gab - int group; // group for snapshot groups - ADDR_SET_VALUE(int new_exponential,MYFLT new_min, MYFLT new_max, - void *new_WidgAddress, void *new_opcode, int grp = 0) : - exponential(new_exponential),min(new_min), max(new_max), - WidgAddress(new_WidgAddress),opcode(new_opcode), - widg_type(FL_WIDG), joy(FL_JOY), group(grp) {} - ADDR_SET_VALUE() - { - exponential=LIN_; - min=0; - max=0; - WidgAddress=NULL; - opcode=NULL; - widg_type = FL_WIDG; - group = 0; - joy = FL_JOY; - } -}; - -struct PANELS { - Fl_Window *panel; - int is_subwindow; - PANELS(Fl_Window *new_panel, int flag) : panel(new_panel), - is_subwindow(flag) { } - PANELS() - { - panel = NULL; - is_subwindow=0; - } -}; - -struct SNAPSHOT { - int is_empty; - vector fields; - SNAPSHOT(vector& valuators, int snapGroup = 0); - SNAPSHOT() - { - is_empty = 1; - } - int get(vector& valuators, int snapGroup = 0); -}; - -typedef vector SNAPVEC; //gab - -struct WIDGET_GLOBALS { - WIDGET_GLOBALS(); - ~WIDGET_GLOBALS() - { - fl_windows.resize(0); - AddrStack.resize(0); //addresses of containers - AddrSetValue.resize(0); //addresses of valuators - for (int i = 0, n = allocatedStrings.size(); i < n; ++i) { - delete[] allocatedStrings[i]; - } - allocatedStrings.resize(0); - snapshots.resize(0); - } - char hack_o_rama1; // IV - Aug 23 2002 - char hack_o_rama2; - int ix, drag, indrag, sldrag; - int stack_count; - int FLcontrol_iheight; - int FLroller_iheight; - int FLcontrol_iwidth; - int FLroller_iwidth; - int FLvalue_iwidth; - int FLcolor; - int FLcolor2; - int FLtext_size; - int FLtext_color; - int FLtext_font; - int FLtext_align; - int currentSnapGroup; // GAB for snapshot groups - int last_KEY; // GAB - bool isKeyDown; //GAB - int FL_ix; - int FL_iy; - vector fl_windows; // all panels - vector AddrStack; //addresses of containers - vector AddrSetValue; //addresses of valuators - vector allocatedStrings; - int last_sldbnk; - FL_MIDI_WIDGET_VALUE *midiFLaddress[16][128]; // gab128 cc * 16 midi channels - int midiFLold_val[16][128]; //gab - vector snapshots; - vector::iterator snapshots_iterator; - FLTKMETER *p_vumeter; -#ifdef CS_IMAGE - vector Bm_image; // map of pointers to CAnyBmp objects - vector::iterator Bm_image_iterator; // iterator of the map -#endif -}; - - diff --git a/6.x/src/widgets/winFLTK.c b/6.x/src/widgets/winFLTK.c deleted file mode 100644 index 237037d5..00000000 --- a/6.x/src/widgets/winFLTK.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - winFLTK.c: graphs using FLTK library - - Copyright (C) 2002 John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -/* winFLTK.c */ -/* Csound FLTK/X graphs */ -/* jpff,06Oct02 */ - -#include "csdl.h" -#include -#include "cwindow.h" - -#ifdef LINUX -#include -#endif - -#include "winFLTK.h" - - - -static void MakeGraph_FLTK(CSOUND *csound, WINDAT *wdptr, const char *name) -{ - wdptr->windid = MakeWindow_FLTK(csound,(char*)name); -} - -static void KillGraph_FLTK(CSOUND *csound, WINDAT *wdptr) -{ - kill_graph(csound, wdptr->windid); -} - -static int dummyWidgetOpcode(CSOUND *csound, void *p) -{ - const char *opname; - - opname = csound->GetOpcodeName(p); - csound->Die(csound, Str("%s: widget opcodes have been disabled by " - "the host application"), opname); - return NOTOK; -} - -PUBLIC int csoundModuleCreate(CSOUND *csound) -{ - (void)csound; - return 0; -} - -PUBLIC int csoundModuleInit(CSOUND *csound) -{ - const OENTRY *ep = &(widgetOpcodes_[0]); - int initFlags = 0; - int *fltkFlags; - int enableDisplays = 0; - OPARMS oparms; - csound->GetOParms(csound, &oparms); - - if (csound->QueryGlobalVariable(csound, - "FLTK_Flags") == (void*) 0) { - if (UNLIKELY(csound->CreateGlobalVariable(csound, - "FLTK_Flags", sizeof(int)) != 0)) - csound->Die(csound, "%s", - Str("widgets.cpp: error allocating FLTK flags")); - initFlags = 1; - } - fltkFlags = getFLTKFlagsPtr(csound); - if (((*fltkFlags) & 2) == 0 && - !(oparms.graphsoff || oparms.postscript)) { -#ifdef LINUX - Display *dpy = XOpenDisplay(NULL); - if (dpy != NULL) { - XCloseDisplay(dpy); -#endif - if (csound->SetIsGraphable(csound, 1) == 0) { - enableDisplays = 1; - (*fltkFlags) |= 64; - - if (!((*fltkFlags) & 256)) - csound->SetInternalYieldCallback(csound, CsoundYield_FLTK); - flgraph_init(csound); /* Create space */ - csound->SetMakeGraphCallback(csound, MakeGraph_FLTK); - csound->SetDrawGraphCallback(csound, DrawGraph_FLTK); - csound->SetKillGraphCallback(csound, KillGraph_FLTK); - csound->SetExitGraphCallback(csound, ExitGraph_FLTK); - /* seemed to crash, but not anymore... */ - csound->RegisterResetCallback(csound, NULL, widget_reset); - csound->Message(csound, "graph init...\n"); - - } -#ifdef LINUX - } -#endif - } - if (initFlags) { -#ifndef __MACH__ - if (enableDisplays) -#endif - (*fltkFlags) |= 28; - } - if (!((*fltkFlags) & 129)) - for ( ; ep->opname != NULL; ep++) { - if (csound->AppendOpcode(csound, ep->opname, - (int)ep->dsblksiz, (int)ep->flags, (int)ep->thread, - ep->outypes, ep->intypes, - ep->iopadr, ep->kopadr, ep->aopadr) != 0) { - csound->ErrorMsg(csound, Str("Error registering opcode '%s'"), - ep->opname); - return -1; - } - } - else if (!((*fltkFlags) & 128)) { - for ( ; ep->opname != NULL; ep++) { - if (csound->AppendOpcode( - csound, ep->opname, (int)ep->dsblksiz, - (int)ep->flags,(int)ep->thread, - ep->outypes, ep->intypes, - (((int)ep->thread & 1) ? dummyWidgetOpcode : (SUBR) 0), - (((int)ep->thread & 2) ? dummyWidgetOpcode : (SUBR) 0), - (((int)ep->thread & 4) ? dummyWidgetOpcode : (SUBR) 0)) != 0) { - csound->ErrorMsg(csound, Str("Error registering opcode '%s'"), - ep->opname); - return -1; - } - } - } - - widget_init(csound); - return 0; -} - -PUBLIC int csoundModuleInfo(void) -{ - return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int)sizeof(MYFLT)); -} diff --git a/6.x/src/widgets/winFLTK.h b/6.x/src/widgets/winFLTK.h deleted file mode 100644 index 68df69aa..00000000 --- a/6.x/src/widgets/winFLTK.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - winFLTK.h: - - Copyright (C) 2006 Istvan Varga - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#ifndef CSOUND_WINFLTK_H -#define CSOUND_WINFLTK_H - -#include "csdl.h" -#ifdef __cplusplus -#include -#endif - -/** - * FLTK flags is the sum of any of the following values: - * 1 (input): disable widget opcodes by setting up dummy opcodes instead - * 2 (input): disable FLTK graphs - * 4 (input): disable the use of a separate thread for widget opcodes - * 8 (input): disable the use of Fl::lock() and Fl::unlock() - * 16 (input): disable the use of Fl::awake() - * 32 (output): widget opcodes are used - * 64 (output): FLTK graphs are used - * 128 (input): disable widget opcodes by not registering any opcodes - * 256 (input): disable the use of Fl::wait() (implies no widget thread) - */ - -static inline int getFLTKFlags(CSOUND *csound) -{ - return (*((int*) csound->QueryGlobalVariableNoCheck(csound, "FLTK_Flags"))); -} - -static inline int *getFLTKFlagsPtr(CSOUND *csound) -{ - return ((int*) csound->QueryGlobalVariableNoCheck(csound, "FLTK_Flags")); -} - -#ifdef __cplusplus - -static inline void Fl_lock(CSOUND *csound) -{ -#ifdef NO_FLTK_THREADS - (void) csound; -#else - if (!(getFLTKFlags(csound) & 8)) { - Fl::lock(); - } -#endif -} - -static inline void Fl_unlock(CSOUND *csound) -{ -#ifdef NO_FLTK_THREADS - (void) csound; -#else - if (!(getFLTKFlags(csound) & 8)) { - Fl::unlock(); - } -#endif -} - -static inline void Fl_awake(CSOUND *csound) -{ -#ifdef NO_FLTK_THREADS - (void) csound; -#else - if (!(getFLTKFlags(csound) & 16)) { - Fl::awake(); - } -#endif -} - -static inline void Fl_wait(CSOUND *csound, double seconds) -{ - if (!(getFLTKFlags(csound) & 256)) - Fl::wait(seconds); -} - -static inline void Fl_wait_locked(CSOUND *csound, double seconds) -{ - int fltkFlags; - - fltkFlags = getFLTKFlags(csound); - if (!(fltkFlags & 256)) { -#ifndef NO_FLTK_THREADS - if (!(fltkFlags & 8)) - Fl::lock(); -#endif - Fl::wait(seconds); -#ifndef NO_FLTK_THREADS - if (!(fltkFlags & 8)) - Fl::unlock(); -#endif - } -} - -#endif /* __cplusplus */ - -#ifdef __cplusplus -extern "C" { -#endif - -extern int CsoundYield_FLTK(CSOUND *); -extern void DrawGraph_FLTK(CSOUND *, WINDAT *); -extern int ExitGraph_FLTK(CSOUND *); -extern void kill_graph(CSOUND *, uintptr_t); -extern void KillXYin_FLTK(CSOUND *, XYINDAT *); -extern uintptr_t MakeWindow_FLTK(CSOUND *, char *); -extern void MakeXYin_FLTK(CSOUND *, XYINDAT *, MYFLT, MYFLT); -extern int myFLwait(void); -extern void ReadXYin_FLTK(CSOUND *, XYINDAT *); - extern void flgraph_init(CSOUND *csound); -extern void widget_init(CSOUND *); -extern int widget_reset(CSOUND *, void *); - -extern const OENTRY widgetOpcodes_[]; - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* CSOUND_WINFLTK_H */ - diff --git a/6.x/src/wiimote/CMakeLists.txt b/6.x/src/wiimote/CMakeLists.txt deleted file mode 100644 index cb4997c0..00000000 --- a/6.x/src/wiimote/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -option(BUILD_WIIMOTE_OPCODES "Build the Wiimote opcodes" ON) - -find_path(WIIUSE_INCLUDE_DIR wiiuse.h /usr/local/include) -find_library(WIIUSE_LIB wiiuse) -check_deps(BUILD_WIIMOTE_OPCODES WIIUSE_LIB) - -if(BUILD_WIIMOTE_OPCODES) - make_plugin(wiimote wiimote.c ${WIIUSE_LIB}) - target_include_directories(wiimote PRIVATE ${WIIUSE_INCLUDE_DIR} ${CSOUND_INCLUDE_DIR}) -endif() diff --git a/6.x/src/wiimote/wiimote.c b/6.x/src/wiimote/wiimote.c deleted file mode 100644 index 2e62eacc..00000000 --- a/6.x/src/wiimote/wiimote.c +++ /dev/null @@ -1,425 +0,0 @@ -/* - wiimote.c: - - Copyright (C) 2009 by John ffitch, - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - - /* wiimote.c */ -#include "csdl.h" -#include "wiiuse.h" /* Uses WIIUSE library which is LGPL */ -#define MAX_WIIMOTES 4 -#include "wii_mac.h" - -typedef struct { - MYFLT axis_x_min; /* 0 -> 255 */ - MYFLT axis_x_scale; /* 1 */ - MYFLT axis_y_min; - MYFLT axis_y_scale; - MYFLT axis_z_min; - MYFLT axis_z_scale; - MYFLT pitch_min; /* -90 -> +90 */ - MYFLT pitch_scale; /* 1 */ - MYFLT roll_min; - MYFLT roll_scale; - /* MYFLT tilt_z_min; */ - /* MYFLT tilt_z_scale; */ - MYFLT joy_min; - MYFLT joy_scale; - MYFLT nunchuk_pitch_min; - MYFLT nunchuk_pitch_scale; - MYFLT nunchuk_roll_min; - MYFLT nunchuk_roll_scale; - /* MYFLT naxis_z_min; */ - /* MYFLT naxis_z_max; */ -} wiirange_t; - - -typedef struct { - OPDS h; - MYFLT *res; - MYFLT *kControl; - MYFLT *num; - /* ------------------------------------- */ - wiimote **wii; - wiirange_t *wiir; - int32_t max_wiimotes; -} WIIMOTE; - -typedef struct { - OPDS h; - MYFLT *kControl; - MYFLT *kValue; - MYFLT *num; - /* ------------------------------------- */ - wiimote **wii; - wiirange_t *wiir; -} WIIMOTES; - -typedef struct { - OPDS h; - MYFLT *iControl; - MYFLT *iMin; - MYFLT *iMax; - MYFLT *num; - } WIIRANGE; - -#ifndef WIIMOTE_STATE_CONNECTED -# if defined(WIIUSE_0_13) -# define WIIMOTE_STATE_CONNECTED (0x0010) -# else -# define WIIMOTE_STATE_CONNECTED (0x0008) -# endif -#endif - -int32_t wiimote_find(CSOUND *csound, WIIMOTE *p) -{ - int32_t n, i; - wiimote **wiimotes; - wiirange_t *wiirange; - int32_t max_wiimotes; - - wiimotes = (wiimote**)csound->QueryGlobalVariable(csound, "wiiMote"); - if (wiimotes == NULL) { - csound->CreateGlobalVariable(csound, "wiiMote", - MAX_WIIMOTES*sizeof(wiimote*)); - wiimotes = (wiimote**)csound->QueryGlobalVariable(csound, "wiiMote"); - } - wiirange = (wiirange_t *)csound->QueryGlobalVariable(csound, "wiiRange"); - if (wiirange == NULL) { - csound->CreateGlobalVariable(csound, "wiiRange", - MAX_WIIMOTES*sizeof(wiirange_t)); - wiirange = (wiirange_t *)csound->QueryGlobalVariable(csound, "wiiRange"); - } - { /* Use our copy not his */ - wiimote** ww = wiiuse_init(MAX_WIIMOTES); - memcpy(wiimotes, ww, MAX_WIIMOTES*sizeof(wiimote*)); - free(ww); - } - i = (int32_t)*p->kControl; - if (i<=0) i = 10; /* default timeout */ - max_wiimotes = (int32_t)*p->num; - if (max_wiimotes<=0 || max_wiimotes>MAX_WIIMOTES) max_wiimotes = MAX_WIIMOTES; - n = wiiuse_find(wiimotes, max_wiimotes, i); - if (LIKELY(n!=0)) n = wiiuse_connect(wiimotes, max_wiimotes); - if (UNLIKELY(n==0)) { - return csound->InitError(csound, "%s", Str("unable to open wiimote\n")); - } - /* Initialise ranges */ - for (i=0; iwii = wiimotes; - p->max_wiimotes = n; - *p->res = FL(1.0); - return OK; -} - -int32_t wiimote_poll(CSOUND *csound, WIIMOTE *p) -{ - wiimote **wiimotes = p->wii; - int32_t i; - int32_t max_wiimotes = p->max_wiimotes; - - wiiuse_poll(wiimotes, max_wiimotes); - for (i=0; i < max_wiimotes; ++i) { - switch (wiimotes[i]->event) { - case WIIUSE_EVENT: - case WIIUSE_STATUS: - case WIIUSE_READ_DATA: - break; - case WIIUSE_DISCONNECT: - case WIIUSE_UNEXPECTED_DISCONNECT: - /* the wiimote disconnected */ - csound->Warning(csound, - Str("wiimote %i disconnected\n"), wiimotes[i]->unid); - *p->res = FL(0.0); - return OK; - case WIIUSE_NUNCHUK_INSERTED: - /* - * This is a good place to set any nunchuk specific - * threshold values. By default they are the same - * as the wiimote. - */ - /* wiiuse_set_nunchuk_orient_threshold((struct nunchuk_t*)&wiimotes[i]-> */ - /* exp.nunchuk, 90.0f); */ - /* wiiuse_set_nunchuk_accel_threshold((struct nunchuk_t*)&wiimotes[i]-> */ - /* exp.nunchuk, 100); */ - csound->Warning(csound, "%s", Str("Nunchuk inserted.\n")); - break; - case WIIUSE_NUNCHUK_REMOVED: - /* some expansion was removed */ - csound->Warning(csound, Str("Nunchuk for wiimote %i was removed.\n"), i); - break; - default: - break; - } - } - *p->res = FL(1.0); - return OK; -} - - -int32_t wii_data_init(CSOUND *csound, WIIMOTE *p) -{ - wiimote **wiimotes; - wiirange_t *wiirange; - wiimotes = (wiimote**)csound->QueryGlobalVariable(csound, "wiiMote"); - if (UNLIKELY(wiimotes==NULL)) - return csound->InitError(csound, "%s", Str("No wii open")); - wiirange = (wiirange_t *)csound->QueryGlobalVariable(csound, "wiiRange"); - if (UNLIKELY(wiirange==NULL)) - return csound->InitError(csound, "%s", Str("No wii open")); - p->wii = wiimotes; - p->wiir = wiirange; - return OK; -} - -int32_t wii_data(CSOUND *csound, WIIMOTE *p) -{ - wiimote **wii = p->wii; - wiirange_t *wiir = p->wiir; - int32_t n = (int32_t)*p->num; - int32_t kontrol = (int32_t)(*p->kControl+FL(0.5)); - if (UNLIKELY(n>=MAX_WIIMOTES || !(wii[n]->state & WIIMOTE_STATE_CONNECTED))) { - printf("state of wii %d is %x\n", n, wii[n]->state); - return csound->PerfError(csound, &(p->h), - Str("wiimote %d does not exist"), n); - } - if (kontrol<0) { - printf("%f -- %.4x: " - "tilt=[%f %f];\nforce=(%f %f %f)\n", - 100.0*wii[n]->battery_level, wii[n]->btns, - wiir[n].pitch_min+wiir[n].pitch_scale*(FL(90.0)+ - (MYFLT)wii[n]->orient.pitch), - wiir[n].roll_min+wiir[n].roll_scale*(FL(90.0)- - (MYFLT)wii[n]->orient.roll), - wii[n]->gforce.x, wii[n]->gforce.y, wii[n]->gforce.z); - *p->res = FL(0.0); - return OK; - } - if (kontrol>0 && kontrol<17) { - *p->res = (MYFLT)IS_JUST_PRESSED(wii[n], 1<<(kontrol-1)); - } - if (kontrol>100 && kontrol<117) { - *p->res = (MYFLT)IS_PRESSED(wii[n], 1<<(kontrol-101)); - return OK; - } - if (kontrol>200 && kontrol<217) { - *p->res = (MYFLT)IS_HELD(wii[n], 1<<(kontrol-201)); - return OK; - } - if (kontrol>300 && kontrol<317) { - *p->res = (MYFLT)IS_RELEASED(wii[n], 1<<(kontrol-301)); - return OK; - } - else switch (kontrol) { - case WII_BUTTONS: - *p->res = (MYFLT)(wii[n]->btns&WIIMOTE_BUTTON_ALL); - return OK; - /* case 17: */ - /* *p->res = wiir[n].axis_x_min+wiir[n].axis_x_scale*(MYFLT)wii[n]->axis.x; */ - /* return OK; */ - /* case 18: */ - /* *p->res = wiir[n].axis_y_min+wiir[n].axis_y_scale*(MYFLT)wii[n]->axis.y; */ - /* return OK; */ - /* case 19: */ - /* *p->res = wiir[n].axis_z_min+wiir[n].axis_z_scale*(MYFLT)wii[n]->axis.z; */ - /* return OK; */ - case WII_PITCH: - /* I think the sign is wrong so negated; inplies negative is down */ - *p->res = wiir[n].pitch_min+ - wiir[n].pitch_scale*(FL(90.0)-(MYFLT)wii[n]->orient.pitch); - return OK; - case WII_ROLL: - *p->res = wiir[n].roll_min+ - wiir[n].roll_scale*(FL(90.0)+(MYFLT)wii[n]->orient.roll); - return OK; - /* case 22: */ - /* *p->res = wiir[n].tilt_z_min+ - wiir[n].tilt_z_scale*(FL(90.0)-(MYFLT)wii[n]->tilt.z); */ - /* return OK; */ - case WII_FORCE_X: - *p->res = (MYFLT)wii[n]->gforce.x; - return OK; - case WII_FORCE_Y: - *p->res = (MYFLT)wii[n]->gforce.y; - return OK; - case WII_FORCE_Z: - *p->res = (MYFLT)wii[n]->gforce.z; - return OK; - case WII_FORCE_TOTAL: - *p->res = SQRT(wii[n]->gforce.x*wii[n]->gforce.x+ - wii[n]->gforce.y*wii[n]->gforce.y+ - wii[n]->gforce.z*wii[n]->gforce.z); - return OK; - case WII_BATTERY: - *p->res = FL(100.0)*(MYFLT)wii[n]->battery_level; - return OK; - case WII_NUNCHUK_ANG: - *p->res = (MYFLT)wii[n]->exp.nunchuk.js.ang; - return OK; - case WII_NUNCHUK_MAG: - *p->res = (MYFLT)wii[n]->exp.nunchuk.js.mag; - return OK; - case WII_NUNCHUK_PITCH: - *p->res = wiir[n].nunchuk_pitch_min+ - wiir[n].nunchuk_pitch_scale*(FL(90.0)- - (MYFLT)wii[n]->exp.nunchuk.orient.pitch); - return OK; - case WII_NUNCHUK_ROLL: - *p->res = wiir[n].nunchuk_roll_min+ - wiir[n].nunchuk_roll_scale*(FL(90.0)- - (MYFLT)wii[n]->exp.nunchuk.orient.roll); - return OK; - /* case 32: */ - /* *p->res = (MYFLT)wii[n]->exp.nunchuk.axis.z; */ - /* return OK; */ - case WII_NUNCHUK_Z: - *p->res = (MYFLT)((wii[n]->exp.nunchuk.btns & NUNCHUK_BUTTON_Z)== - NUNCHUK_BUTTON_Z); - return OK; - case WII_NUNCHUK_C: - *p->res = (MYFLT)((wii[n]->exp.nunchuk.btns & NUNCHUK_BUTTON_C)== - NUNCHUK_BUTTON_C); - return OK; - case WII_IR1_X: - *p->res = (MYFLT)wii[n]->ir.x; - return OK; - case WII_IR1_Y: - *p->res = (MYFLT)wii[n]->ir.y; - return OK; - case WII_IR1_Z: - *p->res = (MYFLT)wii[n]->ir.z; - return OK; - } - return NOTOK; -} - -int32_t wii_data_inits(CSOUND *csound, WIIMOTES *p) -{ - wiimote **wiimotes; - wiirange_t *wiirange; - wiimotes = (wiimote**)csound->QueryGlobalVariable(csound, "wiiMote"); - if (UNLIKELY(wiimotes==NULL)) - return csound->InitError(csound, "%s", Str("No wii open")); - wiirange = (wiirange_t *)csound->QueryGlobalVariable(csound, "wiiRange"); - if (UNLIKELY(wiirange==NULL)) - return csound->InitError(csound, "%s", Str("No wii open")); - p->wii = wiimotes; - p->wiir = wiirange; - return OK; -} - -int32_t wii_send(CSOUND *csound, WIIMOTES *p) -{ - wiimote **wii = p->wii; - int32_t num = (int32_t)*p->num; - if (UNLIKELY(!(wii[num]->state & WIIMOTE_STATE_CONNECTED))) - return csound->PerfError(csound, &(p->h), "%s", Str("Not open")); - switch ((int32_t)(*p->kControl+FL(0.5))) { - /* case 1: */ - /* wii->mode.acc = (int32_t)*p->kValue; */ - /* break; */ - /* case 2: */ - /* wii->mode.ir = (int32_t)*p->kValue; */ - /* break; */ - case WII_RUMBLE: - wiiuse_rumble(wii[num], (int32_t)*p->kValue); - break; - case WII_SET_LEDS: - wiiuse_set_leds(wii[num], ((uint16)*p->kValue)<<4); - break; - } - return OK; -} - -int32_t wiimote_range(CSOUND *csound, WIIRANGE *p) -{ - wiirange_t *wiirange = - (wiirange_t *)csound->QueryGlobalVariable(csound, "wiiRange"); - if (UNLIKELY(wiirange==NULL)) - return csound->InitError(csound, "%s", Str("No wii range")); - switch ((int32_t)(*p->iControl+FL(0.5))) { - /* case 17: */ - /* wiirange->axis_x_min = *p->iMin; */ - /* wiirange->axis_x_scale = (*p->iMax-*p->iMin)/FL(255.0); */ - /* return OK; */ - /* case 18: */ - /* wiirange->axis_y_min = *p->iMin; */ - /* wiirange->axis_y_scale = (*p->iMax-*p->iMin)/FL(255.0); */ - /* return OK; */ - /* case 19: */ - /* wiirange->axis_z_min = *p->iMin; */ - /* wiirange->axis_z_scale = (*p->iMax-*p->iMin)/FL(255.0); */ - /* return OK; */ - case WII_PITCH: - wiirange->pitch_min = *p->iMin; - wiirange->pitch_scale = (*p->iMax-*p->iMin)/FL(180.0); - return OK; - case WII_ROLL: - wiirange->roll_min = *p->iMin; - wiirange->roll_scale = (*p->iMax-*p->iMin)/FL(180.0); - return OK; - /* case 22: */ - /* wiirange->tilt_z_min = *p->iMin; */ - /* wiirange->tilt_z_scale = (*p->iMax-*p->iMin)/FL(180.0); */ - /* return OK; */ - case WII_NUNCHUK_PITCH: - wiirange->nunchuk_pitch_min = *p->iMin; - wiirange->nunchuk_pitch_scale = (*p->iMax-*p->iMin)/FL(180.0); - return OK; - case WII_NUNCHUK_ROLL: - wiirange->nunchuk_roll_min = *p->iMin; - wiirange->nunchuk_roll_scale = (*p->iMax-*p->iMin)/FL(180.0); - return OK; - default: - return NOTOK; - } -} - - - -#define S(x) sizeof(x) - -static OENTRY wiimote_localops[] = { - {"wiiconnect", S(WIIMOTE), 0, 3, "i", "oo", (SUBR)wiimote_find, - (SUBR)wiimote_poll }, - {"wiidata", S(WIIMOTE), 0, 3, "k", "ko", (SUBR)wii_data_init, (SUBR)wii_data }, - {"wiisend", S(WIIMOTES), 0, 3, "", "kko", (SUBR)wii_data_inits, (SUBR)wii_send }, - {"wiirange", S(WIIRANGE), 0, 1, "", "iiio", (SUBR)wiimote_range, NULL, NULL } -}; - -LINKAGE_BUILTIN(wiimote_localops) diff --git a/6.x/vcpkg b/6.x/vcpkg deleted file mode 160000 index f6a5d4e8..00000000 --- a/6.x/vcpkg +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f6a5d4e8eb7476b8d7fc12a56dff300c1c986131 diff --git a/6.x/vcpkg.json b/6.x/vcpkg.json deleted file mode 100644 index 21ef94d8..00000000 --- a/6.x/vcpkg.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", - "name": "csound-plugins", - "version-string": "6.16.2", - "builtin-baseline": "f6a5d4e8eb7476b8d7fc12a56dff300c1c986131", - "dependencies": [ - "ableton-link", - "eigen3", - "fltk", - "fluidsynth", - "hdf5", - "libstk", - "libwebsockets", - "mp3lame", - "zlib" - ] -} \ No newline at end of file diff --git a/6.x/x64-windows-csound.cmake b/6.x/x64-windows-csound.cmake deleted file mode 100644 index dc862f9a..00000000 --- a/6.x/x64-windows-csound.cmake +++ /dev/null @@ -1,8 +0,0 @@ -set(VCPKG_TARGET_ARCHITECTURE x64) -set(VCPKG_CRT_LINKAGE dynamic) - -if(${PORT} MATCHES "fluidsynth|glib|zlib|pcre|libffi|gettext|libiconv|portmidi|portaudio|liblo") - set(VCPKG_LIBRARY_LINKAGE dynamic) -else() - set(VCPKG_LIBRARY_LINKAGE static) -endif() diff --git a/7.x/README.md b/7.x/README.md deleted file mode 100644 index d558c388..00000000 --- a/7.x/README.md +++ /dev/null @@ -1,408 +0,0 @@ -Plugins for Csound 7.x -======= - -Currently, the plugins available in this tree are - -- chua (requires the Eigen library, header-only) -**chuap** - -- fluidOpcodes (requires fluidsynth) -**fluidEngine fluidLoad fluidNote fluidCCi fluidCCk fluidControl fluidProgramSelect fluidAllOut fluidOut fluidInfo fluidSetInterpMethod** - -- dssi4cs (hosts native DSSI/LADSPA plugins; Linux only, requires the ALSA headers) -**dssiinit dssiactivate dssiaudio dssisynth dssictls dssiget dssinote dssievent dssinrpn dssiprogram dssiconfigure dssiprograminfo dssiinfo dssilist** - -- faust (requires the Faust compiler library and headers, `libfaust`) -**faustgen faustcompile faustaudio faustdsp faustplay faustctl** - -- image (requires libpng) -**imageload imagesave imagecreate imagesize imagegetpixel imagesetpixel imagefree** - -- hdf5 (requires the HDF5 library) -**hdf5read hdf5write** - -- linear_algebra (requires the gmm++ library, header-only; vendored under this directory) -**A large family of `la_*` opcodes, with i-rate and k-rate variants, for vector, matrix and tensor operations** - -- py (requires a Python 3.x installation with dev libs) -**Many opcodes to call Python code** - -- websockets (requires libwebsockets) -**websocket** - -- wiimote (requires the wiiuse library; CMake-only, see note below) -**wiiconnect wiidata wiisend wiirange** - -- p5glove (requires the p5glove driver; CMake-only, see note below) -**p5gconnect p5gdata** - -- CUDA (requires the CUDA toolkit; Linux only, disabled by default, see note below) -**cudasynth cudanal cudasliding cudaconv cudapconv** - -- OpenCL (requires the OpenCL headers/loader; see note below) -**cladsyn** - -- STK (port of the Synthesis ToolKit instruments; STK 4.6.2 is vendored under this directory, see note below) -**STKBandedWG STKBeeThree STKBlowBotl STKBlowHole STKBowed STKBrass STKClarinet STKDrummer STKFlute STKFMVoices STKHevyMetl STKMandolin STKModalBar STKMoog STKPercFlut STKPlucked STKResonate STKRhodey STKSaxofony STKShakers STKSimple STKSitar STKStifKarp STKTubeBell STKVoicForm STKWhistle STKWurley** - - -WebAssembly (WASM) plugins ---- - -Besides the native plugin libraries described above, this tree can also be -built for the browser: Csound 7 runs under WebAssembly (WASI) through the -`@csound/browser` runtime, and a subset of these plugins is available as WASM -side modules. The WASM build is driven by the Nix expression in -[`wasm/default.nix`](../wasm/default.nix) and published as the `@csound/plugins` -npm package; see [`wasm/README.md`](../wasm/README.md) for the build and test -instructions. - -Only four plugins are built for WASM: - -- chua (`chuap`) -- image -- linear_algebra -- STK (`stkops`) - -The remaining plugins are **disabled** in the WASM build, either because their -dependencies do not exist in the WASI/static-PIC toolchain or because they need -platform facilities the browser does not provide: fluidOpcodes (FluidSynth), -hdf5, faust (libfaust), websockets, py (Python), wiimote, p5glove, CUDA and -OpenCL. - -The `@csound/plugins` package exposes one asset URL per WASM plugin: - -| Export | Plugin | File | -| --- | --- | --- | -| `plugins.chua` | chua | `chua.wasm` | -| `plugins.image` | image | `image.wasm` | -| `plugins.linearAlgebra` | linear_algebra | `linear_algebra.wasm` | -| `plugins.stk` | STK | `stkops.wasm` | - -The URLs are passed to the runtime's `withPlugins` option, e.g.: - -```js -import { Csound } from "@csound/browser"; -import { plugins } from "@csound/plugins"; - -const csound = await Csound({ withPlugins: [plugins.chua, plugins.image] }); -``` - -Unlike the native build, the WASM STK plugin embeds its raw-wave samples in -`stkops.wasm` (`STK_EMBED_RAWWAVES` defaults to ON for WASM): at initialization -it writes them to Csound's virtual filesystem and sets the wave path, so no -separate download or `RAWWAVE_PATH` setup is needed. An explicit `RAWWAVE_PATH` -still overrides the embedded samples. - - -Fluid settings opcodes ---- - -Besides the engine/SoundFont/MIDI opcodes listed above, `fluidOpcodes` -provides four opcodes to read and write the settings of an engine created by -`fluidEngine` (resolved through `fluid_synth_get_settings`). In each case the -first argument is the engine id and the second is the setting name: - -| Opcode | Outputs | Inputs | Description | -| --- | --- | --- | --- | -| `fluidSettingNum` | – | `iSk` | set an int/num/bool setting | -| `fluidSettingString` | – | `iSS` | set a string setting | -| `fluidSettingGetNum` | `k` | `iS` | read a numeric setting | -| `fluidSettingGetString` | `S` | `iS` | read a string setting | - -The setters fail at init if the setting name is unknown or of the wrong type; -the getters report a message and return 0 (or an empty string) instead. - - -Wiimote opcodes ---- - -The `wiimote` opcodes (`wiiconnect`, `wiidata`, `wiisend`, `wiirange`) are a -CMake-only port of the Csound 6.x plugin. They are **not** built by the CI and -are **not** included in the release packages, because the required `wiiuse` -library is not available as a standard distribution package: it is not in the -Ubuntu repositories, and the vcpkg `wiiuse` port ships only pkg-config -metadata, so it cannot be wired into the automated builds. - -When `wiiuse` (headers and library) is found by CMake, the plugin is built and -installed like any other; otherwise `BUILD_WIIMOTE_OPCODES` is silently -disabled. To build it locally, install `wiiuse` and configure with -`-DBUILD_WIIMOTE_OPCODES=ON`. - - -P5Glove opcodes ---- - -The `p5glove` opcodes (`p5gconnect`, `p5gdata`) are a CMake-only port of the -Csound 6.x plugin. They are **not** built by the CI and are **not** included in -the release packages, because the required P5Glove driver is not widely -packaged: there is no vcpkg port for `libp5glove`, and its Linux backend needs -the legacy libusb-0.1 API (not present in vcpkg). - -When an external `libp5glove` (headers and library) is found by CMake, the -plugin is built and installed like any other; otherwise -`BUILD_P5GLOVE_OPCODES` is silently disabled. On macOS the driver can -additionally be built from the sources bundled under `src/p5glove/libp5glove` -by configuring with `-DP5GLOVE_USE_BUNDLED=ON` (in addition to -`-DBUILD_P5GLOVE_OPCODES=ON`). - - -CUDA opcodes ---- - -The `CUDA` opcodes (`cudasynth`, `cudanal`, `cudasliding`, `cudaconv`, -`cudapconv`) are a port of the Csound 6.x plugin to the Csound 7 plugin API. -They run their DSP kernels on an NVIDIA GPU; `cudanal` and `cudapconv` also -rely on cuFFT. - -They are **disabled by default** and only built when the CUDA toolkit is -found: configure with `-DBUILD_CUDA_OPCODES=ON`. CUDA is **not available on -macOS** (NVIDIA dropped macOS support after 10.13), so on macOS the option is -ignored. The Linux CI builds them compile-only (the hosted runners have no -GPU) and they are included in the Linux release package. Windows is not built -or tested, so the CUDA opcodes are currently Linux-only. - -Building them requires CMake 3.18 or later; with an older CMake the option -is ignored. The compute capabilities default to `75 80 86 89`; override with -`-DCMAKE_CUDA_ARCHITECTURES="..."` (for example `native` for the local GPU). - - -OpenCL opcodes ---- - -The `OpenCL` opcode (`cladsyn`) is a port of the Csound 6.x plugin to the -Csound 7 plugin API. It runs its DSP kernels on any available OpenCL device -(CPU or GPU) through the ICD loader. - -It is built by default when OpenCL is available: the system framework is used -on macOS, `ocl-icd-opencl-dev` on Linux and the vcpkg `opencl` port on Windows. -Configure with `-DBUILD_OPENCL_OPCODES=OFF` to exclude it. The CI builds it -compile-only (the hosted runners have no OpenCL device) and it is included in -the Linux, macOS and Windows release packages. - - -STK opcodes ---- - -The `STK` opcodes are a port of the Csound 6.x plugin to the Csound 7 plugin -API. They expose the instruments of Perry Cook and Gary Scavone's Synthesis -ToolKit in C++ (STK), each named `STK` followed by the STK class, e.g. -`STKSitar`. All of them share the same signature: - -``` -aout STKName ifrequency igain {kcontroller0, kvalue0, ..., kcontrollerN, kvalueN} -``` - -The STK sources are **vendored under this directory** (`include/`, `src/` and -`rawwaves/`) and built from source, so no external STK installation is needed -and the result is independent of any system or package-manager STK. The -vendored copy carries a fix for the sample buildup reported in -[csound/plugins#4](https://github.com/csound/plugins/issues/4): the noise -modulation of the sitar delay line in `Sitar::setFrequency`, which could make -`STKSitar` build up clipped output over time, has been removed. - -It is built by default; configure with `-DBUILD_STK_OPCODES=OFF` to exclude -it. The wavetables the instruments need are installed alongside the plugin -(under `stk/rawwaves`). At run time the `RAWWAVE_PATH` environment variable, -if set, overrides the built-in default location; otherwise the installed -`rawwaves` directory is used. The plugin is included in the Linux, macOS and -Windows release packages. - - -Faust opcodes ---- - -The `faust` opcodes embed the [Faust](https://faust.grame.fr/) compiler and -DSP runtime into Csound, so a Faust program supplied as a string is compiled -at init time and run as a Csound opcode. They are a port of the Csound 6.x -plugin to the Csound 7 plugin API: - -``` -ihandle[,asig1,...] faustgen Scode[,ain1,...] -ihandle faustcompile Scode, Sargs[, iasync, istacksize[, Starget]] -ihandle[,asig1,...] faustaudio ifactory[,ain1,...] -ihandle faustdsp ifactory -asig1[,asig2,...] faustplay ihandle[,ain1,...] - faustctl ihandle, Slabel, kval[, Slabel1, kval1, ...] -``` - -Where: - -- `faustgen` compiles `Scode` and runs it in a single opcode, returning a - handle and the audio outputs. -- `faustcompile` compiles `Scode` and returns `ihandle`, a handle to the - compiled factory, to be passed to `faustaudio` or `faustdsp`. -- `faustaudio`/`faustdsp` instantiate the factory named by `ifactory`; - `faustaudio` has audio inputs and outputs, `faustdsp` has none. -- `faustplay` runs the DSP instance named by `ihandle` (one returned by - `faustgen`, `faustaudio` or `faustdsp`) with explicit inputs and outputs. -- `faustctl` sets the control `Slabel` of a DSP instance; both an i-rate - (`iSi`) and a k-rate (`iSk`) form are provided, the latter updating the - control every k-cycle. - -`Scode` is the Faust program (programs that use the standard library need -`import("stdfaust.lib");`). `Sargs` holds any extra Faust compiler options; -`iasync` selects asynchronous compilation (on by default), `istacksize` is -accepted for backwards compatibility but ignored (the Csound 7 threading API -no longer sets the thread stack size) and `Starget` is an optional LLVM -target string (an empty string selects the native target). - -The opcodes need the Faust compiler library (`libfaust`) and headers. The -build looks for them automatically; if Faust is in a non-standard location, -point CMake at it with `FAUST_INCLUDE_DIR_HINT`, `FAUST_LIB_DIR_HINT` and -`FAUST_STDLIB_DIR_HINT`. With `-DFAUST_STATIC=ON` the plugin is linked -against the self-contained `libfaustwithllvm` archive, which bundles LLVM so -the plugin has no runtime dependency on `libfaust` (at the cost of a much -larger plugin). - -It is built by default; configure with `-DBUILD_FAUST_OPCODES=OFF` to -exclude it. The Faust standard library is installed next to the plugin (in a -`faust` subdirectory), so `import("stdfaust.lib")` works without a separate -Faust installation; set `FAUST_LIB_PATH` at run time to override it. The CI -downloads the official Faust release binaries, builds with `FAUST_STATIC=ON` -and includes the plugin (and the standard library) in the Linux, macOS and -Windows release packages. - - -DSSI and LADSPA opcodes ---- - -The `dssi4cs` plugin hosts native DSSI synths and LADSPA effects: - -``` -ih dssiinit Sfilename, iindex [, iverbose] - dssilist - dssiinfo ih - dssiactivate ih, kactive -a1[,a2,...] dssisynth ih [, ain1, ...] -a1[,a2,...] dssiaudio ih [, ain1, ...] - dssinote ktrigger, ih, knote, kvelocity, kduration [, ichannel] - dssievent ktrigger, ih, knote, kvelocity - dssievent ktrigger, ih, kstatus, kchannel, kdata1, kdata2 [, koffset] - dssinrpn ktrigger, ih, kchannel, kparameter, kvalue [, koffset] - dssictls ih, iport, kvalue, ktrigger -kvalue dssiget ih, iport - dssiprogram ih, kbank, kprogram, ktrigger -Sname, ibank, iprogram dssiprograminfo ih, iindex - dssiconfigure ih, Skey, Svalue -``` - -The opcodes load a plugin library, instantiate a DSSI synth or LADSPA effect, -feed it Csound audio and MIDI events, and return its audio. Libraries are -looked up by path or through `DSSI_PATH` and `LADSPA_PATH`. See the -[module README](src/dssi4cs/README.md) for the full opcode reference. - -Hosting native plugins is Linux-only: the opcodes load the shared objects with -`dlopen` and use the ALSA sequencer event types, so they need the ALSA headers -(`libasound2-dev` on Debian/Ubuntu) but not the ALSA library or a running -sequencer. The DSSI and LADSPA API headers are **vendored under this -directory** (in `src/dssi4cs/include`), so no system DSSI/LADSPA development -package is required. - -It is built by default on Linux when the ALSA headers are found and silently -disabled elsewhere; configure with `-DBUILD_DSSI_OPCODES=OFF` to exclude it. -It is included in the Linux release package only. - - -Release binaries and macOS architecture --------------- - -The CI builds each plugin on its default hosted runner and packages the -resulting plugin libraries into the GitHub release assets. These binaries are -single-architecture — they are **not** universal fat binaries. - -On macOS the release plugins are built on the Apple Silicon (`arm64`) -`macos-latest` runner with no `CMAKE_OSX_ARCHITECTURES` override, and the -dependencies come from vcpkg using the `arm64-osx` triplet. The -`csound7-plugins-*-macos.zip` release asset therefore contains **arm64-only** -`.dylib` files: they load in the arm64 build of Csound on Apple Silicon, but -not in the x86_64 (Intel) build on Intel Macs. Users on Intel Macs should -build the plugins from source against x86_64 versions of their dependencies -(see the build instructions below). - - -Install location --------------- -The CMake scripts in this repository use the default CS_USER_PLUGIN -location on MacOS and Windows as defined in the Csound build, or a -library instalation directory (customisable) on LINUX. These are: - -- LINUX: depends on both `CMAKE_INSTALL_PREFIX` and `USE_LIB64`. It is then installed in: - * if `USE_LIB64=1` then to - * for doubles: `${CSOUND_INSTALL_PREFIX}/lib64/csound/plugins64-${APIVERSION}` - * for floats: `${CSOUND_INSTALL_PREFIX}/lib64/csound/plugins-${APIVERSION}` (floats)` - * if `USE_LIB64=0` then to - * for doubles: `${CSOUND_INSTALL_PREFIX}/lib/csound/plugins64-${APIVERSION}` - * for floats: `${CSOUND_INSTALL_PREFIX}/lib/csound/plugins-${APIVERSION}` - -- MACOS: - * For doubles: `$HOME/Library/csound/${APIVERSION}/plugins64` - * For floats: `$HOME/Library/csound/${APIVERSION}/plugins` -- Windows: - * For doubles: `%LOCALAPPDATA%\csound\${APIVERSION}\plugins64` - * For floats: `%LOCALAPPDATA%\csound\${APIVERSION}\plugins` - - -Build Instructions for Linux and MacOS ---- - -The build requires Csound to be installed, as well as CMake. With this -in place, you can do : - -``` -$ git clone https://github.com/csound/plugins.git -$ cd plugins -$ mkdir build -$ cd build -$ cmake ../ -$ make -``` - -By default, all the plugins are built. If one wants to exclude a -plugin from the build process, one can pass an option to the cmake command. -The options are `BUILD_CHUA_OPCODES`, `BUILD_CUDA_OPCODES`, -`BUILD_DSSI_OPCODES`, `BUILD_OPENCL_OPCODES`, `BUILD_FAUST_OPCODES`, -`BUILD_FLUID_OPCODES`, `BUILD_IMAGE_OPCODES`, `BUILD_HDF5_OPCODES`, -`BUILD_LINEAR_ALGEBRA_OPCODES`, `BUILD_P5GLOVE_OPCODES`, `BUILD_STK_OPCODES`, -`BUILD_WIIMOTE_OPCODES`, `BUILD_WEBSOCKET_OPCODE` and -`BUILD_PYTHON_OPCODES`. For example, to -exclude the chua plugin, the `cmake` command would be: - -``` -$ cmake -DBUILD_CHUA_OPCODES=OFF ../ -``` - - -To install the opcodes you have built - -``` -$ make install -``` - -Depending on your permissions, you might need to prepend `sudo` to -these commands. After the first build the plugins can be updated with - -``` -$ git pull -$ make -$ make install -``` - -using `sudo` in the last step if raised permissions are needed. On -Linux, the installation location can be set with the relevant CMake -variables as indicated above. - -Csound Location ------------- -CMake will normally find the installed Csound headers (and library) -automatically. However, if your Csound headers and library are not -placed in the usual locations, you can use the following CMake option variables -to tell CMake where they are: - -``` -CSOUND_INCLUDE_DIR_HINT -``` -and - -``` -CSOUND_LIBRARY_DIR_HINT diff --git a/7.x/cmake/CompilerOptimizations.cmake b/7.x/cmake/CompilerOptimizations.cmake deleted file mode 100644 index 5888c36b..00000000 --- a/7.x/cmake/CompilerOptimizations.cmake +++ /dev/null @@ -1,53 +0,0 @@ - -check_c_compiler_flag(-ftree-vectorize HAS_TREE_VECTORIZE) -check_cxx_compiler_flag(-ftree-vectorize HAS_CXX_TREE_VECTORIZE) -if (HAS_TREE_VECTORISE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftree-vectorize") -endif() -if (HAS_CXX_TREE_VECTORISE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftree-vectorize") -endif() - - -check_c_compiler_flag(-ffast-math HAS_FAST_MATH) -check_cxx_compiler_flag(-ffast-math HAS_CXX_FAST_MATH) -if (HAS_FAST_MATH AND NOT MINGW) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffast-math") -endif() -if (HAS_CXX_FAST_MATH AND NOT MINGW) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math") -endif() - - - -if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") -check_c_compiler_flag(-mfpmath=sse HAS_FPMATH_SSE) -check_cxx_compiler_flag(-mfpmath=sse HAS_CXX_FPMATH_SSE) - if (HAS_FPMATH_SSE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpmath=sse") -endif() -if (HAS_CXX_FPMATH_SSE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=sse") -endif() - -endif() - - -check_c_compiler_flag(-msse2 HAS_SSE2) -check_cxx_compiler_flag(-msse2 HAS_CXX_SSE2) - if (HAS_SSE2 AND NOT IOS AND NOT WASM) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2") -endif() -if (HAS_CXX_SSE2 AND NOT IOS AND NOT WASM) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2") -endif() - - -check_c_compiler_flag(-fomit-frame-pointer HAS_OMIT_FRAME_POINTER) -check_cxx_compiler_flag(-fomit-frame-pointer HAS_CXX_OMIT_FRAME_POINTER) -if (HAS_OMIT_FRAME_POINTER) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer") -endif() -if (HAS_CXX_OMIT_FRAME_POINTER) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer") -endif() diff --git a/7.x/cmake/Modules/FindEIGEN3.cmake b/7.x/cmake/Modules/FindEIGEN3.cmake deleted file mode 100644 index e4e2ed8d..00000000 --- a/7.x/cmake/Modules/FindEIGEN3.cmake +++ /dev/null @@ -1,100 +0,0 @@ -# - Try to find Eigen3 lib -# -# This module supports requiring a minimum version, e.g. you can do -# find_package(Eigen3 3.1.2) -# to require version 3.1.2 or newer of Eigen3. -# -# Once done this will define -# -# EIGEN3_FOUND - system has eigen lib with correct version -# EIGEN3_INCLUDE_DIR - the eigen include directory -# EIGEN3_VERSION - eigen version -# -# This module reads hints about search locations from -# the following enviroment variables: -# -# EIGEN3_ROOT -# EIGEN3_ROOT_DIR - -# Copyright (c) 2006, 2007 Montel Laurent, -# Copyright (c) 2008, 2009 Gael Guennebaud, -# Copyright (c) 2009 Benoit Jacob -# Redistribution and use is allowed according to the terms of the 2-clause BSD license. - -if(NOT Eigen3_FIND_VERSION) - if(NOT Eigen3_FIND_VERSION_MAJOR) - set(Eigen3_FIND_VERSION_MAJOR 2) - endif(NOT Eigen3_FIND_VERSION_MAJOR) - if(NOT Eigen3_FIND_VERSION_MINOR) - set(Eigen3_FIND_VERSION_MINOR 91) - endif(NOT Eigen3_FIND_VERSION_MINOR) - if(NOT Eigen3_FIND_VERSION_PATCH) - set(Eigen3_FIND_VERSION_PATCH 0) - endif(NOT Eigen3_FIND_VERSION_PATCH) - - set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}") -endif(NOT Eigen3_FIND_VERSION) - -macro(_eigen3_check_version) - file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header) - - string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}") - set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}") - string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}") - set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}") - string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}") - set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}") - - set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION}) - if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) - set(EIGEN3_VERSION_OK FALSE) - else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) - set(EIGEN3_VERSION_OK TRUE) - endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) - - if(NOT EIGEN3_VERSION_OK) - - message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, " - "but at least version ${Eigen3_FIND_VERSION} is required") - endif(NOT EIGEN3_VERSION_OK) -endmacro(_eigen3_check_version) - -if (EIGEN3_INCLUDE_DIR) - - # in cache already - _eigen3_check_version() - set(EIGEN3_FOUND ${EIGEN3_VERSION_OK}) - -else (EIGEN3_INCLUDE_DIR) - - # search first if an Eigen3Config.cmake is available in the system, - # if successful this would set EIGEN3_INCLUDE_DIR and the rest of - # the script will work as usual - find_package(Eigen3 ${Eigen3_FIND_VERSION} NO_MODULE QUIET) - - - if(NOT EIGEN3_INCLUDE_DIR) - find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library - HINTS - ENV EIGEN3_ROOT - ENV EIGEN3_ROOT_DIR - PATHS - ${CMAKE_INSTALL_PREFIX}/include - /usr/local/include - ${CMAKE_INSTALL_PREFIX} - $ENV{HOME}/include/ - PATH_SUFFIXES eigen3 eigen Eigen - ) - endif(NOT EIGEN3_INCLUDE_DIR) - - if(EIGEN3_INCLUDE_DIR) - _eigen3_check_version() - endif(EIGEN3_INCLUDE_DIR) - - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) - - mark_as_advanced(EIGEN3_INCLUDE_DIR) - -endif(EIGEN3_INCLUDE_DIR) - diff --git a/7.x/cmake/Modules/FindFLUIDSYNTH.cmake b/7.x/cmake/Modules/FindFLUIDSYNTH.cmake deleted file mode 100644 index 152604de..00000000 --- a/7.x/cmake/Modules/FindFLUIDSYNTH.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# - Find fluidsynth -# Find the native fluidsynth includes and library -# -# FLUIDSYNTH_INCLUDE_DIR - where to find fluidsynth.h -# FLUIDSYNTH_LIBRARIES - List of libraries when using fluidsynth. -# FLUIDSYNTH_FOUND - True if fluidsynth found. - -if (FLUIDSYNTH_INCLUDE_DIR AND FLUIDSYNTH_LIBRARIES) - # Already in cache, be silent - set (FLUIDSYNTH_FIND_QUIETLY TRUE) -endif () - -if(APPLE) - find_path(FLUIDSYNTH_INCLUDE_DIR fluidsynth.h HINTS - /Library/Frameworks/FluidSynth.framework/Headers - ${FLUIDSYNTH_INCLUDE_DIR_HINT}) -else() - find_path (FLUIDSYNTH_INCLUDE_DIR fluidsynth.h) -endif() - -if(APPLE) - find_library(FLUIDSYNTH_LIBRARIES NAMES FluidSynth HINTS - /Library/Frameworks/FluidSynth.framework/ - ${FLUIDSYNTH_LIBRARY_DIR_HINT}) -else() - find_library (FLUIDSYNTH_LIBRARIES NAMES fluidsynth libfluidsynth) -endif() - -mark_as_advanced (FLUIDSYNTH_LIBRARIES FLUIDSYNTH_INCLUDE_DIR) - -# handle the QUIETLY and REQUIRED arguments and set FLUIDSYNTH_FOUND to TRUE if -# all listed variables are TRUE -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(FLUIDSYNTH DEFAULT_MSG FLUIDSYNTH_LIBRARIES FLUIDSYNTH_INCLUDE_DIR) diff --git a/7.x/cmake/Modules/FindLAME.cmake b/7.x/cmake/Modules/FindLAME.cmake deleted file mode 100644 index 9a637529..00000000 --- a/7.x/cmake/Modules/FindLAME.cmake +++ /dev/null @@ -1,20 +0,0 @@ -# - Find LAME -# Find the native LAME includes and library -# -# LAME_INCLUDE_DIR - where to find lame.h -# LAME_LIBRARY - lame library -# LAME_FOUND - lame found - -if (LAME_INCLUDE_DIR AND LAME_LIBRARY) - # Already in cache, be silent - set (LAME_FIND_QUIETLY TRUE) -endif () - -find_path (LAME_INCLUDE_DIR lame/lame.h HINTS /usr/local/include) -find_library (LAME_LIBRARY NAMES mp3lame libmp3lame HINTS /usr/local/lib) -mark_as_advanced (LAME_LIBRARIES LAME_INCLUDE_DIR) - -# handle the QUIETLY and REQUIRED arguments and set LAME_FOUND to TRUE if -# all listed variables are TRUE -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LAME DEFAULT_MSG LAME_LIBRARY LAME_INCLUDE_DIR) diff --git a/7.x/cmake/Modules/FindSTK.cmake b/7.x/cmake/Modules/FindSTK.cmake deleted file mode 100644 index 1d889b01..00000000 --- a/7.x/cmake/Modules/FindSTK.cmake +++ /dev/null @@ -1,19 +0,0 @@ -# Try to find the STK library. -# Once done this will define: -# STK_FOUND - System has the STK library. -# STK_INCLUDE_DIRS - The STK include directories. -# STK_LIBRARIES - The libraries needed to use the STK. - -find_path(STK_INCLUDE_DIR Stk.h PATH_SUFFIXES stk HINTS "${STK_INCLUDE_DIR_HINT}") -find_library(STK_LIBRARY NAMES stk HINTS "${STK_LIBRARY_DIR_HINT}") - -set(STK_INCLUDE_DIRS ${STK_INCLUDE_DIR}) -set(STK_LIBRARIES ${STK_LIBRARY} ) - -include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set STK_FOUND to TRUE -# if all listed variables are TRUE -find_package_handle_standard_args(STK DEFAULT_MSG - STK_LIBRARY STK_INCLUDE_DIR) - -mark_as_advanced(STK_INCLUDE_DIR STK_LIBRARY) diff --git a/7.x/src/p5glove/libp5glove/macosx_usb_hid.h b/7.x/src/p5glove/libp5glove/macosx_usb_hid.h deleted file mode 100644 index 10abb242..00000000 --- a/7.x/src/p5glove/libp5glove/macosx_usb_hid.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - Copyright (c) 2004 Tim Kreger - - Macintosh OS X USB HID I/O routines - - Created by Tim Kreger on Wed Mar 17 2004. -*/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef INCLUDED_WIN32_USB_HID_H -#define INCLUDED_WIN32_USB_HID_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* - these calls are roughly equivalent to those defined in win32_usb_hid.h -*/ - -typedef void* USBHIDHandle; - -#define INVALID_USBHIDHANDLE_VALUE (0) - - -USBHIDHandle OpenUSBHID( int index, int idVendor, int idProduct, int versionNumber, int flags ); - - -void CloseUSBHID( USBHIDHandle usbHidHandle ); - - -int ReadUSBHID( USBHIDHandle usbHidHandle, void *data, int count ); - - -#ifdef __cplusplus -} -#endif - -#endif /* INCLUDED_WIN32_USB_HID_H */ \ No newline at end of file diff --git a/7.x/src/p5glove/libp5glove/p5glove.h b/7.x/src/p5glove/libp5glove/p5glove.h deleted file mode 100644 index 55cd6e2e..00000000 --- a/7.x/src/p5glove/libp5glove/p5glove.h +++ /dev/null @@ -1,226 +0,0 @@ -/* - * $Id$ - * - * Copyright (c) 2003 Jason McMullan - * - * USB P5 Data Glove support - */ - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef P5GLOVE_H -#define P5GLOVE_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - - -typedef struct p5glove *P5Glove; - -/* Button bitmasks */ -#define P5GLOVE_BUTTON_A 1 -#define P5GLOVE_BUTTON_B 2 -#define P5GLOVE_BUTTON_C 4 - -/* IR Sensor Index */ -#define P5GLOVE_IR_WRIST_TOP 0 -#define P5GLOVE_IR_PINKY_R 1 -#define P5GLOVE_IR_PINKY_L 2 -#define P5GLOVE_IR_PALM 3 -#define P5GLOVE_IR_INDEX 4 -#define P5GLOVE_IR_THUMB_TOP 5 -#define P5GLOVE_IR_WRIST_BOT 6 -#define P5GLOVE_IR_THUMB_BOT 7 - -/* Finger Sensor Index */ -#define P5GLOVE_FINGER_INDEX 0 -#define P5GLOVE_FINGER_MIDDLE 1 -#define P5GLOVE_FINGER_RING 2 -#define P5GLOVE_FINGER_PINKY 3 -#define P5GLOVE_FINGER_THUMB 4 - -/* p5glove_open: - * Open a handle to the Nth P5 Glove. Returns NULL on error, - * and sets errno appropriately. - */ -P5Glove p5glove_open(int glove_number); - - -/* p5glove_close: - * Close an open handle to a P5 Glove. - */ -void p5glove_close(P5Glove glove); - -#define P5GLOVE_DELTA_BUTTONS 0x01 -#define P5GLOVE_DELTA_FINGERS 0x02 -#define P5GLOVE_DELTA_POSITION 0x04 -#define P5GLOVE_DELTA_ROTATION 0x08 - -/* p5glove_sample - * Retrieve a sample from the P5, before 'timeout' milliseconds - * (timeout of < 0 means forever) - * Returns the 'delta mask' on success, -1 on error, and sets - * errno to EAGAIN if it is called faster than the refresh frequency. - */ -int p5glove_sample(P5Glove glove, int timeout); - - -/* Get information about the current glove state - */ - -/* Reference LED positions (in meters) - */ -int p5glove_get_led(P5Glove glove,int led,double position[3]); - -/* Button states - */ -int p5glove_get_buttons(P5Glove glove,uint32_t *button_mask); - -/* Finger flex - * (0.0 - unclenched, 1.0 - clenched) - */ -int p5glove_get_finger(P5Glove glove,int finger,double *clench); - -/* Current glove position (in meters) - */ -int p5glove_get_position(P5Glove glove,double position[3]); - -/* Get Axis/Angle rotation information (angle is in degrees) - */ -int p5glove_get_rotation(P5Glove glove,double *angle,double axis[3]); - - -void p5glove_begin_calibration(P5Glove glove); -void p5glove_end_calibration(P5Glove glove); - -int p5glove_get_mouse_mode(P5Glove glove); -void p5glove_mouse_mode_on(P5Glove glove); -void p5glove_mouse_mode_off(P5Glove glove); - -/* Inline helpers */ - -/* Distance between two points */ -static inline double p5glove_dist(const double a[3],const double b[3]) -{ - double w = 0.0; - int i; - - for (i = 0; i < 3; i++) - w += (a[i]-b[i])*(a[i]-b[i]); - - return sqrt(w); -} - -/* Cross product of two vectors */ -static inline void p5glove_cross(const double v1[3],const double v2[3],double res[3]) -{ - res[0]=v1[1]*v2[2]-v1[2]*v2[1]; - res[1]=v1[2]*v2[0]-v1[0]*v2[2]; - res[2]=v1[0]*v2[1]-v1[1]*v2[0]; -} - -/* Optimized for our use. We know the last row and last column are all zeros, - * except for [3][3]=1. - */ -static inline void p5glove_vec_mat(const double vec[3],double mat[4][4],double res[3]) -{ - int r,c; - - for (r=0; r < 3; r++) { - res[r]=0.0; - for (c=0; c < 3; c++) - res[r] += vec[c]*mat[c][r]; - } -} - -static inline double p5glove_dot(const double a[3],const double b[3]) -{ - double res = 0.0; - int i; - - for (i=0;i < 3; i++) - res += a[i]*b[i]; - - return res; -} - -/* This is safe to call with v==res - */ -static inline void p5glove_normal(const double v[3],double res[3]) -{ - double tmp=0.0; - int i; - - for (i=0; i < 3; i++) { - tmp += v[i]*v[i]; - } - - tmp=sqrt(tmp); - - for (i=0; i < 3; i++) - res[i] = v[i] / tmp; -} - -/* Get the plane normal of three points */ -static inline void p5glove_plane(const double p1[3],const double p2[3],const double p3[3],double xyz[3]) -{ - double v1[3],v2[3]; - - v1[0]=p1[0]-p2[0]; - v1[1]=p1[1]-p2[1]; - v1[2]=p1[2]-p2[2]; - - v2[0]=p3[0]-p2[0]; - v2[1]=p3[1]-p2[1]; - v2[2]=p3[2]-p2[2]; - - p5glove_cross(v1,v2,xyz); - - if (xyz[0]==0.0 && xyz[1]==0.0 && xyz[2]==0.0) - xyz[1]=1.0; - - p5glove_normal(xyz,xyz); -} - -/* Angle of three points */ -static inline double p5glove_angle(const double p1[3],const double p2[3],const double p3[3]) -{ - double v1[3],v2[3]; - - v1[0]=p1[0]-p2[0]; - v1[1]=p1[1]-p2[1]; - v1[2]=p1[2]-p2[2]; - - v2[0]=p3[0]-p2[0]; - v2[1]=p3[1]-p2[1]; - v2[2]=p3[2]-p2[2]; - - p5glove_normal(v1,v1); - p5glove_normal(v2,v2); - - return acos(p5glove_dot(v1,v2)); -} - - -#ifdef __cplusplus -} -#endif - -#endif /* P5GLOVE_H */ diff --git a/7.x/src/p5glove/libp5glove/usb_hid.h b/7.x/src/p5glove/libp5glove/usb_hid.h deleted file mode 100644 index 1ba2e6de..00000000 --- a/7.x/src/p5glove/libp5glove/usb_hid.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - Copyright (c) 2004 Ross Bencina - Copyright (c) 2004 Jason McMullan - - USB/HID I/O routines -*/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef USB_HID_H -#define USB_HID_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct USBHID_struct *USBHID; - -#define INVALID_USBHID_VALUE (0) - - -#define SELECT_VENDOR_ID_FLAG (0x01) -#define SELECT_PRODUCT_ID_FLAG (0x02) -#define SELECT_VERSION_NUMBER_FLAG (0x04) - - -/* - Open the indexth USBHID device which match the delection criteria. The - selection criteria may be any combination of vendor id, product id and - version number as specified by the flags parameter. - - Returns an open handle on success, or INVALID_USBHIDHANDLE if an error - occurred. -*/ -USBHID OpenUSBHID( int index, int vendorId, int productId, int versionNumber, int flags ); - - -/* - Close a USB HID handle previously opened with OpenUSBHID() -*/ -void CloseUSBHID( USBHID handle ); - - -/* - Read count bytes from the USB HID into dest. Returns the number of bytes - read. This routine reads from the Kernel HID ring buffer, if it is no called - frequently enough the data returned may lag behind the latest HID reports - from the device. - - HidD_GetInputReport will read the most recent report, but is only - implemented on Windows XP. -*/ -int ReadUSBHID( USBHID handle, void *dest, int count ); - - -int SetUSBHIDFeature( USBHID handle, char *report, int count ); - -int GetUSBHIDFeature( USBHID handle, char *report, int count ); - - -#ifdef __cplusplus -} -#endif - -#endif /* USB_HID_H */ diff --git a/7.x/src/p5glove/libp5glove/usb_hid_libusb.c b/7.x/src/p5glove/libp5glove/usb_hid_libusb.c deleted file mode 100644 index 3f636631..00000000 --- a/7.x/src/p5glove/libp5glove/usb_hid_libusb.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - Copyright (c) 2004 Jason McMullan - - USB/HID I/O routines -*/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include - -#include "config.h" - -#define USBHID_struct usb_dev_handle -#include "usb_hid.h" - -static int timeout = 1000; - -/* - Open the indexth USBHID device which match the delection criteria. The - selection criteria may be any combination of vendor id, product id and - version number as specified by the flags parameter. - - Returns an open handle on success, or INVALID_USBHIDHANDLE if an error - occurred. -*/ -USBHID OpenUSBHID( int index, int vendorId, int productId, int versionNumber, int flags ) -{ - struct usb_bus *bus; - struct usb_device *dev; - struct usb_dev_handle *usb = NULL; - int err,i=0; - - usb_init(); - - usb_find_busses(); - usb_find_devices(); - - for (bus = usb_get_busses(); bus != NULL; bus = bus->next) { - for (dev = bus->devices; dev != NULL; dev = dev->next) { - if (dev->descriptor.idVendor != vendorId || - dev->descriptor.idProduct != productId) - continue; - - if (i < index) - continue; - - usb = usb_open(dev); - if (usb == NULL) - continue; - - err=usb_claim_interface(usb,1); - if (err < 0) { - fprintf(stderr,"Can't claim P5 glove interface: %s\n",strerror(errno)); - usb_close(usb); - return NULL; - } - - break; - } - if (usb != NULL) - break; - } - - return usb; -} - - -/* - Close a USB HID handle previously opened with OpenUSBHID() -*/ -void CloseUSBHID( USBHID usb ) -{ - usb_release_interface(usb,1); - usb_close(usb); -} - - -/* - Read count bytes from the USB HID into dest. Returns the number of bytes - read. This routine reads from the Kernel HID ring buffer, if it is no called - frequently enough the data returned may lag behind the latest HID reports - from the device. - - HidD_GetInputReport will read the most recent report, but is only - implemented on Windows XP. -*/ -#ifndef HAVE_USB_INTERRUPT_READ -# define usb_read(usb,ep,data,len,tm) usb_bulk_read(usb,ep,data,len,tm) -# define usb_clear_halt(usb,ep) usb_resetep(usb,ep) -#else -//# define usb_read(usb,ep,data,len,tm) usb_get_input(usb,1,data,len) -# define usb_read(usb,ep,data,len,tm) usb_interrupt_read(usb,ep,data,len,tm) -#endif - -int ReadUSBHID( USBHID usb, void *dest, int count ) -{ - return usb_read(usb, 0x81, dest, count, timeout); -} - - -int usb_get_input(USBHID udev, unsigned char *report, int ReportSize) -{ - int err; -retry: - err=usb_control_msg(udev, - USB_ENDPOINT_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE, - 0x01, /* HID_REPORT_GET */ - (report[0]&0xf) | (0x01<<8), /* HID_REPORT_TYPE_INPUT */ - 1, report, ReportSize, timeout); - if (err == -EPIPE) - goto retry; - return err; -} - - -int usb_set_output(USBHID udev, unsigned char *report, int ReportSize ) -{ - return usb_control_msg(udev, - USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE, - 0x09, /* HID_REPORT_SET = 0x09*/ - (report[0]&0xf) | (0x02<<8), /* HID_REPORT_TYPE_OUPUT */ - 1, report, ReportSize, timeout); -} - -int GetUSBHIDFeature( USBHID udev, char *report, int count ) -{ - int err; -retry: - err=usb_control_msg(udev, - USB_ENDPOINT_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE, - 0x01, /* HID_REPORT_GET */ - (report[0]&0xf) | (0x03<<8), /* HID_REPORT_TYPE_FEATURE */ - 1, report, count, timeout); - if (err == -EPIPE) - goto retry; - return err; -} - - -int SetUSBHIDFeature( USBHID udev, char *report, int count ) -{ - return usb_control_msg(udev, - USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE, - 0x09, /* HID_REPORT_SET = 0x09*/ - (report[0]&0xf) | (0x03<<8), /* HID_REPORT_TYPE_FEATURE */ - 1, report, count, timeout); -} diff --git a/7.x/src/py/CMakeLists.txt b/7.x/src/py/CMakeLists.txt deleted file mode 100644 index ab90376b..00000000 --- a/7.x/src/py/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# Build py opcodes -option(BUILD_PYTHON_OPCODES "Build the py opcodes" ON) - -if(BUILD_PYTHON_OPCODES) - find_package(Python3 COMPONENTS Interpreter Development) - check_deps(BUILD_PYTHON_OPCODES Python3_FOUND) - - set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS}) - set(PYTHON_LIBRARIES ${Python3_LIBRARIES}) - - message("-- Python include dirs: ${Python3_INCLUDE_DIRS}") - message("-- Python libraries: ${PYTHON_LIBRARIES}") - - make_plugin(py src/pythonopcodes.c) - target_include_directories(py PRIVATE ${CSOUND_INCLUDE_DIRS}) - target_include_directories(py PRIVATE ${PYTHON_INCLUDE_DIRS}) - target_link_libraries(py ${PYTHON_LIBRARIES}) -endif() diff --git a/7.x/src/py/README.md b/7.x/src/py/README.md deleted file mode 100644 index 04e3ab2e..00000000 --- a/7.x/src/py/README.md +++ /dev/null @@ -1,14 +0,0 @@ -Python opcodes -=== - -This is the porting to Python 3.x of the Python opcodes of Csound which ran under Python 2.7 until know. -The backward compatibility is preserved for the Csound code of the orchestra, however it is not maintained -for the Python code that would be embedded in a Csound orchestra or in Csound instruments, due to the lack -of backward compatibility between Python 3.x and Python 2.7. - -Python 2.7 will not be maintained past 2020. The -[official porting guide](https://docs.python.org/3/howto/pyporting.html) has advice for -running Python 2 code in Python 3. - -To build these opcodes, you will need to install Python from -[www.python.org](www.python.org), or the devel package (on linux). diff --git a/7.x/src/py/examples/cabrera/pythonmarkov.csd b/7.x/src/py/examples/cabrera/pythonmarkov.csd deleted file mode 100644 index 0c701f51..00000000 --- a/7.x/src/py/examples/cabrera/pythonmarkov.csd +++ /dev/null @@ -1,82 +0,0 @@ - - - -odac - - - -sr=44100 -ksmps=128 -nchnls=2 - -pyinit - -; Python script to define probabilities for each note as lists within a list -; Definition of the get_new_note function which randomly generates a new -; note based on the probabilities of each note occuring. -; Each note list must total 1, or there will be problems! - -pyruni {{c = [0.1, 0.2, 0.05, 0.4, 0.25] -d = [0.4, 0.1, 0.1, 0.2, 0.2] -e = [0.2, 0.35, 0.05, 0.4, 0] -g = [0.7, 0.1, 0.2, 0, 0] -a = [0.1, 0.2, 0.05, 0.4, 0.25] - -markov = [c, d, e, g, a] - -import random - -random.seed() - -def get_new_note(previous_note): - number = random.random() - accum = 0 - i = 0 - while accum < number: - accum = accum + markov[int(previous_note)][int(i)] - i = i + 1 - return i - 1.0 - -}} - - - -instr 1 ;Markov chain reader and note spawner -;p4 = frequency of note generation -;p5 = octave -ioct init p5 -klastnote init 0 ;Used to remember last note played (start at first note of scale) -ktrig metro p4 ;generate a trigger with frequency p4 -knewnote pycall1t ktrig, "get_new_note", klastnote ;get new note from chain -schedkwhen ktrig, 0, 10, 2, 0, 0.2, knewnote, ioct ;launch note on instrument 2 -klastnote = knewnote ;New note is now the old note -endin - - -instr 2 ;A simple sine wave instrument -;p4 = note to be played -;p5 = octave -ioct init p5 -ipclass table p4, 2 -ipclass = ioct + (ipclass / 100) ; Pitch class of the note -ifreq = cpspch(ipclass) ;Note frequency in Hertz -aenv linen 6000, 0.05, p3, 0.1 ;Amplitude envelope -aout oscil aenv, ifreq , 1 ;Simple oscillator -outs aout, aout -endin - - - - - -f 1 0 2048 10 1 ;sine wave -f 2 0 8 -2 0 2 4 7 9 ;Pitch classes for pentatonic scale - -; frequency of Octave of -; note generation melody -i 1 0 30 3 7 -i 1 5 25 6 9 -i 1 10 20 7.5 10 -i 1 15 15 1 8 - - - \ No newline at end of file diff --git a/7.x/src/py/examples/embeddedCtcsound.csd b/7.x/src/py/examples/embeddedCtcsound.csd deleted file mode 100644 index 87859e28..00000000 --- a/7.x/src/py/examples/embeddedCtcsound.csd +++ /dev/null @@ -1,38 +0,0 @@ - - - -odac - - - -sr = 48000 -ksmps = 100 -nchnls = 2 - -pyinit ;Start python interpreter - -pyruni {{ -import ctcsound -import sys - -# Get an opaque pointer to the running Csound instance -# and print Python version number -p = _CSOUND_ -print("\\n --> Python version number: {}\\n".format(sys.version_info[0])) -# Create an object called cs from the ctcsound.Csound class -# using the opaque pointer to the Csound instance -cs = ctcsound.Csound(pointer_=p) -}} - -instr 1 - ; Use the cs python object - pyruni {{ -print("\\n --> Sample Rate: {}, Control Rate: {}\\n".format(cs.sr(), cs.kr())) - }} -endin - - - -i1 0 1 - - - diff --git a/7.x/src/py/examples/ievent.sco b/7.x/src/py/examples/ievent.sco deleted file mode 100644 index 65bf76f7..00000000 --- a/7.x/src/py/examples/ievent.sco +++ /dev/null @@ -1 +0,0 @@ -f0 60 diff --git a/7.x/src/py/examples/pyassign.orc b/7.x/src/py/examples/pyassign.orc deleted file mode 100644 index 59d1ef43..00000000 --- a/7.x/src/py/examples/pyassign.orc +++ /dev/null @@ -1,13 +0,0 @@ -sr=44100 -kr=4410 -ksmps=10 -nchnls=1 - -pyinit - -instr 1 - - k1 rand 1000 - pyassign "a", k1 - pyrun "print(a)" -endin diff --git a/7.x/src/py/examples/pyassign.sco b/7.x/src/py/examples/pyassign.sco deleted file mode 100644 index d14b738e..00000000 --- a/7.x/src/py/examples/pyassign.sco +++ /dev/null @@ -1 +0,0 @@ -i1 0 0.01 diff --git a/7.x/src/py/examples/pycall1.orc b/7.x/src/py/examples/pycall1.orc deleted file mode 100644 index 50be70bb..00000000 --- a/7.x/src/py/examples/pycall1.orc +++ /dev/null @@ -1,31 +0,0 @@ -sr=44100 -kr=4410 -ksmps=10 -nchnls=1 - -giSinusoid ftgen 0, 0, 8192, 10, 1 - -pyinit - -pyruni {{ -import random - -pool = [(1 + i/10.0) ** 1.2 for i in range(100)] - -def get_number_from_pool(n, p): - if random.random() < p: - i = int(random.random() * len(pool)) - pool[i] = n - - return random.choice(pool) -}} - -instr 1 - - k1 oscil 1, 3, giSinusoid - - k2 pycall1 "get_number_from_pool", k1 + 2, p4 - - printk 0.01, k2 - -endin diff --git a/7.x/src/py/examples/pycall1.sco b/7.x/src/py/examples/pycall1.sco deleted file mode 100644 index a81415b5..00000000 --- a/7.x/src/py/examples/pycall1.sco +++ /dev/null @@ -1 +0,0 @@ -i1 0 10 0.01 diff --git a/7.x/src/py/examples/pycall2.orc b/7.x/src/py/examples/pycall2.orc deleted file mode 100644 index c289ddc8..00000000 --- a/7.x/src/py/examples/pycall2.orc +++ /dev/null @@ -1,35 +0,0 @@ -sr=44100 -kr=4410 -ksmps=10 -nchnls=1 - -giSinusoid ftgen 0, 0, 8192, 10, 1 - -pyinit - -pyruni {{ -import random - -class GetNumberFromPool: - def __init__(self, e=1.2, a=1.0, f=0.1, N=100): - self.pool = [(a + i*f) ** e for i in range(N)] - - def __call__(self, n, p): - if random.random() < p: - i = int(random.random() * len(self.pool)) - self.pool[i] = n - - return random.choice(self.pool) - -get_number_from_pool = GetNumberFromPool() -}} - -instr 1 - - k1 oscil 1, 3, giSinusoid - - k2 pycall1 "get_number_from_pool", k1 + 2, p4 - - printk 0.01, k2 - -endin diff --git a/7.x/src/py/examples/pycall2.sco b/7.x/src/py/examples/pycall2.sco deleted file mode 100644 index a81415b5..00000000 --- a/7.x/src/py/examples/pycall2.sco +++ /dev/null @@ -1 +0,0 @@ -i1 0 10 0.01 diff --git a/7.x/src/py/examples/pycall3.orc b/7.x/src/py/examples/pycall3.orc deleted file mode 100644 index a090327b..00000000 --- a/7.x/src/py/examples/pycall3.orc +++ /dev/null @@ -1,57 +0,0 @@ -sr=44100 -kr=4410 -ksmps=10 -nchnls=1 - -pyinit - -pyruni {{ -def f0(a, b, c, d, e, f, g, h): - pass - -def f1(a, b, c, d, e, f, g, h): - return a - -def f2(a, b, c, d, e, f, g, h): - return a, b - -def f3(a, b, c, d, e, f, g, h): - return a, b, c - -def f4(a, b, c, d, e, f, g, h): - return a, b, c, d - -def f5(a, b, c, d, e, f, g, h): - return a, b, c, d, e - -def f6(a, b, c, d, e, f, g, h): - return a, b, c, d, e, f - -def f7(a, b, c, d, e, f, g, h): - return a, b, c, d, e, f, g - -def f8(a, b, c, d, e, f, g, h): - return a, b, c, d, e, f, g, h -}} - -instr 1 - - pycall "f0", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1 pycall1 "f1", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2 pycall2 "f2", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2, k3 pycall3 "f3", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2, k3, k4 pycall4 "f4", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2, k3, k4, k5 pycall5 "f5", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2, k3, k4, k5, k6 pycall6 "f6", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2, k3, k4, k5, k6, k7 pycall7 "f7", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2, k3, k4, k5, k6, k7, k8 pycall8 "f8", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - - printk 0.01, k1 - printk 0.01, k2 - printk 0.01, k3 - printk 0.01, k4 - printk 0.01, k5 - printk 0.01, k6 - printk 0.01, k7 - printk 0.01, k8 -endin diff --git a/7.x/src/py/examples/pycall3.sco b/7.x/src/py/examples/pycall3.sco deleted file mode 100644 index 87b69bf1..00000000 --- a/7.x/src/py/examples/pycall3.sco +++ /dev/null @@ -1 +0,0 @@ -i1 0 0.1 diff --git a/7.x/src/py/examples/pycallt.orc b/7.x/src/py/examples/pycallt.orc deleted file mode 100644 index ac939b48..00000000 --- a/7.x/src/py/examples/pycallt.orc +++ /dev/null @@ -1,67 +0,0 @@ -sr=44100 -kr=4410 -ksmps=10 -nchnls=1 - -pyinit - -pyruni {{ -def f0(a, b, c, d, e, f, g, h): - print('f0 got', a, b, c, d, e, f, g, h) - print('f0 returning None') - -def f1(a, b, c, d, e, f, g, h): - print('f1 got', a, b, c, d, e, f, g, h) - print('f1 returning', a) - return a - -def f2(a, b, c, d, e, f, g, h): - print('f2 got', a, b, c, d, e, f, g, h) - print('f2 returning', a, b) - return a, b - -def f3(a, b, c, d, e, f, g, h): - print('f3 got', a, b, c, d, e, f, g, h) - print('f3 returning', a, b, c) - return a, b, c - -def f4(a, b, c, d, e, f, g, h): - print('f4 got', a, b, c, d, e, f, g, h) - print('f4 returning', a, b, c, d) - return a, b, c, d - -def f5(a, b, c, d, e, f, g, h): - print('f5 got', a, b, c, d, e, f, g, h) - print('f5 returning', a, b, c, d, e) - return a, b, c, d, e - -def f6(a, b, c, d, e, f, g, h): - print('f6 got', a, b, c, d, e, f, g, h) - print('f6 returning', a, b, c, d, e, f) - return a, b, c, d, e, f - -def f7(a, b, c, d, e, f, g, h): - print('f7 got', a, b, c, d, e, f, g, h) - print('f7 returning', a, b, c, d, e, f, g) - return a, b, c, d, e, f, g - -def f8(a, b, c, d, e, f, g, h): - print('f8 got', a, b, c, d, e, f, g, h) - print('f8 returning', a, b, c, d, e, f, g, h) - return a, b, c, d, e, f, g, h -}} - -instr 1 - - kt metro 1.5 - - pycallt kt, "f0", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1 pycall1t kt, "f1", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2 pycall2t kt, "f2", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2, k3 pycall3t kt, "f3", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2, k3, k4 pycall4t kt, "f4", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2, k3, k4, k5 pycall5t kt, "f5", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2, k3, k4, k5, k6 pycall6t kt, "f6", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2, k3, k4, k5, k6, k7 pycall7t kt, "f7", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 - k1, k2, k3, k4, k5, k6, k7, k8 pycall8t kt, "f8", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 -endin diff --git a/7.x/src/py/examples/pycallt.sco b/7.x/src/py/examples/pycallt.sco deleted file mode 100644 index ad27e081..00000000 --- a/7.x/src/py/examples/pycallt.sco +++ /dev/null @@ -1 +0,0 @@ -i1 0 10 diff --git a/7.x/src/py/examples/pyeval.orc b/7.x/src/py/examples/pyeval.orc deleted file mode 100644 index 37988f93..00000000 --- a/7.x/src/py/examples/pyeval.orc +++ /dev/null @@ -1,15 +0,0 @@ -sr=44100 -kr=4410 -ksmps=10 -nchnls=1 - - pyinit - - pyruni "from random import random" - -instr 1 - - pyrun "a = random()" - k1 pyeval "a" - printk 0.1, k1 -endin diff --git a/7.x/src/py/examples/pyeval.sco b/7.x/src/py/examples/pyeval.sco deleted file mode 100644 index dd813c63..00000000 --- a/7.x/src/py/examples/pyeval.sco +++ /dev/null @@ -1 +0,0 @@ -i1 0 0.5 diff --git a/7.x/src/py/examples/pyexec.orc b/7.x/src/py/examples/pyexec.orc deleted file mode 100644 index 6e9674cc..00000000 --- a/7.x/src/py/examples/pyexec.orc +++ /dev/null @@ -1,19 +0,0 @@ -sr=44100 -kr=4410 -ksmps=10 -nchnls=1 - - pyinit - - pyruni "import random" - - pyexeci "pyexec1.py" - -instr 1 - - pyexec "pyexec2.py" - - pylexeci "pyexec3.py" - pylexec "pyexec4.py" - -endin diff --git a/7.x/src/py/examples/pyexec.sco b/7.x/src/py/examples/pyexec.sco deleted file mode 100644 index 81d41dd0..00000000 --- a/7.x/src/py/examples/pyexec.sco +++ /dev/null @@ -1,2 +0,0 @@ -i1 0 0.01 -i1 0 0.01 diff --git a/7.x/src/py/examples/pyexec1.py b/7.x/src/py/examples/pyexec1.py deleted file mode 100644 index b2de022a..00000000 --- a/7.x/src/py/examples/pyexec1.py +++ /dev/null @@ -1,12 +0,0 @@ -import time, os - -print() -print("Welcome to Csound!") - -try: - s = ', %s?' % os.getenv('USER') -except: - s = '?' - -print('What sound do you want to hear today%s' % s) -answer = input('--> ') diff --git a/7.x/src/py/examples/pyexec2.py b/7.x/src/py/examples/pyexec2.py deleted file mode 100644 index ee6e4397..00000000 --- a/7.x/src/py/examples/pyexec2.py +++ /dev/null @@ -1 +0,0 @@ -print('your answer is "%s"' % answer) diff --git a/7.x/src/py/examples/pyexec3.py b/7.x/src/py/examples/pyexec3.py deleted file mode 100644 index ec0e305c..00000000 --- a/7.x/src/py/examples/pyexec3.py +++ /dev/null @@ -1 +0,0 @@ -message = 'a private random number: %f' % random.random() diff --git a/7.x/src/py/examples/pyexec4.py b/7.x/src/py/examples/pyexec4.py deleted file mode 100644 index 923bd256..00000000 --- a/7.x/src/py/examples/pyexec4.py +++ /dev/null @@ -1 +0,0 @@ -print(message) diff --git a/7.x/src/py/examples/pyexect.orc b/7.x/src/py/examples/pyexect.orc deleted file mode 100644 index 75b4805b..00000000 --- a/7.x/src/py/examples/pyexect.orc +++ /dev/null @@ -1,25 +0,0 @@ -sr=44100 -kr=4410 -ksmps=10 -nchnls=1 - -pyinit - -instr 1 - - ktrigger1 metro 3 - ktrigger2 metro 6 - ktrigger3 metro 10 - ktrigger4 metro 0.5 - - pyexect ktrigger1, "pyexect1.py" - pyexect ktrigger2, "pyexect2.py" - pyexect ktrigger3, "pyexect3.py" - - pylexect ktrigger3 + ktrigger1, "pyexect4.py" - - a1 rand 5000 - - out a1 - -endin diff --git a/7.x/src/py/examples/pyexect.sco b/7.x/src/py/examples/pyexect.sco deleted file mode 100644 index 90df1b0c..00000000 --- a/7.x/src/py/examples/pyexect.sco +++ /dev/null @@ -1,2 +0,0 @@ -i1 0 5 -i1 0 5 diff --git a/7.x/src/py/examples/pyrun.csd b/7.x/src/py/examples/pyrun.csd deleted file mode 100644 index 0a0d180c..00000000 --- a/7.x/src/py/examples/pyrun.csd +++ /dev/null @@ -1,31 +0,0 @@ - - - -odac - - -sr=44100 -kr=4410 -ksmps=10 -nchnls=1 - -pyinit - -pyruni "import random" - -instr 1 - ; This message is stored in the main namespace - ; and is the same for every instance - pyruni "message = 'a global random number: %f' % random.random()" - pyrun "print(message)" - - ; This message is stored in the private namespace - ; and is different for different instances - pylruni "message = 'a private random number: %f' % random.random()" - pylrun "print(message)" - -endin - - -i1 0 0.01 - - diff --git a/7.x/src/py/examples/pyrun.orc b/7.x/src/py/examples/pyrun.orc deleted file mode 100644 index 21413407..00000000 --- a/7.x/src/py/examples/pyrun.orc +++ /dev/null @@ -1,20 +0,0 @@ -sr=44100 -kr=4410 -ksmps=10 -nchnls=1 - -pyinit - -pyruni "import random" - -instr 1 - ; This message is stored in the main namespace - ; and is the same for every instance - pyruni "message = 'a global random number: %f' % random.random()" - pyrun "print(message)" - - ; This message is stored in the private namespace - ; and is different for different instances - pylruni "message = 'a private random number: %f' % random.random()" - pylrun "print(message)" -endin diff --git a/7.x/src/py/examples/pyrun.sco b/7.x/src/py/examples/pyrun.sco deleted file mode 100644 index 87b69bf1..00000000 --- a/7.x/src/py/examples/pyrun.sco +++ /dev/null @@ -1 +0,0 @@ -i1 0 0.1 diff --git a/7.x/src/py/examples/pyrunt.orc b/7.x/src/py/examples/pyrunt.orc deleted file mode 100644 index ffc4df11..00000000 --- a/7.x/src/py/examples/pyrunt.orc +++ /dev/null @@ -1,23 +0,0 @@ -sr=44100 -kr=4410 -ksmps=10 -nchnls=1 - -pyinit - -instr 1 - - ktrigger1 metro 3 - ktrigger2 metro 6 - ktrigger3 metro 10 - - pyrunt ktrigger1, "print('zum')" - pyrunt ktrigger2, "print('pa')" - pyrunt ktrigger3, "print('zi')" - - pylrunt ktrigger3 + ktrigger1, "print('zut')" - - a1 rand 5000 - - out a1 -endin diff --git a/7.x/src/py/examples/pyrunt.sco b/7.x/src/py/examples/pyrunt.sco deleted file mode 100644 index 90df1b0c..00000000 --- a/7.x/src/py/examples/pyrunt.sco +++ /dev/null @@ -1,2 +0,0 @@ -i1 0 5 -i1 0 5 diff --git a/7.x/src/py/src/README.md b/7.x/src/py/src/README.md deleted file mode 100644 index af366744..00000000 --- a/7.x/src/py/src/README.md +++ /dev/null @@ -1,25 +0,0 @@ -PYTHON OPCODES FOR CSOUND -=== -By Maurizio Umberto Puxeddu.
-Modified by Michael Gogins for Csound 5, 2004 July 24.
-Modified by François Pinot for using with Python 3.x, 2019 November.
- -BEFORE COMPILING ---- -To generate the source code for the Python opcodes just run the **pycall-gen.py** -and **pyx-gen.py** scripts in this directory. - -This way of doing had been broken by adding different modifications directly to -the **pycall.auto.c** and **pyx.auto.c** files. These modifications have been integrated -back into the **pycall-gen.py** and **pyx-gen.py** scripts. -So if one has to modifiy the opcodes, one should do this in the two scripts -**pycall-gen.py** and **pyx-gen.py**, and then regenerate the -opcodes files by running these scripts. - -NOTES ---- -These opcodes require the Python virtual machine to be initialized, which -can be done by putting the `pyinit` opcode in the orchestra header. - -See the [Python opcodes pages](https://csound.com/docs/manual/py.html) of the Csound manual, -and examples in the **examples** directory. diff --git a/7.x/src/py/src/pycall.auto.c b/7.x/src/py/src/pycall.auto.c deleted file mode 100644 index eb316fe1..00000000 --- a/7.x/src/py/src/pycall.auto.c +++ /dev/null @@ -1,1970 +0,0 @@ -/* - * pyx.auto.c - * - * Copyright (C) 2002 Maurizio Umberto Puxeddu, Michael Gogins - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Don't modify this file, it's automatically genetated by pyx-gen.py - */ - -static int pycall0_krate(CSOUND *csound, PYCALL0 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(result != Py_None)) { - return errMsg(p, "callable must return None"); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall0_irate(CSOUND *csound, PYCALL0 *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall0_krate(CSOUND *csound, PYCALL0 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(result != Py_None)) { - return errMsg(p, "callable must return None"); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall0i_irate(CSOUND *csound, PYCALL0 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - create_private_namespace_if_needed(&p->h); - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(result != Py_None)) { - return errMsg(p, "callable must return None"); - } - - Py_DECREF(result); - return OK; -} - -static int pycall0t_krate(CSOUND *csound, PYCALL0T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(result != Py_None)) { - return errMsg(p, "callable must return None"); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall0t_irate(CSOUND *csound, PYCALL0T *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall0t_krate(CSOUND *csound, PYCALL0T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(result != Py_None)) { - return errMsg(p, "callable must return None"); - } - - Py_DECREF(result); - return OK; -} - -static int pycall1_krate(CSOUND *csound, PYCALL1 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyFloat_Check(result))) { - return errMsg(p, "callable must return a float"); - } - else { - *p->result = PyFloat_AsDouble(result); - } - return OK; - - Py_DECREF(result); - return OK; -} - -static int pylcall1_irate(CSOUND *csound, PYCALL1 *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall1_krate(CSOUND *csound, PYCALL1 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyFloat_Check(result))) { - return errMsg(p, "callable must return a float"); - } - else { - *p->result = PyFloat_AsDouble(result); - } - return OK; - - Py_DECREF(result); - return OK; -} - -static int pylcall1i_irate(CSOUND *csound, PYCALL1 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - create_private_namespace_if_needed(&p->h); - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyFloat_Check(result))) { - return errMsg(p, "callable must return a float"); - } - else { - *p->result = PyFloat_AsDouble(result); - } - return OK; - - Py_DECREF(result); - return OK; -} - -static int pycall1t_krate(CSOUND *csound, PYCALL1T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result = p->oresult; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyFloat_Check(result))) { - return errMsg(p, "callable must return a float"); - } - else { - *p->result = PyFloat_AsDouble(result); - p->oresult = *p->result; - } - return OK; - - Py_DECREF(result); - return OK; -} - -static int pylcall1t_irate(CSOUND *csound, PYCALL1T *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall1t_krate(CSOUND *csound, PYCALL1T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result = p->oresult; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyFloat_Check(result))) { - return errMsg(p, "callable must return a float"); - } - else { - *p->result = PyFloat_AsDouble(result); - p->oresult = *p->result; - } - return OK; - - Py_DECREF(result); - return OK; -} - -static int pycall2_krate(CSOUND *csound, PYCALL2 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 2)) { - return errMsg(p, "callable must return 2 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall2_irate(CSOUND *csound, PYCALL2 *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall2_krate(CSOUND *csound, PYCALL2 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 2)) { - return errMsg(p, "callable must return 2 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall2i_irate(CSOUND *csound, PYCALL2 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - create_private_namespace_if_needed(&p->h); - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 2)) { - return errMsg(p, "callable must return 2 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - } - - Py_DECREF(result); - return OK; -} - -static int pycall2t_krate(CSOUND *csound, PYCALL2T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 2)) { - return errMsg(p, "callable must return 2 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - } - - Py_DECREF(result); - return OK; -} - -static int pylcall2t_irate(CSOUND *csound, PYCALL2T *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall2t_krate(CSOUND *csound, PYCALL2T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 2)) { - return errMsg(p, "callable must return 2 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - } - - Py_DECREF(result); - return OK; -} - -static int pycall3_krate(CSOUND *csound, PYCALL3 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 3)) { - return errMsg(p, "callable must return 3 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall3_irate(CSOUND *csound, PYCALL3 *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall3_krate(CSOUND *csound, PYCALL3 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 3)) { - return errMsg(p, "callable must return 3 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall3i_irate(CSOUND *csound, PYCALL3 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - create_private_namespace_if_needed(&p->h); - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 3)) { - return errMsg(p, "callable must return 3 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - } - - Py_DECREF(result); - return OK; -} - -static int pycall3t_krate(CSOUND *csound, PYCALL3T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - *p->result3 = p->oresult3; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 3)) { - return errMsg(p, "callable must return 3 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - p->oresult3 = *p->result3; - } - - Py_DECREF(result); - return OK; -} - -static int pylcall3t_irate(CSOUND *csound, PYCALL3T *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall3t_krate(CSOUND *csound, PYCALL3T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - *p->result3 = p->oresult3; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 3)) { - return errMsg(p, "callable must return 3 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - p->oresult3 = *p->result3; - } - - Py_DECREF(result); - return OK; -} - -static int pycall4_krate(CSOUND *csound, PYCALL4 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 4)) { - return errMsg(p, "callable must return 4 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall4_irate(CSOUND *csound, PYCALL4 *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall4_krate(CSOUND *csound, PYCALL4 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 4)) { - return errMsg(p, "callable must return 4 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall4i_irate(CSOUND *csound, PYCALL4 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - create_private_namespace_if_needed(&p->h); - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 4)) { - return errMsg(p, "callable must return 4 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - } - - Py_DECREF(result); - return OK; -} - -static int pycall4t_krate(CSOUND *csound, PYCALL4T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - *p->result3 = p->oresult3; - *p->result4 = p->oresult4; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 4)) { - return errMsg(p, "callable must return 4 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - p->oresult3 = *p->result3; - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - p->oresult4 = *p->result4; - } - - Py_DECREF(result); - return OK; -} - -static int pylcall4t_irate(CSOUND *csound, PYCALL4T *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall4t_krate(CSOUND *csound, PYCALL4T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - *p->result3 = p->oresult3; - *p->result4 = p->oresult4; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 4)) { - return errMsg(p, "callable must return 4 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - p->oresult3 = *p->result3; - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - p->oresult4 = *p->result4; - } - - Py_DECREF(result); - return OK; -} - -static int pycall5_krate(CSOUND *csound, PYCALL5 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 5)) { - return errMsg(p, "callable must return 5 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall5_irate(CSOUND *csound, PYCALL5 *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall5_krate(CSOUND *csound, PYCALL5 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 5)) { - return errMsg(p, "callable must return 5 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall5i_irate(CSOUND *csound, PYCALL5 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - create_private_namespace_if_needed(&p->h); - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 5)) { - return errMsg(p, "callable must return 5 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - } - - Py_DECREF(result); - return OK; -} - -static int pycall5t_krate(CSOUND *csound, PYCALL5T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - *p->result3 = p->oresult3; - *p->result4 = p->oresult4; - *p->result5 = p->oresult5; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 5)) { - return errMsg(p, "callable must return 5 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - p->oresult3 = *p->result3; - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - p->oresult4 = *p->result4; - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - p->oresult5 = *p->result5; - } - - Py_DECREF(result); - return OK; -} - -static int pylcall5t_irate(CSOUND *csound, PYCALL5T *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall5t_krate(CSOUND *csound, PYCALL5T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - *p->result3 = p->oresult3; - *p->result4 = p->oresult4; - *p->result5 = p->oresult5; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 5)) { - return errMsg(p, "callable must return 5 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - p->oresult3 = *p->result3; - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - p->oresult4 = *p->result4; - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - p->oresult5 = *p->result5; - } - - Py_DECREF(result); - return OK; -} - -static int pycall6_krate(CSOUND *csound, PYCALL6 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 6)) { - return errMsg(p, "callable must return 6 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall6_irate(CSOUND *csound, PYCALL6 *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall6_krate(CSOUND *csound, PYCALL6 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 6)) { - return errMsg(p, "callable must return 6 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall6i_irate(CSOUND *csound, PYCALL6 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - create_private_namespace_if_needed(&p->h); - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 6)) { - return errMsg(p, "callable must return 6 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - } - - Py_DECREF(result); - return OK; -} - -static int pycall6t_krate(CSOUND *csound, PYCALL6T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - *p->result3 = p->oresult3; - *p->result4 = p->oresult4; - *p->result5 = p->oresult5; - *p->result6 = p->oresult6; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 6)) { - return errMsg(p, "callable must return 6 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - p->oresult3 = *p->result3; - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - p->oresult4 = *p->result4; - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - p->oresult5 = *p->result5; - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - p->oresult6 = *p->result6; - } - - Py_DECREF(result); - return OK; -} - -static int pylcall6t_irate(CSOUND *csound, PYCALL6T *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall6t_krate(CSOUND *csound, PYCALL6T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - *p->result3 = p->oresult3; - *p->result4 = p->oresult4; - *p->result5 = p->oresult5; - *p->result6 = p->oresult6; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 6)) { - return errMsg(p, "callable must return 6 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - p->oresult3 = *p->result3; - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - p->oresult4 = *p->result4; - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - p->oresult5 = *p->result5; - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - p->oresult6 = *p->result6; - } - - Py_DECREF(result); - return OK; -} - -static int pycall7_krate(CSOUND *csound, PYCALL7 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 7)) { - return errMsg(p, "callable must return 7 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - *p->result7 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 6)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall7_irate(CSOUND *csound, PYCALL7 *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall7_krate(CSOUND *csound, PYCALL7 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 7)) { - return errMsg(p, "callable must return 7 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - *p->result7 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 6)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall7i_irate(CSOUND *csound, PYCALL7 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - create_private_namespace_if_needed(&p->h); - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 7)) { - return errMsg(p, "callable must return 7 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - *p->result7 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 6)); - } - - Py_DECREF(result); - return OK; -} - -static int pycall7t_krate(CSOUND *csound, PYCALL7T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - *p->result3 = p->oresult3; - *p->result4 = p->oresult4; - *p->result5 = p->oresult5; - *p->result6 = p->oresult6; - *p->result7 = p->oresult7; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 7)) { - return errMsg(p, "callable must return 7 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - p->oresult3 = *p->result3; - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - p->oresult4 = *p->result4; - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - p->oresult5 = *p->result5; - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - p->oresult6 = *p->result6; - *p->result7 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 6)); - p->oresult7 = *p->result7; - } - - Py_DECREF(result); - return OK; -} - -static int pylcall7t_irate(CSOUND *csound, PYCALL7T *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall7t_krate(CSOUND *csound, PYCALL7T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - *p->result3 = p->oresult3; - *p->result4 = p->oresult4; - *p->result5 = p->oresult5; - *p->result6 = p->oresult6; - *p->result7 = p->oresult7; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 7)) { - return errMsg(p, "callable must return 7 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - p->oresult3 = *p->result3; - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - p->oresult4 = *p->result4; - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - p->oresult5 = *p->result5; - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - p->oresult6 = *p->result6; - *p->result7 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 6)); - p->oresult7 = *p->result7; - } - - Py_DECREF(result); - return OK; -} - -static int pycall8_krate(CSOUND *csound, PYCALL8 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 8)) { - return errMsg(p, "callable must return 8 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - *p->result7 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 6)); - *p->result8 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 7)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall8_irate(CSOUND *csound, PYCALL8 *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall8_krate(CSOUND *csound, PYCALL8 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 8)) { - return errMsg(p, "callable must return 8 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - *p->result7 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 6)); - *p->result8 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 7)); - } - - Py_DECREF(result); - return OK; -} - -static int pylcall8i_irate(CSOUND *csound, PYCALL8 *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 1); - - create_private_namespace_if_needed(&p->h); - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 8)) { - return errMsg(p, "callable must return 8 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - *p->result7 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 6)); - *p->result8 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 7)); - } - - Py_DECREF(result); - return OK; -} - -static int pycall8t_krate(CSOUND *csound, PYCALL8T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - *p->result3 = p->oresult3; - *p->result4 = p->oresult4; - *p->result5 = p->oresult5; - *p->result6 = p->oresult6; - *p->result7 = p->oresult7; - *p->result8 = p->oresult8; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, 0); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 8)) { - return errMsg(p, "callable must return 8 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - p->oresult3 = *p->result3; - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - p->oresult4 = *p->result4; - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - p->oresult5 = *p->result5; - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - p->oresult6 = *p->result6; - *p->result7 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 6)); - p->oresult7 = *p->result7; - *p->result8 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 7)); - p->oresult8 = *p->result8; - } - - Py_DECREF(result); - return OK; -} - -static int pylcall8t_irate(CSOUND *csound, PYCALL8T *p) -{ - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylcall8t_krate(CSOUND *csound, PYCALL8T *p) -{ - char command[1024]; - PyObject *result; - int *py_initialize_done; - if (UNLIKELY((py_initialize_done = - csound->QueryGlobalVariable(csound, "PY_INITIALIZE")) == NULL || - *py_initialize_done == 0)) { - return NOTOK; - } - if (!*p->trigger) { - *p->result1 = p->oresult1; - *p->result2 = p->oresult2; - *p->result3 = p->oresult3; - *p->result4 = p->oresult4; - *p->result5 = p->oresult5; - *p->result6 = p->oresult6; - *p->result7 = p->oresult7; - *p->result8 = p->oresult8; - return OK; - } - - format_call_statement(command, (char*) p->function->data, - p->INOCOUNT, p->args, 2); - - result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - - if (UNLIKELY(result == NULL)) { - return pyErrMsg(p, "python exception"); - } - - if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 8)) { - return errMsg(p, "callable must return 8 values"); - } - else { - *p->result1 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 0)); - p->oresult1 = *p->result1; - *p->result2 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 1)); - p->oresult2 = *p->result2; - *p->result3 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 2)); - p->oresult3 = *p->result3; - *p->result4 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 3)); - p->oresult4 = *p->result4; - *p->result5 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 4)); - p->oresult5 = *p->result5; - *p->result6 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 5)); - p->oresult6 = *p->result6; - *p->result7 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 6)); - p->oresult7 = *p->result7; - *p->result8 = PyFloat_AsDouble(PyTuple_GET_ITEM(result, 7)); - p->oresult8 = *p->result8; - } - - Py_DECREF(result); - return OK; -} - diff --git a/7.x/src/py/src/pyx.auto.c b/7.x/src/py/src/pyx.auto.c deleted file mode 100644 index 7080bca3..00000000 --- a/7.x/src/py/src/pyx.auto.c +++ /dev/null @@ -1,680 +0,0 @@ -/* - * pyx.auto.c - * - * Copyright (C) 2002 Maurizio Umberto Puxeddu, Michael Gogins - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Don't modify this file, it's automatically genetated by pyx-gen.py - */ - -char *strNcpy(char *dst, const char *src, size_t siz) -{ - char *d = dst; - const char *s = src; - size_t n = siz; - - /* Copy as many bytes as will fit or until NULL */ - if (n != 0) { - while (--n != 0) { - if ((*d++ = *s++) == '\0') - break; - } - } - - /* Not enough room in dst, add NUL */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - - //while (*s++) ; - } - return dst; /* count does not include NUL */ -} - -static int pyexec_krate(CSOUND *csound, PYEXEC *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - strNcpy(source, (char*) p->string->data, 1024); // source[1023] = '\0' - - result = exec_file_in_given_context(csound, source, 0); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pyexeci_irate(CSOUND *csound, PYEXEC *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - strNcpy(source, (char*) p->string->data, 1024); // source[1023] = '\0' - - result = exec_file_in_given_context(csound, source, 0); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pylexec_irate(CSOUND *csound, PYEXEC *p) -{ - int *py_initialize_done; - if((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylexec_krate(CSOUND *csound, PYEXEC *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - strNcpy(source, (char*) p->string->data, 1024); // source[1023] = '\0' - - result = exec_file_in_given_context(csound, source, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pylexeci_irate(CSOUND *csound, PYEXEC *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - create_private_namespace_if_needed(&p->h); - - strNcpy(source, (char*) p->string->data, 1024); // source[1023] = '\0' - - result = exec_file_in_given_context(csound, source, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pyexect_krate(CSOUND *csound, PYEXECT *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - if (!*p->trigger) { - return OK; - } - strNcpy(source, (char*) p->string->data, 1024); // source[1023] = '\0' - - result = exec_file_in_given_context(csound, source, 0); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pylexect_irate(CSOUND *csound, PYEXECT *p) -{ - int *py_initialize_done; - if((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylexect_krate(CSOUND *csound, PYEXECT *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - if (!*p->trigger) { - return OK; - } - strNcpy(source, (char*) p->string->data, 1024); // source[1023] = '\0' - - result = exec_file_in_given_context(csound, source, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pyrun_krate(CSOUND *csound, PYRUN *p) -{ - char source[40960]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - strNcpy(source, (char*) p->string->data, 40960); // source[40959] = '\0' - - result = run_statement_in_given_context(source, 0); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pyruni_irate(CSOUND *csound, PYRUN *p) -{ - char source[40960]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - strNcpy(source, (char*) p->string->data, 40960); // source[40959] = '\0' - - result = run_statement_in_given_context(source, 0); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pylrun_irate(CSOUND *csound, PYRUN *p) -{ - int *py_initialize_done; - if((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylrun_krate(CSOUND *csound, PYRUN *p) -{ - char source[40960]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - strNcpy(source, (char*) p->string->data, 40960); // source[40959] = '\0' - - result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pylruni_irate(CSOUND *csound, PYRUN *p) -{ - char source[40960]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - create_private_namespace_if_needed(&p->h); - - strNcpy(source, (char*) p->string->data, 40960); // source[40959] = '\0' - - result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pyrunt_krate(CSOUND *csound, PYRUNT *p) -{ - char source[40960]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - if (!*p->trigger) { - return OK; - } - strNcpy(source, (char*) p->string->data, 40960); // source[40959] = '\0' - - result = run_statement_in_given_context(source, 0); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pylrunt_irate(CSOUND *csound, PYRUNT *p) -{ - int *py_initialize_done; - if((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylrunt_krate(CSOUND *csound, PYRUNT *p) -{ - char source[40960]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - if (!*p->trigger) { - return OK; - } - strNcpy(source, (char*) p->string->data, 40960); // source[40959] = '\0' - - result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pyeval_krate(CSOUND *csound, PYEVAL *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - strNcpy(source, (char*) p->string->data, 1024); // source[1023] = '\0' - - result = eval_string_in_given_context(source, 0); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - else if (!PyFloat_Check(result)) { - errMsg(p, "expression must evaluate in a float"); - } - else { - *p->result = PyFloat_AsDouble(result); - } - Py_DECREF(result); - return OK; -} - -static int pyevali_irate(CSOUND *csound, PYEVAL *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - strNcpy(source, (char*) p->string->data, 1024); // source[1023] = '\0' - - result = eval_string_in_given_context(source, 0); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - else if (!PyFloat_Check(result)) { - errMsg(p, "expression must evaluate in a float"); - } - else { - *p->result = PyFloat_AsDouble(result); - } - Py_DECREF(result); - return OK; -} - -static int pyleval_irate(CSOUND *csound, PYEVAL *p) -{ - int *py_initialize_done; - if((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pyleval_krate(CSOUND *csound, PYEVAL *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - strNcpy(source, (char*) p->string->data, 1024); // source[1023] = '\0' - - result = eval_string_in_given_context(source, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - else if (!PyFloat_Check(result)) { - errMsg(p, "expression must evaluate in a float"); - } - else { - *p->result = PyFloat_AsDouble(result); - } - Py_DECREF(result); - return OK; -} - -static int pylevali_irate(CSOUND *csound, PYEVAL *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - create_private_namespace_if_needed(&p->h); - - strNcpy(source, (char*) p->string->data, 1024); // source[1023] = '\0' - - result = eval_string_in_given_context(source, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - else if (!PyFloat_Check(result)) { - errMsg(p, "expression must evaluate in a float"); - } - else { - *p->result = PyFloat_AsDouble(result); - } - Py_DECREF(result); - return OK; -} - -static int pyevalt_krate(CSOUND *csound, PYEVALT *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - if (!*p->trigger) { - *p->result = p->oresult; - return OK; - } - strNcpy(source, (char*) p->string->data, 1024); // source[1023] = '\0' - - result = eval_string_in_given_context(source, 0); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - else if (!PyFloat_Check(result)) { - errMsg(p, "expression must evaluate in a float"); - } - else { - *p->result = PyFloat_AsDouble(result); - p->oresult = *p->result; - } - Py_DECREF(result); - return OK; -} - -static int pylevalt_irate(CSOUND *csound, PYEVALT *p) -{ - int *py_initialize_done; - if((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylevalt_krate(CSOUND *csound, PYEVALT *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - if (!*p->trigger) { - *p->result = p->oresult; - return OK; - } - strNcpy(source, (char*) p->string->data, 1024); // source[1023] = '\0' - - result = eval_string_in_given_context(source, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - else if (!PyFloat_Check(result)) { - errMsg(p, "expression must evaluate in a float"); - } - else { - *p->result = PyFloat_AsDouble(result); - p->oresult = *p->result; - } - Py_DECREF(result); - return OK; -} - -static int pyassign_krate(CSOUND *csound, PYASSIGN *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - snprintf(source, 1024, "%s = %f", (char*) p->string->data, *p->value); - result = run_statement_in_given_context(source, 0); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pyassigni_irate(CSOUND *csound, PYASSIGN *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - snprintf(source, 1024, "%s = %f", (char*) p->string->data, *p->value); - result = run_statement_in_given_context(source, 0); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pylassign_irate(CSOUND *csound, PYASSIGN *p) -{ - int *py_initialize_done; - if((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylassign_krate(CSOUND *csound, PYASSIGN *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - snprintf(source, 1024, "%s = %f", (char*) p->string->data, *p->value); - result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pylassigni_irate(CSOUND *csound, PYASSIGN *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - create_private_namespace_if_needed(&p->h); - - snprintf(source, 1024, "%s = %f", (char*) p->string->data, *p->value); - result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pyassignt_krate(CSOUND *csound, PYASSIGNT *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - if (!*p->trigger) { - return OK; - } - snprintf(source, 1024, "%s = %f", (char*) p->string->data, *p->value); - result = run_statement_in_given_context(source, 0); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - -static int pylassignt_irate(CSOUND *csound, PYASSIGNT *p) -{ - int *py_initialize_done; - if((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - create_private_namespace_if_needed(&p->h); - return OK; -} - -static int pylassignt_krate(CSOUND *csound, PYASSIGNT *p) -{ - char source[1024]; - PyObject *result; - int *py_initialize_done; - if ((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || - *py_initialize_done == 0) { - return NOTOK; - } - - if (!*p->trigger) { - return OK; - } - snprintf(source, 1024, "%s = %f", (char*) p->string->data, *p->value); - result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) { - return pyErrMsg(p, "python exception"); - } - Py_DECREF(result); - return OK; -} - diff --git a/7.x/src/wiimote/wii_mac.h b/7.x/src/wiimote/wii_mac.h deleted file mode 100644 index 12e8963a..00000000 --- a/7.x/src/wiimote/wii_mac.h +++ /dev/null @@ -1,58 +0,0 @@ -/* wii_mac.h: Names for WiiMote opcodes in Csound. - Copyright 2009 John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#define WII_BUTTONS (0) -#define WII_TWO (1) -#define WII_ONE (2) -#define WII_B (3) -#define WII_A (4) -#define WII_MINUS (5) -#define WII_HOME (8) -#define WII_LEFT (9) -#define WII_RIGHT (10) -#define WII_DOWN (11) -#define WII_UP (12) -#define WII_PLUS (13) - -#define WII_AXIS_X (17) -#define WII_AXIS_Y (18) -#define WII_AXIS_Z (19) -#define WII_PITCH (20) -#define WII_ROLL (21) -#define WII_YAW (22) -#define WII_FORCE_X (23) -#define WII_FORCE_Y (24) -#define WII_FORCE_Z (25) -#define WII_FORCE_TOTAL (26) -#define WII_BATTERY (27) -#define WII_NUNCHUK_ANG (28) -#define WII_NUNCHUK_MAG (29) -#define WII_NUNCHUK_PITCH (30) -#define WII_NUNCHUK_ROLL (31) -#define WII_NUNCHUK_YAW (32) -#define WII_NUNCHUK_Z (33) -#define WII_NUNCHUK_C (34) -#define WII_IR1_X (35) -#define WII_IR1_Y (36) -#define WII_IR1_Z (37) - -#define WII_RUMBLE (3) -#define WII_SET_LEDS (4) diff --git a/7.x/CMakeLists.txt b/CMakeLists.txt similarity index 100% rename from 7.x/CMakeLists.txt rename to CMakeLists.txt diff --git a/README.md b/README.md index 7be51043..7f0b0721 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,416 @@ CSOUND PLUGINS === -This repository contains the code for Csound plugins that require +This repository contains the code for Csound 7 plugins that require external dependencies, as well as code for new third-party contributed -plugins. +plugins. Native plugins build with CMake; the WASM package `@csound/plugins` +uses Nix and CMake and is documented in [`wasm/README.md`](wasm/README.md). -The tree is currently organised by major Csound versions. Full and beta releases are available and build artefacts are also accessible from the actions tab. +Csound 6 is end-of-life. Its plugin tree is archived on the +[`csound6` branch](https://github.com/csound/plugins/tree/csound6). -The Csound 7 WASM package, `@csound/plugins`, uses Nix and CMake. See the -[build, test, and npm release notes](wasm/README.md). +Currently, the plugins available in this tree are -NB: Csound 6.x is EOL. It is likely that plugins for that version will be removed from the develop and main branch after the first full release. In that case, we will keep the code solely in the csound6 branch. +- chua (requires the Eigen library, header-only) +**chuap** +- fluidOpcodes (requires fluidsynth) +**fluidEngine fluidLoad fluidNote fluidCCi fluidCCk fluidControl fluidProgramSelect fluidAllOut fluidOut fluidInfo fluidSetInterpMethod** +- dssi4cs (hosts native DSSI/LADSPA plugins; Linux only, requires the ALSA headers) +**dssiinit dssiactivate dssiaudio dssisynth dssictls dssiget dssinote dssievent dssinrpn dssiprogram dssiconfigure dssiprograminfo dssiinfo dssilist** +- faust (requires the Faust compiler library and headers, `libfaust`) +**faustgen faustcompile faustaudio faustdsp faustplay faustctl** + +- image (requires libpng) +**imageload imagesave imagecreate imagesize imagegetpixel imagesetpixel imagefree** + +- hdf5 (requires the HDF5 library) +**hdf5read hdf5write** + +- linear_algebra (requires the gmm++ library, header-only; vendored under this directory) +**A large family of `la_*` opcodes, with i-rate and k-rate variants, for vector, matrix and tensor operations** + +- py (requires a Python 3.x installation with dev libs) +**Many opcodes to call Python code** + +- websockets (requires libwebsockets) +**websocket** + +- wiimote (requires the wiiuse library; CMake-only, see note below) +**wiiconnect wiidata wiisend wiirange** + +- p5glove (requires the p5glove driver; CMake-only, see note below) +**p5gconnect p5gdata** + +- CUDA (requires the CUDA toolkit; Linux only, disabled by default, see note below) +**cudasynth cudanal cudasliding cudaconv cudapconv** + +- OpenCL (requires the OpenCL headers/loader; see note below) +**cladsyn** + +- STK (port of the Synthesis ToolKit instruments; STK 4.6.2 is vendored under this directory, see note below) +**STKBandedWG STKBeeThree STKBlowBotl STKBlowHole STKBowed STKBrass STKClarinet STKDrummer STKFlute STKFMVoices STKHevyMetl STKMandolin STKModalBar STKMoog STKPercFlut STKPlucked STKResonate STKRhodey STKSaxofony STKShakers STKSimple STKSitar STKStifKarp STKTubeBell STKVoicForm STKWhistle STKWurley** + + +WebAssembly (WASM) plugins +--- + +Besides the native plugin libraries described above, this tree can also be +built for the browser: Csound 7 runs under WebAssembly (WASI) through the +`@csound/browser` runtime, and a subset of these plugins is available as WASM +side modules. The WASM build is driven by the Nix expression in +[`wasm/default.nix`](wasm/default.nix) and published as the `@csound/plugins` +npm package; see [`wasm/README.md`](wasm/README.md) for the build and test +instructions. + +Only four plugins are built for WASM: + +- chua (`chuap`) +- image +- linear_algebra +- STK (`stkops`) + +The remaining plugins are **disabled** in the WASM build, either because their +dependencies do not exist in the WASI/static-PIC toolchain or because they need +platform facilities the browser does not provide: fluidOpcodes (FluidSynth), +hdf5, faust (libfaust), websockets, py (Python), wiimote, p5glove, CUDA and +OpenCL. + +The `@csound/plugins` package exposes one asset URL per WASM plugin: + +| Export | Plugin | File | +| --- | --- | --- | +| `plugins.chua` | chua | `chua.wasm` | +| `plugins.image` | image | `image.wasm` | +| `plugins.linearAlgebra` | linear_algebra | `linear_algebra.wasm` | +| `plugins.stk` | STK | `stkops.wasm` | + +The URLs are passed to the runtime's `withPlugins` option, e.g.: + +```js +import { Csound } from "@csound/browser"; +import { plugins } from "@csound/plugins"; + +const csound = await Csound({ withPlugins: [plugins.chua, plugins.image] }); +``` + +Unlike the native build, the WASM STK plugin embeds its raw-wave samples in +`stkops.wasm` (`STK_EMBED_RAWWAVES` defaults to ON for WASM): at initialization +it writes them to Csound's virtual filesystem and sets the wave path, so no +separate download or `RAWWAVE_PATH` setup is needed. An explicit `RAWWAVE_PATH` +still overrides the embedded samples. + + +Fluid settings opcodes +--- + +Besides the engine/SoundFont/MIDI opcodes listed above, `fluidOpcodes` +provides four opcodes to read and write the settings of an engine created by +`fluidEngine` (resolved through `fluid_synth_get_settings`). In each case the +first argument is the engine id and the second is the setting name: + +| Opcode | Outputs | Inputs | Description | +| --- | --- | --- | --- | +| `fluidSettingNum` | – | `iSk` | set an int/num/bool setting | +| `fluidSettingString` | – | `iSS` | set a string setting | +| `fluidSettingGetNum` | `k` | `iS` | read a numeric setting | +| `fluidSettingGetString` | `S` | `iS` | read a string setting | + +The setters fail at init if the setting name is unknown or of the wrong type; +the getters report a message and return 0 (or an empty string) instead. + + +Wiimote opcodes +--- + +The `wiimote` opcodes (`wiiconnect`, `wiidata`, `wiisend`, `wiirange`) are a +CMake-only port of the Csound 6.x plugin. They are **not** built by the CI and +are **not** included in the release packages, because the required `wiiuse` +library is not available as a standard distribution package: it is not in the +Ubuntu repositories, and the vcpkg `wiiuse` port ships only pkg-config +metadata, so it cannot be wired into the automated builds. + +When `wiiuse` (headers and library) is found by CMake, the plugin is built and +installed like any other; otherwise `BUILD_WIIMOTE_OPCODES` is silently +disabled. To build it locally, install `wiiuse` and configure with +`-DBUILD_WIIMOTE_OPCODES=ON`. + + +P5Glove opcodes +--- + +The `p5glove` opcodes (`p5gconnect`, `p5gdata`) are a CMake-only port of the +Csound 6.x plugin. They are **not** built by the CI and are **not** included in +the release packages, because the required P5Glove driver is not widely +packaged: there is no vcpkg port for `libp5glove`, and its Linux backend needs +the legacy libusb-0.1 API (not present in vcpkg). + +When an external `libp5glove` (headers and library) is found by CMake, the +plugin is built and installed like any other; otherwise +`BUILD_P5GLOVE_OPCODES` is silently disabled. On macOS the driver can +additionally be built from the sources bundled under `src/p5glove/libp5glove` +by configuring with `-DP5GLOVE_USE_BUNDLED=ON` (in addition to +`-DBUILD_P5GLOVE_OPCODES=ON`). + + +CUDA opcodes +--- + +The `CUDA` opcodes (`cudasynth`, `cudanal`, `cudasliding`, `cudaconv`, +`cudapconv`) are a port of the Csound 6.x plugin to the Csound 7 plugin API. +They run their DSP kernels on an NVIDIA GPU; `cudanal` and `cudapconv` also +rely on cuFFT. + +They are **disabled by default** and only built when the CUDA toolkit is +found: configure with `-DBUILD_CUDA_OPCODES=ON`. CUDA is **not available on +macOS** (NVIDIA dropped macOS support after 10.13), so on macOS the option is +ignored. The Linux CI builds them compile-only (the hosted runners have no +GPU) and they are included in the Linux release package. Windows is not built +or tested, so the CUDA opcodes are currently Linux-only. + +Building them requires CMake 3.18 or later; with an older CMake the option +is ignored. The compute capabilities default to `75 80 86 89`; override with +`-DCMAKE_CUDA_ARCHITECTURES="..."` (for example `native` for the local GPU). + + +OpenCL opcodes +--- + +The `OpenCL` opcode (`cladsyn`) is a port of the Csound 6.x plugin to the +Csound 7 plugin API. It runs its DSP kernels on any available OpenCL device +(CPU or GPU) through the ICD loader. + +It is built by default when OpenCL is available: the system framework is used +on macOS, `ocl-icd-opencl-dev` on Linux and the vcpkg `opencl` port on Windows. +Configure with `-DBUILD_OPENCL_OPCODES=OFF` to exclude it. The CI builds it +compile-only (the hosted runners have no OpenCL device) and it is included in +the Linux, macOS and Windows release packages. + + +STK opcodes +--- + +The `STK` opcodes are a port of the Csound 6.x plugin to the Csound 7 plugin +API. They expose the instruments of Perry Cook and Gary Scavone's Synthesis +ToolKit in C++ (STK), each named `STK` followed by the STK class, e.g. +`STKSitar`. All of them share the same signature: + +``` +aout STKName ifrequency igain {kcontroller0, kvalue0, ..., kcontrollerN, kvalueN} +``` + +The STK sources are **vendored under this directory** (`include/`, `src/` and +`rawwaves/`) and built from source, so no external STK installation is needed +and the result is independent of any system or package-manager STK. The +vendored copy carries a fix for the sample buildup reported in +[csound/plugins#4](https://github.com/csound/plugins/issues/4): the noise +modulation of the sitar delay line in `Sitar::setFrequency`, which could make +`STKSitar` build up clipped output over time, has been removed. + +It is built by default; configure with `-DBUILD_STK_OPCODES=OFF` to exclude +it. The wavetables the instruments need are installed alongside the plugin +(under `stk/rawwaves`). At run time the `RAWWAVE_PATH` environment variable, +if set, overrides the built-in default location; otherwise the installed +`rawwaves` directory is used. The plugin is included in the Linux, macOS and +Windows release packages. + + +Faust opcodes +--- + +The `faust` opcodes embed the [Faust](https://faust.grame.fr/) compiler and +DSP runtime into Csound, so a Faust program supplied as a string is compiled +at init time and run as a Csound opcode. They are a port of the Csound 6.x +plugin to the Csound 7 plugin API: + +``` +ihandle[,asig1,...] faustgen Scode[,ain1,...] +ihandle faustcompile Scode, Sargs[, iasync, istacksize[, Starget]] +ihandle[,asig1,...] faustaudio ifactory[,ain1,...] +ihandle faustdsp ifactory +asig1[,asig2,...] faustplay ihandle[,ain1,...] + faustctl ihandle, Slabel, kval[, Slabel1, kval1, ...] +``` + +Where: + +- `faustgen` compiles `Scode` and runs it in a single opcode, returning a + handle and the audio outputs. +- `faustcompile` compiles `Scode` and returns `ihandle`, a handle to the + compiled factory, to be passed to `faustaudio` or `faustdsp`. +- `faustaudio`/`faustdsp` instantiate the factory named by `ifactory`; + `faustaudio` has audio inputs and outputs, `faustdsp` has none. +- `faustplay` runs the DSP instance named by `ihandle` (one returned by + `faustgen`, `faustaudio` or `faustdsp`) with explicit inputs and outputs. +- `faustctl` sets the control `Slabel` of a DSP instance; both an i-rate + (`iSi`) and a k-rate (`iSk`) form are provided, the latter updating the + control every k-cycle. + +`Scode` is the Faust program (programs that use the standard library need +`import("stdfaust.lib");`). `Sargs` holds any extra Faust compiler options; +`iasync` selects asynchronous compilation (on by default), `istacksize` is +accepted for backwards compatibility but ignored (the Csound 7 threading API +no longer sets the thread stack size) and `Starget` is an optional LLVM +target string (an empty string selects the native target). + +The opcodes need the Faust compiler library (`libfaust`) and headers. The +build looks for them automatically; if Faust is in a non-standard location, +point CMake at it with `FAUST_INCLUDE_DIR_HINT`, `FAUST_LIB_DIR_HINT` and +`FAUST_STDLIB_DIR_HINT`. With `-DFAUST_STATIC=ON` the plugin is linked +against the self-contained `libfaustwithllvm` archive, which bundles LLVM so +the plugin has no runtime dependency on `libfaust` (at the cost of a much +larger plugin). + +It is built by default; configure with `-DBUILD_FAUST_OPCODES=OFF` to +exclude it. The Faust standard library is installed next to the plugin (in a +`faust` subdirectory), so `import("stdfaust.lib")` works without a separate +Faust installation; set `FAUST_LIB_PATH` at run time to override it. The CI +downloads the official Faust release binaries, builds with `FAUST_STATIC=ON` +and includes the plugin (and the standard library) in the Linux, macOS and +Windows release packages. + + +DSSI and LADSPA opcodes +--- + +The `dssi4cs` plugin hosts native DSSI synths and LADSPA effects: + +``` +ih dssiinit Sfilename, iindex [, iverbose] + dssilist + dssiinfo ih + dssiactivate ih, kactive +a1[,a2,...] dssisynth ih [, ain1, ...] +a1[,a2,...] dssiaudio ih [, ain1, ...] + dssinote ktrigger, ih, knote, kvelocity, kduration [, ichannel] + dssievent ktrigger, ih, knote, kvelocity + dssievent ktrigger, ih, kstatus, kchannel, kdata1, kdata2 [, koffset] + dssinrpn ktrigger, ih, kchannel, kparameter, kvalue [, koffset] + dssictls ih, iport, kvalue, ktrigger +kvalue dssiget ih, iport + dssiprogram ih, kbank, kprogram, ktrigger +Sname, ibank, iprogram dssiprograminfo ih, iindex + dssiconfigure ih, Skey, Svalue +``` + +The opcodes load a plugin library, instantiate a DSSI synth or LADSPA effect, +feed it Csound audio and MIDI events, and return its audio. Libraries are +looked up by path or through `DSSI_PATH` and `LADSPA_PATH`. See the +[module README](src/dssi4cs/README.md) for the full opcode reference. + +Hosting native plugins is Linux-only: the opcodes load the shared objects with +`dlopen` and use the ALSA sequencer event types, so they need the ALSA headers +(`libasound2-dev` on Debian/Ubuntu) but not the ALSA library or a running +sequencer. The DSSI and LADSPA API headers are **vendored under this +directory** (in `src/dssi4cs/include`), so no system DSSI/LADSPA development +package is required. + +It is built by default on Linux when the ALSA headers are found and silently +disabled elsewhere; configure with `-DBUILD_DSSI_OPCODES=OFF` to exclude it. +It is included in the Linux release package only. + + +Release binaries and macOS architecture +-------------- + +The CI builds each plugin on its default hosted runner and packages the +resulting plugin libraries into the GitHub release assets. These binaries are +single-architecture — they are **not** universal fat binaries. + +On macOS the release plugins are built on the Apple Silicon (`arm64`) +`macos-latest` runner with no `CMAKE_OSX_ARCHITECTURES` override, and the +dependencies come from vcpkg using the `arm64-osx` triplet. The +`csound7-plugins-*-macos.zip` release asset therefore contains **arm64-only** +`.dylib` files: they load in the arm64 build of Csound on Apple Silicon, but +not in the x86_64 (Intel) build on Intel Macs. Users on Intel Macs should +build the plugins from source against x86_64 versions of their dependencies +(see the build instructions below). + + +Install location +-------------- +The CMake scripts in this repository use the default CS_USER_PLUGIN +location on MacOS and Windows as defined in the Csound build, or a +library instalation directory (customisable) on LINUX. These are: + +- LINUX: depends on both `CMAKE_INSTALL_PREFIX` and `USE_LIB64`. It is then installed in: + * if `USE_LIB64=1` then to + * for doubles: `${CSOUND_INSTALL_PREFIX}/lib64/csound/plugins64-${APIVERSION}` + * for floats: `${CSOUND_INSTALL_PREFIX}/lib64/csound/plugins-${APIVERSION}` (floats)` + * if `USE_LIB64=0` then to + * for doubles: `${CSOUND_INSTALL_PREFIX}/lib/csound/plugins64-${APIVERSION}` + * for floats: `${CSOUND_INSTALL_PREFIX}/lib/csound/plugins-${APIVERSION}` + +- MACOS: + * For doubles: `$HOME/Library/csound/${APIVERSION}/plugins64` + * For floats: `$HOME/Library/csound/${APIVERSION}/plugins` +- Windows: + * For doubles: `%LOCALAPPDATA%\csound\${APIVERSION}\plugins64` + * For floats: `%LOCALAPPDATA%\csound\${APIVERSION}\plugins` + + +Build Instructions for Linux and MacOS +--- + +The build requires Csound to be installed, as well as CMake. With this +in place, you can do : + +``` +$ git clone https://github.com/csound/plugins.git +$ cd plugins +$ mkdir build +$ cd build +$ cmake ../ +$ make +``` + +By default, all the plugins are built. If one wants to exclude a +plugin from the build process, one can pass an option to the cmake command. +The options are `BUILD_CHUA_OPCODES`, `BUILD_CUDA_OPCODES`, +`BUILD_DSSI_OPCODES`, `BUILD_OPENCL_OPCODES`, `BUILD_FAUST_OPCODES`, +`BUILD_FLUID_OPCODES`, `BUILD_IMAGE_OPCODES`, `BUILD_HDF5_OPCODES`, +`BUILD_LINEAR_ALGEBRA_OPCODES`, `BUILD_P5GLOVE_OPCODES`, `BUILD_STK_OPCODES`, +`BUILD_WIIMOTE_OPCODES`, `BUILD_WEBSOCKET_OPCODE` and +`BUILD_PYTHON_OPCODES`. For example, to +exclude the chua plugin, the `cmake` command would be: + +``` +$ cmake -DBUILD_CHUA_OPCODES=OFF ../ +``` + + +To install the opcodes you have built + +``` +$ make install +``` + +Depending on your permissions, you might need to prepend `sudo` to +these commands. After the first build the plugins can be updated with + +``` +$ git pull +$ make +$ make install +``` + +using `sudo` in the last step if raised permissions are needed. On +Linux, the installation location can be set with the relevant CMake +variables as indicated above. + +Csound Location +------------ +CMake will normally find the installed Csound headers (and library) +automatically. However, if your Csound headers and library are not +placed in the usual locations, you can use the following CMake option variables +to tell CMake where they are: + +``` +CSOUND_INCLUDE_DIR_HINT +``` +and + +``` +CSOUND_LIBRARY_DIR_HINT diff --git a/THIRD_PARTY.md b/THIRD_PARTY.md index 6e94339e..7c3f6707 100644 --- a/THIRD_PARTY.md +++ b/THIRD_PARTY.md @@ -1,7 +1,7 @@ # Third-party code in the WASM package The plugins use the LGPL-2.1-or-later license in `LICENSE`. Their source and -copyright notices live under [`7.x/src`](https://github.com/csound/plugins/tree/develop/7.x/src). +copyright notices live under [`src`](https://github.com/csound/plugins/tree/develop/src). The package also contains code from these libraries: | Library | Used by | License notices | diff --git a/6.x/cmake/CompilerOptimizations.cmake b/cmake/CompilerOptimizations.cmake similarity index 100% rename from 6.x/cmake/CompilerOptimizations.cmake rename to cmake/CompilerOptimizations.cmake diff --git a/7.x/cmake/Modules/FindCSOUND.cmake b/cmake/Modules/FindCSOUND.cmake similarity index 100% rename from 7.x/cmake/Modules/FindCSOUND.cmake rename to cmake/Modules/FindCSOUND.cmake diff --git a/6.x/cmake/Modules/FindEIGEN3.cmake b/cmake/Modules/FindEIGEN3.cmake similarity index 100% rename from 6.x/cmake/Modules/FindEIGEN3.cmake rename to cmake/Modules/FindEIGEN3.cmake diff --git a/7.x/cmake/Modules/FindFAUST.cmake b/cmake/Modules/FindFAUST.cmake similarity index 100% rename from 7.x/cmake/Modules/FindFAUST.cmake rename to cmake/Modules/FindFAUST.cmake diff --git a/6.x/cmake/Modules/FindFLUIDSYNTH.cmake b/cmake/Modules/FindFLUIDSYNTH.cmake similarity index 100% rename from 6.x/cmake/Modules/FindFLUIDSYNTH.cmake rename to cmake/Modules/FindFLUIDSYNTH.cmake diff --git a/7.x/cmake/Modules/FindGMM.cmake b/cmake/Modules/FindGMM.cmake similarity index 100% rename from 7.x/cmake/Modules/FindGMM.cmake rename to cmake/Modules/FindGMM.cmake diff --git a/6.x/cmake/Modules/FindLAME.cmake b/cmake/Modules/FindLAME.cmake similarity index 100% rename from 6.x/cmake/Modules/FindLAME.cmake rename to cmake/Modules/FindLAME.cmake diff --git a/6.x/cmake/Modules/FindSTK.cmake b/cmake/Modules/FindSTK.cmake similarity index 100% rename from 6.x/cmake/Modules/FindSTK.cmake rename to cmake/Modules/FindSTK.cmake diff --git a/7.x/cmake/WasmPlugins.cmake b/cmake/WasmPlugins.cmake similarity index 100% rename from 7.x/cmake/WasmPlugins.cmake rename to cmake/WasmPlugins.cmake diff --git a/7.x/src/CUDA/CMakeLists.txt b/src/CUDA/CMakeLists.txt similarity index 100% rename from 7.x/src/CUDA/CMakeLists.txt rename to src/CUDA/CMakeLists.txt diff --git a/7.x/src/CUDA/adsyn.cu b/src/CUDA/adsyn.cu similarity index 100% rename from 7.x/src/CUDA/adsyn.cu rename to src/CUDA/adsyn.cu diff --git a/7.x/src/CUDA/conv.cu b/src/CUDA/conv.cu similarity index 100% rename from 7.x/src/CUDA/conv.cu rename to src/CUDA/conv.cu diff --git a/7.x/src/CUDA/pconv.cu b/src/CUDA/pconv.cu similarity index 100% rename from 7.x/src/CUDA/pconv.cu rename to src/CUDA/pconv.cu diff --git a/7.x/src/CUDA/pvsops.cu b/src/CUDA/pvsops.cu similarity index 100% rename from 7.x/src/CUDA/pvsops.cu rename to src/CUDA/pvsops.cu diff --git a/7.x/src/CUDA/slidingm.cu b/src/CUDA/slidingm.cu similarity index 100% rename from 7.x/src/CUDA/slidingm.cu rename to src/CUDA/slidingm.cu diff --git a/7.x/src/OpenCL/CMakeLists.txt b/src/OpenCL/CMakeLists.txt similarity index 100% rename from 7.x/src/OpenCL/CMakeLists.txt rename to src/OpenCL/CMakeLists.txt diff --git a/7.x/src/OpenCL/cladsynth.c b/src/OpenCL/cladsynth.c similarity index 100% rename from 7.x/src/OpenCL/cladsynth.c rename to src/OpenCL/cladsynth.c diff --git a/7.x/src/chua/CMakeLists.txt b/src/chua/CMakeLists.txt similarity index 100% rename from 7.x/src/chua/CMakeLists.txt rename to src/chua/CMakeLists.txt diff --git a/7.x/src/chua/ChuaOscillator.cpp b/src/chua/ChuaOscillator.cpp similarity index 100% rename from 7.x/src/chua/ChuaOscillator.cpp rename to src/chua/ChuaOscillator.cpp diff --git a/7.x/src/chua/OpcodeBase.hpp b/src/chua/OpcodeBase.hpp similarity index 100% rename from 7.x/src/chua/OpcodeBase.hpp rename to src/chua/OpcodeBase.hpp diff --git a/7.x/src/dssi4cs/CMakeLists.txt b/src/dssi4cs/CMakeLists.txt similarity index 100% rename from 7.x/src/dssi4cs/CMakeLists.txt rename to src/dssi4cs/CMakeLists.txt diff --git a/7.x/src/dssi4cs/README.md b/src/dssi4cs/README.md similarity index 100% rename from 7.x/src/dssi4cs/README.md rename to src/dssi4cs/README.md diff --git a/7.x/src/dssi4cs/dssi4cs.c b/src/dssi4cs/dssi4cs.c similarity index 100% rename from 7.x/src/dssi4cs/dssi4cs.c rename to src/dssi4cs/dssi4cs.c diff --git a/7.x/src/dssi4cs/dssi4cs.h b/src/dssi4cs/dssi4cs.h similarity index 100% rename from 7.x/src/dssi4cs/dssi4cs.h rename to src/dssi4cs/dssi4cs.h diff --git a/7.x/src/dssi4cs/include/dssi/LICENSE b/src/dssi4cs/include/dssi/LICENSE similarity index 100% rename from 7.x/src/dssi4cs/include/dssi/LICENSE rename to src/dssi4cs/include/dssi/LICENSE diff --git a/7.x/src/dssi4cs/include/dssi/README.md b/src/dssi4cs/include/dssi/README.md similarity index 100% rename from 7.x/src/dssi4cs/include/dssi/README.md rename to src/dssi4cs/include/dssi/README.md diff --git a/7.x/src/dssi4cs/include/dssi/SOURCE.json b/src/dssi4cs/include/dssi/SOURCE.json similarity index 100% rename from 7.x/src/dssi4cs/include/dssi/SOURCE.json rename to src/dssi4cs/include/dssi/SOURCE.json diff --git a/7.x/src/dssi4cs/include/dssi/dssi.h b/src/dssi4cs/include/dssi/dssi.h similarity index 100% rename from 7.x/src/dssi4cs/include/dssi/dssi.h rename to src/dssi4cs/include/dssi/dssi.h diff --git a/7.x/src/dssi4cs/include/dssi/update.py b/src/dssi4cs/include/dssi/update.py similarity index 100% rename from 7.x/src/dssi4cs/include/dssi/update.py rename to src/dssi4cs/include/dssi/update.py diff --git a/7.x/src/dssi4cs/include/ladspa/LICENSE b/src/dssi4cs/include/ladspa/LICENSE similarity index 100% rename from 7.x/src/dssi4cs/include/ladspa/LICENSE rename to src/dssi4cs/include/ladspa/LICENSE diff --git a/7.x/src/dssi4cs/include/ladspa/README.md b/src/dssi4cs/include/ladspa/README.md similarity index 100% rename from 7.x/src/dssi4cs/include/ladspa/README.md rename to src/dssi4cs/include/ladspa/README.md diff --git a/7.x/src/dssi4cs/include/ladspa/SOURCE.json b/src/dssi4cs/include/ladspa/SOURCE.json similarity index 100% rename from 7.x/src/dssi4cs/include/ladspa/SOURCE.json rename to src/dssi4cs/include/ladspa/SOURCE.json diff --git a/7.x/src/dssi4cs/include/ladspa/ladspa.h b/src/dssi4cs/include/ladspa/ladspa.h similarity index 100% rename from 7.x/src/dssi4cs/include/ladspa/ladspa.h rename to src/dssi4cs/include/ladspa/ladspa.h diff --git a/7.x/src/dssi4cs/include/ladspa/update.py b/src/dssi4cs/include/ladspa/update.py similarity index 100% rename from 7.x/src/dssi4cs/include/ladspa/update.py rename to src/dssi4cs/include/ladspa/update.py diff --git a/7.x/src/dssi4cs/load.c b/src/dssi4cs/load.c similarity index 100% rename from 7.x/src/dssi4cs/load.c rename to src/dssi4cs/load.c diff --git a/7.x/src/dssi4cs/tests/dssi_test.cpp b/src/dssi4cs/tests/dssi_test.cpp similarity index 100% rename from 7.x/src/dssi4cs/tests/dssi_test.cpp rename to src/dssi4cs/tests/dssi_test.cpp diff --git a/7.x/src/dssi4cs/tests/fixtures/dssi_test_plugin.c b/src/dssi4cs/tests/fixtures/dssi_test_plugin.c similarity index 100% rename from 7.x/src/dssi4cs/tests/fixtures/dssi_test_plugin.c rename to src/dssi4cs/tests/fixtures/dssi_test_plugin.c diff --git a/7.x/src/dssi4cs/utils.h b/src/dssi4cs/utils.h similarity index 100% rename from 7.x/src/dssi4cs/utils.h rename to src/dssi4cs/utils.h diff --git a/7.x/src/faustcsound/CMakeLists.txt b/src/faustcsound/CMakeLists.txt similarity index 100% rename from 7.x/src/faustcsound/CMakeLists.txt rename to src/faustcsound/CMakeLists.txt diff --git a/7.x/src/faustcsound/README.md b/src/faustcsound/README.md similarity index 100% rename from 7.x/src/faustcsound/README.md rename to src/faustcsound/README.md diff --git a/7.x/src/faustcsound/faustcsound.exports b/src/faustcsound/faustcsound.exports similarity index 100% rename from 7.x/src/faustcsound/faustcsound.exports rename to src/faustcsound/faustcsound.exports diff --git a/7.x/src/faustcsound/faustgen.cpp b/src/faustcsound/faustgen.cpp similarity index 100% rename from 7.x/src/faustcsound/faustgen.cpp rename to src/faustcsound/faustgen.cpp diff --git a/7.x/src/fluidOpcodes/CMakeLists.txt b/src/fluidOpcodes/CMakeLists.txt similarity index 100% rename from 7.x/src/fluidOpcodes/CMakeLists.txt rename to src/fluidOpcodes/CMakeLists.txt diff --git a/7.x/src/fluidOpcodes/OpcodeBase.hpp b/src/fluidOpcodes/OpcodeBase.hpp similarity index 100% rename from 7.x/src/fluidOpcodes/OpcodeBase.hpp rename to src/fluidOpcodes/OpcodeBase.hpp diff --git a/7.x/src/fluidOpcodes/fluidOpcodes.cpp b/src/fluidOpcodes/fluidOpcodes.cpp similarity index 100% rename from 7.x/src/fluidOpcodes/fluidOpcodes.cpp rename to src/fluidOpcodes/fluidOpcodes.cpp diff --git a/7.x/src/hdf5/CMakeLists.txt b/src/hdf5/CMakeLists.txt similarity index 100% rename from 7.x/src/hdf5/CMakeLists.txt rename to src/hdf5/CMakeLists.txt diff --git a/7.x/src/hdf5/HDF5IO.c b/src/hdf5/HDF5IO.c similarity index 100% rename from 7.x/src/hdf5/HDF5IO.c rename to src/hdf5/HDF5IO.c diff --git a/7.x/src/hdf5/HDF5IO.h b/src/hdf5/HDF5IO.h similarity index 100% rename from 7.x/src/hdf5/HDF5IO.h rename to src/hdf5/HDF5IO.h diff --git a/7.x/src/image/CMakeLists.txt b/src/image/CMakeLists.txt similarity index 100% rename from 7.x/src/image/CMakeLists.txt rename to src/image/CMakeLists.txt diff --git a/7.x/src/image/README.md b/src/image/README.md similarity index 100% rename from 7.x/src/image/README.md rename to src/image/README.md diff --git a/7.x/src/image/imageOpcodes.c b/src/image/imageOpcodes.c similarity index 100% rename from 7.x/src/image/imageOpcodes.c rename to src/image/imageOpcodes.c diff --git a/7.x/src/image/imageOpcodes.h b/src/image/imageOpcodes.h similarity index 100% rename from 7.x/src/image/imageOpcodes.h rename to src/image/imageOpcodes.h diff --git a/7.x/src/linear_algebra/CMakeLists.txt b/src/linear_algebra/CMakeLists.txt similarity index 100% rename from 7.x/src/linear_algebra/CMakeLists.txt rename to src/linear_algebra/CMakeLists.txt diff --git a/7.x/src/linear_algebra/OpcodeBase.hpp b/src/linear_algebra/OpcodeBase.hpp similarity index 100% rename from 7.x/src/linear_algebra/OpcodeBase.hpp rename to src/linear_algebra/OpcodeBase.hpp diff --git a/7.x/src/linear_algebra/gmm/gmm.h b/src/linear_algebra/gmm/gmm.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm.h rename to src/linear_algebra/gmm/gmm.h diff --git a/7.x/src/linear_algebra/gmm/gmm_MUMPS_interface.h b/src/linear_algebra/gmm/gmm_MUMPS_interface.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_MUMPS_interface.h rename to src/linear_algebra/gmm/gmm_MUMPS_interface.h diff --git a/7.x/src/linear_algebra/gmm/gmm_algobase.h b/src/linear_algebra/gmm/gmm_algobase.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_algobase.h rename to src/linear_algebra/gmm/gmm_algobase.h diff --git a/7.x/src/linear_algebra/gmm/gmm_arch_config.h b/src/linear_algebra/gmm/gmm_arch_config.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_arch_config.h rename to src/linear_algebra/gmm/gmm_arch_config.h diff --git a/7.x/src/linear_algebra/gmm/gmm_blas.h b/src/linear_algebra/gmm/gmm_blas.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_blas.h rename to src/linear_algebra/gmm/gmm_blas.h diff --git a/7.x/src/linear_algebra/gmm/gmm_blas_interface.h b/src/linear_algebra/gmm/gmm_blas_interface.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_blas_interface.h rename to src/linear_algebra/gmm/gmm_blas_interface.h diff --git a/7.x/src/linear_algebra/gmm/gmm_condition_number.h b/src/linear_algebra/gmm/gmm_condition_number.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_condition_number.h rename to src/linear_algebra/gmm/gmm_condition_number.h diff --git a/7.x/src/linear_algebra/gmm/gmm_conjugated.h b/src/linear_algebra/gmm/gmm_conjugated.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_conjugated.h rename to src/linear_algebra/gmm/gmm_conjugated.h diff --git a/7.x/src/linear_algebra/gmm/gmm_def.h b/src/linear_algebra/gmm/gmm_def.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_def.h rename to src/linear_algebra/gmm/gmm_def.h diff --git a/7.x/src/linear_algebra/gmm/gmm_dense_Householder.h b/src/linear_algebra/gmm/gmm_dense_Householder.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_dense_Householder.h rename to src/linear_algebra/gmm/gmm_dense_Householder.h diff --git a/7.x/src/linear_algebra/gmm/gmm_dense_lu.h b/src/linear_algebra/gmm/gmm_dense_lu.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_dense_lu.h rename to src/linear_algebra/gmm/gmm_dense_lu.h diff --git a/7.x/src/linear_algebra/gmm/gmm_dense_matrix_functions.h b/src/linear_algebra/gmm/gmm_dense_matrix_functions.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_dense_matrix_functions.h rename to src/linear_algebra/gmm/gmm_dense_matrix_functions.h diff --git a/7.x/src/linear_algebra/gmm/gmm_dense_qr.h b/src/linear_algebra/gmm/gmm_dense_qr.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_dense_qr.h rename to src/linear_algebra/gmm/gmm_dense_qr.h diff --git a/7.x/src/linear_algebra/gmm/gmm_dense_sylvester.h b/src/linear_algebra/gmm/gmm_dense_sylvester.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_dense_sylvester.h rename to src/linear_algebra/gmm/gmm_dense_sylvester.h diff --git a/7.x/src/linear_algebra/gmm/gmm_domain_decomp.h b/src/linear_algebra/gmm/gmm_domain_decomp.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_domain_decomp.h rename to src/linear_algebra/gmm/gmm_domain_decomp.h diff --git a/7.x/src/linear_algebra/gmm/gmm_except.h b/src/linear_algebra/gmm/gmm_except.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_except.h rename to src/linear_algebra/gmm/gmm_except.h diff --git a/7.x/src/linear_algebra/gmm/gmm_feedback_management.h b/src/linear_algebra/gmm/gmm_feedback_management.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_feedback_management.h rename to src/linear_algebra/gmm/gmm_feedback_management.h diff --git a/7.x/src/linear_algebra/gmm/gmm_inoutput.h b/src/linear_algebra/gmm/gmm_inoutput.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_inoutput.h rename to src/linear_algebra/gmm/gmm_inoutput.h diff --git a/7.x/src/linear_algebra/gmm/gmm_interface.h b/src/linear_algebra/gmm/gmm_interface.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_interface.h rename to src/linear_algebra/gmm/gmm_interface.h diff --git a/7.x/src/linear_algebra/gmm/gmm_interface_bgeot.h b/src/linear_algebra/gmm/gmm_interface_bgeot.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_interface_bgeot.h rename to src/linear_algebra/gmm/gmm_interface_bgeot.h diff --git a/7.x/src/linear_algebra/gmm/gmm_iter.h b/src/linear_algebra/gmm/gmm_iter.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_iter.h rename to src/linear_algebra/gmm/gmm_iter.h diff --git a/7.x/src/linear_algebra/gmm/gmm_iter_solvers.h b/src/linear_algebra/gmm/gmm_iter_solvers.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_iter_solvers.h rename to src/linear_algebra/gmm/gmm_iter_solvers.h diff --git a/7.x/src/linear_algebra/gmm/gmm_kernel.h b/src/linear_algebra/gmm/gmm_kernel.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_kernel.h rename to src/linear_algebra/gmm/gmm_kernel.h diff --git a/7.x/src/linear_algebra/gmm/gmm_lapack_interface.h b/src/linear_algebra/gmm/gmm_lapack_interface.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_lapack_interface.h rename to src/linear_algebra/gmm/gmm_lapack_interface.h diff --git a/7.x/src/linear_algebra/gmm/gmm_least_squares_cg.h b/src/linear_algebra/gmm/gmm_least_squares_cg.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_least_squares_cg.h rename to src/linear_algebra/gmm/gmm_least_squares_cg.h diff --git a/7.x/src/linear_algebra/gmm/gmm_matrix.h b/src/linear_algebra/gmm/gmm_matrix.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_matrix.h rename to src/linear_algebra/gmm/gmm_matrix.h diff --git a/7.x/src/linear_algebra/gmm/gmm_modified_gram_schmidt.h b/src/linear_algebra/gmm/gmm_modified_gram_schmidt.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_modified_gram_schmidt.h rename to src/linear_algebra/gmm/gmm_modified_gram_schmidt.h diff --git a/7.x/src/linear_algebra/gmm/gmm_opt.h b/src/linear_algebra/gmm/gmm_opt.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_opt.h rename to src/linear_algebra/gmm/gmm_opt.h diff --git a/7.x/src/linear_algebra/gmm/gmm_precond.h b/src/linear_algebra/gmm/gmm_precond.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_precond.h rename to src/linear_algebra/gmm/gmm_precond.h diff --git a/7.x/src/linear_algebra/gmm/gmm_precond_diagonal.h b/src/linear_algebra/gmm/gmm_precond_diagonal.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_precond_diagonal.h rename to src/linear_algebra/gmm/gmm_precond_diagonal.h diff --git a/7.x/src/linear_algebra/gmm/gmm_precond_ildlt.h b/src/linear_algebra/gmm/gmm_precond_ildlt.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_precond_ildlt.h rename to src/linear_algebra/gmm/gmm_precond_ildlt.h diff --git a/7.x/src/linear_algebra/gmm/gmm_precond_ildltt.h b/src/linear_algebra/gmm/gmm_precond_ildltt.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_precond_ildltt.h rename to src/linear_algebra/gmm/gmm_precond_ildltt.h diff --git a/7.x/src/linear_algebra/gmm/gmm_precond_ilu.h b/src/linear_algebra/gmm/gmm_precond_ilu.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_precond_ilu.h rename to src/linear_algebra/gmm/gmm_precond_ilu.h diff --git a/7.x/src/linear_algebra/gmm/gmm_precond_ilut.h b/src/linear_algebra/gmm/gmm_precond_ilut.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_precond_ilut.h rename to src/linear_algebra/gmm/gmm_precond_ilut.h diff --git a/7.x/src/linear_algebra/gmm/gmm_precond_ilutp.h b/src/linear_algebra/gmm/gmm_precond_ilutp.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_precond_ilutp.h rename to src/linear_algebra/gmm/gmm_precond_ilutp.h diff --git a/7.x/src/linear_algebra/gmm/gmm_precond_mr_approx_inverse.h b/src/linear_algebra/gmm/gmm_precond_mr_approx_inverse.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_precond_mr_approx_inverse.h rename to src/linear_algebra/gmm/gmm_precond_mr_approx_inverse.h diff --git a/7.x/src/linear_algebra/gmm/gmm_range_basis.h b/src/linear_algebra/gmm/gmm_range_basis.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_range_basis.h rename to src/linear_algebra/gmm/gmm_range_basis.h diff --git a/7.x/src/linear_algebra/gmm/gmm_real_part.h b/src/linear_algebra/gmm/gmm_real_part.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_real_part.h rename to src/linear_algebra/gmm/gmm_real_part.h diff --git a/7.x/src/linear_algebra/gmm/gmm_ref.h b/src/linear_algebra/gmm/gmm_ref.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_ref.h rename to src/linear_algebra/gmm/gmm_ref.h diff --git a/7.x/src/linear_algebra/gmm/gmm_scaled.h b/src/linear_algebra/gmm/gmm_scaled.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_scaled.h rename to src/linear_algebra/gmm/gmm_scaled.h diff --git a/7.x/src/linear_algebra/gmm/gmm_solver_Schwarz_additive.h b/src/linear_algebra/gmm/gmm_solver_Schwarz_additive.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_solver_Schwarz_additive.h rename to src/linear_algebra/gmm/gmm_solver_Schwarz_additive.h diff --git a/7.x/src/linear_algebra/gmm/gmm_solver_bfgs.h b/src/linear_algebra/gmm/gmm_solver_bfgs.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_solver_bfgs.h rename to src/linear_algebra/gmm/gmm_solver_bfgs.h diff --git a/7.x/src/linear_algebra/gmm/gmm_solver_bicgstab.h b/src/linear_algebra/gmm/gmm_solver_bicgstab.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_solver_bicgstab.h rename to src/linear_algebra/gmm/gmm_solver_bicgstab.h diff --git a/7.x/src/linear_algebra/gmm/gmm_solver_cg.h b/src/linear_algebra/gmm/gmm_solver_cg.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_solver_cg.h rename to src/linear_algebra/gmm/gmm_solver_cg.h diff --git a/7.x/src/linear_algebra/gmm/gmm_solver_constrained_cg.h b/src/linear_algebra/gmm/gmm_solver_constrained_cg.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_solver_constrained_cg.h rename to src/linear_algebra/gmm/gmm_solver_constrained_cg.h diff --git a/7.x/src/linear_algebra/gmm/gmm_solver_gmres.h b/src/linear_algebra/gmm/gmm_solver_gmres.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_solver_gmres.h rename to src/linear_algebra/gmm/gmm_solver_gmres.h diff --git a/7.x/src/linear_algebra/gmm/gmm_solver_idgmres.h b/src/linear_algebra/gmm/gmm_solver_idgmres.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_solver_idgmres.h rename to src/linear_algebra/gmm/gmm_solver_idgmres.h diff --git a/7.x/src/linear_algebra/gmm/gmm_solver_qmr.h b/src/linear_algebra/gmm/gmm_solver_qmr.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_solver_qmr.h rename to src/linear_algebra/gmm/gmm_solver_qmr.h diff --git a/7.x/src/linear_algebra/gmm/gmm_std.h b/src/linear_algebra/gmm/gmm_std.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_std.h rename to src/linear_algebra/gmm/gmm_std.h diff --git a/7.x/src/linear_algebra/gmm/gmm_sub_index.h b/src/linear_algebra/gmm/gmm_sub_index.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_sub_index.h rename to src/linear_algebra/gmm/gmm_sub_index.h diff --git a/7.x/src/linear_algebra/gmm/gmm_sub_matrix.h b/src/linear_algebra/gmm/gmm_sub_matrix.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_sub_matrix.h rename to src/linear_algebra/gmm/gmm_sub_matrix.h diff --git a/7.x/src/linear_algebra/gmm/gmm_sub_vector.h b/src/linear_algebra/gmm/gmm_sub_vector.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_sub_vector.h rename to src/linear_algebra/gmm/gmm_sub_vector.h diff --git a/7.x/src/linear_algebra/gmm/gmm_superlu_interface.h b/src/linear_algebra/gmm/gmm_superlu_interface.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_superlu_interface.h rename to src/linear_algebra/gmm/gmm_superlu_interface.h diff --git a/7.x/src/linear_algebra/gmm/gmm_transposed.h b/src/linear_algebra/gmm/gmm_transposed.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_transposed.h rename to src/linear_algebra/gmm/gmm_transposed.h diff --git a/7.x/src/linear_algebra/gmm/gmm_tri_solve.h b/src/linear_algebra/gmm/gmm_tri_solve.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_tri_solve.h rename to src/linear_algebra/gmm/gmm_tri_solve.h diff --git a/7.x/src/linear_algebra/gmm/gmm_vector.h b/src/linear_algebra/gmm/gmm_vector.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_vector.h rename to src/linear_algebra/gmm/gmm_vector.h diff --git a/7.x/src/linear_algebra/gmm/gmm_vector_to_matrix.h b/src/linear_algebra/gmm/gmm_vector_to_matrix.h similarity index 100% rename from 7.x/src/linear_algebra/gmm/gmm_vector_to_matrix.h rename to src/linear_algebra/gmm/gmm_vector_to_matrix.h diff --git a/7.x/src/linear_algebra/linear_algebra.cpp b/src/linear_algebra/linear_algebra.cpp similarity index 100% rename from 7.x/src/linear_algebra/linear_algebra.cpp rename to src/linear_algebra/linear_algebra.cpp diff --git a/7.x/src/p5glove/CMakeLists.txt b/src/p5glove/CMakeLists.txt similarity index 100% rename from 7.x/src/p5glove/CMakeLists.txt rename to src/p5glove/CMakeLists.txt diff --git a/6.x/src/p5glove/libp5glove/macosx_usb_hid.h b/src/p5glove/libp5glove/macosx_usb_hid.h similarity index 100% rename from 6.x/src/p5glove/libp5glove/macosx_usb_hid.h rename to src/p5glove/libp5glove/macosx_usb_hid.h diff --git a/7.x/src/p5glove/libp5glove/p5glove.c b/src/p5glove/libp5glove/p5glove.c similarity index 100% rename from 7.x/src/p5glove/libp5glove/p5glove.c rename to src/p5glove/libp5glove/p5glove.c diff --git a/6.x/src/p5glove/libp5glove/p5glove.h b/src/p5glove/libp5glove/p5glove.h similarity index 100% rename from 6.x/src/p5glove/libp5glove/p5glove.h rename to src/p5glove/libp5glove/p5glove.h diff --git a/6.x/src/p5glove/libp5glove/usb_hid.h b/src/p5glove/libp5glove/usb_hid.h similarity index 100% rename from 6.x/src/p5glove/libp5glove/usb_hid.h rename to src/p5glove/libp5glove/usb_hid.h diff --git a/6.x/src/p5glove/libp5glove/usb_hid_libusb.c b/src/p5glove/libp5glove/usb_hid_libusb.c similarity index 100% rename from 6.x/src/p5glove/libp5glove/usb_hid_libusb.c rename to src/p5glove/libp5glove/usb_hid_libusb.c diff --git a/7.x/src/p5glove/libp5glove/usb_hid_macosx.c b/src/p5glove/libp5glove/usb_hid_macosx.c similarity index 100% rename from 7.x/src/p5glove/libp5glove/usb_hid_macosx.c rename to src/p5glove/libp5glove/usb_hid_macosx.c diff --git a/7.x/src/p5glove/libp5glove/usb_hid_win32.c b/src/p5glove/libp5glove/usb_hid_win32.c similarity index 100% rename from 7.x/src/p5glove/libp5glove/usb_hid_win32.c rename to src/p5glove/libp5glove/usb_hid_win32.c diff --git a/7.x/src/p5glove/p5glove.c b/src/p5glove/p5glove.c similarity index 100% rename from 7.x/src/p5glove/p5glove.c rename to src/p5glove/p5glove.c diff --git a/6.x/src/py/CMakeLists.txt b/src/py/CMakeLists.txt similarity index 100% rename from 6.x/src/py/CMakeLists.txt rename to src/py/CMakeLists.txt diff --git a/6.x/src/py/README.md b/src/py/README.md similarity index 100% rename from 6.x/src/py/README.md rename to src/py/README.md diff --git a/7.x/src/py/examples/cabrera/python0.csd b/src/py/examples/cabrera/python0.csd similarity index 100% rename from 7.x/src/py/examples/cabrera/python0.csd rename to src/py/examples/cabrera/python0.csd diff --git a/7.x/src/py/examples/cabrera/python1.csd b/src/py/examples/cabrera/python1.csd similarity index 100% rename from 7.x/src/py/examples/cabrera/python1.csd rename to src/py/examples/cabrera/python1.csd diff --git a/7.x/src/py/examples/cabrera/python2.csd b/src/py/examples/cabrera/python2.csd similarity index 100% rename from 7.x/src/py/examples/cabrera/python2.csd rename to src/py/examples/cabrera/python2.csd diff --git a/7.x/src/py/examples/cabrera/python3.csd b/src/py/examples/cabrera/python3.csd similarity index 100% rename from 7.x/src/py/examples/cabrera/python3.csd rename to src/py/examples/cabrera/python3.csd diff --git a/7.x/src/py/examples/cabrera/python4.csd b/src/py/examples/cabrera/python4.csd similarity index 100% rename from 7.x/src/py/examples/cabrera/python4.csd rename to src/py/examples/cabrera/python4.csd diff --git a/7.x/src/py/examples/cabrera/python5.csd b/src/py/examples/cabrera/python5.csd similarity index 100% rename from 7.x/src/py/examples/cabrera/python5.csd rename to src/py/examples/cabrera/python5.csd diff --git a/7.x/src/py/examples/cabrera/pythonlocal.csd b/src/py/examples/cabrera/pythonlocal.csd similarity index 100% rename from 7.x/src/py/examples/cabrera/pythonlocal.csd rename to src/py/examples/cabrera/pythonlocal.csd diff --git a/7.x/src/py/examples/cabrera/pythonlocal2.csd b/src/py/examples/cabrera/pythonlocal2.csd similarity index 100% rename from 7.x/src/py/examples/cabrera/pythonlocal2.csd rename to src/py/examples/cabrera/pythonlocal2.csd diff --git a/6.x/src/py/examples/cabrera/pythonmarkov.csd b/src/py/examples/cabrera/pythonmarkov.csd similarity index 100% rename from 6.x/src/py/examples/cabrera/pythonmarkov.csd rename to src/py/examples/cabrera/pythonmarkov.csd diff --git a/6.x/src/py/examples/embeddedCtcsound.csd b/src/py/examples/embeddedCtcsound.csd similarity index 100% rename from 6.x/src/py/examples/embeddedCtcsound.csd rename to src/py/examples/embeddedCtcsound.csd diff --git a/7.x/src/py/examples/ievent.orc b/src/py/examples/ievent.orc similarity index 100% rename from 7.x/src/py/examples/ievent.orc rename to src/py/examples/ievent.orc diff --git a/6.x/src/py/examples/ievent.sco b/src/py/examples/ievent.sco similarity index 100% rename from 6.x/src/py/examples/ievent.sco rename to src/py/examples/ievent.sco diff --git a/6.x/src/py/examples/pyassign.orc b/src/py/examples/pyassign.orc similarity index 100% rename from 6.x/src/py/examples/pyassign.orc rename to src/py/examples/pyassign.orc diff --git a/6.x/src/py/examples/pyassign.sco b/src/py/examples/pyassign.sco similarity index 100% rename from 6.x/src/py/examples/pyassign.sco rename to src/py/examples/pyassign.sco diff --git a/6.x/src/py/examples/pycall1.orc b/src/py/examples/pycall1.orc similarity index 100% rename from 6.x/src/py/examples/pycall1.orc rename to src/py/examples/pycall1.orc diff --git a/6.x/src/py/examples/pycall1.sco b/src/py/examples/pycall1.sco similarity index 100% rename from 6.x/src/py/examples/pycall1.sco rename to src/py/examples/pycall1.sco diff --git a/6.x/src/py/examples/pycall2.orc b/src/py/examples/pycall2.orc similarity index 100% rename from 6.x/src/py/examples/pycall2.orc rename to src/py/examples/pycall2.orc diff --git a/6.x/src/py/examples/pycall2.sco b/src/py/examples/pycall2.sco similarity index 100% rename from 6.x/src/py/examples/pycall2.sco rename to src/py/examples/pycall2.sco diff --git a/6.x/src/py/examples/pycall3.orc b/src/py/examples/pycall3.orc similarity index 100% rename from 6.x/src/py/examples/pycall3.orc rename to src/py/examples/pycall3.orc diff --git a/6.x/src/py/examples/pycall3.sco b/src/py/examples/pycall3.sco similarity index 100% rename from 6.x/src/py/examples/pycall3.sco rename to src/py/examples/pycall3.sco diff --git a/6.x/src/py/examples/pycallt.orc b/src/py/examples/pycallt.orc similarity index 100% rename from 6.x/src/py/examples/pycallt.orc rename to src/py/examples/pycallt.orc diff --git a/6.x/src/py/examples/pycallt.sco b/src/py/examples/pycallt.sco similarity index 100% rename from 6.x/src/py/examples/pycallt.sco rename to src/py/examples/pycallt.sco diff --git a/6.x/src/py/examples/pyeval.orc b/src/py/examples/pyeval.orc similarity index 100% rename from 6.x/src/py/examples/pyeval.orc rename to src/py/examples/pyeval.orc diff --git a/6.x/src/py/examples/pyeval.sco b/src/py/examples/pyeval.sco similarity index 100% rename from 6.x/src/py/examples/pyeval.sco rename to src/py/examples/pyeval.sco diff --git a/6.x/src/py/examples/pyexec.orc b/src/py/examples/pyexec.orc similarity index 100% rename from 6.x/src/py/examples/pyexec.orc rename to src/py/examples/pyexec.orc diff --git a/6.x/src/py/examples/pyexec.sco b/src/py/examples/pyexec.sco similarity index 100% rename from 6.x/src/py/examples/pyexec.sco rename to src/py/examples/pyexec.sco diff --git a/6.x/src/py/examples/pyexec1.py b/src/py/examples/pyexec1.py similarity index 100% rename from 6.x/src/py/examples/pyexec1.py rename to src/py/examples/pyexec1.py diff --git a/6.x/src/py/examples/pyexec2.py b/src/py/examples/pyexec2.py similarity index 100% rename from 6.x/src/py/examples/pyexec2.py rename to src/py/examples/pyexec2.py diff --git a/6.x/src/py/examples/pyexec3.py b/src/py/examples/pyexec3.py similarity index 100% rename from 6.x/src/py/examples/pyexec3.py rename to src/py/examples/pyexec3.py diff --git a/6.x/src/py/examples/pyexec4.py b/src/py/examples/pyexec4.py similarity index 100% rename from 6.x/src/py/examples/pyexec4.py rename to src/py/examples/pyexec4.py diff --git a/6.x/src/py/examples/pyexect.orc b/src/py/examples/pyexect.orc similarity index 100% rename from 6.x/src/py/examples/pyexect.orc rename to src/py/examples/pyexect.orc diff --git a/6.x/src/py/examples/pyexect.sco b/src/py/examples/pyexect.sco similarity index 100% rename from 6.x/src/py/examples/pyexect.sco rename to src/py/examples/pyexect.sco diff --git a/7.x/src/py/examples/pyexect1.py b/src/py/examples/pyexect1.py similarity index 100% rename from 7.x/src/py/examples/pyexect1.py rename to src/py/examples/pyexect1.py diff --git a/7.x/src/py/examples/pyexect2.py b/src/py/examples/pyexect2.py similarity index 100% rename from 7.x/src/py/examples/pyexect2.py rename to src/py/examples/pyexect2.py diff --git a/7.x/src/py/examples/pyexect3.py b/src/py/examples/pyexect3.py similarity index 100% rename from 7.x/src/py/examples/pyexect3.py rename to src/py/examples/pyexect3.py diff --git a/7.x/src/py/examples/pyexect4.py b/src/py/examples/pyexect4.py similarity index 100% rename from 7.x/src/py/examples/pyexect4.py rename to src/py/examples/pyexect4.py diff --git a/6.x/src/py/examples/pyrun.csd b/src/py/examples/pyrun.csd similarity index 100% rename from 6.x/src/py/examples/pyrun.csd rename to src/py/examples/pyrun.csd diff --git a/6.x/src/py/examples/pyrun.orc b/src/py/examples/pyrun.orc similarity index 100% rename from 6.x/src/py/examples/pyrun.orc rename to src/py/examples/pyrun.orc diff --git a/6.x/src/py/examples/pyrun.sco b/src/py/examples/pyrun.sco similarity index 100% rename from 6.x/src/py/examples/pyrun.sco rename to src/py/examples/pyrun.sco diff --git a/6.x/src/py/examples/pyrunt.orc b/src/py/examples/pyrunt.orc similarity index 100% rename from 6.x/src/py/examples/pyrunt.orc rename to src/py/examples/pyrunt.orc diff --git a/6.x/src/py/examples/pyrunt.sco b/src/py/examples/pyrunt.sco similarity index 100% rename from 6.x/src/py/examples/pyrunt.sco rename to src/py/examples/pyrunt.sco diff --git a/6.x/src/py/src/README.md b/src/py/src/README.md similarity index 100% rename from 6.x/src/py/src/README.md rename to src/py/src/README.md diff --git a/7.x/src/py/src/pycall-gen.py b/src/py/src/pycall-gen.py similarity index 100% rename from 7.x/src/py/src/pycall-gen.py rename to src/py/src/pycall-gen.py diff --git a/6.x/src/py/src/pycall.auto.c b/src/py/src/pycall.auto.c similarity index 100% rename from 6.x/src/py/src/pycall.auto.c rename to src/py/src/pycall.auto.c diff --git a/7.x/src/py/src/pycall.auto.h b/src/py/src/pycall.auto.h similarity index 100% rename from 7.x/src/py/src/pycall.auto.h rename to src/py/src/pycall.auto.h diff --git a/7.x/src/py/src/pythonhelper.h b/src/py/src/pythonhelper.h similarity index 100% rename from 7.x/src/py/src/pythonhelper.h rename to src/py/src/pythonhelper.h diff --git a/7.x/src/py/src/pythonopcodes.c b/src/py/src/pythonopcodes.c similarity index 100% rename from 7.x/src/py/src/pythonopcodes.c rename to src/py/src/pythonopcodes.c diff --git a/7.x/src/py/src/pythonopcodes.h b/src/py/src/pythonopcodes.h similarity index 100% rename from 7.x/src/py/src/pythonopcodes.h rename to src/py/src/pythonopcodes.h diff --git a/7.x/src/py/src/pyx-gen.py b/src/py/src/pyx-gen.py similarity index 100% rename from 7.x/src/py/src/pyx-gen.py rename to src/py/src/pyx-gen.py diff --git a/6.x/src/py/src/pyx.auto.c b/src/py/src/pyx.auto.c similarity index 100% rename from 6.x/src/py/src/pyx.auto.c rename to src/py/src/pyx.auto.c diff --git a/7.x/src/py/src/pyx.auto.h b/src/py/src/pyx.auto.h similarity index 100% rename from 7.x/src/py/src/pyx.auto.h rename to src/py/src/pyx.auto.h diff --git a/7.x/src/stk/CMakeLists.txt b/src/stk/CMakeLists.txt similarity index 100% rename from 7.x/src/stk/CMakeLists.txt rename to src/stk/CMakeLists.txt diff --git a/7.x/src/stk/EmbedRawwaves.cmake b/src/stk/EmbedRawwaves.cmake similarity index 100% rename from 7.x/src/stk/EmbedRawwaves.cmake rename to src/stk/EmbedRawwaves.cmake diff --git a/7.x/src/stk/LICENSE b/src/stk/LICENSE similarity index 100% rename from 7.x/src/stk/LICENSE rename to src/stk/LICENSE diff --git a/7.x/src/stk/OpcodeBase.hpp b/src/stk/OpcodeBase.hpp similarity index 100% rename from 7.x/src/stk/OpcodeBase.hpp rename to src/stk/OpcodeBase.hpp diff --git a/7.x/src/stk/STKInstrumentAdapter.hpp b/src/stk/STKInstrumentAdapter.hpp similarity index 100% rename from 7.x/src/stk/STKInstrumentAdapter.hpp rename to src/stk/STKInstrumentAdapter.hpp diff --git a/7.x/src/stk/include/ADSR.h b/src/stk/include/ADSR.h similarity index 100% rename from 7.x/src/stk/include/ADSR.h rename to src/stk/include/ADSR.h diff --git a/7.x/src/stk/include/Asymp.h b/src/stk/include/Asymp.h similarity index 100% rename from 7.x/src/stk/include/Asymp.h rename to src/stk/include/Asymp.h diff --git a/7.x/src/stk/include/BandedWG.h b/src/stk/include/BandedWG.h similarity index 100% rename from 7.x/src/stk/include/BandedWG.h rename to src/stk/include/BandedWG.h diff --git a/7.x/src/stk/include/BeeThree.h b/src/stk/include/BeeThree.h similarity index 100% rename from 7.x/src/stk/include/BeeThree.h rename to src/stk/include/BeeThree.h diff --git a/7.x/src/stk/include/BiQuad.h b/src/stk/include/BiQuad.h similarity index 100% rename from 7.x/src/stk/include/BiQuad.h rename to src/stk/include/BiQuad.h diff --git a/7.x/src/stk/include/Blit.h b/src/stk/include/Blit.h similarity index 100% rename from 7.x/src/stk/include/Blit.h rename to src/stk/include/Blit.h diff --git a/7.x/src/stk/include/BlitSaw.h b/src/stk/include/BlitSaw.h similarity index 100% rename from 7.x/src/stk/include/BlitSaw.h rename to src/stk/include/BlitSaw.h diff --git a/7.x/src/stk/include/BlitSquare.h b/src/stk/include/BlitSquare.h similarity index 100% rename from 7.x/src/stk/include/BlitSquare.h rename to src/stk/include/BlitSquare.h diff --git a/7.x/src/stk/include/BlowBotl.h b/src/stk/include/BlowBotl.h similarity index 100% rename from 7.x/src/stk/include/BlowBotl.h rename to src/stk/include/BlowBotl.h diff --git a/7.x/src/stk/include/BlowHole.h b/src/stk/include/BlowHole.h similarity index 100% rename from 7.x/src/stk/include/BlowHole.h rename to src/stk/include/BlowHole.h diff --git a/7.x/src/stk/include/BowTable.h b/src/stk/include/BowTable.h similarity index 100% rename from 7.x/src/stk/include/BowTable.h rename to src/stk/include/BowTable.h diff --git a/7.x/src/stk/include/Bowed.h b/src/stk/include/Bowed.h similarity index 100% rename from 7.x/src/stk/include/Bowed.h rename to src/stk/include/Bowed.h diff --git a/7.x/src/stk/include/Brass.h b/src/stk/include/Brass.h similarity index 100% rename from 7.x/src/stk/include/Brass.h rename to src/stk/include/Brass.h diff --git a/7.x/src/stk/include/Chorus.h b/src/stk/include/Chorus.h similarity index 100% rename from 7.x/src/stk/include/Chorus.h rename to src/stk/include/Chorus.h diff --git a/7.x/src/stk/include/Clarinet.h b/src/stk/include/Clarinet.h similarity index 100% rename from 7.x/src/stk/include/Clarinet.h rename to src/stk/include/Clarinet.h diff --git a/7.x/src/stk/include/Cubic.h b/src/stk/include/Cubic.h similarity index 100% rename from 7.x/src/stk/include/Cubic.h rename to src/stk/include/Cubic.h diff --git a/7.x/src/stk/include/Delay.h b/src/stk/include/Delay.h similarity index 100% rename from 7.x/src/stk/include/Delay.h rename to src/stk/include/Delay.h diff --git a/7.x/src/stk/include/DelayA.h b/src/stk/include/DelayA.h similarity index 100% rename from 7.x/src/stk/include/DelayA.h rename to src/stk/include/DelayA.h diff --git a/7.x/src/stk/include/DelayL.h b/src/stk/include/DelayL.h similarity index 100% rename from 7.x/src/stk/include/DelayL.h rename to src/stk/include/DelayL.h diff --git a/7.x/src/stk/include/Drummer.h b/src/stk/include/Drummer.h similarity index 100% rename from 7.x/src/stk/include/Drummer.h rename to src/stk/include/Drummer.h diff --git a/7.x/src/stk/include/Echo.h b/src/stk/include/Echo.h similarity index 100% rename from 7.x/src/stk/include/Echo.h rename to src/stk/include/Echo.h diff --git a/7.x/src/stk/include/Effect.h b/src/stk/include/Effect.h similarity index 100% rename from 7.x/src/stk/include/Effect.h rename to src/stk/include/Effect.h diff --git a/7.x/src/stk/include/Envelope.h b/src/stk/include/Envelope.h similarity index 100% rename from 7.x/src/stk/include/Envelope.h rename to src/stk/include/Envelope.h diff --git a/7.x/src/stk/include/FM.h b/src/stk/include/FM.h similarity index 100% rename from 7.x/src/stk/include/FM.h rename to src/stk/include/FM.h diff --git a/7.x/src/stk/include/FMVoices.h b/src/stk/include/FMVoices.h similarity index 100% rename from 7.x/src/stk/include/FMVoices.h rename to src/stk/include/FMVoices.h diff --git a/7.x/src/stk/include/FileLoop.h b/src/stk/include/FileLoop.h similarity index 100% rename from 7.x/src/stk/include/FileLoop.h rename to src/stk/include/FileLoop.h diff --git a/7.x/src/stk/include/FileRead.h b/src/stk/include/FileRead.h similarity index 100% rename from 7.x/src/stk/include/FileRead.h rename to src/stk/include/FileRead.h diff --git a/7.x/src/stk/include/FileWrite.h b/src/stk/include/FileWrite.h similarity index 100% rename from 7.x/src/stk/include/FileWrite.h rename to src/stk/include/FileWrite.h diff --git a/7.x/src/stk/include/FileWvIn.h b/src/stk/include/FileWvIn.h similarity index 100% rename from 7.x/src/stk/include/FileWvIn.h rename to src/stk/include/FileWvIn.h diff --git a/7.x/src/stk/include/FileWvOut.h b/src/stk/include/FileWvOut.h similarity index 100% rename from 7.x/src/stk/include/FileWvOut.h rename to src/stk/include/FileWvOut.h diff --git a/7.x/src/stk/include/Filter.h b/src/stk/include/Filter.h similarity index 100% rename from 7.x/src/stk/include/Filter.h rename to src/stk/include/Filter.h diff --git a/7.x/src/stk/include/Fir.h b/src/stk/include/Fir.h similarity index 100% rename from 7.x/src/stk/include/Fir.h rename to src/stk/include/Fir.h diff --git a/7.x/src/stk/include/Flute.h b/src/stk/include/Flute.h similarity index 100% rename from 7.x/src/stk/include/Flute.h rename to src/stk/include/Flute.h diff --git a/7.x/src/stk/include/FormSwep.h b/src/stk/include/FormSwep.h similarity index 100% rename from 7.x/src/stk/include/FormSwep.h rename to src/stk/include/FormSwep.h diff --git a/7.x/src/stk/include/FreeVerb.h b/src/stk/include/FreeVerb.h similarity index 100% rename from 7.x/src/stk/include/FreeVerb.h rename to src/stk/include/FreeVerb.h diff --git a/7.x/src/stk/include/Function.h b/src/stk/include/Function.h similarity index 100% rename from 7.x/src/stk/include/Function.h rename to src/stk/include/Function.h diff --git a/7.x/src/stk/include/Generator.h b/src/stk/include/Generator.h similarity index 100% rename from 7.x/src/stk/include/Generator.h rename to src/stk/include/Generator.h diff --git a/7.x/src/stk/include/Granulate.h b/src/stk/include/Granulate.h similarity index 100% rename from 7.x/src/stk/include/Granulate.h rename to src/stk/include/Granulate.h diff --git a/7.x/src/stk/include/Guitar.h b/src/stk/include/Guitar.h similarity index 100% rename from 7.x/src/stk/include/Guitar.h rename to src/stk/include/Guitar.h diff --git a/7.x/src/stk/include/HevyMetl.h b/src/stk/include/HevyMetl.h similarity index 100% rename from 7.x/src/stk/include/HevyMetl.h rename to src/stk/include/HevyMetl.h diff --git a/7.x/src/stk/include/Iir.h b/src/stk/include/Iir.h similarity index 100% rename from 7.x/src/stk/include/Iir.h rename to src/stk/include/Iir.h diff --git a/7.x/src/stk/include/Instrmnt.h b/src/stk/include/Instrmnt.h similarity index 100% rename from 7.x/src/stk/include/Instrmnt.h rename to src/stk/include/Instrmnt.h diff --git a/7.x/src/stk/include/JCRev.h b/src/stk/include/JCRev.h similarity index 100% rename from 7.x/src/stk/include/JCRev.h rename to src/stk/include/JCRev.h diff --git a/7.x/src/stk/include/JetTable.h b/src/stk/include/JetTable.h similarity index 100% rename from 7.x/src/stk/include/JetTable.h rename to src/stk/include/JetTable.h diff --git a/7.x/src/stk/include/LentPitShift.h b/src/stk/include/LentPitShift.h similarity index 100% rename from 7.x/src/stk/include/LentPitShift.h rename to src/stk/include/LentPitShift.h diff --git a/7.x/src/stk/include/Mandolin.h b/src/stk/include/Mandolin.h similarity index 100% rename from 7.x/src/stk/include/Mandolin.h rename to src/stk/include/Mandolin.h diff --git a/7.x/src/stk/include/Mesh2D.h b/src/stk/include/Mesh2D.h similarity index 100% rename from 7.x/src/stk/include/Mesh2D.h rename to src/stk/include/Mesh2D.h diff --git a/7.x/src/stk/include/MidiFileIn.h b/src/stk/include/MidiFileIn.h similarity index 100% rename from 7.x/src/stk/include/MidiFileIn.h rename to src/stk/include/MidiFileIn.h diff --git a/7.x/src/stk/include/Modal.h b/src/stk/include/Modal.h similarity index 100% rename from 7.x/src/stk/include/Modal.h rename to src/stk/include/Modal.h diff --git a/7.x/src/stk/include/ModalBar.h b/src/stk/include/ModalBar.h similarity index 100% rename from 7.x/src/stk/include/ModalBar.h rename to src/stk/include/ModalBar.h diff --git a/7.x/src/stk/include/Modulate.h b/src/stk/include/Modulate.h similarity index 100% rename from 7.x/src/stk/include/Modulate.h rename to src/stk/include/Modulate.h diff --git a/7.x/src/stk/include/Moog.h b/src/stk/include/Moog.h similarity index 100% rename from 7.x/src/stk/include/Moog.h rename to src/stk/include/Moog.h diff --git a/7.x/src/stk/include/NRev.h b/src/stk/include/NRev.h similarity index 100% rename from 7.x/src/stk/include/NRev.h rename to src/stk/include/NRev.h diff --git a/7.x/src/stk/include/Noise.h b/src/stk/include/Noise.h similarity index 100% rename from 7.x/src/stk/include/Noise.h rename to src/stk/include/Noise.h diff --git a/7.x/src/stk/include/OnePole.h b/src/stk/include/OnePole.h similarity index 100% rename from 7.x/src/stk/include/OnePole.h rename to src/stk/include/OnePole.h diff --git a/7.x/src/stk/include/OneZero.h b/src/stk/include/OneZero.h similarity index 100% rename from 7.x/src/stk/include/OneZero.h rename to src/stk/include/OneZero.h diff --git a/7.x/src/stk/include/PRCRev.h b/src/stk/include/PRCRev.h similarity index 100% rename from 7.x/src/stk/include/PRCRev.h rename to src/stk/include/PRCRev.h diff --git a/7.x/src/stk/include/PercFlut.h b/src/stk/include/PercFlut.h similarity index 100% rename from 7.x/src/stk/include/PercFlut.h rename to src/stk/include/PercFlut.h diff --git a/7.x/src/stk/include/Phonemes.h b/src/stk/include/Phonemes.h similarity index 100% rename from 7.x/src/stk/include/Phonemes.h rename to src/stk/include/Phonemes.h diff --git a/7.x/src/stk/include/PitShift.h b/src/stk/include/PitShift.h similarity index 100% rename from 7.x/src/stk/include/PitShift.h rename to src/stk/include/PitShift.h diff --git a/7.x/src/stk/include/Plucked.h b/src/stk/include/Plucked.h similarity index 100% rename from 7.x/src/stk/include/Plucked.h rename to src/stk/include/Plucked.h diff --git a/7.x/src/stk/include/PoleZero.h b/src/stk/include/PoleZero.h similarity index 100% rename from 7.x/src/stk/include/PoleZero.h rename to src/stk/include/PoleZero.h diff --git a/7.x/src/stk/include/Recorder.h b/src/stk/include/Recorder.h similarity index 100% rename from 7.x/src/stk/include/Recorder.h rename to src/stk/include/Recorder.h diff --git a/7.x/src/stk/include/ReedTable.h b/src/stk/include/ReedTable.h similarity index 100% rename from 7.x/src/stk/include/ReedTable.h rename to src/stk/include/ReedTable.h diff --git a/7.x/src/stk/include/Resonate.h b/src/stk/include/Resonate.h similarity index 100% rename from 7.x/src/stk/include/Resonate.h rename to src/stk/include/Resonate.h diff --git a/7.x/src/stk/include/Rhodey.h b/src/stk/include/Rhodey.h similarity index 100% rename from 7.x/src/stk/include/Rhodey.h rename to src/stk/include/Rhodey.h diff --git a/7.x/src/stk/include/SKINImsg.h b/src/stk/include/SKINImsg.h similarity index 100% rename from 7.x/src/stk/include/SKINImsg.h rename to src/stk/include/SKINImsg.h diff --git a/7.x/src/stk/include/SKINItbl.h b/src/stk/include/SKINItbl.h similarity index 100% rename from 7.x/src/stk/include/SKINItbl.h rename to src/stk/include/SKINItbl.h diff --git a/7.x/src/stk/include/Sampler.h b/src/stk/include/Sampler.h similarity index 100% rename from 7.x/src/stk/include/Sampler.h rename to src/stk/include/Sampler.h diff --git a/7.x/src/stk/include/Saxofony.h b/src/stk/include/Saxofony.h similarity index 100% rename from 7.x/src/stk/include/Saxofony.h rename to src/stk/include/Saxofony.h diff --git a/7.x/src/stk/include/Shakers.h b/src/stk/include/Shakers.h similarity index 100% rename from 7.x/src/stk/include/Shakers.h rename to src/stk/include/Shakers.h diff --git a/7.x/src/stk/include/Simple.h b/src/stk/include/Simple.h similarity index 100% rename from 7.x/src/stk/include/Simple.h rename to src/stk/include/Simple.h diff --git a/7.x/src/stk/include/SineWave.h b/src/stk/include/SineWave.h similarity index 100% rename from 7.x/src/stk/include/SineWave.h rename to src/stk/include/SineWave.h diff --git a/7.x/src/stk/include/SingWave.h b/src/stk/include/SingWave.h similarity index 100% rename from 7.x/src/stk/include/SingWave.h rename to src/stk/include/SingWave.h diff --git a/7.x/src/stk/include/Sitar.h b/src/stk/include/Sitar.h similarity index 100% rename from 7.x/src/stk/include/Sitar.h rename to src/stk/include/Sitar.h diff --git a/7.x/src/stk/include/Skini.h b/src/stk/include/Skini.h similarity index 100% rename from 7.x/src/stk/include/Skini.h rename to src/stk/include/Skini.h diff --git a/7.x/src/stk/include/Sphere.h b/src/stk/include/Sphere.h similarity index 100% rename from 7.x/src/stk/include/Sphere.h rename to src/stk/include/Sphere.h diff --git a/7.x/src/stk/include/StifKarp.h b/src/stk/include/StifKarp.h similarity index 100% rename from 7.x/src/stk/include/StifKarp.h rename to src/stk/include/StifKarp.h diff --git a/7.x/src/stk/include/Stk.h b/src/stk/include/Stk.h similarity index 100% rename from 7.x/src/stk/include/Stk.h rename to src/stk/include/Stk.h diff --git a/7.x/src/stk/include/TapDelay.h b/src/stk/include/TapDelay.h similarity index 100% rename from 7.x/src/stk/include/TapDelay.h rename to src/stk/include/TapDelay.h diff --git a/7.x/src/stk/include/TubeBell.h b/src/stk/include/TubeBell.h similarity index 100% rename from 7.x/src/stk/include/TubeBell.h rename to src/stk/include/TubeBell.h diff --git a/7.x/src/stk/include/Twang.h b/src/stk/include/Twang.h similarity index 100% rename from 7.x/src/stk/include/Twang.h rename to src/stk/include/Twang.h diff --git a/7.x/src/stk/include/TwoPole.h b/src/stk/include/TwoPole.h similarity index 100% rename from 7.x/src/stk/include/TwoPole.h rename to src/stk/include/TwoPole.h diff --git a/7.x/src/stk/include/TwoZero.h b/src/stk/include/TwoZero.h similarity index 100% rename from 7.x/src/stk/include/TwoZero.h rename to src/stk/include/TwoZero.h diff --git a/7.x/src/stk/include/Vector3D.h b/src/stk/include/Vector3D.h similarity index 100% rename from 7.x/src/stk/include/Vector3D.h rename to src/stk/include/Vector3D.h diff --git a/7.x/src/stk/include/VoicForm.h b/src/stk/include/VoicForm.h similarity index 100% rename from 7.x/src/stk/include/VoicForm.h rename to src/stk/include/VoicForm.h diff --git a/7.x/src/stk/include/Voicer.h b/src/stk/include/Voicer.h similarity index 100% rename from 7.x/src/stk/include/Voicer.h rename to src/stk/include/Voicer.h diff --git a/7.x/src/stk/include/Whistle.h b/src/stk/include/Whistle.h similarity index 100% rename from 7.x/src/stk/include/Whistle.h rename to src/stk/include/Whistle.h diff --git a/7.x/src/stk/include/Wurley.h b/src/stk/include/Wurley.h similarity index 100% rename from 7.x/src/stk/include/Wurley.h rename to src/stk/include/Wurley.h diff --git a/7.x/src/stk/include/WvIn.h b/src/stk/include/WvIn.h similarity index 100% rename from 7.x/src/stk/include/WvIn.h rename to src/stk/include/WvIn.h diff --git a/7.x/src/stk/include/WvOut.h b/src/stk/include/WvOut.h similarity index 100% rename from 7.x/src/stk/include/WvOut.h rename to src/stk/include/WvOut.h diff --git a/7.x/src/stk/rawwaves/ahh.raw b/src/stk/rawwaves/ahh.raw similarity index 100% rename from 7.x/src/stk/rawwaves/ahh.raw rename to src/stk/rawwaves/ahh.raw diff --git a/7.x/src/stk/rawwaves/bassdrum.raw b/src/stk/rawwaves/bassdrum.raw similarity index 100% rename from 7.x/src/stk/rawwaves/bassdrum.raw rename to src/stk/rawwaves/bassdrum.raw diff --git a/7.x/src/stk/rawwaves/britestk.raw b/src/stk/rawwaves/britestk.raw similarity index 100% rename from 7.x/src/stk/rawwaves/britestk.raw rename to src/stk/rawwaves/britestk.raw diff --git a/7.x/src/stk/rawwaves/cowbell1.raw b/src/stk/rawwaves/cowbell1.raw similarity index 100% rename from 7.x/src/stk/rawwaves/cowbell1.raw rename to src/stk/rawwaves/cowbell1.raw diff --git a/7.x/src/stk/rawwaves/crashcym.raw b/src/stk/rawwaves/crashcym.raw similarity index 100% rename from 7.x/src/stk/rawwaves/crashcym.raw rename to src/stk/rawwaves/crashcym.raw diff --git a/7.x/src/stk/rawwaves/dope.raw b/src/stk/rawwaves/dope.raw similarity index 100% rename from 7.x/src/stk/rawwaves/dope.raw rename to src/stk/rawwaves/dope.raw diff --git a/7.x/src/stk/rawwaves/eee.raw b/src/stk/rawwaves/eee.raw similarity index 100% rename from 7.x/src/stk/rawwaves/eee.raw rename to src/stk/rawwaves/eee.raw diff --git a/7.x/src/stk/rawwaves/fwavblnk.raw b/src/stk/rawwaves/fwavblnk.raw similarity index 100% rename from 7.x/src/stk/rawwaves/fwavblnk.raw rename to src/stk/rawwaves/fwavblnk.raw diff --git a/7.x/src/stk/rawwaves/halfwave.raw b/src/stk/rawwaves/halfwave.raw similarity index 100% rename from 7.x/src/stk/rawwaves/halfwave.raw rename to src/stk/rawwaves/halfwave.raw diff --git a/7.x/src/stk/rawwaves/hihatcym.raw b/src/stk/rawwaves/hihatcym.raw similarity index 100% rename from 7.x/src/stk/rawwaves/hihatcym.raw rename to src/stk/rawwaves/hihatcym.raw diff --git a/7.x/src/stk/rawwaves/impuls10.raw b/src/stk/rawwaves/impuls10.raw similarity index 100% rename from 7.x/src/stk/rawwaves/impuls10.raw rename to src/stk/rawwaves/impuls10.raw diff --git a/7.x/src/stk/rawwaves/impuls20.raw b/src/stk/rawwaves/impuls20.raw similarity index 100% rename from 7.x/src/stk/rawwaves/impuls20.raw rename to src/stk/rawwaves/impuls20.raw diff --git a/7.x/src/stk/rawwaves/impuls40.raw b/src/stk/rawwaves/impuls40.raw similarity index 100% rename from 7.x/src/stk/rawwaves/impuls40.raw rename to src/stk/rawwaves/impuls40.raw diff --git a/7.x/src/stk/rawwaves/makefunc.c b/src/stk/rawwaves/makefunc.c similarity index 100% rename from 7.x/src/stk/rawwaves/makefunc.c rename to src/stk/rawwaves/makefunc.c diff --git a/7.x/src/stk/rawwaves/makemidi.c b/src/stk/rawwaves/makemidi.c similarity index 100% rename from 7.x/src/stk/rawwaves/makemidi.c rename to src/stk/rawwaves/makemidi.c diff --git a/7.x/src/stk/rawwaves/makewavs.c b/src/stk/rawwaves/makewavs.c similarity index 100% rename from 7.x/src/stk/rawwaves/makewavs.c rename to src/stk/rawwaves/makewavs.c diff --git a/7.x/src/stk/rawwaves/mand1.raw b/src/stk/rawwaves/mand1.raw similarity index 100% rename from 7.x/src/stk/rawwaves/mand1.raw rename to src/stk/rawwaves/mand1.raw diff --git a/7.x/src/stk/rawwaves/mand10.raw b/src/stk/rawwaves/mand10.raw similarity index 100% rename from 7.x/src/stk/rawwaves/mand10.raw rename to src/stk/rawwaves/mand10.raw diff --git a/7.x/src/stk/rawwaves/mand11.raw b/src/stk/rawwaves/mand11.raw similarity index 100% rename from 7.x/src/stk/rawwaves/mand11.raw rename to src/stk/rawwaves/mand11.raw diff --git a/7.x/src/stk/rawwaves/mand12.raw b/src/stk/rawwaves/mand12.raw similarity index 100% rename from 7.x/src/stk/rawwaves/mand12.raw rename to src/stk/rawwaves/mand12.raw diff --git a/7.x/src/stk/rawwaves/mand2.raw b/src/stk/rawwaves/mand2.raw similarity index 100% rename from 7.x/src/stk/rawwaves/mand2.raw rename to src/stk/rawwaves/mand2.raw diff --git a/7.x/src/stk/rawwaves/mand3.raw b/src/stk/rawwaves/mand3.raw similarity index 100% rename from 7.x/src/stk/rawwaves/mand3.raw rename to src/stk/rawwaves/mand3.raw diff --git a/7.x/src/stk/rawwaves/mand4.raw b/src/stk/rawwaves/mand4.raw similarity index 100% rename from 7.x/src/stk/rawwaves/mand4.raw rename to src/stk/rawwaves/mand4.raw diff --git a/7.x/src/stk/rawwaves/mand5.raw b/src/stk/rawwaves/mand5.raw similarity index 100% rename from 7.x/src/stk/rawwaves/mand5.raw rename to src/stk/rawwaves/mand5.raw diff --git a/7.x/src/stk/rawwaves/mand6.raw b/src/stk/rawwaves/mand6.raw similarity index 100% rename from 7.x/src/stk/rawwaves/mand6.raw rename to src/stk/rawwaves/mand6.raw diff --git a/7.x/src/stk/rawwaves/mand7.raw b/src/stk/rawwaves/mand7.raw similarity index 100% rename from 7.x/src/stk/rawwaves/mand7.raw rename to src/stk/rawwaves/mand7.raw diff --git a/7.x/src/stk/rawwaves/mand8.raw b/src/stk/rawwaves/mand8.raw similarity index 100% rename from 7.x/src/stk/rawwaves/mand8.raw rename to src/stk/rawwaves/mand8.raw diff --git a/7.x/src/stk/rawwaves/mand9.raw b/src/stk/rawwaves/mand9.raw similarity index 100% rename from 7.x/src/stk/rawwaves/mand9.raw rename to src/stk/rawwaves/mand9.raw diff --git a/7.x/src/stk/rawwaves/mandpluk.raw b/src/stk/rawwaves/mandpluk.raw similarity index 100% rename from 7.x/src/stk/rawwaves/mandpluk.raw rename to src/stk/rawwaves/mandpluk.raw diff --git a/7.x/src/stk/rawwaves/marmstk1.raw b/src/stk/rawwaves/marmstk1.raw similarity index 100% rename from 7.x/src/stk/rawwaves/marmstk1.raw rename to src/stk/rawwaves/marmstk1.raw diff --git a/7.x/src/stk/rawwaves/ooo.raw b/src/stk/rawwaves/ooo.raw similarity index 100% rename from 7.x/src/stk/rawwaves/ooo.raw rename to src/stk/rawwaves/ooo.raw diff --git a/7.x/src/stk/rawwaves/peksblnk.raw b/src/stk/rawwaves/peksblnk.raw similarity index 100% rename from 7.x/src/stk/rawwaves/peksblnk.raw rename to src/stk/rawwaves/peksblnk.raw diff --git a/7.x/src/stk/rawwaves/ppksblnk.raw b/src/stk/rawwaves/ppksblnk.raw similarity index 100% rename from 7.x/src/stk/rawwaves/ppksblnk.raw rename to src/stk/rawwaves/ppksblnk.raw diff --git a/7.x/src/stk/rawwaves/ridecymb.raw b/src/stk/rawwaves/ridecymb.raw similarity index 100% rename from 7.x/src/stk/rawwaves/ridecymb.raw rename to src/stk/rawwaves/ridecymb.raw diff --git a/7.x/src/stk/rawwaves/silence.raw b/src/stk/rawwaves/silence.raw similarity index 100% rename from 7.x/src/stk/rawwaves/silence.raw rename to src/stk/rawwaves/silence.raw diff --git a/7.x/src/stk/rawwaves/sine.c b/src/stk/rawwaves/sine.c similarity index 100% rename from 7.x/src/stk/rawwaves/sine.c rename to src/stk/rawwaves/sine.c diff --git a/7.x/src/stk/rawwaves/sineblnk.raw b/src/stk/rawwaves/sineblnk.raw similarity index 100% rename from 7.x/src/stk/rawwaves/sineblnk.raw rename to src/stk/rawwaves/sineblnk.raw diff --git a/7.x/src/stk/rawwaves/sinewave.raw b/src/stk/rawwaves/sinewave.raw similarity index 100% rename from 7.x/src/stk/rawwaves/sinewave.raw rename to src/stk/rawwaves/sinewave.raw diff --git a/7.x/src/stk/rawwaves/snardrum.raw b/src/stk/rawwaves/snardrum.raw similarity index 100% rename from 7.x/src/stk/rawwaves/snardrum.raw rename to src/stk/rawwaves/snardrum.raw diff --git a/7.x/src/stk/rawwaves/snglpeak.raw b/src/stk/rawwaves/snglpeak.raw similarity index 100% rename from 7.x/src/stk/rawwaves/snglpeak.raw rename to src/stk/rawwaves/snglpeak.raw diff --git a/7.x/src/stk/rawwaves/tambourn.raw b/src/stk/rawwaves/tambourn.raw similarity index 100% rename from 7.x/src/stk/rawwaves/tambourn.raw rename to src/stk/rawwaves/tambourn.raw diff --git a/7.x/src/stk/rawwaves/tomhidrm.raw b/src/stk/rawwaves/tomhidrm.raw similarity index 100% rename from 7.x/src/stk/rawwaves/tomhidrm.raw rename to src/stk/rawwaves/tomhidrm.raw diff --git a/7.x/src/stk/rawwaves/tomlowdr.raw b/src/stk/rawwaves/tomlowdr.raw similarity index 100% rename from 7.x/src/stk/rawwaves/tomlowdr.raw rename to src/stk/rawwaves/tomlowdr.raw diff --git a/7.x/src/stk/rawwaves/tommiddr.raw b/src/stk/rawwaves/tommiddr.raw similarity index 100% rename from 7.x/src/stk/rawwaves/tommiddr.raw rename to src/stk/rawwaves/tommiddr.raw diff --git a/7.x/src/stk/rawwaves/twopeaks.raw b/src/stk/rawwaves/twopeaks.raw similarity index 100% rename from 7.x/src/stk/rawwaves/twopeaks.raw rename to src/stk/rawwaves/twopeaks.raw diff --git a/7.x/src/stk/src/ADSR.cpp b/src/stk/src/ADSR.cpp similarity index 100% rename from 7.x/src/stk/src/ADSR.cpp rename to src/stk/src/ADSR.cpp diff --git a/7.x/src/stk/src/Asymp.cpp b/src/stk/src/Asymp.cpp similarity index 100% rename from 7.x/src/stk/src/Asymp.cpp rename to src/stk/src/Asymp.cpp diff --git a/7.x/src/stk/src/BandedWG.cpp b/src/stk/src/BandedWG.cpp similarity index 100% rename from 7.x/src/stk/src/BandedWG.cpp rename to src/stk/src/BandedWG.cpp diff --git a/7.x/src/stk/src/BeeThree.cpp b/src/stk/src/BeeThree.cpp similarity index 100% rename from 7.x/src/stk/src/BeeThree.cpp rename to src/stk/src/BeeThree.cpp diff --git a/7.x/src/stk/src/BiQuad.cpp b/src/stk/src/BiQuad.cpp similarity index 100% rename from 7.x/src/stk/src/BiQuad.cpp rename to src/stk/src/BiQuad.cpp diff --git a/7.x/src/stk/src/Blit.cpp b/src/stk/src/Blit.cpp similarity index 100% rename from 7.x/src/stk/src/Blit.cpp rename to src/stk/src/Blit.cpp diff --git a/7.x/src/stk/src/BlitSaw.cpp b/src/stk/src/BlitSaw.cpp similarity index 100% rename from 7.x/src/stk/src/BlitSaw.cpp rename to src/stk/src/BlitSaw.cpp diff --git a/7.x/src/stk/src/BlitSquare.cpp b/src/stk/src/BlitSquare.cpp similarity index 100% rename from 7.x/src/stk/src/BlitSquare.cpp rename to src/stk/src/BlitSquare.cpp diff --git a/7.x/src/stk/src/BlowBotl.cpp b/src/stk/src/BlowBotl.cpp similarity index 100% rename from 7.x/src/stk/src/BlowBotl.cpp rename to src/stk/src/BlowBotl.cpp diff --git a/7.x/src/stk/src/BlowHole.cpp b/src/stk/src/BlowHole.cpp similarity index 100% rename from 7.x/src/stk/src/BlowHole.cpp rename to src/stk/src/BlowHole.cpp diff --git a/7.x/src/stk/src/Bowed.cpp b/src/stk/src/Bowed.cpp similarity index 100% rename from 7.x/src/stk/src/Bowed.cpp rename to src/stk/src/Bowed.cpp diff --git a/7.x/src/stk/src/Brass.cpp b/src/stk/src/Brass.cpp similarity index 100% rename from 7.x/src/stk/src/Brass.cpp rename to src/stk/src/Brass.cpp diff --git a/7.x/src/stk/src/Chorus.cpp b/src/stk/src/Chorus.cpp similarity index 100% rename from 7.x/src/stk/src/Chorus.cpp rename to src/stk/src/Chorus.cpp diff --git a/7.x/src/stk/src/Clarinet.cpp b/src/stk/src/Clarinet.cpp similarity index 100% rename from 7.x/src/stk/src/Clarinet.cpp rename to src/stk/src/Clarinet.cpp diff --git a/7.x/src/stk/src/Delay.cpp b/src/stk/src/Delay.cpp similarity index 100% rename from 7.x/src/stk/src/Delay.cpp rename to src/stk/src/Delay.cpp diff --git a/7.x/src/stk/src/DelayA.cpp b/src/stk/src/DelayA.cpp similarity index 100% rename from 7.x/src/stk/src/DelayA.cpp rename to src/stk/src/DelayA.cpp diff --git a/7.x/src/stk/src/DelayL.cpp b/src/stk/src/DelayL.cpp similarity index 100% rename from 7.x/src/stk/src/DelayL.cpp rename to src/stk/src/DelayL.cpp diff --git a/7.x/src/stk/src/Drummer.cpp b/src/stk/src/Drummer.cpp similarity index 100% rename from 7.x/src/stk/src/Drummer.cpp rename to src/stk/src/Drummer.cpp diff --git a/7.x/src/stk/src/Echo.cpp b/src/stk/src/Echo.cpp similarity index 100% rename from 7.x/src/stk/src/Echo.cpp rename to src/stk/src/Echo.cpp diff --git a/7.x/src/stk/src/Envelope.cpp b/src/stk/src/Envelope.cpp similarity index 100% rename from 7.x/src/stk/src/Envelope.cpp rename to src/stk/src/Envelope.cpp diff --git a/7.x/src/stk/src/FM.cpp b/src/stk/src/FM.cpp similarity index 100% rename from 7.x/src/stk/src/FM.cpp rename to src/stk/src/FM.cpp diff --git a/7.x/src/stk/src/FMVoices.cpp b/src/stk/src/FMVoices.cpp similarity index 100% rename from 7.x/src/stk/src/FMVoices.cpp rename to src/stk/src/FMVoices.cpp diff --git a/7.x/src/stk/src/FileLoop.cpp b/src/stk/src/FileLoop.cpp similarity index 100% rename from 7.x/src/stk/src/FileLoop.cpp rename to src/stk/src/FileLoop.cpp diff --git a/7.x/src/stk/src/FileRead.cpp b/src/stk/src/FileRead.cpp similarity index 100% rename from 7.x/src/stk/src/FileRead.cpp rename to src/stk/src/FileRead.cpp diff --git a/7.x/src/stk/src/FileWrite.cpp b/src/stk/src/FileWrite.cpp similarity index 100% rename from 7.x/src/stk/src/FileWrite.cpp rename to src/stk/src/FileWrite.cpp diff --git a/7.x/src/stk/src/FileWvIn.cpp b/src/stk/src/FileWvIn.cpp similarity index 100% rename from 7.x/src/stk/src/FileWvIn.cpp rename to src/stk/src/FileWvIn.cpp diff --git a/7.x/src/stk/src/FileWvOut.cpp b/src/stk/src/FileWvOut.cpp similarity index 100% rename from 7.x/src/stk/src/FileWvOut.cpp rename to src/stk/src/FileWvOut.cpp diff --git a/7.x/src/stk/src/Fir.cpp b/src/stk/src/Fir.cpp similarity index 100% rename from 7.x/src/stk/src/Fir.cpp rename to src/stk/src/Fir.cpp diff --git a/7.x/src/stk/src/Flute.cpp b/src/stk/src/Flute.cpp similarity index 100% rename from 7.x/src/stk/src/Flute.cpp rename to src/stk/src/Flute.cpp diff --git a/7.x/src/stk/src/FormSwep.cpp b/src/stk/src/FormSwep.cpp similarity index 100% rename from 7.x/src/stk/src/FormSwep.cpp rename to src/stk/src/FormSwep.cpp diff --git a/7.x/src/stk/src/FreeVerb.cpp b/src/stk/src/FreeVerb.cpp similarity index 100% rename from 7.x/src/stk/src/FreeVerb.cpp rename to src/stk/src/FreeVerb.cpp diff --git a/7.x/src/stk/src/Granulate.cpp b/src/stk/src/Granulate.cpp similarity index 100% rename from 7.x/src/stk/src/Granulate.cpp rename to src/stk/src/Granulate.cpp diff --git a/7.x/src/stk/src/Guitar.cpp b/src/stk/src/Guitar.cpp similarity index 100% rename from 7.x/src/stk/src/Guitar.cpp rename to src/stk/src/Guitar.cpp diff --git a/7.x/src/stk/src/HevyMetl.cpp b/src/stk/src/HevyMetl.cpp similarity index 100% rename from 7.x/src/stk/src/HevyMetl.cpp rename to src/stk/src/HevyMetl.cpp diff --git a/7.x/src/stk/src/Iir.cpp b/src/stk/src/Iir.cpp similarity index 100% rename from 7.x/src/stk/src/Iir.cpp rename to src/stk/src/Iir.cpp diff --git a/7.x/src/stk/src/JCRev.cpp b/src/stk/src/JCRev.cpp similarity index 100% rename from 7.x/src/stk/src/JCRev.cpp rename to src/stk/src/JCRev.cpp diff --git a/7.x/src/stk/src/LentPitShift.cpp b/src/stk/src/LentPitShift.cpp similarity index 100% rename from 7.x/src/stk/src/LentPitShift.cpp rename to src/stk/src/LentPitShift.cpp diff --git a/7.x/src/stk/src/Mandolin.cpp b/src/stk/src/Mandolin.cpp similarity index 100% rename from 7.x/src/stk/src/Mandolin.cpp rename to src/stk/src/Mandolin.cpp diff --git a/7.x/src/stk/src/Mesh2D.cpp b/src/stk/src/Mesh2D.cpp similarity index 100% rename from 7.x/src/stk/src/Mesh2D.cpp rename to src/stk/src/Mesh2D.cpp diff --git a/7.x/src/stk/src/MidiFileIn.cpp b/src/stk/src/MidiFileIn.cpp similarity index 100% rename from 7.x/src/stk/src/MidiFileIn.cpp rename to src/stk/src/MidiFileIn.cpp diff --git a/7.x/src/stk/src/Modal.cpp b/src/stk/src/Modal.cpp similarity index 100% rename from 7.x/src/stk/src/Modal.cpp rename to src/stk/src/Modal.cpp diff --git a/7.x/src/stk/src/ModalBar.cpp b/src/stk/src/ModalBar.cpp similarity index 100% rename from 7.x/src/stk/src/ModalBar.cpp rename to src/stk/src/ModalBar.cpp diff --git a/7.x/src/stk/src/Modulate.cpp b/src/stk/src/Modulate.cpp similarity index 100% rename from 7.x/src/stk/src/Modulate.cpp rename to src/stk/src/Modulate.cpp diff --git a/7.x/src/stk/src/Moog.cpp b/src/stk/src/Moog.cpp similarity index 100% rename from 7.x/src/stk/src/Moog.cpp rename to src/stk/src/Moog.cpp diff --git a/7.x/src/stk/src/NRev.cpp b/src/stk/src/NRev.cpp similarity index 100% rename from 7.x/src/stk/src/NRev.cpp rename to src/stk/src/NRev.cpp diff --git a/7.x/src/stk/src/Noise.cpp b/src/stk/src/Noise.cpp similarity index 100% rename from 7.x/src/stk/src/Noise.cpp rename to src/stk/src/Noise.cpp diff --git a/7.x/src/stk/src/OnePole.cpp b/src/stk/src/OnePole.cpp similarity index 100% rename from 7.x/src/stk/src/OnePole.cpp rename to src/stk/src/OnePole.cpp diff --git a/7.x/src/stk/src/OneZero.cpp b/src/stk/src/OneZero.cpp similarity index 100% rename from 7.x/src/stk/src/OneZero.cpp rename to src/stk/src/OneZero.cpp diff --git a/7.x/src/stk/src/PRCRev.cpp b/src/stk/src/PRCRev.cpp similarity index 100% rename from 7.x/src/stk/src/PRCRev.cpp rename to src/stk/src/PRCRev.cpp diff --git a/7.x/src/stk/src/PercFlut.cpp b/src/stk/src/PercFlut.cpp similarity index 100% rename from 7.x/src/stk/src/PercFlut.cpp rename to src/stk/src/PercFlut.cpp diff --git a/7.x/src/stk/src/Phonemes.cpp b/src/stk/src/Phonemes.cpp similarity index 100% rename from 7.x/src/stk/src/Phonemes.cpp rename to src/stk/src/Phonemes.cpp diff --git a/7.x/src/stk/src/PitShift.cpp b/src/stk/src/PitShift.cpp similarity index 100% rename from 7.x/src/stk/src/PitShift.cpp rename to src/stk/src/PitShift.cpp diff --git a/7.x/src/stk/src/Plucked.cpp b/src/stk/src/Plucked.cpp similarity index 100% rename from 7.x/src/stk/src/Plucked.cpp rename to src/stk/src/Plucked.cpp diff --git a/7.x/src/stk/src/PoleZero.cpp b/src/stk/src/PoleZero.cpp similarity index 100% rename from 7.x/src/stk/src/PoleZero.cpp rename to src/stk/src/PoleZero.cpp diff --git a/7.x/src/stk/src/Recorder.cpp b/src/stk/src/Recorder.cpp similarity index 100% rename from 7.x/src/stk/src/Recorder.cpp rename to src/stk/src/Recorder.cpp diff --git a/7.x/src/stk/src/Resonate.cpp b/src/stk/src/Resonate.cpp similarity index 100% rename from 7.x/src/stk/src/Resonate.cpp rename to src/stk/src/Resonate.cpp diff --git a/7.x/src/stk/src/Rhodey.cpp b/src/stk/src/Rhodey.cpp similarity index 100% rename from 7.x/src/stk/src/Rhodey.cpp rename to src/stk/src/Rhodey.cpp diff --git a/7.x/src/stk/src/Sampler.cpp b/src/stk/src/Sampler.cpp similarity index 100% rename from 7.x/src/stk/src/Sampler.cpp rename to src/stk/src/Sampler.cpp diff --git a/7.x/src/stk/src/Saxofony.cpp b/src/stk/src/Saxofony.cpp similarity index 100% rename from 7.x/src/stk/src/Saxofony.cpp rename to src/stk/src/Saxofony.cpp diff --git a/7.x/src/stk/src/Shakers.cpp b/src/stk/src/Shakers.cpp similarity index 100% rename from 7.x/src/stk/src/Shakers.cpp rename to src/stk/src/Shakers.cpp diff --git a/7.x/src/stk/src/Simple.cpp b/src/stk/src/Simple.cpp similarity index 100% rename from 7.x/src/stk/src/Simple.cpp rename to src/stk/src/Simple.cpp diff --git a/7.x/src/stk/src/SineWave.cpp b/src/stk/src/SineWave.cpp similarity index 100% rename from 7.x/src/stk/src/SineWave.cpp rename to src/stk/src/SineWave.cpp diff --git a/7.x/src/stk/src/SingWave.cpp b/src/stk/src/SingWave.cpp similarity index 100% rename from 7.x/src/stk/src/SingWave.cpp rename to src/stk/src/SingWave.cpp diff --git a/7.x/src/stk/src/Sitar.cpp b/src/stk/src/Sitar.cpp similarity index 100% rename from 7.x/src/stk/src/Sitar.cpp rename to src/stk/src/Sitar.cpp diff --git a/7.x/src/stk/src/Skini.cpp b/src/stk/src/Skini.cpp similarity index 100% rename from 7.x/src/stk/src/Skini.cpp rename to src/stk/src/Skini.cpp diff --git a/7.x/src/stk/src/Sphere.cpp b/src/stk/src/Sphere.cpp similarity index 100% rename from 7.x/src/stk/src/Sphere.cpp rename to src/stk/src/Sphere.cpp diff --git a/7.x/src/stk/src/StifKarp.cpp b/src/stk/src/StifKarp.cpp similarity index 100% rename from 7.x/src/stk/src/StifKarp.cpp rename to src/stk/src/StifKarp.cpp diff --git a/7.x/src/stk/src/Stk.cpp b/src/stk/src/Stk.cpp similarity index 100% rename from 7.x/src/stk/src/Stk.cpp rename to src/stk/src/Stk.cpp diff --git a/7.x/src/stk/src/TapDelay.cpp b/src/stk/src/TapDelay.cpp similarity index 100% rename from 7.x/src/stk/src/TapDelay.cpp rename to src/stk/src/TapDelay.cpp diff --git a/7.x/src/stk/src/TubeBell.cpp b/src/stk/src/TubeBell.cpp similarity index 100% rename from 7.x/src/stk/src/TubeBell.cpp rename to src/stk/src/TubeBell.cpp diff --git a/7.x/src/stk/src/Twang.cpp b/src/stk/src/Twang.cpp similarity index 100% rename from 7.x/src/stk/src/Twang.cpp rename to src/stk/src/Twang.cpp diff --git a/7.x/src/stk/src/TwoPole.cpp b/src/stk/src/TwoPole.cpp similarity index 100% rename from 7.x/src/stk/src/TwoPole.cpp rename to src/stk/src/TwoPole.cpp diff --git a/7.x/src/stk/src/TwoZero.cpp b/src/stk/src/TwoZero.cpp similarity index 100% rename from 7.x/src/stk/src/TwoZero.cpp rename to src/stk/src/TwoZero.cpp diff --git a/7.x/src/stk/src/VoicForm.cpp b/src/stk/src/VoicForm.cpp similarity index 100% rename from 7.x/src/stk/src/VoicForm.cpp rename to src/stk/src/VoicForm.cpp diff --git a/7.x/src/stk/src/Voicer.cpp b/src/stk/src/Voicer.cpp similarity index 100% rename from 7.x/src/stk/src/Voicer.cpp rename to src/stk/src/Voicer.cpp diff --git a/7.x/src/stk/src/Whistle.cpp b/src/stk/src/Whistle.cpp similarity index 100% rename from 7.x/src/stk/src/Whistle.cpp rename to src/stk/src/Whistle.cpp diff --git a/7.x/src/stk/src/Wurley.cpp b/src/stk/src/Wurley.cpp similarity index 100% rename from 7.x/src/stk/src/Wurley.cpp rename to src/stk/src/Wurley.cpp diff --git a/7.x/src/stk/stkOpcodes.cpp b/src/stk/stkOpcodes.cpp similarity index 100% rename from 7.x/src/stk/stkOpcodes.cpp rename to src/stk/stkOpcodes.cpp diff --git a/7.x/src/stk/tests/stk_adapter_test.cpp b/src/stk/tests/stk_adapter_test.cpp similarity index 100% rename from 7.x/src/stk/tests/stk_adapter_test.cpp rename to src/stk/tests/stk_adapter_test.cpp diff --git a/7.x/src/websockets/CMakeLists.txt b/src/websockets/CMakeLists.txt similarity index 100% rename from 7.x/src/websockets/CMakeLists.txt rename to src/websockets/CMakeLists.txt diff --git a/7.x/src/websockets/WebSocketOpcode.c b/src/websockets/WebSocketOpcode.c similarity index 100% rename from 7.x/src/websockets/WebSocketOpcode.c rename to src/websockets/WebSocketOpcode.c diff --git a/7.x/src/websockets/WebSocketOpcode.h b/src/websockets/WebSocketOpcode.h similarity index 100% rename from 7.x/src/websockets/WebSocketOpcode.h rename to src/websockets/WebSocketOpcode.h diff --git a/7.x/src/wiimote/CMakeLists.txt b/src/wiimote/CMakeLists.txt similarity index 100% rename from 7.x/src/wiimote/CMakeLists.txt rename to src/wiimote/CMakeLists.txt diff --git a/6.x/src/wiimote/wii_mac.h b/src/wiimote/wii_mac.h similarity index 100% rename from 6.x/src/wiimote/wii_mac.h rename to src/wiimote/wii_mac.h diff --git a/7.x/src/wiimote/wiimote.c b/src/wiimote/wiimote.c similarity index 100% rename from 7.x/src/wiimote/wiimote.c rename to src/wiimote/wiimote.c diff --git a/7.x/tests/plugin_load_test.cpp b/tests/plugin_load_test.cpp similarity index 100% rename from 7.x/tests/plugin_load_test.cpp rename to tests/plugin_load_test.cpp diff --git a/7.x/vcpkg b/vcpkg similarity index 100% rename from 7.x/vcpkg rename to vcpkg diff --git a/7.x/vcpkg.json b/vcpkg.json similarity index 100% rename from 7.x/vcpkg.json rename to vcpkg.json diff --git a/wasm/README.md b/wasm/README.md index a2039f2f..60cbc7ce 100644 --- a/wasm/README.md +++ b/wasm/README.md @@ -63,7 +63,7 @@ npm test npm pack ``` -Nix pins the toolchain and builds the existing `7.x` CMake targets with Ninja. +Nix pins the toolchain and builds the CMake targets in the repository root with Ninja. Dependencies use threaded static PIC builds. Each plugin exports its TLS size, alignment, and initializer so the engine can set up thread-local storage. The C runtime imports the engine's allocator; it does not link its own heap. diff --git a/wasm/default.nix b/wasm/default.nix index fa6ac34d..7d1b3ec4 100644 --- a/wasm/default.nix +++ b/wasm/default.nix @@ -104,7 +104,15 @@ let in wasiCxx.mkDerivation { pname = "csound-plugins-wasm"; version = (builtins.fromJSON (builtins.readFile ../package.json)).version; - src = pkgs.lib.cleanSource ../7.x; + src = pkgs.lib.sourceByRegex ../. [ + "CMakeLists\\.txt" + "cmake" + "cmake/.*" + "src" + "src/.*" + "tests" + "tests/.*" + ]; nativeBuildInputs = [ pkgs.cmake pkgs.ninja ]; buildInputs = [ libpng zlib ]; dontStrip = true; @@ -145,10 +153,10 @@ in wasiCxx.mkDerivation { cp ${libcxx.src}/libcxx/LICENSE.TXT $out/share/licenses/libcxx.txt cp ${libcxx.src}/libcxxabi/LICENSE.TXT $out/share/licenses/libcxxabi.txt cp ${libunwindSource}/libunwind/LICENSE.TXT $out/share/licenses/libunwind.txt - cp ${../7.x/src/stk/LICENSE} $out/share/licenses/stk.txt + cp ${../src/stk/LICENSE} $out/share/licenses/stk.txt cp ${pkgs.pkgsCross.wasi32.llvmPackages.compiler-rt.src}/compiler-rt/LICENSE.TXT $out/share/licenses/compiler-rt.txt cp ${pkgs.eigen.src}/COPYING* $out/share/licenses/eigen/ - sed -n '1,/^=*[*][/]$/p' ${../7.x/src/linear_algebra/gmm/gmm.h} > $out/share/licenses/gmm.txt + sed -n '1,/^=*[*][/]$/p' ${../src/linear_algebra/gmm/gmm.h} > $out/share/licenses/gmm.txt tar -xOf ${pkgs.libpng.src} libpng-${pkgs.libpng.version}/LICENSE > $out/share/licenses/libpng.txt tar -xOf ${pkgs.zlib.src} zlib-${pkgs.zlib.version}/LICENSE > $out/share/licenses/zlib.txt for plugin in chua image linear_algebra stkops; do diff --git a/7.x/x64-windows-csound.cmake b/x64-windows-csound.cmake similarity index 100% rename from 7.x/x64-windows-csound.cmake rename to x64-windows-csound.cmake