public void DrawSequencerPosition(Rect rect, Sequencer sequencer, float startWindow, float endWindow) { Rect activeArea = new Rect(rect); activeArea.x += leftPadding; activeArea.width -= leftPadding + rightPadding; float loopPosition = sequencer.currentIndex; float relativePostition = sequencer.GetDivisionLength() * loopPosition / sequencer.length; float positionWidth = sequencer.GetDivisionLength() * activeArea.width / sequencer.length; positionWidth = Mathf.Max(2.0f, positionWidth); EditorGUI.DrawRect(activeArea, Color.gray); Rect position = new Rect(relativePostition * activeArea.width + activeArea.x, activeArea.y, positionWidth, activeArea.height); float x = activeArea.width * startWindow + activeArea.x; float width = Mathf.Round(activeArea.width * (endWindow - startWindow)); Rect window = new Rect(x, activeArea.y, width, activeArea.height); EditorGUI.DrawRect(window, windowColor); EditorGUI.DrawRect(new Rect(x, activeArea.y, 1, activeArea.height), Color.black); EditorGUI.DrawRect(new Rect(x + width, activeArea.y, 1, activeArea.height), Color.black); if (sequencer.isActiveAndEnabled && Application.isPlaying) { EditorGUI.DrawRect(position, tickColor); } }
public void DrawSequencer(Rect rect, Sequencer sequencer, SerializedProperty allNotes) { float divisionLength = sequencer.GetDivisionLength(); numRows = maxKey - minKey + 1; numCols = Mathf.RoundToInt(sequencer.length / divisionLength); colWidth = (rect.width - keyboardWidth - rightPadding) / numCols; rowHeight = Mathf.Clamp(rect.height / numRows, minRowHeight, maxRowHeight); float scrollableWidth = numCols * colWidth + keyboardWidth + 1; float scrollableHeight = numRows * rowHeight; if (lastHeight != rect.height) { lastHeight = rect.height; scrollPosition.y = GetScrollPosition(sequencer, rect.height); } Rect scrollableArea = new Rect(0, 0, scrollableWidth, scrollableHeight); scrollPosition = GUI.BeginScrollView(rect, scrollPosition, scrollableArea, false, true); DrawNoteRows(scrollableArea); DrawBarHighlights(scrollableArea); DrawNoteDivisionLines(scrollableArea); DrawActiveNotes(sequencer, divisionLength); DrawPressedNotes(divisionLength); DrawPositionOverlay(sequencer); GUI.EndScrollView(); }
public void DrawSequencerPosition(Rect rect, Sequencer sequencer) { Rect activeArea = new Rect(rect); activeArea.x += leftPadding; activeArea.width -= leftPadding + rightPadding; float loopPosition = sequencer.currentIndex; float relativePostition = sequencer.GetDivisionLength() * loopPosition / sequencer.length; float positionWidth = sequencer.GetDivisionLength() * activeArea.width / sequencer.length; EditorGUI.DrawRect(activeArea, Color.gray); Rect position = new Rect(relativePostition * activeArea.width + activeArea.x, activeArea.y, positionWidth, activeArea.height); if (sequencer.isActiveAndEnabled && Application.isPlaying) { EditorGUI.DrawRect(position, tickColor); } }
public void DrawSequencer(Rect rect, Sequencer sequencer, float zoomPercent, SerializedProperty allNotes) { float divisionLength = sequencer.GetDivisionLength(); numRows = maxKey - minKey + 1; numCols = Mathf.RoundToInt(sequencer.length / divisionLength); numSixteenths = Mathf.RoundToInt(sequencer.length); float zoomLog = Mathf.Log(maxColZoomWidth / minColWidth); float zoomSize = minColWidth * Mathf.Exp(zoomLog * zoomPercent); float minWidth = Mathf.Max(zoomSize, minColWidth); colWidth = Mathf.Max(minWidth * divisionLength, (rect.width - keyboardWidth - rightPadding) / numCols); sixteenthWidth = Mathf.Max(minWidth, (rect.width - keyboardWidth - rightPadding) / numSixteenths); float noteAreaHeight = rect.height - bottomPadding - velocitySectionHeight; rowHeight = Mathf.Clamp(noteAreaHeight / numRows, minRowHeight, maxRowHeight); float scrollableWidth = numCols * colWidth + keyboardWidth + 1; float scrollableHeight = numRows * rowHeight + velocitySectionHeight; Rect scrollableArea = new Rect(0, 0, scrollableWidth, scrollableHeight); if (sequencer.autoScroll && sequencer.isActiveAndEnabled && EditorApplication.isPlaying && !EditorApplication.isPaused) { float playPosition = keyboardWidth + colWidth * sequencer.currentIndex; scrollPosition = sequencer.scrollPosition; if (playPosition < scrollPosition.x - keyboardWidth || playPosition + colWidth >= scrollPosition.x - keyboardWidth + rect.width) { scrollPosition.x = playPosition - keyboardWidth; } sequencer.scrollPosition = scrollPosition; } sequencer.scrollPosition = GUI.BeginScrollView(rect, sequencer.scrollPosition, scrollableArea, true, true); scrollPosition = sequencer.scrollPosition; DrawNoteRows(rect); DrawBarHighlights(rect); DrawNoteDivisionLines(rect); DrawActiveNotes(sequencer, divisionLength, rect); DrawPressedNotes(divisionLength); DrawPositionOverlay(sequencer, rect); velocities.DrawSequencerVelocities(GetVelocityRect(rect), sequencer, GetMinVisibleTime(), GetMaxVisibleTime(rect.width)); GUI.EndScrollView(); }
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; } }
void MouseUp(float time, Sequencer sequencer, SerializedProperty allNotes) { float divisionLength = sequencer.GetDivisionLength(); mouseActive = false; if (mode == Mode.kKeyboarding) { sequencer.NoteOff(pressedKey); pressedKey = -1; return; } dragTime = Mathf.Clamp(time, 0.0f, sequencer.length); float startTime = Mathf.Min(pressTime, dragTime); float endTime = Mathf.Max(pressTime, dragTime); if (mode == Mode.kDraggingStart) { Undo.RecordObject(sequencer, "Move Note Start"); if (activeNote != null) { float newStart = Mathf.Min(activeNote.end - minNoteTime, activeTime); sequencer.ClampNotesInRange(pressNote, newStart, activeNote.end, activeNote); activeNote.start = newStart; } } else if (mode == Mode.kDraggingEnd) { Undo.RecordObject(sequencer, "Move Note End"); if (activeNote != null) { float newEnd = Mathf.Max(activeNote.start + minNoteTime, activeTime); sequencer.ClampNotesInRange(pressNote, activeNote.start, newEnd, activeNote); activeNote.end = newEnd; } } else if (mode == Mode.kAdding) { Undo.RecordObject(sequencer, "Add Sequencer Notes"); int startDragIndex = Mathf.FloorToInt(startTime / divisionLength); int endDragIndex = Mathf.CeilToInt(endTime / divisionLength); sequencer.ClampNotesInRange(pressNote, startDragIndex * divisionLength, endDragIndex * divisionLength); for (int i = startDragIndex; i < endDragIndex; ++i) { sequencer.AddNote(pressNote, i * divisionLength, (i + 1) * divisionLength, defaultVelocity); } } else if (mode == Mode.kDeleting) { Undo.RecordObject(sequencer, "Delete Sequencer Notes"); sequencer.RemoveNotesInRange(pressNote, startTime, endTime); } mode = Mode.kWaiting; if (!Application.isPlaying) { CopyNoteRowToSerializedProperty(sequencer.allNotes[pressNote], allNotes.GetArrayElementAtIndex(pressNote)); } }
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); }