File: startBristol.in

package info (click to toggle)
bristol 0.60.10-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,652 kB
  • sloc: ansic: 124,457; sh: 10,579; makefile: 111
file content (600 lines) | stat: -rwxr-xr-x 13,926 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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
#!/bin/sh
#
# Diverse Bristol audio routines.
# Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2011
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 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 General Public License
#  along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#set -x

args=$*

vers=@VERSION@

cli=0
engine=1
gui=1
quiet=0
verbose=0
jack=0
export JACK_START_SERVER=1
midi=seq
HELP=0
README=0

EMULATE=hammondB3
FREQ=0

#PORT=5028
# Randomise the port numbers, can be overridden by -port which would be a
# requirement for multitimbral
PORT=`date +%N`
PORT=`expr $PORT % 65536` >/dev/null 2>&1
if [ -z $PORT ]; then
	PORT=`date +%s`
	PORT=`expr $PORT % 65536` >/dev/null 2>&1
fi
if [ $PORT -lt 1024 ]; then
	PORT=`expr $PORT + 5028`
fi

valgrind=0
execme=1
liblist=0

host=net

engstatus=0
guistatus=0

JS=1
RATE=44100
DRIVER=@DEFAULT_AUDIO_FLAG@
COUNT=256

LOGO=no

#
# The following is configured by the autotools process.
#
BRISTOL_DIR=@BRISTOL_DIR@

#
# Whatever directory was called for startBristol we also neede in the PATH
#
PATH=${PATH}:`dirname $0`

showhelp()
{
	if [ $HELP -eq 3 ]; then
		brighton -V
		exit 0
	fi
	if [ $HELP -eq 2 ]; then
		brighton -h | less
		exit 0
	fi
	if [ $verbose = 1 ]; then
		# let the bristol gui give a verbose help text.
		engine=0
	else
		brighton -V
		echo
		echo "startBristol [-explorer|-mini|-memory|-hammond|-b3|-dx|-axxe|-odyssey|-2600|-mono|-poly|-juno|-prophet|-pro10|-pro52|-mixer|-vox|-rhodes|-rhodesbass|-obx|-obxa|-aks|<others>] [-oss|-alsa|-jack] [[-help|-h] [-verbose|-v]]"
		echo
		echo "Try 'startBristol -v|-h' for more verbose help output on device configuration."
		echo
		echo "Try 'startBristol -readme' for very verbose output"
		echo "Try 'startBristol -readme -mini' for info on specific emulator"
		echo
		echo "Try 'startBristol -b3' or 'startBristol -jack', for example, if you are unsure."
		echo
		echo "Q&A to nickycopeland@hotmail.com"
		echo "bugs, features, enhancements to http://sourceforge.net/projects/bristol"
		echo
		exit 0
	fi
}

