Esempio n. 1
0
        private static void Run(Options options)
        {
            const int    resolution       = 1000;
            const double tickSeconds      = 1.0 / resolution;
            const double tickMilliSeconds = tickSeconds * 1000;

            var savePath = GetSavePath(options);

            if (File.Exists(savePath))
            {
                File.Delete(savePath);
            }

            using (var zipArchive = ZipFile.Open(savePath, ZipArchiveMode.Create))
            {
                using (var fileStream = zipArchive.CreateEntry("config.json", CompressionLevel.Optimal).Open())
                    using (var sw = new StreamWriter(fileStream))
                    {
                        var config = new Dictionary <string, object>
                        {
                            { "version", 0 },
                            { "resolution", resolution }
                        };
                        sw.Write(JsonConvert.SerializeObject(config));
                    }

                using (var fileStream = zipArchive.CreateEntry("dump", CompressionLevel.Optimal).Open())
                    using (var dumpWriter = new DumpWriter(fileStream))
                    {
                        var sequence       = new Sequence(options.InputFile);
                        var sequencer      = new Sequencer(sequence);
                        var ymf825DumpChip = new Ymf825DumpChip(dumpWriter);
                        var ymf825Driver   = new Ymf825Driver(ymf825DumpChip);
                        var project        = LoadProject(options);
                        var driver         = new MidiDriver(project.Tones.ToArray(), project.Equalizers.ToArray(), ymf825Driver);
                        var stopped        = false;

                        ymf825Driver.EnableSectionMode();
                        ymf825Driver.SleepAction += i =>
                        {
                            var tick = (int)Math.Ceiling(i / tickMilliSeconds);

                            if (dumpWriter.Disposed)
                            {
                                return;
                            }

                            dumpWriter.RealtimeWait((ushort)tick);
                        };
                        driver.Start();

                        sequencer.OnTrackEvent += (sender, args) =>
                        {
                            foreach (var argsEvent in args.Events)
                            {
                                driver.ProcessMidiEvent(argsEvent);
                            }
                        };
                        sequencer.SequenceEnd += (sender, args) => stopped = true;
                        sequencer.Tick         = 0L;

                        while (!stopped)
                        {
                            sequencer.Progress(tickSeconds);
                            dumpWriter.Wait(1);
                        }
                    }
            }
        }
Esempio n. 2
0
 public Ymf825DumpChip(DumpWriter dumpWriter)
 {
     this.dumpWriter = dumpWriter;
 }