/// <summary> /// Initializes a new instance of the <see cref="MidiFile"/> with the specified chunks. /// </summary> /// <param name="chunks">Chunks to add to the file.</param> /// <remarks> /// Note that header chunks cannot be added into the collection since it may cause inconsistence in the file structure. /// Header chunk with appropriate information will be written to a file automatically on /// <see cref="Write(string, bool, MidiFileFormat, WritingSettings)"/>. /// </remarks> /// <exception cref="ArgumentNullException"><paramref name="chunks"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="chunks"/> contain instances of <see cref="HeaderChunk"/>; or /// <paramref name="chunks"/> contain null.</exception> public MidiFile(IEnumerable <MidiChunk> chunks) { if (chunks == null) { throw new ArgumentNullException(nameof(chunks)); } if (chunks.Any(c => c is HeaderChunk)) { throw new ArgumentException("Header chunk cannot be added to chunks collection.", nameof(chunks)); } if (chunks.Any(c => c == null)) { throw new ArgumentException("Null cannot be added to chunks collection.", nameof(chunks)); } Chunks.AddRange(chunks); }
public new void parse() { base.parse(); if (isRoot) { // Check version Chunk_Base version = getChunksByID(Chunk_MVER.Magic).FirstOrDefault(); if (version == null || !(version is Chunk_MVER)) { throw new WMOException("File is not a valid WMO file (missing version header)."); } // WMOv4 required. if (((Chunk_MVER)version).fileVersion != 17) { throw new WMOException("Unsupported WMO version!"); } // Root file needs to be a root file. if (!Chunks.Any(c => c.ChunkID == Chunk_MOHD.Magic)) { throw new WMOException("File is not a valid WMO file (missing root header)."); } // Parse all group files and import their chunks. foreach (WMOFile groupFile in groupFiles) { groupFile.parse(); Chunks.AddRange(groupFile.getChunks().Where(c => c.ChunkID != Chunk_MVER.Magic)); groupFile.flush(); } Log.Write("WMO: Root file loaded with {0} group file children.", groupFiles.Count); } }
/// <summary> /// Initializes a new instance of the <see cref="MidiFile"/> with the specified chunks. /// </summary> /// <param name="chunks">Chunks to add to the file.</param> /// <remarks> /// Note that header chunks cannot be added into the collection since it may cause inconsistence in the file structure. /// Header chunk with appropriate information will be written to a file automatically on /// <see cref="Write(string, bool, MidiFileFormat, WritingSettings)"/>. /// </remarks> /// <exception cref="ArgumentNullException"><paramref name="chunks"/> is null.</exception> public MidiFile(IEnumerable <MidiChunk> chunks) { ThrowIfArgument.IsNull(nameof(chunks), chunks); Chunks.AddRange(chunks); }
/// <summary> /// Initializes a new instance of the <see cref="MidiFile"/> with the specified chunks. /// </summary> /// <param name="chunks">Chunks to add to the file.</param> /// <remarks> /// Note that header chunks cannot be added into the collection since it may cause inconsistence in the file structure. /// Header chunk with appropriate information will be written to a file automatically on /// <see cref="Write(string, bool, MidiFileFormat, WritingSettings)"/>. /// </remarks> /// <exception cref="ArgumentNullException"><paramref name="chunks"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="chunks"/> contain instances of <see cref="HeaderChunk"/>; or /// <paramref name="chunks"/> contain null.</exception> public MidiFile(params MidiChunk[] chunks) { Chunks.AddRange(chunks); }