<commit_before>"use strict";

function gswaScheduler() {};

gswaScheduler.prototype = {
	setContext( ctx ) {
		this.ctx = ctx;
	},
	setBPM( bpm ) {
		this.bps = bpm / 60;
		this._updateDur();
	},
	setData( data ) {
		this.data = data;
		this._updateDur();
	},
	currentTime() {
		return this.started
			? ( this.ctx.currentTime -
				this._startedWhen +
				this._startedOffset ) * this.bps
			: 0;
	},
	stop() {
		if ( this.started ) {
			clearTimeout( this._timeout );
			this.onstop && this._smps.forEach( this.onstop );
			this._onended();
		}
	},
	startBeat( whenBeat, offsetBeat, durationBeat ) {
		return this.start(
			this.ctx.currentTime + whenBeat / this.bps,
			offsetBeat / this.bps,
			durationBeat / this.bps );
	},
	start( when, off, dur ) {
		when = when || this.ctx.currentTime;
		off = off || 0;
		dur = dur || dur === 0 ? dur : ( this.duration - off );
		this.started = true;
		this._startedWhen = when;
		this._startedOffset = off;
		this._smps = [];
		this.data.forEach( smp => {
			var sWhn = this._sWhn( smp ) - off,
				sOff = this._sOff( smp ),
				sDur = this._sDur( smp ),
				sEnd = sWhn + sDur;

			if ( sWhn < 0 ) {
				sOff -= sWhn;
				sDur += sWhn;
				sWhn = 0;
			}
			if ( sEnd > dur ) {
				sDur -= sEnd - dur;
			}
			if ( sDur > 0 ) {
				this._smps.push( smp );
				this.onstart( smp, when + sWhn, sOff, sDur );
			}
		} );
		this._timeout = setTimeout( this._onended.bind( this ), dur * 1000 );
	},
<commit_msg>gswaScheduler: .start() and .startBeat() take loopStartBeat and loopDurationBeat. .start() calls now ._start()<commit_after>"use strict";

function gswaScheduler() {};

gswaScheduler.prototype = {
	setContext( ctx ) {
		this.ctx = ctx;
	},
	setBPM( bpm ) {
		this.bps = bpm / 60;
		this._updateDur();
	},
	setData( data ) {
		this.data = data;
		this._updateDur();
	},
	currentTime() {
		return this.started
			? ( this.ctx.currentTime -
				this._startedWhen +
				this._startedOffset ) * this.bps
			: 0;
	},
	stop() {
		if ( this.started ) {
			clearTimeout( this._timeout );
			this.onstop && this._smps.forEach( this.onstop );
			this._onended();
		}
	},
	startBeat( whenBeat, offsetBeat, durationBeat, loopStartBeat, loopDurationBeat ) {
		return this.start(
			this.ctx.currentTime + whenBeat / this.bps,
			offsetBeat / this.bps,
			durationBeat / this.bps,
		 	loopStartBeat / this.bps,
			loopDurationBeat / this.bps
		);
	},
	start( when, off, dur, loopStart, loopDuration ) {
		when = when || this.ctx.currentTime;
		off = off || 0;
		dur = dur || dur === 0 ? dur : ( this.duration - off );

		this._start( when, off, dur );
	},

	// private:
	_start(  when, off, dur  ) {
		this.started = true;
		this._startedWhen = when;
		this._startedOffset = off;
		this._smps = [];
		this.data.forEach( smp => {
			var sWhn = this._sWhn( smp ) - off,
				sOff = this._sOff( smp ),
				sDur = this._sDur( smp ),
				sEnd = sWhn + sDur;

			if ( sWhn < 0 ) {
				sOff -= sWhn;
				sDur += sWhn;
				sWhn = 0;
			}
			if ( sEnd > dur ) {
				sDur -= sEnd - dur;
			}
			if ( sDur > 0 ) {
				this._smps.push( smp );
				this.onstart( smp, when + sWhn, sOff, sDur );
			}
		} );
		this._timeout = setTimeout( this._onended.bind( this ), dur * 1000 );
	},

{'fraction_non_alphanumeric': 0.1609984399375975, 'fraction_numerical': 0.00748829953198128, 'mean_word_length': 2.5308370044052864, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '792900', 'n_tokens_mistral': 1496, 'n_tokens_neox': 1233, 'n_words': 272}