<commit_before>/* global it, describe, recorderDelay, recorderDuration, maxTimeout */

define(["tests/Core", "chai", "Tone/component/Recorder", "Tone/signal/Signal", "Tone/source/Oscillator", 
	"Tone/core/Master", "Tone/signal/Threshold", "Tone/signal/Switch", "Tone/signal/Route", "Tone/signal/Select"], 
function(core, chai, Recorder, Signal, Oscillator, Master, Threshold, Switch, Route, Select){

	var expect = chai.expect;

	Master.mute();

	//SIGNAL
	describe("Tone.Signal", function(){
		this.timeout(maxTimeout);


		it("can be created and disposed", function(){
			var s = new Signal();
			s.dispose();
			wasDisposed(s, expect);
		});

		it("can start with a value initially", function(){
			var signal = new Signal(0);
			expect(signal.getValue()).to.equal(0);
			signal.dispose();
		});

		it("can set a value", function(){
			var signal = new Signal(0);
			signal.setValue(10);
			expect(signal.getValue()).to.equal(10);
			signal.dispose();
		});

		it("can set a value in the future", function(done){
			var sig = new Signal(10);
			sig.setValueAtTime(100, "+0.1");
			expect(sig.getValue()).to.equal(10);
			var recorder = new Recorder();
			sig.connect(recorder);
			recorder.record(recorderDuration, recorderDelay, function(buffers){
				var buffer = buffers[0];
				var reached100 = false;
				for (var i = 0; i < buffer.length; i++){
					if (buffer[i] === 100){
						reached100 = true;
						break;
					} 
				}
				expect(reached100).to.be.true;
				sig.dispose();
				done();
			});
		});

		it("can change value with sample accurate timing", function(done){			
			var changeSignal = new Signal(0);
			changeSignal.setValueAtTime(1, "+"+(recorderDelay));
			var recorder = new Recorder();
			changeSignal.connect(recorder);
			recorder.record(recorderDuration, recorderDelay, function(buffers){
				var buffer = buffers[0];
				for (var i = 0; i < buffer.length; i++){
					if (buffer[i] === 1){
						expect(changeSignal.samplesToSeconds(i)).is.closeTo(0.0, 0.1);
						changeSignal.dispose();
						recorder.dispose();
						done();
						break;
					}
				}
			});
		});
		
		it("can sync to another signal", function(done){
			var syncTo = new Signal(1);
			var signalSync = new Signal(2);
			signalSync.sync(syncTo);
			syncTo.setValue(2);
			var recorder = new Recorder();
			signalSync.connect(recorder);
			recorder.record(recorderDuration, recorderDelay, function(buffers){
				var buffer = buffers[0];
				for (var i = 0; i < buffer.length; i++){
					expect(buffer[i]).to.equal(4);
				}
				signalSync.dispose();
				recorder.dispose();
				done();
			});
		});	

		it("can ramp from the current value", function(done){
			var sig1 = new Signal(0);
			sig1.setValue(-10);
			var recorder = new Recorder(1);
			sig1.connect(recorder);
			var waitTime = recorderDelay;
			expect(sig1.getValue()).to.equal(-10);
			sig1.linearRampToValueNow(1, waitTime);
			recorder.record(recorderDuration, recorderDelay, function(buffers){
				var buffer = buffers[0];
				for (var i = 0; i < buffer.length; i++){
					if (buffer[i] === 1){
						expect(sig1.samplesToSeconds(i)).is.closeTo(0, 0.1);
						done();
						sig1.dispose();
						break;
					}
				}
			});
		});
	});


	//THRESHOLD
	describe("Tone.Threshold", function(){
		this.timeout(maxTimeout);

		it("can be created and disposed", function(){
			var thresh = new Threshold();
			thresh.dispose();
			wasDisposed(thresh, expect);
		});

		it("thresholds an incoming signal to 0 when it is below the thresh", function(done){
			var signal = new Signal(0.1);
			var thresh = new Threshold(0.5);
			signal.connect(thresh);<commit_msg>more signal API tests<commit_after>/* global it, describe, recorderDelay, recorderDuration, maxTimeout */

define(["tests/Core", "chai", "Tone/component/Recorder", "Tone/signal/Signal", "Tone/source/Oscillator", 
	"Tone/core/Master", "Tone/signal/Threshold", "Tone/signal/Switch", "Tone/signal/Route", "Tone/signal/Select"], 
function(core, chai, Recorder, Signal, Oscillator, Master, Threshold, Switch, Route, Select){

	var expect = chai.expect;

	Master.mute();

	//SIGNAL
	describe("Tone.Signal", function(){
		this.timeout(maxTimeout);


		it("can be created and disposed", function(){
			var s = new Signal();
			s.dispose();
			wasDisposed(s, expect);
		});

		it("can start with a value initially", function(){
			var signal = new Signal(0);
			expect(signal.getValue()).to.equal(0);
			signal.dispose();
		});

		it("can set a value", function(){
			var signal = new Signal(0);
			signal.setValue(10);
			expect(signal.getValue()).to.equal(10);
			signal.dispose();
		});

		it("can set a value in the future", function(done){
			var sig = new Signal(10);
			sig.setValueAtTime(100, "+0.1");
			expect(sig.getValue()).to.equal(10);
			var recorder = new Recorder();
			sig.connect(recorder);
			recorder.record(recorderDuration, recorderDelay, function(buffers){
				var buffer = buffers[0];
				var reached100 = false;
				for (var i = 0; i < buffer.length; i++){
					if (buffer[i] === 100){
						reached100 = true;
						break;
					} 
				}
				expect(reached100).to.be.true;
				sig.dispose();
				done();
			});
		});

		it("can change value with sample accurate timing", function(done){			
			var changeSignal = new Signal(0);
			changeSignal.setValueAtTime(1, "+"+(recorderDelay));
			var recorder = new Recorder();
			changeSignal.connect(recorder);
			recorder.record(recorderDuration, recorderDelay, function(buffers){
				var buffer = buffers[0];
				for (var i = 0; i < buffer.length; i++){
					if (buffer[i] === 1){
						expect(changeSignal.samplesToSeconds(i)).is.closeTo(0.0, 0.1);
						changeSignal.dispose();
						recorder.dispose();
						done();
						break;
					}
				}
			});
		});
		
		it("can sync to another signal", function(done){
			var syncTo = new Signal(1);
			var signalSync = new Signal(2);
			signalSync.sync(syncTo);
			syncTo.setValue(2);
			var recorder = new Recorder();
			signalSync.connect(recorder);
			recorder.record(recorderDuration, recorderDelay, function(buffers){
				var buffer = buffers[0];
				for (var i = 0; i < buffer.length; i++){
					expect(buffer[i]).to.equal(4);
				}
				signalSync.dispose();
				recorder.dispose();
				done();
			});
		});	

		it("can ramp from the current value", function(done){
			var sig1 = new Signal(0);
			sig1.setValue(-10);
			var recorder = new Recorder(1);
			sig1.connect(recorder);
			var waitTime = recorderDelay;
			expect(sig1.getValue()).to.equal(-10);
			sig1.linearRampToValueNow(1, waitTime);
			recorder.record(recorderDuration, recorderDelay, function(buffers){
				var buffer = buffers[0];
				for (var i = 0; i < buffer.length; i++){
					if (buffer[i] === 1){
						expect(sig1.samplesToSeconds(i)).is.closeTo(0, 0.1);
						done();
						sig1.dispose();
						break;
					}
				}
			});
		});

		it("can ramp exponentially from the current value now", function(){
			var sig = new Signal(1);
			sig.exponentialRampToValueNow(10);
			sig.dispose();
		});

		it("can ramp exponentially from the current value in the future", function(){
			var sig = new Signal(1);
			sig.exponentialRampToValueAtTime(10, 0.5);
			sig.dispose();
		});
	});


	//THRESHOLD
	describe("Tone.Threshold", function(){
		this.timeout(maxTimeout);

		it("can be created and disposed", function(){
			var thresh = new Threshold();
			thresh.dispose();
			wasDisposed(thresh, expect);
		});

		it("thresholds an incoming signal to 0 when it is below the thresh", function(done){
			var signal = new Signal(0.1);
			var thresh = new Threshold(0.5);
			signal.connect(thresh);
{'fraction_non_alphanumeric': 0.16398629053519642, 'fraction_numerical': 0.019509622989717902, 'mean_word_length': 3.47874852420307, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, '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': '4971066', 'n_tokens_mistral': 3156, 'n_tokens_neox': 2492, 'n_words': 595}