From 228e7d4676f56f54d398ae68c791e0d58b4a5998 Mon Sep 17 00:00:00 2001 From: bbbradsmith Date: Wed, 11 Dec 2024 15:39:38 -0500 Subject: [PATCH] txtout command line action to export text file --- doc/8-advanced/command-line.md | 3 +++ src/main.cpp | 38 ++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/doc/8-advanced/command-line.md b/doc/8-advanced/command-line.md index 3a84575e1..59923bc85 100644 --- a/doc/8-advanced/command-line.md +++ b/doc/8-advanced/command-line.md @@ -84,6 +84,9 @@ the following parameters may be used: - `-cmdout path`: output command stream dump to `path`. - you must provide a file, otherwise Furnace will quit. +- `-txtout path`: output text file export to `path`. + - you must provide a file, otherwise Furnace will quit. + ## COMMAND LINE INTERFACE Furnace provides a command-line interface (CLI) player which may be activated through the `-console` option. diff --git a/src/main.cpp b/src/main.cpp index 34cb46d75..a50c30e47 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -86,6 +86,7 @@ FurnaceCLI cli; String outName; String vgmOutName; String cmdOutName; +String txtOutName; int benchMode=0; int subsong=-1; DivAudioExportOptions exportOptions; @@ -437,6 +438,12 @@ TAParamResult pCmdOut(String val) { return TA_PARAM_SUCCESS; } +TAParamResult pTxtOut(String val) { + txtOutName=val; + e.setAudio(DIV_AUDIO_DUMMY); + return TA_PARAM_SUCCESS; +} + bool needsValue(String param) { for (size_t i=0; i","output .vgm data")); params.push_back(TAParam("D","direct",false,pDirect,"","set VGM export direct stream mode")); params.push_back(TAParam("C","cmdout",true,pCmdOut,"","output command stream")); + params.push_back(TAParam("t","txtout",true,pTxtOut,"","export as text file")); params.push_back(TAParam("L","loglevel",true,pLogLevel,"debug|info|warning|error","set the log level (info by default)")); params.push_back(TAParam("v","view",true,pView,"pattern|commands|nothing","set visualization (nothing by default)")); params.push_back(TAParam("i","info",false,pInfo,"","get info about a song")); @@ -549,6 +557,7 @@ int main(int argc, char** argv) { outName=""; vgmOutName=""; cmdOutName=""; + txtOutName=""; // load config for locale e.prePreInit(); @@ -716,14 +725,14 @@ int main(int argc, char** argv) { return 1; } - if (fileName.empty() && (benchMode || infoMode || outName!="" || vgmOutName!="" || cmdOutName!="")) { + if (fileName.empty() && (benchMode || infoMode || outName!="" || vgmOutName!="" || cmdOutName!="" || txtOutName!="")) { logE("provide a file!"); return 1; } #ifdef HAVE_GUI - if (e.preInit(consoleMode || benchMode || infoMode || outName!="" || vgmOutName!="" || cmdOutName!="")) { - if (consoleMode || benchMode || infoMode || outName!="" || vgmOutName!="" || cmdOutName!="") { + if (e.preInit(consoleMode || benchMode || infoMode || outName!="" || vgmOutName!="" || cmdOutName!="" || txtOutName!="")) { + if (consoleMode || benchMode || infoMode || outName!="" || vgmOutName!="" || cmdOutName!="" || txtOutName!="") { logW("engine wants safe mode, but Furnace GUI is not going to start."); } else { safeMode=true; @@ -735,7 +744,7 @@ int main(int argc, char** argv) { } #endif - if (safeMode && (consoleMode || benchMode || infoMode || outName!="" || vgmOutName!="" || cmdOutName!="")) { + if (safeMode && (consoleMode || benchMode || infoMode || outName!="" || vgmOutName!="" || cmdOutName!="" || txtOutName!="")) { logE("you can't use safe mode and console/export mode together."); return 1; } @@ -752,7 +761,7 @@ int main(int argc, char** argv) { #endif - if (!fileName.empty() && ((!e.getConfBool("tutIntroPlayed",TUT_INTRO_PLAYED)) || e.getConfInt("alwaysPlayIntro",0)!=3 || consoleMode || benchMode || infoMode || outName!="" || vgmOutName!="" || cmdOutName!="")) { + if (!fileName.empty() && ((!e.getConfBool("tutIntroPlayed",TUT_INTRO_PLAYED)) || e.getConfInt("alwaysPlayIntro",0)!=3 || consoleMode || benchMode || infoMode || outName!="" || vgmOutName!="" || cmdOutName!="" || txtOutName!="")) { logI("loading module..."); FILE* f=ps_fopen(fileName.c_str(),"rb"); if (f==NULL) { @@ -844,7 +853,7 @@ int main(int argc, char** argv) { return 0; } - if (outName!="" || vgmOutName!="" || cmdOutName!="") { + if (outName!="" || vgmOutName!="" || cmdOutName!="" || txtOutName!="") { if (cmdOutName!="") { SafeWriter* w=e.saveCommand(); if (w!=NULL) { @@ -882,6 +891,23 @@ int main(int argc, char** argv) { e.saveAudio(outName.c_str(),exportOptions); e.waitAudioFile(); } + if (txtOutName!="") { + e.setConsoleMode(true); + SafeWriter* w=e.saveText(false); + if (w!=NULL) { + FILE* f=fopen(txtOutName.c_str(),"wb"); + if (f!=NULL) { + fwrite(w->getFinalBuf(),1,w->size(),f); + fclose(f); + } else { + reportError(fmt::sprintf(_("could not open file! (%s)"),e.getLastError())); + } + w->finish(); + delete w; + } else { + reportError(_("could not write txt!")); + } + } finishLogFile(); return 0; }