using System;
using System.IO;
namespace NAudio.Midi
{
///
/// SMPTE Offset Event
///
public class SmpteOffsetEvent : MetaEvent
{
private readonly byte hours;
private readonly byte minutes;
private readonly byte seconds;
private readonly byte frames;
private readonly byte subFrames; // 100ths of a frame
///
/// Creates a new time signature event
///
public SmpteOffsetEvent(byte hours, byte minutes, byte seconds, byte frames, byte subFrames)
{
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
this.frames = frames;
this.subFrames = subFrames;
}
///
/// Reads a new time signature event from a MIDI stream
///
/// The MIDI stream
/// The data length
public SmpteOffsetEvent(BinaryReader br,int length)
{
if(length != 5)
{
throw new FormatException(String.Format("Invalid SMPTE Offset length: Got {0}, expected 5",length));
}
hours = br.ReadByte();
minutes = br.ReadByte();
seconds = br.ReadByte();
frames = br.ReadByte();
subFrames = br.ReadByte();
}
///
/// Creates a deep clone of this MIDI event.
///
public override MidiEvent Clone() => (SmpteOffsetEvent)MemberwiseClone();
///
/// Hours
///
public int Hours => hours;
///
/// Minutes
///
public int Minutes => minutes;
///
/// Seconds
///
public int Seconds => seconds;
///
/// Frames
///
public int Frames => frames;
///
/// SubFrames
///
public int SubFrames => subFrames;
///
/// Describes this time signature event
///
/// A string describing this event
public override string ToString()
{
return String.Format("{0} {1}:{2}:{3}:{4}:{5}",
base.ToString(),hours,minutes,seconds,frames,subFrames);
}
///
/// 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(hours);
writer.Write(minutes);
writer.Write(seconds);
writer.Write(frames);
writer.Write(subFrames);
}
}
}