public static List <MidiEvent> GetEventsOfType(MidiFile midiFile, MidiEventType type, bool isDeltaAccumulated = false) { List <MidiEvent> retObj = new List <MidiEvent>(); foreach (TrackChunk chunk in midiFile.Chunks.ToList()) { long acumulatedTimeInTicks = 0; foreach (var eventito in chunk.Events) { acumulatedTimeInTicks += eventito.DeltaTime; if (eventito.EventType == type) { var e = eventito.Clone(); if (!isDeltaAccumulated) { e.DeltaTime = acumulatedTimeInTicks; } retObj.Add(e); } } } if (isDeltaAccumulated) { return(retObj); } else { return(ConvertAccumulatedTimeToDeltaTime(retObj)); } }
public void NotifyLearnMidiEvent(MidiEventType midiEventToLearn) { if (LearnMidiEvent != null) { LearnMidiEvent(midiEventToLearn, new PropertyChangedEventArgs("MidiEventType midiEventToLearn")); } }
/// <summary> /// Initializes a new instance of the <see cref="ChannelEvent"/> with the specified parameters count. /// </summary> /// <param name="eventType">The type of event.</param> /// <param name="parametersCount">Count of the parameters for this channel event.</param> /// <exception cref="ArgumentOutOfRangeException">Parameters count is negative number which is unallowable.</exception> protected ChannelEvent(MidiEventType eventType, int parametersCount) : base(eventType) { ThrowIfArgument.IsNegative(nameof(parametersCount), parametersCount, "Parameters count is negative."); _parameters = new SevenBitNumber[parametersCount]; }
internal InvalidSystemCommonEventParameterValueException(MidiEventType eventType, string componentName, int componentValue) : base($"{componentValue} is invalid value for the {componentName} property of a system common event of {eventType} type.") { EventType = eventType; ComponentName = componentName; ComponentValue = componentValue; }
public void NotifyMidiEventLearned(MidiEventType midiEventLearned) { if (MidiEventLearned != null) { MidiEventLearned(midiEventLearned, new PropertyChangedEventArgs("MidiEventType midiEventLearned")); } }
internal InvalidMetaEventParameterValueException(MidiEventType eventType, string propertyName, int value) : base($"{value} is invalid value for the {propertyName} property of a meta event of {eventType} type.") { EventType = eventType; PropertyName = propertyName; Value = value; }
public MidiEvent(BinaryReader reader) { EventType = Event.Type.Midi; EventTypeByte = reader.ReadByte(); Channel = (byte)(EventTypeByte & 0x0F); Type = (MidiEventType)(byte)(EventTypeByte & 0xF0); DataBytes = reader.ReadBytes(2); }
/// <summary> /// Received MIDI learn command from a button. /// </summary> /// <param name="learnCommandButton">Button the event was received from</param> /// <param name="e">RoutedEventArgs</param> private void LearnMidiCommand(object learnCommandButton, RoutedEventArgs e) { // Check if the button is not already active, indicating an active learning session. // If not, initiate the learning session. if (((SolidColorBrush)(learnCommandButton as Button).Background).Color != Color.FromArgb(255, 0, 120, 215)) { // Clear all button highlights. for (int i = 0; i < 12; i++) { Button currentButtonElement = (Button)this.FindName("MidiEventType" + i.ToString()); // Check if the type has been trained yet. if (midiController.learnedMidiTriggers[i].id == 0) { // If not, use the standard color for the button. currentButtonElement.Background = this.themeButtonColor; } else { // Otherwise use the highlight color. currentButtonElement.Background = new SolidColorBrush(Color.FromArgb(255, 0, 71, 138)); } } // Highlight the relevant button that should be learned. (learnCommandButton as Button).Background = new SolidColorBrush(Color.FromArgb(255, 0, 120, 215)); // Get ID of the MIDI event type. var eventType = (learnCommandButton as Button).Name.Substring(13); MidiEventType midiEventToLearn = (MidiEventType)int.Parse(eventType); // Notify subscribers about learning a new MIDI event. this.globalEventHandlerInstance.NotifyLearnMidiEvent(midiEventToLearn); } else { // Check if the type has been trained yet. var eventType = (learnCommandButton as Button).Name.Substring(13); if (midiController.learnedMidiTriggers[int.Parse(eventType)].id == 0) { // If not, use the standard color for the button. (learnCommandButton as Button).Background = this.themeButtonColor; } else { // Otherwise use the highlight color. (learnCommandButton as Button).Background = new SolidColorBrush(Color.FromArgb(255, 0, 71, 138)); } // Notify subscribers that no MIDI event should be learned. this.globalEventHandlerInstance.NotifyLearnMidiEvent(MidiEventType.Empty); } }
/// <summary> /// Event to learn a new MIDI event type. /// </summary> /// <param name="midiEventToLearn">The MIDI event that should be learned as MidiEventType</param> /// <param name="e">PropertyChangedEventArgs</param> private void LearnMidiEvent(object midiEventToLearn, PropertyChangedEventArgs e) { if ((MidiEventType)midiEventToLearn != MidiEventType.Empty) { this.midiLearningActive = true; this.midiLearningType = (MidiEventType)midiEventToLearn; } else { this.midiLearningActive = false; this.midiLearningType = (MidiEventType)midiEventToLearn; } }
/// <summary> /// Retrieves the events in a MIDI file stream. /// </summary> /// <param name="Handle">The MIDI stream to get the events from.</param> /// <param name="Track">The track to get the events from... 0 = 1st track.</param> /// <param name="Filter">The type of event to retrieve (use <see cref="MidiEventType.None"/> to retrieve all events).</param> /// <returns>An array of <see cref="MidiEvent" /> configuration entries on success, <see langword="null" /> on error.</returns> /// <exception cref="Errors.Handle"><paramref name="Handle" /> is not valid.</exception> /// <exception cref="Errors.NotAvailable">The stream is for real-time events only, so does not have an event sequence.</exception> /// <exception cref="Errors.Parameter"><paramref name="Track" /> is not valid.</exception> public static MidiEvent[] StreamGetEvents(int Handle, int Track, MidiEventType Filter) { var count = StreamGetEvents(Handle, Track, Filter, null); if (count <= 0) { return(null); } var events = new MidiEvent[count]; StreamGetEvents(Handle, Track, Filter, events); return(events); }
public static List <MidiEvent> GetEventsOfType(TrackChunk chunk, MidiEventType type) { List <MidiEvent> retObj = new List <MidiEvent>(); long acumulatedTimeInTicks = 0; foreach (var eventito in chunk.Events) { acumulatedTimeInTicks += eventito.DeltaTime; if (eventito.EventType == type) { var e = eventito.Clone(); e.DeltaTime = acumulatedTimeInTicks; retObj.Add(e); } } return(ConvertAccumulatedTimeToDeltaTime(retObj)); }
/// <summary> /// Initializes a new instance of the <see cref="MidiEvent"/> with the specified event type. /// </summary> /// <param name="eventType">The type of event.</param> /// <exception cref="InvalidEnumArgumentException"><paramref name="eventType"/> specified an invalid value.</exception> public MidiEvent(MidiEventType eventType) { ThrowIfArgument.IsInvalidEnumValue(nameof(eventType), eventType); EventType = eventType; }
/// <summary> /// Initializes a new instance of the <see cref="MetaEvent"/> with the specified event type. /// </summary> /// <param name="eventType">The type of event.</param> internal MetaEvent(MidiEventType eventType) : base(eventType) { }
/// <summary> /// Opens a new <see cref="MidiFile"/> from the specified path. /// </summary> /// <param name="path">The path to load the midi file from.</param> public MidiFile(string path) { Utils.PrintDebug("Loading file: " + path + "\r\n-----------------"); BinaryReader br = new BinaryReader(File.Open(path, FileMode.Open)); using (br) { // Check valid MIDI file if (Encoding.ASCII.GetString(br.ReadBytes(4)) == "MThd") { if (Utils.CorrectEndian(br.ReadUInt32()) == 6) { // Valid MIDI file // Get MIDI internal file format fileFormat = (FileFormat)Utils.CorrectEndian(br.ReadUInt16()); Utils.PrintDebug("HEAD: FileFormat " + fileFormat.ToString()); // Get track count trackCount = Utils.CorrectEndian(br.ReadUInt16()); Utils.PrintDebug("HEAD: Tracks " + trackCount); // Get MIDI time conversion deltaTicksPerQuarterNote = Utils.CorrectEndian(br.ReadUInt16()); Utils.PrintDebug("HEAD: DeltaTicksPerQuarterNote " + deltaTicksPerQuarterNote); // Current track uint track = 0; // Tracks list List <TrackChunk> tracks = new List <TrackChunk>(); // Repeat for every track chunk while (br.BaseStream.Position != br.BaseStream.Length) { Utils.PrintDebug("-----------------\r\nTRACK: " + br.BaseStream.Position); if (Encoding.ASCII.GetString(br.ReadBytes(4)) == "MTrk") { // Valid track chunk // Create new track data List <MetaEvent> metaEvents = new List <MetaEvent>(); List <MidiEvent> midiEvents = new List <MidiEvent>(); // Absolute time uint absTime = 0; // End position in bytes of chunk long targetPosition = br.BaseStream.Position + 4 + Utils.CorrectEndian(br.ReadUInt32()); // Used for continous status between MIDI events byte statusOld = 0x00; // Repeat for every event while (br.BaseStream.Position < targetPosition) { // Get delta time (time since last MIDI event) uint deltaTime = Utils.ReadVariableLengthUint(br); // Get first byte of event (used to identify event type) byte eventHeader = br.ReadByte(); // Update absolute time absTime += deltaTime; switch (eventHeader) { case 0xFF: // Meta Event // Get meta event type MetaEventType metaCode = (MetaEventType)br.ReadByte(); // Get length in bytes of event data int lenData1 = (int)Utils.ReadVariableLengthUint(br); switch (metaCode) { case MetaEventType.SequenceNumber: if (lenData1 == 2) { ushort sequenceNumber = Utils.CorrectEndian(br.ReadUInt16()); metaEvents.Add(new SequenceNumberEvent(track, deltaTime, absTime, sequenceNumber)); Utils.PrintDebug(string.Format("META: {0} {1} {2}", metaCode.ToString(), sequenceNumber, br.BaseStream.Position)); } else { Utils.PrintDebug("Could not read MIDI file - invalid SequenceNumber meta event"); throw new FormatException("Could not read MIDI file - invalid SequenceNumber meta event"); } break; case MetaEventType.TextEvent: string text = Encoding.ASCII.GetString(br.ReadBytes(lenData1)); metaEvents.Add(new TextEvent(track, deltaTime, absTime, text)); Utils.PrintDebug(string.Format("META: {0} {1} {2}", metaCode.ToString(), text, br.BaseStream.Position)); break; case MetaEventType.CopyrightNotice: string copyright = Encoding.ASCII.GetString(br.ReadBytes(lenData1)); metaEvents.Add(new TextEvent(track, deltaTime, absTime, copyright, MetaEventType.CopyrightNotice)); Utils.PrintDebug(string.Format("META: {0} {1} {2}", metaCode.ToString(), copyright, br.BaseStream.Position)); break; case MetaEventType.SequenceName: string sequenceName = Encoding.ASCII.GetString(br.ReadBytes(lenData1)); metaEvents.Add(new TextEvent(track, deltaTime, absTime, sequenceName, MetaEventType.SequenceName)); Utils.PrintDebug(string.Format("META: {0} {1} {2}", metaCode.ToString(), sequenceName, br.BaseStream.Position)); break; case MetaEventType.InstrumentName: string instrumentName = Encoding.ASCII.GetString(br.ReadBytes(lenData1)); metaEvents.Add(new TextEvent(track, deltaTime, absTime, instrumentName, MetaEventType.InstrumentName)); Utils.PrintDebug(string.Format("META: {0} {1} {2}", metaCode.ToString(), instrumentName, br.BaseStream.Position)); break; case MetaEventType.LyricText: string lyric = Encoding.ASCII.GetString(br.ReadBytes(lenData1)); metaEvents.Add(new TextEvent(track, deltaTime, absTime, lyric, MetaEventType.LyricText)); Utils.PrintDebug(string.Format("META: {0} {1} {2}", metaCode.ToString(), lyric, br.BaseStream.Position)); break; case MetaEventType.MarkerText: string marker = Encoding.ASCII.GetString(br.ReadBytes(lenData1)); metaEvents.Add(new TextEvent(track, deltaTime, absTime, marker, MetaEventType.MarkerText)); Utils.PrintDebug(string.Format("META: {0} {1} {2}", metaCode.ToString(), marker, br.BaseStream.Position)); break; case MetaEventType.CuePoint: string cuePoint = Encoding.ASCII.GetString(br.ReadBytes(lenData1)); metaEvents.Add(new TextEvent(track, deltaTime, absTime, cuePoint, MetaEventType.CuePoint)); Utils.PrintDebug(string.Format("META: {0} {1} {2}", metaCode.ToString(), cuePoint, br.BaseStream.Position)); break; case MetaEventType.MidiChannelPrefix: if (lenData1 == 1) { byte channel = br.ReadByte(); metaEvents.Add(new MidiChannelPrefixEvent(track, deltaTime, absTime, channel)); Utils.PrintDebug(string.Format("META: {0} {1} {2}", metaCode.ToString(), channel, br.BaseStream.Position)); } else { Utils.PrintDebug("Could not read MIDI file - invalid MIDIChannelPrefix meta event (Position: " + br.BaseStream.Position + ")"); throw new FormatException("Could not read MIDI file - invalid MIDIChannelPrefix meta event (Position: " + br.BaseStream.Position + ")"); } break; case MetaEventType.EndOfTrack: if (lenData1 == 0) { metaEvents.Add(new EndOfTrackEvent(track, deltaTime, absTime)); Utils.PrintDebug(string.Format("META: {0} {1}", metaCode.ToString(), br.BaseStream.Position)); } else { Utils.PrintDebug("Could not read MIDI file - invalid EndOfTrack meta event (Position: " + br.BaseStream.Position + ")"); throw new FormatException("Could not read MIDI file - invalid EndOfTrack meta event (Position: " + br.BaseStream.Position + ")"); } break; case MetaEventType.SetTempo: if (lenData1 == 3) { uint tempo = (uint)((br.ReadByte() << 16) + (br.ReadByte() << 8) + br.ReadByte()); metaEvents.Add(new SetTempoEvent(track, deltaTime, absTime, tempo)); Utils.PrintDebug(string.Format("META: {0} {1} {2}", metaCode.ToString(), tempo, br.BaseStream.Position)); } else { Utils.PrintDebug("Could not read MIDI file - invalid SetTempo meta event (Position: " + br.BaseStream.Position + ")"); throw new FormatException("Could not read MIDI file - invalid SetTempo meta event (Position: " + br.BaseStream.Position + ")"); } break; case MetaEventType.SMPTEOffset: if (lenData1 == 5) { byte hour = br.ReadByte(); byte frameRateCode = (byte)(hour & 0xC0); float frameRate = 24F; switch (frameRateCode) { case 0: // 24 frameRate = 24F; break; case 1: // 25 frameRate = 25F; break; case 2: // 'Drop' 30 frameRate = 29.97F; break; case 3: // 30 frameRate = 30F; break; } hour = (byte)(hour & 0x3F); byte minute = br.ReadByte(); byte second = br.ReadByte(); byte frame = br.ReadByte(); byte subFrame = br.ReadByte(); metaEvents.Add(new SMPTEOffsetEvent(track, deltaTime, absTime, frameRate, hour, minute, second, frame, subFrame)); Utils.PrintDebug(string.Format("META: SMPTEOffset {0} {1} {2} {3} {4} {5} {6}", frameRate, hour, minute, second, frame, subFrame, br.BaseStream.Position)); } else { Utils.PrintDebug("Could not read MIDI file - invalid SMPTEOffset meta event (Position: " + br.BaseStream.Position + ")"); throw new FormatException("Could not read MIDI file - invalid SMPTEOffset meta event (Position: " + br.BaseStream.Position + ")"); } break; case MetaEventType.TimeSignature: if (lenData1 == 4) { byte numerator = br.ReadByte(); byte denominator = (byte)Math.Pow(br.ReadByte(), 2); byte ticksPerQuarterNote = br.ReadByte(); byte ticksPerQuarter32Note = br.ReadByte(); metaEvents.Add(new TimeSignatureEvent(track, deltaTime, absTime, numerator, denominator, ticksPerQuarterNote, ticksPerQuarter32Note)); Utils.PrintDebug(string.Format("META: {0} {1} {2} {3} {4} {5}", metaCode.ToString(), numerator, denominator, ticksPerQuarterNote, ticksPerQuarter32Note, br.BaseStream.Position)); } else { Utils.PrintDebug("Could not read MIDI file - invalid TimeSignature meta event (Position: " + br.BaseStream.Position + ")"); throw new FormatException("Could not read MIDI file - invalid TimeSignature meta event (Position: " + br.BaseStream.Position + ")"); } break; case MetaEventType.KeySignature: if (lenData1 == 2) { sbyte key = br.ReadSByte(); byte flats = (byte)key; byte sharps = 0; if (key < 0) { flats = 0; sharps = (byte)(key * -1); } bool minor = Convert.ToBoolean(br.ReadByte()); metaEvents.Add(new KeySignatureEvent(track, deltaTime, absTime, key, minor)); Utils.PrintDebug(string.Format("META: {0} {1} {2} {3} {4} {5}", metaCode.ToString(), key, sharps, flats, minor, br.BaseStream.Position)); } else { Utils.PrintDebug("Could not read MIDI file - invalid KeySignature meta event (Position: " + br.BaseStream.Position + ")"); throw new FormatException("Could not read MIDI file - invalid KeySignature meta event (Position: " + br.BaseStream.Position + ")"); } break; default: byte[] data = br.ReadBytes(lenData1); Utils.PrintDebug(string.Format("META: {0} {1}", metaCode.ToString(), br.BaseStream.Position)); break; } break; default: // MIDI Event // Get first half of first byte byte first = (byte)((eventHeader & 0xF0) >> 4); // Get second half of first byte byte last = (byte)(eventHeader & 0x0F); if (first == 0xF) // System Message { if (last == 0x0 || last == 0x7) // Sysex Event { byte[] data = br.ReadBytes((int)Utils.ReadVariableLengthUint(br)); metaEvents.Add(new SysExEvent(track, deltaTime, absTime, data)); Utils.PrintDebug(string.Format("SYSEX: {0}", br.BaseStream.Position)); } else { Utils.PrintDebug("System messages are not supported (Position: " + br.BaseStream.Position + ")"); throw new NotImplementedException("System messages are not supported (Position: " + br.BaseStream.Position + ")"); } } else // Standard Midi Event { // Get event data, assume status has been carried for now // Get type of MIDI event MidiEventType eventType = (MidiEventType)((statusOld & 0xF0) >> 4); // Get channel of MIDI event byte channel = (byte)(eventHeader & 0x0F); // Indicates that old data is being used bool usingOld = true; if (Enum.IsDefined(typeof(MidiEventType), first)) // New status code { // Use new status values eventType = (MidiEventType)first; channel = last; usingOld = false; statusOld = eventHeader; // Update temporary status record } // Get event specific data switch (eventType) { case MidiEventType.NoteOff: byte key1 = eventHeader; if (!usingOld) { key1 = br.ReadByte(); } byte vel1 = br.ReadByte(); midiEvents.Add(new NoteOffEvent(channel, track, deltaTime, absTime, key1, vel1)); Utils.PrintDebug(string.Format("MIDI: {0} {1} {2} {3}", eventType.ToString(), key1, vel1, br.BaseStream.Position)); break; case MidiEventType.NoteOn: byte key2 = eventHeader; if (!usingOld) { key2 = br.ReadByte(); } byte vel2 = br.ReadByte(); midiEvents.Add(new NoteOnEvent(channel, track, deltaTime, absTime, key2, vel2)); Utils.PrintDebug(string.Format("MIDI: {0} {1} {2} {3}", eventType.ToString(), key2, vel2, br.BaseStream.Position)); break; case MidiEventType.PolyphonicKeyPressure: byte key3 = eventHeader; if (!usingOld) { key3 = br.ReadByte(); } byte vel3 = br.ReadByte(); midiEvents.Add(new PolyphonicKeyPressureEvent(channel, track, deltaTime, absTime, key3, vel3)); Utils.PrintDebug(string.Format("MIDI: {0} {1} {2} {3}", eventType.ToString(), key3, vel3, br.BaseStream.Position)); break; case MidiEventType.ControlChange: byte controller = eventHeader; if (!usingOld) { controller = br.ReadByte(); } byte value = br.ReadByte(); midiEvents.Add(new ControlChangeEvent(channel, track, deltaTime, absTime, controller, value)); Utils.PrintDebug(string.Format("MIDI: {0} {1} {2} {3}", eventType.ToString(), controller, value, br.BaseStream.Position)); break; case MidiEventType.InstrumentChange: byte patch = eventHeader; if (!usingOld) { patch = br.ReadByte(); } midiEvents.Add(new InstrumentChangeEvent(channel, track, deltaTime, absTime, patch)); Utils.PrintDebug(string.Format("MIDI: {0} {1} {2}", eventType.ToString(), patch, br.BaseStream.Position)); break; case MidiEventType.ChannelPressure: byte pressure = eventHeader; if (!usingOld) { pressure = br.ReadByte(); } midiEvents.Add(new ChannelPressureEvent(channel, track, deltaTime, absTime, pressure)); Utils.PrintDebug(string.Format("MIDI: {0} {1} {2}", eventType.ToString(), pressure, br.BaseStream.Position)); break; case MidiEventType.PitchWeelChange: byte p1 = eventHeader; if (!usingOld) { p1 = br.ReadByte(); } byte p2 = br.ReadByte(); ushort pitch = (ushort)((p2 << 8) + p1); midiEvents.Add(new PitchWheelChangeEvent(channel, track, deltaTime, absTime, pitch)); Utils.PrintDebug(string.Format("MIDI: {0} {1} {2}", eventType.ToString(), pitch, br.BaseStream.Position)); break; } } break; } track++; } tracks.Add(new TrackChunk(metaEvents.ToArray(), midiEvents.ToArray())); } else { // Unrecognised track chunk Utils.PrintDebug("Could not read MIDI file - invalid chunk"); throw new FormatException("Could not read MIDI file - invalid chunk"); } } // Update public tracks this.tracks = tracks.ToArray(); Utils.PrintDebug("-----------------\r\nLoad Complete\r\n-----------------"); } else { // Header chunk was not 6 bytes long Utils.PrintDebug("Could not read MIDI file - unexpected header chunk length"); throw new FormatException("Could not read MIDI file - unexpected header chunk length"); } } else { // Header cunk missing / corrupted Utils.PrintDebug("Could not read MIDI file - header chunk missing"); throw new FormatException("Could not read MIDI file - header chunk missing"); } } }
/// <summary> /// Initializes a new instance of the <see cref="ChannelEvent"/> with the specified parameters count. /// </summary> /// <param name="eventType">The type of event.</param> /// <param name="parametersCount">Count of the parameters for this channel event.</param> protected ChannelEvent(MidiEventType eventType, int parametersCount) : base(eventType) { _parameters = new byte[parametersCount]; }
/// <summary> /// Initializes a new instance of the <see cref="SysExEvent"/> with the specified event type. /// </summary> /// <param name="eventType">The type of event.</param> /// <exception cref="InvalidEnumArgumentException"><paramref name="eventType"/> specified an invalid value.</exception> protected SysExEvent(MidiEventType eventType) : base(eventType) { }
public static List <MidiEvent> GetEventsOfType(string base64encodedMidiFile, MidiEventType type) { var midiFile = MidiFile.Read(base64encodedMidiFile); return(GetEventsOfType(midiFile, type)); }
/// <summary> /// Initializes a new instance of the <see cref="NoteEvent"/>. /// </summary> protected NoteEvent(MidiEventType eventType) : base(eventType, ParametersCount) { }
/// <summary> /// Initializes a new instance of the <see cref="NoteEvent"/> with the specified /// note number and velocity. /// </summary> /// <param name="eventType">The type of event.</param> /// <param name="noteNumber">Note number.</param> /// <param name="velocity">Velocity.</param> /// <exception cref="InvalidEnumArgumentException"><paramref name="eventType"/> specified an invalid value.</exception> protected NoteEvent(MidiEventType eventType, SevenBitNumber noteNumber, SevenBitNumber velocity) : this(eventType) { NoteNumber = noteNumber; Velocity = velocity; }
public void SetEventType(MidiEventType eventTypeIn) { eventType = eventTypeIn; }
/// <summary> /// Initializes a new instance of the <see cref="SystemCommonEvent"/> with the specified event type. /// </summary> /// <param name="eventType">The type of event.</param> /// <exception cref="InvalidEnumArgumentException"><paramref name="eventType"/> specified an invalid value.</exception> protected SystemCommonEvent(MidiEventType eventType) : base(eventType) { }
/// <summary> /// Initializes a new instance of the <see cref="BaseTextEvent"/>. /// </summary> public BaseTextEvent(MidiEventType eventType) : base(eventType) { }
/// <summary> /// Initializes a new instance of the <see cref="MidiEvent"/> with the specified event type. /// </summary> /// <param name="eventType">The type of event.</param> public MidiEvent(MidiEventType eventType) { EventType = eventType; }
private MidiEvent(byte channel, MidiEventType type, byte[] data) { Channel = channel; Type = type; DataBytes = data; }
/// <summary> /// Initializes a new instance of the <see cref="MetaEvent"/> with the specified event type. /// </summary> /// <param name="eventType">The type of event.</param> /// <exception cref="InvalidEnumArgumentException"><paramref name="eventType"/> specified an invalid value.</exception> protected MetaEvent(MidiEventType eventType) : base(eventType) { }
private int ParseChannelEvent(int index, uint time, byte type) { uint channel = (uint)(type & 0x0F); MidiEventType eventType = (MidiEventType)(type & 0xF0); ChannelEvent channelEvent = new ChannelEvent(); channelEvent.SetChannel(channel); channelEvent.SetTime(time); channelEvent.SetEventType(eventType); Console.WriteLine("--- Channel: " + channel); Console.WriteLine("--- Time: " + time); Console.WriteLine("--- Event Type: " + eventType); byte param1; byte param2; switch (eventType) { case MidiEventType.NoteOn: param1 = midi[index++]; param2 = midi[index++]; channelEvent.SetParam1(param1); channelEvent.SetParam2(param2); if (param2 == 0) { channelEvent.SetEventType(MidiEventType.NoteOff); } Console.WriteLine("--- Note: " + param1); Console.WriteLine("--- Velocity: " + param2); break; case MidiEventType.NoteOff: param1 = midi[index++]; param2 = midi[index++]; channelEvent.SetParam1(param1); channelEvent.SetParam2(param2); Console.WriteLine("--- Note: " + param1); Console.WriteLine("--- Velocity: " + param2); break; case MidiEventType.NoteAftertouch: param1 = midi[index++]; param2 = midi[index++]; channelEvent.SetParam1(param1); channelEvent.SetParam2(param2); Console.WriteLine("--- Note: " + param1); Console.WriteLine("--- Amount: " + param2); break; case MidiEventType.Controller: param1 = midi[index++]; param2 = midi[index++]; channelEvent.SetParam1(param1); channelEvent.SetParam2(param2); Console.WriteLine("--- Controller: " + param1); Console.WriteLine("--- Value: " + param2); break; case MidiEventType.ProgramChange: param1 = midi[index++]; channelEvent.SetParam1(param1); Console.WriteLine("--- Program: " + param1); break; case MidiEventType.ChannelAftertouch: param1 = midi[index++]; channelEvent.SetParam1(param1); Console.WriteLine("--- Amount: " + param1); break; case MidiEventType.PitchBend: param1 = midi[index++]; param2 = midi[index++]; channelEvent.SetParam1(param1); channelEvent.SetParam2(param2); Console.WriteLine("--- LSB Value: " + param1); Console.WriteLine("--- MSB Value: " + param2); break; default: return(-1); } midiEvents.Add(channelEvent); return(index); }
/// <summary> /// Initializes a new instance of the <see cref="SystemRealTimeEvent"/> with the specified event type. /// </summary> /// <param name="eventType">The type of event.</param> protected SystemRealTimeEvent(MidiEventType eventType) : base(eventType) { }
internal InvalidChannelEventParameterValueException(MidiEventType eventType, byte value) : base($"{value} is invalid value for parameter of channel event of {eventType} type.") { EventType = eventType; Value = value; }
/// <summary> /// Initializes a new instance of the <see cref="BaseTextEvent"/> with the specified text. /// </summary> /// <param name="eventType">The type of event.</param> /// <param name="text">Text contained in the event.</param> /// <exception cref="InvalidEnumArgumentException"><paramref name="eventType"/> specified an invalid value.</exception> public BaseTextEvent(MidiEventType eventType, string text) : this(eventType) { Text = text; }
/// <summary> /// Initialises the <see cref="MidiEvent"/>. /// </summary> /// <param name="channel">The channel of the event.</param> /// <param name="track">The track of the event.</param> /// <param name="deltaTime">The delta time of the event.</param> /// <param name="absoluteTime">The absolute time of the event.</param> /// <param name="type">The type of the event.</param> protected void Init(byte channel, uint track, uint deltaTime, uint absoluteTime, MidiEventType type) { Init(track, deltaTime, absoluteTime); this.channel = channel; this.type = type; }