Ejemplo n.º 1
0
        private static void SavePatternList(ProjectSaveBuffer serializer, ICollection <Pattern> patterns)
        {
            // Save the original song id so we can patch it when pasting between projects.
            foreach (var pat in patterns)
            {
                int songId = pat.Song.Id;
                serializer.Serialize(ref songId);
                break;
            }

            int numUniquePatterns = patterns.Count;

            serializer.Serialize(ref numUniquePatterns);

            foreach (var pat in patterns)
            {
                var patId      = pat.Id;
                var patChannel = pat.ChannelType;
                var patName    = pat.Name;
                serializer.Serialize(ref patId);
                serializer.Serialize(ref patChannel);
                serializer.Serialize(ref patName);
            }

            foreach (var pat in patterns)
            {
                pat.SerializeState(serializer);
            }
        }
Ejemplo n.º 2
0
        private static void SaveArpeggioList(ProjectSaveBuffer serializer, ICollection <Arpeggio> arpeggios)
        {
            int numArpeggios = arpeggios.Count;

            serializer.Serialize(ref numArpeggios);

            foreach (var arp in arpeggios)
            {
                var arpId   = arp.Id;
                var arpName = arp.Name;
                serializer.Serialize(ref arpId);
                serializer.Serialize(ref arpName);
            }

            foreach (var arp in arpeggios)
            {
                arp.SerializeState(serializer);
            }
        }
Ejemplo n.º 3
0
        private static void SaveInstrumentList(ProjectSaveBuffer serializer, ICollection <Instrument> instruments)
        {
            int numInstruments = instruments.Count;

            serializer.Serialize(ref numInstruments);

            foreach (var inst in instruments)
            {
                var instId   = inst.Id;
                var instName = inst.Name;
                serializer.Serialize(ref instId);
                serializer.Serialize(ref instName);
            }

            foreach (var inst in instruments)
            {
                inst.SerializeState(serializer);
            }
        }
Ejemplo n.º 4
0
        private static void SaveSampleList(ProjectSaveBuffer serializer, IDictionary <int, DPCMSampleMapping> mappings)
        {
            int numMappings = mappings.Count;

            serializer.Serialize(ref numMappings);

            foreach (var kv in mappings)
            {
                var note    = kv.Key;
                var mapping = kv.Value;

                serializer.Serialize(ref note);
                mapping.SerializeState(serializer);

                var sampleName = mapping.Sample.Name;
                var sampleData = mapping.Sample.Data;

                serializer.Serialize(ref sampleName);
                serializer.Serialize(ref sampleData);
            }
        }
Ejemplo n.º 5
0
        public static void SaveNotes(Project project, Note[] notes)
        {
            if (notes == null)
            {
                SetClipboardData(null);
                return;
            }

            var instruments = new HashSet <Instrument>();

            foreach (var note in notes)
            {
                if (note.Instrument != null)
                {
                    instruments.Add(note.Instrument);
                }
            }

            var serializer = new ProjectSaveBuffer(null);

            SaveInstrumentList(serializer, instruments);

            int numNotes = notes.Length;

            serializer.Serialize(ref numNotes);
            foreach (var note in notes)
            {
                note.SerializeState(serializer);
            }

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

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

            SetClipboardData(clipboardData.ToArray());
        }
Ejemplo n.º 6
0
        private static void SaveSampleList(ProjectSaveBuffer serializer, IDictionary <int, DPCMSampleMapping> mappings)
        {
            var samples = new HashSet <DPCMSample>();

            foreach (var kv in mappings)
            {
                if (kv.Value.Sample != null)
                {
                    samples.Add(kv.Value.Sample);
                }
            }

            int numSamples = samples.Count;

            serializer.Serialize(ref numSamples);

            foreach (var sample in samples)
            {
                var sampleId   = sample.Id;
                var sampleName = sample.Name;

                serializer.Serialize(ref sampleId);
                serializer.Serialize(ref sampleName);

                sample.SerializeState(serializer);
            }

            int numMappings = mappings.Count;

            serializer.Serialize(ref numMappings);

            foreach (var kv in mappings)
            {
                var note       = kv.Key;
                var mapping    = kv.Value;
                var sampleName = mapping.Sample.Name;

                serializer.Serialize(ref note);
                serializer.Serialize(ref sampleName);

                mapping.SerializeState(serializer);
            }
        }
Ejemplo n.º 7
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());
        }
Ejemplo n.º 8
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());
        }
Ejemplo n.º 9
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());
        }