Ejemplo n.º 1
0
        /// <summary>
        /// 把整个灯光平移至某个时间格
        /// </summary>
        /// <param name="lightGroup"></param>
        /// <param name="startTime"></param>
        /// <returns></returns>
        public static List <Light> SetStartTime(List <Light> lightGroup, int startTime)
        {
            List <Light> ll = LightBusiness.Copy(lightGroup);

            if (ll.Count == 0)
            {
                return(ll);
            }
            ll = LightBusiness.Sort(ll);
            int addTime = startTime - ll[0].Time;

            for (int i = 0; i < ll.Count; i++)
            {
                ll[i].Time += addTime;
            }
            return(ll);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 写入Midi文件
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="mActionBeanList"></param>
        public void WriteMidiFile(String filePath, String fileName, List <Light> mActionBeanList, bool isWriteToFile)
        {
            fileName = "";
            List <char> StartStr = new List <char>
            {
                (char)77,
                (char)84,
                (char)104,
                (char)100,
                (char)0,
                (char)0,
                (char)0,
                (char)6,
                (char)0,
                (char)0,
                (char)0,
                (char)1,
                (char)0,
                (char)96,
                (char)77,
                (char)84,
                (char)114,
                (char)107,
                (char)0,
                (char)0,
                (char)0,
                (char)33
            };//文件头

            //StartStr.Add((char)0);
            //StartStr.Add((char)255);
            //StartStr.Add((char)3);
            //StartStr.Add((char)1);
            //StartStr.Add((char)0);
            if (isWriteToFile)
            {
                StartStr.Add((char)0); //00 ff 03 - 音轨名称
                StartStr.Add((char)255);
                StartStr.Add((char)3);
                if (Encoding.Default.BodyName.ToLower().Equals("gb2312") || Encoding.Default.BodyName.ToLower().Equals("big5"))
                {
                    StartStr.Add((char)(fileName.Length * 2));// 汉字编码2个字节
                }
                else
                {
                    StartStr.Add((char)fileName.Length);
                }
            }
            List <char> StartStr2 = new List <char>
            {
                (char)0,
                (char)255,
                (char)88,
                (char)4,
                (char)4,
                (char)2,
                (char)36,
                (char)8,
                (char)0,
                (char)255,
                (char)88,
                (char)4,
                (char)4,
                (char)2,
                (char)36,
                (char)8
            };//文件头

            List <char> EndStr = new List <char>
            {
                (char)0,
                (char)255,
                (char)47,
                (char)0
            };//文件尾

            String Action = WriteMidiContent(LightBusiness.Copy(mActionBeanList));
            //18 - 21 位置的数字可以由两种方法得出 20 + 动作次数(开始结束都算)* 4 或是 文件大小 - 22
            String Zero = "";
            String Size;

            if (isWriteToFile)
            {
                if (Encoding.Default.BodyName.ToLower().Equals("gb2312") || Encoding.Default.BodyName.ToLower().Equals("big5"))
                {
                    Size = System.Convert.ToString(20 + fileName.Length * 2 + mActionBeanList.Count * 4, 2);
                }
                else
                {
                    Size = System.Convert.ToString(20 + fileName.Length + mActionBeanList.Count * 4, 2);
                }
            }
            else
            {
                Size = System.Convert.ToString(20 + mActionBeanList.Count * 4, 2);
            }
            for (int j = 0; j < 32 - Size.Length; j++)
            {
                Zero += '0';
            }
            Size = Zero + Size;
            String one   = Size.Substring(0, 8);
            String two   = Size.Substring(8, 8);
            String three = Size.Substring(16, 8);
            String four  = Size.Substring(24, 8);

            StartStr[18] = (char)System.Convert.ToInt32(one, 2);
            StartStr[19] = (char)System.Convert.ToInt32(two, 2);
            StartStr[20] = (char)System.Convert.ToInt32(three, 2);
            StartStr[21] = (char)System.Convert.ToInt32(four, 2);
            StringBuilder line = new StringBuilder();

            for (int j = 0; j < StartStr.Count; j++)
            {
                line.Append(StartStr[j]);
            }
            //获得文件路径
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            FileStream f = new FileStream(filePath, FileMode.OpenOrCreate);

            for (int j = 0; j < line.Length; j++)
            {
                f.WriteByte((byte)line[j]);
            }
            line.Clear();

            //gb2312
            Byte[] bytess = Encoding.Default.GetBytes(fileName);
            foreach (Byte b in bytess)
            {
                f.WriteByte(b);
            }

            for (int j = 0; j < StartStr2.Count; j++)
            {
                line.Append(StartStr2[j]);
            }

            line.Append(Action);

            for (int j = 0; j < EndStr.Count; j++)
            {
                line.Append(EndStr[j]);
            }

            for (int j = 0; j < line.Length; j++)
            {
                f.WriteByte((byte)line[j]);
            }
            f.Close();
        }