namespace QuikDawEditor; public partial class ClipControl { bool MouseDownOnClipUnitRight = false; double MouseDownClipUnitRightXdiff = 0; bool MouseDownOnClipUnitLeft = false; double MouseDownClipUnitLeftXdiff = 0; bool MouseOverClipUnitRight = false; bool MouseOverClipUnitLeft = false; bool MouseIsSelecting = false; bool MouseDownInClipAreaGrid = false; Point MouseDownInClipPoint; private double generalMinClipWidthMs { get { return 1000; } } Clip copyingClip { get { return projPlayer.copyingClip; } } private bool IsCopyingClipOverlapping() { List otherClips = copyingClip.myTrack.Clips.Where(clp => clp.GetIndexInTrack != copyingClip.GetIndexInTrack).ToList(); return otherClips.Where(clp=> clp.ClipLeftMs <= copyingClip.ClipLeftMs && clp.ClipRightMs >= copyingClip.ClipLeftMs).Count() > 0 || otherClips.Where(clp=> clp.ClipLeftMs <= copyingClip.ClipRightMs && clp.ClipRightMs >= copyingClip.ClipRightMs).Count() > 0 || otherClips.Where(clp => clp.ClipLeftMs >= copyingClip.ClipLeftMs && clp.ClipRightMs <= copyingClip.ClipRightMs).Count() > 0; } private void ClipControl_MouseLeave(object sender, MouseEventArgs e) { Cursor = Cursors.Arrow; MouseOverClipUnitRight = false; MouseOverClipUnitLeft = false; if (MouseIsSelecting) { this.ReleaseMouseCapture(); SelectionRect.Visibility = Visibility.Hidden; MouseIsSelecting = false; } try { thisClip.GainPointsVisible = false; } catch { } } private void ClipControl_MouseEnter(object sender, MouseEventArgs e) { thisClip.GainPointsVisible = true; } private void ClipTopLabel_MouseDown(object sender, MouseButtonEventArgs e) { if (MouseInExtendButton) return; if (e.ChangedButton == MouseButton.Right) { ClipInfoTB.ContextMenu.IsOpen = true; return; } MouseDownOnClipLabel(this, e); } private void ClipTopLabel_PreviewMouseUp(object sender, MouseButtonEventArgs e) { if (MouseInExtendButton) return; if (MouseOverClipUnitLeft | MouseDownOnClipUnitLeft | MouseOverClipUnitRight | MouseDownOnClipUnitRight) return; e.Handled = true; MouseUpOnClipLabel(this, e); } private void ClipTopLabel_PreviewMouseMove(object sender, MouseEventArgs e) { if (MouseInExtendButton) return; if (MouseOverClipUnitLeft | MouseDownOnClipUnitLeft | MouseDownOnClipUnitRight | MouseOverClipUnitRight) return; e.Handled = true; MouseMoveOnClipLabel(this, e); } bool MouseInExtendButton = false; private void ExtendClipBut_MouseEnter(object sender, MouseEventArgs e) { MouseInExtendButton = true; } private void ExtendClipBut_MouseLeave(object sender, MouseEventArgs e) { MouseInExtendButton = false; } private void thisClipControl_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e) { e.Handled = true; } double MouseUpY = 0; private void ClipAreaGrid_PreviewMouseUp(object sender, MouseButtonEventArgs e) { Clip thisClip = (Clip)this.DataContext; if (e.ChangedButton == MouseButton.Right) { e.Handled = true; thisClip.SplitButLineX = e.GetPosition(this).X; MouseUpY = e.GetPosition(this).Y; thisClip.IsSplitLineVisible = true; this.ContextMenu.IsOpen = true; AvailableOnStopDP.IsEnabled = projPlayer.IsProjectNotPlaying; LowerMenuDP.Visibility = Visibility.Visible; } if (MouseDownInClipAreaGrid) { if (MouseIsSelecting) MouseIsSelecting = false; else SelectionRect.Visibility = Visibility.Hidden; } thisClip.SplitButLineX = e.GetPosition(this).X; if (MouseDownOnClipUnitRight) { undoActions.Add(new ClipWidthChangedUndoClass(thisClip.UndoClipID, thisClip.premoveClipWidthms, thisClip.premoveRightEdgeGainVal)); thisClip.SortGainPoints(); thisClip.ResetMe(projPlayer.CurrentPlayingPosMS); if (thisClip.premoveClipRightms >= editingProject.projectEndPointMs | thisClip.ClipRightMs > editingProject.projectEndPointMs) projPlayer.UpdateEndPoint(); editingProject.NeedsSaving = true; } if (MouseDownOnClipUnitLeft) { undoActions.Add(new ClipRelativeStartChangedUndoClass(thisClip.UndoClipID, thisClip.premoveClipRelStartms, thisClip.premoveClipWidthms, thisClip.premoveLeftEdgeGainVal)); editingProject.NeedsSaving = true; thisClip.SortGainPoints(); } MouseDownOnClipUnitRight = false; MouseDownOnClipUnitLeft = false; MouseOverClipUnitRight = false; MouseOverClipUnitLeft = false; MouseDownInClipAreaGrid = false; Cursor = Cursors.Arrow; ClipAreaGrid.ReleaseMouseCapture(); } private void ClipAreaGrid_PreviewMouseDown(object sender, MouseButtonEventArgs e) { foreach (Track t in editingProject.GetAllTracksInProject) foreach (Clip c in t.Clips) c.IsSplitLineVisible = false; if (e.ChangedButton == MouseButton.Right) { if (SelectionRect.IsVisible) SelectionRect.ContextMenu.IsOpen = true; e.Handled = true; return; } if (SelectionRect.IsVisible) { SelectionRect.Width = 0; MouseDownInClipPoint.X = e.GetPosition(this).X ; SelectionRect.Visibility = Visibility.Hidden; } MouseDownInClipAreaGrid = !(mouseOverGainPoint | mouseOverGainPath); MouseDownInClipPoint.X = e.GetPosition(this).X; if (mouseOverGainPoint) return; else { ClipAreaGrid.CaptureMouse(); if (MouseOverClipUnitRight) { thisClip.premoveClipWidthms = thisClip.ClipWidthMs; thisClip.premoveClipRightms = thisClip.ClipRightMs; MouseDownOnClipUnitRight = true; MouseDownClipUnitRightXdiff = this.ActualWidth - e.GetPosition(this).X; thisClip.premoveRightEdgeGainVal = thisClip.ClipEndGainPoint.GainValue; return; } if (MouseOverClipUnitLeft) { MouseDownOnClipUnitLeft = true; thisClip.premoveClipRelStartms = thisClip.ClipRelativeLoopStartMs; thisClip.premoveClipWidthms = thisClip.ClipWidthMs; MouseDownClipUnitLeftXdiff = e.GetPosition(this).X; thisClip.premoveLeftEdgeGainVal = thisClip.ClipStartGainPoint.GainValue; return; } } } double lastSign = 0; private void ClipAreaGrid_PreviewMouseMove(object sender, MouseEventArgs e) { double actualWidth = this.ActualWidth; if (mouseOverGainPoint) { Cursor = Cursors.Arrow; MouseOverClipUnitRight = false; MouseOverClipUnitLeft = false; MouseDownOnClipUnitLeft = false; MouseDownOnClipUnitRight = false; return; } double posx = e.GetPosition(this).X; double posxInMsZoomed = PixelsToMsecZoomed(posx); double posxInMs = PixelsToMsec(posx); if (MouseDownOnClipUnitRight) { posx += MouseDownClipUnitRightXdiff; double maxRightMs = Math.Min(MaxClipRightMs(thisClip), (thisClip.IsLooped | thisClip.IsMidiClip) ? Double.MaxValue : thisClip.ClipVirtualStartMs + thisClip.ClipSourceLenMilliseconds); if (editingProject.CurrentSnapTo == 2) { //No snap thisClip.ClipWidthMs = Math.Min(Math.Max(generalMinClipWidthMs, posxInMsZoomed), maxRightMs - thisClip.ClipLeftMs); } else { //Snap to selected double newclipRightMs = posxInMsZoomed + thisClip.ClipLeftMs; double nearestSnapMs = GetNearestSnapMs(newclipRightMs, editingProject.CurrentSnapTo); double lastdiff = newclipRightMs - nearestSnapMs; int newSign = Math.Sign(lastdiff); if (newSign != lastSign) { lastSign = newSign; double newClipRightMs = nearestSnapMs; thisClip.ClipWidthMs = Math.Min(Math.Max(generalMinClipWidthMs, newClipRightMs - thisClip.ClipLeftMs), maxRightMs - thisClip.ClipLeftMs); if (thisClip.IsCurrentClip) thisClip.ResetMe(projPlayer.CurrentPlayingPosMS); } } editingProject.NeedsSaving = true; return; } if (MouseDownOnClipUnitLeft) { posx -= MouseDownClipUnitLeftXdiff; double minLeftMs = Math.Max(MinClipLeftMs(thisClip), thisClip.ClipVirtualStartMs); posxInMsZoomed = Math.Max(posxInMsZoomed, minLeftMs - thisClip.ClipLeftMs); double newLeftMarginMs = Math.Max(thisClip.ClipLeftMs + posxInMsZoomed, minLeftMs); double newWidthMs = thisClip.ClipWidthMs - posxInMsZoomed; if (newWidthMs <= generalMinClipWidthMs) return; if (editingProject.CurrentSnapTo == 2) { //No snap double newClipRelStartMs = newLeftMarginMs - thisClip.ClipVirtualStartMs; thisClip.ClipRelativeLoopStartMs = newClipRelStartMs; thisClip.myTrack.ResetClips(projPlayer.CurrentPlayingPosMS); } else { //Snap to selected double nearestSnapMs = GetNearestSnapMs(newLeftMarginMs, editingProject.CurrentSnapTo); double lastdiff = newLeftMarginMs - nearestSnapMs; int newSign = Math.Sign(lastdiff); if (newSign != lastSign) { lastSign = newSign; double newClipLeftMs = nearestSnapMs; newLeftMarginMs = Math.Max(minLeftMs, newClipLeftMs); double newClipRelStartMs = newLeftMarginMs - thisClip.ClipVirtualStartMs; thisClip.ClipRelativeLoopStartMs = newClipRelStartMs; thisClip.myTrack.ResetClips(projPlayer.CurrentPlayingPosMS); } } editingProject.NeedsSaving = true; return; } if (MouseDownInClipAreaGrid) { double selWidth = e.GetPosition(this).X - MouseDownInClipPoint.X; if (Math.Abs(selWidth) > 5) { SelectionRect.Visibility = Visibility.Visible; MouseIsSelecting = true; if (selWidth > 5) {//forwards selection SelectionRect.Margin = new Thickness(MouseDownInClipPoint.X + MsecToPixelsZoomed(thisClip.ClipRelativeLoopStartMs), 0, 0, 0); SelectionRect.Width = Math.Max(5, selWidth); } else { //backwards selection SelectionRect.Margin = new Thickness(e.GetPosition(this).X + MsecToPixelsZoomed(thisClip.ClipRelativeLoopStartMs), 0, 0, 0); SelectionRect.Width = Math.Max(5, Math.Abs(selWidth)); } return; } } MouseOverClipUnitRight = (posx <= actualWidth) && (posx > actualWidth - 5); MouseOverClipUnitLeft = (posx >= 0) && (posx < 5); if (MouseOverClipUnitRight | MouseOverClipUnitLeft | MouseDownOnClipUnitLeft | MouseDownOnClipUnitRight) Cursor = Cursors.SizeWE; else Cursor = Cursors.Arrow; } }