Esempio n. 1
0
        public static void SaveEnvelopeValues(sbyte[] values)
        {
            var clipboardData = new List <byte>();

            clipboardData.AddRange(BitConverter.GetBytes(MagicNumberClipboardEnvelope));
            clipboardData.AddRange(BitConverter.GetBytes(values.Length));
            for (int i = 0; i < values.Length; i++)
            {
                clipboardData.Add((byte)values[i]);
            }

            PlatformUtils.ClearClipboardString();
            PlatformUtils.SetClipboardData(clipboardData.ToArray());
        }
Esempio n. 2
0
 public static void Reset()
 {
     PlatformUtils.SetClipboardData(null);
 }
Esempio n. 3
0
        public static void SavePatterns(Project project, Pattern[,] patterns, Song.PatternCustomSetting[] customSettings = null)
        {
            if (patterns == null)
            {
                PlatformUtils.SetClipboardData(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 == ChannelType.Dpcm)
                        {
                            foreach (var n in pattern.Notes.Values)
                            {
                                var mapping = project.GetDPCMMapping(n.Value);
                                if (mapping != 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)
            {
                PlatformUtils.SetClipboardData(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].groove);
                    serializer.Serialize(ref customSettings[i].groovePaddingMode);
                    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);

            PlatformUtils.SetClipboardData(clipboardData.ToArray());
        }
Esempio n. 4
0
        public static void SaveNotes(Project project, Note[] notes, bool dpcm)
        {
            if (notes == null)
            {
                PlatformUtils.SetClipboardData(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)
                        {
                            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);

            PlatformUtils.SetClipboardData(clipboardData.ToArray());
        }