From 4d11ec5cbf0aa84d81d65cfb3fd804bae5c43c79 Mon Sep 17 00:00:00 2001 From: ryohey Date: Wed, 2 Oct 2024 09:51:33 +0900 Subject: [PATCH 1/2] Add NoteNumber --- app/src/actions/song.ts | 4 ++-- app/src/entities/transform/NotePoint.ts | 7 ++----- app/src/entities/unit/NoteNumber.ts | 8 ++++++++ 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 app/src/entities/unit/NoteNumber.ts diff --git a/app/src/actions/song.ts b/app/src/actions/song.ts index 7899967e..0a5ebb33 100644 --- a/app/src/actions/song.ts +++ b/app/src/actions/song.ts @@ -1,4 +1,4 @@ -import { NotePoint } from "../entities/transform/NotePoint" +import { NoteNumber } from "../entities/unit/NoteNumber" import { isNotNull } from "../helpers/array" import { downloadSongAsMidi } from "../midi/midiConversion" import Song, { emptySong } from "../song" @@ -141,7 +141,7 @@ export const transposeNotes = } return { id, - noteNumber: NotePoint.clampNoteNumber(n.noteNumber + deltaPitch), + noteNumber: NoteNumber.clamp(n.noteNumber + deltaPitch), } }) .filter(isNotNull), diff --git a/app/src/entities/transform/NotePoint.ts b/app/src/entities/transform/NotePoint.ts index 075339e1..ffac8716 100644 --- a/app/src/entities/transform/NotePoint.ts +++ b/app/src/entities/transform/NotePoint.ts @@ -1,4 +1,4 @@ -import { MaxNoteNumber } from "../../Constants" +import { NoteNumber } from "../unit/NoteNumber" export interface NotePoint { tick: number @@ -6,12 +6,9 @@ export interface NotePoint { } export namespace NotePoint { - export const clampNoteNumber = (noteNumber: number) => - Math.min(MaxNoteNumber, Math.max(0, noteNumber)) - export const clamp = (point: NotePoint): NotePoint => ({ tick: Math.max(0, point.tick), - noteNumber: clampNoteNumber(point.noteNumber), + noteNumber: NoteNumber.clamp(point.noteNumber), }) export function equals(a: NotePoint, b: NotePoint): boolean { diff --git a/app/src/entities/unit/NoteNumber.ts b/app/src/entities/unit/NoteNumber.ts new file mode 100644 index 00000000..e0ae926b --- /dev/null +++ b/app/src/entities/unit/NoteNumber.ts @@ -0,0 +1,8 @@ +import { MaxNoteNumber } from "../../Constants" + +export type NoteNumber = number + +export namespace NoteNumber { + export const clamp = (noteNumber: number) => + Math.min(MaxNoteNumber, Math.max(0, noteNumber)) +} From fd8af278200de30f6a9bcc3d5c0b49e869683555 Mon Sep 17 00:00:00 2001 From: ryohey Date: Wed, 2 Oct 2024 09:54:04 +0900 Subject: [PATCH 2/2] Fix problem that notes can be placed out of range --- app/src/actions/track.ts | 7 ++++++- app/src/components/PianoRoll/PianoRoll.tsx | 11 ++++++++++- app/src/entities/unit/NoteNumber.ts | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/actions/track.ts b/app/src/actions/track.ts index b4570f0f..7dedfaa3 100644 --- a/app/src/actions/track.ts +++ b/app/src/actions/track.ts @@ -3,6 +3,7 @@ import { AnyChannelEvent, AnyEvent, SetTempoEvent } from "midifile-ts" import { ValueEventType } from "../entities/event/ValueEventType" import { Range } from "../entities/geometry/Range" import { Measure } from "../entities/measure/Measure" +import { NoteNumber } from "../entities/unit/NoteNumber" import { closedRange, isNotUndefined } from "../helpers/array" import { isEventInRange } from "../helpers/filterEvents" import { @@ -234,7 +235,11 @@ export const createNote = song, }: RootStore) => (tick: number, noteNumber: number) => { - if (selectedTrack === undefined || selectedTrack.channel == undefined) { + if ( + selectedTrack === undefined || + selectedTrack.channel == undefined || + !NoteNumber.isValid(noteNumber) + ) { return } pushHistory() diff --git a/app/src/components/PianoRoll/PianoRoll.tsx b/app/src/components/PianoRoll/PianoRoll.tsx index fd52f757..e9a417aa 100644 --- a/app/src/components/PianoRoll/PianoRoll.tsx +++ b/app/src/components/PianoRoll/PianoRoll.tsx @@ -102,9 +102,18 @@ const PianoRollWrapper: FC = observer(() => { [s, transform], ) + const onChangeSplitPane = useCallback(() => { + s.setScrollTopInPixels(s.scrollTop) + }, [s]) + return ( - + Math.min(MaxNoteNumber, Math.max(0, noteNumber)) + + export const isValid = (noteNumber: number) => + noteNumber >= 0 && noteNumber <= MaxNoteNumber }