<commit_before>
///<reference path="lib/libmusicxml.ts"/>
///<reference path="download.ts"/>

const kGuidoMode 	= "1";
const kLilyMode 	= "2";
const kBrailleMode 	= "3";

//----------------------------------------------------------------------------
// this is the editor part, currently using CodeMirror
//----------------------------------------------------------------------------
class XMLConverter {

	private fFileName = "";
	private fMode: string;
	private fXmlContent = "";
	private fCode: HTMLElement;
	private fLogs: HTMLElement;
	private fXmlEngine: libmusicxml;

	constructor () {
		this.fCode = document.getElementById ("code");
		this.fLogs = document.getElementById ("logs");
		$(document).on({		// prevents document to capture dropped files
			dragover: function() 	{ return false;},
			drop: function() 		{ return false;}
		});
	}

	capture(event: DragEvent) {
		event.stopImmediatePropagation();
		event.preventDefault();
	}

	dragEnter (event : DragEvent) : void { 
		this.capture (event);
		this.fCode.style.opacity = "0.3";
	}

	dragLeave (event : DragEvent) : void {
		this.capture (event);
		this.fCode.style.opacity = "1";
	}

	drop (event : DragEvent) : void {
		this.dragLeave (event);
		var data = event.dataTransfer.getData("text");
		if (data) this.convert (data, "noname");
		else {
			let filelist = event.dataTransfer.files;
			if (!filelist) return;
		
			let filecount = filelist.length;
			for (let i = 0; i < filecount; i++ )
				this.droppedFile (filelist[i]);
		}
	}

	droppedFile (file: File) {
		let reader = new FileReader();	
		reader.onload = (event) => { this.convert (reader.result.toString(), file.name); };
		reader.readAsText(file, file.name);
	}
	
	initialize (xmlengine: libmusicxml) {
		this.fXmlEngine = xmlengine;
		let div = document.getElementById ("codepane");
		div.addEventListener ("dragenter",	(e: DragEvent) => { this.dragEnter(e); }, true);
		div.addEventListener ("dragleave",	(e: DragEvent) => { this.dragLeave(e); }, true);
		div.addEventListener ("drop",		(e: DragEvent) => { this.drop(e); }, true);

		$("input[name='output'").change ( (event) => { this.changeMode(<string>$("input[name='output']:checked").val()); } );
		$("#gmnbars").change 			( (event) => { this.convert(this.fXmlContent, this.fFileName+".xml"); } );
		$("#transpose").change 			( (event) => { this.convert(this.fXmlContent, this.fFileName+".xml"); } );
		$("#guidotry").click			( (event) => { this.tryGuido(); } );
		$("#clearlog").click			( (event) => { $("#logs").html(""); } );

		this.changeMode(<string>$("input[name='output']:checked").val());
		let logs = document.getElementById ("logs");
		// $("#log-font").click		( () => { logs.style.fontFamily = <string>$("#log-font").val(); });
		// $("#log-size").click		( () => { logs.style.fontSize = $("#log-size").val() + "px"; });
		// logs.style.fontFamily = <string>$("#log-font").val();
		// logs.style.fontSize = $("#log-size").val() + "px";
	}

	tryGuido () {
		let gmn = $("#code").text();
		if (gmn.length && (gmn.length < 2000))
			window.open("https://guidoeditor.grame.fr/?code=" + btoa(gmn), '_blank');
		else {
console.log ("post to guidoeditor due to url size limit");
			// const xhr = new XMLHttpRequest();
			// xhr.open('POST', 'http://localhost:8000/');
			// xhr.setRequestHeader('Access-Control-Allow-Origin', 'true');
			// xhr.setRequestHeader('Content-Type', 'text/plain');
			// // xhr.onreadystatechange = handler;
			// xhr.send (gmn); 

			$.post("http://localhost:8000", gmn, function(result: string){
								console.log("post result: " + result );
						}, "text");
 		}
	}

	// tryGuido () {
	// 	let gmn = $("#code").text();
	// 	if (gmn.length)
	// 		window.open("https://guidoeditor.grame.fr/?code=" + btoa(gmn), '_blank');
	// }

	save () : void {
		if (this.fXmlContent.length) {
			let content = this.fCode.innerText;
			if (content.length)
				download (this.fFileName + this.outSuffix(),  this.fCode.innerText); 
		}
	}

