示例#1
0
        public static bool AreEqual(MidiEvent event1, MidiEvent event2, bool compareDeltaTimes)
        {
            if (ReferenceEquals(event1, event2))
            {
                return(true);
            }

            if (ReferenceEquals(null, event1) || ReferenceEquals(null, event2))
            {
                return(false);
            }

            if (compareDeltaTimes && event1.DeltaTime != event2.DeltaTime)
            {
                return(false);
            }

            if (event1.GetType() != event2.GetType())
            {
                return(false);
            }

            if (event1 is SystemRealTimeEvent)
            {
                return(true);
            }

            if (event1 is ChannelEvent)
            {
                var parametersField = typeof(ChannelEvent).GetField("_parameters", BindingFlags.Instance | BindingFlags.NonPublic);
                var e1Parameters    = (SevenBitNumber[])parametersField.GetValue(event1);
                var e2Parameters    = (SevenBitNumber[])parametersField.GetValue(event2);
                return(e1Parameters.SequenceEqual(e2Parameters) && ((ChannelEvent)event1).Channel == ((ChannelEvent)event2).Channel);
            }

            var sysExEvent1 = event1 as SysExEvent;

            if (sysExEvent1 != null)
            {
                var sysExEvent2 = event2 as SysExEvent;
                return(sysExEvent1.Completed == sysExEvent2.Completed &&
                       ArrayEquality.AreEqual(sysExEvent1.Data, sysExEvent2.Data));
            }

            var baseTextEvent = event1 as BaseTextEvent;

            if (baseTextEvent != null)
            {
                return(baseTextEvent.Text == ((BaseTextEvent)event2).Text);
            }

            Func <MidiEvent, MidiEvent, bool> comparer;

            if (Comparers.TryGetValue(event1.GetType(), out comparer))
            {
                return(comparer(event1, event2));
            }

            throw new NotImplementedException("Events comparing is not implemented.");
        }
示例#2
0
 public bool Accepts(MidiEvent m_e)
 {
     if (_Include.Count == 0)
     {
         if (_Exclude.Count == 0)
         {
             return(true);
         }
         else
         {
             return
                 (!_Exclude.Contains(m_e.GetType()));
         }
     }
     else
     {
         if (_Exclude.Count == 0)
         {
             return
                 (_Include.Contains(m_e.GetType()));
         }
         else
         {
             return
                 (_Include.Contains(m_e.GetType()) &&
                  !_Exclude.Contains(m_e.GetType()));
         }
     }
 }
