Skip to content

Commit

Permalink
ループボタンで初期ループを作成
Browse files Browse the repository at this point in the history
  • Loading branch information
romot-co committed Oct 22, 2024
1 parent aa36df8 commit b1bfd40
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 32 deletions.
32 changes: 29 additions & 3 deletions src/components/Sing/ToolBar/ToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ import {
import CharacterMenuButton from "@/components/Sing/CharacterMenuButton/MenuButton.vue";
import { useHotkeyManager } from "@/plugins/hotkeyPlugin";
import { SequencerEditTarget } from "@/store/type";
import { getNoteDuration } from "@/sing/domain";
const store = useStore();
Expand Down Expand Up @@ -431,9 +432,34 @@ const goToZero = () => {
void store.dispatch("SET_PLAYHEAD_POSITION", { position: 0 });
};
const { isLoopEnabled, setLoopEnabled } = useLoopControl();
const toggleLoop = () => {
void setLoopEnabled(!isLoopEnabled.value);
const {
isLoopEnabled,
setLoopEnabled,
setLoopRange,
loopStartTick,
loopEndTick,
} = useLoopControl();
const toggleLoop = async () => {
// ループが存在しない場合は見える範囲の1小節でループを作成
if (loopStartTick.value === loopEndTick.value) {
const sequencerBodyElement = document.querySelector(".sequencer-body");
if (!sequencerBodyElement) return;
const currentPosition = store.getters.GET_PLAYHEAD_POSITION();
const timeSignature = store.state.timeSignatures[0];
const oneMeasureTicks =
getNoteDuration(timeSignature.beatType, store.state.tpqn) *
timeSignature.beats;
const measureNumber = Math.floor(currentPosition / oneMeasureTicks);
const startTick = measureNumber * oneMeasureTicks;
const endTick = startTick + oneMeasureTicks;
await setLoopRange(startTick, endTick);
await setLoopEnabled(true);
} else {
// すでにループが存在する場合は単純に有効/無効を切り替え
await setLoopEnabled(!isLoopEnabled.value);
}
};
const volume = computed({
Expand Down
11 changes: 11 additions & 0 deletions src/domain/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,17 @@ export const migrateProjectFileObject = async (
projectData.song.trackOrder = Object.keys(newTracks);
}

// FIXME: 0.21.0 のマイグレーション
//if (semver.satisfies(projectAppVersion, "<0.21.0", semverSatisfiesOptions)) {
if (!("loop" in projectData.song)) {
projectData.song.loop = {
startTick: 0,
endTick: 0,
isLoopEnabled: false,
};
}
//}

// Validation check
// トークはvalidateTalkProjectで検証する
// ソングはSET_SCOREの中の`isValidScore`関数で検証される
Expand Down
6 changes: 5 additions & 1 deletion src/domain/project/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ export const projectSchema = z.object({
timeSignatures: z.array(timeSignatureSchema),
tracks: z.record(trackIdSchema, trackSchema),
trackOrder: z.array(trackIdSchema),
loop: loopSchema,
loop: z.object({
startTick: z.number(),
endTick: z.number(),
isLoopEnabled: z.boolean(),
}),
}),
});

Expand Down
14 changes: 0 additions & 14 deletions src/sing/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,20 +342,6 @@ export function createDefaultTrack(): Track {
};
}

export function createDefaultLoop(): Loop {
const defaultEndTick = getMeasureDuration(
DEFAULT_BEATS,
DEFAULT_BEAT_TYPE,
DEFAULT_TPQN,
);
console.log("defaultEndTick", defaultEndTick);
return {
isLoopEnabled: false,
startTick: 0,
endTick: defaultEndTick,
};
}

export function getSnapTypes(tpqn: number) {
return getRepresentableNoteTypes(tpqn).filter((value) => {
return value <= MAX_SNAP_TYPE;
Expand Down
17 changes: 7 additions & 10 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
createDefaultTempo,
createDefaultTimeSignature,
createDefaultTrack,
createDefaultLoop,
DEFAULT_TPQN,
} from "@/sing/domain";
import { EditorType } from "@/type/preload";
Expand Down Expand Up @@ -62,7 +61,7 @@ const applySongProjectToStore = async (
actions: DotNotationDispatch<AllActions>,
songProject: LatestProjectType["song"],
) => {
const { tpqn, tempos, timeSignatures, tracks, trackOrder } = songProject;
const { tpqn, tempos, timeSignatures, tracks, trackOrder, loop } = songProject;

Check failure on line 64 in src/store/project.ts

View workflow job for this annotation

GitHub Actions / build-test

Insert `⏎···`

Check failure on line 64 in src/store/project.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎···`

await actions.SET_TPQN({ tpqn });
await actions.SET_TEMPOS({ tempos });
Expand All @@ -76,6 +75,11 @@ const applySongProjectToStore = async (
}),
),
});
await actions.SET_LOOP_ENABLED({ isLoopEnabled: loop.isLoopEnabled });
await actions.SET_LOOP_RANGE({
loopStartTick: loop.startTick,
loopEndTick: loop.endTick,
});
};

export const projectStore = createPartialStore<ProjectStoreTypes>({
Expand Down Expand Up @@ -129,14 +133,6 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
await context.actions.SET_TIME_SIGNATURES({
timeSignatures: [createDefaultTimeSignature(1)],
});
const defaultLoop = createDefaultLoop();
await context.actions.SET_LOOP_ENABLED({
isLoopEnabled: defaultLoop.isLoopEnabled,
});
await context.actions.SET_LOOP_RANGE({
loopStartTick: defaultLoop.startTick,
loopEndTick: defaultLoop.endTick,
});
const trackId = TrackId(crypto.randomUUID());
await context.actions.SET_TRACKS({
tracks: new Map([[trackId, createDefaultTrack()]]),
Expand All @@ -159,6 +155,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
if (characterInfos == undefined)
throw new Error("characterInfos == undefined");

console.log(migrateProjectFileObject);

Check warning on line 158 in src/store/project.ts

View workflow job for this annotation

GitHub Actions / build-test

Unexpected console statement
const parsedProjectData = await migrateProjectFileObject(projectData, {
fetchMoraData: (payload) => actions.FETCH_MORA_DATA(payload),
voices: characterInfos.flatMap((characterInfo) =>
Expand Down
7 changes: 3 additions & 4 deletions src/store/singing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ import {
createDefaultTrack,
createDefaultTempo,
createDefaultTimeSignature,
createDefaultLoop,
isValidNotes,
isValidTrack,
SEQUENCER_MIN_NUM_MEASURES,
Expand Down Expand Up @@ -475,9 +474,9 @@ export const singingStoreState: SingingStoreState = {
nowAudioExporting: false,
cancellationOfAudioExportRequested: false,
isSongSidebarOpen: false,
isLoopEnabled: createDefaultLoop().isLoopEnabled,
loopStartTick: createDefaultLoop().startTick,
loopEndTick: createDefaultLoop().endTick,
isLoopEnabled: false,
loopStartTick: 0,
loopEndTick: 0,
};

export const singingStore = createPartialStore<SingingStoreTypes>({
Expand Down

0 comments on commit b1bfd40

Please sign in to comment.