示例#1
0
        public MidiEvent Read(MidiReader reader, ReadingSettings settings, byte currentStatusByte)
        {
            var statusByte = currentStatusByte.GetHead();
            var channel    = currentStatusByte.GetTail();

            ChannelEvent channelEvent = null;

            switch (statusByte)
            {
            case EventStatusBytes.Channel.NoteOff:
                channelEvent = new NoteOffEvent();
                break;

            case EventStatusBytes.Channel.NoteOn:
                channelEvent = new NoteOnEvent();
                break;

            case EventStatusBytes.Channel.ControlChange:
                channelEvent = new ControlChangeEvent();
                break;

            case EventStatusBytes.Channel.PitchBend:
                channelEvent = new PitchBendEvent();
                break;

            case EventStatusBytes.Channel.ChannelAftertouch:
                channelEvent = new ChannelAftertouchEvent();
                break;

            case EventStatusBytes.Channel.ProgramChange:
                channelEvent = new ProgramChangeEvent();
                break;

            case EventStatusBytes.Channel.NoteAftertouch:
                channelEvent = new NoteAftertouchEvent();
                break;

            default:
                ReactOnUnknownChannelEvent(statusByte, channel, reader, settings);
                return(null);
            }

            channelEvent.Read(reader, settings, MidiEvent.UnknownContentSize);
            channelEvent.Channel = channel;

            var noteOnEvent = channelEvent as NoteOnEvent;

            if (noteOnEvent != null && settings.SilentNoteOnPolicy == SilentNoteOnPolicy.NoteOff && noteOnEvent.Velocity == 0)
            {
                channelEvent = new NoteOffEvent
                {
                    DeltaTime  = noteOnEvent.DeltaTime,
                    Channel    = noteOnEvent.Channel,
                    NoteNumber = noteOnEvent.NoteNumber
                }
            }
            ;

            return(channelEvent);
        }
示例#2
0
        /// <summary>
        /// Gets name of the controller presented by an instance of <see cref="ControlChangeEvent"/>.
        /// </summary>
        /// <param name="controlChangeEvent">Control Change event to get controller name of.</param>
        /// <returns>Controller name of the <paramref name="controlChangeEvent"/> event.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="controlChangeEvent"/> is null.</exception>
        public static ControlName GetControlName(this ControlChangeEvent controlChangeEvent)
        {
            ThrowIfArgument.IsNull(nameof(controlChangeEvent), controlChangeEvent);

            return(GetControlName(controlChangeEvent.ControlNumber));
        }