[go: up one dir, main page]

File: exec.tcl

package info (click to toggle)
cecilia 2.0.5-2.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,440 kB
  • ctags: 833
  • sloc: tcl: 9,786; sh: 1,085; makefile: 69; csh: 13
file content (319 lines) | stat: -rw-r--r-- 10,044 bytes parent folder | download | duplicates (3)
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#
# 	UNIX-SPECIFIC CSOUND CONTROL
# 	(c) 1997 Jean Piche & Alexandre Burton
# 	v1.80a (10/08/97)
#
#----------------
# version 2.0.4 updates by Stephen Burgess
#
#----------------
#       Updated by Hans-Christoph Steiner
#       added Darwin/MacOS X port
#       $Id $

proc CsoundLaunch {} {
    global  fileselect errno  son newfile lan module path soundOutInfo pauser
    if ![info exist pauser] {set pauser 0}
    if $pauser {CsoundPause;return} {set pauser 0}
    
    set range [$path(edit).panel.$soundOutInfo(userCHN).t tag ranges mis] 
    catch {$path(edit).panel.$soundOutInfo(userCHN).t delete [lindex $range 0] [lindex $range 1]}
    
    if {$module(path) == ""} {
	setstate idle
	errFile2 "$lan(nom88)"
	return
    }	
    if {[preCompile] == "true"} {
	makeCommand $module(path)  
    } else {
	setstate idle
    }
}


proc CsoundPause {} {
    global stuff lip path pID pauser tcl_platform

    switch $tcl_platform(os) {
	IRIX {
	    set pause 23
	    set play  25
	}
	Linux {
	    set pause 19
	    set play  18
	}
	Darwin {
	    set pause 19
	    set play  18
	}
    }
    
    if $pauser {
	exec kill -$play $pID
	set pauser 0
	setstate play
    } else {
	bug exec kill -$pause $pID
	exec kill -$pause $pID
	set pauser 1
	setstate pause
    }
}

proc CsoundStop {} {
    global stuff lip path pID pauser prefs errorCatch
    setstate idle 
    set pauser 0
    catch {exec kill $pID} res
    catch {close $stuff}

    $path(panel).csoundOut.t config -state normal
    $path(panel).csoundOut.t insert end "$lip"
    $path(panel).csoundOut.t config -state disabled
    catch {destroy .message}
     if $errorCatch {
	if {$res == ""} {
	    if {$prefs(globalMode) && $prefs(play)} {$path(winOut).rates.play invoke}
	}
   }
}

