Exemplo n.º 1
0
 public void ConvertFromBinary(System.IO.BinaryReader reader)
 {
     //this.ChunkID = UtilBinary.ReadCharsValue(reader, 4);  ///read by MidiFile
     this.ChunkSize            = UtilBinary.ReadUintValue(reader);
     this.FormatType           = (TrackFormatType)UtilBinary.ReadUshortValue(reader);
     this.NumberOfTracks       = UtilBinary.ReadUshortValue(reader);
     this.PulsesPerQuarterNote = UtilBinary.ReadUshortValue(reader);
 }
Exemplo n.º 2
0
 public override void ConvertToBinary(System.IO.BinaryWriter writer)
 {
     if (this.DataLength > 0)
     {
         base.ConvertToBinary(writer);
         UtilBinary.WriteValue(writer, this.Text.ToCharArray());
     }
 }
Exemplo n.º 3
0
 public override void ConvertToBinary(System.IO.BinaryWriter writer)
 {
     if (this.DataLength > 0)
     {
         base.ConvertToBinary(writer);
         UtilBinary.WriteValue(writer, this.MicroSecondsPerQuarterNote, 3);
     }
 }
Exemplo n.º 4
0
 public void ConvertToBinary(System.IO.BinaryWriter writer)
 {
     UtilBinary.WriteValue(writer, this.ChunkID);
     UtilBinary.WriteValue(writer, this.GetSizeInBytes());
     UtilBinary.WriteValue(writer, (ushort)this.FormatType);
     UtilBinary.WriteValue(writer, this.NumberOfTracks);
     UtilBinary.WriteValue(writer, this.PulsesPerQuarterNote);
 }
Exemplo n.º 5
0
 public virtual void ConvertFromBinary(System.IO.BinaryReader reader)
 {
     byte[] typeAndChannelBytes = UtilBinary.SplitByte(reader.ReadByte());
     this.Type    = typeAndChannelBytes[0];
     this.Channel = typeAndChannelBytes[1];
     //this.Parameter1 = reader.ReadByte();
     //this.Parameter2 = reader.ReadByte();
 }
Exemplo n.º 6
0
 public override void ConvertToBinary(System.IO.BinaryWriter writer)
 {
     if (this.DataLength > 0)
     {
         base.ConvertToBinary(writer);
         UtilBinary.WriteValue(writer, this.Numerator);
         UtilBinary.WriteValue(writer, this.CalculateRawDenominator());
         UtilBinary.WriteValue(writer, this.MetronomePulse);
         UtilBinary.WriteValue(writer, this.ThirtySecondNotes);
     }
 }
Exemplo n.º 7
0
        //public static ChannelMidiEvent CreateNoteAfterTouchChannelMidiEvent(byte channel, byte noteNumber, byte aftertouchValue, uint deltaTime)
        //{
        //    return new ChannelMidiEvent(ChannelEventType.NoteAfterTouch, channel, noteNumber, aftertouchValue, deltaTime);
        //}

        //public static ChannelMidiEvent CreateControllerChannelMidiEvent(byte channel, byte controllerNumber, byte controllerValue, uint deltaTime)
        //{
        //    return new ChannelMidiEvent(ChannelEventType.Controller, channel, controllerNumber, controllerValue, deltaTime);
        //}

        //public static ChannelMidiEvent CreateProgramChangehannelMidiEvent(byte channel, byte programNumber, uint deltaTime)
        //{
        //    return new ChannelMidiEvent(ChannelEventType.ProgramChange, channel, programNumber, 0, deltaTime);
        //}

        //public static ChannelMidiEvent CreateChannelAftertouchChannelMidiEvent(byte channel, byte value, uint deltaTime)
        //{
        //    return new ChannelMidiEvent(ChannelEventType.ChannelAfterTouch, channel, value, 0, deltaTime);
        //}

        //public static ChannelMidiEvent CreatePitchBendChannelMidiEvent(byte channel, byte pitchValueLSB, byte pitchValueMSB, uint deltaTime)
        //{
        //    return new ChannelMidiEvent(ChannelEventType.PitchBend, channel, pitchValueLSB, pitchValueMSB, deltaTime);
        //}

        public override void ConvertToBinary(System.IO.BinaryWriter writer)
        {
            base.ConvertToBinary(writer);

            //if (this.Parameter2 == 0 && this.Type == ChannelEventType.NoteOn)
            //    UtilBinary.WriteValue(writer, UtilBinary.CombineBytes((byte)ChannelEventType.NoteOff, this.Channel));
            //else
            UtilBinary.WriteValue(writer, UtilBinary.CombineBytes((byte)this.Type, this.Channel));

            UtilBinary.WriteValue(writer, this.Parameter1);
            UtilBinary.WriteValue(writer, this.Parameter2);
        }
