3 #this is a script to pass things from scvim to sclang
5 #Copyright 2007 Alex Norman
7 #This file is part of SCVIM.
9 #SCVIM is free software: you can redistribute it and/or modify
10 #it under the terms of the GNU General Public License as published by
11 #the Free Software Foundation, either version 3 of the License, or
12 #(at your option) any later version.
14 #SCVIM is distributed in the hope that it will be useful,
15 #but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 #GNU General Public License for more details.
19 #You should have received a copy of the GNU General Public License
20 #along with SCVIM. If not, see <http://www.gnu.org/licenses/>.
26 pipe_loc
= "/tmp/sclang-pipe" unless (pipe_loc
= ENV["SCVIM_PIPE_LOC"])
28 if ENV["SCLANG_RUNDIR"]
29 rundir
= ENV["SCLANG_RUNDIR"]
30 elsif RUBY_PLATFORM =~
/darwin/
31 rundir
= "/Applications/SuperCollider/"
34 pid_loc
= "/tmp/sclangpipe_app-pid" unless (pid_loc
= ENV["SCVIM_PIPE_PID_LOC"])
39 '/Applications/SuperCollider/SuperCollider.app/Contents/Resources/sclang',
40 '/Applications/SuperCollider/sclang',
49 puts
"cannot find sclang executable, is it in your path?"
53 sclangargs
= "-i scvim" # this arg must always be passed, so that sclang knows to load classes from folders named "scide_scvim"
55 opts
= OptionParser
.new
do |opts
|
56 opts
.on("-h", "--help", "Display this help") do
60 opts
.on("-d <path>", "Set runtime directory") do |d
|
64 opts
.on("-g <memory-growth>[km]", "Set heap growth (default 256k)") do |g
|
65 sclangargs
= sclangargs
+ " -g #{g}"
68 opts
.on("-l <path>", "Set library configuration file") do |l
|
69 sclangargs
= sclangargs
+ " -l #{l}"
72 opts
.on("-m <memory-space>[km]", "Set initial heap size (default 2m)") do |m
|
73 sclangargs
= sclangargs
+ " -m #{m}"
76 opts
.on("-u <network-port-number>", "Set UDP listening port (default 57120)") do |p
|
77 sclangargs
= sclangargs
+ " -u #{p}"
80 opts
.on("-r", "Call Main.run on startup") do
81 sclangargs
= sclangargs
+ " -r"
84 opts
.on("-s", "Call Main.stop on shutdown") do
85 sclangargs
= sclangargs
+ " -s"
92 File
.open(pid_loc
, "w"){ |f
| f
.puts Process
.pid
}
94 #remove the pipe if it exists
95 FileUtils
.rm(pipe_loc
) if File
.exists
?(pipe_loc
)
97 system("mkfifo", pipe_loc
)
103 IO
.popen("#{app} -d #{rundir.chomp} #{sclangargs}", "w") do |sclang
|
105 x
= `cat #{pipe_loc}`
111 $p = Process
.fork
{ pipeproc
.call
}
113 #if we get a hup then we kill the pipe process and
116 Process
.kill("INT", $p)
117 $p = Process
.fork
{ pipeproc
.call
}
122 FileUtils
.rm(pipe_loc
)
123 FileUtils
.rm(pid_loc
)
127 #we sleep until a signal comes