Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[project-s] リファクタリング #1735

Merged
merged 4 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/Sing/CharacterMenuButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default defineComponent({
)
)
);
if (engineId === undefined)
if (engineId == undefined)
throw new Error(
`No engineId for target character style (speakerUuid == ${speakerUuid}, styleId == ${styleId})`
);
Expand Down Expand Up @@ -209,8 +209,8 @@ export default defineComponent({

const selectedCharacterInfo = computed(() => {
if (
userOrderedCharacterInfos.value === undefined ||
store.state.singer === undefined
userOrderedCharacterInfos.value == undefined ||
store.state.singer == undefined
)
return undefined;
return store.getters.CHARACTER_INFO(
Expand Down
110 changes: 56 additions & 54 deletions src/components/Sing/ScoreSequencer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
transform: `translateX(${guideLineX}px)`,
}"
></div>
<!-- TODO: 1つのv-forで全てのノートを描画できるようにする -->
<sequencer-note
v-for="note in unselectedNotes"
:key="note.id"
Expand Down Expand Up @@ -230,12 +231,20 @@ export default defineComponent({
const state = store.state;
// 分解能(Ticks Per Quarter Note)
const tpqn = computed(() => state.score.tpqn);
// ノート
const notes = computed(() => state.score.notes);
// テンポ
const tempos = computed(() => state.score.tempos);
// 拍子
const timeSignatures = computed(() => state.score.timeSignatures);
// ノート
const notes = computed(() => state.score.notes);
const unselectedNotes = computed(() => {
const selectedNoteIds = state.selectedNoteIds;
return notes.value.filter((value) => !selectedNoteIds.has(value.id));
});
const selectedNotes = computed(() => {
const selectedNoteIds = state.selectedNoteIds;
return notes.value.filter((value) => selectedNoteIds.has(value.id));
});
// ズーム状態
const zoomX = computed(() => state.sequencerZoomX);
const zoomY = computed(() => state.sequencerZoomY);
Expand All @@ -245,11 +254,8 @@ export default defineComponent({
});
// シーケンサグリッド
const gridCellTicks = snapTicks; // ひとまずスナップ幅=グリッドセル幅
const gridCellBaseWidth = computed(() => {
return tickToBaseX(gridCellTicks.value, tpqn.value);
});
const gridCellWidth = computed(() => {
return gridCellBaseWidth.value * zoomX.value;
return tickToBaseX(gridCellTicks.value, tpqn.value) * zoomX.value;
});
const gridCellBaseHeight = getKeyBaseHeight();
const gridCellHeight = computed(() => {
Expand Down Expand Up @@ -299,16 +305,9 @@ export default defineComponent({
const baseX = tickToBaseX(playheadTicks.value, tpqn.value);
return Math.floor(baseX * zoomX.value);
});
const unselectedNotes = computed(() => {
const selectedNoteIds = state.selectedNoteIds;
return notes.value.filter((value) => !selectedNoteIds.has(value.id));
});
const selectedNotes = computed(() => {
const selectedNoteIds = state.selectedNoteIds;
return notes.value.filter((value) => selectedNoteIds.has(value.id));
});
// フレーズ
const phraseInfos = computed(() => {
return Object.entries(state.phrases).map(([key, phrase]) => {
return [...state.phrases.entries()].map(([key, phrase]) => {
const startBaseX = tickToBaseX(phrase.startTicks, tpqn.value);
const endBaseX = tickToBaseX(phrase.endTicks, tpqn.value);
const startX = startBaseX * zoomX.value;
Expand All @@ -330,6 +329,7 @@ export default defineComponent({
let previewRequestId = 0;
let dragStartTicks = 0;
let dragStartNoteNumber = 0;
let dragStartGuideLineTicks = 0;
let draggingNoteId = ""; // FIXME: 無効状態はstring以外の型にする
let edited = false; // プレビュー終了時にScoreの変更を行うかどうかを表す変数
// ダブルクリック
Expand All @@ -339,7 +339,7 @@ export default defineComponent({
undefined,
];
let ignoreDoubleClick = false;
// ガイドライン
// 入力を補助する線
const showGuideLine = ref(true);
const guideLineX = ref(0);

Expand Down Expand Up @@ -422,11 +422,10 @@ export default defineComponent({
edited = true;
}

// 当たり判定を0.25だけずらす
const guidelineTicks =
Math.round(dragStartTicks / snapTicks.value - 0.25) * snapTicks.value +
movingTicks;
const guideLineBaseX = tickToBaseX(guidelineTicks, tpqn.value);
const guideLineBaseX = tickToBaseX(
dragStartGuideLineTicks + movingTicks,
tpqn.value
);
guideLineX.value = guideLineBaseX * zoomX.value;
};

Expand Down Expand Up @@ -557,8 +556,7 @@ export default defineComponent({
note?: Note
) => {
if (nowPreviewing.value) {
// RESIZE_RIGHT・RESIZE_LEFTのあとにADDも発生するので、その場合は無視する
// TODO: stopPropagation付けたり、他のイベントではエラーを投げるようにする
store.dispatch("LOG_WARN", "startPreview was called during preview.");
return;
}
const sequencerBodyElement = sequencerBody.value;
Expand All @@ -577,15 +575,17 @@ export default defineComponent({
const cursorBaseY = (scrollY.value + cursorY) / zoomY.value;
const cursorTicks = baseXToTick(cursorBaseX, tpqn.value);
const cursorNoteNumber = baseYToNoteNumber(cursorBaseY);
// NOTE: 入力を補助する線の判定の境目はスナップ幅の3/4の位置
const guideLineTicks =
Math.round(cursorTicks / snapTicks.value - 0.25) * snapTicks.value;
const copiedNotes: Note[] = [];
if (mode === "ADD") {
if (cursorNoteNumber < 0) {
return;
}
note = {
id: uuidv4(),
position:
Math.round(cursorTicks / snapTicks.value - 0.25) * snapTicks.value,
position: guideLineTicks,
duration: snapTicks.value,
noteNumber: cursorNoteNumber,
lyric: getDoremiFromNoteNumber(cursorNoteNumber),
Expand Down Expand Up @@ -626,6 +626,7 @@ export default defineComponent({
previewMode = mode;
dragStartTicks = cursorTicks;
dragStartNoteNumber = cursorNoteNumber;
dragStartGuideLineTicks = guideLineTicks;
draggingNoteId = note.id;
edited = mode === "ADD";
copiedNotesForPreview.clear();
Expand Down Expand Up @@ -709,6 +710,7 @@ export default defineComponent({
const scrollLeft = sequencerBodyElement.scrollLeft;
const cursorBaseX = (scrollLeft + cursorX) / zoomX.value;
const cursorTicks = baseXToTick(cursorBaseX, tpqn.value);
// NOTE: 入力を補助する線の判定の境目はスナップ幅の3/4の位置
const guideLineTicks =
Math.round(cursorTicks / snapTicks.value - 0.25) * snapTicks.value;
const guideLineBaseX = tickToBaseX(guideLineTicks, tpqn.value);
Expand Down Expand Up @@ -1097,6 +1099,35 @@ export default defineComponent({
position: relative;
}

.sequencer-grid {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gridはきれいにコンポーネントに分けられそうだなと思いました!
(Vueは体感700行くらい超えてくると結構コーディングが重くなってくるので。。。)

display: block;
pointer-events: none;
}

.sequencer-grid-cell {
display: block;
stroke: #e8e8e8;
stroke-width: 1;
}

.sequencer-grid-cell-white {
fill: #fff;
}

.sequencer-grid-cell-black {
fill: #f2f2f2;
}

.sequencer-grid-measure-line {
backface-visibility: hidden;
stroke: #b0b0b0;
}

.sequencer-grid-beat-line {
backface-visibility: hidden;
stroke: #d0d0d0;
}

.sequencer-guideline {
position: absolute;
top: 0;
Expand Down Expand Up @@ -1132,33 +1163,4 @@ export default defineComponent({
border-left: 1px solid rgba(colors.$background-rgb, 0.83);
border-right: 1px solid rgba(colors.$background-rgb, 0.83);
}

.sequencer-grid {
display: block;
pointer-events: none;
}

.sequencer-grid-cell {
display: block;
stroke: #e8e8e8;
stroke-width: 1;
}

.sequencer-grid-cell-white {
fill: #fff;
}

.sequencer-grid-cell-black {
fill: #f2f2f2;
}

.sequencer-grid-measure-line {
backface-visibility: hidden;
stroke: #b0b0b0;
}

.sequencer-grid-beat-line {
backface-visibility: hidden;
stroke: #d0d0d0;
}
</style>
4 changes: 2 additions & 2 deletions src/components/Sing/SequencerKeys.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default defineComponent({
};

const onMouseUp = () => {
if (noteNumberOfKeyBeingPressed.value !== undefined) {
if (noteNumberOfKeyBeingPressed.value != undefined) {
const noteNumber = noteNumberOfKeyBeingPressed.value;
noteNumberOfKeyBeingPressed.value = undefined;
store.dispatch("STOP_PREVIEW_SOUND", { noteNumber });
Expand All @@ -130,7 +130,7 @@ export default defineComponent({

const onMouseEnter = (noteNumber: number) => {
if (
noteNumberOfKeyBeingPressed.value !== undefined &&
noteNumberOfKeyBeingPressed.value != undefined &&
noteNumberOfKeyBeingPressed.value !== noteNumber
) {
store.dispatch("STOP_PREVIEW_SOUND", {
Expand Down
5 changes: 4 additions & 1 deletion src/components/Sing/SequencerPhraseIndicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export default defineComponent({
PLAYABLE: "playable",
};
const className = computed(() => {
const phrase = store.state.phrases[props.phraseKey];
const phrase = store.state.phrases.get(props.phraseKey);
if (phrase == undefined) {
throw new Error("phrase is undefined.");
}
return classNames[phrase.state];
});

Expand Down
15 changes: 10 additions & 5 deletions src/components/Sing/ToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ import {
onUnmounted,
} from "vue";
import { useStore } from "@/store";
import { isTriplet, isValidBeatType } from "@/sing/domain";
import { getSnapTypes } from "@/sing/storeHelper";
import {
getSnapTypes,
isTriplet,
isValidBeatType,
isValidBeats,
isValidBpm,
} from "@/sing/domain";

export default defineComponent({
name: "SingToolBar",
Expand Down Expand Up @@ -142,21 +147,21 @@ export default defineComponent({

const setBpmInputBuffer = (bpmStr: string | number | null) => {
const bpm = Number(bpmStr);
if (!Number.isFinite(bpm) || bpm < 40) {
if (!isValidBpm(bpm)) {
return;
}
bpmInputBuffer.value = bpm;
};
const setBeatsInputBuffer = (beatsStr: string | number | null) => {
const beats = Number(beatsStr);
if (!Number.isInteger(beats) || beats <= 0) {
if (!isValidBeats(beats)) {
return;
}
beatsInputBuffer.value = beats;
};
const setBeatTypeInputBuffer = (beatTypeStr: string | number | null) => {
const beatType = Number(beatTypeStr);
if (!Number.isInteger(beatType) || !isValidBeatType(beatType)) {
if (!isValidBeatType(beatType)) {
return;
}
beatTypeInputBuffer.value = beatType;
Expand Down
10 changes: 5 additions & 5 deletions src/infrastructures/AudioRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ class AudioPlayerVoice {
* @param offset オフセット(秒)
*/
play(contextTime: number, offset: number) {
if (this.stopContextTime !== undefined) {
if (this.stopContextTime != undefined) {
throw new Error("Already started.");
}
this.audioBufferSourceNode.start(contextTime, offset);
Expand All @@ -555,7 +555,7 @@ class AudioPlayerVoice {
* @param contextTime 停止する時刻(コンテキスト時刻)
*/
stop(contextTime: number) {
if (this.stopContextTime === undefined) {
if (this.stopContextTime == undefined) {
throw new Error("Not started.");
}
if (contextTime < this.stopContextTime) {
Expand Down Expand Up @@ -740,7 +740,7 @@ class SynthVoice {
const stopContextTime = t0 + rel * 4;

if (
this.stopContextTime === undefined ||
this.stopContextTime == undefined ||
stopContextTime < this.stopContextTime
) {
// リリースのスケジュールを行う
Expand Down Expand Up @@ -796,7 +796,7 @@ export class PolySynth implements Instrument {
};

this.gainNode = new GainNode(this.audioContext);
this.gainNode.gain.value = options?.volume ?? 0.12;
this.gainNode.gain.value = options?.volume ?? 0.11;
}

/**
Expand Down Expand Up @@ -833,7 +833,7 @@ export class PolySynth implements Instrument {
});
this.voices.push(voice);
}
if (duration !== undefined) {
if (duration != undefined) {
voice.noteOff(contextTime + duration);
}
}
Expand Down
Loading
Loading