void MouseDown(int note, float time, Sequencer sequencer, SerializedProperty allNotes) { float divisionLength = sequencer.GetDivisionLength(); roundingToIndex = false; mouseActive = true; activeNote = sequencer.GetNoteInRange(note, time, time); dragTime = time; activeTime = time; pressTime = time; pressNote = note; if (pressedKey >= 0) { sequencer.NoteOff(pressedKey); pressedKey = -1; } if (time < 0.0f) { mode = Mode.kKeyboarding; pressedKey = note; sequencer.NoteOn(pressedKey, 1.0f); return; } else if (activeNote != null) { float startPixels = colWidth * (time - activeNote.start) / divisionLength; float endPixels = colWidth * (activeNote.end - time) / divisionLength; if (endPixels <= grabResizeWidth) { mode = Mode.kDraggingEnd; } else if (startPixels <= grabResizeWidth) { mode = Mode.kDraggingStart; } else { mode = Mode.kDeleting; } } else { mode = Mode.kAdding; } }
bool MouseDrag(int note, float time, Sequencer sequencer, SerializedProperty allNotes) { float divisionLength = sequencer.GetDivisionLength(); float clampedTime = Mathf.Clamp(time, 0.0f, sequencer.length); float lastDragTime = dragTime; dragTime = clampedTime; float newActiveTime = dragTime; if (roundingToIndex) { newActiveTime = divisionLength * Mathf.Round(dragTime / divisionLength); } if (Mathf.Abs(dragTime - pressTime) >= dragDeltaStartRounding) { roundingToIndex = true; } if (mode == Mode.kKeyboarding) { if (note == pressedKey) { return(false); } sequencer.NoteOff(pressedKey); sequencer.NoteOn(note); pressedKey = note; return(true); } else if (mode == Mode.kDraggingStart) { if (activeNote == null) { return(false); } newActiveTime = Mathf.Min(activeNote.end - minNoteTime, newActiveTime); bool redraw = activeTime == newActiveTime; activeTime = newActiveTime; return(redraw); } else if (mode == Mode.kDraggingEnd) { if (activeNote == null) { return(false); } newActiveTime = Mathf.Max(activeNote.start + minNoteTime, newActiveTime); bool redraw = activeTime == newActiveTime; activeTime = newActiveTime; return(redraw); } else if (mode == Mode.kAdding) { int lastIndex = Mathf.FloorToInt(lastDragTime / divisionLength); int index = Mathf.FloorToInt(time / divisionLength); return(lastIndex != index); } return(true); }