Exemplo n.º 8
0
        public KeySignatureEvent KeySignature;       // = new KeySignatureEvent();               // = 0x59

        public void ConvertToBinary(System.IO.BinaryWriter writer)
        {
            UtilBinary.WriteValue(writer, this.ChunkID);
            UtilBinary.WriteValue(writer, this.GetSizeInBytes());

            ///these will only get written only if there is actually data to write.

            if (this.SequenceNumber != null)
            {
                this.SequenceNumber.ConvertToBinary(writer);
            }

            if (this.Comments != null)
            {
                this.Comments.ConvertToBinary(writer);
            }

            if (this.CopyrightNotice != null)
            {
                this.CopyrightNotice.ConvertToBinary(writer);
            }

            if (this.TrackName != null)
            {
                this.TrackName.ConvertToBinary(writer);
            }

            if (this.InstrumentName != null)
            {
                this.InstrumentName.ConvertToBinary(writer);
            }

            if (this.Lyrics != null)
            {
                this.Lyrics.ConvertToBinary(writer);
            }

            if (this.Marker != null)
            {
                this.Marker.ConvertToBinary(writer);
            }

            if (this.CuePoint != null)
            {
                this.CuePoint.ConvertToBinary(writer);
            }

            if (this.DeviceName != null)
            {
                this.DeviceName.ConvertToBinary(writer);
            }

            if (this.Channel != null)
            {
                this.Channel.ConvertToBinary(writer);
            }

            if (this.Port != null)
            {
                this.Port.ConvertToBinary(writer);
            }

            if (this.Tempo != null)
            {
                this.Tempo.ConvertToBinary(writer);
            }

            if (this.SMPTEOffSet != null)
            {
                this.SMPTEOffSet.ConvertToBinary(writer);
            }

            if (this.TimeSignature != null)
            {
                this.TimeSignature.ConvertToBinary(writer);
            }

            if (this.KeySignature != null)
            {
                this.KeySignature.ConvertToBinary(writer);
            }

            foreach (ChannelMidiEvent chan in this.ChannelEvents)
            {
                chan.ConvertToBinary(writer);
                //Debug.Write(chan.ToString());
            }

            this.EndOfTrack.ConvertToBinary(writer);    //mandatory and must be at end
        }
