namespace QuikDawEditor; public partial class EditingControl : UserControl, INotifyPropertyChanged { public delegate void CoverMessageHandler(string messageText); public event CoverMessageHandler CoverMessageInvoked; public delegate void MarkersCBSelectionChangedHandler(int selindex); public event MarkersCBSelectionChangedHandler MarkersCBSelectionChanged; public string RelRes() { ReleaseResources(); return "Resources released"; } public EditingControl() { InitializeComponent(); if (Settings.Default.ErrorProducingVsts == null) Settings.Default.ErrorProducingVsts = new System.Collections.Specialized.StringCollection(); if (Settings.Default.SkipLoadingPlugins == null) Settings.Default.SkipLoadingPlugins = new System.Collections.Specialized.StringCollection(); } private void edControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { ClipSelectionRectangle.DataContext = projPlayer.ClipSelectionRect; } public event PropertyChangedEventHandler PropertyChanged; public void NotifyPropertyChanged([CallerMemberName] String propertyName = "") { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } private double _RecordedTracksBorderHeight = 20; public double RecordedTracksBorderHeight { get { return _RecordedTracksBorderHeight; } set { _RecordedTracksBorderHeight = value; NotifyPropertyChanged(nameof(RecordedTracksBorderHeight)); } } public double TracksAreaMinWidth { get { return TracksFullWidthDP.ActualWidth / editingProject.ViewXZoomFac; } } public void UpdateTracksAreaMinWidth() { NotifyPropertyChanged(nameof(TracksAreaMinWidth)); } private double maxZoomFac = 99; internal Task NullAsync() { return Task.CompletedTask; } internal void HorizontalZoomMainTracks(int eDeltaSign) { projPlayer.IsZooming = true; double prevCursorMs = PixelsToMsec(Mouse.GetPosition(TrackContentControlsIC).X); double increm = Math.Log(editingProject.ViewXZoomFac) / 2.5 + 0.65; if (Keyboard.IsKeyDown(Key.LeftCtrl)) increm = maxZoomFac; //max increm = Math.Round(eDeltaSign * increm, 2); editingProject.ViewXZoomFac = Math.Round(Math.Max(0.20, Math.Min(maxZoomFac, editingProject.ViewXZoomFac + increm)), 3); //__________________Update UI from new XZoomFac_____________________ UpdateTracksAreaMinWidth(); projPlayer.UpdatePlayPosLine(); UpdateElementsFromZoomX(); LeftFillerLabel.Text = "Zoom: x" + Math.Round(editingProject.ViewXZoomFac, editingProject.ViewXZoomFac < 1 ? 1 : 0).ToString(); //_________________________________________________________________ TracksContentSV.ScrollToHorizontalOffset(MsecToPixels(prevCursorMs) * editingProject.ViewXZoomFac - Mouse.GetPosition(TracksContentSV).X); ////CAUSES STATIC BUT SYNCHRONIZES AUDIO WHEN ZOOMING //projPlayer.bufferedSampleProvider.ClearBuffer(); projPlayer.IsZooming = false; } private void UpdateElementsFromZoomX() { editingProject.UpdateProjectEndPointMarker(); editingProject.UpdateProjectGridLines(); //Redraw smallest unit of main tracks gridlines that are tiled as background playGridHeader.UpdateGridVisual(); //Redraw the top grid with nos. editingProject.UpdateLoopRange(); foreach (Marker m in editingProject.Markers) m.UpdateMarker(); foreach (LyricLine l in editingProject.LyricLines) l.UpdateLyricLine(); StartingBookmarkEllipse.Margin = new Thickness(MsecToPixels((double)editingProject.StartingBookmarkMs) * editingProject.ViewXZoomFac, 0, 0, 0); List allTracks = editingProject.GetAllTracksInProject; for (int trackno = 0; trackno < allTracks.Count; trackno++) { foreach (Clip cc in allTracks[trackno].Clips) { cc.UpdateClipZoom(); //****causes glitching cc.NotifyGainPointsChanged(); if (cc.IsMidiClip) cc.UpdateMidiImageSource(); } foreach (AutomationLane autoLane in allTracks[trackno].AutomationLanes) { autoLane.ReverseTransformFactorX = 1 / editingProject.ViewXZoomFac; autoLane.SetAutoPointLayoutTransform(); } } //Master track automation lanes foreach (AutomationLane autoLane in editingProject.MasterTrack.AutomationLanes) { autoLane.ReverseTransformFactorX = 1 / editingProject.ViewXZoomFac; autoLane.SetAutoPointLayoutTransform(); } editingProject.clipFloatCanvas.scaleTransformX = 1 / editingProject.ViewXZoomFac; } public void ResetVisual() { editingProject.ViewXZoomFac = 1; TrackContentControlsIC.LayoutTransform = new ScaleTransform(1, 1); LeftFillerLabel.Text = "Zoom: x1"; } internal bool dontUpdateScroll = false; private void TracksContentSV_ScrollChanged(object sender, ScrollChangedEventArgs e) { ScaleBarSV.ScrollToHorizontalOffset(TracksContentSV.HorizontalOffset); TrackControlsAreaDP.Margin = new Thickness(0, -TracksContentSV.VerticalOffset, 0, 0); if (editingProject != null) editingProject.TracksContentSVVerticalOffset = TracksContentSV.VerticalOffset; //if (!dontUpdateScroll) TracksContentSVHorizontalScrollOffset = TracksContentSV.HorizontalOffset; } private void TracksContentGrid_SizeChanged(object sender, SizeChangedEventArgs e) { TracksViewingWidthPixels = TracksContentGrid.ActualWidth; //Debug.WriteLine("trackscontentgrid size change=" + TracksViewingWidthPixels.ToString()); } private void AddMarkerMenuItem_Click(object sender, RoutedEventArgs e) { InputBox inBox = new InputBox("New section name") { Owner = Application.Current.MainWindow }; inBox.ShowDialog(); if (inBox.Result == "Cancel") return; Marker newmarker = new Marker() { timePosMs = GetNearestSnapMs((int)PixelsToMsecZoomed(MouseDownOnArrangerBarX), editingProject.CurrentSnapTo) }; newmarker.Name = inBox.TextBoxText; Marker insertBeforeMarker = editingProject.Markers.FirstOrDefault(m => m.timePosMs >= newmarker.timePosMs); int insertIdx = insertBeforeMarker == null ? editingProject.Markers.Count : editingProject.Markers.IndexOf(insertBeforeMarker); editingProject.Markers.Insert(insertIdx, newmarker); editingProject.NeedsSaving = true; } private void TrackContentControl_ChildClipMoved(double mousePosX) { projPlayer.AutoScrollingOn = true; if (mousePosX < TracksContentSV.HorizontalOffset) TracksContentSV.ScrollToHorizontalOffset(mousePosX); if (mousePosX > TracksContentSV.HorizontalOffset + TracksContentSV.ActualWidth + 200) TracksContentSV.ScrollToHorizontalOffset(mousePosX - TracksContentSV.ActualWidth + 200); projPlayer.AutoScrollingOn = false; } private void ScaleBarSV_PreviewKeyDown(object sender, KeyEventArgs e) { e.Handled = true; } private void TrackControl_Loaded(object sender, RoutedEventArgs e) { TrackControlsIC.Height = Math.Min(TrackControlsSV.Height - 20, TrackControlsIC.Items.Count * 80); } private void MasterTrackToggleBut_Click(object sender, RoutedEventArgs e) { editingProject.MasterTrack.IsTrackCollapsed = !editingProject.MasterTrack.IsTrackCollapsed; undoActions.Add(new MasterTrackShowHideUndo()); editingProject.NeedsSaving = true; } private void TrackControlsSV_PreviewMouseWheel(object sender, MouseWheelEventArgs e) { e.Handled = true; TracksContentSV.ScrollToVerticalOffset(TracksContentSV.VerticalOffset - e.Delta); } private void ToggleAllTracksYScaleBut_Click(object sender, RoutedEventArgs e) { double newYScale = editingProject.MasterTrack.TrackYScale == 1 ? 0.7 : 1; editingProject.MasterTrack.TrackYScale = newYScale; foreach (Track t in editingProject.GetAllTracksInProject) t.TrackYScale = newYScale; editingProject.NeedsSaving = true; } private void TracksContentSV_SizeChanged(object sender, SizeChangedEventArgs e) { if (editingProject == null) return; editingProject.projectEndPointMs = Math.Max(editingProject.projectEndPointMs, PixelsToMsec(TracksContentSV.ActualWidth)); } private void SetRecInBut_Click(object sender, RoutedEventArgs e) { RecordInputsCM.DataContext = editingProject; RecordInputsCM.IsOpen = true; } private void AddNewMidiTrackBut_Click(object sender, RoutedEventArgs e) { AddNewMidiTrack_Execute(); } private void AddNewSubMixTrackBut_Click(object sender, RoutedEventArgs e) { Track newSubmixtrack = new Track(TrackType.Submix) { TrackName = "New submix track" }; editingProject.Tracks.Add(newSubmixtrack); undoActions.Add(new TrackAddUndo(newSubmixtrack.UndoTrackID)); } private void AddNewAudioTrackBut_Click(object sender, RoutedEventArgs e) { AddNewAudioTrack_Execute(); } private void AddNewTrackBut_Click(object sender, RoutedEventArgs e) { AddNewTrackCM.IsOpen = true; } Marker currentMarker = null; private void RenameMarkerMenuItem_Click(object sender, RoutedEventArgs e) { InputBox inputBox = new InputBox("Section name", currentMarker.Name); inputBox.ShowDialog(); if (inputBox.Result == "Ok") { undoActions.Add(new ArrangeMarkerNameChangeUndo(editingProject.Markers.IndexOf(currentMarker), currentMarker.Name)); currentMarker.Name = inputBox.TextBoxText; editingProject.NeedsSaving = true; } } private void DeleteMarkerMenuItem_Click(object sender, RoutedEventArgs e) { undoActions.Add(new ArrangeMarkerDeleteUndo(editingProject.Markers.IndexOf(currentMarker), currentMarker.Name, currentMarker.timePosMs, currentMarker.widthMs, currentMarker.markerBackground)); editingProject.Markers.Remove(currentMarker); editingProject.NeedsSaving = true; } private void ClipGainSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { if (editingProject.GainAdjustingClip == null) return; editingProject.GainAdjustingClip.ClipGainFactor = (float)Math.Pow(Math.E, e.NewValue); } private void ClipGainSlider_LostFocus(object sender, RoutedEventArgs e) { editingProject.ClipGainSliderVisibility = Visibility.Hidden; } private void OpenLyricEditorMenuItem_Click(object sender, RoutedEventArgs e) { //editingProject.lyricWindow.Visibility = Visibility.Visible; editingProject.IsLyricEditorVisible = true; projPlayer.lyricWindow.Activate(); projPlayer.lyricWindow.myRTB.Focus(); } List GetContainedClips(Rect msRect) { return editingProject.GetAllClips.Where(c => c.ClipLeftMs > msRect.Left && c.ClipRightMs < msRect.Right && c.CalculateClipTopPix + c.ClipAreaHeight < msRect.Bottom && c.CalculateClipTopPix + 45 > msRect.Top ).ToList(); } private void ShowLyricLaneBut_Click(object sender, RoutedEventArgs e) { editingProject.IsLyricBarVisible = !editingProject.IsLyricBarVisible; editingProject.NeedsSaving = true; } }