示例#1
0
//		public byte[] GetMetaStringValue(int offset)
//		{
//			return (SmfFileHandle[SelectedTrackNumber, offset, 3]);
//		}
        public byte[] GetMetaValue(int offset)
        {
            switch ((MetaMsgU16FF)SmfFileHandle.Get16BitInt32(SelectedTrackNumber, offset))
            {
            //0xff00
            case MetaMsgU16FF.SequenceNo:
                return(SmfFileHandle[SelectedTrackNumber, offset, 5]);

            //MetaHelpers.meta_FF00(SmfFileHandle[SelectedTrackNumber,offset+3],SmfFileHandle[SelectedTrackNumber,offset+4]);
            //0xff20
            case MetaMsgU16FF.Chanel:
                return(SmfFileHandle[SelectedTrackNumber, offset, 4]);

            //SmfFileHandle[SelectedTrackNumber,offset+3].ToString() /*SmfStringFormatter.meta_FF20( trk, pos+3 )*/;
            //0xff51
            case MetaMsgU16FF.Tempo:
                return(SmfFileHandle[SelectedTrackNumber, offset, 6]);

            //MetaHelpers.meta_FF51(Convert.ToInt32(SmfFileHandle[SelectedTrackNumber].Get24Bit(offset+3)));
            //0xff54:
            case MetaMsgU16FF.SMPTE:
                return(SmfFileHandle[SelectedTrackNumber, offset, 4]);

            //MetaHelpers.meta_FF54(); // "?"
            //0xff58:
            case MetaMsgU16FF.TimeSignature:
                return(SmfFileHandle[SelectedTrackNumber, offset, 7]);

            //MetaHelpers.meta_FF58(SmfFileHandle[SelectedTrackNumber],3,4,5,6);
            //0xff59:
            case MetaMsgU16FF.KeySignature:
                return(SmfFileHandle[SelectedTrackNumber, offset, 5]);

            //MetaHelpers.meta_FF59(SmfFileHandle[SelectedTrackNumber],3,4);
            //0xff2f
            case MetaMsgU16FF.EndOfTrack:
                return(SmfFileHandle[SelectedTrackNumber, offset, 2]);

            //0xff7f
            case MetaMsgU16FF.SystemSpecific:
                return(SmfFileHandle[SelectedTrackNumber, offset, 3]);

            //0xff7f
            case MetaMsgU16FF.SystemExclusive:
                return(SmfFileHandle[SelectedTrackNumber, offset, 4]);

            default:
                string msg = string.Format("We're not sure how to handle this message {0:X4} {1:X2}.  Treating data as META event.", RunningStatus32, SmfFileHandle[SelectedTrackNumber, offset + 1]);
                MessageBox.Show(msg, "Press OK to continue", MessageBoxButtons.OK);
                return(SmfFileHandle[SelectedTrackNumber, offset, SmfFileHandle[SelectedTrackNumber, offset + 2] + 3]);
            }
        }
