From 275ebc2fd50cc5d964d6b55d92db9ee79248f0f6 Mon Sep 17 00:00:00 2001 From: Daniel Ledda Date: Sun, 2 Jun 2024 15:52:01 +0200 Subject: [PATCH] update --- src/Track.ts | 36 ++++++++++++++++++++++++++++++++++++ src/ui/Beat/Beat.vue | 28 +++++++++++++++++++++++----- src/ui/Track/Track.vue | 9 +-------- 3 files changed, 60 insertions(+), 13 deletions(-) diff --git a/src/Track.ts b/src/Track.ts index 2bb5434..3a70e00 100644 --- a/src/Track.ts +++ b/src/Track.ts @@ -2,6 +2,7 @@ import { isPosInt, EffectScoped } from "@/utils"; import { ref, shallowRef, computed, watch, reactive, triggerRef, type Ref, type ShallowRef } from "vue"; import type { BeatManager } from "./Beat"; import { z } from "zod"; +import { useAppStateStore, type UITool } from "./AppState"; export type TrackInitOptions = { visible?: boolean, @@ -80,6 +81,8 @@ export class Track extends EffectScoped { private timeSig: { up: number, down: number }; private manager: BeatManager; private unitRecord: ShallowRef; + private appState = useAppStateStore(); + name: Ref; timeSigUp: Ref; timeSigDown: Ref; @@ -207,6 +210,39 @@ export class Track extends EffectScoped { triggerRef(this.unitRecord); } + /** + * Not specifying the index will apply the tool to the whole track + */ + applySelectedTool(index?: number) { + switch (this.appState.selectedTool.value) { + case "sticking": + if (typeof index !== 'number') { + this.unitRecord.value.forEach(unit => unit.stickingType = this.appState.activeStickingType.value); + triggerRef(this.unitRecord); + } else { + this.setStickingType(index, this.appState.activeStickingType.value); + } + break; + case "track-unit-type": + const activeTrackUnitType = this.appState.activeTrackUnitType.value; + if (typeof index !== 'number') { + this.unitRecord.value.forEach(unit => { + unit.on = activeTrackUnitType === null ? false : true; + if (activeTrackUnitType !== null) { + unit.type = activeTrackUnitType; + } + }); + triggerRef(this.unitRecord); + } else { + this.updateUnit(index, { + on: activeTrackUnitType === null ? false : true, + type: activeTrackUnitType === null ? undefined : activeTrackUnitType, + }); + } + break; + } + } + setUnitOn(index: number, on: boolean): void { const unit = this.getUnitByIndex(index); if (!unit) { diff --git a/src/ui/Beat/Beat.vue b/src/ui/Beat/Beat.vue index 9101bfd..a0cd4f7 100644 --- a/src/ui/Beat/Beat.vue +++ b/src/ui/Beat/Beat.vue @@ -23,8 +23,11 @@ item-key="index">