Added new immediate mode for Ziffers evaluation using Ctrl+Shift+Enter.

This commit is contained in:
2023-12-25 18:06:32 +02:00
parent fea2a3eb21
commit 4913dde4a1
6 changed files with 45 additions and 16 deletions

View File

@ -7,6 +7,7 @@ import { MidiEvent, MidiParams } from "./MidiEvent";
import { RestEvent } from "./RestEvent";
import { arrayOfObjectsToObjectWithArrays, isGenerator } from "../Utils/Generic";
import { TonnetzSpaces } from "zifferjs/src/tonnetz";
import { safeMod } from "zifferjs/src/utils";
export type InputOptions = { [key: string]: string | number };
@ -31,6 +32,7 @@ export class Player extends AbstractEvent {
options: InputOptions,
public app: Editor,
zid: string = "",
waitTime: number = 0,
) {
super(app);
this.options = options;
@ -46,9 +48,24 @@ export class Player extends AbstractEvent {
} else {
throw new Error("Invalid input");
}
if(waitTime) this.waitTime = waitTime;
this.zid = zid;
}
updatePattern(input: string, options: InputOptions): boolean {
const oldIndex = this.ziffers.index;
const newPattern = new Ziffers(input, options);
if(newPattern.values.length > 0) {
this.ziffers = newPattern;
this.ziffers.update();
this.ziffers.index = oldIndex;
this.input = input;
this.options = options;
return true;
}
return false;
}
isValid() {
return this.ziffers.values.length > 0;
}
@ -417,10 +434,8 @@ export class Player extends AbstractEvent {
}
rotate(amount: number = 1) {
// TODO: Only works for evaluated patterns (setRedo). Fix this for generative patterns. Mod by current cycle?
if (this.atTheBeginning()) {
this.ziffers.setRedo(0);
this.ziffers.rotate(amount);
this.ziffers.rotate(amount+safeMod(this.ziffers.cycleIndex,this.ziffers.evaluated.length));
}
return this;
}