Class TrackChunk
Represents a track chunk of a standard MIDI file.
Inherited Members
Namespace: Melanchall.DryWetMidi.Core
Assembly: Melanchall.DryWetMidi.dll
Syntax
public sealed class TrackChunk : MidiChunk
Remarks
See https://midi.org/standard-midi-files-specification for detailed MIDI file specification.
Constructors
TrackChunk()
Initializes a new instance of the TrackChunk.
Declaration
public TrackChunk()
TrackChunk(params MidiEvent[])
Initializes a new instance of the TrackChunk with the specified events.
Declaration
public TrackChunk(params MidiEvent[] events)
Parameters
| Type | Name | Description |
|---|---|---|
| MidiEvent[] | events | Events to add to the track chunk. |
Remarks
Note that End Of Track events cannot be added into the collection since it may cause inconsistency in a
track chunk structure. End Of Track event will be written to the track chunk automatically on
Write(string, bool, MidiFileFormat, WritingSettings).
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | events is null. |
| ArgumentException | events contain an instance of EndOfTrackEvent; or
events contain null. |
TrackChunk(IEnumerable<MidiEvent>)
Initializes a new instance of the TrackChunk with the specified events.
Declaration
public TrackChunk(IEnumerable<MidiEvent> events)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<MidiEvent> | events | Events to add to the track chunk. |
Remarks
Note that End Of Track events cannot be added into the collection since it may cause inconsistency in a
track chunk structure. End Of Track event will be written to the track chunk automatically on
Write(string, bool, MidiFileFormat, WritingSettings).
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | events is null. |
Fields
Id
ID of the track chunk. This field is constant.
Declaration
public const string Id = "MTrk"
Field Value
| Type | Description |
|---|---|
| string |
Properties
Events
Gets the collection of events contained in the track chunk.
Declaration
public EventsCollection Events { get; }
Property Value
| Type | Description |
|---|---|
| EventsCollection |
Methods
Clone()
Clones chunk by creating a copy of it.
Declaration
public override MidiChunk Clone()
Returns
| Type | Description |
|---|---|
| MidiChunk | Copy of the chunk. |
Overrides
GetContentSize(WritingSettings)
Gets size of TrackChunk's content as number of bytes required to write it according
to specified WritingSettings.
Declaration
protected override uint GetContentSize(WritingSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| WritingSettings | settings | Settings according to which the chunk's content will be written. |
Returns
| Type | Description |
|---|---|
| uint | Number of bytes required to write TrackChunk's content. |
Overrides
ReadContent(MidiReader, ReadingSettings, uint)
Reads content of a TrackChunk.
Declaration
protected override void ReadContent(MidiReader reader, ReadingSettings settings, uint size)
Parameters
| Type | Name | Description |
|---|---|---|
| MidiReader | reader | Reader to read the chunk's content with. |
| ReadingSettings | settings | Settings according to which the chunk's content must be read. |
| uint | size | Expected size of the content taken from the chunk's header. |
Overrides
Remarks
Content of a TrackChunk is collection of MIDI events.
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | Method was called after the writer's underlying stream was disposed. |
| IOException | An I/O error occurred on the writer's underlying stream. |
| UnexpectedRunningStatusException | Unexpected running status is encountered. |
| UnknownChannelEventException | Reader has encountered an unknown channel event. |
| NotEnoughBytesException | Not enough bytes to read an event. |
| InvalidChannelEventParameterValueException | Value of a channel event's parameter just read is invalid. |
| MissedEndOfTrackEventException | Track chunk doesn't end with End Of Track event. |
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string that represents the current object. |
Overrides
WriteContent(MidiWriter, WritingSettings)
Writes content of a TrackChunk.
Declaration
protected override void WriteContent(MidiWriter writer, WritingSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| MidiWriter | writer | Writer to write the chunk's content with. |
| WritingSettings | settings | Settings according to which the chunk's content must be written. |
Overrides
Remarks
Content of a TrackChunk is collection of MIDI events.
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | Method was called after the writer's underlying stream was disposed. |
| IOException | An I/O error occurred on the writer's underlying stream. |