/// <summary> /// 指定されたイベントの後ろにイベントを挿入する /// </summary> /// <param name="TargetEvent">このイベントの後ろに新たに入る</param> /// <param name="Step">Step値</param> /// <param name="EventType">イベントタイプ</param> /// <param name="MIDImessage">MIDIメッセージ(Chは0固定であること)</param> /// <returns>新たに挿入したイベント</returns> public MIDIEvent insertEvent(MIDIEvent TargetEvent, int Step, MIDIEventType EventType, byte[] MIDImessage) { if (MIDImessage == null) { return(null); } MIDIEvent eve = new MIDIEvent(); eve.EventType = EventType; eve.MIDIMessage = MIDImessage; eve.MIDIMessageLst = null; eve.Step = Step; insertEve(TargetEvent, Step, eve); return(eve); }
/// <summary> /// Tickを考慮せずに最後のイベントの後ろに追加する。 /// </summary> /// <param name="Tick"></param> /// <param name="EventType"></param> /// <param name="MIDImessage"></param> public void addEvent(int Step, MIDIEventType EventType, byte[] MIDImessage) { if (MIDImessage == null) { return; } MIDIEvent eve = new MIDIEvent(); eve.EventType = EventType; eve.MIDIMessage = MIDImessage; eve.MIDIMessageLst = null; eve.Step = Step; MIDIEvent lastEvent = this.getEndEvent(); if (lastEvent == null)//初めのイベント { eve.AfterIndex = null; eve.BeforeIndex = null; eve.Number = this.eNumber; this.Event.Add(eve); this.eStartIndex = 0; this.eEndIndex = 0; this.eCounter = 1; this.eNumber++; return; } eve.BeforeIndex = lastEvent.Number; eve.AfterIndex = null; eve.Number = this.eNumber; this.eEndIndex = this.eNumber; this.Event.Add(eve); this.eCounter++; this.eNumber++; lastEvent.AfterIndex = eve.Number; }
public MIDIEvent(int delta, byte type) { Delta = delta; RawType = type; Type = GetEventType(type); }
IMIDIEvent GetNextEvent() { int delta = dReader.Read7BitEncodedInt32(); byte type = dReader.ReadByte(); if (type < 0x80) { // data byte found if (runningStatus && lastEvent != null) { // if running status the read type byte is actually the first databyte if (lastEvent.Type == MIDIEventType.ProgramChange || lastEvent.Type == MIDIEventType.KeyPressure) { return(new MIDIChannelEvent(delta, lastEvent.RawType, type, 0)); } else { byte secondData = dReader.ReadByte(); return(new MIDIChannelEvent(delta, lastEvent.RawType, type, secondData)); } } throw new InvalidDataException("data byte found but running status not set"); } else { MIDIEventType eType = MIDIEvent.GetEventType(type); byte data1, data2; switch (eType) { case MIDIEventType.ProgramChange: case MIDIEventType.KeyPressure: data1 = dReader.ReadByte(); lastEvent = new MIDIChannelEvent(delta, type, data1, 0); break; case MIDIEventType.NoteOff: case MIDIEventType.NoteOn: case MIDIEventType.PolyphonicKeyPressure: case MIDIEventType.ControllerChange: case MIDIEventType.ChannelPitchBend: data1 = dReader.ReadByte(); data2 = dReader.ReadByte(); lastEvent = new MIDIChannelEvent(delta, type, data1, data2); break; case MIDIEventType.Meta: data1 = dReader.ReadByte(); int length = dReader.Read7BitEncodedInt32(); byte[] buffer = dReader.ReadBytes(length); lastEvent = new MIDIMetaEvent(delta, type, data1, buffer); break; default: throw new NotImplementedException("unknown MIDI Event found !"); } if (type >= 0xF0 && runningStatus) { runningStatus = false; } else { runningStatus = true; } return(lastEvent); } }