Exemplo n.º 9
0
        public void ConvertFromBinary(System.IO.BinaryReader reader)
        {
            this.ChunkSize = UtilBinary.ReadUintValue(reader);

            ChannelEventType lastChannelEventType    = 0;// = ChannelEventType.Unknown;
            byte             lastChannelEventChannel = 0;

            while (true)
            {
                //Debug.WriteLine(reader.BaseStream.Position);

                uint deltaTicks     = UtilBinary.ReadVariableLengthValue(reader);
                byte trackEventType = UtilBinary.ReadByteValue(reader);

                if (trackEventType == (byte)0xFF)
                {
                    //Debug.WriteLine("*****************Meta Event********************");

                    MetaEventType metaEventType = (MetaEventType)UtilBinary.ReadByteValue(reader);

                    //Debug.WriteLine(metaEventType);

                    int lengthOfMetaData = 0;

                    //meta event
                    switch (metaEventType)
                    {
                    case MetaEventType.SequenceNumber:
                        UtilBinary.ReadByteValue(reader);
                        this.SequenceNumber = new SequenceNumberEvent(UtilBinary.ReadByteValue(reader), UtilBinary.ReadByteValue(reader));
                        break;

                    case MetaEventType.TextEvent:
                        lengthOfMetaData = (int)UtilBinary.ReadVariableLengthValue(reader);
                        this.Comments    = new TextEvent(new string(UtilBinary.ReadCharsValue(reader, lengthOfMetaData)));
                        //Debug.WriteLine(this.Comments.Text);
                        break;

                    case MetaEventType.CopyrightNotice:
                        lengthOfMetaData     = (int)UtilBinary.ReadVariableLengthValue(reader);
                        this.CopyrightNotice = new CopyrightNoticeEvent(new string(UtilBinary.ReadCharsValue(reader, lengthOfMetaData)));
                        //Debug.WriteLine(this.CopyrightNotice.Text);
                        break;

                    case MetaEventType.TrackName:
                        lengthOfMetaData = (int)UtilBinary.ReadVariableLengthValue(reader);
                        this.TrackName   = new TrackNameEvent(new string(UtilBinary.ReadCharsValue(reader, lengthOfMetaData)));
                        //Debug.WriteLine(this.TrackName.Text);
                        break;

                    case MetaEventType.InstrumentName:
                        lengthOfMetaData    = (int)UtilBinary.ReadVariableLengthValue(reader);
                        this.InstrumentName = new InstrumentNameEvent(new string(UtilBinary.ReadCharsValue(reader, lengthOfMetaData)));
                        //Debug.WriteLine(this.InstrumentName.Text);
                        break;

                    case MetaEventType.Lyrics:
                        lengthOfMetaData = (int)UtilBinary.ReadVariableLengthValue(reader);
                        this.Lyrics      = new LyricsEvent(new string(UtilBinary.ReadCharsValue(reader, lengthOfMetaData)));
                        //Debug.WriteLine(this.Lyrics.Text);
                        break;

                    case MetaEventType.Marker:
                        lengthOfMetaData = (int)UtilBinary.ReadVariableLengthValue(reader);
                        this.Marker      = new MarkerEvent(new string(UtilBinary.ReadCharsValue(reader, lengthOfMetaData)));
                        //Debug.WriteLine(this.Marker.Text);
                        break;

                    case MetaEventType.CuePoint:
                        lengthOfMetaData = (int)UtilBinary.ReadVariableLengthValue(reader);
                        this.CuePoint    = new CuePointEvent(new string(UtilBinary.ReadCharsValue(reader, lengthOfMetaData)));
                        //Debug.WriteLine(this.CuePoint.Text);
                        break;

                    case MetaEventType.DeviceName:
                        lengthOfMetaData = (int)UtilBinary.ReadVariableLengthValue(reader);
                        this.DeviceName  = new DeviceNameEvent(new string(UtilBinary.ReadCharsValue(reader, lengthOfMetaData)));
                        //Debug.WriteLine(this.DeviceName.Text);
                        break;

                    case MetaEventType.MidiChannel:
                        UtilBinary.ReadByteValue(reader);
                        this.Channel = new MidiChannelEvent(UtilBinary.ReadByteValue(reader));
                        //Debug.WriteLine(this.Channel.Channel);
                        break;

                    case MetaEventType.MidiPort:
                        UtilBinary.ReadByteValue(reader);
                        this.Port = new MidiPortEvent(UtilBinary.ReadByteValue(reader));
                        break;

                    case MetaEventType.EndOfTrack:
                        UtilBinary.ReadByteValue(reader);
                        //this.EndOfTrack = new EndOfTrackEvent();
                        //this.EndOfTrack.DeltaTicks = deltaTicks;
                        //Debug.WriteLine(this.EndOfTrack.ToString());
                        return;

                        break;

                    case MetaEventType.Tempo:
                        UtilBinary.ReadByteValue(reader);
                        uint microSecondsPerQuarterNote = UtilBinary.Read3ByteInteger(reader);
                        this.Tempo = new TempoEvent(microSecondsPerQuarterNote, this.TimeSignature.Denominator);
                        break;

                    case MetaEventType.SMPTEOffSet:
                        UtilBinary.ReadByteValue(reader);
                        this.SMPTEOffSet = new SMPTEOffSetEvent(UtilBinary.ReadByteValue(reader), UtilBinary.ReadByteValue(reader), UtilBinary.ReadByteValue(reader), UtilBinary.ReadByteValue(reader));
                        break;

                    case MetaEventType.TimeSignature:
                        UtilBinary.ReadByteValue(reader);
                        this.TimeSignature                   = new TimeSignatureEvent();
                        this.TimeSignature.Numerator         = UtilBinary.ReadByteValue(reader);
                        this.TimeSignature.Denominator       = (byte)Math.Pow(2, UtilBinary.ReadByteValue(reader));
                        this.TimeSignature.MetronomePulse    = UtilBinary.ReadByteValue(reader);
                        this.TimeSignature.ThirtySecondNotes = UtilBinary.ReadByteValue(reader);
                        //Debug.WriteLine(this.TimeSignature.ToString());
                        //this.Tempo = new TempoEvent(this.Tempo.MicroSecondsPerQuarterNote, this.TimeSignature.Denominator);
                        break;

                    case MetaEventType.KeySignature:
                        UtilBinary.ReadByteValue(reader);
                        this.KeySignature = new KeySignatureEvent(UtilBinary.ReadByteValue(reader), UtilBinary.ReadByteValue(reader));
                        break;

                    case MetaEventType.SequencerSpecific:
                        throw new NotImplementedException();
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    //Debug.WriteLine("---------------------");
                    //Debug.WriteLine(deltaTime);

                    //Debug.WriteLine(UtilBinary.ReadByteValue(reader));
                    //Debug.WriteLine(UtilBinary.ReadByteValue(reader));
                    //Debug.WriteLine(UtilBinary.ReadByteValue(reader));

                    ChannelMidiEvent chan = new ChannelMidiEvent();

                    chan.DeltaTicks = deltaTicks;
                    chan.File       = this.File;

                    byte[] typeAndChannelBytes = UtilBinary.SplitByte(trackEventType);
                    byte   typeOrData          = typeAndChannelBytes[0];

                    if (Enum.IsDefined(typeof(ChannelEventType), typeOrData))
                    {
                        chan.Type            = (ChannelEventType)typeOrData;
                        lastChannelEventType = chan.Type;

                        chan.Channel            = typeAndChannelBytes[1];
                        lastChannelEventChannel = chan.Channel;

                        chan.Parameter1 = UtilBinary.ReadByteValue(reader);
                        chan.Parameter2 = UtilBinary.ReadByteValue(reader);
                    }
                    else
                    {
                        chan.Type       = lastChannelEventType;
                        chan.Channel    = lastChannelEventChannel;
                        chan.Parameter1 = trackEventType;
                        chan.Parameter2 = UtilBinary.ReadByteValue(reader);
                    }

                    if (chan.Type == ChannelEventType.NoteOn && chan.Parameter2 == 0)
                    {
                        chan.Type = ChannelEventType.NoteOff;
                    }

                    //Debug.WriteLine(chan.Type.ToString());
                    //Debug.WriteLine(chan.Channel.ToString());

                    //this.File.Tracks[(int)chan.Channel].ChannelEvents.Add(chan);
                    this.ChannelEvents.Add(chan);

                    //Debug.Write(chan.ToString());
                }
            }
        }
Exemplo n.º 10
0
 public uint GetSizeInBytes()
 {
     return(UtilBinary.GetLengthOfVariableLengthValue(this.DeltaTicks) + sizeof(byte) + sizeof(byte) + sizeof(byte));
 }
Exemplo n.º 11
0
 public virtual void ConvertToBinary(System.IO.BinaryWriter writer)
 {
     UtilBinary.WriteVariableLengthValue(writer, this.DeltaTime); //use variable length binary
     UtilBinary.WriteValue(writer, UtilBinary.CombineBytes((byte)this.Type, this.Channel));
 }