<commit_before>'use strict';

angular.module('emuwebApp')
	.directive('mouseTrackAndCorrectionTool', function (viewState, ConfigProviderService, Ssffdataservice, Drawhelperservice, HistoryService, Soundhandlerservice) {
		return {
			restrict: 'A',
			scope: {},
			link: function (scope, element, atts) {

				var curMouseSample;
				var dragStartSample;
				var dragEndSample;

				var canvas = element[0];

				var ctx = canvas.getContext('2d');
				// var elem = element[0];
				var tr, col, sRaSt;
				var trackName;
				var bundleName;

				/////////////////////////////
				// observe attribute
				atts.$observe('ssffTrackname', function (val) {
					if (val) {
						trackName = val;
					}
				});

				// bundleName needed to reset tr, col, sRaSt on bundle change
				atts.$observe('bundleName', function (val) {
					if (val) {
						bundleName = val;
						if (!$.isEmptyObject(Ssffdataservice.data)) {
							if (Ssffdataservice.data.length !== 0) {
								tr = ConfigProviderService.getSsffTrackConfig('FORMANTS');
								if (tr !== undefined) {
									col = Ssffdataservice.getColumnOfTrack(tr.name, tr.columnName);
									sRaSt = Ssffdataservice.getSampleRateAndStartTimeOfTrack(tr.name);
								}
							}
						}
					}
				});


				/////////////////////////////
				// Bindings
				element.bind('mousedown', function (event) {
					dragStartSample = Math.round(Drawhelperservice.getX(event) * viewState.getPCMpp(event) + viewState.curViewPort.sS);
					dragEndSample = dragStartSample;
					viewState.select(dragStartSample, dragStartSample);
					//Drawhelperservice.drawViewPortTimes(ctx, true);
					switchMarkupContext(event);
					scope.$apply();
				});

				element.bind('mousemove', function (event) {
					var mbutton = 0;
					if (event.buttons === undefined) {
						mbutton = event.which;
					} else {
						mbutton = event.buttons;
					}
					// perform mouse tracking
					var mouseX = Drawhelperservice.getX(event);
					viewState.curMousePosSample = Math.round(viewState.curViewPort.sS + mouseX / element[0].width * (viewState.curViewPort.eS - viewState.curViewPort.sS));

					switch (mbutton) {
					case 0:
						if (viewState.getPermission('labelAction')) {
							switchMarkupContext(event);
							if (!$.isEmptyObject(Ssffdataservice.data)) {
								if (Ssffdataservice.data.length !== 0) {
									if (!viewState.getdragBarActive()) {
										if (viewState.curCorrectionToolNr !== undefined && !viewState.getdragBarActive() && !$.isEmptyObject(ConfigProviderService.getAssignment(trackName))) {
											// var col = Ssffdataservice.data[0].Columns[0];
											if (tr === undefined) {
												tr = ConfigProviderService.getSsffTrackConfig('FORMANTS');
												col = Ssffdataservice.getColumnOfTrack(tr.name, tr.columnName);
												sRaSt = Ssffdataservice.getSampleRateAndStartTimeOfTrack(tr.name);
											}

											var startTimeVP = viewState.getViewPortStartTime();
											var endTimeVP = viewState.getViewPortEndTime();

											var colStartSampleNr = Math.round(startTimeVP * sRaSt.sampleRate + sRaSt.startTime);
											var colEndSampleNr = Math.round(endTimeVP * sRaSt.sampleRate + sRaSt.startTime);
											var nrOfSamples = colEndSampleNr - colStartSampleNr;
											var curSampleArrs = col.values.slice(colStartSampleNr, colStartSampleNr + nrOfSamples);

											// console.log(colStartSampleNr)


											var curMouseTime = startTimeVP + (Drawhelperservice.getX(event) / event.originalEvent.srcElement.width) * (endTimeVP - startTimeVP);
											var curMouseSample = Math.round((curMouseTime + sRaSt.startTime) * sRaSt.sampleRate) - 1; //-1 for in view correction

											var curMouseSampleTime = (1 / sRaSt.sampleRate * curMouseSample) + sRaSt.startTime;


											if (curMouseSample - colStartSampleNr < 0 || curMouseSample - colStartSampleNr >= curSampleArrs.length) {
												console.log('early return');
												return;
											}

											viewState.curPreselColumnSample = curMouseSample - colStartSampleNr;

											var x = (curMouseSampleTime - startTimeVP) / (endTimeVP - startTimeVP) * canvas.width;
											var y = canvas.height - curSampleArrs[viewState.curPreselColumnSample][viewState.curCorrectionToolNr - 1] / (viewState.spectroSettings.rangeTo - viewState.spectroSettings.rangeFrom) * canvas.height;

											// draw sample
											ctx.strokeStyle = 'black';
											ctx.fillStyle = 'black';
											ctx.beginPath();
											ctx.arc(x, y - 1, 2, 0, 2 * Math.PI, false);
											ctx.closePath();
											ctx.stroke();
											ctx.fill();


											if (event.shiftKey) {
												var oldValue = angular.copy(curSampleArrs[viewState.curPreselColumnSample][viewState.curCorrectionToolNr - 1]);
												console.log(e.originalEvent.target);
												var newValue = viewState.spectroSettings.rangeTo - Drawhelperservice.getY(event) / 128 * viewState.spectroSettings.rangeTo; // SIC only using rangeTo

												curSampleArrs[viewState.curPreselColumnSample][viewState.curCorrectionToolNr - 1] = viewState.spectroSettings.rangeTo - Drawhelperservice.getY(event) / event.originalEvent.srcElement.height * viewState.spectroSettings.rangeTo;<commit_msg>replaced srcEl with target<commit_after>'use strict';

angular.module('emuwebApp')
	.directive('mouseTrackAndCorrectionTool', function (viewState, ConfigProviderService, Ssffdataservice, Drawhelperservice, HistoryService, Soundhandlerservice) {
		return {
			restrict: 'A',
			scope: {},
			link: function (scope, element, atts) {

				var curMouseSample;
				var dragStartSample;
				var dragEndSample;

				var canvas = element[0];

				var ctx = canvas.getContext('2d');
				// var elem = element[0];
				var tr, col, sRaSt;
				var trackName;
				var bundleName;

				/////////////////////////////
				// observe attribute
				atts.$observe('ssffTrackname', function (val) {
					if (val) {
						trackName = val;
					}
				});

				// bundleName needed to reset tr, col, sRaSt on bundle change
				atts.$observe('bundleName', function (val) {
					if (val) {
						bundleName = val;
						if (!$.isEmptyObject(Ssffdataservice.data)) {
							if (Ssffdataservice.data.length !== 0) {
								tr = ConfigProviderService.getSsffTrackConfig('FORMANTS');
								if (tr !== undefined) {
									col = Ssffdataservice.getColumnOfTrack(tr.name, tr.columnName);
									sRaSt = Ssffdataservice.getSampleRateAndStartTimeOfTrack(tr.name);
								}
							}
						}
					}
				});


				/////////////////////////////
				// Bindings
				element.bind('mousedown', function (event) {
					dragStartSample = Math.round(Drawhelperservice.getX(event) * viewState.getPCMpp(event) + viewState.curViewPort.sS);
					dragEndSample = dragStartSample;
					viewState.select(dragStartSample, dragStartSample);
					//Drawhelperservice.drawViewPortTimes(ctx, true);
					switchMarkupContext(event);
					scope.$apply();
				});

				element.bind('mousemove', function (event) {
					var mbutton = 0;
					if (event.buttons === undefined) {
						mbutton = event.which;
					} else {
						mbutton = event.buttons;
					}
					// perform mouse tracking
					var mouseX = Drawhelperservice.getX(event);
					viewState.curMousePosSample = Math.round(viewState.curViewPort.sS + mouseX / element[0].width * (viewState.curViewPort.eS - viewState.curViewPort.sS));

					switch (mbutton) {
					case 0:
						if (viewState.getPermission('labelAction')) {
							switchMarkupContext(event);
							if (!$.isEmptyObject(Ssffdataservice.data)) {
								if (Ssffdataservice.data.length !== 0) {
									if (!viewState.getdragBarActive()) {
										if (viewState.curCorrectionToolNr !== undefined && !viewState.getdragBarActive() && !$.isEmptyObject(ConfigProviderService.getAssignment(trackName))) {
											// var col = Ssffdataservice.data[0].Columns[0];
											if (tr === undefined) {
												tr = ConfigProviderService.getSsffTrackConfig('FORMANTS');
												col = Ssffdataservice.getColumnOfTrack(tr.name, tr.columnName);
												sRaSt = Ssffdataservice.getSampleRateAndStartTimeOfTrack(tr.name);
											}

											var startTimeVP = viewState.getViewPortStartTime();
											var endTimeVP = viewState.getViewPortEndTime();

											var colStartSampleNr = Math.round(startTimeVP * sRaSt.sampleRate + sRaSt.startTime);
											var colEndSampleNr = Math.round(endTimeVP * sRaSt.sampleRate + sRaSt.startTime);
											var nrOfSamples = colEndSampleNr - colStartSampleNr;
											var curSampleArrs = col.values.slice(colStartSampleNr, colStartSampleNr + nrOfSamples);

											// console.log(colStartSampleNr)


											var curMouseTime = startTimeVP + (Drawhelperservice.getX(event) / event.originalEvent.target.width) * (endTimeVP - startTimeVP);
											var curMouseSample = Math.round((curMouseTime + sRaSt.startTime) * sRaSt.sampleRate) - 1; //-1 for in view correction

											var curMouseSampleTime = (1 / sRaSt.sampleRate * curMouseSample) + sRaSt.startTime;


											if (curMouseSample - colStartSampleNr < 0 || curMouseSample - colStartSampleNr >= curSampleArrs.length) {
												console.log('early return');
												return;
											}

											viewState.curPreselColumnSample = curMouseSample - colStartSampleNr;

											var x = (curMouseSampleTime - startTimeVP) / (endTimeVP - startTimeVP) * canvas.width;
											var y = canvas.height - curSampleArrs[viewState.curPreselColumnSample][viewState.curCorrectionToolNr - 1] / (viewState.spectroSettings.rangeTo - viewState.spectroSettings.rangeFrom) * canvas.height;

											// draw sample
											ctx.strokeStyle = 'black';
											ctx.fillStyle = 'black';
											ctx.beginPath();
											ctx.arc(x, y - 1, 2, 0, 2 * Math.PI, false);
											ctx.closePath();
											ctx.stroke();
											ctx.fill();


											if (event.shiftKey) {
												var oldValue = angular.copy(curSampleArrs[viewState.curPreselColumnSample][viewState.curCorrectionToolNr - 1]);
												var newValue = viewState.spectroSettings.rangeTo - Drawhelperservice.getY(event) / event.originalEvent.target.height * viewState.spectroSettings.rangeTo; // SIC only using rangeTo

												curSampleArrs[viewState.curPreselColumnSample][viewState.curCorrectionToolNr - 1] = viewState.spectroSettings.rangeTo - Drawhelperservice.getY(event) / event.originalEvent.target.height * viewState.spectroSettings.rangeTo;
{'fraction_non_alphanumeric': 0.12423605805958747, 'fraction_numerical': 0.004297173414820474, 'mean_word_length': 2.763205174272368, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5446472', 'n_tokens_mistral': 4479, 'n_tokens_neox': 3203, 'n_words': 555}