From 95d86bb823ad98581fd54b1ab7997b8083c800c3 Mon Sep 17 00:00:00 2001 From: Keith Clark Date: Fri, 7 Aug 2020 17:39:19 +0100 Subject: [PATCH] Ensure channel panning value always resolves to a number. Add note to README about the optional value behaviour. --- README.md | 2 +- zzfxm.js | 4 ++-- zzfxm.min.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f30ef5c..a9ebb57 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,7 @@ Param | Description | Default | Min Value | Max Value ``` Channel data is a single array containing the instrument, panning and note data the current pattern. -The first slot indicates which instrument to use for playing notes. Slot 2 contains the channel panning value and slots 3 onwards hold the note. +The first slot indicates which instrument to use for playing notes. Slot 2 contains the channel panning value and slots 3 onwards hold the note. If the array slot for an instrument, panning or note value is left empty it will coalesced to `0`. ## `` structure diff --git a/zzfxm.js b/zzfxm.js index 1fdc8e2..92e1183 100644 --- a/zzfxm.js +++ b/zzfxm.js @@ -30,7 +30,7 @@ * @returns {Array.>} Left and right channel sample data. */ -const zzfxM = (instruments, patterns, sequence, BPM = 125) => { +zzfxM = (instruments, patterns, sequence, BPM = 125) => { let instrumentParameters; let i; let j; @@ -97,7 +97,7 @@ const zzfxM = (instruments, patterns, sequence, BPM = 125) => { if (note) { // set attenuation attenuation = note % 1; - panning = patternChannel[1]; + panning = patternChannel[1] || 0; if (note |= 0) { // get cached sample sampleBuffer = sampleCache[ diff --git a/zzfxm.min.js b/zzfxm.min.js index e7911da..5b7b3cc 100644 --- a/zzfxm.min.js +++ b/zzfxm.min.js @@ -1,2 +1,2 @@ //! ZzFXM (v2.0.1) | (C) Keith Clark | MIT | https://github.com/keithclark/ZzFXM -zzfxM=(f,n,o,t=125)=>{let z,e,l,r,g,h,x,a,u,c,d,i,m,p,G,M,R=[],b=[],j=[],k=0,q=1,s={},v=zzfxR/t*60>>2;for(;q;k++)R=[q=a=d=m=0],o.map((t,d)=>{for(x=n[t][k]||[0,0,0],q|=!!n[t][k],G=m+(n[t][0].length-2-!a)*v,e=2,r=m;ev-99&&u?i+=(i<1)/99:0)h=(1-i)*R[p++]/2||0,b[r]=(b[r]||0)+h*M-h,j[r]=(j[r++]||0)+h*M+h;g&&(i=g%1,M=x[1],(g|=0)&&(R=s[[c=x[p=0]||0,g]]=s[[c,g]]||(z=[...f[c]],z[2]*=2**((g-12)/12),zzfxG(...z))))}m=G});return[b,j]} \ No newline at end of file +zzfxM=(f,n,o,t=125)=>{let z,e,l,r,g,h,x,a,u,c,d,i,m,p,G,M,R=[],b=[],j=[],k=0,q=1,s={},v=zzfxR/t*60>>2;for(;q;k++)R=[q=a=d=m=0],o.map((t,d)=>{for(x=n[t][k]||[0,0,0],q|=!!n[t][k],G=m+(n[t][0].length-2-!a)*v,e=2,r=m;ev-99&&u?i+=(i<1)/99:0)h=(1-i)*R[p++]/2||0,b[r]=(b[r]||0)+h*M-h,j[r]=(j[r++]||0)+h*M+h;g&&(i=g%1,M=x[1]||0,(g|=0)&&(R=s[[c=x[p=0]||0,g]]=s[[c,g]]||(z=[...f[c]],z[2]*=2**((g-12)/12),zzfxG(...z))))}m=G});return[b,j]} \ No newline at end of file