-
Notifications
You must be signed in to change notification settings - Fork 2
/
MidiSynth Instrument File.tcl
153 lines (127 loc) · 2.76 KB
/
MidiSynth Instrument File.tcl
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
#
# MidiSynth Instrument file
# APDA SynthLab User's Manual Appendix A pg 33
#
little_endian
requires 0 "49 4E 53 54"
set Instruments { "" }
proc pstr { n name } {
set p [pos]
set len [uint8]
if { $len == 0 } {
move -1
entry $name "" $n
bytes $n
return ""
}
if { $len >= $n } { set len [expr $n - 1] }
set str [ascii $len]
goto $p
entry $name $str $n ;# [expr $len + 1]
bytes $n
return $str
}
proc waveref {} {
uint8 "WaveList 1 wave number"
uint8 "WaveList 2 wave number"
uint8 "WaveList 3 wave number"
uint8 "WaveList 4 wave number"
uint8 "WaveList 5 wave number"
uint8 "WaveList 6 wave number"
uint8 "WaveList 7 wave number"
uint8 "WaveList 8 wave number"
}
proc waveref_block {} {
# $200 bytes
section "Wave Ref Block" {
for { set n 1 } { $n < 17 } { incr n } {
section "Instr #$n Wave Ref" {
section "Gen 1 Osc A" { waveref }
section "Gen 1 Osc B" { waveref }
section "Gen 2 Osc A" { waveref }
section "Gen 2 Osc B" { waveref }
}
}
}
}
proc envelope {} {
section "Envelope" {
uint8 "Attack Level"
uint8 "Attack Rate"
uint8 "Decay 1 Level"
uint8 "Decay 1 Rate"
uint8 "Decay 2 Level"
uint8 "Decay 2 Rate"
uint8 "Sustain Level"
uint8 "Decay 3 Rate"
uint8 "Release 1 Level"
uint8 "Release 1 Rate"
uint8 "Release 2 Level"
uint8 "Release 2 Rate"
uint8 "Release 3 Rate"
uint8 "Decay Gain"
uint8 "Veclocity Gain"
uint8 "Pitch Bend"
}
}
proc wavelist { n } {
section "WaveList $n" {
uint8 "Top key"
uint8 "Configuration"
uint8 "Channel"
uint8 "Detune"
uint8 "Wave Address A"
uint8 "Wave Size A"
uint8 "Volume A"
uint8 "Octave Tuning A"
uint8 "Semi-tone Tuning A"
uint8 "Fine Tuning A"
uint8 "Wave Address B"
uint8 "Wave Size B"
uint8 "Volume B"
uint8 "Octave Tuning B"
uint8 "Semi-tone Tuning B"
uint8 "Fine Tuning B"
}
}
section "Instrument Header" {
ascii 4 "File Type"
uint16 -hex "Version"
uint16 "Size" ;# 400
ascii 16 "Owner" ;#
pstr 16 "Wave File" ;# actually a pascal string
uint8 "Master Semi-tone tuning"
uint8 "Master Fine tuning"
uint8 "Reserved"
uint8 "Master Volume"
set instr_count [uint8 "Number of Instruments"]
# uint16 "Reserved"
bytes 3 "Reserved"
# bytes 512 "Wave Ref Block"
waveref_block
bytes 208 "Free"
# 16 instrument names (16-byte pascal strings)
# pstr "Instrument #1"
for { set i 1 } { $i < 17 } { incr i } {
set iname [pstr 16 "Instrument #$i"]
lappend Instruments $iname
# ascii 16 "Instrument #$i"
}
}
for { set j 1 } { $j < 17 } { incr j } {
section "Instr #$j" {
sectionvalue [lindex $Instruments $j]
section "Generator 1" {
envelope
for { set i 1 } { $i < 9 } { incr i } {
wavelist $i
}
}
section "Generator 2" {
envelope
for { set i 1 } { $i < 9 } { incr i } {
wavelist $i
}
}
}
}