standardise on hap rather than event, especially in function names

This commit is contained in:
alex 2022-05-05 17:20:36 +01:00
parent b0dfb44e96
commit f8f744dd87
13 changed files with 159 additions and 153 deletions

View file

@ -36,23 +36,23 @@ const latency = 0.1;
// Pattern.prototype.midi = function (output: string | number, channel = 1) {
Pattern.prototype.serial = async function (...args) {
return this._withEvent((event) => {
return this._withHap((hap) => {
if (!serialWriter) {
getWriter(...args);
}
const onTrigger = (time, event, currentTime) => {
const onTrigger = (time, hap, currentTime) => {
var message = "";
if (typeof event.value === 'object') {
for (const [key, val] of Object.entries(event.value).flat()) {
if (typeof hap.value === 'object') {
for (const [key, val] of Object.entries(hap.value).flat()) {
message += `${key}:${val};`
}
}
else {
message = event.value;
message = hap.value;
}
const offset = (time - currentTime + latency) * 1000;
window.setTimeout(serialWriter, offset, message);
};
return event.setContext({ ...event.context, onTrigger });
return hap.setContext({ ...hap.context, onTrigger });
});
};