private Intermediate CutNoteByBar(Intermediate src) { try { foreach (Track track in src.TrackList) { LinkedListNode <NoteRest> noteNode = track.NotesList[0].NoteList.First; for (; noteNode != null; noteNode = noteNode.Next) { NoteRest nr = noteNode.Value; if (nr.Start.Bar < nr.End.Bar && (nr.End.Bar != nr.Start.Bar + 1 || nr.End.Tick != 0)) { NoteRest newNr; var newPos = new Position(nr.Start.Bar + 1, 0); if (nr is Note) { var note = (Note)nr; newNr = new Note(newPos.Clone(), note.End.Clone(), note.KeyNumber, note.Velocity); } else { var rest = (Rest)nr; newNr = new Rest(newPos.Clone(), rest.End.Clone()); } track.NotesList[0].NoteList.AddAfter(noteNode, newNr); nr.End = newPos.Clone(); nr.TieFlag = true; } } } return(src); } catch (Exception ex) { throw new Exception(Resources.ErrorModifierCutByBar, ex); } }
private Intermediate CutNoteByControlCommands(Intermediate src) { try { foreach (Track track in src.TrackList) { LinkedListNode <NoteRest> noteNode = track.NotesList[0].NoteList.First; if (src.TrackList.IndexOf(track) == 0) { LinkedListNode <Tempo> tempoNode = src.TempoList.First; while (tempoNode != null) { NoteRest curNote = noteNode.Value; Tempo curTempo = tempoNode.Value; if (curNote.End.CompareTo(curTempo.Position) <= 0) { noteNode = noteNode.Next; continue; } if (curNote.Start.CompareTo(curTempo.Position) < 0) { NoteRest newNote; if (curNote is Note) { var nt = (Note)curNote; newNote = new Note(curTempo.Position.Clone(), nt.End.Clone(), nt.KeyNumber, nt.Velocity); } else { var rst = (Rest)curNote; newNote = new Rest(curTempo.Position.Clone(), rst.End.Clone()); } track.NotesList[0].NoteList.AddAfter(noteNode, newNote); curNote.End = curTempo.Position.Clone(); curNote.TieFlag = true; } tempoNode = tempoNode.Next; } } noteNode = track.NotesList[0].NoteList.First; LinkedListNode <Instrument> instNode = track.InstrumentList.First; while (instNode != null) { NoteRest curNote = noteNode.Value; Instrument curInst = instNode.Value; if (curNote.End.CompareTo(curInst.Position) <= 0) { noteNode = noteNode.Next; continue; } if (curNote.Start.CompareTo(curInst.Position) < 0) { NoteRest newNote; if (curNote is Note) { var nt = (Note)curNote; newNote = new Note(curInst.Position.Clone(), nt.End.Clone(), nt.KeyNumber, nt.Velocity); } else { var rst = (Rest)curNote; newNote = new Rest(curInst.Position.Clone(), rst.End.Clone()); } track.NotesList[0].NoteList.AddAfter(noteNode, newNote); curNote.End = curInst.Position.Clone(); curNote.TieFlag = true; } instNode = instNode.Next; } noteNode = track.NotesList[0].NoteList.First; LinkedListNode <Volume> volNode = track.VolumeList.First; while (volNode != null) { NoteRest curNote = noteNode.Value; Volume curVol = volNode.Value; if (curNote.End.CompareTo(curVol.Position) <= 0) { noteNode = noteNode.Next; continue; } if (curNote.Start.CompareTo(curVol.Position) < 0) { NoteRest newNote; if (curNote is Note) { var nt = (Note)curNote; newNote = new Note(curVol.Position.Clone(), nt.End.Clone(), nt.KeyNumber, nt.Velocity); } else { var rst = (Rest)curNote; newNote = new Rest(curVol.Position.Clone(), rst.End.Clone()); } track.NotesList[0].NoteList.AddAfter(noteNode, newNote); curNote.End = curVol.Position.Clone(); curNote.TieFlag = true; } volNode = volNode.Next; } noteNode = track.NotesList[0].NoteList.First; LinkedListNode <Pan> panNode = track.PanList.First; while (panNode != null) { NoteRest curNote = noteNode.Value; Pan curPan = panNode.Value; if (curNote.End.CompareTo(curPan.Position) <= 0) { noteNode = noteNode.Next; continue; } if (curNote.Start.CompareTo(curPan.Position) < 0) { NoteRest newNote; if (curNote is Note) { var nt = (Note)curNote; newNote = new Note(curPan.Position.Clone(), nt.End.Clone(), nt.KeyNumber, nt.Velocity); } else { var rst = (Rest)curNote; newNote = new Rest(curPan.Position.Clone(), rst.End.Clone()); } track.NotesList[0].NoteList.AddAfter(noteNode, newNote); curNote.End = curPan.Position.Clone(); curNote.TieFlag = true; } panNode = panNode.Next; } } return(src); } catch (Exception ex) { throw new Exception(Resources.ErrorModifierCutByCommands, ex); } }
private void DeleteInvalidControlCommands(Intermediate src, List <CommandPartSet> partSet) { try { int i = 0; foreach (Track track in src.TrackList) { LinkedListNode <NoteRest> noteNode = track.NotesList[0].NoteList.First; var newInstrumentSetList = new LinkedList <ChangeEventSet>(); LinkedListNode <ChangeEventSet> instNode = partSet[i].InstrumentSetList.First; while (noteNode != null && instNode != null) { NoteRest curNote = noteNode.Value; ChangeEventSet curInst = instNode.Value; if (curNote.End.CompareTo(curInst.Position) <= 0) { noteNode = noteNode.Next; continue; } if (curNote is Rest) { if (instNode.Next != null) { if (instNode.Next.Value.Position.CompareTo(curNote.End) > 0) { newInstrumentSetList.AddLast(curInst); } } else { if (noteNode.Next != null) { newInstrumentSetList.AddLast(curInst); } } } else { newInstrumentSetList.AddLast(curInst); } instNode = instNode.Next; } partSet[i].InstrumentSetList = newInstrumentSetList; noteNode = track.NotesList[0].NoteList.First; var newVolumeSetList = new LinkedList <ChangeEventSet>(); LinkedListNode <ChangeEventSet> volNode = partSet[i].VolumeSetList.First; while (noteNode != null && volNode != null) { NoteRest curNote = noteNode.Value; ChangeEventSet curVol = volNode.Value; if (curNote.End.CompareTo(curVol.Position) <= 0) { noteNode = noteNode.Next; continue; } if (curNote is Rest) { if (volNode.Next != null) { if (volNode.Next.Value.Position.CompareTo(curNote.End) > 0) { newVolumeSetList.AddLast(curVol); } } else { if (noteNode.Next != null) { newVolumeSetList.AddLast(curVol); } } } else { newVolumeSetList.AddLast(curVol); } volNode = volNode.Next; } partSet[i].VolumeSetList = newVolumeSetList; noteNode = track.NotesList[0].NoteList.First; var newPansetList = new LinkedList <ChangeEventSet>(); LinkedListNode <ChangeEventSet> panNode = partSet[i].PanSetList.First; while (noteNode != null && panNode != null) { NoteRest curNote = noteNode.Value; ChangeEventSet curPan = panNode.Value; if (curNote.End.CompareTo(curPan.Position) <= 0) { noteNode = noteNode.Next; continue; } if (curNote is Rest) { if (panNode.Next != null) { if (panNode.Next.Value.Position.CompareTo(curNote.End) > 0) { newPansetList.AddLast(curPan); } } else { if (noteNode.Next != null) { newPansetList.AddLast(curPan); } } } else { newPansetList.AddLast(curPan); } panNode = panNode.Next; } partSet[i].PanSetList = newPansetList; i++; } } catch (Exception ex) { throw new Exception(Resources.ErrorModifierRemoveUselessCommands, ex); } }