示例#2
0
        string GetEventString(int offset, int plus)
        {
            int ExpandedRSE = RunningStatus32 << 8;

            if (!MidiMessageInfo.IsMidiBMessage(RunningStatus32))
            {
                Debug.Assert(false, string.Format("warning… {0:X2}", ExpandedRSE));
                return(null);
            }
            else if (MidiMessageInfo.IsNoteOn(ExpandedRSE))
            {
                return(GetNoteMsg(0, offset + plus, m9));
            }
            else if (MidiMessageInfo.IsNoteOff(ExpandedRSE))
            {
                return(GetNoteMsg(0, offset + plus, m8));
            }
            else if (MidiMessageInfo.IsKeyAftertouch(ExpandedRSE))
            {
                return(string.Format(mA, SmfFileHandle[SelectedTrackNumber, offset + plus], SmfFileHandle[SelectedTrackNumber, offset + plus + 1]));
            }
            else if (MidiMessageInfo.IsControlChange(ExpandedRSE))
            {
                return(string.Format(mB, SmfStringFormatter.cc[SmfFileHandle.Get8Bit(SelectedTrackNumber, offset + plus)].Replace((char)0xa, (char)0x20).Trim(), SmfFileHandle.Get8Bit(SelectedTrackNumber, offset + plus + 1)));
            }
            else if (MidiMessageInfo.IsProgramChange(ExpandedRSE))
            {
                return(SmfStringFormatter.patches[SmfFileHandle[SelectedTrackNumber, offset + plus]].Replace((char)0xa, (char)0x20).Trim());
            }
            else if (MidiMessageInfo.IsChannelAftertouch(ExpandedRSE))
            {
                return(MidiMessageInfo.ChannelAftertouchRange.Name);
            }
            else if (MidiMessageInfo.IsPitchBend(ExpandedRSE))
            {
                return(MidiMessageInfo.PitchBendRange.Name);
            }
            else if (MidiMessageInfo.IsSystemMessage(ExpandedRSE))
            {
                return(MidiMessageInfo.SystemExclusiveMessageRange.Name);
            }
            else if (MidiMessageInfo.IsSystemCommon(ExpandedRSE))
            {
                return(MidiMessageInfo.SystemCommonMessageRange.Name);
            }
            else if (MidiMessageInfo.IsSystemRealtime(ExpandedRSE))
            {
                return(MidiMessageInfo.SystemRealtimeMessageRange.Name);
            }
            return(null);
        }
示例#3
0
        /// MESSAGE PARSER see 'ParseTrackMeta'
        public virtual int GetTrackTiming(int ntrack, int position, int delta)
        {
            int  DELTA_Returned    = delta;
            byte CurrentByte       = SmfFileHandle.Get8Bit(ntrack, position);
            int  CurrentIntMessage = SmfFileHandle.Get16BitInt32(ntrack, position);

            switch (CurrentIntMessage)
            {
            case (int)MetaMsgU16FF.Text:
            case (int)MetaMsgU16FF.Copyright:
            case (int)MetaMsgU16FF.SequenceName:
            case (int)MetaMsgU16FF.InstrumentName:
            case (int)MetaMsgU16FF.Lyric:
            case (int)MetaMsgU16FF.Marker:
            case (int)MetaMsgU16FF.Cue:
            case (int)MetaMsgU16FF.Port:
            case (int)MetaMsgU16FF.SequenceNo:
            case (int)MetaMsgU16FF.Chanel:
            case (int)MetaMsgU16FF.EndOfTrack:
            case (int)MetaMsgU16FF.SMPTE:
                DELTA_Returned = GetMetaNextPos(position);
                break;

            case (int)MetaMsgU16FF.Tempo:
                MidiTimeInfo.Tempo = 60000000 / Convert.ToInt32(SmfFileHandle[ntrack].Get24Bit(position + 3));
                DELTA_Returned     = GetMetaNextPos(position);
                break;

            case (int)MetaMsgU16FF.TimeSignature:
                TimeSignature.SetSignature(
                    (int)this[ntrack, position + 3],
                    (int)Math.Pow(-this[ntrack, position + 4], 2),
                    (int)this[ntrack, position + 5],
                    (int)this[ntrack, position + 6]
                    );
                DELTA_Returned = GetMetaNextPos(position);
                break;

            case (int)MetaMsgU16FF.KeySignature:
                byte b = (this[ntrack, position + 3]);
                KeySignature.SetSignature((KeySignatureType)b, this[ntrack, position + 4] == 0);
                DELTA_Returned = GetMetaNextPos(position);
                break;

            case (int)MetaMsgU16FF.SystemSpecific:
            case (int)MetaMsgU16FF.SystemExclusive:
                DELTA_Returned = GetMetaNextPos(position);
                break;

            default:
            {
                if (CurrentByte < 0x80)
                {
                    // Running Status
                    int ExpandedRSE = RunningStatus32 << 8;
                    int delta1      = -1;
                    if ((delta1 = GetNextRsePosition(position)) == -1)
                    {
                        int test = GetOffset(position);
                        Debug.Assert(false, string.Format("warning… {0:X2}, {1:X}|{1:N0}", ExpandedRSE, test));
                    }
                    else
                    {
                        DELTA_Returned = delta1;
                    }
                }
                else if (MidiMessageInfo.IsMidiMessage(CurrentIntMessage))
                {
                    RunningStatus32 = (SmfFileHandle[ntrack, position]);
                    DELTA_Returned  = GetNextPosition(position);
                    DELTA_Returned++;
                    return(DELTA_Returned);
                }
                else
                {
                    throw new FormatException("Bad format!\nThere is probably a problem with the Input File unless we made an error reading it!)");
                }
            }

            break;
            }
            DELTA_Returned++;
            return(DELTA_Returned);
        }
