Ejemplo n.º 1
0
        public void addWithID(int clock, int value, long id)
        {
            ensureBufferLength(length);
            int index = findIndexFromClock(clock);

            if (index >= 0)
            {
                VsqBPPair v = items[index];
                v.value      = value;
                v.id         = id;
                items[index] = v;
            }
            else
            {
                length++;
                ensureBufferLength(length);
                clocks[length - 1] = clock;
                Array.Sort(clocks, 0, length);
                index = findIndexFromClock(clock);
                for (int i = length - 1; i > index; i--)
                {
                    items[i] = items[i - 1];
                }
                items[index] = new VsqBPPair(value, id);
                maxId        = Math.Max(maxId, id);
            }
        }
Ejemplo n.º 2
0
        public void setData(string value)
        {
            length = 0;
            maxId  = 0;
            string[] spl = PortUtil.splitString(value, ',');
            for (int i = 0; i < spl.Length; i++)
            {
                string[] spl2 = PortUtil.splitString(spl[i], '=');
                if (spl2.Length < 2)
                {
                    continue;
                }
                try {
                    int clock = int.Parse(spl2[0]);
                    ensureBufferLength(length + 1);
                    clocks[length] = clock;
                    items[length]  = new VsqBPPair(int.Parse(spl2[1]), maxId + 1);
                    maxId++;
                    length++;
                } catch (Exception ex) {
                    serr.println("VsqBPList#setData; ex=" + ex);
#if DEBUG
                    sout.println("    i=" + i + "; spl2[0]=" + spl2[0] + "; spl2[1]=" + spl2[1]);
#endif
                }
            }
        }
