From 87d53591f6cd4460f8ebf34b862242d4b05f7c17 Mon Sep 17 00:00:00 2001 From: Daniel Ledda Date: Sat, 1 Jun 2024 20:16:48 +0200 Subject: [PATCH] update --- src/Beat.ts | 33 ++++----- src/Track.ts | 15 ++-- src/globals.d.ts | 15 ++++ src/ui/Beat/Beat.vue | 18 ++++- src/ui/BeatSettings/BeatSettings.vue | 3 + src/ui/Root/Toolbox.vue | 15 ++-- src/ui/Track/Track.vue | 103 ++++++++------------------- src/ui/TrackUnit/trackUnit.ts | 3 +- 8 files changed, 97 insertions(+), 108 deletions(-) diff --git a/src/Beat.ts b/src/Beat.ts index 42b779a..03ed271 100644 --- a/src/Beat.ts +++ b/src/Beat.ts @@ -44,6 +44,7 @@ export class Beat extends EffectScoped { barSettingsLocked: Ref; name: Ref; saveDirty = ref(false); + displaySticking = ref(false); constructor(opts: BeatGroupInitOptions) { super(); @@ -112,19 +113,13 @@ export class Beat extends EffectScoped { } } - getTrackByIndex(trackIndex: number) { - const track = this.tracks.value[trackIndex]; - if (!track) { - throw new Error(`Could not find the track with index: ${trackIndex}`); - } - return track; - } - insertAt(trackIndex: number, newIndex: number): void { - const track = this.getTrackByIndex(trackIndex); - this.tracks.value.splice(trackIndex, 1); - this.tracks.value = this.tracks.value.slice(0, newIndex).concat([track]).concat(this.tracks.value.slice(newIndex)); - triggerRef(this.tracks); + const track = this.tracks.value[trackIndex]; + if (track) { + this.tracks.value.splice(trackIndex, 1); + this.tracks.value = this.tracks.value.slice(0, newIndex).concat([track]).concat(this.tracks.value.slice(newIndex)); + triggerRef(this.tracks); + } } notifyChange() { @@ -153,10 +148,12 @@ export class Beat extends EffectScoped { } removeTrack(index: number): void { - const track = this.getTrackByIndex(index); - this.tracks.value.splice(index, 1); - track.destroy(); - triggerRef(this.tracks); + const track = this.tracks.value[index]; + if (track) { + this.tracks.value.splice(index, 1); + track.destroy(); + triggerRef(this.tracks); + } } bakeLoops(): void { @@ -166,6 +163,10 @@ export class Beat extends EffectScoped { this.tracks.value.forEach(track => track.bakeLoops()); } + getTracks(): Track[] { + return this.tracks.value; + } + serialise(): Readonly { return { tracks: this.tracks.value.map(track => track.serialise()), diff --git a/src/Track.ts b/src/Track.ts index 03f1b16..fd7e2f6 100644 --- a/src/Track.ts +++ b/src/Track.ts @@ -34,10 +34,7 @@ export type TrackSerial = z.infer; export const TrackUnitTypeList = [ "Normal", "GhostNote", "Accent", "GhostNoteAccent" ] as const; export type TrackUnitType = typeof TrackUnitTypeList[number]; -export const PaintableTrackUnitStickingTypeList = [ "lh", "rh", "lf", "rf" ] as const; -export type PaintableTrackUnitStickingType = typeof PaintableTrackUnitStickingTypeList[number]; - -export const TrackUnitStickingTypeList = [ "lh", "rh", "lf", "rf" ] as const; +export const TrackUnitStickingTypeList = [ "none", "lh", "rh", "lf", "rf" ] as const; export type TrackUnitStickingType = typeof TrackUnitStickingTypeList[number]; export function isValidTimeSigRange(sig: number): boolean { @@ -53,7 +50,7 @@ export function deserialise(serial: unknown, manager: BeatManager) { const units = beat.units.isOn.map((isOn, i) => ({ on: isOn, type: beat.units.type[i] ?? 0, - stickingType: beat.units.stickingType[i] ?? 0, + stickingType: beat.units.stickingType[i] ?? null, })); return Track.asScoped({ manager, @@ -79,10 +76,10 @@ export class Track extends EffectScoped { private loopLengthInternal: any; private timeSig: { up: number, down: number }; private manager: BeatManager; + private unitRecord: ShallowRef; name: Ref; timeSigUp: Ref; timeSigDown: Ref; - unitRecord: ShallowRef; barCount: Ref; loopLength: Ref; looping: Ref; @@ -140,6 +137,10 @@ export class Track extends EffectScoped { return this.unitRecord.value[index] ?? null; } + unitCount() { + return this.unitRecord.value.length; + } + private updateTrackUnitLength() { const newBarCount = this.barCount.value * this.timeSigUp.value; if (newBarCount < this.unitRecord.value.length) { @@ -187,7 +188,7 @@ export class Track extends EffectScoped { return { on: false, type: 0, - stickingType: 0, + stickingType: null, }; } diff --git a/src/globals.d.ts b/src/globals.d.ts index 908f34e..fdd7a0b 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -6,4 +6,19 @@ declare global { } } +declare module "*.gif" { + const value: string; + export = value; +} + +declare module "*.png" { + const value: string; + export = value; +} + +declare module "*.svg" { + const value: string; + export = value; +} + export {}; diff --git a/src/ui/Beat/Beat.vue b/src/ui/Beat/Beat.vue index 1ccd05b..daf7040 100644 --- a/src/ui/Beat/Beat.vue +++ b/src/ui/Beat/Beat.vue @@ -3,7 +3,18 @@
- +
+
{{ TrackUnitStickingTypeList[type + 1]?.toUpperCase() }}
+ + +
+ + import TrackView from "@/ui/Track/Track.vue"; + import StickingTrackView from "@/ui/Track/StickingTrack.vue"; import EditableTextField from "@/ui/Widgets/EditableTextField/EditableTextField.vue"; import { useBeatStore } from '@/BeatStore'; import { computed, ref } from "vue"; import Draggable from "vuedraggable"; - import type { Track } from "@/Track"; + import { TrackUnitStickingTypeList, type Track } from "@/Track"; import Icon from "@/ui/Widgets/Icon/Icon.vue"; const props = defineProps<{ @@ -43,7 +55,7 @@ const beat = computed(() => beats.value[props.beatIndex] ?? null); const tracks = computed(() => { - const trackList = beat.value?.tracks.value ?? []; + const trackList = beat.value?.getTracks() ?? []; const length = trackList.length; const list: { index: number, track: Track }[] = []; for (let i = 0; i < length; i++) { diff --git a/src/ui/BeatSettings/BeatSettings.vue b/src/ui/BeatSettings/BeatSettings.vue index 7ac9639..ac3581c 100644 --- a/src/ui/BeatSettings/BeatSettings.vue +++ b/src/ui/BeatSettings/BeatSettings.vue @@ -7,6 +7,9 @@
+
+ +
diff --git a/src/ui/Root/Toolbox.vue b/src/ui/Root/Toolbox.vue index f427eb4..1dc73bc 100644 --- a/src/ui/Root/Toolbox.vue +++ b/src/ui/Root/Toolbox.vue @@ -7,7 +7,6 @@ @click="selectedTool = 'track-unit-type'">
@@ -17,7 +16,7 @@ :key="type ?? 'eraser'" class="toolbox-button track-unit-type" :class="{ active: i === activeTrackUnitType || type === null && activeTrackUnitType === null }" - @click="activeTrackUnitType = type === null ? null : i; selectedTool = 'track-unit-type'"> + @click="activeTrackUnitType = (type === null ? null : i); selectedTool = 'track-unit-type'">
@@ -27,16 +26,16 @@