-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscl2hz.dc
93 lines (79 loc) · 1.41 KB
/
scl2hz.dc
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
# Currently, this script is limited to working with scales where the
# assumption is a 2/1 (octave) period
"string.dc" import
"!" const :bang
"/" const :slash
# Get the filename
var filename_to_open
"SCALA_FILE" envget filename_to_open !
# Open file and assign file pointer
var myfile
filename_to_open @ "r" fopen myfile !
# data master array
var master_array 128 allot
var idx 0 idx !
261 const HZ_BASE
: is_bang_alone? { textline }
textline strlen 2 =
textline :bang strspn 1 =
and
;
: go_past_solo_bang
inf times
myfile @ freadline
0 = if
exittimes
else
is_bang_alone? if
exittimes
else
again
endif
endif
;
: write_and_advance
master_array idx @ + !
idx @ 1 + idx !
;
: calc_and_write_fraction
:slash str_split
dup lpop tonum
swap lpop tonum
swap /
write_and_advance
;
: calc_and_write_cents
tonum 1200 / 2 swap pow
write_and_advance
;
var myline # place to put line of text
: read_data
inf times
myfile @ freadline
-1 = if
exittimes
else
myline !
myline @ :slash strfind
if
myline @ calc_and_write_fraction
else
myline @ calc_and_write_cents
endif
again
endif
;
: show_data
6 -5 1 for
idx @ times
master_array i + @
261 2 j pow *
* . cr
again
next
;
# The main event:
go_past_solo_bang
go_past_solo_bang
read_data
show_data