internal IEnumerable <IContainer> ToContainers(ModuleSchema schema, ModuleJson module, ModuleAddress parentAddress, string?parentPath, SchemaVariables variables) { variables = variables.WithVariables(ExtraVariables); ModuleOffset offset = ModuleOffset.FromDisplayValue(Offset.Value); if (Repeat is null) { yield return(resolvedContainer.ToContainer(schema, module, ResolvedName, ResolvedDescription, parentAddress + offset, parentPath, variables)); } else { int gap = ModuleOffset.FromDisplayValue(Repeat.Gap.Value).LogicalValue; foreach (var tuple in module.GetRepeatSequence(Repeat.Items, variables)) { var itemVariables = variables.WithVariable(Repeat.IndexVariable, tuple.index, Repeat.IndexTemplate); var formattedDescription = tuple.variables.Replace(ResolvedDescription); var formattedName = Invariant($"{ResolvedName}[{tuple.index}]"); yield return(resolvedContainer.ToContainer(schema, module, formattedName, formattedDescription, parentAddress + offset, parentPath, itemVariables)); offset += gap; } } }
public IEnumerable <IField> ToFields(ModuleJson module, ModuleOffset offset) { AssertNotNull(ResolvedName); AssertNotNull(ResolvedDescription); if (Repeat is null) { yield return(ToField(module, ResolvedName, ResolvedDescription, offset)); } else { Preconditions.AssertNotNull(Repeat.Items); var variables = SchemaVariables.Empty; int?gap = Repeat.Gap?.Value; foreach (var tuple in module.GetRepeatSequence(Repeat.Items, variables)) { var itemVariables = variables.WithVariable(Repeat.IndexVariable, tuple.index); var formattedDescription = tuple.variables.Replace(ResolvedDescription); var formattedName = Invariant($"{ResolvedName}[{tuple.index}]"); var field = ToField(module, formattedName, formattedDescription, offset); yield return(field); offset += gap ?? field.Size; } } }
internal INodeDetail ToNodeDetail(ModuleJson module, IContainer nodeContainer, SchemaVariables nodeVariables) { Validation.Validate(Path is null ^ FormatPaths is null, "Exactly one of Path and FormatPaths must be specified"); if (Path is object) { var container = nodeContainer.ResolveContainer(nodeVariables.Replace(Path)); return(container is FieldContainer fc ? new FieldContainerNodeDetail(Description, fc) : throw new ArgumentException($"'{Path}' does not resolve to a field container")); } else { var formattableFields = module.GetRepeatSequence(Repeat, SchemaVariables.Empty) .ToReadOnlyList(tuple => FieldFormattableString.Create(nodeContainer, Format, FormatPaths, tuple.variables)); return(new ListNodeDetail(Description, formattableFields)); } }
internal IEnumerable <TreeNode> ToTreeNodes(ModuleJson json, string?parentNodePath, IContainer parentContainer) { Preconditions.AssertNotNull(Name); Preconditions.AssertNotNull(Path); Preconditions.AssertNotNull(Format); if (Repeat is null) { yield return(ToTreeNode(json, Name, parentContainer, SchemaVariables.Empty)); } else { foreach (var tuple in json.GetRepeatSequence(Repeat, SchemaVariables.Empty)) { string name = Invariant($"{Name}[{tuple.index}]"); yield return(ToTreeNode(json, name, parentContainer, tuple.variables)); } } TreeNode ToTreeNode(ModuleJson json, string name, IContainer parentContainer, SchemaVariables variables) { string nodePath = PathUtilities.AppendPath(parentNodePath, name); string?midiNotePath = MidiNotePath is null ? null : variables.Replace(MidiNotePath); var resolvedContainerPath = variables.Replace(Path !); var container = parentContainer.ResolveContainer(resolvedContainerPath); var formattableString = FieldFormattableString.Create(container, Format !, FormatPaths, variables); var childTreeNodes = new List <TreeNode>(); foreach (var child in Children) { childTreeNodes.AddRange(child.ToTreeNodes(json, nodePath, container)); } var treeDetails = Details.Select(detail => detail.ToNodeDetail(json, container, variables)).ToList().AsReadOnly(); return(new TreeNode(name, nodePath, container, formattableString, midiNotePath, childTreeNodes.AsReadOnly(), treeDetails)); } }