Exemplo n.º 1
0
        /// <summary>
        /// partを挿入する
        /// (既存partが増えると挿入位置を特定するのに時間がかかるようになるので注意)
        /// </summary>
        /// <param name="StartTick">絶対値によるTick値</param>
        /// <param name="prt">part</param>
        public void insertPart(int StartTick, MIDIPart prt)
        {
            if (prt == null)
            {
                return;
            }
            prt.StartTick = StartTick;

            if (this.Part == null)
            {
                this.Part = new List <MIDIPart>();
            }
            if (this.Part.Count == 0 || this.mStartIndex == null)//初めのprt
            {
                prt.AfterIndex  = null;
                prt.BeforeIndex = null;
                prt.Number      = this.mNumber;
                this.Part.Add(prt);
                this.mStartIndex = 0;
                this.mEndIndex   = 0;
                this.mCounter    = 1;
                this.mNumber++;
                return;
            }

            //遅くなる原因になっているループ
            MIDIPart pPrt = getStartPart();

            while (true)
            {
                if (pPrt.StartTick > prt.StartTick)
                {
                    pPrt = getPrevPart(pPrt);
                    break;
                }
                MIDIPart ppPrt = getNextPart(pPrt);
                if (ppPrt == null)
                {
                    break;
                }
                pPrt = ppPrt;
            }

            prt.BeforeIndex = pPrt.Number;
            prt.AfterIndex  = pPrt.AfterIndex;
            prt.Number      = this.mNumber;
            pPrt.AfterIndex = prt.Number;
            this.Part.Add(prt);
            if (prt.AfterIndex == null)
            {
                this.mEndIndex = this.mNumber;
            }
            else
            {
                pPrt             = getNextPart(prt);
                pPrt.BeforeIndex = prt.Number;
            }
            this.mCounter++;
            this.mNumber++;
        }
Exemplo n.º 2
0
        //指定したpartの前の小節を得る
        public MIDIPart getPrevPart(MIDIPart prt)
        {
            if (prt == null || prt.BeforeIndex == null)
            {
                return(null);
            }

            return(Part[(int)prt.BeforeIndex]);
        }
Exemplo n.º 3
0
        //指定したpartの次のpartを得る
        public MIDIPart getNextPart(MIDIPart prt)
        {
            if (prt == null || prt.AfterIndex == null)
            {
                return(null);
            }

            return(Part[(int)prt.AfterIndex]);
        }
Exemplo n.º 4
0
        //インデックスからpartを得る
        public MIDIPart searchPart(int index)
        {
            int st_d  = int.MaxValue;
            int ed_d  = int.MaxValue;
            int now_d = int.MaxValue;
            int mode  = -1;

            if (this.mStartIndex != null)
            {
                st_d = Math.Abs((int)this.mStartIndex - index);
            }
            if (this.mEndIndex != null)
            {
                ed_d = Math.Abs((int)this.mEndIndex - index);
            }
            if (this.NowPart != null)
            {
                now_d = Math.Abs(this.NowPart.Number - index);
            }
            MIDIPart prt = null;

            if (st_d < ed_d && st_d < now_d)
            {
                prt  = this.getStartPart();
                mode = 0;
            }
            else if (ed_d < st_d && ed_d < now_d)
            {
                prt  = this.getEndPart();
                mode = 1;
            }
            else if (now_d <= st_d && now_d <= ed_d)
            {
                prt = this.NowPart;
                if (prt.Number < index)
                {
                    mode = 0;
                }
                else
                {
                    mode = 1;
                }
            }
            else
            {
                return(null);
            }

            switch (mode)
            {
            case 0:
                while (prt != null)
                {
                    if (prt.Number == index)
                    {
                        return(prt);
                    }
                    prt = this.getNextPart(prt);
                }
                break;

            case 1:
                while (prt != null)
                {
                    if (prt.Number == index)
                    {
                        return(prt);
                    }
                    prt = this.getPrevPart(prt);
                }
                break;
            }

            return(null);
        }