diff --git a/js/player.js b/js/player.js index 0ca2b13..26d0135 100644 --- a/js/player.js +++ b/js/player.js @@ -34,6 +34,7 @@ function Modplayer() this.onReady=function(){}; this.onPlay=function(){}; this.onStop=function(){}; + this.onMix=function(){}; this.buffer=0; this.mixerNode=0; @@ -316,7 +317,16 @@ Modplayer.prototype.patterndata = function(pn) { var i, c, patt; if (this.format=='mod') { - patt=new Uint8Array(this.player.pattern_unpack[pn]); + if (this.player.track_index) { + patt = new Uint8Array(64*this.player.channels*5); + for(i=0;i<64;i++) for(c=0;c this.patterns) this.patterns=this.patterntable[i]; - } - this.patterns+=1; - var patlen=4*64*this.channels; + bufp += 30*this.samples + (this.signature === "KRIS" ? 4 : 0); + this.songlen=buffer[bufp]; + if (buffer[bufp+1] != 127) this.repeatpos=buffer[bufp+1]; + bufp += 2; - this.pattern=new Array(); - this.note=new Array(); - this.pattern_unpack=new Array(); - for(i=0;i this.patterns) this.patterns=this.patterntable[i]; } - for(j=0;j<64;j++) { - for(c=0;c>4; - this.pattern_unpack[i][ppu+2]=255; - this.pattern_unpack[i][ppu+3]=this.pattern[i][pp+2]&0x0f; - this.pattern_unpack[i][ppu+4]=this.pattern[i][pp+3]; + this.patterns+=1; + var patlen=4*64*this.channels; + + bufp += 128 + (this.samples===15 ? 0 : 4); + this.pattern=new Array(); + this.note=new Array(); + this.pattern_unpack=new Array(); + for(i=0;i>4; + this.pattern_unpack[i][ppu+2]=255; + this.pattern_unpack[i][ppu+3]=this.pattern[i][pp+2]&0x0f; + this.pattern_unpack[i][ppu+4]=this.pattern[i][pp+3]; + } + } + } + } else { + this.track_index = buffer.slice(bufp, bufp + 128*this.channels*2); + + for(i = 0; i < 128; i++) { + for(c = 0; c < this.channels; c++) { + if (this.track_index[2*this.channels*i+2*c] > this.patterns) + this.patterns = this.track_index[2*this.channels*i+2*c]; + } + } + this.patterns += 1; + patlen = 4*64; + + bufp += 2+this.track_index.length; + this.pattern=new Array(); + this.note=new Array(); + this.pattern_unpack=new Array(); + for(i=0;i= 0 && np < this.baseperiodtable.length) ? np : 0; + } + for(j=0;j<64;j++) { + var pp=j*4; + var ppu=j*5; + var n = this.baseperiodtable[this.pattern[i][pp]/2-36]; + if (n) { nn=this.note[i][j]; nn=(nn%12)|(Math.floor(nn/12)+2)<<4; } + this.pattern_unpack[i][ppu+0]=(nn)?nn:255; + this.pattern_unpack[i][ppu+1]=this.pattern[i][pp+1]; + this.pattern_unpack[i][ppu+2]=255; + this.pattern_unpack[i][ppu+3]=this.pattern[i][pp+2]&0x0f; + this.pattern_unpack[i][ppu+4]=this.pattern[i][pp+3]; + nn = this.pattern[i][pp+1]; + this.pattern[i][pp+0] = (n>>8)&0x0f || nn&0xf0; + this.pattern[i][pp+1] = n&0xff; + this.pattern[i][pp+2] = (nn&0xf)<<4 | this.pattern[i][pp+2]&0xf; } } } - var sst=1084+this.patterns*patlen; + var sst=bufp+this.patterns*patlen; for(i=0;i=0 && oldrow>=0) $(".currentrow").removeClass("currentrow"); - $("#pattern"+hb(mod.currentpattern())+"_row"+hb(mod.row)).addClass("currentrow"); - $("#pattern"+hb(mod.currentpattern())).scrollTop(mod.row*16); + $("#pattern"+hb(mod.position)+"_row"+hb(mod.row)).addClass("currentrow"); + $("#pattern"+hb(mod.position)).scrollTop(mod.row*16); if (oldpos != mod.position) { if (oldpos>=0) $(".currentpattern").removeClass("currentpattern"); - $("#pattern"+hb(mod.currentpattern())).addClass("currentpattern"); + $("#pattern"+hb(mod.position)).addClass("currentpattern"); } } @@ -354,10 +354,12 @@ $(document).ready(function() { var s=window.currentModule.split("/"); if (s.length > 1) { $("title").html(s[1]+" - module player for Web Audio"); - window.history.pushState("object of string", "Title", "/"+s[0]+"/"+s[1]); + if (window.location.protocol !== "file:") + window.history.pushState("object of string", "Title", "/"+s[0]+"/"+s[1]); } else { $("title").html(s[0]+" - module player for Web Audio"); - window.history.pushState("object of string", "Title", "/"+s[0]); + if (window.location.protocol !== "file:") + window.history.pushState("object of string", "Title", "/"+s[0]); } if (window.playlistActive) { @@ -369,7 +371,7 @@ $(document).ready(function() { } var pd=""; - for(p=0;p"; for(i=0; i<12; i++) pd+="\n"; @@ -503,6 +505,7 @@ $(document).ready(function() { $("#modfile").focus(); var s=document.getElementById("modfile"); var i=s.selectedIndex; + if (!s[i]) return; s[i].selected=false; s[(i<(s.length-12))?(i+12):(s.length-1)].selected=true; s[i].selected=true;