if [ $# = 0 ]; then
	HELP=1
fi

# Nokey: Don't override BRISTOL if it's not already set
if [ -z "$BRISTOL" ]; then
	if [ -d "${BRISTOL_DIR}/memory" ]; then
		export BRISTOL=${BRISTOL_DIR}
	else
		# We should first take our basename and look for a binary
		BRISTOL=`dirname $0`
		BRISTOL=`dirname $BRISTOL`

		if [ ! -f $BRISTOL/bin/bristol ]; then
			#
			# Take a default
			#
			export BRISTOL=/opt/audio/bristol
		fi
	fi
fi
export BRISTOL

for index in $*; do
	if [ $index = "-stop" ]; then
		pkill bristol
		if [ $? != 0 ]; then
			pkill brighton
		fi
		exit 0
	fi
	if [ $index = "-exit" ]; then
		pkill bristol
		pkill brighton
		exit 0
	fi
	if [ $index = "-kill" ]; then
		pkill -f "\\$2"
		exit 0
	fi
	if [ $index = "-host" ]; then
		host=`echo $2 | awk -F: '{print $1}'`
		if [ $host = "unix" ]; then
			localport=`echo $2 | awk -F: '{print $2}'`
			if [ -z $localport ]; then
				localport=$PORT
			fi
		fi
	fi
	if [ $index = "-freqtweak" ]; then
		FREQ=$2
		if [ $FREQ != 0 -a -x /usr/bin/cpufreq-set -a $execme -eq 0 ]; then
			echo Setting min CPU speed to $FREQ
			cpufreq-set -d ${FREQ}
		fi
	fi
	if [ $index = "-count" ]; then
		COUNT=$2
	fi
	if [ $index = "-rc" ]; then
		BRISTOL_RC=/dev/null
	fi
	if [ $index = "-sleep" ]; then
		sleep $2
	fi
	if [ $index = "-emulate" ]; then
		EMULATE=$2
	fi
	if [ $index = "-port" ]; then
		PORT=$2
	fi
	if [ $index = "-cache" ]; then
		export BRISTOL_CACHE=$2
	fi
	if [ $index = "-memdump" ]; then
		export BRISTOL_DUMP=$2
	fi
	if [ $index = "--summary" ]; then
		brighton --summary
		exit 0
	fi
	if [ $index = "-summary" ]; then
		brighton -summary
		exit 0
	fi
	if [ $index = "-console" ]; then
		export BRISTOL_LOG_CONSOLE=true
	fi
	if [ $index = "-cli" ]; then
		cli=1
		execme=0
	fi
	if [ $index = "-exec" ]; then
		execme=0
	fi
	if [ $index = "-ladi" ]; then
		execme=1
	fi
	if [ $index = "-valgrind" ]; then
		valgrind=1
	fi
	if [ $index = "-debug" ]; then
		liblist=1
	fi
	if [ $index = "-liblist" ]; then
		liblist=1
	fi
	if [ $index = "-master" ]; then
		engine=0
	fi
	if [ $index = "-engine" ]; then
		engine=0
	fi
	if [ $index = "-gui" ]; then
		gui=0
	fi
	if [ $index = "-readme" ]; then
		README=1
	fi
	if [ $index = "-v" ]; then
		HELP=2
	fi
	if [ $index = "--v" ]; then
		HELP=2
	fi
	if [ $index = "-verbose" ]; then
		verbose=1
	fi
	if [ $index = "--verbose" ]; then
		verbose=1
	fi
	if [ $index = "-version" ]; then
		HELP=3
	fi
	if [ $index = "-V" ]; then
		HELP=3
	fi
	if [ $index = "-logo" ]; then
		LOGO=yes
	fi
	if [ $index = "-h" ]; then
		HELP=2
	fi
	if [ $index = "--h" ]; then
		HELP=2
	fi
	if [ $index = "-help" ]; then
		HELP=2
	fi
	if [ $index = "--help" ]; then
		HELP=2
	fi
	if [ $index = "-libtest" ]; then
		engine=0
	fi
	if [ $index = "-quiet" ]; then
		quiet=1
	fi
	if [ $index = "-q" ]; then
		quiet=1
	fi
	if [ $index = "-jsmuuid" ]; then
		export BRISTOL_AUTOCONN=false
	fi
	if [ $index = "-jackstats" ]; then
		JS=0
	fi
	if [ $index = "-jack" ]; then
		jack=1
		COUNT=1024
		DRIVER=-jack
	fi
	if [ $index = "-audio" ]; then
		DRIVER=-$2
	fi
	if [ $index = "-alsa" ]; then
		jack=0
		DRIVER=-alsa
	fi
	if [ $index = "-jackstart" ]; then
		unset JACK_START_SERVER
	fi
	shift
done

#
# As a note for anybody interested in reading this script, brighton also has
# a BRISTOL_CACHE directory for private memories, sequences and controller maps.
# Default is in $HOME/.bristol and we create this if it is not already made
#
if [ -z "$BRISTOL_CACHE" ]; then
	export BRISTOL_CACHE=${HOME}/.bristol
fi

if [ -z "$BRISTOL_DUMP" ]; then
	mkdir -p ${BRISTOL_CACHE}/memory
else
	if [ ! -d $BRISTOL_DUMP/memory/$EMULATE ]; then
		mkdir -p $BRISTOL_DUMP/memory/$EMULATE
		cp -f $BRISTOL_DIR/memory/$EMULATE/* $BRISTOL_DUMP/memory/$EMULATE
		cp -f $BRISTOL_CACHE/memory/$EMULATE/* $BRISTOL_DUMP/memory/$EMULATE
		echo created memory shadow in $BRISTOL_DUMP
	fi
	export BRISTOL_CACHE=$BRISTOL_DUMP
fi

PREARGS=
POSTARGS=
#
# Changed some of the processing to have tokens in the PREARGS file. We are
# looking for PREARGS and POSTARGS. If we don't find either of them then take
# the whole file which was the previous method and is equivalent to PREARGS
#
if [ -z "${BRISTOL_RC}" -a -f ${BRISTOL_CACHE}/bristolrc ]; then
	BRISTOL_RC=${BRISTOL_CACHE}/bristolrc
fi
if [ -f "${BRISTOL_RC}" ]; then
	egrep '(PREARGS|POSTARGS)' ${BRISTOL_RC} >/dev/null

	if [ $? -gt 0 ]; then
		PREARGS=`cat ${BRISTOL_RC}`
	else
		PREARGS=`awk -F= '/PREARGS/ {print $2}'  ${BRISTOL_RC}`
		POSTARGS=`awk -F= '/POSTARGS/ {print $2}'  ${BRISTOL_RC}`
	fi
fi

# Nokey: Does the BRISTOL directory actually exist?
if [ ! -d $BRISTOL ]; then
	# Apparently not. Let's try to make a guess as to where it is.

	# Try to find out how we were started. If this script was in
	#  the PATH of the user, the $0 should have a leading '/'.
	#  This leading '/' would also be there if this script was
	#  executed as /full/path/name/startBristol
	STARTUP=$0
	# If this script was started as ./"*whatever*" then we need
	#  to strip off the './' in order to accurately determine
	#  the BRISTOL directory
	if [ "$(echo $STARTUP | cut -c 1-2)" = "./" ]; then
		STARTUP=$(echo $STARTUP | cut -c 3-)
	fi
	
	if [ "$(echo $STARTUP | cut -c 1)" = "/" ]; then
		BIN_DIR=$(dirname $STARTUP)
	else
		BIN_DIR=$(dirname $PWD/$STARTUP)
	fi

	export BRISTOL=$(dirname $BIN_DIR)
	unset BIN_DIR STARTUP
fi

if [ ${README} -ge 1 ]; then
	brighton $args | less
	exit 0
fi

if [ ${HELP} -ge 1 ]; then
	showhelp
fi

#
# Try and get Jack driver information. If the daemon is running, use it. If
# user has a .jackdrc use that, otherwise use /etc/jackdrc
#
if [ ${DRIVER} = "-jack" ]; then 
	jack=1

	if [ $JS -ne 0 ]; then 
		JP=`bristoljackstats 2>&1`
		if [ $? -eq 0 ]; then
			JACKPARAMS=`echo $JP | awk '/JACKSTATS/'`
			RATE=`echo ${JACKPARAMS} | awk '{print $2}'`
			COUNT=`echo ${JACKPARAMS} | awk '{print $3}'`

			echo jackstats found -rate ${RATE} -count ${COUNT}
		fi
	else
		#
		# We should not really get here. If jack was requested but the daemon
		# could not be reached (we did not get feedback from bristoljackstats)
		# then larger issues will occur presently
		#
		# Thanks to Sylvain Robitaille for the next code.
		#
		# See if the process is running
		#
		# We should replace this with pgrep and do it for this user - if the
		# daemon is running with other rights we may not be able to connect.
		#
		JACKD=`ps ax | grep -w jackd | grep -vw grep` 

		#
		# Otherwise see what would be started
		#
		if [ -z "${JACKD}" ]; then 
			echo "jack driver requested, jackd not running" 

			if [ -f /etc/jackdrc ]; then
				echo "jack configuration found in /etc/jackdrc"
				JACKD=`cat /etc/jackdrc`
			fi

			if [ -f ~/.jackdrc ]; then
				echo "private jack configuration found in ~/.jackdrc"
				JACKD=`cat ~/.jackdrc`
			fi
		fi

		if [ -z "${JACKD}" ]; then 
			RATE=48000 
			COUNT=1024 
		else
			RATE=`echo ${JACKD} |grep -o -- '-r[0-9][0-9]*' |sed 's/^-r//'` 

			if [ -z "${RATE}" ]; then 
				# assume Jackd's default rate: 
				RATE=48000 
			fi 

			#COUNT=`echo ${JACKD} |grep -o -- '-p[0-9][0-9]*' |sed 's/^-p//'` 
			COUNT=`echo ${JACKD} |grep -o -- '-p[0-9][0-9]*' |tail -n1 |sed 's/^-p//'`

			if [ -z "${COUNT}" ]; then 
				# assume Jackd's default count: 
				COUNT=1024 
			fi 
		fi
	fi
fi

#
# If slabhome already exists, we should take it rather than this definition.
#
export SLAB_HOME=$BRISTOL
export BRIGHTON=$BRISTOL


if [ ${liblist} != 0 ]; then
	echo
	echo '*** bristol libraries ***'
	echo
	ldd `which bristol`
	echo '*** brighton libraries ***'
	echo
	ldd `which brighton`
	echo
fi

if [ $jack -eq 1 ]; then
	ldd `which bristol` | grep jack > /dev/null 2>&1
	if [ $? -ne 0 ]; then
		echo Requested Jack drivers, not compiled into bristol
		exit -1
	fi
fi

if [ ${LOGO} = "yes" ]; then
	#
	# Just to make sure
	#
	echo
	echo "Bristol is about to start."
	echo
	echo "This program is totally unrelated to ANY of the companies that produced"
	echo "the original instruments emulated by bristol, and none of the original"
	echo "manufacturers in ANY way endorse this product."
	echo

	sleep 1
fi

#
# Requesting an engine. This means we need a free TCP port. Our default is 
# 5028 and if it is not free then search for one from there
#
if [ $engine = 1 ]; then
	if [ $host = "unix" ]; then
		echo checking availability of host port $localport
		ls /tmp/br.$localport >/dev/null 2>&1
		if [ $? -eq 0 ]; then
			echo "host port looked busy, unlinking"
			rm -f /tmp/br.$localport
		fi
	else
		echo checking availability of TCP port $PORT
		netstat -taln | awk '{print $4}' | grep $PORT > /dev/null
		while [ $? -eq 0 ]; do
			echo -n "port looked busy, trying "
			PORT=`expr $PORT + 1`
			echo $PORT
			netstat -taln | grep $PORT > /dev/null
		done
		if [ ${PORT} -lt 1024 -a ${USER} != "root" ]; then
				echo you may not have permissions for ports less than 1024
		else
			echo using port $PORT
		fi
	fi
fi

#
# Start up the GUI
#
if [ $cli = 1 ]; then
	if [ $engine = 1 ]; then
		bristol -rate ${RATE} -count ${COUNT} ${PREARGS} $args -port $PORT ${POSTARGS} &
	fi
	export BRISTOL_LOG_CONSOLE=true
	brighton ${PREARGS} $args -port ${PORT} ${POSTARGS}
else
	if [ $gui = 1 ]; then
		if [ $engine = 1 ]; then
			if [ $quiet = 0 ]; then
				brighton ${PREARGS} $args -port ${PORT} ${POSTARGS} &
			else
				brighton ${PREARGS} $args -port ${PORT} ${POSTARGS} > /dev/null 2>&1 &
			fi
		else
			if [ $quiet = 0 ]; then
				if [ $execme = 0 ]; then
					if [ $valgrind = 0 ]; then
						brighton ${PREARGS} $args -port ${PORT} ${POSTARGS}
					else
						valgrind --leak-check=full -v --show-reachable=yes --track-origins=yes brighton $args -port ${PORT} ${POSTARGS}
					fi
				else
					exec brighton ${PREARGS} $args -port ${PORT} ${POSTARGS}
				fi
				guistatus=$?
			else
				if [ $execme = 0 ]; then
					brighton ${PREARGS} $args -port ${PORT} ${POSTARGS} > /dev/null 2>&1
				else
					exec brighton ${PREARGS} $args -port ${PORT} ${POSTARGS} > /dev/null 2>&1
				fi
				guistatus=$?
			fi
		fi
	fi

	#
	# the bristol engine has flags for -oss or -alsa drivers, -preload buffers of
	# -count samples:
	#	bristol -preload 4 -count 256 [-oss]
	#
	if [ $engine = 1 ]; then
		if [ $quiet = 0 ]; then
			if [ $valgrind = 0 ]; then
				if [ $execme = 0 ]; then
					bristol -rate ${RATE} -count ${COUNT} ${PREARGS} $args -port $PORT ${POSTARGS}
					engstatus=$?
				else
					exec bristol -rate ${RATE} -count ${COUNT} ${PREARGS} $args -port $PORT ${POSTARGS}
				fi
			else
				valgrind --leak-check=full -v --show-reachable=yes --track-origins=yes bristol -rate ${RATE} -count ${COUNT} ${PREARGS} $args -port $PORT ${POSTARGS}
				engstatus=$?
			fi
		else
			if [ $execme = 0 ]; then
				bristol -rate ${RATE} -count ${COUNT} ${PREARGS} $args -port $PORT ${POSTARGS} > /dev/null 2>&1
			else
				exec bristol -rate ${RATE} -count ${COUNT} ${PREARGS} $args -port $PORT ${POSTARGS} > /dev/null 2>&1
			fi
			engstatus=$?
		fi
	fi
fi

# Make sure we have the children returned, prevents ugly delayed output
if [ $engine = 1 ]; then
	wait % >/dev/null 2>&1
fi
if [ $gui = 1 ]; then
	wait % >/dev/null 2>&1
fi

sleep 1

if [ $FREQ != 0 -a -x /usr/bin/cpufreq-set ]; then
	cpufreq-set -d 250MHz
fi
# This could be a lot more intelligent but it will work. We need to remove any
# dangling sockets. Alternatively just delete the files, the check for their
# existance is superfluous
rm -f /tmp/br.* >/dev/null 2>&1

 exit `expr $engstatus + $guistatus`