This commit is contained in:
André Michelle
2026-03-17 14:45:50 +01:00
parent 2807fb8446
commit a7806dfd8a
2 changed files with 12 additions and 45 deletions
@@ -113,7 +113,7 @@ export const ValueEditor = ({lifecycle, service, range, snapping, eventMapping,
if (dblclck && !event.shiftKey) {
if (target === null || target.type === "loop-duration") {
const rect = canvas.getBoundingClientRect()
const position = snapping.xToUnitRound(event.clientX - rect.left) - reader.offset
const position = Math.round(range.xToUnit(event.clientX - rect.left) - reader.offset)
const clickValue = valueAxis.axisToValue(event.clientY - rect.top)
const formatValue = context.currentValue
const value: number = Math.abs(valueToPixel(clickValue) - valueToPixel(formatValue))
@@ -121,8 +121,8 @@ export const ValueEditor = ({lifecycle, service, range, snapping, eventMapping,
? formatValue
: context.quantize(clickValue)
return editing.modify(() =>
ValueEventEditing.createOrMoveEvent(reader.content, snapping, position, value,
context.floating ? Interpolation.Linear : Interpolation.None))
ValueEventEditing.createOrMoveEvent(reader.content, position, value,
context.floating ? Interpolation.Linear : Interpolation.None), false)
.match({
none: () => Option.None,
some: adapter => {
@@ -1,6 +1,5 @@
import {ValueEventBoxAdapter, ValueEventCollectionBoxAdapter} from "@opendaw/studio-adapters"
import {Interpolation, ppqn, ValueEvent} from "@opendaw/lib-dsp"
import {Snapping} from "@/ui/timeline/Snapping.ts"
import {assert, panic, unitValue} from "@opendaw/lib-std"
export namespace ValueEventEditing {
@@ -24,57 +23,25 @@ export namespace ValueEventEditing {
}
}
export const createOrMoveEvent = (collection: ValueEventCollectionBoxAdapter,
snapping: Snapping,
pointer: ppqn,
position: ppqn,
value: unitValue,
interpolation: Interpolation = Interpolation.Linear): ValueEventBoxAdapter => {
const position: ppqn = snapping.round(pointer)
const le = collection.events.lowerEqual(position)
const ge = collection.events.greaterEqual(position)
if (null === le || null === ge) { // alone > no interference
return collection.createEvent({
position: position,
index: 0,
value,
interpolation
})
if (null === le || null === ge) {
return collection.createEvent({position, index: 0, value, interpolation})
} else if (le === ge) {
if (pointer >= position) {
if (le.index === 0) {
return collection.createEvent({
position,
index: 1,
value,
interpolation
})
} else {
le.box.value.setValue(value)
return le
}
} else {
le.box.index.setValue(1)
return collection.createEvent({
position,
index: 0,
value,
interpolation
})
}
} else if (le.position === ge.position) {
if (pointer < position) {
ge.box.value.setValue(value)
return ge
if (le.index === 0) {
return collection.createEvent({position, index: 1, value, interpolation})
} else {
le.box.value.setValue(value)
return le
}
} else if (le.position === ge.position) {
le.box.value.setValue(value)
return le
} else {
return collection.createEvent({
position,
index: 0,
value,
interpolation
})
return collection.createEvent({position, index: 0, value, interpolation})
}
}
}