void SetSustain(uint length) { List <ActionHistory.Action> actions = new List <ActionHistory.Action>(); uint songEndTick = editor.currentSong.TimeToTick(editor.currentSong.length, editor.currentSong.resolution); foreach (ChartObject chartObject in editor.currentSelectedObjects) { if (chartObject.classID == (int)SongObject.ID.Note) { Note note = chartObject as Note; uint assignedLength = length; if (length == uint.MaxValue) { assignedLength = songEndTick - note.tick; } if (GameSettings.extendedSustainsEnabled) { Note original = (Note)note.Clone(); note.length = assignedLength; note.CapSustain(note.FindNextSameFretWithinSustainExtendedCheck()); if (original.length != note.length) { actions.Add(new ActionHistory.Modify(original, note)); } } else { // Needs to handle chords Note[] chordNotes = note.GetChord(); Note[] chordNotesCopy = new Note[chordNotes.Length]; Note capNote = note.nextSeperateNote; for (int i = 0; i < chordNotes.Length; ++i) { chordNotesCopy[i] = (Note)chordNotes[i].Clone(); chordNotes[i].length = assignedLength; chordNotes[i].CapSustain(capNote); if (chordNotesCopy[i].length != chordNotes[i].length) { actions.Add(new ActionHistory.Modify(chordNotesCopy[i], chordNotes[i])); } } } } } if (actions.Count > 0) { editor.actionHistory.Insert(actions.ToArray()); } ChartEditor.isDirty = true; }
public static void CapSustain(this Note note, Song song, bool extendedSustainsEnabled) { Note nextFret; nextFret = note.FindNextSameFretWithinSustainExtendedCheck(extendedSustainsEnabled); if (nextFret != null) { note.CapSustain(nextFret, song); } }
protected static ActionHistory.Action[] ForwardCap(Note note) { List <ActionHistory.Action> actionRecord = new List <ActionHistory.Action>(); Note next; next = note.nextSeperateNote; if (!GameSettings.extendedSustainsEnabled) { // Get chord next = note.nextSeperateNote; if (next != null) { foreach (Note noteToCap in note.chord) { ActionHistory.Action action = noteToCap.CapSustain(next); if (action != null) { actionRecord.Add(action); } } } } else { // Find the next note of the same fret type or open next = note.next; while (next != null && next.guitarFret != note.guitarFret && !next.IsOpenNote()) { next = next.next; } // If it's an open note it won't be capped if (next != null) { ActionHistory.Action action = note.CapSustain(next); if (action != null) { actionRecord.Add(action); } } } return(actionRecord.ToArray()); }
void GenerateSustainDragCommands(bool compareWithOriginal) { if (nCon.note.song == null || Input.GetMouseButton(0) || initialDraggingSnappedPos.HasValue) { return; } uint snappedPos = GetSnappedSustainPos(); sustainDragCommands.Clear(); Song song = editor.currentSong; bool extendedSustainsEnabled = GameSettings.extendedSustainsEnabled; bool commandsActuallyChangeData = false; foreach (Note note in originalDraggedNotes) { int pos = SongObjectHelper.FindObjectPosition(note, editor.currentChart.notes); Debug.Assert(pos != SongObjectHelper.NOTFOUND, "Was not able to find note reference in chart"); Note newNote = new Note(note); Note referenceNote = editor.currentChart.notes[pos]; Note capNote = referenceNote.FindNextSameFretWithinSustainExtendedCheck(extendedSustainsEnabled); newNote.SetSustainByPos(snappedPos, song, extendedSustainsEnabled); if (capNote != null) { newNote.CapSustain(capNote, song); } Note lengthComparisionNote = compareWithOriginal ? note : referenceNote; commandsActuallyChangeData |= lengthComparisionNote.length != newNote.length; sustainDragCommands.Add(new SongEditModify <Note>(note, newNote)); } if (!commandsActuallyChangeData) { sustainDragCommands.Clear(); } }
/// <summary> /// Calculates and sets the sustain length based the tick position it should end at. Will be a length of 0 if the note position is greater than the specified position. /// </summary> /// <param name="pos">The end-point for the sustain.</param> public static void SetSustainByPos(this Note note, uint pos) { if (pos > note.tick) { note.length = pos - note.tick; } else { note.length = 0; } // Cap the sustain Note nextFret; nextFret = note.FindNextSameFretWithinSustainExtendedCheck(); if (nextFret != null) { note.CapSustain(nextFret); } }