Renamed root level note() to midi(). midi() & sound() now accepts object as parameter
This commit is contained in:
@ -75,7 +75,7 @@ export abstract class Event {
|
||||
|
||||
}
|
||||
|
||||
export abstract class SoundEvent extends Event {
|
||||
export abstract class AudibleEvent extends Event {
|
||||
constructor(app: Editor) {
|
||||
super(app);
|
||||
}
|
||||
@ -119,33 +119,4 @@ export abstract class SoundEvent extends Event {
|
||||
// Overwrite in subclasses
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class Skip {
|
||||
|
||||
_fallbackMethod = (): Skip => {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static createRestProxy = () => {
|
||||
const instance = new Skip();
|
||||
return new Proxy(instance, {
|
||||
// @ts-ignore
|
||||
get(target, propKey, receiver) {
|
||||
// @ts-ignore
|
||||
if (typeof target[propKey] === 'undefined') {
|
||||
return target._fallbackMethod;
|
||||
}
|
||||
// @ts-ignore
|
||||
return target[propKey];
|
||||
},
|
||||
// @ts-ignore
|
||||
set(target, propKey, value, receiver) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
out = (): void => {}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
import { SoundEvent } from './Event';
|
||||
import { AudibleEvent } from './AbstractEvents';
|
||||
import { type Editor } from '../main';
|
||||
import { MidiConnection } from "../IO/MidiConnection";
|
||||
import { midiToFreq, noteFromPc } from 'zifferjs';
|
||||
|
||||
export class Note extends SoundEvent {
|
||||
export class NoteEvent extends AudibleEvent {
|
||||
midiConnection: MidiConnection;
|
||||
|
||||
constructor(input: number|object, public app: Editor) {
|
||||
@ -1,7 +1,7 @@
|
||||
import { type Editor } from '../main';
|
||||
import { Event } from "./Event";
|
||||
import { Event } from "./AbstractEvents";
|
||||
|
||||
export class Rest extends Event {
|
||||
export class RestEvent extends Event {
|
||||
constructor(duration: number, app: Editor) {
|
||||
super(app);
|
||||
this.values["duration"] = duration;
|
||||
@ -12,7 +12,7 @@ export class Rest extends Event {
|
||||
}
|
||||
|
||||
public static createRestProxy = (duration: number, app: Editor) => {
|
||||
const instance = new Rest(duration, app);
|
||||
const instance = new RestEvent(duration, app);
|
||||
return new Proxy(instance, {
|
||||
// @ts-ignore
|
||||
get(target, propKey, receiver) {
|
||||
28
src/classes/SkipEvent.ts
Normal file
28
src/classes/SkipEvent.ts
Normal file
@ -0,0 +1,28 @@
|
||||
export class SkipEvent {
|
||||
|
||||
_fallbackMethod = (): SkipEvent => {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static createSkipProxy = () => {
|
||||
const instance = new SkipEvent();
|
||||
return new Proxy(instance, {
|
||||
// @ts-ignore
|
||||
get(target, propKey, receiver) {
|
||||
// @ts-ignore
|
||||
if (typeof target[propKey] === 'undefined') {
|
||||
return target._fallbackMethod;
|
||||
}
|
||||
// @ts-ignore
|
||||
return target[propKey];
|
||||
},
|
||||
// @ts-ignore
|
||||
set(target, propKey, value, receiver) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
out = (): void => {}
|
||||
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
import { type Editor } from '../main';
|
||||
import { SoundEvent } from './Event';
|
||||
import { AudibleEvent } from './AbstractEvents';
|
||||
import { midiToFreq, noteFromPc } from 'zifferjs';
|
||||
|
||||
import {
|
||||
@ -7,7 +7,7 @@ import {
|
||||
// @ts-ignore
|
||||
} from "superdough";
|
||||
|
||||
export class Sound extends SoundEvent {
|
||||
export class SoundEvent extends AudibleEvent {
|
||||
|
||||
constructor(sound: string|object, public app: Editor) {
|
||||
super(app);
|
||||
@ -1,9 +1,10 @@
|
||||
import { Chord, Pitch, Rest as ZRest, Ziffers } from "zifferjs";
|
||||
import { Editor } from "../main";
|
||||
import { Event, Skip } from "./Event";
|
||||
import { Sound } from "./Sound";
|
||||
import { Note } from "./Note";
|
||||
import { Rest } from "./Rest";
|
||||
import { Event } from "./AbstractEvents";
|
||||
import { SkipEvent } from "./SkipEvent";
|
||||
import { SoundEvent } from "./SoundEvent";
|
||||
import { NoteEvent } from "./MidiEvent";
|
||||
import { RestEvent } from "./RestEvent";
|
||||
|
||||
export class Player extends Event {
|
||||
input: string;
|
||||
@ -40,30 +41,28 @@ export class Player extends Event {
|
||||
if(this.areWeThereYet()) {
|
||||
const event = this.next() as Pitch|Chord|ZRest;
|
||||
if(event instanceof Pitch) {
|
||||
// TODO: Quick hack. Select which attributes to use, but some ziffers stuff is needed for chaining key change etc.
|
||||
const obj = event.getExisting("freq","pitch","key","scale","octave");
|
||||
return new Sound(obj, this.app).sound(name);
|
||||
return new SoundEvent(obj, this.app).sound(name);
|
||||
} else if(event instanceof ZRest) {
|
||||
return Rest.createRestProxy(event.duration, this.app);
|
||||
return RestEvent.createRestProxy(event.duration, this.app);
|
||||
}
|
||||
} else {
|
||||
return Skip.createRestProxy();
|
||||
return SkipEvent.createSkipProxy();
|
||||
}
|
||||
}
|
||||
|
||||
note(value: number|undefined = undefined) {
|
||||
midi(value: number|undefined = undefined) {
|
||||
if(this.areWeThereYet()) {
|
||||
const event = this.next() as Pitch|Chord|ZRest;
|
||||
if(event instanceof Pitch) {
|
||||
// TODO: Quick hack. Select which attributes to use, but some ziffers stuff is needed for chaining key change etc.
|
||||
const obj = event.getExisting("note","pitch","bend","key","scale","octave");
|
||||
const note = new Note(obj, this.app);
|
||||
const note = new NoteEvent(obj, this.app);
|
||||
return value ? note.note(value) : note;
|
||||
} else if(event instanceof ZRest) {
|
||||
return Rest.createRestProxy(event.duration, this.app);
|
||||
return RestEvent.createRestProxy(event.duration, this.app);
|
||||
}
|
||||
} else {
|
||||
return Skip.createRestProxy();
|
||||
return SkipEvent.createSkipProxy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user