Ejemplo n.º 1
0
        private void On_Load()
        {
            _tunes = new List <Tune>();

            //var p = new Project { TuneFilenames = new[] { "abc", "def" } };
            //string x = JsonConvert.SerializeObject(p);

            var fileConverterFactory = new FileConverterFactory(new FileSystemHelper());

            try
            {
                var project = Project.OpenProject(Path.Combine(Directory.GetCurrentDirectory(), "TestProject"));

                foreach (var fileName in project.TuneFilenames)
                {
                    var metaDataPath = Path.Combine(project.WorkingFolder, "MetaData");
                    Directory.CreateDirectory(metaDataPath);

                    var tunePath = Path.Combine(project.WorkingFolder, fileName);

                    var rawTunePath = Path.ChangeExtension(Path.Combine(metaDataPath, fileName), "m6raw");
                    var summaryPath = Path.ChangeExtension(Path.Combine(metaDataPath, fileName), "summary");

                    IFileConverter converter;
                    if ((converter = fileConverterFactory.ParseFile(rawTunePath)) == null)
                    {
                        converter = fileConverterFactory.ParseFile(tunePath);
                    }
                    if (converter == null)
                    {
                        continue;
                    }

                    var waveData = converter.ProcessFile();
                    if (waveData == null)
                    {
                        continue;
                    }

                    if (!File.Exists(rawTunePath))
                    {
                        try
                        {
                            using (var rawFile = File.Create(rawTunePath))
                            {
                                Serializer.Serialize(rawFile, waveData);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }

                    var tune = new Tune(waveData);

                    SummaryCollection summaryData = null;
                    try
                    {
                        using (var summaryFile = File.OpenRead(summaryPath))
                        {
                            summaryData = Serializer.Deserialize <SummaryCollection>(summaryFile);
                        }

                        tune.SummaryCollection = summaryData;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }

                    if (summaryData == null)
                    {
                        tune.BuildSummaries();
                        try
                        {
                            using (var summaryFile = File.Create(summaryPath))
                            {
                                Serializer.Serialize(summaryFile, tune.SummaryCollection);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }

                    tune.StartTick = 0;
                    tune.Track     = _tunes.Count;

                    _tunes.Add(tune);
                }

                _delta = new Delta();

                _ticksPerPixel = 1024;

                _bbBitmap = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);

                _desktopRange = new Range(0, ClientRectangle.Width * _ticksPerPixel);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }