/// <summary> /// Return info from this MXFFile /// </summary> /// <param name="path"></param> /// <returns></returns> public string GetTrackInfo(int trackID) { try { List <MXFLogicalObject> lot = MXFLogicalObject.GetLogicChilds <MXFGenericTrack>(this.LogicalBase[typeof(MXFMaterialPackage)]); MXFLogicalObject track = lot.Where(a => ((MXFGenericTrack)a.Object).TrackID == trackID).FirstOrDefault(); if (track != null) { MXFGenericTrack gtrack = track.Object as MXFGenericTrack; if (gtrack != null) { StringBuilder sb = new StringBuilder(); sb.Append(string.Format("'{0}' ", gtrack.TrackName)); MXFTimelineTrack ttrack = gtrack as MXFTimelineTrack; if (ttrack != null) { sb.Append(string.Format("Rate: {0} ", ttrack.EditRate)); } MXFSequence seq = MXFLogicalObject.GetFirstChild <MXFSequence>(track); if (seq != null && seq.DataDefinition != null) { sb.Append(string.Format("Type: {0} ", seq.DataDefinition.Description)); } return(sb.ToString()); } } return(""); } catch (Exception) { } return(""); }
// TODO find better name, maybe Wrap public MXFLogicalObject CreateLogicalObject() { var wrapper = new MXFLogicalObject(this); this.LogicalWrapper = wrapper; return(wrapper); }
/// <summary> /// Add all children (recursively) /// </summary> /// <param name="lObj"></param> protected MXFLogicalObject LogicalAddChilds(MXFLogicalObject lObj) { // Check properties for reference MXFObject obj = lObj.Object; if (obj != null) { var desc = obj.Descendants().OfType <IResolvable>(); foreach (var r in desc) { // create and add the logical child var refObj = r.GetReference(); if (refObj != null) { MXFLogicalObject newLObj = refObj.CreateLogicalObject(); lObj.AddChild(newLObj); if (refObj.Children.Any()) { LogicalAddChilds(newLObj); } } } } return(lObj); }
/// <summary> /// Get all childs cast to the required type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="lo"></param> /// <returns></returns> public static List <T> GetChilds <T>(MXFLogicalObject lo) { if (lo.HasChildren) { return(lo.Children.Select(a => a.Object).Cast <T>().ToList()); } return(null); }
/// <summary> /// Get all childs cast to the required type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="lo"></param> /// <returns></returns> public static T GetFirstChild <T>(MXFLogicalObject lo) { if (lo.HasChildren) { return(lo.Children.Select(a => a.Object).Cast <T>().FirstOrDefault()); } return(default(T)); }
/// <summary> /// Get all childs cast to the required type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="lo"></param> /// <returns></returns> public static List <MXFLogicalObject> GetLogicChilds <T>(MXFLogicalObject lo) { if (lo.HasChildren) { return(lo.Children.Where(a => a.Object is T).ToList()); } return(null); }
/// <summary> /// Add a child /// </summary> /// <param name="child"></param> /// <returns></returns> public MXFLogicalObject AddChild(MXFLogicalObject child) { if (this.Children == null) { this.Children = new List <MXFLogicalObject>(); } child.Parent = this; this.Children.Add(child); return(child); }
/// <summary> /// Add all children (recusive) /// </summary> /// <param name="parent"></param> protected MXFLogicalObject LogicalAddChilds(MXFLogicalObject parent) { // Check properties for reference MXFObject reference = parent.Object; if (reference != null) { foreach (PropertyInfo propertyInfo in reference.GetType().GetProperties()) { if (propertyInfo.CanRead) { if (propertyInfo.PropertyType == typeof(MXFRefKey)) { // Found one! MXFRefKey refKey = (MXFRefKey)propertyInfo.GetValue(reference, null); if (refKey != null && refKey.Reference != null) { // Add the child MXFLogicalObject lo = new MXFLogicalObject(refKey.Reference, refKey.Reference.ToString()); parent.AddChild(lo); // Add all sub stuff LogicalAddChilds(lo); } } } } if (reference.HasChildren) { foreach (MXFObject child in reference.Children) { if (child.HasChildren) { foreach (MXFObject grandchild in child.Children) { MXFRefKey refKey = grandchild as MXFRefKey; if (refKey != null && refKey.Reference != null) { MXFLogicalObject lo = new MXFLogicalObject(refKey.Reference, refKey.Reference.ToString()); // Add the child parent.AddChild(lo); // Add all sub stuff LogicalAddChilds(lo); } } } } } } return(parent); }
public static T UnWrapAs <T>(this MXFLogicalObject lObj) where T : MXFObject { return(lObj.Object as T); }
/// <summary> /// Process a new KLV object /// </summary> /// <param name="klv"></param> /// <param name="partitions"></param> /// <param name="currentPartition"></param> /// <param name="partitionNumber"></param> /// <param name="allPrimerKeys"></param> private void ProcessKLVObject(MXFKLV klv, MXFObject partitions, ref MXFPartition currentPartition, ref int partitionNumber, ref Dictionary <UInt16, MXFEntryPrimer> allPrimerKeys) { // Is this a header, add to the partitions switch (klv.Key.Type) { case KeyType.Partition: currentPartition = klv as MXFPartition; currentPartition.File = this; currentPartition.PartitionNumber = partitionNumber; this.Partitions.Add(currentPartition); partitions.AddChild(currentPartition); partitionNumber++; break; case KeyType.PrimerPack: if (currentPartition != null) { MXFPrimerPack primer = klv as MXFPrimerPack; if (primer != null) // Just to be sure { // Let the partition know all primer keys allPrimerKeys = primer.AllKeys; currentPartition.PrimerKeys = primer.AllKeys; } currentPartition.AddChild(klv); // Add the primer } break; case KeyType.RIP: // Only add the RIP when not yet present if (this.RIP == null) { this.AddChild(klv); this.RIP = klv as MXFRIP; } break; case KeyType.SystemItem: if (currentPartition != null) { // Store the first system item for every partition // (required to calculate essence positions) if (currentPartition.FirstSystemItem == null) { currentPartition.FirstSystemItem = klv as MXFSystemItem; } currentPartition.AddChild(klv); } else { this.AddChild(klv); } // Store the first and the last system item if (this.FirstSystemItem == null) { this.FirstSystemItem = klv as MXFSystemItem; } this.LastSystemItem = klv as MXFSystemItem; break; case KeyType.Essence: if (currentPartition != null) { // Store the first system item for every partition // (required to calculate essence positions) MXFEssenceElement ee = klv as MXFEssenceElement; if (ee.IsPicture && currentPartition.FirstPictureEssenceElement == null) { currentPartition.FirstPictureEssenceElement = ee; } currentPartition.AddChild(klv); } else { this.AddChild(klv); } break; case KeyType.Preface: this.LogicalBase = new MXFLogicalObject(klv, klv.ToString()); // Normal if (currentPartition != null) { currentPartition.AddChild(klv); } else { this.AddChild(klv); } break; default: // Normal if (currentPartition != null) { currentPartition.AddChild(klv); } else { this.AddChild(klv); } break; } }