public MIDIPatternActionMoveNotes(MIDIPatternConnect pattern, IEnumerable <SelectedSNote> notesToMove, double ticks, int keys) : base(pattern)
        {
            Ticks = ticks;
            Keys  = keys;

            NoteLocations = PianoRollPattern.Pattern.GetNoteLocations(notesToMove);
        }
        PerKeyArray <HashSet <int> > MoveNotes(double xOffset, int keyOffset, PerKeyArray <HashSet <int> > selectedNotes)
        {
            var pattern = PianoRollPattern.Pattern;

            var notesToMove = pattern.FetchSelectedNotes(selectedNotes);

            pattern.RemoveSelectedNotes(notesToMove);
            var shiftedNotes = notesToMove.Roll(keyOffset).MapParallel(k =>
            {
                foreach (var n in k)
                {
                    n.Start += xOffset;
                }
                return(k.AsEnumerable());
            });

            pattern.InjectNotes(shiftedNotes);

            var editedSelection = shiftedNotes.ToSelectedSNotes();

            PianoRollPattern.DeselectAllNotes();
            PianoRollPattern.SelectNoteRange(editedSelection);

            return(pattern.GetNoteLocations(shiftedNotes));
        }
Beispiel #3
0
        public PerKeyArray <HashSet <SNote> > FetchSelectedNotes(PerKeyArray <HashSet <int> > selector)
        {
            var rets = PerKeyArray.Create(() => new HashSet <SNote>());

            Parallel.For(0, Constants.KeyCount, i =>
            {
                var select = selector[i];
                var ret    = rets[i];
                var key    = Notes[i];

                foreach (var idx in select)
                {
                    try
                    {
                        ret.Add(key[idx]);
                    }
                    catch
                    {
                        throw new DataIntegrityException("Invalid indexes were passed into the note selection fetcher");
                    }
                }
            });

            return(rets);
        }
Beispiel #4
0
 public void RemoveSelectedNotes(PerKeyArray <HashSet <SNote> > selector)
 {
     Parallel.For(0, Constants.KeyCount, i =>
     {
         var select = selector[i];
         Notes[i]   = Notes[i].Where((n) => !select.Contains(n)).ToList();
     });
 }
Beispiel #5
0
 public void InjectNotes(PerKeyArray <IEnumerable <SNote> > notes)
 {
     Parallel.For(0, Constants.KeyCount, i =>
     {
         var inject = notes[i];
         Notes[i]   = Notes[i].Concat(inject).ToList();
         Notes[i].Sort();
     });
 }
Beispiel #6
0
        public PerKeyArray <HashSet <int> > GetNoteLocations(IEnumerable <SelectedSNote> selection)
        {
            var separatedSelection = PerKeyArray.Create(() => new List <SNote>());

            foreach (var n in selection)
            {
                separatedSelection[n.Key].Add(n.Note);
            }

            return(GetNoteLocations(separatedSelection.Map(k => k.AsEnumerable())));
        }
Beispiel #7
0
        public PerKeyArray <HashSet <int> > GetNoteLocations(PerKeyArray <IEnumerable <SNote> > separatedSelection)
        {
            var locations = PerKeyArray.Create(() => new HashSet <int>());

            Parallel.For(0, Constants.KeyCount, i =>
            {
                var selection    = separatedSelection[i];
                var notes        = Notes[i];
                var locationsKey = locations[i];

                foreach (var s in selection)
                {
                    var idx = notes.IndexOf(s);
                    if (idx == -1)
                    {
                        throw new DataIntegrityException("Invalid notes were passed into the note location finder");
                    }
                    locationsKey.Add(idx);
                }
            });
            return(locations);
        }
 protected override void UndoInternal()
 {
     NoteLocations = MoveNotes(-Ticks, -Keys, NoteLocations);
 }
 protected override void ApplyInternal()
 {
     NoteLocations = MoveNotes(Ticks, Keys, NoteLocations);
 }