using NAudio.Midi; using QuikDawEditor.EditingClasses; using QuikDawEditor.Undo; using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using static QuikDawEditor.EDITING.MiscMethods; using static QuikDawEditor.EDITING.MidiMethods; using static QuikDawEditor.EDITING.AudioMethods; using static QuikDawEditor.EDITING.StaticProperties; using static QuikDawEditor.EDITING.VstMethods; using QuikDawEditor.VST; namespace QuikDawEditor; public partial class EditingControl { private void TracksContentSV_DragOver(object sender, DragEventArgs e) { //Debug.WriteLine("formats:\n" + string.Join("\n", e.Data.GetFormats())); e.Handled = true; e.Effects = DragDropEffects.None; if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); string ext = System.IO.Path.GetExtension(files[0]).ToLower(); if (Regex.IsMatch(ext, @"(\.mp3$|\.wav$|\.mid)")) e.Effects = DragDropEffects.Copy; } else if (e.Data.GetDataPresent("vstfxfavdrag") || e.Data.GetDataPresent("vstfxrefdrag") || e.Data.GetDataPresent("vstifavdrag") || e.Data.GetDataPresent("vstirefdrag")) { e.Effects = DragDropEffects.Copy; } } private void TracksContentSV_Drop(object sender, DragEventArgs e) { //Drop file or clip onto empty part of scrollviewer if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string f in files) { string fileToAdd = f; string ext = Path.GetExtension(fileToAdd).ToLower(); double AddPositionMs = PixelsToMsec(e.GetPosition(TracksContentSV).X + TracksContentSV.HorizontalOffset) / editingProject.ViewXZoomFac; switch (ext) { case ".mp3": case ".wav": AddNewAudioClipToTrack(f, null, AddPositionMs, -1, false, false); break; case ".mid": case ".midi": try { MidiFile mfile = new MidiFile(files[0]); AddMidiTracks(mfile.Events, -1, 0, AddPositionMs, Double.MaxValue); } catch (Exception ex) { MessageBox.Show("Error reading midi...\n" + ex.Message); } break; } } } else if (e.Data.GetDataPresent("vstfxfavdrag")) { VstFavorite thisVSTFav = (VstFavorite)e.Data.GetData("vstfxfavdrag"); VstPluginReference thisVSTRef = thisVSTFav.myPluginRef; if (thisVSTRef != null) { if (thisVSTRef.isNotifying) return; AddNewAudioTrack_Execute(); AddVSTEffect(editingProject.Tracks[editingProject.Tracks.Count - 1], thisVSTRef); editingProject.NeedsSaving = true; } } else if (e.Data.GetDataPresent("vstfxrefdrag")) { VstPluginReference thisVSTRef = (VstPluginReference)e.Data.GetData("vstfxrefdrag"); if (thisVSTRef != null) { if (thisVSTRef.isNotifying) return; AddNewAudioTrack_Execute(); AddVSTEffect(editingProject.Tracks[editingProject.Tracks.Count - 1], thisVSTRef); editingProject.NeedsSaving = true; } } else if (e.Data.GetDataPresent("vstifavdrag")) { VstFavorite thisVSTFav = (VstFavorite)e.Data.GetData("vstifavdrag"); VstPluginReference thisVSTRef = thisVSTFav.myPluginRef; if (thisVSTRef != null) { if (thisVSTRef.isNotifying) return; AddNewMidiTrack_Execute(); Track addedMidiTrack = editingProject.Tracks[editingProject.Tracks.Count - 1]; addedMidiTrack.TrackInstrumentVsts.Clear(); AddVSTInstrument(addedMidiTrack, thisVSTRef); editingProject.NeedsSaving = true; } } else if (e.Data.GetDataPresent("vstirefdrag")) { VstPluginReference thisVSTRef = (VstPluginReference)e.Data.GetData("vstirefdrag"); if (thisVSTRef != null) { if (thisVSTRef.isNotifying) return; AddNewMidiTrack_Execute(); Track addedMidiTrack = editingProject.Tracks[editingProject.Tracks.Count - 1]; addedMidiTrack.TrackInstrumentVsts.Clear(); AddVSTInstrument(addedMidiTrack, thisVSTRef); editingProject.NeedsSaving = true; } } else if (e.Data.GetDataPresent("clipdrag")) { //move/copy clip from track to new fresh track } } private void TrackControl_DragOver(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.StringFormat) && e.Data.GetData(DataFormats.StringFormat).ToString() == "clipdrag") { Point cpoint = e.GetPosition(TrackControlsAreaDP); editingProject.clipFloatCanvas.Top = cpoint.Y; e.Effects = DragDropEffects.None; e.Handled = true; return; } } private void FloatImage_DragOver(object sender, DragEventArgs e) { Image thisImg = (Image)sender; e.Handled = true; e.Effects = DragDropEffects.Move; Point thisPos = e.GetPosition(this); editingProject.trackFloatCanvas.Top = thisPos.Y; editingProject.trackFloatCanvas.Left = 3; } private void FloatImage_Drop(object sender, DragEventArgs e) { editingProject.TrackDropCompleted(); } private void TrackContentControlsIC_PreviewDragOver(object sender, DragEventArgs e) { //Debug.WriteLine("formats:\n" + string.Join("\n", e.Data.GetFormats())); if (e.Data.GetDataPresent(DataFormats.StringFormat) && e.Data.GetData(DataFormats.StringFormat).ToString() == "clipdrag") { Point cpoint = e.GetPosition(TrackContentControlsIC); editingProject.clipFloatCanvas.Left = cpoint.X; editingProject.clipFloatCanvas.Top = cpoint.Y - editingProject.clipFloatCanvas.offsetPoint.Y; editingProject.clipFloatCanvas.sourceClip.IsVisible = Keyboard.IsKeyDown(Key.LeftCtrl); } } private void MasterTrackContentControl_PreviewDragOver(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.StringFormat) && e.Data.GetData(DataFormats.StringFormat).ToString() == "clipdrag") { Point cpoint = e.GetPosition(TracksAreaDP); editingProject.clipFloatCanvas.Left = cpoint.X * editingProject.ViewXZoomFac; } } private void TrackContentControlBottomBorder_DragOver(object sender, DragEventArgs e) { e.Effects = DragDropEffects.None; } private void WinFormsLabel_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) { //Debug.WriteLine("eY= " + e.Y.ToString()); if (e.Data.GetData("FileDrop") != null) { e.Effect = System.Windows.Forms.DragDropEffects.Copy; dropFile = ((string[])e.Data.GetData("FileDrop"))[0]; } } Track hoveringDropTrack; string dropFile; double dropPointMs; private void WinFormsLabel_DragOver(object sender, System.Windows.Forms.DragEventArgs e) { double relEY = (double)e.Y / dpiYFac + TracksContentSV.VerticalOffset; double relEX = (double)e.X / dpiXFac; List allTracks = editingProject.GetAllTracksInProject; hoveringDropTrack = allTracks.FirstOrDefault(t => t.GetActualTrackTop + 210 < relEY && t.GetActualTrackTop + t.GetActualTrackHeight + 190 > relEY); if (hoveringDropTrack != null && hoveringDropTrack.IsAudioTrack) e.Effect = System.Windows.Forms.DragDropEffects.Copy; else e.Effect = System.Windows.Forms.DragDropEffects.None; dropPointMs = PixelsToMsecZoomed(relEX - 200 + TracksContentSV.HorizontalOffset); } private void WinFormsLabel_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { if (hoveringDropTrack != null && dropFile != "") AddNewAudioClipToTrack(dropFile, hoveringDropTrack, dropPointMs, -1); hoveringDropTrack = null; dropFile = ""; WaveLoopDropForm.Visibility = Visibility.Collapsed; LeftDP.IsEnabled = true; TracksContentSV.IsEnabled = true; ScaleBarSV.IsEnabled = true; ((EditorWindow)App.Current.MainWindow).ControlsDP.IsEnabled = true; ((EditorWindow)App.Current.MainWindow).MarkersCB.IsEnabled = true; ((EditorWindow)App.Current.MainWindow).MenuDP.IsEnabled = true; } }