private static bool LoadAndMergeSampleList(ProjectLoadBuffer serializer, bool checkOnly = false, bool createMissing = true) { int numMappings = 0; serializer.Serialize(ref numMappings); bool needMerge = false; for (int i = 0; i < numMappings; i++) { int note = 0; serializer.Serialize(ref note); var mapping = new DPCMSampleMapping(); mapping.SerializeState(serializer); string sampleName = null; byte[] sampleData = null; serializer.Serialize(ref sampleName); serializer.Serialize(ref sampleData); if (serializer.Project.GetDPCMMapping(note) == null) { needMerge = true; if (!checkOnly && createMissing) { var sample = serializer.Project.FindMatchingSample(sampleData); if (sample == null) { sample = serializer.Project.CreateDPCMSample(sampleName, sampleData); } serializer.Project.MapDPCMSample(note, sample, mapping.Pitch, mapping.Loop); } } } return(needMerge); }
private static bool LoadAndMergeSampleList(ProjectLoadBuffer serializer, bool checkOnly = false, bool createMissing = true) { int numSamples = 0; serializer.Serialize(ref numSamples); bool needMerge = false; var dummySample = new DPCMSample(); for (int i = 0; i < numSamples; i++) { int sampleId = 0; string sampleName = ""; serializer.Serialize(ref sampleId); serializer.Serialize(ref sampleName); var existingSample = serializer.Project.GetSample(sampleName); if (existingSample != null) { serializer.RemapId(sampleId, existingSample.Id); dummySample.SerializeState(serializer); // Skip } else { needMerge = true; if (!checkOnly && createMissing) { var sample = serializer.Project.CreateDPCMSample(sampleName); serializer.RemapId(sampleId, sample.Id); sample.SerializeState(serializer); } else { serializer.RemapId(sampleId, -1); dummySample.SerializeState(serializer); // Skip } } } int numMappings = 0; serializer.Serialize(ref numMappings); for (int i = 0; i < numMappings; i++) { int note = 0; string sampleName = ""; serializer.Serialize(ref note); serializer.Serialize(ref sampleName); var mapping = new DPCMSampleMapping(); mapping.SerializeState(serializer); if (serializer.Project.GetDPCMMapping(note) == null) { needMerge = true; if (!checkOnly && createMissing) { var sample = serializer.Project.GetSample(sampleName); if (sample != null) { serializer.Project.MapDPCMSample(note, sample, mapping.Pitch, mapping.Loop); } } } } serializer.Project.SortSamples(); return(needMerge); }