namespace QuikDawEditor; public partial class ClipControl { private void SplitThisClip(Clip thisClip, double splitPointMS) { try { Clip newClip = new Clip(thisClip.ClipSourceFileName, thisClip.clipType) { ClipVirtualStartMs = thisClip.ClipVirtualStartMs, ClipRelativeLoopStartMs = splitPointMS - thisClip.ClipVirtualStartMs, ClipSourceLenMilliseconds = thisClip.ClipSourceLenMilliseconds, ClipWidthMs = thisClip.ClipRightMs - splitPointMS, IsLooped = thisClip.IsLooped, IsMuted = thisClip.IsMuted, IsSelected = thisClip.IsSelected, ClipGainFactor = thisClip.ClipGainFactor }; Debug.WriteLine("Created new clip"); //float keepOrigClipEndGainVal = 1; //if (thisClip.ClipEndGainPoint == null) // MessageBox.Show("clipendgainpoint was null!"); //else // keepOrigClipEndGainVal = thisClip.ClipEndGainPoint.GainValue; float keepOrigClipEndGainVal = thisClip.ClipEndGainPoint == null ? 1 : thisClip.ClipEndGainPoint.GainValue; double presplitClipWidthMs = thisClip.ClipWidthMs; thisClip.ClipWidthMs = splitPointMS - thisClip.ClipLeftMs; thisClip.myTrack.Clips.Insert(thisClip.GetIndexInTrack + 1, newClip); thisClip.myTrack.UpdateMyClipsToOwner(); thisClip.SortGainPoints(); float interpolatedGainVal = 1; try { GainPoint prevGainPoint = thisClip.GainPoints.LastOrDefault(gp => gp.sourcePointms < thisClip.ClipRelativeLoopEndMs); GainPoint nextGainPoint = thisClip.GainPoints.FirstOrDefault(gp => gp.sourcePointms > thisClip.ClipRelativeLoopEndMs); if (!(prevGainPoint == null || nextGainPoint == null)) interpolatedGainVal = GetGainValBetweenGainPoints(thisClip.ClipRelativeLoopEndMs, prevGainPoint, nextGainPoint); List leftGPs = thisClip.GainPoints.Where(gp => gp.sourcePointms <= thisClip.ClipRelativeLoopEndMs).ToList(); List rightGPs = thisClip.GainPoints.Where(gp => gp.sourcePointms > thisClip.ClipRelativeLoopEndMs).ToList(); rightGPs.Insert(0, new GainPoint() { sourcePointms = newClip.ClipRelativeLoopStartMs, IsLeftEdgeGainPoint = true, GainValue = interpolatedGainVal }); rightGPs.Add(new GainPoint() { sourcePointms = newClip.ClipRelativeLoopEndMs, IsRightEdgeGainPoint = true, GainValue = keepOrigClipEndGainVal }); //Fill in necessary gain points at edges for split clips thisClip.GainPoints = new ObservableCollection(leftGPs); newClip.GainPoints = new ObservableCollection(rightGPs); thisClip.ClipEndGainPoint.GainValue = interpolatedGainVal; thisClip.NotifyGainPointsChanged(); // Necessary??? newClip.NotifyGainPointsChanged(); } catch (Exception ex) { Debug.WriteLine("Error splitting with gain points\n" + ex.Message); } if (thisClip.IsAudioClip) { newClip.IsReversed = thisClip.IsReversed; thisClip.myTrack.AddClipSampleProviderToClip(newClip); } if (thisClip.IsMidiClip) { foreach (QDMidiNote qmn in thisClip.ClipMidiNotes) newClip.ClipMidiNotes.Add(new QDMidiNote(qmn)); foreach (QDSustain qsus in thisClip.ClipSustainEvents) newClip.ClipSustainEvents.Add(new QDSustain(qsus)); foreach (QDPitchChange qpch in thisClip.ClipPitchChangeEvents) newClip.ClipPitchChangeEvents.Add(new QDPitchChange(qpch)); foreach (QDModulation qmod in thisClip.ClipModulationEvents) newClip.ClipModulationEvents.Add(new QDModulation(qmod)); } Debug.WriteLine("Finished preparing new clips"); editingProject.NeedsSaving = true; undoActions.Add(new ClipSplitUndoClass(thisClip.myTrack.UndoTrackID, newClip.UndoClipID, thisClip.UndoClipID, presplitClipWidthMs, newClip.ClipEndGainPoint.GainValue)); thisClip.myTrack.ResetClips(projPlayer.CurrentPlayingPosMS); } catch (Exception ex) { Debug.WriteLine("Error in changing clip virtual start: clipidx=" + thisClip.GetIndexInTrack.ToString()); } } public void CutOutSelectionToNewClip(double splitPointms1, double splitPointms2) { //try //{ // Clip newClip1 = new Clip(thisClip.ClipSourceFileName) // { // ClipVirtualStartMs = thisClip.ClipVirtualStartMs, // ClipRelativeLoopStartMs = splitPointms1 - thisClip.ClipVirtualStartMs, // ClipSourceLenMilliseconds = thisClip.ClipSourceLenMilliseconds, // ClipWidthMs = thisClip.ClipRightMs - splitPointms1 // }; // thisClip.ClipWidthMs = splitPointms1 - thisClip.ClipLeftMs; // thisClip.myTrack.Clips.Insert(clipIndex + 1, newClip1); // thisClip.myTrack.UpdateClipIndexes(); // float interpolatedGainVal1 = 1; // float interpolatedGainVal2 = 1; // thisClip.SortGainPoints(); // try // { // GainPoint prevGainPoint = thisClip.GainPoints.LastOrDefault(gp => gp.sourcePointms <= splitPointms1); // GainPoint nextGainPoint = thisClip.GainPoints.FirstOrDefault(gp => gp.sourcePointms >= splitPointms1); // if (!(prevGainPoint == null || nextGainPoint == null)) // interpolatedGainVal1 = GetGainValBetweenGainPoints(splitPointms1, prevGainPoint, nextGainPoint); // List leftGPs1 = thisClip.GainPoints.Where(gp => gp.sourcePointms <= thisClip.ClipRelativeLoopEndMs).ToList(); // List rightGPs1 = thisClip.GainPoints.Where(gp => gp.sourcePointms > thisClip.ClipRelativeLoopEndMs).ToList(); // thisClip.GainPoints = new ObservableCollection(leftGPs1); // newClip1.GainPoints = new ObservableCollection(rightGPs1); // thisClip.ClipEndGainPoint.GainValue = interpolatedGainVal1; // newClip1.ClipStartGainPoint.GainValue = interpolatedGainVal1; // thisClip.SortGainPoints(); // newClip1.SortGainPoints(); // //Cut clip out at 2nd point ***************** // Clip newClip2 = new Clip(thisClip.ClipSourceFileName) // { // ClipVirtualStartMs = thisClip.ClipVirtualStartMs, // ClipRelativeLoopStartMs = splitPointms2 - thisClip.ClipVirtualStartMs, // ClipSourceLenMilliseconds = thisClip.ClipSourceLenMilliseconds, // ClipWidthMs = newClip1.ClipRightMs - splitPointms2 // }; // newClip1.ClipWidthMs = splitPointms2 - newClip1.ClipLeftMs; // thisClip.myTrack.Clips.Insert(clipIndex + 2, newClip2); // thisClip.myTrack.UpdateClipIndexes(); // prevGainPoint = newClip1.GainPoints.LastOrDefault(gp => gp.sourcePointms <= splitPointms2); // nextGainPoint = newClip1.GainPoints.FirstOrDefault(gp => gp.sourcePointms >= splitPointms2); // if (!(prevGainPoint == null || nextGainPoint == null)) // interpolatedGainVal2 = GetGainValBetweenGainPoints(splitPointms2, prevGainPoint, nextGainPoint); // List leftGPs2 = newClip1.GainPoints.Where(gp => gp.sourcePointms <= newClip1.ClipRelativeLoopEndMs).ToList(); // List rightGPs2 = newClip1.GainPoints.Where(gp => gp.sourcePointms > newClip1.ClipRelativeLoopEndMs).ToList(); // newClip1.GainPoints = new ObservableCollection(leftGPs2); // newClip2.GainPoints = new ObservableCollection(rightGPs2); // newClip1.ClipEndGainPoint.GainValue = interpolatedGainVal2; // newClip2.ClipStartGainPoint.GainValue = interpolatedGainVal2; // newClip1.SortGainPoints(); // newClip2.SortGainPoints(); // } // catch (Exception ex) { Debug.WriteLine("Error splitting with gain points\n" + ex.Message); } //} //catch (Exception ex) { Debug.WriteLine("Error in creating cut out clip\n" + ex.Message); } } public void FadeInFromStart(double endpointms) { //Remove gain points between new points List deletedGainPoints = new List(thisClip.GainPoints.Where(gp => gp.sourcePointms > thisClip.ClipStartGainPoint.sourcePointms && gp.sourcePointms <= endpointms)); foreach (GainPoint delGP in deletedGainPoints) thisClip.GainPoints.Remove(delGP); int insertIdx = thisClip.GainPoints.IndexOf(thisClip.ClipStartGainPoint) + 1; undoActions.Add(new GainPointsFadeInUndoClass(thisClip.UndoClipID, insertIdx, deletedGainPoints, thisClip.ClipStartGainPoint.GainValue)); thisClip.GainPoints.Insert(insertIdx, new GainPoint() { sourcePointms = endpointms, GainValue = 1 }); thisClip.ClipStartGainPoint.GainValue = 0; thisClip.NotifyGainPointsChanged(); } public void FadeOutToEnd(double startpointms) { //Remove gain points between new points List deletedGainPoints = new List(thisClip.GainPoints.Where(gp => gp.sourcePointms >= startpointms && gp.sourcePointms < thisClip.ClipEndGainPoint.sourcePointms)); foreach (GainPoint delGP in deletedGainPoints) thisClip.GainPoints.Remove(delGP); int insertIdx = thisClip.GainPoints.IndexOf(thisClip.ClipEndGainPoint); undoActions.Add(new GainPointsFadeOutUndoClass(thisClip.UndoClipID, insertIdx, deletedGainPoints, thisClip.ClipEndGainPoint.GainValue)); thisClip.GainPoints.Insert(insertIdx, new GainPoint() { sourcePointms = startpointms, GainValue = 1 }); thisClip.ClipEndGainPoint.GainValue = 0; thisClip.NotifyGainPointsChanged(); } public void ResetSelectionGainPoints(double startpointms, double endpointms, bool addends) { //Remove gain points between new points List deletedGainPoints = new List(thisClip.GainPoints.Where(gp => gp.sourcePointms > startpointms && gp.sourcePointms < endpointms)); foreach (GainPoint delGP in deletedGainPoints) thisClip.GainPoints.Remove(delGP); int insertIdx = thisClip.GainPoints.IndexOf(thisClip.GainPoints.FirstOrDefault(gp => gp.sourcePointms > endpointms)); undoActions.Add(new GainPointsSelectionClearedOrResetUndoClass(thisClip.UndoClipID, insertIdx, deletedGainPoints, addends)); if (addends) { thisClip.GainPoints.Insert(insertIdx, new GainPoint() { sourcePointms = endpointms, GainValue = 1 }); thisClip.GainPoints.Insert(insertIdx, new GainPoint() { sourcePointms = startpointms, GainValue = 1 }); } thisClip.NotifyGainPointsChanged(); } public void InsertMuteGainPoints(double absRectStartMs, double absRectEndMs) { GainPoint prevGainPoint = thisClip.GainPoints.LastOrDefault(gp => gp.sourcePointms < absRectStartMs); GainPoint nextGainPoint = thisClip.GainPoints.FirstOrDefault(gp => gp.sourcePointms > absRectEndMs); float gainValAtStart = GetGainValBetweenGainPoints(absRectStartMs, prevGainPoint, thisClip.GainPoints[thisClip.GainPoints.IndexOf(prevGainPoint) + 1]); float gainValAtEnd = GetGainValBetweenGainPoints(absRectEndMs, thisClip.GainPoints[thisClip.GainPoints.IndexOf(nextGainPoint) - 1], nextGainPoint); List deletedGainPoints = new List(thisClip.GainPoints.Where(gp => gp.sourcePointms >= absRectStartMs && gp.sourcePointms <= absRectEndMs)); int deletedStart = deletedGainPoints.Count > 0 ? thisClip.GainPoints.IndexOf(deletedGainPoints[0]) : -1; if (deletedStart > -1) for (int n = 0; n < deletedGainPoints.Count; n++) thisClip.GainPoints.RemoveAt(deletedStart); int insertIdx = thisClip.GainPoints.IndexOf(nextGainPoint); undoActions.Add(new GainPointsSelectionMutedUndoClass(thisClip.UndoClipID, insertIdx, deletedGainPoints)); GainPoint startGP = new GainPoint() { sourcePointms = absRectStartMs, GainValue = 0 }; GainPoint endGP = new GainPoint() { sourcePointms = absRectEndMs, GainValue = 0 }; List newGainPoints = new List() { new GainPoint() { sourcePointms = endGP.sourcePointms + 1, GainValue = gainValAtEnd }, endGP, startGP, new GainPoint() { sourcePointms = startGP.sourcePointms - 1, GainValue = gainValAtStart } }; foreach (GainPoint gp in newGainPoints) thisClip.GainPoints.Insert(insertIdx, gp); //thisClip.SortGainPoints(); thisClip.NotifyGainPointsChanged(); } public void RemoveGainPoint(int gainPointIdx) { try { thisClip.GainPoints.RemoveAt(gainPointIdx); } catch (Exception ex) { Debug.WriteLine("error removing gainpoint: " + ex.Message); } } public void RemoveMutedGainPoints(int deletedStartIdx, List deletedPairs, int insertedTetramerIdx) { try { for (int n = 0; n < 4; n++) thisClip.GainPoints.RemoveAt(insertedTetramerIdx); if (deletedStartIdx > -1) for (int gno = deletedPairs.Count - 1; gno > -1; gno -= 1) thisClip.GainPoints.Insert(deletedStartIdx, deletedPairs[gno]); } catch (Exception ex) { Debug.WriteLine("error removing muted gain points: " + ex.Message); } } }