示例#4
0
        /// MESSAGE PARSER
        /// get track (specific) message
        public virtual int GetNTrackMessage(int ntrack, int position, int delta)
        {
            int  DELTA_Returned    = delta;
            byte CurrentByte       = SmfFileHandle.Get8Bit(ntrack, position);
            int  CurrentIntMessage = SmfFileHandle.Get16BitInt32(ntrack, position);

            switch (CurrentIntMessage)
            {
            case (int)MetaMsgU16FF.Text:
            // FF01
            case (int)MetaMsgU16FF.Copyright:
            // FF02
            case (int)MetaMsgU16FF.SequenceName:
            // FF03
            case (int)MetaMsgU16FF.InstrumentName:
            // FF04
            case (int)MetaMsgU16FF.Lyric:
            // FF05
            case (int)MetaMsgU16FF.Marker:
            // FF06
            case (int)MetaMsgU16FF.Cue:
            // FF07
            case (int)MetaMsgU16FF.Port:
                // FF08
                this.MessageHandler(MidiMsgType.MetaStr, ntrack, position, CurrentIntMessage, CurrentByte, TicksPerQuarterNote, RunningStatus32, false);
                //lve.AddItem( c4, MeasureBarTick( TicksPerQuarterNote ), TicksPerQuarterNote.ToString(), ""/*(RunningStatus32 & 0x0F)+1*/, MetaHelpers.MetaNameFF( CurrentIntMessage ) , GetMetaString( position ) );
                DELTA_Returned = GetMetaNextPos(position);
                break;

            case (int)MetaMsgU16FF.SequenceNo:
            // FF00
            case (int)MetaMsgU16FF.Chanel:
            // FF20
            case (int)MetaMsgU16FF.EndOfTrack:
            // FF2F
            case (int)MetaMsgU16FF.Tempo:
            // FF51
            case (int)MetaMsgU16FF.SMPTE:
            // FF54
            case (int)MetaMsgU16FF.TimeSignature:
            // FF58
            case (int)MetaMsgU16FF.KeySignature:
                // FF59
                // why is this filtered and no others ? see gettrackmessage
                this.MessageHandler(MidiMsgType.MetaInf, ntrack, position, CurrentIntMessage, CurrentByte, TicksPerQuarterNote, RunningStatus32, false);
                DELTA_Returned = GetMetaNextPos(position);
                break;

            case (int)MetaMsgU16FF.SystemSpecific:
            // FF7F
            case (int)MetaMsgU16FF.SystemExclusive:
                // FF7F
                Debug.Print("?---------sys");
                this.MessageHandler(MidiMsgType.System, ntrack, position, CurrentIntMessage, CurrentByte, TicksPerQuarterNote, RunningStatus32, false);
                DELTA_Returned = GetMetaNextPos(position);
                break;

            default:
            {
                if (CurrentByte < 0x80)
                {
                    // Running Status
                    int ExpandedRSE = RunningStatus32 << 8;
                    int delta1      = -1;
                    if ((delta1 = GetNextRsePosition(position)) == -1)
                    {
                        int test = GetOffset(position);
                        Debug.Assert(false, string.Format("warning… {0:X2}, {1:X}|{1:N0}", ExpandedRSE, test));
                    }
                    else
                    {
                        DELTA_Returned = delta1;
                        this.MessageHandler(GetMsgTyp(RunningStatus32), ntrack, position, RunningStatus32, (byte)RunningStatus32, TicksPerQuarterNote, RunningStatus32, true);
                    }
                }
                else if (MidiMessageInfo.IsMidiMessage(CurrentIntMessage))
                {
                    RunningStatus32 = (SmfFileHandle[ntrack, position]);
                    DELTA_Returned  = GetNextPosition(position);
//							Debug.Print("{0:X}",runningStatus32);
                    this.MessageHandler(GetMsgTyp(RunningStatus32), ntrack, position, RunningStatus32, (byte)RunningStatus32, TicksPerQuarterNote, RunningStatus32, false);
                    DELTA_Returned++;
                    return(DELTA_Returned);
                }
                else
                {
                    throw new FormatException("Bad format!\nThere is probably a problem with the Input File unless we made an error reading it!)");
                }
            }

            break;
            }
            DELTA_Returned++;
            // what is roy[1] if not the current track position?
            return(DELTA_Returned);
        }
