Skip to content

Commit

Permalink
singing.tsのsearchPhrasesをリファクタリング (#1850)
Browse files Browse the repository at this point in the history
* change: i -> noteIndex

* refactor: RENDERのgeneratePhraseHash引数を切り出す。foundPhrases.setに同じ構造があるため、再利用。

* refactor: if文で、ノートが重複していないかどうかをわかりやすく

* change: hashParams -> generateHashParams

* refactor: nullの場合も考慮してnextNoteStart変数を変更

* add: 処理内容をわかりやすくする(レビューの提案を反映)

* 微調整

* 差分減らし

* メインブランチのテストが落ちてたのでついでに修正

---------

Co-authored-by: Hiroshiba <[email protected]>
  • Loading branch information
weweweok and Hiroshiba authored Mar 18, 2024
1 parent 102d8a9 commit 1790938
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/store/singing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,32 +759,33 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
) => {
const foundPhrases = new Map<string, Phrase>();
let phraseNotes: Note[] = [];
for (let i = 0; i < notes.length; i++) {
const note = notes[i];
for (let noteIndex = 0; noteIndex < notes.length; noteIndex++) {
const note = notes[noteIndex];

phraseNotes.push(note);

// ノートが途切れていたら別のフレーズにする
const currentNoteEnd = note.position + note.duration;
const nextNoteStart =
noteIndex + 1 < notes.length ? notes[noteIndex + 1].position : null;
if (
i === notes.length - 1 ||
note.position + note.duration !== notes[i + 1].position
noteIndex === notes.length - 1 ||
nextNoteStart == null ||
currentNoteEnd !== nextNoteStart
) {
const phraseFirstNote = phraseNotes[0];
const phraseLastNote = phraseNotes[phraseNotes.length - 1];
const hash = await generatePhraseHash({
const params = {
singer,
keyRangeAdjustment,
volumeRangeAdjustment,
tpqn,
tempos,
notes: phraseNotes,
});
};
const hash = await generatePhraseHash(params);
foundPhrases.set(hash, {
singer,
keyRangeAdjustment,
volumeRangeAdjustment,
tpqn,
tempos,
notes: phraseNotes,
...params,
startTicks: phraseFirstNote.position,
endTicks: phraseLastNote.position + phraseLastNote.duration,
state: "WAITING_TO_BE_RENDERED",
Expand Down
1 change: 1 addition & 0 deletions tests/unit/lib/selectPriorPhrase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const createPhrase = (
startTicks: start * DEFAULT_TPQN,
endTicks: end * DEFAULT_TPQN,
keyRangeAdjustment: 0,
volumeRangeAdjustment: 0,
state,
tempos,
tpqn: DEFAULT_TPQN,
Expand Down

0 comments on commit 1790938

Please sign in to comment.