initial public release.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { Expose, Type } from 'class-transformer';
|
||||
import { KGRegion } from './KGRegion';
|
||||
import { KGMidiNote } from '../midi/KGMidiNote';
|
||||
|
||||
/**
|
||||
* KGMidiRegion - Class representing a MIDI region in the DAW
|
||||
* Contains MIDI notes and inherits position/length from KGRegion
|
||||
*/
|
||||
export class KGMidiRegion extends KGRegion {
|
||||
@Expose()
|
||||
protected override __type: string = 'KGMidiRegion';
|
||||
|
||||
@Expose()
|
||||
@Type(() => KGMidiNote)
|
||||
protected notes: KGMidiNote[] = [];
|
||||
|
||||
constructor(id: string, trackId: string, trackIndex: number, name: string, startFromBeat: number = 0, length: number = 0) {
|
||||
super(id, trackId, trackIndex, name, startFromBeat, length);
|
||||
this.__type = 'KGMidiRegion';
|
||||
}
|
||||
|
||||
// Getter
|
||||
public getNotes(): KGMidiNote[] {
|
||||
return this.notes;
|
||||
}
|
||||
|
||||
// Setter
|
||||
public setNotes(notes: KGMidiNote[]): void {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
// Add a single note
|
||||
public addNote(note: KGMidiNote): void {
|
||||
this.notes.push(note);
|
||||
}
|
||||
|
||||
// Remove a note by ID
|
||||
public removeNote(noteId: string): void {
|
||||
this.notes = this.notes.filter(note => note.getId() !== noteId);
|
||||
}
|
||||
|
||||
// Override getCurrentType to return specific subclass type
|
||||
public override getCurrentType(): string {
|
||||
return 'KGMidiRegion';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import { Expose } from 'class-transformer';
|
||||
import type { Selectable } from '../../components/interfaces';
|
||||
|
||||
/**
|
||||
* KGRegion - Base class for regions in the DAW
|
||||
* Contains position and length information
|
||||
*/
|
||||
export class KGRegion implements Selectable {
|
||||
@Expose()
|
||||
protected __type: string = 'KGRegion';
|
||||
|
||||
@Expose()
|
||||
protected id: string = '';
|
||||
|
||||
@Expose()
|
||||
protected trackId: string = '';
|
||||
|
||||
@Expose()
|
||||
protected trackIndex: number = 0;
|
||||
|
||||
@Expose()
|
||||
protected name: string = '';
|
||||
|
||||
@Expose()
|
||||
protected startFromBeat: number = 0;
|
||||
|
||||
@Expose()
|
||||
protected length: number = 0;
|
||||
|
||||
@Expose()
|
||||
protected selected: boolean = false;
|
||||
|
||||
constructor(id: string, trackId: string, trackIndex: number, name: string, startFromBeat: number = 0, length: number = 0) {
|
||||
this.id = id;
|
||||
this.trackId = trackId;
|
||||
this.trackIndex = trackIndex;
|
||||
this.name = name;
|
||||
this.startFromBeat = startFromBeat;
|
||||
this.length = length;
|
||||
|
||||
this.selected = false;
|
||||
}
|
||||
|
||||
// Getters
|
||||
public getId(): string {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public getTrackId(): string {
|
||||
return this.trackId;
|
||||
}
|
||||
|
||||
public getTrackIndex(): number {
|
||||
return this.trackIndex;
|
||||
}
|
||||
|
||||
public getName(): string {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public getStartFromBeat(): number {
|
||||
return this.startFromBeat;
|
||||
}
|
||||
|
||||
public getLength(): number {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
// Setters
|
||||
public setId(id: string): void {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public setTrackId(trackId: string): void {
|
||||
this.trackId = trackId;
|
||||
}
|
||||
|
||||
public setTrackIndex(trackIndex: number): void {
|
||||
this.trackIndex = trackIndex;
|
||||
}
|
||||
|
||||
public setName(name: string): void {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public setStartFromBeat(startFromBeat: number): void {
|
||||
this.startFromBeat = startFromBeat;
|
||||
}
|
||||
|
||||
public setLength(length: number): void {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
// interface methods
|
||||
public select(): void {
|
||||
this.selected = true;
|
||||
}
|
||||
|
||||
public deselect(): void {
|
||||
this.selected = false;
|
||||
}
|
||||
|
||||
public isSelected(): boolean {
|
||||
return this.selected;
|
||||
}
|
||||
|
||||
// Type identification method for performance-optimized instanceof checks
|
||||
public getRootType(): string {
|
||||
return 'KGRegion';
|
||||
}
|
||||
|
||||
// Current type identification for copy/paste operations
|
||||
public getCurrentType(): string {
|
||||
return 'KGRegion';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user