Exemplo n.º 1
0
        // Token: 0x06003234 RID: 12852 RVA: 0x001470DC File Offset: 0x001452DC
        private void ProcessEvents(WritingSettings settings, Action <IEventWriter, MidiEvent, bool> eventHandler)
        {
            byte?b     = null;
            bool flag  = true;
            bool flag2 = true;
            bool flag3 = true;

            foreach (MidiEvent midiEvent in this.Events.Concat(new EndOfTrackEvent[]
            {
                new EndOfTrackEvent()
            }))
            {
                if (!(midiEvent is UnknownMetaEvent) || !settings.CompressionPolicy.HasFlag(CompressionPolicy.DeleteUnknownMetaEvents))
                {
                    if (settings.CompressionPolicy.HasFlag(CompressionPolicy.NoteOffAsSilentNoteOn))
                    {
                        NoteOffEvent noteOffEvent = midiEvent as NoteOffEvent;
                        if (noteOffEvent != null)
                        {
                            midiEvent = new NoteOnEvent
                            {
                                DeltaTime  = noteOffEvent.DeltaTime,
                                Channel    = noteOffEvent.Channel,
                                NoteNumber = noteOffEvent.NoteNumber
                            };
                        }
                    }
                    if ((!settings.CompressionPolicy.HasFlag(CompressionPolicy.DeleteDefaultSetTempo) || !TrackChunk.TrySkipDefaultSetTempo(midiEvent, ref flag)) && (!settings.CompressionPolicy.HasFlag(CompressionPolicy.DeleteDefaultKeySignature) || !TrackChunk.TrySkipDefaultKeySignature(midiEvent, ref flag2)) && (!settings.CompressionPolicy.HasFlag(CompressionPolicy.DeleteDefaultTimeSignature) || !TrackChunk.TrySkipDefaultTimeSignature(midiEvent, ref flag3)))
                    {
                        IEventWriter writer = EventWriterFactory.GetWriter(midiEvent);
                        bool         arg;
                        if (midiEvent is ChannelEvent)
                        {
                            byte statusByte = writer.GetStatusByte(midiEvent);
                            byte?b2         = b;
                            int? num        = (b2 != null) ? new int?((int)b2.GetValueOrDefault()) : null;
                            int  num2       = (int)statusByte;
                            arg = (!(num.GetValueOrDefault() == num2 & num != null) || !settings.CompressionPolicy.HasFlag(CompressionPolicy.UseRunningStatus));
                            b   = new byte?(statusByte);
                        }
                        else
                        {
                            b   = null;
                            arg = true;
                        }
                        eventHandler(writer, midiEvent, arg);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void ProcessEvents(WritingSettings settings, Action <IEventWriter, MidiEvent, bool> eventHandler)
        {
            byte?runningStatus   = null;
            var  writeStatusByte = true;

            var skipSetTempo      = true;
            var skipKeySignature  = true;
            var skipTimeSignature = true;

            foreach (var midiEvent in Events.Concat(new[] { new EndOfTrackEvent() }))
            {
                var eventToWrite = midiEvent;
                if (eventToWrite is UnknownMetaEvent && settings.CompressionPolicy.HasFlag(CompressionPolicy.DeleteUnknownMetaEvents))
                {
                    continue;
                }

                //

                if (settings.CompressionPolicy.HasFlag(CompressionPolicy.NoteOffAsSilentNoteOn))
                {
                    var noteOffEvent = eventToWrite as NoteOffEvent;
                    if (noteOffEvent != null)
                    {
                        eventToWrite = new NoteOnEvent
                        {
                            DeltaTime  = noteOffEvent.DeltaTime,
                            Channel    = noteOffEvent.Channel,
                            NoteNumber = noteOffEvent.NoteNumber
                        }
                    }
                    ;
                }

                //

                if (settings.CompressionPolicy.HasFlag(CompressionPolicy.DeleteDefaultSetTempo) &&
                    TrySkipDefaultSetTempo(eventToWrite, ref skipSetTempo))
                {
                    continue;
                }

                if (settings.CompressionPolicy.HasFlag(CompressionPolicy.DeleteDefaultKeySignature) &&
                    TrySkipDefaultKeySignature(eventToWrite, ref skipKeySignature))
                {
                    continue;
                }

                if (settings.CompressionPolicy.HasFlag(CompressionPolicy.DeleteDefaultTimeSignature) &&
                    TrySkipDefaultTimeSignature(eventToWrite, ref skipTimeSignature))
                {
                    continue;
                }

                //

                IEventWriter eventWriter = EventWriterFactory.GetWriter(eventToWrite);

                if (eventToWrite is ChannelEvent)
                {
                    var statusByte = eventWriter.GetStatusByte(eventToWrite);
                    writeStatusByte = runningStatus != statusByte || !settings.CompressionPolicy.HasFlag(CompressionPolicy.UseRunningStatus);
                    runningStatus   = statusByte;
                }
                else
                {
                    runningStatus   = null;
                    writeStatusByte = true;
                }

                //

                eventHandler(eventWriter, eventToWrite, writeStatusByte);
            }
        }