コード例 #1
0
ファイル: FileBusiness.cs プロジェクト: hhm2maker/Maker
        /// <summary>
        /// 写入Midi文件内容
        /// </summary>
        /// <param name="filePath">Midi文件的内容</param>
        public String WriteMidiContent(List <Light> lab)
        {
            ReplaceControl(lab, midiArr);

            lab = LightBusiness.Sort(lab);
            //还原时间
            int NowTime  = 0;
            int jianTime = 0;

            for (int j = 0; j < lab.Count; j++)
            {
                if (lab[j].Time != NowTime)
                {
                    NowTime      = lab[j].Time;
                    lab[j].Time -= jianTime;
                    jianTime     = NowTime;
                }
                else
                {
                    lab[j].Time -= jianTime;
                }
            }
            StringBuilder Action = new StringBuilder();

            //144 128
            for (int j = 0; j < lab.Count; j++)
            {
                List <int> lI = GetListTime(lab[j].Time);

                for (int x = 0; x < lI.Count; x++)
                {
                    if (x != lI.Count - 1)
                    {
                        Action.Append((char)(lI[x] + 128));
                    }
                    else
                    {
                        Action.Append((char)(lI[x]));
                    }
                }
                //Action.Append((char)lab[j].Time);
                Action.Append((char)lab[j].Action);
                Action.Append((char)lab[j].Position);
                Action.Append((char)lab[j].Color);
            }
            return(Action.ToString());
        }
コード例 #2
0
ファイル: LightGroupMethod.cs プロジェクト: hhm2maker/Maker
        /// <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);
        }
コード例 #3
0
ファイル: FileBusiness.cs プロジェクト: hhm2maker/Maker
        /// <summary>
        /// 写入Midi文件 非ANSI
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="mActionBeanList"></param>
        public void WriteMidiFile(String filePath, List <Light> mActionBeanList)
        {
            List <Light> lab = new List <Light>();

            for (int j = 0; j < mActionBeanList.Count; j++)
            {
                lab.Add(new Light(mActionBeanList[j].Time, mActionBeanList[j].Action, mActionBeanList[j].Position, mActionBeanList[j].Color));
            }
            lab = LightBusiness.Sort(lab);
            //还原时间
            int NowTime  = 0;
            int jianTime = 0;

            for (int j = 0; j < lab.Count; j++)
            {
                if (lab[j].Time != NowTime)
                {
                    NowTime      = lab[j].Time;
                    lab[j].Time -= jianTime;
                    jianTime     = NowTime;
                }
                else
                {
                    lab[j].Time -= jianTime;
                }
            }
            List <char> mData    = new List <char>(); //文件字符
            List <char> StartStr = new List <char>(); //文件头
            List <char> EndStr   = new List <char>(); //文件尾

            StartStr.Add((char)77);
            StartStr.Add((char)84);
            StartStr.Add((char)104);
            StartStr.Add((char)100);
            StartStr.Add((char)0);
            StartStr.Add((char)0);
            StartStr.Add((char)0);
            StartStr.Add((char)6);
            StartStr.Add((char)0);
            StartStr.Add((char)0);
            StartStr.Add((char)0);
            StartStr.Add((char)1);
            StartStr.Add((char)0);
            StartStr.Add((char)96);
            StartStr.Add((char)77);
            StartStr.Add((char)84);
            StartStr.Add((char)114);
            StartStr.Add((char)107);
            StartStr.Add((char)0);
            StartStr.Add((char)0);
            StartStr.Add((char)0);
            StartStr.Add((char)33);
            StartStr.Add((char)0);
            StartStr.Add((char)255);
            StartStr.Add((char)88);
            StartStr.Add((char)4);
            StartStr.Add((char)4);
            StartStr.Add((char)2);
            StartStr.Add((char)36);
            StartStr.Add((char)8);
            StartStr.Add((char)0);
            StartStr.Add((char)255);
            StartStr.Add((char)88);
            StartStr.Add((char)4);
            StartStr.Add((char)4);
            StartStr.Add((char)2);
            StartStr.Add((char)36);
            StartStr.Add((char)8);

            EndStr.Add((char)0);
            EndStr.Add((char)255);
            EndStr.Add((char)47);
            EndStr.Add((char)0);

            StringBuilder Action = new StringBuilder();

            //144 128
            for (int j = 0; j < lab.Count; j++)
            {
                List <int> lI = GetListTime(lab[j].Time);

                for (int x = 0; x < lI.Count; x++)
                {
                    if (x != lI.Count - 1)
                    {
                        Action.Append((char)(lI[x] + 128));
                    }
                    else
                    {
                        Action.Append((char)(lI[x]));
                    }
                }
                //Action.Append((char)lab[j].Time);
                Action.Append((char)lab[j].Action);
                Action.Append((char)lab[j].Position);
                Action.Append((char)lab[j].Color);
            }
            //18 - 21 位置的数字可以由两种方法得出 20 + 动作次数(开始结束都算)* 4 或是 文件大小 - 22
            String Zero = "";
            String Size;

            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]);
            }
            line.Append(Action.ToString());
            for (int j = 0; j < EndStr.Count; j++)
            {
                line.Append(EndStr[j]);
            }
            //获得文件路径
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            FileStream f = new FileStream(filePath, FileMode.OpenOrCreate);

            for (int j = 0; j < line.Length; j++)
            {
                //Console.WriteLine((int)line[j]);
                f.WriteByte((byte)line[j]);
            }
            f.Close();
        }
コード例 #4
0
ファイル: FileBusiness.cs プロジェクト: hhm2maker/Maker
        /// <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();
        }