support sample stretching

This commit is contained in:
2023-09-24 23:35:37 +02:00
parent 2843b65122
commit 759c60dbf9
2 changed files with 79 additions and 62 deletions

View File

@ -230,25 +230,25 @@ export class SoundEvent extends AudibleEvent {
// Frequency management
public sound = (value: string) => this.updateValue("s", value);
public chord = (value: string|object[]|number[]|number,...kwargs: number[]) => {
if(typeof value === "string") {
public chord = (value: string | object[] | number[] | number, ...kwargs: number[]) => {
if (typeof value === "string") {
const chord = parseChord(value);
value = chord.map((note: number) => { return {note: note, freq: midiToFreq(note) } });
} else if(value instanceof Array && typeof value[0] === "number") {
value = (value as number[]).map((note: number) => { return {note: note, freq: midiToFreq(note) } });
value = chord.map((note: number) => { return { note: note, freq: midiToFreq(note) } });
} else if (value instanceof Array && typeof value[0] === "number") {
value = (value as number[]).map((note: number) => { return { note: note, freq: midiToFreq(note) } });
} else if (typeof value === "number" && kwargs.length > 0) {
value = [value, ...kwargs].map((note: number) => { return {note: note, freq: midiToFreq(note) } });
value = [value, ...kwargs].map((note: number) => { return { note: note, freq: midiToFreq(note) } });
}
return this.updateValue("chord", value);
}
public invert = (howMany: number = 0) => {
if(this.values.chord) {
if (this.values.chord) {
let notes = this.values.chord.map((obj: { [key: string]: number }) => obj.note);
notes = howMany < 0 ? [...notes].reverse() : notes;
for (let i = 0; i < Math.abs(howMany); i++) {
notes[i % notes.length] += howMany <= 0 ? -12 : 12;
}
const chord = notes.map((note: number) => { return {note: note, freq: midiToFreq(note) } });
const chord = notes.map((note: number) => { return { note: note, freq: midiToFreq(note) } });
return this.updateValue("chord", chord);
} else {
return this;
@ -259,8 +259,8 @@ export class SoundEvent extends AudibleEvent {
public cut = (value: number) => this.updateValue("cut", value);
public clip = (value: number) => this.updateValue("clip", value);
public n = (value: number) => this.updateValue("n", value);
public note = (value: number|string) => {
if(typeof value === "string") {
public note = (value: number | string) => {
if (typeof value === "string") {
return this.updateValue("note", noteNameToMidi(value));
} else {
return this.updateValue("note", value);
@ -295,6 +295,13 @@ export class SoundEvent extends AudibleEvent {
public size = (value: number) => this.updateValue("size", value);
public sz = this.size;
// Unit
public stretch = (beat: number) => {
this.updateValue("unit", "c");
this.updateValue("speed", 2 / beat)
return this;
}
// ================================================================================
// AbstactEvent overrides
// ================================================================================