Ejemplo n.º 3
0
        public long add(int clock, int value)
        {
            ensureBufferLength(length);
            int index = findIndexFromClock(clock);

            if (index >= 0)
            {
                VsqBPPair v = items[index];
                v.value      = value;
                items[index] = v;
                return(v.id);
            }
            else
            {
                length++;
                ensureBufferLength(length);
                clocks[length - 1] = clock;
                Array.Sort(clocks, 0, length);
                index = findIndexFromClock(clock);
                maxId++;
                for (int i = length - 1; i > index; i--)
                {
                    items[i] = items[i - 1];
                }
                items[index] = new VsqBPPair(value, maxId);
                return(maxId);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// コントロールカーブを編集するコマンドを発行します.
        /// </summary>
        /// <param name="track">編集対象のコントロールカーブが含まれるトラックの番号</param>
        /// <param name="target">編集対象のコントロールカーブ名</param>
        /// <param name="delete">削除を行うデータ点のリスト</param>
        /// <param name="add_or_move">追加または移動を行うデータ点のリスト</param>
        /// <returns></returns>
        public static VsqCommand generateCommandTrackCurveEdit2(int track, string target, List <long> delete, SortedDictionary <int, VsqBPPair> add)
        {
            VsqCommand command = new VsqCommand();

            command.Type    = VsqCommandType.TRACK_CURVE_EDIT2;
            command.Args    = new Object[4];
            command.Args[0] = track;
            command.Args[1] = target;
            List <long> cp_delete = new List <long>();

            foreach (var id in delete)
            {
                cp_delete.Add(id);
            }
            command.Args[2] = cp_delete;

            SortedDictionary <int, VsqBPPair> cp_add = new SortedDictionary <int, VsqBPPair>();

            foreach (var clock in add.Keys)
            {
                VsqBPPair item = add[clock];
                cp_add[clock] = item;
            }
            command.Args[3] = cp_add;
            return(command);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// データ点のIDを一度クリアし,新たに番号付けを行います.
 /// IDは,Redo,Undo用コマンドが使用するため,このメソッドを呼ぶとRedo,Undo操作が破綻する.XMLからのデシリアライズ直後のみ使用するべき.
 /// </summary>
 public void renumberIDs()
 {
     maxId = 0;
     for (int i = 0; i < length; i++)
     {
         maxId++;
         VsqBPPair v = items[i];
         v.id     = maxId;
         items[i] = v;
     }
 }
Ejemplo n.º 6
0
 public int findValueFromID(long id)
 {
     for (int i = 0; i < length; i++)
     {
         VsqBPPair item = items[i];
         if (item.id == id)
         {
             return(item.value);
         }
     }
     return(defaultValue);
 }
Ejemplo n.º 7
0
 public void setValueForID(long id, int value)
 {
     for (int i = 0; i < length; i++)
     {
         VsqBPPair item = items[i];
         if (item.id == id)
         {
             item.value = value;
             items[i]   = item;
             break;
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// コントロールカーブを編集するコマンドを発行します.
        /// </summary>
        /// <param name="track">編集対象のコントロールカーブが含まれるトラックの番号</param>
        /// <param name="target">編集対象のコントロールカーブ名</param>
        /// <param name="delete">削除を行うデータ点のリスト</param>
        /// <param name="add_or_move">追加または移動を行うデータ点のリスト</param>
        /// <returns></returns>
        public static VsqCommand generateCommandTrackCurveEdit2All(int track, List <string> target, List <List <long> > delete, List <SortedDictionary <int, VsqBPPair> > add)
        {
            VsqCommand command = new VsqCommand();

            command.Type    = VsqCommandType.TRACK_CURVE_EDIT2_ALL;
            command.Args    = new Object[4];
            command.Args[0] = track;
            List <string> cp_target = new List <string>();
            int           c         = target.Count;

            for (int i = 0; i < c; i++)
            {
                cp_target.Add(target[i]);
            }
            command.Args[1] = cp_target;

            List <List <long> > cp_vec_delete = new List <List <long> >();

            c = delete.Count;
            for (int i = 0; i < c; i++)
            {
                List <long> cp_delete = new List <long>();
                foreach (var id in delete[i])
                {
                    cp_delete.Add(id);
                }
                cp_vec_delete.Add(cp_delete);
            }
            command.Args[2] = cp_vec_delete;

            List <SortedDictionary <int, VsqBPPair> > cp_vec_add = new List <SortedDictionary <int, VsqBPPair> >();

            c = add.Count;
            for (int i = 0; i < c; i++)
            {
                SortedDictionary <int, VsqBPPair> cp_add = new SortedDictionary <int, VsqBPPair>();
                SortedDictionary <int, VsqBPPair> tmp    = add[i];
                foreach (var clock in tmp.Keys)
                {
                    VsqBPPair item = tmp[clock];
                    cp_add[clock] = item;
                }
                cp_vec_add.Add(cp_add);
            }
            command.Args[3] = cp_vec_add;
            return(command);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 指定したid値を持つVsqBPPairを検索し、その結果を返します。
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public VsqBPPairSearchContext findElement(long id)
        {
            VsqBPPairSearchContext context = new VsqBPPairSearchContext();

            for (int i = 0; i < length; i++)
            {
                VsqBPPair item = items[i];
                if (item.id == id)
                {
                    context.clock = clocks[i];
                    context.index = i;
                    context.point = item;
                    return(context);
                }
            }
            context.clock = -1;
            context.index = -1;
            context.point = new VsqBPPair(defaultValue, -1);
            return(context);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 時刻clockのデータを時刻new_clockに移動します。
        /// 時刻clockにデータがなければ何もしない。
        /// 時刻new_clockに既にデータがある場合、既存のデータは削除される。
        /// </summary>
        /// <param name="clock"></param>
        /// <param name="new_clock"></param>
        public void move(int clock, int new_clock, int new_value)
        {
            ensureBufferLength(length);
            int index = findIndexFromClock(clock);

            if (index < 0)
            {
                return;
            }
            VsqBPPair item = items[index];

            for (int i = index; i < length - 1; i++)
            {
                clocks[i] = clocks[i + 1];
                items[i]  = items[i + 1];
            }
            length--;
            int index_new = findIndexFromClock(new_clock);

            if (index_new >= 0)
            {
                item.value       = new_value;
                items[index_new] = item;
                return;
            }
            else
            {
                length++;
                ensureBufferLength(length);
                clocks[length - 1] = new_clock;
                Array.Sort(clocks, 0, length);
                index_new  = findIndexFromClock(new_clock);
                item.value = new_value;
                for (int i = length - 1; i > index_new; i--)
                {
                    items[i] = items[i - 1];
                }
                items[index_new] = item;
            }
        }