Пример #1
0
        protected override void SecondPassParse()
        {
            object l = new object();

            ParseStage = ParsingStage.SecondPass;
            RunSecondPassParse();
            cancel.ThrowIfCancellationRequested();
            int keysMerged  = 0;
            var eventMerger = Task.Run(() =>
            {
                MergeAudioEvents();
            });
            var controlEventMerger = Task.Run(() =>
            {
                MergeControlEvents();
            });

            cancel.ThrowIfCancellationRequested();
            ParseStage = ParsingStage.MergingKeys;
            long noteCount = 0;

            Parallel.For(0, 256, new ParallelOptions()
            {
                CancellationToken = cancel
            }, (i) =>
            {
                var en = TimedMerger <Note> .MergeMany(parsers.Select(p => p.Notes[i]).ToArray(), n => n.start);
                if (LoaderSettings.RemoveOverlaps)
                {
                    Notes[i] = RemoveOverlaps(en).ToArray();
                }
                else
                {
                    Notes[i] = en.ToArray();
                }
                foreach (var p in parsers)
                {
                    p.Notes[i] = null;
                }
                lock (l)
                {
                    noteCount += Notes[i].Length;
                    keysMerged++;
                    ParseNumber    += 10;
                    ParseStatusText = "Merging Notes\nMerged keys " + keysMerged + " of " + 256;
                    Console.WriteLine("Merged key " + keysMerged + "/" + 256);
                }
            });
            MidiNoteCount = noteCount;
            MergeColorEvents();
            cancel.ThrowIfCancellationRequested();
            ParseStatusText = "Merging Events...";
            ParseStage      = ParsingStage.MergingEvents;
            controlEventMerger.GetAwaiter().GetResult();
            eventMerger.GetAwaiter().GetResult();
            ParseStatusText = "Done!";
        }
Пример #2
0
        protected void FirstPassParse()
        {
            object l            = new object();
            int    tracksParsed = 0;

            ParseStage = ParsingStage.FirstPass;
            Parallel.For(0, parsers.Length, new ParallelOptions()
            {
                CancellationToken = cancel
            }, (i) =>
            {
                var reader = new BufferByteReader(ReadProvider, 10000000, trackBeginnings[i], trackLengths[i]);
                parsers[i] = new MIDITrackParser(reader, division, i, LoaderSettings);
                parsers[i].FirstPassParse();
                lock (l)
                {
                    tracksParsed++;
                    ParseNumber    += 20;
                    ParseStatusText = "Analyzing MIDI\nTracks " + tracksParsed + " of " + parsers.Length;
                    Console.WriteLine("Pass 1 Parsed track " + tracksParsed + "/" + parsers.Length);

                    if (FirstKey > parsers[i].FirstKey)
                    {
                        FirstKey = parsers[i].FirstKey;
                    }
                    if (LastKey < parsers[i].LastKey)
                    {
                        LastKey = parsers[i].LastKey;
                    }
                }
            });
            cancel.ThrowIfCancellationRequested();
            var temposMerge = TimedMerger <TempoEvent> .MergeMany(parsers.Select(p => p.Tempos).ToArray(), t => t.time);

            globalTempos  = temposMerge.Cast <TempoEvent>().ToArray();
            MidiNoteCount = parsers.Select(p => p.noteCount).Sum();
        }