Exemplo n.º 1
0
        static private MidiMetaMessage ParseMidiMetaMessage(MidiFileFormatReader mffr)
        {
            MidiMetaMessage result = null;

            // Get message type
            EMetaEventType type = (EMetaEventType)mffr.ReadUInt8();

            // Get body length
            uint length = mffr.ReadVarLengthQuantity();

            switch (type)
            {
            case EMetaEventType.TrackSequenceNumber:
                result = new MidiMetaTrackSequenceNumberMessage(mffr.ReadUInt16());
                break;

            case EMetaEventType.TextEvent:
            case EMetaEventType.Copyright:
            case EMetaEventType.SequenceTrackName:
            case EMetaEventType.TrackInstrumentName:
            case EMetaEventType.Lyric:
            case EMetaEventType.Marker:
            case EMetaEventType.CuePoint:
            case EMetaEventType.ProgramName:
            case EMetaEventType.DeviceName:
            case EMetaEventType.MidiChannel:
                result = new MidiMetaTextMessage(type, mffr.ReadString(length));
                break;

            case EMetaEventType.MidiPort:
                result = new MidiMetaMidiPortMessage(mffr.ReadUInt8());
                break;

            case EMetaEventType.EndTrack:
                // No extra data for the end of track message
                result = new MidiMetaMessage(type);
                break;

            case EMetaEventType.SetTempo:
                result = new MidiMetaTempoMessage(mffr.ReadUInt24());
                break;

            case EMetaEventType.SmpteOffset:
                break;

            case EMetaEventType.TimeSignature:
                result = new MidiMetaTimeSignatureMessage(mffr.ReadUInt8(), mffr.ReadUInt8(), mffr.ReadUInt8(), mffr.ReadUInt8());
                break;

            case EMetaEventType.KeySignature:
                result = new MidiMetaKeySignatureMessage(mffr.ReadUInt8(), (mffr.ReadUInt8() != 0));
                break;

            case EMetaEventType.SequencerSpecific:
                // Read body
                byte[] body = new byte[length];
                for (int i = 0; i < length; i++)
                {
                    body[i] = mffr.ReadUInt8();
                }
                result = new MidiMetaMessage(type, body);

                break;

            default:
                throw new FormatException(string.Format("Found unknown or unsupported metaevent code {0}", type));
            }

            return(result);
        }
Exemplo n.º 2
0
 public SerMidiMetaTextMessage(MidiMetaTextMessage msg)
     : base(msg)
 {
     this.type = msg.Type;
     this.text = msg.Text;
 }
Exemplo n.º 3
0
 public MidiMetaMessage(EMetaEventType type, byte[] body)
     : base(EMidiCommand.MetaEvent, 0)
 {
     this.type = type;
     this.body = body;
 }
Exemplo n.º 4
0
 public MidiMetaMessage(EMetaEventType type)
     : this(type, null)
 {
 }
Exemplo n.º 5
0
 public MidiMetaTextMessage(EMetaEventType type, string text)
     : base(type)
 {
     this.text = text;
 }