示例#3
0
        public static bool Equals(MidiEvent e1, MidiEvent e2)
        {
            if (ReferenceEquals(e1, e2))
            {
                return(true);
            }

            if (ReferenceEquals(null, e1) || ReferenceEquals(null, e2))
            {
                return(false);
            }

            if (e1.DeltaTime != e2.DeltaTime)
            {
                return(false);
            }

            if (e1.GetType() != e2.GetType())
            {
                return(false);
            }

            if (e1 is ChannelEvent)
            {
                var parametersField = typeof(ChannelEvent).GetField("_parameters", BindingFlags.Instance | BindingFlags.NonPublic);
                var e1Parameters    = (SevenBitNumber[])parametersField.GetValue(e1);
                var e2Parameters    = (SevenBitNumber[])parametersField.GetValue(e2);
                return(e1Parameters.SequenceEqual(e2Parameters));
            }

            var sysExEvent1 = e1 as SysExEvent;

            if (sysExEvent1 != null)
            {
                var sysExEvent2 = e2 as SysExEvent;
                return(sysExEvent1.Completed == sysExEvent2.Completed &&
                       ArrayUtilities.Equals(sysExEvent1.Data, sysExEvent2.Data));
            }

            var baseTextEvent = e1 as BaseTextEvent;

            if (baseTextEvent != null)
            {
                return(baseTextEvent.Text == ((BaseTextEvent)e2).Text);
            }

            Func <MidiEvent, MidiEvent, bool> comparer;

            if (_comparers.TryGetValue(e1.GetType(), out comparer))
            {
                return(comparer(e1, e2));
            }

            return(true);
        }
            /// <summary>Generates a line of code to add the specified event to the "events" list.</summary>
            /// <param name="ev">The event to be added.</param>
            void GenerateAddEvent(MidiEvent ev)
            {
                string eventName   = ev.GetType().Name;
                string eventParams =
                    Case <BaseTextMetaMidiEvent>(ev, e => Commas(e.DeltaTime, TextString(e.Text))) ??
                    Case <NoteVoiceMidiEvent>(ev, e =>
                                              e.Channel == (byte)SpecialChannel.Percussion && Enum.IsDefined(typeof(GeneralMidiPercussion), e.Note) ?
                                              Commas(e.DeltaTime, "GeneralMidiPercussion." + (GeneralMidiPercussion)e.Note, e.Parameter2) :
                                              Commas(e.DeltaTime, e.Channel, "\"" + MidiEvent.GetNoteName(e.Note) + "\"", e.Parameter2)) ??
                    Case <ProgramChangeVoiceMidiEvent>(ev, e =>
                                                       Enum.IsDefined(typeof(GeneralMidiInstrument), e.Number) ?
                                                       Commas(e.DeltaTime, e.Channel, "GeneralMidiInstrument." + (GeneralMidiInstrument)e.Number) :
                                                       Commas(e.DeltaTime, e.Channel, e.Number)) ??
                    Case <SystemExclusiveMidiEvent>(ev, e => Commas(e.DeltaTime, ByteArrayCreationString(e.Data))) ??
                    Case <ChannelPrefixMetaMidiEvent>(ev, e => Commas(e.DeltaTime, e.Prefix)) ??
                    Case <EndOfTrackMetaMidiEvent>(ev, e => Commas(e.DeltaTime)) ??
                    Case <KeySignatureMetaMidiEvent>(ev, e => Commas(e.DeltaTime, "Key." + e.Key, "Tonality." + e.Tonality)) ??
                    Case <MidiPortMetaMidiEvent>(ev, e => Commas(e.DeltaTime, e.Port)) ??
                    Case <ProprietaryMetaMidiEvent>(ev, e => Commas(e.DeltaTime, ByteArrayCreationString(e.Data))) ??
                    Case <SequenceNumberMetaMidiEvent>(ev, e => Commas(e.DeltaTime, e.Number)) ??
                    Case <SMPTEOffsetMetaMidiEvent>(ev, e => Commas(e.DeltaTime, e.Hours, e.Minutes, e.Seconds, e.Frames, e.FractionalFrames)) ??
                    Case <TempoMetaMidiEvent>(ev, e => Commas(e.DeltaTime, e.Value)) ??
                    Case <TimeSignatureMetaMidiEvent>(ev, e => Commas(e.DeltaTime, e.Numerator, e.Denominator, e.MidiClocksPerClick, e.NumberOfNotated32nds)) ??
                    Case <UnknownMetaMidiEvent>(ev, e => Commas(e.DeltaTime, ByteArrayCreationString(e.Data))) ??
                    Case <ChannelPressureVoiceMidiEvent>(ev, e => Commas(e.DeltaTime, e.Channel, e.Pressure)) ??
                    Case <ControllerVoiceMidiEvent>(ev, e => Commas(e.DeltaTime, e.Channel, "Controller." + (Controller)e.Number, e.Value)) ??
                    Case <PitchWheelVoiceMidiEvent>(ev, e => Commas(e.DeltaTime, e.Channel, "PitchWheelStep." + (PitchWheelStep)e.Position)) ??
                    null;

                if (eventParams == null)
                {
                    throw new ArgumentException("Unknown MidiEvent");
                }
                Ln(EventsListName, ".Add(new ", eventName, "(", eventParams, "));");
            }
示例#5
0
        private static bool IsInvalid(MidiEvent midiEvent)
        {
            var eventType = midiEvent.GetType();

            if (eventType == typeof(ControlChangeEvent) ||
                eventType == typeof(PitchWheelChangeEvent) ||
                eventType == typeof(PatchChangeEvent))
            {
                return(true);
            }

            return(false);
        }
示例#6
0
        private void tp_TrackEvent(object sender, MidiEvent anEvent)
        {
            //Console.WriteLine(this._sequencer.Position.ToString());
            //			anEvent.Message.Accept((TrackPlayer)sender);

            //((Endogine.Midi.MetaMessage)anEvent.Message).Type == Endogine.Midi.MetaType.TrackName
            if (anEvent.GetType() == typeof(Endogine.Midi.ChannelMessage))
            {
                //				Endogine.Midi.ChannelMessage msg = (Endogine.Midi.ChannelMessage)anEvent;
                //				if (msg.Command == Endogine.Midi.ChannelCommand.NoteOn)
                //					this.checkBox1.Checked = !(this.checkBox1.Checked);
            }
        }
