-
-
Notifications
You must be signed in to change notification settings - Fork 12.6k
/
Copy pathcsound.rb
264 lines (231 loc) · 8.45 KB
/
csound.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
class Csound < Formula
desc "Sound and music computing system"
homepage "https://csound.com"
url "https://github.com/csound/csound.git",
tag: "6.18.0",
revision: "f0bea4d87b49da2be7e9f1fc77826a7327cbc391"
license "LGPL-2.1-or-later"
head "https://github.com/csound/csound.git", branch: "master"
livecheck do
url :stable
strategy :github_latest
end
bottle do
sha256 arm64_ventura: "4127a58ac9823cca00717ceb5908387bf8175566c698def90d37631bec9fbc40"
sha256 arm64_monterey: "fe0178a5610cbf9be705bdb6bc0eb12c2e4e7edf99b115fcc53152fd744e561a"
sha256 arm64_big_sur: "bf72e89c87b6e8204b9b20d8d457d9f77c26fd9e29cabd525dfb49ad8fc58160"
sha256 monterey: "bd030d8999a6a0cd958408f71432fc8233080aa75f32db981e2a7bcc31101ec5"
sha256 big_sur: "8075d251a547c27e84055c43298120de81a289258ea226826f091f39e27fe873"
sha256 catalina: "65e209e1fc848b56f806be9b273f95080a7f3c721083291f118d171e3b479ea7"
sha256 x86_64_linux: "00996dcdc227b095142852b9e7696c7dc6d97829fb0c72394bfc14b51c6c52c6"
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 "[email protected]"
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.5.tar.gz"
sha256 "74a470c8ae8f9c325e65e981839852e821ec56b980f8b923cb77ca833c4603ed"
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