<commit_before>const MAX_PLUCK_FREQ = 4220; // straight from SoX source code (src/syncth.c)

module.exports = {
	default_octave: 4, // exported so that help can reference it

	// returns a link to an ultrachord
	ultrachord: function(words) {
		const execSync = require('child_process').execSync;

		var errors = [];

		function makeid() {
			var text = "";
			var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
			for (var i = 0; i < 16; i++) {
				text += possible.charAt(Math.floor(Math.random() * possible.length));
			}

			return text;
		}

		function getFrequency(octave, note) {
			// 1.059463094359 == 2^12, used for note frequency calculation!
			var base_note = 10; // A
			var base_octave = module.exports.default_octave;
			var note_distance = ((octave * 12) + note) - ((base_octave * 12) + base_note);
			// 440hz == A4
			var frequency = 440 * Math.pow(1.059463094359, note_distance);
			return frequency.toFixed(4);
		}

		function noteToNumber(letter) {
			switch (letter) {
				case 'a':
					return 9;
				case 'b':
					return 11;
				case 'c':
					return 0;
				case 'd':
					return 2;
				case 'e':
					return 4;
				case 'f':
					return 5;
				case 'g':
					return 7;
				default:
					return -1;
			}
		}

		var id = makeid();
		var filename = '';

		var timbres = ['pluck', 'square', 'triangle', 'sawtooth', 'sine', 'sin', 'saw', 'tri'];
		var timbre = timbres[2]; // square wave because chiptune dumbo
		var notes = [];

		words.slice(1).forEach(function(word) {
			// toLowerCase to make life easier!
			var param = word.toLowerCase();

			// check if it's a timbre
			if (timbres.indexOf(param) !== -1) {
				filename += timbre = param;
				filename += '_';
				return;
			}

			// abort if a note parameter is not well-formed
			if (!param.match(/^[a-gA-G](-|[#b♯♭]{0,2})[0-9]?$/)) {
				errors.push(param + ' unrecognized');
				return;
			}

			// note to number function call happens
			var note_val = noteToNumber(param.charAt(0));
			filename += param.charAt(0);

			// sharps and flats handling
			for (var i = 1; i < param.length; i++) {
				switch (param.charAt(i)) {
					case '#':
					case '♯':
						note_val++;
						filename += 'S';
						break;
					case 'b':
					case '♭':
						note_val--;
						filename += 'b';
						break;
				}
			}

			// octave handling
			var octave_val = parseInt(param.charAt(param.length - 1), 10);
			if (!Number.isInteger(octave_val)) {
				octave_val = 4;
			}
			filename += octave_val;
			filename += '_';

			// push the final note via a get frequency function
			var freq = getFrequency(octave_val, note_val)
			if (timbre == 'pluck' && freq > MAX_PLUCK_FREQ) {
				errors.push(param + ' out of pluck range');
				return;
			}
			notes.push({ timbre: timbre, freq: freq });
		});

		var error_text = errors.length ? ' (' + errors.join(', ') + ')' : '';

		if (notes.length == 0) return 'no valid notes' + error_text;
		console.log(notes);
		console.log(filename);

		// create the synth, convert to mp3, upload to uguu.se<commit_msg>I forgot a semicolon like a dumnus<commit_after>const MAX_PLUCK_FREQ = 4220; // straight from SoX source code (src/syncth.c)

module.exports = {
	default_octave: 4, // exported so that help can reference it

	// returns a link to an ultrachord
	ultrachord: function(words) {
		const execSync = require('child_process').execSync;

		var errors = [];

		function makeid() {
			var text = "";
			var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
			for (var i = 0; i < 16; i++) {
				text += possible.charAt(Math.floor(Math.random() * possible.length));
			}

			return text;
		}

		function getFrequency(octave, note) {
			// 1.059463094359 == 2^12, used for note frequency calculation!
			var base_note = 10; // A
			var base_octave = module.exports.default_octave;
			var note_distance = ((octave * 12) + note) - ((base_octave * 12) + base_note);
			// 440hz == A4
			var frequency = 440 * Math.pow(1.059463094359, note_distance);
			return frequency.toFixed(4);
		}

		function noteToNumber(letter) {
			switch (letter) {
				case 'a':
					return 9;
				case 'b':
					return 11;
				case 'c':
					return 0;
				case 'd':
					return 2;
				case 'e':
					return 4;
				case 'f':
					return 5;
				case 'g':
					return 7;
				default:
					return -1;
			}
		}

		var id = makeid();
		var filename = '';

		var timbres = ['pluck', 'square', 'triangle', 'sawtooth', 'sine', 'sin', 'saw', 'tri'];
		var timbre = timbres[2]; // square wave because chiptune dumbo
		var notes = [];

		words.slice(1).forEach(function(word) {
			// toLowerCase to make life easier!
			var param = word.toLowerCase();

			// check if it's a timbre
			if (timbres.indexOf(param) !== -1) {
				filename += timbre = param;
				filename += '_';
				return;
			}

			// abort if a note parameter is not well-formed
			if (!param.match(/^[a-gA-G](-|[#b♯♭]{0,2})[0-9]?$/)) {
				errors.push(param + ' unrecognized');
				return;
			}

			// note to number function call happens
			var note_val = noteToNumber(param.charAt(0));
			filename += param.charAt(0);

			// sharps and flats handling
			for (var i = 1; i < param.length; i++) {
				switch (param.charAt(i)) {
					case '#':
					case '♯':
						note_val++;
						filename += 'S';
						break;
					case 'b':
					case '♭':
						note_val--;
						filename += 'b';
						break;
				}
			}

			// octave handling
			var octave_val = parseInt(param.charAt(param.length - 1), 10);
			if (!Number.isInteger(octave_val)) {
				octave_val = 4;
			}
			filename += octave_val;
			filename += '_';

			// push the final note via a get frequency function
			var freq = getFrequency(octave_val, note_val);
			if (timbre == 'pluck' && freq > MAX_PLUCK_FREQ) {
				errors.push(param + ' out of pluck range');
				return;
			}
			notes.push({ timbre: timbre, freq: freq });
		});

		var error_text = errors.length ? ' (' + errors.join(', ') + ')' : '';

		if (notes.length == 0) return 'no valid notes' + error_text;
		console.log(notes);
		console.log(filename);

		// create the synth, convert to mp3, upload to uguu.se
{'fraction_non_alphanumeric': 0.15348152991173586, 'fraction_numerical': 0.02811376266753841, 'mean_word_length': 2.6928183464091733, 'pattern_counts': {'":': 0, '<': 7, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2858989', 'n_tokens_mistral': 2787, 'n_tokens_neox': 2152, 'n_words': 575}