public static Pattern[,] LoadPatterns(Project project, Song song, bool createMissingInstruments) { var buffer = GetClipboardData(MagicNumberClipboardPatterns); if (buffer == null) { return(null); } var decompressedBuffer = Compression.DecompressBytes(buffer, 4); var serializer = new ProjectLoadBuffer(project, decompressedBuffer, Project.Version); LoadAndMergeInstrumentList(serializer, false, createMissingInstruments); int numNonNullPatterns = LoadAndMergePatternList(serializer, song); int numPatterns = 0; int numChannels = 0; serializer.Serialize(ref numPatterns); serializer.Serialize(ref numChannels); var patterns = new Pattern[numPatterns, numChannels]; for (int i = 0; i < numPatterns; i++) { for (int j = 0; j < numChannels; j++) { var patId = -1; serializer.Serialize(ref patId, true); patterns[i, j] = patId == -1 ? null : song.GetPattern(patId); } } return(patterns); }
private static int LoadAndMergePatternList(ProjectLoadBuffer serializer, Song song) { // Remap whatever original song we had to the current one. int songId = -1; serializer.Serialize(ref songId); serializer.RemapId(songId, song.Id); int numPatterns = 0; serializer.Serialize(ref numPatterns); var patternIdNameMap = new List <Tuple <int, int, string> >(); for (int i = 0; i < numPatterns; i++) { var patId = 0; var patChannel = 0; var patName = ""; serializer.Serialize(ref patId); serializer.Serialize(ref patChannel); serializer.Serialize(ref patName); patternIdNameMap.Add(new Tuple <int, int, string>(patId, patChannel, patName)); } var dummyPattern = new Pattern(); // Match patterns by name, create missing ones and remap IDs. for (int i = 0; i < numPatterns; i++) { var patId = patternIdNameMap[i].Item1; var patChannel = patternIdNameMap[i].Item2; var patName = patternIdNameMap[i].Item3; if (serializer.Project.IsChannelActive(patChannel)) { var existingPattern = song.GetChannelByType(patChannel).GetPattern(patName); if (existingPattern != null) { serializer.RemapId(patId, existingPattern.Id); dummyPattern.SerializeState(serializer); // Skip } else { var pattern = song.GetChannelByType(patChannel).CreatePattern(patName); serializer.RemapId(patId, pattern.Id); pattern.SerializeState(serializer); } } else { serializer.RemapId(patId, -1); dummyPattern.SerializeState(serializer); // Skip } } return(numPatterns); }
private static bool LoadAndMergeInstrumentList(ProjectLoadBuffer serializer, bool checkOnly = false, bool createMissing = true) { int numInstruments = 0; serializer.Serialize(ref numInstruments); var instrumentIdNameMap = new List <Tuple <int, string> >(); for (int i = 0; i < numInstruments; i++) { var instId = 0; var instName = ""; serializer.Serialize(ref instId); serializer.Serialize(ref instName); instrumentIdNameMap.Add(new Tuple <int, string>(instId, instName)); } var dummyInstrument = new Instrument(); var needMerge = false; // Match instruments by name, create missing ones and remap IDs. for (int i = 0; i < numInstruments; i++) { var instId = instrumentIdNameMap[i].Item1; var instName = instrumentIdNameMap[i].Item2; var existingInstrument = serializer.Project.GetInstrument(instName); if (existingInstrument != null) { serializer.RemapId(instId, existingInstrument.Id); dummyInstrument.SerializeState(serializer); // Skip } else { needMerge = true; if (!checkOnly) { if (createMissing) { var instrument = serializer.Project.CreateInstrument(instName); serializer.RemapId(instId, instrument.Id); instrument.SerializeState(serializer); } else { serializer.RemapId(instId, -1); dummyInstrument.SerializeState(serializer); // Skip } } } } return(needMerge); }
public static Pattern[,] LoadPatterns(Project project, Song song, bool createMissingInstruments, bool createMissingSamples, out Song.PatternCustomSetting[] customSettings) { var buffer = GetClipboardDataInternal(MagicNumberClipboardPatterns); if (buffer == null) { customSettings = null; return(null); } var decompressedBuffer = Compression.DecompressBytes(buffer, 4); var serializer = new ProjectLoadBuffer(project, decompressedBuffer, Project.Version); LoadAndMergeSampleList(serializer, false, createMissingSamples); LoadAndMergeInstrumentList(serializer, false, createMissingInstruments); LoadAndMergePatternList(serializer, song); int numPatterns = 0; int numChannels = 0; serializer.Serialize(ref numPatterns); serializer.Serialize(ref numChannels); var patterns = new Pattern[numPatterns, numChannels]; for (int i = 0; i < numPatterns; i++) { for (int j = 0; j < numChannels; j++) { var patId = -1; serializer.Serialize(ref patId, true); patterns[i, j] = patId == -1 ? null : song.GetPattern(patId); } } var tempoMode = 0; var hasCustomSettings = false; serializer.Serialize(ref hasCustomSettings); serializer.Serialize(ref tempoMode); if (hasCustomSettings && tempoMode == project.TempoMode) { customSettings = new Song.PatternCustomSetting[numPatterns]; for (int i = 0; i < numPatterns; i++) { customSettings[i] = new Song.PatternCustomSetting(); serializer.Serialize(ref customSettings[i].useCustomSettings); serializer.Serialize(ref customSettings[i].patternLength); serializer.Serialize(ref customSettings[i].noteLength); serializer.Serialize(ref customSettings[i].barLength); } } else { customSettings = null; } return(patterns); }
private static bool LoadAndMergeArpeggioList(ProjectLoadBuffer serializer, bool checkOnly = false, bool createMissing = true) { int numArpeggios = 0; serializer.Serialize(ref numArpeggios); var arpeggioIdNameMap = new List <Tuple <int, string> >(); for (int i = 0; i < numArpeggios; i++) { var arpId = 0; var arpName = ""; serializer.Serialize(ref arpId); serializer.Serialize(ref arpName); arpeggioIdNameMap.Add(new Tuple <int, string>(arpId, arpName)); } var dummyArpeggio = new Arpeggio(); var needMerge = false; // Match arpeggios by name, create missing ones and remap IDs. for (int i = 0; i < numArpeggios; i++) { var arpId = arpeggioIdNameMap[i].Item1; var arpName = arpeggioIdNameMap[i].Item2; var existingArpeggio = serializer.Project.GetArpeggio(arpName); if (existingArpeggio != null) { serializer.RemapId(arpId, existingArpeggio.Id); dummyArpeggio.SerializeState(serializer); // Skip } else { needMerge = true; if (!checkOnly && createMissing) { var instrument = serializer.Project.CreateArpeggio(arpName); serializer.RemapId(arpId, instrument.Id); instrument.SerializeState(serializer); } else { serializer.RemapId(arpId, -1); dummyArpeggio.SerializeState(serializer); // Skip } } } serializer.Project.SortArpeggios(); return(needMerge); }
public static Note[] LoadNotes(Project project, bool createMissingInstruments, bool createMissingArpeggios, bool createMissingSamples) { var buffer = GetClipboardDataInternal(MagicNumberClipboardNotes); if (buffer == null) { return(null); } var serializer = new ProjectLoadBuffer(project, Compression.DecompressBytes(buffer, 4), Project.Version); LoadAndMergeSampleList(serializer, false, createMissingSamples); LoadAndMergeArpeggioList(serializer, false, createMissingArpeggios); LoadAndMergeInstrumentList(serializer, false, createMissingInstruments); int numNotes = 0; serializer.Serialize(ref numNotes); var notes = new Note[numNotes]; for (int i = 0; i < numNotes; i++) { var note = new Note(); note.SerializeState(serializer); if (!note.IsEmpty) { notes[i] = note; } } project.SortInstruments(); return(notes); }
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); }
private static bool LoadAndMergeInstrumentList(ProjectLoadBuffer serializer, bool checkOnly = false, bool createMissing = true) { int numInstruments = 0; serializer.Serialize(ref numInstruments); var instrumentIdNameMap = new List <Tuple <int, int, string> >(); for (int i = 0; i < numInstruments; i++) { var instId = 0; var instType = 0; var instName = ""; serializer.Serialize(ref instId); serializer.Serialize(ref instType); serializer.Serialize(ref instName); instrumentIdNameMap.Add(new Tuple <int, int, string>(instId, instType, instName)); } var dummyInstrument = new Instrument(); var needMerge = false; // Match instruments by name, create missing ones and remap IDs. for (int i = 0; i < numInstruments; i++) { var instId = instrumentIdNameMap[i].Item1; var instType = instrumentIdNameMap[i].Item2; var instName = instrumentIdNameMap[i].Item3; var existingInstrument = serializer.Project.GetInstrument(instName); if (existingInstrument != null) { if (existingInstrument.Expansion == instType) { serializer.RemapId(instId, existingInstrument.Id); } else { serializer.RemapId(instId, -1); // Incompatible expansion type, skip. } dummyInstrument.SerializeState(serializer); // Skip } else { needMerge = true; if (!checkOnly && createMissing && (instType == ExpansionType.None || serializer.Project.UsesExpansionAudio(instType))) { var instrument = serializer.Project.CreateInstrument(instType, instName); serializer.RemapId(instId, instrument.Id); instrument.SerializeState(serializer); } else { serializer.RemapId(instId, -1); dummyInstrument.SerializeState(serializer); // Skip } } } serializer.Project.SortInstruments(); return(needMerge); }