/// <summary> /// Reads content of a MIDI meta event. /// </summary> /// <param name="reader">Reader to read the content with.</param> /// <param name="settings">Settings according to which the event's content must be read.</param> /// <param name="size">Size of the event's content.</param> protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size) { var invalidMetaEventParameterValuePolicy = settings.InvalidMetaEventParameterValuePolicy; var formatAndHours = reader.ReadByte(); Format = GetFormat(formatAndHours); Hours = ProcessValue(GetHours(formatAndHours), nameof(Hours), MaxHours, invalidMetaEventParameterValuePolicy); Minutes = ProcessValue(reader.ReadByte(), nameof(Minutes), MaxMinutes, invalidMetaEventParameterValuePolicy); Seconds = ProcessValue(reader.ReadByte(), nameof(Seconds), MaxSeconds, invalidMetaEventParameterValuePolicy); Frames = ProcessValue(reader.ReadByte(), nameof(Frames), MaxFrames[Format], invalidMetaEventParameterValuePolicy); SubFrames = ProcessValue(reader.ReadByte(), nameof(SubFrames), MaxSubFrames, invalidMetaEventParameterValuePolicy); }
// Token: 0x0600338E RID: 13198 RVA: 0x001480A0 File Offset: 0x001462A0 protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size) { this.Numerator = reader.ReadByte(); this.Denominator = (byte)Math.Pow(2.0, (double)reader.ReadByte()); if (size >= 4) { this.ClocksPerClick = reader.ReadByte(); this.NumberOf32ndNotesPerBeat = reader.ReadByte(); } }
/// <summary> /// Reads content of a MIDI meta event. /// </summary> /// <param name="reader">Reader to read the content with.</param> /// <param name="settings">Settings according to which the event's content must be read.</param> /// <param name="size">Size of the event's content.</param> protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size) { Numerator = reader.ReadByte(); Denominator = (byte)Math.Pow(2, reader.ReadByte()); if (size >= 4) { ClocksPerClick = reader.ReadByte(); ThirtySecondNotesPerBeat = reader.ReadByte(); } }
// Token: 0x06003378 RID: 13176 RVA: 0x00147F08 File Offset: 0x00146108 protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size) { InvalidMetaEventParameterValuePolicy invalidMetaEventParameterValuePolicy = settings.InvalidMetaEventParameterValuePolicy; byte formatAndHours = reader.ReadByte(); this.Format = SmpteOffsetEvent.GetFormat(formatAndHours); this.Hours = SmpteOffsetEvent.ProcessValue(SmpteOffsetEvent.GetHours(formatAndHours), "Hours", 23, invalidMetaEventParameterValuePolicy); this.Minutes = SmpteOffsetEvent.ProcessValue(reader.ReadByte(), "Minutes", 59, invalidMetaEventParameterValuePolicy); this.Seconds = SmpteOffsetEvent.ProcessValue(reader.ReadByte(), "Seconds", 59, invalidMetaEventParameterValuePolicy); this.Frames = SmpteOffsetEvent.ProcessValue(reader.ReadByte(), "Frames", SmpteOffsetEvent.MaxFrames[this.Format], invalidMetaEventParameterValuePolicy); this.SubFrames = SmpteOffsetEvent.ProcessValue(reader.ReadByte(), "SubFrames", 99, invalidMetaEventParameterValuePolicy); }
/// <summary> /// Reads content of a MIDI event. /// </summary> /// <param name="reader">Reader to read the content with.</param> /// <param name="settings">Settings according to which the event's content must be read.</param> /// <param name="size">Size of the event's content.</param> /// <exception cref="InvalidChannelEventParameterValueException">An invalid value for channel /// event's parameter was encountered.</exception> internal sealed override void Read(MidiReader reader, ReadingSettings settings, int size) { for (int i = 0; i < _parameters.Length; i++) { var parameter = reader.ReadByte(); if (parameter > SevenBitNumber.MaxValue) { switch (settings.InvalidChannelEventParameterValuePolicy) { case InvalidChannelEventParameterValuePolicy.Abort: throw new InvalidChannelEventParameterValueException($"{parameter} is invalid value for channel event's parameter.", parameter); case InvalidChannelEventParameterValuePolicy.ReadValid: parameter &= SevenBitNumber.MaxValue; break; case InvalidChannelEventParameterValuePolicy.SnapToLimits: parameter = SevenBitNumber.MaxValue; break; } } _parameters[i] = (SevenBitNumber)parameter; } }
// Token: 0x0600332D RID: 13101 RVA: 0x00147E64 File Offset: 0x00146064 protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size) { InvalidMetaEventParameterValuePolicy invalidMetaEventParameterValuePolicy = settings.InvalidMetaEventParameterValuePolicy; this.Key = (sbyte)KeySignatureEvent.ProcessValue((int)reader.ReadSByte(), "Key", -7, 7, invalidMetaEventParameterValuePolicy); this.Scale = (byte)KeySignatureEvent.ProcessValue((int)reader.ReadByte(), "Scale", 0, 1, invalidMetaEventParameterValuePolicy); }
public MidiEvent Read(MidiReader reader, ReadingSettings settings, byte currentStatusByte) { var statusByte = reader.ReadByte(); var size = reader.ReadVlqNumber(); // Type eventType; var midiEvent = TryGetEventType(settings.CustomMetaEventTypes, statusByte, out eventType) ? (MetaEvent)Activator.CreateInstance(eventType) : new UnknownMetaEvent(statusByte); // var readerPosition = reader.Position; midiEvent.Read(reader, settings, size); var bytesRead = reader.Position - readerPosition; var bytesUnread = size - bytesRead; if (bytesUnread > 0) { reader.Position += bytesUnread; } return(midiEvent); }
internal override void Read(MidiReader reader, ReadingSettings settings, int size) { var data = reader.ReadByte(); var midiTimeCodeComponent = (byte)data.GetHead(); if (!Enum.IsDefined(typeof(MidiTimeCodeComponent), midiTimeCodeComponent)) { throw new InvalidMidiTimeCodeComponentException("Invalid MIDI Time Code component.", midiTimeCodeComponent); } Component = (MidiTimeCodeComponent)midiTimeCodeComponent; var componentValue = data.GetTail(); if (componentValue > ComponentValueMasks[Component]) { switch (settings.InvalidSystemCommonEventParameterValuePolicy) { case InvalidSystemCommonEventParameterValuePolicy.Abort: throw new InvalidSystemCommonEventParameterValueException($"{componentValue} is invalid value for the {nameof(ComponentValue)} of {Component} of a MIDI Time Code event.", componentValue); case InvalidSystemCommonEventParameterValuePolicy.SnapToLimits: componentValue = (FourBitNumber)ComponentValueMasks[Component]; break; } } ComponentValue = componentValue; }
// Token: 0x0600333E RID: 13118 RVA: 0x0001725C File Offset: 0x0001545C protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size) { if (size >= 1) { this.Port = reader.ReadByte(); } }
/// <summary> /// Reads an event from the reader's underlying stream. /// </summary> /// <param name="reader">Reader to read an event.</param> /// <param name="settings">Settings according to which an event must be read.</param> /// <param name="channelEventStatusByte">Current channel event status byte used as running status.</param> /// <returns>Instance of the <see cref="MidiEvent"/> representing a MIDI event.</returns> /// <exception cref="ObjectDisposedException">Method was called after the writer's underlying stream /// was disposed.</exception> /// <exception cref="IOException">An I/O error occurred on the writer's underlying stream.</exception> /// <exception cref="UnexpectedRunningStatusException">Unexpected running status is encountered.</exception> /// <exception cref="UnknownChannelEventException">Reader has encountered an unknown channel event.</exception> /// <exception cref="NotEnoughBytesException">Not enough bytes to read an event.</exception> /// <exception cref="InvalidChannelEventParameterValueException">Value of a channel event's parameter just /// read is invalid.</exception> private MidiEvent ReadEvent(MidiReader reader, ReadingSettings settings, ref byte?channelEventStatusByte) { var deltaTime = reader.ReadVlqLongNumber(); if (deltaTime < 0) { deltaTime = 0; } // var statusByte = reader.ReadByte(); if (statusByte <= SevenBitNumber.MaxValue) { if (channelEventStatusByte == null) { throw new UnexpectedRunningStatusException(); } statusByte = channelEventStatusByte.Value; reader.Position--; } // var eventReader = EventReaderFactory.GetReader(statusByte); var midiEvent = eventReader.Read(reader, settings, statusByte); // if (settings.SilentNoteOnPolicy == SilentNoteOnPolicy.NoteOff) { var noteOnEvent = midiEvent as NoteOnEvent; if (noteOnEvent?.Velocity == 0) { midiEvent = new NoteOffEvent { DeltaTime = noteOnEvent.DeltaTime, Channel = noteOnEvent.Channel, NoteNumber = noteOnEvent.NoteNumber }; } } // if (midiEvent is ChannelEvent) { channelEventStatusByte = statusByte; } // midiEvent.DeltaTime = deltaTime; return(midiEvent); }
/// <summary> /// Reads content of a MIDI meta event. /// </summary> /// <param name="reader">Reader to read the content with.</param> /// <param name="settings">Settings according to which the event's content must be read.</param> /// <param name="size">Size of the event's content.</param> protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size) { var invalidMetaEventParameterValuePolicy = settings.InvalidMetaEventParameterValuePolicy; Key = (sbyte)ProcessValue(reader.ReadSByte(), nameof(Key), MinKey, MaxKey, invalidMetaEventParameterValuePolicy); Scale = (byte)ProcessValue(reader.ReadByte(), nameof(Scale), MinScale, MaxScale, invalidMetaEventParameterValuePolicy); }
internal override void Read(MidiReader reader, ReadingSettings settings, int size) { var data = reader.ReadByte(); var messageType = data.GetHead(); // TODO: proper exception if (!Enum.IsDefined(typeof(MidiTimeCodeComponent), (byte)messageType)) { throw new Exception(); } Component = (MidiTimeCodeComponent)(byte)messageType; // TODO: check value and apply policy ComponentValue = data.GetTail(); }
internal override void Read(MidiReader reader, ReadingSettings settings, int size) { var number = reader.ReadByte(); if (number > SevenBitNumber.MaxValue) { switch (settings.InvalidSystemCommonEventParameterValuePolicy) { case InvalidSystemCommonEventParameterValuePolicy.Abort: throw new InvalidSystemCommonEventParameterValueException($"{number} is invalid value for the {nameof(Number)} of a Song Select event.", number); case InvalidSystemCommonEventParameterValuePolicy.SnapToLimits: number = SevenBitNumber.MaxValue; break; } } Number = (SevenBitNumber)number; }
// Token: 0x060033A3 RID: 13219 RVA: 0x00148300 File Offset: 0x00146500 public MidiEvent Read(MidiReader reader, ReadingSettings settings, byte currentStatusByte) { byte b = reader.ReadByte(); int num = reader.ReadVlqNumber(); string typeName; MetaEventReader.TryGetEventType(b, out typeName); MetaEvent @event = this.GetEvent(typeName, b); long position = reader.Position; @event.Read(reader, settings, num); long num2 = reader.Position - position; long num3 = (long)num - num2; if (num3 > 0L) { reader.Position += num3; } return(@event); }
// Token: 0x060032AB RID: 12971 RVA: 0x00147A34 File Offset: 0x00145C34 internal sealed override void Read(MidiReader reader, ReadingSettings settings, int size) { for (int i = 0; i < this._parameters.Length; i++) { byte b = reader.ReadByte(); if (b > SevenBitNumber.MaxValue) { switch (settings.InvalidChannelEventParameterValuePolicy) { case InvalidChannelEventParameterValuePolicy.Abort: throw new InvalidChannelEventParameterValueException(string.Format("{0} is invalid value for channel event's parameter.", b), b); case InvalidChannelEventParameterValuePolicy.ReadValid: b &= SevenBitNumber.MaxValue; break; case InvalidChannelEventParameterValuePolicy.SnapToLimits: b = SevenBitNumber.MaxValue; break; } } this._parameters[i] = (SevenBitNumber)b; } }
// Token: 0x0600330B RID: 13067 RVA: 0x0001703F File Offset: 0x0001523F protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size) { this.Channel = reader.ReadByte(); }
internal override void Read(MidiReader reader, ReadingSettings settings, int size) { _lsb = ProcessValue(reader.ReadByte(), "LSB", settings.InvalidSystemCommonEventParameterValuePolicy); _msb = ProcessValue(reader.ReadByte(), "MSB", settings.InvalidSystemCommonEventParameterValuePolicy); }
// Token: 0x06003233 RID: 12851 RVA: 0x00146EB4 File Offset: 0x001450B4 private MidiEvent ReadEvent(MidiReader reader, ReadingSettings settings, ref byte?channelEventStatusByte) { long num = reader.ReadVlqLongNumber(); if (num < 0L) { num = 0L; } this.absTime += num; byte b = reader.ReadByte(); if (b <= SevenBitNumber.MaxValue) { if (channelEventStatusByte == null) { throw new UnexpectedRunningStatusException(); } b = channelEventStatusByte.Value; long position = reader.Position; reader.Position = position - 1L; } MidiEvent midiEvent = EventReaderFactory.GetReader(b).Read(reader, settings, b); if (settings.SilentNoteOnPolicy == SilentNoteOnPolicy.NoteOff) { NoteOnEvent noteOnEvent = midiEvent as NoteOnEvent; SevenBitNumber?sevenBitNumber = (noteOnEvent != null) ? new SevenBitNumber?(noteOnEvent.Velocity) : null; int? num2 = (sevenBitNumber != null) ? new int?((int)sevenBitNumber.GetValueOrDefault()) : null; if (num2.GetValueOrDefault() == 0 & num2 != null) { midiEvent = new NoteOffEvent { DeltaTime = noteOnEvent.DeltaTime, Channel = noteOnEvent.Channel, NoteNumber = noteOnEvent.NoteNumber }; } } if (midiEvent is ChannelEvent) { channelEventStatusByte = new byte?(b); } midiEvent.DeltaTime = num; midiEvent.AbsoluteTime = this.absTime; if (midiEvent is NoteOnEvent) { this.onEvents.Add(this.Events.Count); } else if (midiEvent is NoteOffEvent) { for (int i = 0; i < this.onEvents.Count; i++) { NoteOnEvent noteOnEvent2 = this.Events[this.onEvents[i]] as NoteOnEvent; if (noteOnEvent2.Channel == ((NoteOffEvent)midiEvent).Channel && noteOnEvent2.NoteNumber == ((NoteOffEvent)midiEvent).NoteNumber) { ((NoteOnEvent)this.Events[this.onEvents[i]]).OffEvent = (NoteOffEvent)midiEvent; this.onEvents.RemoveAt(i); return(null); } } } return(midiEvent); }
internal override void Read(MidiReader reader, ReadingSettings settings, int size) { // TODO: apply policy Lsb = (SevenBitNumber)reader.ReadByte(); Msb = (SevenBitNumber)reader.ReadByte(); }
internal override void Read(MidiReader reader, ReadingSettings settings, int size) { Number = (SevenBitNumber)reader.ReadByte(); }