Пример #1
0
        public static Pattern[,] LoadPatterns(Project project, Song song, bool createMissingInstruments, bool createMissingArpeggios, 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);
            LoadAndMergeArpeggioList(serializer, false, createMissingArpeggios);
            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].beatLength);
                }
            }
            else
            {
                customSettings = null;
            }

            return(patterns);
        }
Пример #2
0
        public static void SaveNotes(Project project, Note[] notes, bool dpcm)
        {
            if (notes == null)
            {
                SetClipboardDataInternal(null);
                return;
            }

            var serializer  = new ProjectSaveBuffer(null);
            var instruments = new HashSet <Instrument>();
            var arpeggios   = new HashSet <Arpeggio>();
            var samples     = new Dictionary <int, DPCMSampleMapping>();

            if (dpcm)
            {
                foreach (var note in notes)
                {
                    if (note != null)
                    {
                        var mapping = project.GetDPCMMapping(note.Value);
                        if (mapping != null && mapping.Sample != null)
                        {
                            samples[note.Value] = mapping;
                        }
                    }
                }
            }
            else
            {
                foreach (var note in notes)
                {
                    if (note != null)
                    {
                        if (note.Instrument != null)
                        {
                            instruments.Add(note.Instrument);
                        }
                        if (note.Arpeggio != null)
                        {
                            arpeggios.Add(note.Arpeggio);
                        }
                    }
                }
            }

            SaveSampleList(serializer, samples);
            SaveArpeggioList(serializer, arpeggios);
            SaveInstrumentList(serializer, instruments);

            var numNotes = notes.Length;

            serializer.Serialize(ref numNotes);
            foreach (var note in notes)
            {
                if (note == null)
                {
                    Note.EmptyNote.SerializeState(serializer);
                }
                else
                {
                    note.SerializeState(serializer);
                }
            }

            var buffer        = Compression.CompressBytes(serializer.GetBuffer(), CompressionLevel.Fastest);
            var clipboardData = new List <byte>();

            clipboardData.AddRange(BitConverter.GetBytes(MagicNumberClipboardNotes));
            clipboardData.AddRange(buffer);

            SetClipboardDataInternal(clipboardData.ToArray());
        }
Пример #3
0
        public static void SavePatterns(Project project, Pattern[,] patterns, Song.PatternCustomSetting[] customSettings = null)
        {
            if (patterns == null)
            {
                SetClipboardDataInternal(null);
                return;
            }

            var uniqueInstruments  = new HashSet <Instrument>();
            var uniqueArpeggios    = new HashSet <Arpeggio>();
            var uniquePatterns     = new HashSet <Pattern>();
            var uniqueDPCMMappings = new Dictionary <int, DPCMSampleMapping>();
            var numPatterns        = patterns.GetLength(0);
            var numChannels        = patterns.GetLength(1);

            Debug.Assert(customSettings == null || customSettings.Length == numPatterns);

            for (int i = 0; i < numPatterns; i++)
            {
                for (int j = 0; j < numChannels; j++)
                {
                    var pattern = patterns[i, j];
                    if (pattern != null)
                    {
                        uniquePatterns.Add(pattern);
                        if (pattern.ChannelType == Channel.Dpcm)
                        {
                            foreach (var n in pattern.Notes.Values)
                            {
                                var mapping = project.GetDPCMMapping(n.Value);
                                if (mapping != null && mapping.Sample != null)
                                {
                                    uniqueDPCMMappings[n.Value] = mapping;
                                }
                            }
                        }
                        else
                        {
                            foreach (var n in pattern.Notes.Values)
                            {
                                if (n.Instrument != null)
                                {
                                    uniqueInstruments.Add(n.Instrument);
                                }
                                if (n.Arpeggio != null)
                                {
                                    uniqueArpeggios.Add(n.Arpeggio);
                                }
                            }
                        }
                    }
                }
            }

            if (uniquePatterns.Count == 0)
            {
                SetClipboardDataInternal(null);
                return;
            }

            var serializer = new ProjectSaveBuffer(null);

            SaveSampleList(serializer, uniqueDPCMMappings);
            SaveArpeggioList(serializer, uniqueArpeggios);
            SaveInstrumentList(serializer, uniqueInstruments);
            SavePatternList(serializer, uniquePatterns);

            serializer.Serialize(ref numPatterns);
            serializer.Serialize(ref numChannels);

            for (int i = 0; i < numPatterns; i++)
            {
                for (int j = 0; j < numChannels; j++)
                {
                    var pattern = patterns[i, j];
                    var patId   = pattern == null ? -1 : pattern.Id;
                    serializer.Serialize(ref patId);
                }
            }

            var hasCustomSettings = customSettings != null;
            var tempoMode         = project.TempoMode;

            serializer.Serialize(ref hasCustomSettings);
            serializer.Serialize(ref tempoMode);

            if (hasCustomSettings)
            {
                for (int i = 0; i < numPatterns; i++)
                {
                    serializer.Serialize(ref customSettings[i].useCustomSettings);
                    serializer.Serialize(ref customSettings[i].patternLength);
                    serializer.Serialize(ref customSettings[i].noteLength);
                    serializer.Serialize(ref customSettings[i].beatLength);
                }
            }

            var buffer        = Compression.CompressBytes(serializer.GetBuffer(), CompressionLevel.Fastest);
            var clipboardData = new List <byte>();

            clipboardData.AddRange(BitConverter.GetBytes(MagicNumberClipboardPatterns));
            clipboardData.AddRange(buffer);

            SetClipboardDataInternal(clipboardData.ToArray());
        }
Пример #4
0
        public static void SavePatterns(Project project, Pattern[,] patterns)
        {
            if (patterns == null)
            {
                SetClipboardData(null);
                return;
            }

            var uniqueInstruments = new HashSet <Instrument>();
            var uniquePatterns    = new HashSet <Pattern>();
            var numPatterns       = patterns.GetLength(0);
            var numChannels       = patterns.GetLength(1);

            for (int i = 0; i < numPatterns; i++)
            {
                for (int j = 0; j < numChannels; j++)
                {
                    var pattern = patterns[i, j];
                    if (pattern != null)
                    {
                        uniquePatterns.Add(pattern);
                        for (int k = 0; k < pattern.Song.PatternLength; k++)
                        {
                            var inst = pattern.Notes[k].Instrument;
                            if (inst != null)
                            {
                                uniqueInstruments.Add(inst);
                            }
                        }
                    }
                }
            }

            if (uniquePatterns.Count == 0)
            {
                SetClipboardData(null);
                return;
            }

            var serializer = new ProjectSaveBuffer(null);

            SaveInstrumentList(serializer, uniqueInstruments);
            SavePatternList(serializer, uniquePatterns);

            serializer.Serialize(ref numPatterns);
            serializer.Serialize(ref numChannels);

            for (int i = 0; i < numPatterns; i++)
            {
                for (int j = 0; j < numChannels; j++)
                {
                    var pattern = patterns[i, j];
                    var patId   = pattern == null ? -1 : pattern.Id;
                    serializer.Serialize(ref patId);
                }
            }

            var buffer        = Compression.CompressBytes(serializer.GetBuffer(), CompressionLevel.Fastest);
            var clipboardData = new List <byte>();

            clipboardData.AddRange(BitConverter.GetBytes(MagicNumberClipboardPatterns));
            clipboardData.AddRange(buffer);

            SetClipboardData(clipboardData.ToArray());
        }