Merge pull request #1024 from tidalcycles/fix-draw-bugs

better theme integration for visuals + various fixes
This commit is contained in:
Felix Roos 2024-03-28 11:37:56 +01:00 committed by GitHub
commit aa25265cc2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 119 additions and 107 deletions

View file

@ -67,6 +67,9 @@ export class Cyclist {
);
}
now() {
if (!this.started) {
return 0;
}
const secondsSinceLastTick = this.getTime() - this.lastTick - this.clock.duration;
return this.lastBegin + secondsSinceLastTick * this.cps; // + this.clock.minLatency;
}

View file

@ -49,6 +49,27 @@ export class Hap {
return this.whole.begin.add(this.duration);
}
isActive(currentTime) {
return this.whole.begin <= currentTime && this.endClipped >= currentTime;
}
isInPast(currentTime) {
return currentTime > this.endClipped;
}
isInNearPast(margin, currentTime) {
return currentTime - margin <= this.endClipped;
}
isInFuture(currentTime) {
return currentTime < this.whole.begin;
}
isInNearFuture(margin, currentTime) {
return currentTime < this.whole.begin && currentTime > this.whole.begin - margin;
}
isWithinTime(min, max) {
return this.whole.begin <= max && this.endClipped >= min;
}
wholeOrPart() {
return this.whole ? this.whole : this.part;
}
@ -70,6 +91,10 @@ export class Hap {
return this.whole != undefined && this.whole.begin.equals(this.part.begin);
}
hasTag(tag) {
return this.context.tags?.includes(tag);
}
resolveState(state) {
if (this.stateful && this.hasOnset()) {
console.log('stateful');

View file

@ -2474,13 +2474,13 @@ export const hsl = register('hsl', (h, s, l, pat) => {
});
/**
* Sets the id of the hap in, for filtering in the future.
* @name id
* Tags each Hap with an identifier. Good for filtering. The function populates Hap.context.tags (Array).
* @name tag
* @noAutocomplete
* @param {string} id anything unique
* @param {string} tag anything unique
*/
Pattern.prototype.id = function (id) {
return this.withContext((ctx) => ({ ...ctx, id }));
Pattern.prototype.tag = function (tag) {
return this.withContext((ctx) => ({ ...ctx, tags: (ctx.tags || []).concat([tag]) }));
};
//////////////////////////////////////////////////////////////////////