Fix chord & note issues

This commit is contained in:
2023-11-28 07:50:03 +02:00
parent 22508acb9f
commit 278dce0196
4 changed files with 50 additions and 58 deletions

View File

@ -2,6 +2,7 @@ import { type UserAPI } from "../API";
import { MidiEvent } from "../classes/MidiEvent";
import { Player } from "../classes/ZPlayer";
import { SoundEvent } from "../classes/SoundEvent";
import { SkipEvent } from "../classes/SkipEvent";
declare global {
interface Number {
@ -24,7 +25,7 @@ declare global {
z15(): Player;
z16(): Player;
midi(): MidiEvent;
sound(name: string): SoundEvent;
sound(name: string): SoundEvent|SkipEvent;
}
}
@ -101,11 +102,11 @@ export const makeNumberExtensions = (api: UserAPI) => {
return api.midi(this.valueOf(), ...kwargs);
};
Number.prototype.sound = function (name: string) {
Number.prototype.sound = function (name: string): SoundEvent|SkipEvent {
if (Number.isInteger(this.valueOf())) {
return (api.sound(name) as SoundEvent).note(this.valueOf());
} else {
return (api.sound(name) as SoundEvent).freq(this.valueOf());
}
}
};
};