-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModel.js
More file actions
179 lines (157 loc) · 3.76 KB
/
Model.js
File metadata and controls
179 lines (157 loc) · 3.76 KB
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
import {freeze} from './Util.js'
export const defaultSampleRate = 44100
export const mod = freeze({
numSamples: 32, // 0th sample is empty!
numPitches: 60,
numSongPositions: 128,
maxPatterns: 128,
maxChannels: 32,
numRows: 64,
maxVolume: 64,
maxSampleNameLength: 22,
maxSampleLength: 2 ** 17 - 2,
defaultTempo: 125,
defaultSpeed: 6,
defaultChannels: 4,
})
/**
* @typedef {{
* name: string
* wave: Readonly<Int8Array<ArrayBuffer>> // MOD format requires length to be even
* loopStart: number // MOD format requires loop points to be even
* loopEnd: number
* finetune: number // -8 to 7
* volume: number
* }} Sample
*/
export const Sample = freeze({
/** @type {Readonly<Sample>} */
empty: freeze({
name: '',
wave: new Int8Array(),
loopStart: 0,
loopEnd: 0,
finetune: 0,
volume: mod.maxVolume,
}),
/**
* @param {Readonly<Pick<Sample, 'loopStart' | 'loopEnd'>>} s
*/
hasLoop(s) {
return s.loopEnd > s.loopStart
},
/**
* @param {number} pos
*/
roundToNearest(pos) {
return Math.round(pos / 2) * 2
},
/**
* @param {number} pos
*/
roundDown(pos) {
return pos & ~1
},
})
/**
* @typedef {{
* pitch: number // -1 = no note
* inst: number // 0 = no instrument
* effect: Effect
* param0: number
* param1: number
* }} Cell
*/
export const Cell = freeze({
/** @type {Readonly<Cell>} */
empty: freeze({
pitch: -1,
inst: 0,
effect: 0,
param0: 0,
param1: 0,
}),
/**
* Interpret the parameter hex digits as a single byte
* @param {Readonly<Pick<Cell, 'param0' | 'param1'>>} c
*/
paramByte(c) {
return (c.param0 << 4) | c.param1
},
/**
* Interpret the parameter hex digits as binary-coded decimal
* @param {Readonly<Pick<Cell, 'param0' | 'param1'>>} c
*/
paramDecimal(c) {
return c.param0 * 10 + c.param1
},
})
/** @enum {number} */
export const CellPart = freeze({
pitch: 0x1,
inst: 0x2,
effect: 0x4,
param: 0x8,
none: 0x0,
all: 0xf,
})
/** @enum {number} */
export const Effect = freeze({
Arpeggio: 0x0,
SlideUp: 0x1,
SlideDown: 0x2,
Portamento: 0x3,
Vibrato: 0x4,
VolSlidePort: 0x5,
VolSlideVib: 0x6,
Tremolo: 0x7,
Panning: 0x8, // not supported by Protracker
SampleOffset: 0x9,
VolumeSlide: 0xA,
PositionJump: 0xB,
Volume: 0xC,
PatternBreak: 0xD,
Extended: 0xE,
Speed: 0xF,
})
/** @enum {number} */
export const ExtEffect = freeze({
// Filter: 0x0, (not supported in XM)
FineSlideUp: 0x1,
FineSlideDown: 0x2,
Glissando: 0x3,
VibratoWave: 0x4,
Finetune: 0x5,
PatternLoop: 0x6,
TremoloWave: 0x7,
Panning: 0x8, // not supported by FastTracker, 8xx is preferred
Retrigger: 0x9,
FineVolumeUp: 0xA,
FineVolumeDown: 0xB,
NoteCut: 0xC,
NoteDelay: 0xD,
PatternDelay: 0xE,
// InvertLoop: 0xF, (not supported in XM)
})
/**
* @typedef {Readonly<Cell>[]} PatternChannel
*/
export const PatternChannel = freeze({})
/**
* @typedef {Readonly<PatternChannel>[]} Pattern
*/
export const Pattern = freeze({})
/**
* @typedef {{
* name: string
* numChannels: number
* sequence: readonly number[]
* restartPos: number
* patterns: readonly Readonly<Pattern>[]
* samples: readonly Readonly<Sample>[]
* }} Module
*/
export const Module = freeze({})
if (import.meta.main) {
;/** @satisfies {Serializable} */(/** @type {Module} */(null))
}