Beispiel #1
0
 public AudioEvent(MIDIEvent inputEvent, double inputTime)
 {
     Event = inputEvent;
     Time  = inputTime;
 }
Beispiel #2
0
        void SecondPassParse()
        {
            object l            = new object();
            int    tracksParsed = 0;

            ParseStage = ParsingStage.SecondPass;
            Parallel.For(0, parsers.Length, (i) =>
            {
                parsers[i].SecondPassParse();
                lock (l)
                {
                    tracksParsed++;
                    ParseNumber    += 20;
                    ParseStatusText = "Loading MIDI\nTracks " + tracksParsed + " of " + parsers.Length;
                    Console.WriteLine("Pass 2 Parsed track " + tracksParsed + "/" + parsers.Length);
                }
            });
            cancel.ThrowIfCancellationRequested();
            int keysMerged  = 0;
            var eventMerger = Task.Run(() =>
            {
                int count      = loaderSettings.EventPlayerThreads;
                MIDINoteEvents = new MIDIEvent[count][];
                Parallel.For(0, count, new ParallelOptions()
                {
                    CancellationToken = cancel
                }, i =>
                {
                    try
                    {
                        MIDINoteEvents[i] = TimedMerger <MIDIEvent> .MergeMany(parsers.Select(p => new SkipIterator <MIDIEvent>(p.NoteEvents, i, count)).ToArray(), e =>
                        {
                            return(e.time);
                        }).ToArray();
                    }
                    catch (OperationCanceledException)
                    {
                    }
                });
            });
            var controlEventMerger = Task.Run(() =>
            {
                int count         = loaderSettings.EventPlayerThreads;
                MIDIControlEvents = TimedMerger <MIDIEvent> .MergeMany(parsers.Select(p => p.ControlEvents).ToArray(), e => e.time).ToArray();
            });

            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;
            List <ColorEvent[]> ce = new List <ColorEvent[]>();

            foreach (var p in parsers)
            {
                ce.AddRange(p.ColorEvents);
            }
            ColorEvents = ce.ToArray();
            cancel.ThrowIfCancellationRequested();
            ParseStatusText = "Merging Events...";
            ParseStage      = ParsingStage.MergingEvents;
            Console.WriteLine("Merging events...");
            controlEventMerger.GetAwaiter().GetResult();
            eventMerger.GetAwaiter().GetResult();
            ParseStatusText = "Done!";
        }