Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion js/ft2.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
Greets to Guru, Alfred and CCR for their work figuring out the .xm format. :)
*/

function Fasttracker()
function Fasttracker(songEventListener)
{
this.songEventListener = songEventListener;

var i, t;

this.clearsong();
Expand Down Expand Up @@ -587,21 +589,25 @@ Fasttracker.prototype.advance = function(mod) {
mod.row++; mod.tick=0; mod.flags|=2;
}
}
this.songEventListener.onSongRowChange?.();
}

// step to new pattern?
if (mod.row>=mod.patternlen[mod.patterntable[mod.position]]) {
mod.position++;
mod.row=0;
mod.flags|=4;
this.songEventListener.onSongPatternChange?.();
}

// end of song?
if (mod.position>=mod.songlen) {
if (mod.repeat) {
mod.position=0;
this.songEventListener.onSongEnd?.(true);
} else {
this.endofsong=true;
this.songEventListener.onSongEnd?.(false);
}
return;
}
Expand Down Expand Up @@ -742,6 +748,9 @@ Fasttracker.prototype.process_tick = function(mod) {
if (!mod.tick) {
// process only on tick 0
mod.effects_t0[mod.channel[ch].command](mod, ch);
if (this.songEventListener.onSongEffect && (mod.channel[ch].command > 0 || mod.channel[ch].data > 0)) {
this.songEventListener.onSongEffect(ch, mod.channel[ch].command, mod.channel[ch].data);
}
} else {
mod.effects_t1[mod.channel[ch].command](mod, ch);
}
Expand Down
10 changes: 7 additions & 3 deletions js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ function Modplayer()
this.onReady=function(){};
this.onPlay=function(){};
this.onStop=function(){};
this.onSongPatternChange = null;
this.onSongEnd = null; // params = isRepeating
this.onSongRowChange = null;
this.onSongEffect = null; // params = channel, command, command-data

this.buffer=0;
this.mixerNode=0;
Expand Down Expand Up @@ -80,13 +84,13 @@ Modplayer.prototype.load = function(url)

switch (ext) {
case 'mod':
this.player=new Protracker();
this.player=new Protracker(this);
break;
case 's3m':
this.player=new Screamtracker();
this.player=new Screamtracker(this);
break;
case 'xm':
this.player=new Fasttracker();
this.player=new Fasttracker(this);
break;
}

Expand Down
17 changes: 15 additions & 2 deletions js/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
*/

// constructor for protracker player object
function Protracker()
function Protracker(songEventListener)
{
this.songEventListener = songEventListener;

var i, t;

this.clearsong();
Expand Down Expand Up @@ -350,14 +352,22 @@ Protracker.prototype.advance = function(mod) {
mod.row++; mod.tick=0; mod.flags|=2;
}
}
this.songEventListener.onSongRowChange?.();
}
if (mod.row>=64) {
mod.position++;
mod.row=0;
mod.flags|=4;
this.songEventListener.onSongPatternChange?.();
}
if (mod.row>=64) { mod.position++; mod.row=0; mod.flags|=4; }
if (mod.position>=mod.songlen) {
if (mod.repeat) {
mod.position=0;
this.songEventListener.onSongEnd?.(true);
} else {
this.endofsong=true;
//mod.stop();
this.songEventListener.onSongEnd?.(false);
}
return;
}
Expand Down Expand Up @@ -423,6 +433,9 @@ Protracker.prototype.mix = function(mod, bufs, buflen) {
if (!mod.tick) {
// process only on tick 0
mod.effects_t0[mod.channel[ch].command](mod, ch);
if (this.songEventListener.onSongEffect && (mod.channel[ch].command > 0 || mod.channel[ch].data > 0)) {
this.songEventListener.onSongEffect(ch, mod.channel[ch].command, mod.channel[ch].data);
}
} else {
mod.effects_t1[mod.channel[ch].command](mod, ch);
}
Expand Down
11 changes: 10 additions & 1 deletion js/st3.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
command data memory?
*/

function Screamtracker()
function Screamtracker(songEventListener)
{
this.songEventListener = songEventListener;

var i, t;

this.clearsong();
Expand Down Expand Up @@ -440,6 +442,7 @@ Screamtracker.prototype.advance = function(mod) {
mod.row++; mod.tick=0; mod.flags|=2;
}
}
this.songEventListener.onSongRowChange?.();
}

// step to new pattern?
Expand All @@ -448,14 +451,17 @@ Screamtracker.prototype.advance = function(mod) {
mod.row=0;
mod.flags|=4;
while (mod.patterntable[mod.position]==254) mod.position++; // skip markers
this.songEventListener.onSongPatternChange?.();
}

// end of song?
if (mod.position>=mod.songlen || mod.patterntable[mod.position]==255) {
if (mod.repeat) {
mod.position=0;
this.songEventListener.onSongEnd?.(true);
} else {
this.endofsong=true;
this.songEventListener.onSongEnd?.(false);
}
return;
}
Expand Down Expand Up @@ -547,6 +553,9 @@ Screamtracker.prototype.process_tick = function(mod) {
if (!mod.tick) {
// process only on tick 0 effects
mod.effects_t0[mod.channel[ch].command](mod, ch);
if (this.songEventListener.onSongEffect && (mod.channel[ch].command > 0 || mod.channel[ch].data > 0)) {
this.songEventListener.onSongEffect(ch, mod.channel[ch].command, mod.channel[ch].data);
}
} else {
mod.effects_t1[mod.channel[ch].command](mod, ch);
}
Expand Down