MzxBox

catalogTestPerformer.json

{
	"label": "Test Performer Plugin",
	"purpose": "Performer",
	"kind": "testPerformerPluginV1_0",
	"ui": "http://127.0.0.1:8080/performer/ui1.html",
	"evaluate": "createNewTestPerformerPlugin",
	"script": "http://127.0.0.1:8080/performer/plugin1.js"
}

plugin1.ts

function createNewTestPerformerPlugin() {
	let audioContext = null;
	let outputVolume = null;
	let properties = {
		volume: 0.7,
		kind: 'sine'
	};
	let nodes = [];
	return {
		launch: (context, parameters) => {
			if (!(outputVolume)) {
				audioContext = context;
				outputVolume = audioContext.createGain();
			}
			if (parameters) {
				properties = parameters;
			}
			outputVolume.gain.value = properties.volume;
		},
		busy: () => {
			return false;
		},
		strum: (when, pitches, tempo, slides) => {
			const wholeDUration = slides.reduce((sum, currentSlide) => sum + currentSlide.duration, 0);
			pitches.forEach((singlePitch) => {
				let beep = audioContext.createOscillator();
				beep.frequency.value = 440 * Math.pow(Math.pow(2, (1 / 12)), singlePitch - 69);
				beep.type = properties.kind;
				beep.connect(outputVolume);
				beep.start(when);
				beep.stop(when + wholeDUration);
				nodes.push(beep);
			});
		},
		cancel: () => {
			nodes.forEach((node) => {
				node.disconnect();
			});
			nodes = [];
		},
		output: () => {
			return outputVolume;
		}
	};
}

ui1.html

<html>

<head>
	<style>
		body {
			background: silver;
		}
	</style>
</head>

<body>
	<h1>Test Performer Plugin</h1>
	<p>Volume</p>
	<p><input type="range" id="volumeslider" min="0" max="1" step="0.1" onchange="setVolume(this.value);" /></p>
	<p>Wave type</p>
	<p>
		<input type="radio" id="wave1" name="beepkind" onclick="setKind('sine');" />Sine
		<br />
		<input type="radio" id="wave2" name="beepkind" onclick="setKind('square');" />Square
		<br />
		<input type="radio" id="wave3" name="beepkind" onclick="setKind('sawtooth');" />Sawtooth
		<br />
		<input type="radio" id="wave4" name="beepkind" onclick="setKind('triangle');" />Triangle
	</p>
</body>
<script>
	let dialigId = '';
	let properties = {
		volume: 0.7,
		kind: 'sine'
	};

	function setKind(kind) {
		properties.kind = kind;
		postMessageToHost();
	}

	function setVolume(nn) {
		properties.volume = nn;
		postMessageToHost();
	}

	function onHostMessage(messageEvent) {
		if (dialigId) {
			if (messageEvent.data.hostData) {
				properties = messageEvent.data.hostData;
			}
			document.getElementById('volumeslider').value = properties.volume;
			switch (properties.kind) {
				case 'sine':
					document.getElementById('wave1').checked = true;
					break;
				case 'square':
					document.getElementById('wave2').checked = true;
					break;
				case 'sawtooth':
					document.getElementById('wave3').checked = true;
					break;
				default:
					document.getElementById('wave4').checked = true;
			}
		} else {
			dialigId = messageEvent.data.hostData;
		}
	}

	function postMessageToHost() {
		window.parent.postMessage({
			dialogID: dialigId,
			pluginData: properties,
			done: false,
			screenWait: false
		}, '*');
	}
	window.addEventListener('message', onHostMessage, false);
	postMessageToHost();
</script>

</html>

Proudly powered by WordPress