private static void _ReadBehaviorData(XElement element, Vixen.Module.Sequence.SequenceBase sequence) { foreach (IRuntimeBehaviorModuleInstance runtimeBehavior in sequence.RuntimeBehaviors) { sequence.ModuleDataSet.GetModuleTypeData(runtimeBehavior); } }
private static void _ReadMedia(XElement element, Vixen.Module.Sequence.SequenceBase sequence) { foreach (IMediaModuleInstance media in sequence.Media) { sequence.ModuleDataSet.GetModuleInstanceData(media); } }
//static public void ReadXml<T>(XElement element, T sequence) static public void ReadXml(XElement element, Vixen.Module.Sequence.SequenceBase sequence) { //where T : Vixen.Module.Sequence.SequenceBase { Guid[] effectTable; Guid[] channelIdTable; element = element.Element("Sequence"); sequence.Length = int.Parse(element.Attribute("length").Value); // Timing _ReadTimingSource(element, sequence); // Module data _ReadModuleData(element, sequence); // Intervals _ReadIntervals(element, sequence); // Command table _ReadEffectTable(element, out effectTable); // Channel id table _ReadChannelIdTable(element, out channelIdTable); // Data nodes _ReadDataNodes(element, sequence, effectTable, channelIdTable); // Things that need to wait for other sequence data: // Runtime behavior module data _ReadBehaviorData(element, sequence); // Media module data _ReadMedia(element, sequence); sequence._ReadXml(element); }
private static void _ReadDataNodes(XElement element, Vixen.Module.Sequence.SequenceBase sequence, Guid[] effectTable, Guid[] channelIdTable) { byte[] bytes = new byte[2 * sizeof(ushort) + sizeof(byte)]; int effectIdIndex; int channelIdIndex; int channelIdCount; Guid effectId; List <OutputChannel> channels = new List <OutputChannel>(); byte parameterCount; List <object> parameters = new List <object>(); byte[] data; long dataLength; int startTime, timeSpan; // Data is stored as a base-64 stream from a binary stream. string dataString = element.Element("Data").Value; data = Convert.FromBase64String(dataString); using (MemoryStream dataStream = new MemoryStream(data)) { dataLength = dataStream.Length; while (dataStream.Position < dataLength) { channels.Clear(); parameters.Clear(); dataStream.Read(bytes, 0, bytes.Length); // Index of the command spec id from the command table (word). effectIdIndex = BitConverter.ToUInt16(bytes, 0 * sizeof(ushort)); // Referenced channel count (word). channelIdCount = BitConverter.ToUInt16(bytes, 1 * sizeof(ushort)); // Parameter count (byte) parameterCount = bytes[2 * sizeof(ushort)]; // Start time (dword). dataStream.Read(bytes, 0, sizeof(int)); startTime = BitConverter.ToInt32(bytes, 0); // Time span (dword). dataStream.Read(bytes, 0, sizeof(int)); timeSpan = BitConverter.ToInt32(bytes, 0); // Referenced channels (index into channel table, word). var outputChannels = Vixen.Sys.Execution.Fixtures.SelectMany(x => x.Channels); OutputChannel channel; while (channelIdCount-- > 0) { dataStream.Read(bytes, 0, sizeof(ushort)); channelIdIndex = BitConverter.ToUInt16(bytes, 0); // Channel may no longer exist. //channels.Add(sequence.OutputChannels.FirstOrDefault(x => x.Id == channelIdTable[channelIdIndex])); channel = outputChannels.FirstOrDefault(x => x.Id == channelIdTable[channelIdIndex]); if (channel != null) { channels.Add(channel); } } // Parameters (various) while (parameterCount-- > 0) { parameters.Add(ParameterValue.ReadFromStream(dataStream)); } // Get the effect inserted into the sequence. if (effectIdIndex < effectTable.Length) { effectId = effectTable[effectIdIndex]; if (Modules.IsValidId(effectId)) { sequence.InsertData(channels.ToArray(), startTime, timeSpan, new Command(effectId, parameters.ToArray())); } } } } }
private static void _ReadIntervals(XElement element, Vixen.Module.Sequence.SequenceBase sequence) { string[] intervalTimesString = element.Element("Intervals").Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); long[] intervalTimes = Array.ConvertAll(intervalTimesString, x => long.Parse(x)); sequence.Data.InsertIntervals(intervalTimes); }
private static void _ReadModuleData(XElement element, Vixen.Module.Sequence.SequenceBase sequence) { string moduleDataString = element.Element("ModuleData").Value; sequence.ModuleDataSet.Deserialize(moduleDataString); }
private static void _ReadTimingSource(XElement element, Vixen.Module.Sequence.SequenceBase sequence) { sequence.TimingProvider = TimingProviders.ReadXml(element, sequence); }