示例#5
0
        //
        // META STRING
        // ---------------
        #region Meta STRING Helpers

        /// <summary>
        /// Return a string value per meta-event or throw exception.
        /// </summary>
        /// <param name="trk"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        public string GetMetaSTR(int offset)
        {
            int flag = SmfFileHandle.Get16BitInt32(SelectedTrackNumber, offset);

            switch ((MetaMsgU16FF)flag)
            {
            //0xff00
            case MetaMsgU16FF.SequenceNo:
                return(MetaHelpers.meta_FF00(
                           SmfFileHandle[SelectedTrackNumber, offset + 3],
                           SmfFileHandle[SelectedTrackNumber, offset + 4]
                           ));

            //0xff20
            case MetaMsgU16FF.Chanel:
                /*SmfStringFormatter.meta_FF20( trk, pos+3 )*/
                return(SmfFileHandle[SelectedTrackNumber, offset + 3].ToString());

            //0xff51
            case MetaMsgU16FF.Tempo:
                return(MetaHelpers.meta_FF51(Convert.ToInt32(SmfFileHandle[SelectedTrackNumber].Get24Bit(offset + 3))));

            //0xff54:
            case MetaMsgU16FF.SMPTE:
                return(MetaHelpers.meta_FF54());

            // "?"
            //0xff58:
            case MetaMsgU16FF.TimeSignature:
                return(MetaHelpers.meta_FF58(SmfFileHandle[SelectedTrackNumber], offset));

            //0xff59:
            case MetaMsgU16FF.KeySignature:
                return(MetaHelpers.meta_FF59(SmfFileHandle[SelectedTrackNumber], offset));

            //0xff2f
            case MetaMsgU16FF.EndOfTrack:
                return(MetaHelpers.meta_FF2F());

            //0xff7f
            case MetaMsgU16FF.SystemSpecific:                     // actually 'Sequencer-Specific Meta-Event'
                //Sequencer Specific
                long result     = 0;
                int  nextOffset = GetIntVar(offset + 2, out result) - offset;
                return(SmfFileHandle[SelectedTrackNumber, offset, Convert.ToInt32(result) + 3].StringifyHex());

            case MetaMsgU16FF.SystemExclusive:
                //System Exclusive
                long result1     = 0;
                int  nextOffset1 = GetIntVar(offset + 1, out result1) - offset;
                return(SmfFileHandle[SelectedTrackNumber, offset, Convert.ToInt32(result1) + 4].StringifyHex());

            default:
                // check for a channel message
                if (runningStatus32 == 0xF0)
                {
                    long ro = 0;
                    int  no = GetIntVar(offset + 1, out ro) - offset;
                    return(SmfFileHandle[SelectedTrackNumber, offset, Convert.ToInt32(ro) + 2].StringifyHex());
                }
                string msg = string.Format(
                    "We're not sure how to handle this message {0:X4} {1:X2}.  Treating data as META event.",
                    RunningStatus32,
                    SmfFileHandle[SelectedTrackNumber, offset, 2].StringifyHex()
                    );
                MessageBox.Show(msg, "Press OK to continue", MessageBoxButtons.OK);
                return(System.Text.Encoding.UTF8.GetString(SmfFileHandle[SelectedTrackNumber, offset, SmfFileHandle[SelectedTrackNumber, offset + 2] + 3]));
            }
        }