Skip to content

Commit

Permalink
Added a GC in Cambiare preventing meta overflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
PoneyClairDeLune committed Jul 20, 2024
1 parent b0af206 commit 9411f55
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/cambiare/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ HTMLElement.prototype.setTextRaw = function (text) {
};

let Cambiare = class extends RootDisplay {
#metaGcLine = 16;
#metaMaxLine = 128;
#metaAmend = false;
#metaType = "";
Expand All @@ -208,6 +209,9 @@ let Cambiare = class extends RootDisplay {
#metaMoveX = 0;
#metaMoveY = 0;
#maxPoly = 0;
#metaGcThread;
#metaGcAt = 0;
#metaGcScheduled = false;
#underlinedCh = allocated.invalidCh;
#renderRange = 1;
#renderPort = 0;
Expand Down Expand Up @@ -1132,6 +1136,10 @@ let Cambiare = class extends RootDisplay {
metaLineType,
upThis.#metaLastLine
]);
if (upThis.#sectMeta.view.children.length > upThis.#metaGcLine) {
upThis.#metaGcAt = Date.now() + 1000;
upThis.#metaGcScheduled = 1;
};
while (upThis.#sectMeta.view.children.length > upThis.#metaMaxLine) {
upThis.#sectMeta.view.children[0].remove();
};
Expand All @@ -1141,6 +1149,38 @@ let Cambiare = class extends RootDisplay {
upThis.#scrollMeta();
});
upThis.#sectMeta.view.style.transform = `translateX(0px) translateY(140px)`;
upThis.#metaGcThread = setInterval(async () => {
let timeNow = Date.now();
if (upThis.#metaGcScheduled == 0) {
return;
};
switch (upThis.#metaGcScheduled) {
case 1: {
if (timeNow < upThis.#metaGcAt) {
break;
};
upThis.#sectMeta.view.style.transition = "none";
let gcCount = 0;
while (upThis.#sectMeta.view.children.length > upThis.#metaGcLine) {
upThis.#sectMeta.view.children[0].remove();
gcCount ++;
};
upThis.#scrollMeta();
console.debug(`Meta garbage collector removed ${gcCount} events.`);
upThis.#metaGcScheduled = 2;
break;
};
case 2: {
if (timeNow < upThis.#metaGcAt + 100) {
break;
};
upThis.#sectMeta.view.style.transition = "";
console.debug(`Meta garbage collector restored meta animation.`);
upThis.#metaGcScheduled = 0;
break;
};
};
}, 100);
upThis.dispatchEvent("mode", "?");
upThis.dispatchEvent("mastervolume", 100);
upThis.dispatchEvent("tempo", 120);
Expand All @@ -1161,6 +1201,7 @@ let Cambiare = class extends RootDisplay {
upThis.#container = undefined;
upThis.#visualizer = undefined;
clearInterval(upThis.#renderThread);
clearInterval(upThis.#metaGcThread);
};
constructor(attachElement, clockSource) {
super(new OctaviaDevice, 0.1, 0.75);
Expand Down
2 changes: 1 addition & 1 deletion test/cambiare.htm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</template>
<div class="column"></div>
</div>
<div class="columns is-multiline is-mobile is-vcentered" x-data="{styles:[['block','Block'],['comb','Comb'],['piano','Piano'],['line','Line']],pans:[[0,'Block'],[1,'Pin'],[2,'Arc'],[3,'Dash'],[5,'Needle'],[6,'Sector'],[7,'Knob']]}">
<div class="columns is-multiline is-mobile is-vcentered" x-data="{styles:[['block','Block'],['comb','Comb'],['piano','Piano'],['line','Line']],pans:[[0,'Block'],[1,'Pin'],[2,'Arc'],[3,'Dash'],[5,'Needle'],[6,'Sector'],[7,'Hand']]}">
<div class="column column-option"><b>Note style</b></div>
<template x-for="style in styles">
<div class="column column-option column-button" @click="gStyle(style[0])" x-text="style[1]" :active="($store.noteStyle||'comb')==style[0]?'true':'false'"></div>
Expand Down

0 comments on commit 9411f55

Please sign in to comment.