Skip to content

Commit

Permalink
Merge pull request stakira#916 from oxygen-dioxide/note-overlapping-fix
Browse files Browse the repository at this point in the history
Editing macro: fix overlapping notes
  • Loading branch information
stakira authored Nov 14, 2023
2 parents 01a96a1 + f0a87f1 commit 34fafe4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
40 changes: 40 additions & 0 deletions OpenUtau.Core/Editing/NoteBatchEdits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,46 @@ public void Run(UProject project, UVoicePart part, List<UNote> selectedNotes, Do
}
}

public class FixOverlap: BatchEdit {
/// <summary>
/// Fix overlapping notes.
/// If multiple notes start at the same time, only the one with the highest tone will be kept
/// If one notes's end is overlapped by another note, the end will be moved to the start of the next note
/// </summary>
public virtual string Name => name;

private string name;

public FixOverlap() {
name = $"pianoroll.menu.notes.fixoverlap";
}

public void Run(UProject project, UVoicePart part, List<UNote> selectedNotes, DocManager docManager) {
var notes = selectedNotes.Count > 0 ? selectedNotes : part.notes.ToList();
if(notes.Count == 0){
return;
}
docManager.StartUndoGroup();
var currentNote = notes[0];
foreach(var note in notes.Skip(1)){
if(note.position == currentNote.position){
if(note.tone > currentNote.tone){
docManager.ExecuteCmd(new RemoveNoteCommand(part, currentNote));
currentNote = note;
}else{
docManager.ExecuteCmd(new RemoveNoteCommand(part, note));
}
}else if(note.position < currentNote.End){
docManager.ExecuteCmd(new ResizeNoteCommand(part, currentNote, note.position - currentNote.End));
currentNote = note;
}else{
currentNote = note;
}
}
docManager.EndUndoGroup();
}
}

public class HanziToPinyin : BatchEdit {
public virtual string Name => name;

Expand Down
3 changes: 2 additions & 1 deletion OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,17 @@ Warning: this option removes custom presets.</system:String>
<system:String x:Key="pianoroll.menu.notes">Notes</system:String>
<system:String x:Key="pianoroll.menu.notes.addtaildash">Add tail "-"</system:String>
<system:String x:Key="pianoroll.menu.notes.addtailrest">Add tail "R"</system:String>
<system:String x:Key="pianoroll.menu.notes.autolegato">Auto Legato</system:String>
<system:String x:Key="pianoroll.menu.notes.bakepitch">Convert PITD to pitch control points</system:String>
<system:String x:Key="pianoroll.menu.notes.clear.vibratos">Clear vibratos</system:String>
<system:String x:Key="pianoroll.menu.notes.fixoverlap">Fix overlapping notes</system:String>
<system:String x:Key="pianoroll.menu.notes.hanzitopinyin">Hanzi to pinyin</system:String>
<system:String x:Key="pianoroll.menu.notes.lengthencrossfade">Lengthen crossfades</system:String>
<system:String x:Key="pianoroll.menu.notes.loadrenderedpitch">Load rendered pitch</system:String>
<system:String x:Key="pianoroll.menu.notes.octavedown">Move an octave down</system:String>
<system:String x:Key="pianoroll.menu.notes.octaveup">Move an octave up</system:String>
<system:String x:Key="pianoroll.menu.notes.quantize15">Quantize to 1/128</system:String>
<system:String x:Key="pianoroll.menu.notes.quantize30">Quantize to 1/64</system:String>
<system:String x:Key="pianoroll.menu.notes.autolegato">Auto Legato</system:String>
<system:String x:Key="pianoroll.menu.notes.reset.aliases">Reset phoneme aliases</system:String>
<system:String x:Key="pianoroll.menu.notes.reset.exps">Reset all expressions</system:String>
<system:String x:Key="pianoroll.menu.notes.reset.phonemetimings">Reset phoneme timings</system:String>
Expand Down
1 change: 1 addition & 0 deletions OpenUtau/ViewModels/PianoRollViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public PianoRollViewModel() {
new QuantizeNotes(15),
new QuantizeNotes(30),
new AutoLegato(),
new FixOverlap(),
new HanziToPinyin(),
new ResetPitchBends(),
new ResetAllExpressions(),
Expand Down

0 comments on commit 34fafe4

Please sign in to comment.