Exemplo n.º 1
0
        /// <summary>
        /// コンパイル開始
        /// </summary>
        /// <returns></returns>
        public int Start()
        {
            try
            {
                Disp(string.Format(msg.get("I04000"), "mucomMD2vgm"));
                Disp("");

                Disp(msg.get("I04001"));
                if (!File.Exists(srcFn))
                {
                    msgBox.setErrMsg(msg.get("E04000"));
                    return(-1);
                }

                Disp(msg.get("I04002"));
                string      path = Path.GetDirectoryName(Path.GetFullPath(srcFn));
                List <Line> src  = GetSrc(File.ReadAllLines(srcFn, System.Text.Encoding.GetEncoding("Shift_JIS")), path);
                if (src == null)
                {
                    msgBox.setErrMsg(msg.get("E04001"));
                    return(-1);
                }

                Disp(msg.get("I04003"));
                desVGM = new ClsVgm(stPath, srcFn, isLoopEx, rendSecond);
                if (desVGM.Analyze(src) != 0)
                {
                    msgBox.setErrMsg(string.Format(
                                         msg.get("E04002")
                                         , desVGM.lineNumber));
                    return(-1);
                }

                if (desVGM.info.useOPN2 || desVGM.info.useOPM)
                {
                    Disp(msg.get("I04021"));
                    desVGM.LoadVoicedat();
                }

                if (desVGM.info.useDCSG)
                {
                    Disp(msg.get("I04022"));
                    desVGM.LoadSSGdat();
                }

                if (desVGM.info.useOPN2)
                {
                    Disp(msg.get("I04023"));
                    int i = desVGM.LoadAdpcmdat();
                    if (i > 0)
                    {
                        Disp(string.Format("ADPCM読み込まれ、PCM番号 1 から {0} まで使用されます。", i));
                    }

                    Disp(msg.get("I04004"));
                    if (desVGM.instPCMDatSeq.Count > 0)
                    {
                        GetPCMData(path);
                    }
                }

                byte[] desBuf = null;

                if (!isLoopEx)
                {
                    Disp(msg.get("I04005"));
                    MMLAnalyze mmlAnalyze = new MMLAnalyze(desVGM);
                    if (mmlAnalyze.Start() != 0)
                    {
                        msgBox.setErrMsg(string.Format(msg.get("E04003"), mmlAnalyze.lineNumber));
                        return(-1);
                    }

                    desVGM.CutYM2612();

                    switch (desVGM.info.format)
                    {
                    case enmFormat.VGM:
                        Disp(msg.get("I04006"));
                        desBuf = desVGM.Vgm_getByteData(mmlAnalyze.mmlData, enmLoopExStep.none);
                        Disp(msg.get("I04007"));
                        break;

                    case enmFormat.XGM:
                        Disp(msg.get("I04008"));
                        desBuf = desVGM.Xgm_getByteData(mmlAnalyze.mmlData, enmLoopExStep.none);
                        Disp(msg.get("I04009"));
                        break;
                    }

                    if (desBuf == null)
                    {
                        msgBox.setErrMsg(string.Format(
                                             msg.get("E04004")
                                             , desVGM.lineNumber));
                        return(-1);
                    }
                }
                else
                {
                    //Loopポイントその他の情報を採取するために一旦解析と1ループの演奏を行う。

                    Disp(msg.get("I04024"));
                    MMLAnalyze mmlAnalyze = new MMLAnalyze(desVGM);
                    if (mmlAnalyze.Start() != 0)
                    {
                        msgBox.setErrMsg(string.Format(msg.get("E04003"), mmlAnalyze.lineNumber));
                        return(-1);
                    }

                    desVGM.CutYM2612();

                    switch (desVGM.info.format)
                    {
                    case enmFormat.VGM:
                        Disp(msg.get("I04025"));
                        desBuf = desVGM.Vgm_getByteData(mmlAnalyze.mmlData, enmLoopExStep.Inspect);
                        Disp(msg.get("I04026"));
                        break;

                    case enmFormat.XGM:
                        Disp(msg.get("I04030"));
                        desBuf = desVGM.Xgm_getByteData(mmlAnalyze.mmlData, enmLoopExStep.Inspect);
                        Disp(msg.get("I04031"));
                        break;
                    }

                    msgBox.clear();

                    if (desBuf == null)
                    {
                        msgBox.setErrMsg(string.Format(
                                             msg.get("E04004")
                                             , desVGM.lineNumber));
                        return(-1);
                    }


                    //情報収集
                    Dictionary <KeyValuePair <enmChipType, int>, clsLoopInfo> dicLoopInfo = GetLoopInfo();
                    Dictionary <KeyValuePair <enmChipType, int>, long>        dicInspectedClockCounter = GetClockCounterInfo();

                    if (dicLoopInfo.Count != 0)
                    {
                        //収集した情報をもとに 本解析と演奏を行う。

                        desBuf = null;

                        Disp(msg.get("I04027"));
                        mmlAnalyze = new MMLAnalyze(desVGM);
                        if (mmlAnalyze.Start() != 0)
                        {
                            msgBox.setErrMsg(string.Format(msg.get("E04003"), mmlAnalyze.lineNumber));
                            return(-1);
                        }

                        desVGM.CutYM2612();

                        SetLoopInfo(desVGM, dicLoopInfo);
                        SetInspectedClockCounter(desVGM, dicInspectedClockCounter);

                        //1.ループ無しのパートがすべて演奏完了するまで演奏する
                        //(この間、ループ有りのパートはループ回数を消化しながらループさせる)
                        //2.ループ無しのパートがすべて演奏完了したうえで、ループ有りのパートがループ回数を完全に消化したら、
                        //もう一度ループ回数を充てんし、ループ回数を全て消化するまでループする
                        switch (desVGM.info.format)
                        {
                        case enmFormat.VGM:
                            Disp(msg.get("I04028"));
                            desBuf = desVGM.Vgm_getByteData(mmlAnalyze.mmlData, enmLoopExStep.Playing);
                            Disp(msg.get("I04029"));
                            break;

                        case enmFormat.XGM:
                            Disp(msg.get("I04032"));
                            desBuf = desVGM.Xgm_getByteData(mmlAnalyze.mmlData, enmLoopExStep.Playing);
                            Disp(msg.get("I04033"));
                            break;
                        }

                        if (desBuf == null)
                        {
                            msgBox.setErrMsg(string.Format(
                                                 msg.get("E04004")
                                                 , desVGM.lineNumber));
                            return(-1);
                        }
                    }
                }



                Disp(msg.get("I04010"));
                if (desVGM.info.format == enmFormat.VGM)
                {
                    outFile(desBuf);
                }
                else
                {
                    OutXgmFile(desBuf);
                }


                Result();

                return(0);
            }
            catch (Exception ex)
            {
                log.ForcedWrite(ex);
                msgBox.setErrMsg(string.Format(msg.get("E04005")
                                               , (desVGM == null) ? -1 : desVGM.lineNumber
                                               , ex.Message
                                               , ex.StackTrace));
                return(-1);
            }
            finally
            {
                Disp(msg.get("I04011"));
                Disp("");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// コンパイル開始
        /// </summary>
        /// <returns></returns>
        public int Start()
        {
            try
            {
                Disp(string.Format(msg.get("I04000"), "mml2vgm"));
                Disp("");

                List <Line> src = null;

                //.gwiファイルの読み込み
                if (!bufferMode)
                {
                    Disp(msg.get("I04001"));
                    srcFn = srcFn.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar);
                    if (!File.Exists(srcFn))
                    {
                        msgBox.setErrMsg(msg.get("E04000"), new LinePos(srcFn));
                        return(-1);
                    }

                    Disp(msg.get("I04002"));
                    //string path = Path.GetDirectoryName(Path.GetFullPath(srcFn));
                    //wrkPath インクルードファイル取り込み対象パス
                    srcTxt = File.ReadAllLines(srcFn);
                }

                //インクルードファイルのマージ
                src = GetSrc(srcTxt, wrkPath);

                if (src == null)
                {
                    msgBox.setErrMsg(msg.get("E04001"), new LinePos(srcFn));
                    return(-1);
                }

                Disp(msg.get("I04003"));
                //ざっくりくわけ
                SourceParser sp = new SourceParser();
                sp.Parse(src);

                desVGM            = new ClsVgm(stPath, sp);
                desVGM.doSkip     = doSkip;
                desVGM.doSkipStop = doSkipStop;
                desVGM.caretPoint = caretPoint;
                desVGM.wrkPath    = wrkPath;
                if (desVGM.Analyze(src) != 0)
                {
                    msgBox.setErrMsg(string.Format(
                                         msg.get("E04002")
                                         , desVGM.linePos.row), desVGM.linePos);
                    return(-1);
                }

                Disp(msg.get("I04004"));
                //wrkPath PCMファイル取り込み対象パス
                if (desVGM.instPCMDatSeq.Count > 0)
                {
                    GetPCMData(wrkPath);
                }

                Disp(msg.get("I04005"));

                MMLAnalyze mmlAnalyze = new MMLAnalyze(desVGM);
                mmlAnalyze.doSkip     = doSkip;
                mmlAnalyze.caretPoint = caretPoint;

                if (mmlAnalyze.Start() != 0)
                {
                    msgBox.setErrMsg(string.Format(
                                         msg.get("E04003")
                                         , mmlAnalyze.linePos.row), mmlAnalyze.linePos);
                    return(-1);
                }

                if (desVGM.info.format != enmFormat.ZGM)
                {
                    switch (desVGM.info.format)
                    {
                    case enmFormat.VGM:
                        Disp(msg.get("I04006"));
                        desBuf = desVGM.Vgm_getByteData(mmlAnalyze.mmlData);
                        Disp(msg.get("I04007"));
                        break;

                    case enmFormat.XGM:
                        Disp(msg.get("I04008"));
                        desBuf = desVGM.Xgm_getByteData(mmlAnalyze.mmlData);
                        Disp(msg.get("I04009"));
                        break;

                    default:
                        break;
                    }

                    if (desBuf == null)
                    {
                        if (desVGM.linePos != null)
                        {
                            msgBox.setErrMsg(string.Format(
                                                 msg.get("E04004")
                                                 , desVGM.linePos.row), desVGM.linePos);
                        }
                        return(-1);
                    }

                    if (outVgmFile && writeFileMode)
                    {
                        Disp(msg.get("I04021"));
                        if (desVGM.info.format == enmFormat.VGM)
                        {
                            OutVgmFile(desBuf);
                        }
                        else
                        {
                            OutXgmFile(desBuf);
                        }
                    }
                }
                else
                {
                    Disp(msg.get("I04023"));
                    ZGMmaker zmake = new ZGMmaker();
                    desBuf = zmake.Build(desVGM);
                    Disp(msg.get("I04024"));

                    if (desBuf == null)
                    {
                        msgBox.setErrMsg(string.Format(
                                             msg.get("E04004")
                                             , desVGM.linePos.row), desVGM.linePos);
                        return(-1);
                    }

                    if (outVgmFile && writeFileMode)
                    {
                        Disp(msg.get("I04025"));
                        zmake.OutFile(desBuf, desFn);
                    }
                }

                if (outTraceInfoFile && writeFileMode)
                {
                    Disp(msg.get("I04022"));
                    OutTraceInfoFile(desBuf);
                }

                Result();

                FileInformation.loopCounter  = desVGM.loopClock;
                FileInformation.totalCounter = desVGM.lClock;
                FileInformation.format       = desVGM.info.format;

                return(0);
            }
            catch (Exception ex)
            {
                Disp(ex.Message);
                msgBox.setErrMsg(string.Format(msg.get("E04005")
                                               , (desVGM.linePos == null ? "-" : desVGM.linePos.row.ToString())
                                               , ex.Message
                                               , ex.StackTrace), desVGM.linePos);
                return(-1);
            }
            finally
            {
                Disp(msg.get("I04011"));
                Disp("");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// コンパイル開始
        /// </summary>
        /// <returns></returns>
        public int Start()
        {
            desVGM = null;

            try
            {
                log.Write("start mml2vgm core");

                // ファイル存在チェック
                log.Write("ファイル存在チェック");
                if (!File.Exists(srcFn))
                {
                    msgBox.setErrMsg("ファイルが見つかりません。");
                    return(-1);
                }

                // ファイルの読み込み
                log.Write("ファイルの読み込み");
                string[] srcBuf = File.ReadAllLines(srcFn);
                string   path   = Path.GetDirectoryName(Path.GetFullPath(srcFn));

                log.Write("clsVgmインスタンス作成");
                desVGM = new ClsVgm(stPath);

                log.Write("mmlファイルの整形");
                List <Line> src = new List <Line>();
                int         ln  = 1;
                foreach (string s in srcBuf)
                {
                    if (!string.IsNullOrEmpty(s) && s.TrimStart().Length > 2 && s.TrimStart().Substring(0, 2) == "'+")
                    {
                        string includeFn = s.Substring(2).Trim().Trim('"');
                        if (!File.Exists(includeFn))
                        {
                            includeFn = Path.Combine(path, includeFn);
                            if (!File.Exists(includeFn))
                            {
                                msgBox.setErrMsg(string.Format("インクルードファイル({0})が見つかりません。", includeFn));
                                return(-1);
                            }
                        }
                        string[] incBuf = File.ReadAllLines(includeFn);
                        int      iln    = 1;
                        foreach (string i in incBuf)
                        {
                            Line iline = new Line(includeFn, iln, i);
                            src.Add(iline);
                            iln++;
                        }

                        ln++;
                        continue;
                    }

                    Line line = new Line(srcFn, ln, s);
                    src.Add(line);
                    ln++;
                }

                // 解析
                log.Write("テキスト解析開始(start clsVGM)");
                int ret;
                ret = desVGM.Analyze(src);

                log.Write("テキスト解析完了(end clsVGM)");

                if (ret != 0)
                {
                    msgBox.setErrMsg(string.Format("想定外のエラー ソース解析に失敗?(analyze)(line:{0})", desVGM.lineNumber));
                    return(-1);
                }

                // PCM定義あり?
                log.Write("PCM定義あり?");
                if (desVGM.instPCM.Count > 0)
                {
                    log.Write("PCM取得");
                    GetPCMData(path);
                    log.Write("PCM取得完了");
                }


                // 解析した情報をもとにVGMファイル作成
                byte[] desBuf;
                log.Write("MML解析開始(start GetByteData)");
                if (desVGM.format == enmFormat.VGM)
                {
                    desBuf = desVGM.GetByteData();
                }
                else
                {
                    desBuf = desVGM.Xgm_getByteData();
                }
                log.Write("MML解析完了(start GetByteData)");


                if (desBuf == null)
                {
                    msgBox.setErrMsg(string.Format("想定外のエラー ソース解析に失敗?(getByteData)(line:{0})", desVGM.lineNumber));
                    return(-1);
                }


                if (Path.GetExtension(desFn).ToLower() != ".vgz")
                {
                    if (desVGM.format == enmFormat.VGM)
                    {
                        log.Write("VGMファイル出力");
                        // ファイル出力
                        File.WriteAllBytes(desFn, desBuf);
                    }
                    else
                    {
                        log.Write("XGMファイル出力");
                        //XGM
                        // ファイル出力
                        File.WriteAllBytes(Path.Combine(Path.GetDirectoryName(desFn), Path.GetFileNameWithoutExtension(desFn) + ".xgm"), desBuf);
                    }
                }
                else
                {
                    log.Write("VGZファイル出力");
                    int    num;
                    byte[] buf = new byte[1024];

                    MemoryStream inStream   = new MemoryStream(desBuf);
                    FileStream   outStream  = new FileStream(desFn, FileMode.Create);
                    GZipStream   compStream = new GZipStream(outStream, CompressionMode.Compress);

                    try
                    {
                        while ((num = inStream.Read(buf, 0, buf.Length)) > 0)
                        {
                            compStream.Write(buf, 0, num);
                        }
                    }
                    catch
                    {
                    }
                    finally
                    {
                        if (compStream != null)
                        {
                            compStream.Dispose();
                        }
                        else if (outStream != null)
                        {
                            outStream.Dispose();
                        }
                        if (inStream != null)
                        {
                            inStream.Dispose();
                        }
                    }
                }

                // 終了
                return(0);
            }
            catch (Exception ex)
            {
                msgBox.setErrMsg(string.Format("想定外のエラー line:{0} \r\nメッセージ:\r\n{1}\r\nスタックトレース:\r\n{2}\r\n", desVGM.lineNumber, ex.Message, ex.StackTrace));
                return(-1);
            }
            finally
            {
                log.Write("end mml2vgm core");
            }
        }