<commit_before>import { getContext } from "../Global";
import { Tone } from "../Tone";
import { FrequencyClass } from "../type/Frequency";
import { TimeClass } from "../type/Time";
import { TransportTimeClass } from "../type/TransportTime";
import "../type/Units";
import { getDefaultsFromInstance, omitFromObject, optionsFromArguments } from "../util/Defaults";
import { RecursivePartial } from "../util/Interface";
import { isArray, isDefined, isNumber, isString, isUndef } from "../util/TypeCheck";
import { Context } from "./Context";

/**
 * A unit which process audio
 */
export interface ToneWithContextOptions {
	context: Context;
}

/**
 * The Base class for all nodes that have an AudioContext.
 */
export abstract class ToneWithContext<Options extends ToneWithContextOptions> extends Tone {

	/**
	 * The context belonging to the node.
	 */
	readonly context: Context;

	/**
	 * The default context to use if no AudioContext is passed in to the constructor
	 */
	readonly defaultContext?: Context;

	constructor(context?: Context | Partial<ToneWithContextOptions>) {
		const options = optionsFromArguments(ToneWithContext.getDefaults(), arguments, ["context"]);
		super();
		if (this.defaultContext) {
			this.context = this.defaultContext;
		} else {
			this.context = options.context;
		}
	}

	static getDefaults(): ToneWithContextOptions {
		return {
			context: getContext(),
		};
	}

	/**
	 * Return the current time of the Context clock plus the lookAhead.
	 */
	now(): Seconds {
		return this.context.currentTime + this.context.lookAhead;
	}

	/**
	 * Return the current time of the Context clock without any lookAhead.
	 */
	immediate(): Seconds {
		return this.context.currentTime;
	}

	/**
	 * The duration in seconds of one sample.
	 */
	get sampleTime(): Seconds {
		return 1 / this.context.sampleRate;
	}

	/**
	 * The number of seconds of 1 processing block (128 samples)
	 */
	get blockTime(): Seconds {
		return 128 / this.context.sampleRate;
	}

	/**
	 * Convert the incoming time to seconds
	 */
	toSeconds(time: Time): Seconds {
		return new TimeClass(this.context, time).toSeconds();
	}
<commit_msg>time is optional in toSeconds<commit_after>import { getContext } from "../Global";
import { Tone } from "../Tone";
import { FrequencyClass } from "../type/Frequency";
import { TimeClass } from "../type/Time";
import { TransportTimeClass } from "../type/TransportTime";
import "../type/Units";
import { getDefaultsFromInstance, omitFromObject, optionsFromArguments } from "../util/Defaults";
import { RecursivePartial } from "../util/Interface";
import { isArray, isDefined, isNumber, isString, isUndef } from "../util/TypeCheck";
import { Context } from "./Context";

/**
 * A unit which process audio
 */
export interface ToneWithContextOptions {
	context: Context;
}

/**
 * The Base class for all nodes that have an AudioContext.
 */
export abstract class ToneWithContext<Options extends ToneWithContextOptions> extends Tone {

	/**
	 * The context belonging to the node.
	 */
	readonly context: Context;

	/**
	 * The default context to use if no AudioContext is passed in to the constructor
	 */
	readonly defaultContext?: Context;

	constructor(context?: Context | Partial<ToneWithContextOptions>) {
		const options = optionsFromArguments(ToneWithContext.getDefaults(), arguments, ["context"]);
		super();
		if (this.defaultContext) {
			this.context = this.defaultContext;
		} else {
			this.context = options.context;
		}
	}

	static getDefaults(): ToneWithContextOptions {
		return {
			context: getContext(),
		};
	}

	/**
	 * Return the current time of the Context clock plus the lookAhead.
	 */
	now(): Seconds {
		return this.context.currentTime + this.context.lookAhead;
	}

	/**
	 * Return the current time of the Context clock without any lookAhead.
	 */
	immediate(): Seconds {
		return this.context.currentTime;
	}

	/**
	 * The duration in seconds of one sample.
	 */
	get sampleTime(): Seconds {
		return 1 / this.context.sampleRate;
	}

	/**
	 * The number of seconds of 1 processing block (128 samples)
	 */
	get blockTime(): Seconds {
		return 128 / this.context.sampleRate;
	}

	/**
	 * Convert the incoming time to seconds
	 */
	toSeconds(time?: Time): Seconds {
		return new TimeClass(this.context, time).toSeconds();
	}

{'fraction_non_alphanumeric': 0.1260229132569558, 'fraction_numerical': 0.003740939911152677, 'mean_word_length': 3.7586206896551726, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1670126', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1203, 'n_words': 390}