Unify custom instruments and regular ones

This commit is contained in:
2024-03-16 20:09:52 -07:00
parent da41c77dad
commit 89aa2a0efb
2 changed files with 19 additions and 19 deletions

View File

@ -1,9 +1,8 @@
nflags=klass()
function nflags:init(o)
self.c = o.c or 0 -- custom
self.e = o.e or 0 -- effect
self.v = o.v or 0 -- volume
self.w = o.w or 0 -- waveform
self.w = o.w or 0 -- waveform and custom
self.p = o.p or 0 -- pitch
self:validate()
@ -14,32 +13,33 @@ function nflags:clone()
end
function nflags:validate()
local c,e,v,w,p
=self.c,self.e,self.v,self.w,self.p
local e,v,w,p
=self.e,self.v,self.w,self.p
assert_range(c,0,2,"custom")
assert_range(e,0,8,"effect")
assert_range(v,0,8,"volume")
assert_range(w,0,8,"waveform")
assert_range(w,0,16,"waveform")
assert_range(p,0,64,"pitch")
end
function nflags:encode()
self:validate()
local c,e,v,w,p
=self.c,self.e,self.v,self.w,self.p
local e,v,w,p
=self.e,self.v,self.w,self.p
c &= 0xffff
e &= 0xffff
v &= 0xffff
w &= 0xffff
p &= 0xffff
local wlow = w&7;
local whi = (w&8)>>3;
return (
(c << 15) |
(whi << 15) |
(e << 12) |
(v << 9) |
(w << 6) |
(wlow << 6) |
(p)
)
end