using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace NAudio.Midi
{
///
/// Represents a MIDI track sequence number event event
///
public class TrackSequenceNumberEvent : MetaEvent
{
private ushort sequenceNumber;
///
/// Creates a new track sequence number event
///
public TrackSequenceNumberEvent(ushort sequenceNumber)
{
this.sequenceNumber = sequenceNumber;
}
///
/// Reads a new track sequence number event from a MIDI stream
///
/// The MIDI stream
/// the data length
public TrackSequenceNumberEvent(BinaryReader br, int length)
{
// TODO: there is a form of the TrackSequenceNumberEvent that
// has a length of zero
if(length != 2)
{
throw new FormatException("Invalid sequence number length");
}
sequenceNumber = (ushort) ((br.ReadByte() << 8) + br.ReadByte());
}
///
/// Creates a deep clone of this MIDI event.
///
public override MidiEvent Clone() => (TrackSequenceNumberEvent)MemberwiseClone();
///
/// Describes this event
///
/// String describing the event
public override string ToString()
{
return String.Format("{0} {1}", base.ToString(), sequenceNumber);
}
///
/// Calls base class export first, then exports the data
/// specific to this event
/// MidiEvent.Export
///
public override void Export(ref long absoluteTime, BinaryWriter writer)
{
base.Export(ref absoluteTime, writer);
writer.Write((byte)((sequenceNumber >> 8) & 0xFF));
writer.Write((byte)(sequenceNumber & 0xFF));
}
}
}