	outSuffix () : string		{ 
		switch (this.fMode) {
			case kGuidoMode: return ".gmn";
			case kLilyMode : return ".ly";
			case kBrailleMode: return ".brl";<commit_msg>fix post url<commit_after>
///<reference path="lib/libmusicxml.ts"/>
///<reference path="download.ts"/>

const kGuidoMode 	= "1";
const kLilyMode 	= "2";
const kBrailleMode 	= "3";

//----------------------------------------------------------------------------
// this is the editor part, currently using CodeMirror
//----------------------------------------------------------------------------
class XMLConverter {

	private fFileName = "";
	private fMode: string;
	private fXmlContent = "";
	private fCode: HTMLElement;
	private fLogs: HTMLElement;
	private fXmlEngine: libmusicxml;

	constructor () {
		this.fCode = document.getElementById ("code");
		this.fLogs = document.getElementById ("logs");
		$(document).on({		// prevents document to capture dropped files
			dragover: function() 	{ return false;},
			drop: function() 		{ return false;}
		});
	}

	capture(event: DragEvent) {
		event.stopImmediatePropagation();
		event.preventDefault();
	}

	dragEnter (event : DragEvent) : void { 
		this.capture (event);
		this.fCode.style.opacity = "0.3";
	}

	dragLeave (event : DragEvent) : void {
		this.capture (event);
		this.fCode.style.opacity = "1";
	}

	drop (event : DragEvent) : void {
		this.dragLeave (event);
		var data = event.dataTransfer.getData("text");
		if (data) this.convert (data, "noname");
		else {
			let filelist = event.dataTransfer.files;
			if (!filelist) return;
		
			let filecount = filelist.length;
			for (let i = 0; i < filecount; i++ )
				this.droppedFile (filelist[i]);
		}
	}

	droppedFile (file: File) {
		let reader = new FileReader();	
		reader.onload = (event) => { this.convert (reader.result.toString(), file.name); };
		reader.readAsText(file, file.name);
	}
	
	initialize (xmlengine: libmusicxml) {
		this.fXmlEngine = xmlengine;
		let div = document.getElementById ("codepane");
		div.addEventListener ("dragenter",	(e: DragEvent) => { this.dragEnter(e); }, true);
		div.addEventListener ("dragleave",	(e: DragEvent) => { this.dragLeave(e); }, true);
		div.addEventListener ("drop",		(e: DragEvent) => { this.drop(e); }, true);

		$("input[name='output'").change ( (event) => { this.changeMode(<string>$("input[name='output']:checked").val()); } );
		$("#gmnbars").change 			( (event) => { this.convert(this.fXmlContent, this.fFileName+".xml"); } );
		$("#transpose").change 			( (event) => { this.convert(this.fXmlContent, this.fFileName+".xml"); } );
		$("#guidotry").click			( (event) => { this.tryGuido(); } );
		$("#clearlog").click			( (event) => { $("#logs").html(""); } );

		this.changeMode(<string>$("input[name='output']:checked").val());
		let logs = document.getElementById ("logs");
		// $("#log-font").click		( () => { logs.style.fontFamily = <string>$("#log-font").val(); });
		// $("#log-size").click		( () => { logs.style.fontSize = $("#log-size").val() + "px"; });
		// logs.style.fontFamily = <string>$("#log-font").val();
		// logs.style.fontSize = $("#log-size").val() + "px";
	}

	tryGuido () {
		let gmn = $("#code").text();
		if (gmn.length && (gmn.length < 2000))
			window.open("https://guidoeditor.grame.fr/?code=" + btoa(gmn), '_blank');
		else {
console.log ("post to guidoeditor due to url size limit");
			// const xhr = new XMLHttpRequest();
			// xhr.open('POST', 'http://localhost:8000/');
			// xhr.setRequestHeader('Access-Control-Allow-Origin', 'true');
			// xhr.setRequestHeader('Content-Type', 'text/plain');
			// // xhr.onreadystatechange = handler;
			// xhr.send (gmn); 

			$.post("https://guidoeditor.grame.fr", gmn, function(result: string){
								console.log("post result: " + result );
						}, "text");
 		}
	}

	// tryGuido () {
	// 	let gmn = $("#code").text();
	// 	if (gmn.length)
	// 		window.open("https://guidoeditor.grame.fr/?code=" + btoa(gmn), '_blank');
	// }

	save () : void {
		if (this.fXmlContent.length) {
			let content = this.fCode.innerText;
			if (content.length)
				download (this.fFileName + this.outSuffix(),  this.fCode.innerText); 
		}
	}

	outSuffix () : string		{ 
		switch (this.fMode) {
			case kGuidoMode: return ".gmn";
			case kLilyMode : return ".ly";
			case kBrailleMode: return ".brl";
{'fraction_non_alphanumeric': 0.2385977680737506, 'fraction_numerical': 0.004124211547792334, 'mean_word_length': 3.1163255117324016, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 37, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2841889', 'n_tokens_mistral': 3051, 'n_tokens_neox': 2773, 'n_words': 543}