示例#7
0
        public static bool IsMidiEventUnwanted(MidiEvent message)
        {
            if (message == null)
            {
                return(false);
            }

            Type eventType = message.GetType();

            if (eventType == typeof(ProgramChangeEvent) || eventType == typeof(ControlChangeEvent))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#8
0
        private void ProcessEvent(MidiEvent e)
        {
            switch (e)
            {
            // Voice messages
            case OffNoteVoiceMidiEvent ev:
                sequencer.SendMessage(new MidiNoteOffMessage(ev.Channel, ev.Note, ev.Velocity));
                velocities[ev.Note] = 0;
                NotifyPropertyChanged("VuMeter");
                break;

            case OnNoteVoiceMidiEvent ev:
                sequencer.SendMessage(new MidiNoteOnMessage(ev.Channel, ev.Note, ev.Velocity));
                velocities[ev.Note] = ev.Velocity;
                NotifyPropertyChanged("VuMeter");
                break;

            case ControllerVoiceMidiEvent ev:
                sequencer.SendMessage(new MidiControlChangeMessage(ev.Channel, ev.Number, ev.Value));
                switch ((Controller)ev.Number)
                {
                case Controller.VolumeCourse:       Volume = ev.Value; NotifyPropertyChanged(nameof(Volume)); break;

                case Controller.ExpressionCourse:   Expression = ev.Value; NotifyPropertyChanged(nameof(Expression)); break;

                case Controller.PanPositionCourse:  Pan = ev.Value; NotifyPropertyChanged(nameof(Pan)); break;
                }
                break;

            case ProgramChangeVoiceMidiEvent ev:
                sequencer.SendMessage(new MidiProgramChangeMessage(ev.Channel, ev.Number));
                Program = ev.Number;
                NotifyPropertyChanged(nameof(Program));
                break;

            case AftertouchNoteVoiceMidiEvent ev:   sequencer.SendMessage(new MidiPolyphonicKeyPressureMessage(ev.Channel, ev.Note, ev.Pressure)); break;

            case ChannelPressureVoiceMidiEvent ev:  sequencer.SendMessage(new MidiChannelPressureMessage(ev.Channel, ev.Pressure)); break;

            case PitchWheelVoiceMidiEvent ev:       sequencer.SendMessage(new MidiPitchBendChangeMessage(ev.Channel, (UInt16)ev.Position)); break;

            // SysEx messages
            case SystemExclusiveMidiEvent ev:       sequencer.SendMessage(new MidiSystemExclusiveMessage(ev.Data.AsBuffer())); break;

            // Meta events
            //case SequenceNumberMetaMidiEvent ev:

            //case TextMetaMidiEvent ev:
            //case CopyrightTextMetaMidiEvent ev:
            case SequenceTrackNameTextMetaMidiEvent ev: Name = ev.Text; NotifyPropertyChanged(nameof(Name)); break;

            //case InstrumentTextMetaMidiEvent ev:
            //case LyricTextMetaMidiEvent ev:
            case MarkerTextMetaMidiEvent ev:        sequencer.SetMarkerText(ev.Text); break;

            //case CuePointTextMetaMidiEvent ev:
            //case ProgramNameTextMetaMidiEvent ev:
            //case DeviceNameTextMidiEvent ev:
            //case ChannelPrefixMetaMidiEvent ev:
            case MidiPortMetaMidiEvent ev:          break;

            case EndOfTrackMetaMidiEvent ev:        break;

            case TempoMetaMidiEvent ev:             sequencer.SetQuarterDuration((UInt32)ev.Value); break;

            //case SMPTEOffsetMetaMidiEvent ev:
            case TimeSignatureMetaMidiEvent ev:     sequencer.SetTimeSignature(ev.Numerator, 1u << ev.Denominator); break;
            //case KeySignatureMetaMidiEvent ev:  break;
            //case ProprietaryMetaMidiEvent ev:


            default:
                Debug.WriteLine($"Do not know how to convert event of type {e.GetType()}");
                break;
            }
        }
示例#9
0
        private void tp_TrackEvent(object sender, MidiEvent anEvent)
        {
            //Console.WriteLine(this._sequencer.Position.ToString());
            //			anEvent.Message.Accept((TrackPlayer)sender);

            //((Endogine.Midi.MetaMessage)anEvent.Message).Type == Endogine.Midi.MetaType.TrackName
            if (anEvent.GetType() == typeof(Endogine.Midi.ChannelMessage))
            {
                //				Endogine.Midi.ChannelMessage msg = (Endogine.Midi.ChannelMessage)anEvent;
                //				if (msg.Command == Endogine.Midi.ChannelCommand.NoteOn)
                //					this.checkBox1.Checked = !(this.checkBox1.Checked);
            }
        }