private static int TrackVoiceStats(MidiEvent midiEvent, FastList <byte> instList, FastList <byte> drumList, FastList <byte> channelList, int noteOnCount) { if (midiEvent.Command == MidiEventTypeEnum.NoteOn) { var chan = midiEvent.Channel; if (channelList.IndexOf((byte)chan) == -1) { channelList.Add((byte)chan); } noteOnCount++; } else if (midiEvent.Command == MidiEventTypeEnum.ProgramChange) { var chan = midiEvent.Channel; var prog = midiEvent.Data1; if (chan == MidiHelper.DrumChannel) { if (drumList.IndexOf((byte)prog) == -1) { drumList.Add((byte)prog); } } else { if (instList.IndexOf((byte)prog) == -1) { instList.Add((byte)prog); } } } return(noteOnCount); }
public void Gather(NaturalResource res) { if (!IsCaptured) { return; } int nid = nearResource.IndexOf(res); if (nid == -1) { return; } resourceIndex = nid; NaturalResource exRes = ExResource; if (exRes != null) { harvester.Move(MathEx.Degree2Radian(exRes.Longitude), MathEx.Degree2Radian(exRes.Latitude)); harvester.SetMovePurpose(MovePurpose.Gather); } harvester.ExRes = exRes; }
public int AddString(string str) { // 在链表中查找索引,如果没找到则返回链表的Count int idx = table.IndexOf(str); if (idx != -1) { return(idx); } table.Push(str); return(++idx); }
public MidiTrack MergeTracks() { var eventCount = 0; var notesPlayed = 0; var programsUsed = new FastList <byte>(); var drumProgramsUsed = new FastList <byte>(); var channelsUsed = new FastList <byte>(); for (int x = 0; x < Tracks.Length; x++) { eventCount += Tracks[x].MidiEvents.Length; notesPlayed += Tracks[x].NoteOnCount; for (int i = 0; i < Tracks[x].Instruments.Length; i++) { var p = Tracks[x].Instruments[i]; if (programsUsed.IndexOf(p) == -1) { programsUsed.Add(p); } } for (int i = 0; i < Tracks[x].DrumInstruments.Length; i++) { var p = Tracks[x].DrumInstruments[i]; if (drumProgramsUsed.IndexOf(p) == -1) { drumProgramsUsed.Add(p); } } for (int i = 0; i < Tracks[x].ActiveChannels.Length; i++) { var p = Tracks[x].ActiveChannels[i]; if (channelsUsed.IndexOf(p) == -1) { channelsUsed.Add(p); } } } var track = new MidiTrack(programsUsed.ToArray(), drumProgramsUsed.ToArray(), channelsUsed.ToArray(), new MidiEvent[eventCount]); track.NoteOnCount = notesPlayed; return(track); }
private void PrepareLightGroups(RenderDrawContext context, FastList <RenderView> renderViews, RenderView renderView, RenderViewLightData renderViewData, IShadowMapRenderer shadowMapRenderer, RenderGroup group) { var viewIndex = renderViews.IndexOf(renderView); foreach (var activeRenderer in renderViewData.ActiveRenderers) { // Find lights var lightCollection = activeRenderer.LightGroup.FindLightCollectionByGroup(group); // Light collections aren't cleared (see ClearCache). Can be null after switching to empty scenes. if (lightCollection is null) { continue; } // Indices of lights in lightCollection that need processing lightIndicesToProcess.Clear(); for (int i = 0; i < lightCollection.Count; i++) { lightIndicesToProcess.Add(i); } // Loop over all the renderers in order int rendererIndex = 0; foreach (var renderer in activeRenderer.Renderers) { var processLightsParameters = new LightGroupRendererBase.ProcessLightsParameters { Context = context, ViewIndex = viewIndex, View = renderView, Views = renderViews, Renderers = activeRenderer.Renderers, RendererIndex = rendererIndex++, LightCollection = lightCollection, LightIndices = lightIndicesToProcess, LightType = activeRenderer.LightGroup.LightType, ShadowMapRenderer = shadowMapRenderer, ShadowMapTexturesPerLight = renderViewData.RenderLightsWithShadows, }; renderer.ProcessLights(processLightsParameters); } } }
private MidiTrack ReadTrack(IReadable input) { var instList = new FastList <Byte>(); var drumList = new FastList <Byte>(); var channelList = new FastList <Byte>(); var eventList = new FastList <MidiEvent>(); var noteOnCount = 0; var totalTime = 0; while (input.Read8BitChars(4) != "MTrk") { var length = input.ReadInt32BE(); while (length > 0) { length--; input.ReadByte(); } } var endPosition = input.ReadInt32BE() + input.Position; var prevStatus = 0; while (input.Position < endPosition) { var delta = ReadVariableLength(input); totalTime += delta; var status = input.ReadByte(); if (status >= 0x80 && status <= 0xEF) {//voice message prevStatus = status; eventList.Add(ReadVoiceMessage(input, delta, (byte)status, (byte)input.ReadByte())); noteOnCount = TrackVoiceStats(eventList[eventList.Count - 1], instList, drumList, channelList, noteOnCount); } else if (status >= 0xF0 && status <= 0xF7) {//system common message prevStatus = 0; eventList.Add(ReadSystemCommonMessage(input, delta, (byte)status)); } else if (status >= 0xF8 && status <= 0xFF) {//realtime message eventList.Add(ReadRealTimeMessage(input, delta, (byte)status)); } else { //data bytes if (prevStatus == 0) { //if no running status continue to next status byte while ((status & 0x80) != 0x80) { status = input.ReadByte(); } if (status >= 0x80 && status <= 0xEF) {//voice message prevStatus = status; eventList.Add(ReadVoiceMessage(input, delta, (byte)status, (byte)input.ReadByte())); noteOnCount = TrackVoiceStats(eventList[eventList.Count - 1], instList, drumList, channelList, noteOnCount); } else if (status >= 0xF0 && status <= 0xF7) {//system common message eventList.Add(ReadSystemCommonMessage(input, delta, (byte)status)); } else if (status >= 0xF8 && status <= 0xFF) {//realtime message eventList.Add(ReadRealTimeMessage(input, delta, (byte)status)); } } else {//otherwise apply running status eventList.Add(ReadVoiceMessage(input, delta, (byte)prevStatus, (byte)status)); noteOnCount = TrackVoiceStats(eventList[eventList.Count - 1], instList, drumList, channelList, noteOnCount); } } } if (input.Position != endPosition) { throw new Exception("The track length was invalid for the current MTrk chunk."); } if (channelList.IndexOf(MidiHelper.DrumChannel) != -1) { if (drumList.IndexOf(0) == -1) { drumList.Add(0); } } else { if (instList.IndexOf(0) == -1) { instList.Add(0); } } var track = new MidiTrack(instList.ToArray(), drumList.ToArray(), channelList.ToArray(), eventList.ToArray()); track.NoteOnCount = noteOnCount; track.EndTime = totalTime; return(track); }
public MidiTrack MergeTracks() { var eventCount = 0; var notesPlayed = 0; var programsUsed = new FastList<byte>(); var drumProgramsUsed = new FastList<byte>(); var channelsUsed = new FastList<byte>(); for (int x = 0; x < Tracks.Length; x++) { eventCount += Tracks[x].MidiEvents.Length; notesPlayed += Tracks[x].NoteOnCount; for (int i = 0; i < Tracks[x].Instruments.Length; i++) { var p = Tracks[x].Instruments[i]; if (programsUsed.IndexOf(p) == -1) programsUsed.Add(p); } for (int i = 0; i < Tracks[x].DrumInstruments.Length; i++) { var p = Tracks[x].DrumInstruments[i]; if (drumProgramsUsed.IndexOf(p) == -1) drumProgramsUsed.Add(p); } for (int i = 0; i < Tracks[x].ActiveChannels.Length; i++) { var p = Tracks[x].ActiveChannels[i]; if (channelsUsed.IndexOf(p) == -1) channelsUsed.Add(p); } } var track = new MidiTrack(programsUsed.ToArray(), drumProgramsUsed.ToArray(), channelsUsed.ToArray(), new MidiEvent[eventCount]); track.NoteOnCount = notesPlayed; return track; }
private static int TrackVoiceStats(MidiEvent midiEvent, FastList<byte> instList, FastList<byte> drumList, FastList<byte> channelList, int noteOnCount) { if (midiEvent.Command == MidiEventTypeEnum.NoteOn) { var chan = midiEvent.Channel; if (channelList.IndexOf((byte)chan) == -1) channelList.Add((byte)chan); noteOnCount++; } else if (midiEvent.Command == MidiEventTypeEnum.ProgramChange) { var chan = midiEvent.Channel; var prog = midiEvent.Data1; if (chan == MidiHelper.DrumChannel) { if (drumList.IndexOf((byte)prog) == -1) drumList.Add((byte)prog); } else { if (instList.IndexOf((byte)prog) == -1) instList.Add((byte)prog); } } return noteOnCount; }
private MidiTrack ReadTrack(IReadable input) { var instList = new FastList<Byte>(); var drumList = new FastList<Byte>(); var channelList = new FastList<Byte>(); var eventList = new FastList<MidiEvent>(); var noteOnCount = 0; var totalTime = 0; while (input.Read8BitChars(4) != "MTrk") { var length = input.ReadInt32BE(); while (length > 0) { length--; input.ReadByte(); } } var endPosition = input.ReadInt32BE() + input.Position; var prevStatus = 0; while (input.Position < endPosition) { var delta = ReadVariableLength(input); totalTime += delta; var status = input.ReadByte(); if (status >= 0x80 && status <= 0xEF) {//voice message prevStatus = status; eventList.Add(ReadVoiceMessage(input, delta, (byte)status, (byte)input.ReadByte())); noteOnCount = TrackVoiceStats(eventList[eventList.Count - 1], instList, drumList, channelList, noteOnCount); } else if (status >= 0xF0 && status <= 0xF7) {//system common message prevStatus = 0; eventList.Add(ReadSystemCommonMessage(input, delta, (byte)status)); } else if (status >= 0xF8 && status <= 0xFF) {//realtime message eventList.Add(ReadRealTimeMessage(input, delta, (byte)status)); } else {//data bytes if (prevStatus == 0) {//if no running status continue to next status byte while ((status & 0x80) != 0x80) { status = input.ReadByte(); } if (status >= 0x80 && status <= 0xEF) {//voice message prevStatus = status; eventList.Add(ReadVoiceMessage(input, delta, (byte)status, (byte)input.ReadByte())); noteOnCount = TrackVoiceStats(eventList[eventList.Count - 1], instList, drumList, channelList, noteOnCount); } else if (status >= 0xF0 && status <= 0xF7) {//system common message eventList.Add(ReadSystemCommonMessage(input, delta, (byte)status)); } else if (status >= 0xF8 && status <= 0xFF) {//realtime message eventList.Add(ReadRealTimeMessage(input, delta, (byte)status)); } } else {//otherwise apply running status eventList.Add(ReadVoiceMessage(input, delta, (byte)prevStatus, (byte)status)); noteOnCount = TrackVoiceStats(eventList[eventList.Count - 1], instList, drumList, channelList, noteOnCount); } } } if (input.Position != endPosition) throw new Exception("The track length was invalid for the current MTrk chunk."); if (channelList.IndexOf(MidiHelper.DrumChannel) != -1) { if (drumList.IndexOf(0) == -1) drumList.Add(0); } else { if (instList.IndexOf(0) == -1) instList.Add(0); } var track = new MidiTrack(instList.ToArray(), drumList.ToArray(), channelList.ToArray(), eventList.ToArray()); track.NoteOnCount = noteOnCount; track.EndTime = totalTime; return track; }