proc makeCommand {what} {
    global prefs lan new module  path soundOutInfo realtim
    global commande midifile  soundName selectedMIDIfile 
    global   midiIn ceclib tcl_platform midiinfo value

    if {$prefs(globalMode) == "0"} {
		set soundName devaudio
		set bufs "-b$prefs(realb) -B$prefs(realB)"
    } else {
		set bufs "-b$prefs(diskb) -B$prefs(diskB)"
		set soundName \"[autoIncrement]\"
		if {$soundName == ""} {errFile2 "$lan(nom80)";return}
		$path(winOut).rates.play config -state normal -command {playSound \"$soundName\" $path(winOut).p.h.d.b}
		if {$prefs(type) == "$lan(nom3)"} {
			$path(winOut).rates.edit config -state disabled
			set soundName "$soundName.raw"
		} else {	
			$path(winOut).rates.edit config -state normal
		}
    }	    
    if {$prefs(heart) == 1} {set heart "-H"} else {set heart ""}  
    switch $prefs(type) {
		"aiff"	{set s "-A -R"} 
		"raw" 	{set s "-h"}
		"wav"	{set s "-W -R"}
    }  
    if [info exists midiinfo] {set F "-F \"$value($midiinfo)\""} {set F ""}
    if {$prefs(time) == 1} {set time "/usr/bin/time"} else {set time ""}    
    if {$prefs(sigin) == 1} {set i "-i devaudio"} else {set i ""}
    if {$prefs(graph) == 0} {set g "-d"} else {set g ""}
    if {$prefs(ascii) == 0} {set as ""} else {set as "-g"}
    if {$prefs(midi) == 1 | $midiIn == 1} {set m "-M /dev/$prefs(midiport)"} else {set m ""} 
    if {$midifile == 0} {set mi ""} else {set mi "-T -F $selectedMIDIfile"}
    set sc ""
    if {$prefs(wind) == 1} {
		set me 0
		if {$prefs(amp)}   {set me [expr $me+1]}
		if {$prefs(range)} {set me [expr $me+2]}
		if {$prefs(warn)}  {set me [expr $me+4]}
		set mess "-m $me"		
		if {$prefs(heart) == 1} {set heart "-H"} else {set heart ""}
    } else {
		set mess "-m 0"
		set heart ""
    }
    if {$prefs(tempo) == "off"} {set tem ""} else {set tem "-t $prefs(tempo)"}  
    if {$tcl_platform(platform) == "unix" && $realtim == 1} {set rl "-L stdin"} else {set rl ""}
    set compile $module(tempfile)
#######################
    set commande "$time $prefs(help:CSND) $tem $as $F $heart $mess $s $sc -o $soundName $rl $bufs $g $i $m $mi $compile.orc $compile.sco"
#######################
    $path(panel).csoundOut.t config -state normal
    $path(panel).csoundOut.t delete 0.0 end
    $path(panel).csoundOut.t insert end "% $commande \n"
    $path(panel).csoundOut.t config -state disabled
    set iconer 0
    bind . <Control-m> "Run Csound"    
    Run Csound perf
}	

proc Run {what why} {
	
    global commande lip killButt midirec fillButt stuff prefs  okline pID errorCatch
    global newline tcl_platform soundName

    if $prefs(prev_line) {
    	previewcsound $commande	
	if { $okline == 0 } { return }
	set commande $newline
    }
    
    bug here

    if {$prefs(wind) == 1} {
	switch $tcl_platform(os) {
	    IRIX {
		set comm "xwsh   -name ${what} -hold -bg gray20  -geometry 84x24+250+250  -e $commande" 
	    }
	    Linux {
# This wrapper adds a sleep after csound runs to keep the window open
# run csound in an xterm, exit if it all runs smoothly, sleep on error to display it
		bug linux...
		set csoundWrapper "/tmp/.cecilia-wrap-csound"
		if ![file exists $csoundWrapper] {
		    bug creating new linux wrapper
		    set csoundWrapperFileHandle [open $csoundWrapper w+]
		    puts $csoundWrapperFileHandle "\#!/bin/sh\n$@\necho Cecilia/Csound done...\nsleep 1000000\n\n"
		    close $csoundWrapperFileHandle
		    exec chmod 755 $csoundWrapper
		}
		set comm "xterm -title ${what} -e $csoundWrapper $commande" 
	    }
	    Darwin {
# This wrapper adds a sleep after csound runs to keep the window open
# run csound in an xterm, exit if it all runs smoothly, sleep on error to display it
		bug darwin...
		set csoundWrapper "/tmp/.cecilia-wrap-csound.command"
		if [file exists $csoundWrapper] {
		    bug deleting Darwin wrapper
		    # this should delete the file in case its an older version
		    file delete -force $csoundWrapper
		} 
		bug creating new Darwin wrapper
		set csoundWrapperFileHandle [open $csoundWrapper w+]
		puts $csoundWrapperFileHandle \
		    "\#!/bin/sh\n\
                    echo Csound command: $commande\n\ 
                    $commande || echo ERROR: read message above\n\
                    echo Cecilia/Csound done.\n\n"
		close $csoundWrapperFileHandle
		exec chmod 755 $csoundWrapper
		
		set comm "/usr/bin/open $csoundWrapper" 
	    }
	}
    } else {
	set comm "$commande"
    }

    set errorCatch 1
    set midirec 1
    set lip ""
    set stuff ""
    setstate play

    switch -- $why {
	"perf" {
	    set stuff [open |[subst $comm]  RDWR ]
	    set pID [pid $stuff]
	    fconfigure $stuff -blocking 0
	    fileevent $stuff readable Logg
	    if {$prefs(globalMode) == "1" && $prefs(spee) == "1"} {errFile1 "WRITING:\n$soundName\nto disk..."}
	}
	"anal" {
	    set stuff [open |[subst $comm] RDWR]
	    set pID [pid $stuff]
	    fconfigure $stuff -blocking 0
	    fileevent $stuff readable anaLogg
	    if {$prefs(globalMode) == "1" && $prefs(spee) == "1"} {errFile1 "WRITING:\n$soundName\nto disk..."}
	}
    }
}

proc putIt {chan val} {
    global stuff realArr
    catch {puts $stuff "i${chan} 0 0.001 $val"}
    catch {flush $stuff}
}
proc anaLogg {} {
    global stuff
    if [eof $stuff] {CsoundStop}
}

proc Logg {} {
    global stuff path soundOutInfo nchnls module lip prefs errorCatch
    if [eof $stuff] {
	CsoundStop
    } else {
	gets $stuff line
	$path(panel).csoundOut.t config -state normal
	$path(panel).csoundOut.t insert end "$line \n"
	$path(panel).csoundOut.t config -state disabled
	set ender ""; set li ""
        set ft $path(edit).panel.orcOut.t
	set f $path(edit).panel.$soundOutInfo(nchnls).t

	if [regexp -- "error:" $line] {
		bell;bell
		gets $stuff lined
		set errorCatch 0
		CsoundStop
		set end2 [$ft index end]
		set dif [expr round([$ft index end] - [$ft search $lined 1.0 ]) -1]
		set ender [expr [$f index end]-$dif]
		set end3 [$f index "$ender lineend"]
		$f insert "$end3 lineend" "  ;<---[lrange $line 1 [expr [lsearch  $line line] - 1]]"
		$f tag add mis $end3 "$end3 lineend"
		$f tag configure mis -foreground darkorange
		if {[string first ' $line] != "-1" } {
		    set  lo [$f search [string trim [string range $line [string first  ' $line] [string last  ' $line]] '] 1.0 ]
		    $f tag add sel "$lo wordstart" "$lo wordend"		
		    $f mark set insert $lo
		}
		errFile2 "There is an error in your orchestra.\n Orange colored arrow points to it!"
catch {tkwait visibility .speedo}
		catch {destroy .speedo}
		wm deiconify .edit
		raise .edit
		$f yview [expr [$f index end]-$dif.0]
		
		
	}
	    
	if [regexp -- "INIT ERROR" $line] {
		bell;bell
		set errorCatch 0
		CsoundStop		
		set ender [$path(edit).panel.$soundOutInfo(nchnls).t index end]
		$path(edit).panel.$soundOutInfo(nchnls).t insert $ender  "\n;INIT ERROR: [lrange $line 5 end]"
		$path(edit).panel.$soundOutInfo(nchnls).t tag add mis $ender end
		$path(edit).panel.$soundOutInfo(nchnls).t tag configure mis -foreground darkorange
		$path(edit).panel.$soundOutInfo(nchnls).t yview $ender
		catch {destroy .speedo}
		errFile2 "There is an error in your use of functions.\n Orange colored message describes it!"
		wm deiconify .edit
		raise .edit
	}

	if [regexp -- "opds" $line] {
		bell;bell
		set errorCatch 0
		CsoundStop
		set ender [$path(edit).panel.$soundOutInfo(nchnls).t index end]
		$path(edit).panel.$soundOutInfo(nchnls).t insert "$ender + 1l"  "\n;SOMETHING WRONG WITH CHANNELS AND/OR\n;INSTRUMENT STRUCTURE"
		bug [$path(edit).panel.$soundOutInfo(nchnls).t index end]
		$path(edit).panel.$soundOutInfo(nchnls).t tag add mis $ender end
		$path(edit).panel.$soundOutInfo(nchnls).t tag configure mis -foreground darkorange
		$path(edit).panel.$soundOutInfo(nchnls).t yview $ender
		errFile2 "SOMETHING WRONG WITH CHANNELS\n AND/OR INSTRUMENT STRUCTURE?"
	}
	    
	if [regexp -- "overall amps" $line] {
	    for {set c 0} {$c<$nchnls($soundOutInfo(nchnls))} {incr c} {
		$path(winOutAmp).ok$c config -text [lindex $line [expr $c + 5]]
	    }
	}
	if [regexp -- "samples out of range" $line] {
	    for {set c 0} {$c<$nchnls($soundOutInfo(nchnls))} {incr c} {
	    	if {[set amp [lindex $line [expr $c + 5]]] > 0} {
		    $path(winOutAmp).ov$c config -text $amp -fg red
		} else {
		    $path(winOutAmp).ov$c config -text ok
		}
	    }
	}
    }	
}