// Methods internal override bool MoveNext() { if (_currentChunk == null) { return(false); } if (_currentChunkIndex >= _currentChunk._count - 1) { if (_currentChunk._next == null) { return(false); } else { _currentChunk = _currentChunk._next; _currentChunkIndex = 0; Debug.Assert(_currentChunk._count > 0); return(true); } } else { _currentChunkIndex++; return(true); } }
public void ReadAdtlChunk(Byte[] InData) { Chunks = new List <ListChunk>(); var dataReader = new BinaryReader(new MemoryStream(InData), Encoding.ASCII); while (dataReader.BaseStream.Position < dataReader.BaseStream.Length) { var type = new String(dataReader.ReadChars(4)); uint size = dataReader.ReadUInt32(); if (size % 2 != 0) // account for padding { size += 1; } byte[] ChunkData = dataReader.ReadBytes((int)size); ListChunk newChunk = null; switch (type) { case LiCkAdtlType.labl: newChunk = new LiCkInfoLabl(ChunkData); break; case LiCkAdtlType.note: newChunk = new LiCkNote(ChunkData); break; case LiCkAdtlType.ltxt: newChunk = new LiCkLtxt(ChunkData); break; } if (newChunk != null) { Chunks.Add(newChunk); } } }
/// <summary> /// Move to the next list (branch) of nodes /// </summary> /// <returns>Moved to the next list of nodes</returns> public override bool MoveNext() { if (this.currentChunk == null) { return(false); } if (this.currentChunkIndex >= this.currentChunk.Count - 1) { if (this.currentChunk.Next == null) { return(false); } else { this.currentChunk = this.currentChunk.Next; this.currentChunkIndex = 0; Debug.Assert(this.currentChunk.Count > 0); return(true); } } else { this.currentChunkIndex++; return(true); } }
// Overriden methods public override XmlNode Item(int index) { if (_chunks == null) { return(null); } if (index < ListChunk.ChunkSize) { return(_chunks[index]); } int chunkNo = index / ListChunk.ChunkSize; ListChunk curChunk = _chunks; while (chunkNo > 0) { curChunk = curChunk._next; chunkNo--; Debug.Assert(curChunk != null); } return(curChunk[index % ListChunk.ChunkSize]); }
public RiffContext(Stream stream, Action <iRiffChunk> consume, ListChunk root) { this.stream = stream; this.consume = consume; currentOffset = 12; pushList(root.contentTag, root.size); }
private static Dictionary <int, (WaveSampleChunk, int)> AddSamples(Config config, DLS dls) { ListChunk waves = dls.WavePool; var sampleDict = new Dictionary <int, (WaveSampleChunk, int)>((int)config.SampleTableSize); for (int i = 0; i < config.SampleTableSize; i++) { int ofs = config.Reader.ReadInt32(config.SampleTableOffset + (i * 4)); if (ofs == 0) { continue; // Skip null samples } ofs += config.SampleTableOffset; SampleHeader sh = config.Reader.ReadObject <SampleHeader>(ofs); // Create format chunk var fmt = new FormatChunk(WaveFormat.PCM); fmt.WaveInfo.Channels = 1; fmt.WaveInfo.SamplesPerSec = (uint)(sh.SampleRate >> 10); fmt.WaveInfo.AvgBytesPerSec = fmt.WaveInfo.SamplesPerSec; fmt.WaveInfo.BlockAlign = 1; fmt.FormatInfo.BitsPerSample = 8; // Create wave sample chunk and add loop if there is one var wsmp = new WaveSampleChunk { UnityNote = 60, Options = WaveSampleOptions.NoTruncation | WaveSampleOptions.NoCompression }; if (sh.DoesLoop == 0x40000000) { wsmp.Loop = new WaveSampleLoop { LoopStart = (uint)sh.LoopOffset, LoopLength = (uint)(sh.Length - sh.LoopOffset), LoopType = LoopType.Forward }; } // Get PCM sample byte[] pcm = new byte[sh.Length]; Array.Copy(config.ROM, ofs + 0x10, pcm, 0, sh.Length); // Add int dlsIndex = waves.Count; waves.Add(new ListChunk("wave") { fmt, wsmp, new DataChunk(pcm), new ListChunk("INFO") { new InfoSubChunk("INAM", $"Sample {i}") } }); sampleDict.Add(i, (wsmp, dlsIndex)); } return(sampleDict); }
private static void AddInfo(Config config, DLS dls) { var info = new ListChunk("INFO"); dls.Add(info); info.Add(new InfoSubChunk("INAM", config.Name)); //info.Add(new InfoSubChunk("ICOP", config.Creator)); info.Add(new InfoSubChunk("IENG", "Kermalis")); info.Add(new InfoSubChunk("ISFT", Util.Utils.ProgramName)); }
internal override void AddNode(XmlNode node) { if (this._lastChunk == null) { this._chunks = new ListChunk(); this._lastChunk = this._chunks; } else if (this._lastChunk._count == 10) { this._lastChunk._next = new ListChunk(); this._lastChunk = this._lastChunk._next; } this._lastChunk.AddNode(node); ++this._count; }
private ListChunk GetListChunk(Guid contentGuid, string languageCode, int currentChunk) { var currentCulture = CultureInfo.GetCultureInfo(languageCode); var currentPage = ContentLoader.Service.Get <NewsListPage>(contentGuid, currentCulture); var years = ContentLoader.Service.GetChildren <PageData>(currentPage.ContentLink, currentCulture); var allPages = new List <PageData>(); foreach (var year in years) { var yearPage = ContentLoader.Service.Get <PageData>(year.ContentLink, currentCulture); var listPages = ContentLoader.Service.GetChildren <PageData>(yearPage.ContentLink, currentCulture).ToList(); foreach (var listPage in listPages) { allPages.Add(listPage); } } var pageSize = 2; var totalNoOfItems = allPages.Count; var chunkedListPages = allPages.Skip(currentChunk * pageSize).Take(pageSize).ToList(); var list = new ContentArea(); foreach (var newsPage in chunkedListPages) { list.Items.Add(new ContentAreaItem { ContentLink = newsPage.ContentLink }); } var nextPage = currentChunk + 1; var viewModel = new ListChunk { List = list, ShowNextPage = totalNoOfItems > nextPage * pageSize, NextPage = nextPage, LanguageCode = currentPage.Language.Name, ContentGuid = currentPage.ContentGuid, ReadMoreNewsListText = "Show more", FallbackUrl = $"{UrlResolver.Service.GetUrl(currentPage.ContentLink)}{nextPage}", LoadMoreUrl = $"{UrlResolver.Service.GetUrl(currentPage.ContentLink)}more" }; return(viewModel); }
// Methods internal override void AddNode( XmlNode node ) { if ( _lastChunk == null ) { _chunks = new ListChunk(); _lastChunk = _chunks; } else if ( _lastChunk._count == ListChunk.ChunkSize ) { _lastChunk._next = new ListChunk(); _lastChunk = _lastChunk._next; } _lastChunk.AddNode( node ); _count++; }
// Methods internal override void AddNode(XmlNode node) { if (_lastChunk == null) { _chunks = new ListChunk(); _lastChunk = _chunks; } else if (_lastChunk._count == ListChunk.ChunkSize) { _lastChunk._next = new ListChunk(); _lastChunk = _lastChunk._next; } _lastChunk.AddNode(node); _count++; }
/// <summary> /// Writes the content of the chunk <paramref name="instance"/> to the <see cref="P:CurrentStream"/>. /// </summary> /// <param name="instance">Must not be null.</param> /// <remarks>The <paramref name="instance"/> either has data fields or sub-chunks. Mixed content is not supported.</remarks> public void WriteRuntimeChunkType(object instance) { var objectReader = new ObjectMemberReader(instance); if (objectReader.IsChunkContainer) { object childObject = null; while (objectReader.GetNextChunkObject(out childObject)) { // property value is null, skip it. if (childObject == null) { continue; } if (objectReader.CurrentMemberIsCollection) { var collection = (IEnumerable <object>)childObject; if (objectReader.CurrentMemberIsListChunk) { // insert a LIST chunk. var listChunk = new ListChunk(); listChunk.InnerChunks = collection; this.WriteNextChunk(listChunk); } else { foreach (var item in collection) { this.WriteNextChunk(item); } } } else { this.WriteNextChunk(childObject); } } } else { objectReader.WriteFields(this); } }
/// <summary> /// Adds a node to the current list of data. /// </summary> /// <param name="node">Node object to add</param> public override void AddNode(XmlDiffViewNode node) { if (this.lastChunk == null) { this.chunks = new ListChunk(); this.lastChunk = this.chunks; this.currentChunk = this.chunks; } else if (this.lastChunk.Count == ListChunk.ChunkSize) { this.lastChunk.Next = new ListChunk(); this.lastChunk = this.lastChunk.Next; } this.lastChunk.AddNode(node); this.count++; }
public bool MoveNext() { if (this._currentChunk == null) { return(false); } if (this._currentChunkIndex >= this._currentChunk._count - 1) { if (this._currentChunk._next == null) { return(false); } this._currentChunk = this._currentChunk._next; this._currentChunkIndex = 0; return(true); } ++this._currentChunkIndex; return(true); }
internal override bool MoveNext() { if (this._currentChunk == null) { return(false); } if (this._currentChunkIndex >= this._currentChunk._count - 1) { if (this._currentChunk._next == null) { return(false); } this._currentChunk = this._currentChunk._next; this._currentChunkIndex = 0; Debug.Assert(this._currentChunk._count > 0); return(true); } ++this._currentChunkIndex; return(true); }
/// <summary>Parse a RIFF file</summary> public static void parse(Stream stream, Action <iRiffChunk> consumeChunk) { ListChunk list = stream.read <ListChunk>(); if (list.tag != RIFF) { throw new ArgumentException("The stream is not a RIFF file"); } if (list.size < 0) { throw new NotImplementedException("RIFF parser only works for files less than 2GB"); } if (list.size == 0) { throw new ArgumentException("The RIFF has no data"); } RiffContext context = new RiffContext(stream, consumeChunk, list); context.parse(); }
public bool MoveNext() { if ( _currentChunk == null ) return false; if ( _currentChunkIndex >= _currentChunk._count - 1 ) { if ( _currentChunk._next == null ) return false; else { _currentChunk = _currentChunk._next; _currentChunkIndex = 0; Debug.Assert( _currentChunk._count > 0 ); return true; } } else { _currentChunkIndex++; return true; } }
/// <summary> /// Reset the position in the lists of nodes. /// </summary> public override void Reset() { this.currentChunk = this.chunks; this.currentChunkIndex = -1; }
internal Enumerator(MultiNodeList nodeList) { _nodeList = nodeList; _currentChunk = nodeList._chunks; }
private bool Read(string filepath) { // check file existance if (!File.Exists(filepath)) { Console.WriteLine("Wave file does not exist."); return(false); } // set filestream this.Stream = new AudioStream(filepath, true); // check file length if (this.Stream.Length <= Wave.MinSize) { Console.WriteLine("Wave file too small."); return(false); } // read the headerchunk of the file if (!this.Header.Read(this.Stream)) { Console.WriteLine("Error reading wave file header."); return(false); } // check file formatchunk if (!this.Format.Read(this.Stream)) { Console.WriteLine("Error reading wave file format."); return(false); } // skip all list chunks ListChunk.SkipAll(this.Stream); // read all samples if (!this.Data.Read(this.Stream, this.Format)) { Console.WriteLine("Error reading wave file samples."); return(false); } // transform clip if (!this.TransformTo16()) { Console.WriteLine("Error transforming wave file into a 16bit PCM."); return(false); } // trim clip this.Data.Trim(); this.Header.Size = Wave.MinSize + this.Data.Size; #if DEBUG this.Header.Debug(); this.Format.Debug(); this.Data.Debug(); #endif return(true); }
internal override void Reset() { _currentChunk = _chunks; _currentChunkIndex = -1; }
/// <summary> /// Move to the next list (branch) of nodes /// </summary> /// <returns>Moved to the next list of nodes</returns> public override bool MoveNext() { if (this.currentChunk == null) { return false; } if (this.currentChunkIndex >= this.currentChunk.Count - 1) { if (this.currentChunk.Next == null) { return false; } else { this.currentChunk = this.currentChunk.Next; this.currentChunkIndex = 0; Debug.Assert(this.currentChunk.Count > 0); return true; } } else { this.currentChunkIndex++; return true; } }
internal override void Reset() { this._currentChunk = this._chunks; this._currentChunkIndex = -1; }
public void Reset() { this._currentChunk = this._nodeList._chunks; this._currentChunkIndex = -1; }
public void Reset() { _currentChunk = _nodeList._chunks; _currentChunkIndex = -1; }
internal Enumerator( MultiNodeList nodeList ) { _nodeList = nodeList; _currentChunk = nodeList._chunks; }