-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheffect_maker
executable file
·493 lines (459 loc) · 12.1 KB
/
effect_maker
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
#!/bin/bash
user_name="$( whoami )" # i need this for the function show_error to filter only user pid
### Values ##################################################
user_values=("0" "0" "0" "0" "0" "0" "0" "0" "0")
bank_effect=("leer" "leer" "leer" "leer" "leer" "leer" "leer" "leer" "leer" "leer" "leer" "leer")
option_key=("a" "y" "s" "x" "d" "c" "f" "v" "g" "b" "h" "n" "j" "m" "k" "," "l" ".")
control_key=(" r " " e " " t " "1-9" " z " " 0 " " p " " o " " i " " u " " w " )
control_key_desc=("Set Values to 0" "Load Values" "Save Values" "Load Bank" "Delete Bank" "Switch Bank" "Play Testsound" "Refresh GUI" "Play All" "Save All" "Show error message if it sounds crazy")
### function delete_bank ########################################
function delete_bank {
printf " Which bank do you want to remove? :"
read which_bank
delete_bank_name="${bank_effect[$which_bank-1]}"
rm "savenload/$delete_bank_name"
bank_effect[$which_bank-1]="leer"
if [[ "$EFFECT_NAME" -eq "$delete_bank_name" ]]; then
unset effect_options
unset max_values
unset step_size
unset user_values
fi
}
### function reset ##############################################
function reset_user_values {
i=0
index=${#user_values[*]}
while [[ "$i" -lt "$index" ]]; do
user_values[$i]="0"
i=$[$i+1]
done
unset i
unset index
}
### function load ###############################################
function load_user_values {
if [[ -e savenload/$EFFECT_NAME ]]; then
load_values=( $( cat savenload/$EFFECT_NAME ) )
i=1
index="${#load_values[*]}"
while [[ "$i" -lt "$index" ]]; do
user_values[$i-1]="${load_values[$i]}"
i=$[$i+1]
done
fi
unset i
unset index
}
### funktion save ##############################################
function save {
if ! [[ -z "$EFFECT_NAME" ]]; then
if ! [[ "$EFFECT_NAME" == "leer" ]]; then
temp_effect="$EFFECT_NAME"
i=0
index="${#effect_options[*]}"
while [[ "$i" -lt "$index" ]]; do
usr_values="${user_values[$i]}"
temp_effect="$temp_effect"' '"$usr_values"
i=$[$i+1]
done
echo $temp_effect > "savenload/$EFFECT_NAME"
fi
fi
unset i
unset index
unset usr_values
}
### Function save_all #######################################
function save_all {
### Ask for a name ###
choose_name=$1
while [[ -z "$choose_name" ]]; do
printf "Choose filename of your effect.file:"
read choose_name
if [[ -e effects/$choose_name ]]; then
printf "\nfilename exist. Will you overwrite it? [y/n]:\n"
read overwrite_file
if [[ "$overwrite_file" = "y" ]]; then
echo "" > "effects/$choose_name"
else
unset choose_name
fi
else
touch "effects/$choose_name"
fi
done
if [[ "$choose_name" = "test.all.play" ]]; then
rm test.all.play 1>&/dev/null
touch test.all.play
else
choose_name="effects/$choose_name"
fi
i=0
index="${#bank_effect[*]}"
while [[ "$i" -lt "$index" ]]; do
if ! [[ "${bank_effect[$i]}" = "leer" ]]; then
sv_EFFECT_NAME="${bank_effect[$i]}"
### load user settings lus ###
### load separator ls ###
### finish it ###
temp_effect="$sv_EFFECT_NAME"' ' # fi
if [[ -e savenload/$sv_EFFECT_NAME ]]; then
sv_load_values=( $( cat savenload/$sv_EFFECT_NAME ) ) # lus
sv_EFFECT=( $( cat $EFFECTS_FOLDER""$sv_EFFECT_NAME ) ) # ls
sv_i=0 # lus ls
sv_index="${#sv_load_values[*]}" # lus ls
sv_y=0 # ls
while [[ "$sv_i" -lt "$sv_index" ]]; do # lus ls
sv_user_values[$sv_i]="${sv_load_values[$sv_i+1]}" # lus
sv_separator[$sv_i]="${sv_EFFECT[$sv_y+5]}" # ls
sv_usr_values="${sv_user_values[$sv_i]}" # fi
sv_sep="${sv_separator[$sv_i]}" # fi
if [[ "$sv_sep" = "s" ]]; then #fi
temp_effect="$temp_effect"''"$sv_usr_values"' ' #fi
else #fi
temp_effect="$temp_effect"''"$sv_usr_values"''"$sv_sep" #fi
fi #fi
sv_i=$[$sv_i+1] # lus ls fi
sv_y=$[$sv_y+6] # ls
done # lus ls fi
fi
echo "$temp_effect" >> "$choose_name" # fi
fi
i=$[$i+1]
done
killall play 1>&/dev/null
play -q test.wav $( cat $choose_name ) 1>&/tmp/error1 &
unset i
unset index
unset choose_name
unset sv_i
unset sv_index
unset sv_y
unset temp_effect
unset sv_load_values
unset sv_EFFECT_NAME
unset sv_EFFECT
unset sv_user_values
unset sv_separator
unset sv_usr_values
unset sv_sep
unset temp_effect
}
### Function preload ########################################
function preload {
EFFECTS_FOLDER='effect_desc/'
ls $EFFECTS_FOLDER > /var/tmp/effect_maker
printf "\n"
if ! [[ "$1" -eq "0" ]]; then
cat -n /var/tmp/effect_maker
printf '\nChoose an effect in integer :'
read CHOOSE_EFFECT
EFFECT_NAME=$(tail +$CHOOSE_EFFECT /var/tmp/effect_maker | head -1)
bank_effect[$1-1]=$EFFECT_NAME
else
x=0
z="${#bank_effect[*]}"
while [[ "$x" -lt "$z" ]]; do
t=$[$x+1]
if ! [[ "${bank_effect[$x]}" == "leer" ]]; then
printf "$t"'. '"${bank_effect[$x]} "
fi
x=$[$x+1]
if [[ $( echo "$t % 6 |bc" ) -eq "0" ]]; then
printf "\n"
fi
done
test_it="leer"
while [[ "$test_it" == "leer" ]]; do
printf "Which bank do you want to switch to: "
read CHOOSE_EFFECT
test_it="${bank_effect[$CHOOSE_EFFECT-1]}"
done
EFFECT_NAME="$test_it"
fi
EFFECT=( $( cat $EFFECTS_FOLDER""$EFFECT_NAME ) )
index="${#EFFECT[*]}"
i=0
y=0
unset effect_options
unset min_values
unset max_values
unset step_size
unset user_values
unset separator
while [[ "$i" -lt "$index" ]]; do
effect_options[$y]="${EFFECT[$i]}"
min_values[$y]="${EFFECT[$i+1]}"
max_values[$y]="${EFFECT[$i+2]}"
step_size[$y]="${EFFECT[$i+3]}"
user_values[$y]="${EFFECT[$i+4]}"
separator[$y]="${EFFECT[$i+5]}"
i=$[$i+6]
y=$[$y+1]
done
if [[ "$1" -eq "0" ]]; then
load_user_values
fi
unset i
unset y
unset x
unset z
unset index
unset CHOOSE_EFFECT
}
### Function gui_balken #####################################
function gui_balken {
display_var_as_block "$1" "12"
display_var_as_block "$2" "4"
display_var_as_block "$3" "4"
display_var_as_block "$4" "12"
display_var_as_block "$5" "12"
printf "\n"
}
### Function gui_text #####################################
function gui_text {
pos=$(echo "$1" |wc -m )
max=20
printf " "$1
while [[ "$pos" -lt "$max" ]]; do
printf " "
pos=$[$pos+1]
done
unset pos
unset max
}
### Function gui_bank ########################################
function gui_bank {
i=0
index="${#bank_effect[*]}"
while [[ "$i" -lt "$index" ]]; do
y=$[$i+1]
if [[ "$y" -gt 9 ]]; then
transport="$y"'.'"${bank_effect[$i]}"
else
transport="0$y"'.'"${bank_effect[$i]}"
fi
if [[ "${bank_effect[$i]}" = "$EFFECT_NAME" ]]; then
transport="$transport"'.'"active"
fi
gui_text $transport
if [[ "$i" = 3 || "$i" = 7 ]]; then
printf "\n"
fi
i=$[$i+1]
done
printf "\n"
unset i
unset y
unset transport
}
### Function keydescriptions ################################
function key_desc {
i=0
index="${#control_key[*]}"
while [[ "$i" -lt "$index" ]]; do
display_var_as_block " < ${control_key[$i]} >" "5"
display_var_as_block "${control_key_desc[$i]}" "20"
if [[ $( echo "( $i + 1 ) % 3" | bc ) -eq 0 ]]; then
printf "\n"
fi
i=$[$i+1]
done
printf "\n"
unset i
unset index
}
### Function line ###########################################
function line {
i=0
while [[ "$i" -lt 80 ]]; do
printf "#"
i=$[$i+1]
done
printf "\n"
unset i
}
### Function lbr ############################################
function lbr {
printf "\n"
}
### Funtion display_var_as_block (var, blocksize) ##########
function display_var_as_block {
printf "$1"
pos=$( echo "$1" | wc -m )
while [[ "$pos" -lt "$2" ]]; do
printf " "
pos=$[$pos+1]
done
unset pos
}
### Function header ########################################
function header {
line
lbr
gui_bank
lbr
line
}
### Function footer ########################################
function footer {
line
lbr
key_desc
lbr
line
printf "columns: $( tput cols ) lines: $( tput lines) \n"
printf "Press < o > to refresh ui and delete below messages:\n"
}
### Function tput_pos ######################################
function tput_pos {
if ! [[ -z $2 ]]; then
tput sc
line=$[$1+9]
tput cup $line 22
printf " "
tput rc
if [[ $( echo "$2 < 0" |bc ) = "0" ]]; then
if [[ $( echo "$2 < 10" | bc ) = "1" && $( echo "$2 >= 0" | bc ) = "1" ]]; then
column=27
elif [[ $( echo "$2 < 100" | bc ) = "1" && $( echo "$2 >= 10" | bc ) = "1" ]]; then
column=26
elif [[ $( echo "$2 < 1000" | bc ) = "1" && $( echo "$2 >= 100" | bc ) = "1" ]]; then
column=25
elif [[ $( echo "$2 < 10000" | bc ) = "1" && $( echo "$2 >= 1000" | bc ) = "1" ]]; then
column=24
fi
else
if [[ $( echo "$2 > -10" | bc ) = "1" && $( echo "$2 <= 0" | bc ) = "1" ]]; then
column=26
elif [[ $( echo "$2 > -100" | bc ) = "1" && $( echo "$2 <= -10" | bc ) = "1" ]]; then
column=25
elif [[ $( echo "$2 > -1000" | bc ) = "1" && $( echo "$2 <= -100" | bc ) = "1" ]]; then
column=24
elif [[ $( echo "$2 > -10000" | bc ) = "1" && $( echo "$2 <= -1000" | bc ) = "1" ]]; then
column=23
fi
fi
tput cup $line $column
printf "%s" "$2"
tput rc
unset line
unset output
unset column
fi
}
### Function build gui #####################################
function build_gui {
lbr
gui_text "Name"
gui_balken "Position" "+" "-" "Max Value" "Step Size"
i=0
index="${#effect_options[*]}"
while [[ "$i" -lt "$index" ]]; do
gui_text "${effect_options[$i]}"
gui_balken "" "${option_key[$y]}" "${option_key[$y+1]}" "${max_values[$i]}" "${step_size[$i]}"
tput_pos "$i" "${user_values[$i]}"
i=$[$i+1]
y=$[$y+2]
done
lbr
unset y
unset i
unset index
}
### Function refresh_gui ##################################
function refresh_gui {
clear
header
build_gui
footer
}
### Function show_error ###################################
function show_error {
printf "wait for play error message"
while ! [[ -z "$( pgrep -u "$user_name" play )" ]]; do
printf "."
done
refresh_gui
error1="$( cat /tmp/error1 )"
rm /tmp/error1 && touch /tmp/error1
printf "%s" "$error1"
}
### Function play_all #####################################
function play_all {
save_all "test.all.play"
}
### Function sox_play #####################################
function sox_play {
temp_effect="$EFFECT_NAME"' '
i=0
index="${#effect_options[*]}"
while [[ "$i" -lt "$index" ]]; do
usr_values="${user_values[$i]}"
sep=${separator[$i]}
if [[ "$sep" = "s" ]]; then
temp_effect="$temp_effect"''"$usr_values"' '
else
temp_effect="$temp_effect"''"$usr_values"''"$sep"
fi
i=$[$i+1]
done
echo $temp_effect > temp.effect
killall play 1>&/dev/null
play -q test.wav $( cat temp.effect ) 1>&/tmp/error1 &
unset i
unset index
unset usr_values
unset temp_effect
}
### Function KeyPress #####################################
function keypress {
case "$1" in
q) stop=1 ;;
p) sox_play ;;
e) load_user_values; refresh_gui; save ;;
r) reset_user_values; refresh_gui; save ;;
t) save ;;
z) delete_bank; preload "0"; refresh_gui; save ;;
o) refresh_gui ;;
i) save; play_all ;;
u) save; save_all ;;
[0-9]) save; preload $1; refresh_gui; save ;;
w) show_error ;;
*)
i=0
y=0
index=${#option_key[*]}
while [[ "$i" -lt "$index" ]]; do
if [[ "$1" = "${option_key[$i]}" ]]; then
if [[ $( echo "$i % 2" | bc ) -eq "0" ]]; then
if [[ $( echo "${user_values[$y]} < ${max_values[$y]}" |bc ) -eq "1" ]]; then user_values[$y]=$( echo "${user_values[$y]}+${step_size[$y]}" | bc ); fi
else
if [[ $( echo "${user_values[$y]} > ${min_values[$y]}" |bc ) -eq "1" ]]; then user_values[$y]=$( echo "${user_values[$y]}-${step_size[$y]}" | bc ); fi
fi
### repair point failure
usr_val_str=${user_values[$y]}
if [[ ${usr_val_str:0:1} == "." ]]; then
user_values[$y]='0'"${user_values[$y]}"
fi
tput_pos "$y" "${user_values[$y]}"
i=$index
fi
i=$[$i+1]
if [[ $( echo "$i % 2" | bc ) -eq "0" ]]; then y=$[$y+1]; fi
done
unset usr_val_str
unset i
unset y
unset index ;;
esac
}
### Working zone ##########################################
stop=0
refresh_gui
while [[ "$stop" = 0 ]]; do
tput_pos
read -s -n 1 key
keypress $key
done