using QuikDawEditor.EditingClasses; using QuikDawEditor.Undo; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Input; using static QuikDawEditor.EDITING.ShorcutKeys; using static QuikDawEditor.EDITING.MiscMethods; using static QuikDawEditor.EDITING.MidiMethods; using static QuikDawEditor.EDITING.StaticProperties; using QuikDawEditor.MiscClasses; namespace QuikDawEditor { public partial class EditingControl { UserCommandKeyPair AddNewAudioTrackUCKP { get { return userCommandKeyPairs.Where(uckp => uckp.CommandName == "AddNewAudioTrack").FirstOrDefault(); } } UserCommandKeyPair AddNewMidiTrackUCKP { get { return userCommandKeyPairs.Where(uckp => uckp.CommandName == "AddNewMidiTrack").FirstOrDefault(); } } UserCommandKeyPair QuantizeClipsUCKP { get { return userCommandKeyPairs.Where(uckp => uckp.CommandName == "Quantize").FirstOrDefault(); } } private void edControl_PreviewKeyDown(object sender, KeyEventArgs e) { if (HotKeysDisabled) return; if (EdPianoRoll.IsFocused) return; //Check for shorcut keys if (QuantizeClipsUCKP?.shortcutKey == e.Key) if (QuantizeClipsUCKP.modifierKeysMatch(Keyboard.Modifiers)) QuantizeClips_Execute(); if (AddNewAudioTrackUCKP?.shortcutKey == e.Key) if (AddNewAudioTrackUCKP.modifierKeysMatch(Keyboard.Modifiers)) AddNewAudioTrack_Execute(); if (AddNewMidiTrackUCKP?.shortcutKey == e.Key) if (AddNewMidiTrackUCKP.modifierKeysMatch(Keyboard.Modifiers)) AddNewMidiTrack_Execute(); if (Keyboard.IsKeyDown(Key.LeftCtrl) | Keyboard.IsKeyDown(Key.RightCtrl)) { switch (e.Key) { case Key.Home: TracksContentSV.ScrollToHorizontalOffset(0); if (Keyboard.IsKeyDown(Key.LeftCtrl) | Keyboard.IsKeyDown(Key.RightCtrl)) { projPlayer.ChangePlayPos(0); projPlayer.UpdatePlayPosLine(); } e.Handled = true; break; case Key.End: TracksContentSV.ScrollToHorizontalOffset(MsecToPixels(editingProject.projectEndPointMs)); e.Handled = true; break; case Key.P: if (Keyboard.IsKeyDown(Key.LeftShift)) TracksContentSV.ScrollToHorizontalOffset(MsecToPixels(projPlayer.CurrentPlayingPosMS) * editingProject.ViewXZoomFac - 500); e.Handled = true; break; case Key.Delete: List allSelectedClips = editingProject.GetAllSelectedClips; if (allSelectedClips.Count > 0) { if (MessageBox.Show("Delete " + allSelectedClips.Count.ToString() + " clip" + (allSelectedClips.Count > 0 ? "s" : "") + "?", "Delete clip(s)", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes, MessageBoxOptions.DefaultDesktopOnly) == MessageBoxResult.No) return; List DeletedTrackIDs = new List(); List DeletedClipJsonStrings = new List(); List DeletedClipsIndexes = new List(); foreach (Clip delClip in allSelectedClips) { DeletedClipJsonStrings.Add(GetJsonForClip(delClip)); DeletedClipsIndexes.Add(delClip.myTrack.Clips.IndexOf(delClip)); DeletedTrackIDs.Add(delClip.myTrack.UndoTrackID); delClip.myTrack.RemoveAndDisposeClip(delClip); if (editingProject.pianoRoll.myClip == delClip) editingProject.pianoRoll.myClip = null; } undoActions.Add(new DeleteSelectedClipsUndo(DeletedTrackIDs, DeletedClipsIndexes, DeletedClipJsonStrings)); } e.Handled = true; editingProject.NeedsSaving = true; break; } } } internal void PerformUndo() { if (!IsUndoing) //Prevent overlapping undos { if (undoActions.Count > 0) { IInputElement focusedControl = Keyboard.FocusedElement; if (projPlayer.IsProjectPlaying && undoActions.Last().PreventWhilePlaying) { InfoText = "Cannot undo while playing"; return; } if (undoActions.Last().IsLongUndoAction) ShowProcessingMessage("Undoing...\n" + undoActions.Last().GetType().ToString().Replace("SharedClasses.", "").Replace("Undo", "")); Dispatcher.InvokeAsync(() => { IsUndoing = true; try { undoActions.Last().Undo(); undoActions.RemoveAt(undoActions.Count - 1); } catch { } HideProcessingMessage(); IsUndoing = false; editingProject.NeedsSaving = true; focusedControl?.Focus(); }, System.Windows.Threading.DispatcherPriority.Background); } } } private void AddNewAudioTrack_Execute() { Track newAudioTrack = new Track(TrackType.Audio) { TrackName = "New audio track" }; editingProject.Tracks.Add(newAudioTrack); undoActions.Add(new TrackAddUndo(newAudioTrack.UndoTrackID)); editingProject.NeedsSaving = true; } private void AddNewMidiTrack_Execute() { AddNewMidiTrackToProject(); } private void QuantizeClips_Execute() { if (editingProject.GetSelectedMidiClips.Count == 0) { MessageBox.Show("No clips selected", "", MessageBoxButton.OK, MessageBoxImage.Exclamation, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); return; } QuantizeWindow qWin = new QuantizeWindow() { Owner = App.Current.MainWindow, ShowInTaskbar = false }; qWin.ShowDialog(); if (qWin.Result == "Ok") { foreach (Clip c in editingProject.GetSelectedMidiClips) QuantizeMidiNotes(c, c.ClipMidiEvents, qWin.snapTo, (bool)qWin.QuantizeNoteStartsCB.IsChecked, (bool)qWin.QuantizeNoteLengthsCB.IsChecked, (bool)qWin.ApplySwingCB.IsChecked); } } } }