homebrew-core/Formula/csound.rb

266 lines
8.5 KiB
Ruby

class Csound < Formula
desc "Sound and music computing system"
homepage "https://csound.com"
url "https://github.com/csound/csound.git",
tag: "6.18.1",
revision: "a1580f9cdf331c35dceb486f4231871ce0b00266"
license "LGPL-2.1-or-later"
revision 1
head "https://github.com/csound/csound.git", branch: "master"
livecheck do
url :stable
strategy :github_latest
end
bottle do
sha256 arm64_ventura: "158f7bd20fd0c0b3d1d9f5066d35ff79630c9eb1eda8f15f0f75f25019866006"
sha256 arm64_monterey: "6d8413442ddd3660cd572b141ad8a5c2ea9dd1119694d7f1e8b4c9fee2279d40"
sha256 arm64_big_sur: "928ffd75d79ff5aff1638367919978d19b87a512dd739e848f7dcbf9a9e4015c"
sha256 ventura: "99b89dfb2f7047730fe4dff6572e2fb6ceafc3f68e0c407a2a3033efbbb93c09"
sha256 monterey: "440842d27ea5ae7d4b7f1c0f3af9d40226e7aab97c9d3701ea5d21f17bce55f9"
sha256 big_sur: "b6d0479f32f83fd8c8ce19679dc21ac0bee7d50f673d4b9356cbc067ebd8a05f"
sha256 x86_64_linux: "e03f6ce722993e8f566853bdb6442564a7357f5dfa3024367664f93accda3407"
end
depends_on "asio" => :build
depends_on "cmake" => :build
depends_on "eigen" => :build
depends_on "swig" => :build
depends_on "faust"
depends_on "fltk"
depends_on "fluid-synth"
depends_on "gettext"
depends_on "hdf5"
depends_on "jack"
depends_on "lame"
depends_on "liblo"
depends_on "libpng"
depends_on "libsamplerate"
depends_on "libsndfile"
depends_on "libwebsockets"
depends_on "numpy"
depends_on "openjdk"
depends_on "portaudio"
depends_on "portmidi"
depends_on "python@3.11"
depends_on "stk"
uses_from_macos "bison" => :build
uses_from_macos "flex" => :build
uses_from_macos "curl"
uses_from_macos "zlib"
on_macos do
depends_on "wiiuse"
end
on_linux do
depends_on "alsa-lib"
end
conflicts_with "libextractor", because: "both install `extract` binaries"
conflicts_with "pkcrack", because: "both install `extract` binaries"
fails_with gcc: "5"
resource "ableton-link" do
url "https://github.com/Ableton/link/archive/Link-3.0.6.tar.gz"
sha256 "4f4fae68bd9351cba603f07990b0d1d9cd7f986c1c78f748d97168c8ae5269b2"
end
resource "csound-plugins" do
url "https://github.com/csound/plugins/archive/refs/tags/1.0.2.tar.gz"
sha256 "8c2f0625ad1d38400030f414b92d82cfdec5c04b7dc178852f3e1935abf75d30"
# Fix build on macOS 12.3+ by replacing old system Python/Python.h with Homebrew's Python.h
patch do
url "https://github.com/csound/plugins/commit/13800c4dd58e3c214e5d7207180ad7115b4e2f27.patch?full_index=1"
sha256 "e088cc300845408f3956f070fa34a900b700c7860678bc6d37f7506d615787a6"
end
end
resource "getfem" do
url "https://download.savannah.gnu.org/releases/getfem/stable/getfem-5.4.2.tar.gz"
sha256 "80b625d5892fe9959c3b316340f326e3ece4e98325eb0a81dd5b9ddae563b1d1"
end
def python3
deps.map(&:to_formula)
.find { |f| f.name.match?(/^python@\d\.\d+$/) }
.opt_libexec/"bin/python"
end
def install
ENV["JAVA_HOME"] = Language::Java.java_home
site_packages = prefix/Language::Python.site_packages(python3)
rpaths = [rpath]
rpaths << rpath(target: frameworks) if OS.mac?
system "cmake", "-S", ".", "-B", "build",
"-DCMAKE_INSTALL_RPATH=#{rpaths.join(";")}",
"-DBUILD_JAVA_INTERFACE=ON",
"-DBUILD_LUA_INTERFACE=OFF",
"-DBUILD_TESTS=OFF",
"-DCS_FRAMEWORK_DEST=#{frameworks}",
"-DJAVA_MODULE_INSTALL_DIR=#{libexec}",
"-DPYTHON3_MODULE_INSTALL_DIR=#{site_packages}",
*std_cmake_args
system "cmake", "--build", "build"
system "cmake", "--install", "build"
if OS.mac?
include.install_symlink frameworks/"CsoundLib64.framework/Headers" => "csound"
site_packages.install buildpath/"interfaces/ctcsound.py"
else
# On Linux, csound depends on binutils, but both formulae install `srconv` binaries
(bin/"srconv").unlink
end
resource("csound-plugins").stage do
resource("ableton-link").stage buildpath/"ableton-link"
resource("getfem").stage { cp_r "src/gmm", buildpath }
args = %W[
-DABLETON_LINK_HOME=#{buildpath}/ableton-link
-DBUILD_ABLETON_LINK_OPCODES=ON
-DBUILD_CHUA_OPCODES=ON
-DBUILD_CUDA_OPCODES=OFF
-DBUILD_FAUST_OPCODES=ON
-DBUILD_FLUID_OPCODES=ON
-DBUILD_HDF5_OPCODES=ON
-DBUILD_IMAGE_OPCODES=ON
-DBUILD_JACK_OPCODES=ON
-DBUILD_LINEAR_ALGEBRA_OPCODES=ON
-DBUILD_MP3OUT_OPCODE=ON
-DBUILD_OPENCL_OPCODES=OFF
-DBUILD_PYTHON_OPCODES=ON
-DBUILD_STK_OPCODES=ON
-DBUILD_WEBSOCKET_OPCODE=ON
-DGMM_INCLUDE_DIR=#{buildpath}
-DPython3_EXECUTABLE=#{python3}
-DUSE_FLTK=ON
]
args += if OS.mac?
%W[
-DBUILD_P5GLOVE_OPCODES=ON
-DBUILD_WIIMOTE_OPCODES=ON
-DCSOUND_FRAMEWORK=#{frameworks}/CsoundLib64.framework
-DCSOUND_INCLUDE_DIR=#{frameworks}/CsoundLib64.framework/Headers
-DPLUGIN_INSTALL_DIR=#{frameworks}/CsoundLib64.framework/Resources/Opcodes64
]
else
%w[
-DBUILD_P5GLOVE_OPCODES=OFF
-DBUILD_WIIMOTE_OPCODES=OFF
]
end
system "cmake", "-S", ".", "-B", "build", *args, *std_cmake_args
system "cmake", "--build", "build"
system "cmake", "--install", "build"
end
end
def caveats
caveats = <<~EOS
To use the Java bindings, you may need to add to #{shell_profile}:
export CLASSPATH="#{opt_libexec}/csnd6.jar:."
and link the native shared library into your Java Extensions folder:
EOS
on_macos do
caveats = <<~EOS
#{caveats}\
mkdir -p ~/Library/Java/Extensions
ln -s "#{opt_libexec}/lib_jcsound6.jnilib" ~/Library/Java/Extensions
EOS
end
on_linux do
caveats = <<~EOS
srconv is not installed because it conflicts with binutils. To run srconv:
csound --utility=srconv
#{caveats}\
sudo mkdir -p /usr/java/packages/lib
sudo ln -s "#{opt_libexec}/lib_jcsound6.jnilib" /usr/java/packages/lib
EOS
end
caveats
end
test do
(testpath/"test.orc").write <<~EOS
0dbfs = 1
gi_peer link_create
gi_programHandle faustcompile "process = _;", "--vectorize --loop-variant 1"
FLrun
gi_fluidEngineNumber fluidEngine
gi_realVector la_i_vr_create 1
pyinit
instr 1
a_, a_, a_ chuap 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
a_signal STKPlucked 440, 1
a_, a_ hrtfstat a_signal, 0, 0, sprintf("hrtf-%d-left.dat", sr), sprintf("hrtf-%d-right.dat", sr), 9, sr
hdf5write "test.h5", a_signal
mp3out a_signal, a_signal, "test.mp3"
out a_signal
endin
EOS
(testpath/"test.sco").write <<~EOS
i 1 0 1
e
EOS
if OS.mac?
ENV["OPCODE6DIR64"] = frameworks/"CsoundLib64.framework/Resources/Opcodes64"
ENV["SADIR"] = frameworks/"CsoundLib64.framework/Versions/Current/samples"
else
ENV["OPCODE6DIR64"] = lib/"csound/plugins64-6.0"
ENV["SADIR"] = share/"samples"
end
ENV["RAWWAVE_PATH"] = Formula["stk"].pkgshare/"rawwaves"
system bin/"csound", "test.orc", "test.sco"
assert_predicate testpath/"test.#{OS.mac? ? "aif" : "wav"}", :exist?
assert_predicate testpath/"test.h5", :exist?
assert_predicate testpath/"test.mp3", :exist?
(testpath/"opcode-existence.orc").write <<~EOS
JackoInfo
instr 1
i_ websocket 8888, 0
endin
EOS
system bin/"csound", "--orc", "--syntax-check-only", "opcode-existence.orc"
if OS.mac?
(testpath/"mac-opcode-existence.orc").write <<~EOS
instr 1
p5gconnect
i_ wiiconnect 1, 1
endin
EOS
system bin/"csound", "--orc", "--syntax-check-only", "mac-opcode-existence.orc"
end
system python3, "-c", "import ctcsound"
(testpath/"test.java").write <<~EOS
import csnd6.*;
public class test {
public static void main(String args[]) {
csnd6.csoundInitialize(csnd6.CSOUNDINIT_NO_ATEXIT | csnd6.CSOUNDINIT_NO_SIGNAL_HANDLER);
}
}
EOS
system Formula["openjdk"].bin/"javac", "-classpath", "#{libexec}/csnd6.jar", "test.java"
system Formula["openjdk"].bin/"java", "-classpath", "#{libexec}/csnd6.jar:.",
"-Djava.library.path=#{libexec}", "test"
end
end