protected bool FinishImport()
        {
            foreach (var s in project.Samples)
            {
                s.Process();
            }

            foreach (var s in project.Songs)
            {
                foreach (var c in s.Channels)
                {
                    c.ColorizePatterns();

                    for (int p = 0; p < s.Length; p++)
                    {
                        var pattern = c.PatternInstances[p];
                        if (pattern != null && patternLengths.TryGetValue(pattern, out var instLength))
                        {
                            if (instLength < s.GetPatternLength(p))
                            {
                                s.SetPatternCustomSettings(p, instLength, s.BeatLength);
                            }
                        }
                    }
                }

                // FamiTracker always assumes 4 rows per beat for BPM calculation, but let's assume
                // the artists properly set first row highlight to that.
                if (barLength == -1)
                {
                    s.SetSensibleBeatLength();
                }
                else
                {
                    s.SetBeatLength(barLength);
                }

                ApplyHaltEffect(s, patternFxData);

                s.DeleteNotesPastMaxInstanceLength();
                s.UpdatePatternStartNotes();

                CreateArpeggios(s, patternFxData);
                CreateSlideNotes(s, patternFxData);

                s.DeleteEmptyPatterns();
            }

            project.ConvertToCompoundNotes();
            project.InvalidateCumulativePatternCache();
            project.SortEverything(false);
            project.Validate();

            PrintAdditionalWarnings();

            return(true);
        }
        protected bool FinishImport()
        {
            foreach (var s in project.Songs)
            {
                foreach (var c in s.Channels)
                {
                    c.ColorizePatterns();

                    for (int p = 0; p < s.Length; p++)
                    {
                        var pattern = c.PatternInstances[p];
                        if (pattern != null && patternLengths.TryGetValue(pattern, out var instLength))
                        {
                            if (instLength < s.GetPatternLength(p))
                            {
                                s.SetPatternCustomSettings(p, instLength);
                            }
                        }
                    }
                }

                s.DeleteNotesPastMaxInstanceLength();
                s.UpdatePatternStartNotes();

                if (barLength == -1)
                {
                    s.SetSensibleBarLength();
                }
                else
                {
                    s.SetBarLength(barLength);
                }

                ApplyHaltEffect(s, patternFxData);
                CreateArpeggios(s, patternFxData);
                CreateSlideNotes(s, patternFxData);

                s.DeleteEmptyPatterns();
            }

            project.UpdateAllLastValidNotesAndVolume();
            project.Validate();

            return(true);
        }
Exemple #3
0
        const uint MagicNumber = 0x21534D46; // FMS!

        public Project Load(string filename)
        {
#if !DEBUG
            try
#endif
            {
                using (var stream = File.OpenRead(filename))
                {
                    var data = new byte[4];
                    stream.Read(data, 0, 4);
                    if (BitConverter.ToUInt32(data, 0) != MagicNumber)
                    {
                        stream.Close();
                        return(null);
                    }

                    stream.Read(data, 0, 4);
                    int loadVersion = BitConverter.ToInt32(data, 0);

                    if (loadVersion > Project.Version)
                    {
                        Log.LogMessage(LogSeverity.Error, $"File version ({loadVersion}) is more recent than this version of FamiStudio ({Project.Version}).");
                        return(null);
                    }

                    var buffer = new byte[stream.Length - stream.Position];
                    stream.Read(buffer, 0, buffer.Length);
                    buffer = Compression.DecompressBytes(buffer);

                    var project    = new Project();
                    var serializer = new ProjectLoadBuffer(project, buffer, loadVersion);
                    project.SerializeState(serializer);
                    project.Filename = filename;
                    project.Validate();
                    return(project);
                }
            }
#if !DEBUG
            catch
            {
                return(null);
            }
#endif
        }