diff --git a/CMakeLists.txt b/CMakeLists.txt index fef510ef..d3b98fc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -394,6 +394,7 @@ src/gui/doAction.cpp src/gui/editing.cpp src/gui/editControls.cpp src/gui/insEdit.cpp +src/gui/log.cpp src/gui/mixer.cpp src/gui/midiMap.cpp src/gui/newSong.cpp diff --git a/src/audio/rtmidi.cpp b/src/audio/rtmidi.cpp index fcd992be..c4a6f8f9 100644 --- a/src/audio/rtmidi.cpp +++ b/src/audio/rtmidi.cpp @@ -44,18 +44,18 @@ bool TAMidiInRtMidi::gather() { std::vector TAMidiInRtMidi::listDevices() { std::vector ret; - logD("listing devices.\n"); + logD("listing devices."); if (port==NULL) return ret; try { unsigned int count=port->getPortCount(); - logD("got port count.\n"); + logD("got port count."); for (unsigned int i=0; igetPortName(i); if (name!="") ret.push_back(name); } } catch (RtMidiError& e) { - logW("could not get MIDI inputs! %s\n",e.what()); + logW("could not get MIDI inputs! %s",e.what()); } return ret; } @@ -78,10 +78,10 @@ bool TAMidiInRtMidi::openDevice(String name) { } } isOpen=portOpen; - if (!portOpen) logW("could not find MIDI in device...\n"); + if (!portOpen) logW("could not find MIDI in device..."); return portOpen; } catch (RtMidiError& e) { - logW("could not open MIDI in device! %s\n",e.what()); + logW("could not open MIDI in device! %s",e.what()); return false; } return true; @@ -93,7 +93,7 @@ bool TAMidiInRtMidi::closeDevice() { try { port->closePort(); } catch (RtMidiError& e) { - logW("could not close MIDI in device! %s\n",e.what()); + logW("could not close MIDI in device! %s",e.what()); isOpen=false; // still return false; } @@ -106,7 +106,7 @@ bool TAMidiInRtMidi::init() { try { port=new RtMidiIn; } catch (RtMidiError& e) { - logW("could not initialize RtMidi in! %s\n",e.what()); + logW("could not initialize RtMidi in! %s",e.what()); return false; } return true; @@ -176,10 +176,10 @@ bool TAMidiOutRtMidi::openDevice(String name) { } } isOpen=portOpen; - if (!portOpen) logW("could not find MIDI out device...\n"); + if (!portOpen) logW("could not find MIDI out device..."); return portOpen; } catch (RtMidiError& e) { - logW("could not open MIDI out device! %s\n",e.what()); + logW("could not open MIDI out device! %s",e.what()); return false; } return true; @@ -191,7 +191,7 @@ bool TAMidiOutRtMidi::closeDevice() { try { port->closePort(); } catch (RtMidiError& e) { - logW("could not close MIDI out device! %s\n",e.what()); + logW("could not close MIDI out device! %s",e.what()); isOpen=false; // still return false; } @@ -210,7 +210,7 @@ std::vector TAMidiOutRtMidi::listDevices() { if (name!="") ret.push_back(name); } } catch (RtMidiError& e) { - logW("could not get MIDI outputs! %s\n",e.what()); + logW("could not get MIDI outputs! %s",e.what()); } return ret; } @@ -220,7 +220,7 @@ bool TAMidiOutRtMidi::init() { try { port=new RtMidiOut; } catch (RtMidiError& e) { - logW("could not initialize RtMidi out! %s\n",e.what()); + logW("could not initialize RtMidi out! %s",e.what()); return false; } return true; diff --git a/src/audio/sdl.cpp b/src/audio/sdl.cpp index 7fbbceb5..3ef38d4f 100644 --- a/src/audio/sdl.cpp +++ b/src/audio/sdl.cpp @@ -75,7 +75,7 @@ std::vector TAAudioSDL::listAudioDevices() { std::vector ret; if (!audioSysStarted) { if (SDL_Init(SDL_INIT_AUDIO)<0) { - logE("could not initialize SDL to list audio devices\n"); + logE("could not initialize SDL to list audio devices"); } else { audioSysStarted=true; } @@ -96,12 +96,12 @@ std::vector TAAudioSDL::listAudioDevices() { bool TAAudioSDL::init(TAAudioDesc& request, TAAudioDesc& response) { if (initialized) { - logE("audio already initialized\n"); + logE("audio already initialized"); return false; } if (!audioSysStarted) { if (SDL_Init(SDL_INIT_AUDIO)<0) { - logE("could not initialize SDL\n"); + logE("could not initialize SDL"); return false; } audioSysStarted=true; @@ -119,7 +119,7 @@ bool TAAudioSDL::init(TAAudioDesc& request, TAAudioDesc& response) { ai=SDL_OpenAudioDevice(request.deviceName.empty()?NULL:request.deviceName.c_str(),0,&ac,&ar,SDL_AUDIO_ALLOW_FREQUENCY_CHANGE); if (ai==0) { - logE("could not open audio device: %s\n",SDL_GetError()); + logE("could not open audio device: %s",SDL_GetError()); return false; } diff --git a/src/engine/config.cpp b/src/engine/config.cpp index f7444e3c..92866a9f 100644 --- a/src/engine/config.cpp +++ b/src/engine/config.cpp @@ -32,13 +32,13 @@ bool DivEngine::saveConf() { configFile=configPath+String(CONFIG_FILE); FILE* f=ps_fopen(configFile.c_str(),"wb"); if (f==NULL) { - logW("could not write config file! %s\n",strerror(errno)); + logW("could not write config file! %s",strerror(errno)); return false; } for (auto& i: conf) { String toWrite=fmt::sprintf("%s=%s\n",i.first,i.second); if (fwrite(toWrite.c_str(),1,toWrite.size(),f)!=toWrite.size()) { - logW("could not write config file! %s\n",strerror(errno)); + logW("could not write config file! %s",strerror(errno)); fclose(f); return false; } @@ -52,10 +52,10 @@ bool DivEngine::loadConf() { configFile=configPath+String(CONFIG_FILE); FILE* f=ps_fopen(configFile.c_str(),"rb"); if (f==NULL) { - logI("creating default config.\n"); + logI("creating default config."); return saveConf(); } - logI("loading config.\n"); + logI("loading config."); while (!feof(f)) { String key=""; String value=""; diff --git a/src/engine/dispatchContainer.cpp b/src/engine/dispatchContainer.cpp index c89a0fa0..4f4ecf39 100644 --- a/src/engine/dispatchContainer.cpp +++ b/src/engine/dispatchContainer.cpp @@ -148,13 +148,13 @@ void DivDispatchContainer::init(DivSystem sys, DivEngine* eng, int chanCount, do bb[0]=blip_new(32768); if (bb[0]==NULL) { - logE("not enough memory!\n"); + logE("not enough memory!"); return; } bb[1]=blip_new(32768); if (bb[1]==NULL) { - logE("not enough memory!\n"); + logE("not enough memory!"); return; } @@ -312,7 +312,7 @@ void DivDispatchContainer::init(DivSystem sys, DivEngine* eng, int chanCount, do dispatch=new DivPlatformMMC5; break; default: - logW("this system is not supported yet! using dummy platform.\n"); + logW("this system is not supported yet! using dummy platform."); dispatch=new DivPlatformDummy; break; } diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index fbafb668..690ee993 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -193,7 +193,7 @@ void DivEngine::runExportThread() { sf=sf_open(exportPath.c_str(),SFM_WRITE,&si); if (sf==NULL) { - logE("could not open file for writing! (%s)\n",sf_strerror(NULL)); + logE("could not open file for writing! (%s)",sf_strerror(NULL)); exporting=false; return; } @@ -207,7 +207,7 @@ void DivEngine::runExportThread() { deinitAudioBackend(); playSub(false); - logI("rendering to file...\n"); + logI("rendering to file..."); while (playing) { nextBuf(NULL,outBuf,0,2,EXPORT_BUFSIZE); @@ -216,10 +216,10 @@ void DivEngine::runExportThread() { outBuf[2][1+(i<<1)]=MAX(-1.0f,MIN(1.0f,outBuf[1][i])); } if (totalProcessed>EXPORT_BUFSIZE) { - logE("error: total processed is bigger than export bufsize! %d>%d\n",totalProcessed,EXPORT_BUFSIZE); + logE("error: total processed is bigger than export bufsize! %d>%d",totalProcessed,EXPORT_BUFSIZE); } if (sf_writef_float(sf,outBuf[2],totalProcessed)!=(int)totalProcessed) { - logE("error: failed to write entire buffer!\n"); + logE("error: failed to write entire buffer!"); break; } } @@ -229,7 +229,7 @@ void DivEngine::runExportThread() { delete[] outBuf[2]; if (sf_close(sf)!=0) { - logE("could not close audio file!\n"); + logE("could not close audio file!"); } exporting=false; @@ -239,10 +239,10 @@ void DivEngine::runExportThread() { disCont[i].setQuality(lowQuality); } if (!output->setRun(true)) { - logE("error while activating audio!\n"); + logE("error while activating audio!"); } } - logI("done!\n"); + logI("done!"); break; } case DIV_EXPORT_MODE_MANY_SYS: { @@ -262,10 +262,10 @@ void DivEngine::runExportThread() { for (int i=0; iEXPORT_BUFSIZE) { - logE("error: total processed is bigger than export bufsize! (%d) %d>%d\n",i,totalProcessed,EXPORT_BUFSIZE); + logE("error: total processed is bigger than export bufsize! (%d) %d>%d",i,totalProcessed,EXPORT_BUFSIZE); } if (sf_writef_short(sf[i],sysBuf,totalProcessed)!=(int)totalProcessed) { - logE("error: failed to write entire buffer! (%d)\n",i); + logE("error: failed to write entire buffer! (%d)",i); break; } } @@ -311,7 +311,7 @@ void DivEngine::runExportThread() { for (int i=0; isetRun(true)) { - logE("error while activating audio!\n"); + logE("error while activating audio!"); } } - logI("done!\n"); + logI("done!"); break; } case DIV_EXPORT_MODE_MANY_CHAN: { @@ -338,20 +338,20 @@ void DivEngine::runExportThread() { outBuf[2]=new float[EXPORT_BUFSIZE*2]; int loopCount=remainingLoops; - logI("rendering to files...\n"); + logI("rendering to files..."); for (int i=0; iEXPORT_BUFSIZE) { - logE("error: total processed is bigger than export bufsize! %d>%d\n",totalProcessed,EXPORT_BUFSIZE); + logE("error: total processed is bigger than export bufsize! %d>%d",totalProcessed,EXPORT_BUFSIZE); } if (sf_writef_float(sf,outBuf[2],totalProcessed)!=(int)totalProcessed) { - logE("error: failed to write entire buffer!\n"); + logE("error: failed to write entire buffer!"); break; } } if (sf_close(sf)!=0) { - logE("could not close audio file!\n"); + logE("could not close audio file!"); } } exporting=false; @@ -405,10 +405,10 @@ void DivEngine::runExportThread() { disCont[i].setQuality(lowQuality); } if (!output->setRun(true)) { - logE("error while activating audio!\n"); + logE("error while activating audio!"); } } - logI("done!\n"); + logI("done!"); break; } } @@ -479,12 +479,12 @@ void DivEngine::renderSamples() { memPos=(memPos+0xfffff)&0xf00000; } if (memPos>=16777216) { - logW("out of ADPCM-A memory for sample %d!\n",i); + logW("out of ADPCM-A memory for sample %d!",i); break; } if (memPos+paddedLen>=16777216) { memcpy(adpcmAMem+memPos,s->dataA,16777216-memPos); - logW("out of ADPCM-A memory for sample %d!\n",i); + logW("out of ADPCM-A memory for sample %d!",i); } else { memcpy(adpcmAMem+memPos,s->dataA,paddedLen); } @@ -504,12 +504,12 @@ void DivEngine::renderSamples() { memPos=(memPos+0xfffff)&0xf00000; } if (memPos>=16777216) { - logW("out of ADPCM-B memory for sample %d!\n",i); + logW("out of ADPCM-B memory for sample %d!",i); break; } if (memPos+paddedLen>=16777216) { memcpy(adpcmBMem+memPos,s->dataB,16777216-memPos); - logW("out of ADPCM-B memory for sample %d!\n",i); + logW("out of ADPCM-B memory for sample %d!",i); } else { memcpy(adpcmBMem+memPos,s->dataB,paddedLen); } @@ -533,14 +533,14 @@ void DivEngine::renderSamples() { memPos=(memPos+0xffff)&0xff0000; } if (memPos>=16777216) { - logW("out of QSound PCM memory for sample %d!\n",i); + logW("out of QSound PCM memory for sample %d!",i); break; } if (memPos+length>=16777216) { for (unsigned int i=0; i<16777216-(memPos+length); i++) { qsoundMem[(memPos+i)^0x8000]=s->data8[i]; } - logW("out of QSound PCM memory for sample %d!\n",i); + logW("out of QSound PCM memory for sample %d!",i); } else { for (int i=0; idata8[i]; @@ -567,12 +567,12 @@ void DivEngine::renderSamples() { memPos=(memPos+0x1ffff)&0xfe0000; } if (memPos>=1048576) { - logW("out of X1-010 memory for sample %d!\n",i); + logW("out of X1-010 memory for sample %d!",i); break; } if (memPos+paddedLen>=1048576) { memcpy(x1_010Mem+memPos,s->data8,1048576-memPos); - logW("out of X1-010 memory for sample %d!\n",i); + logW("out of X1-010 memory for sample %d!",i); } else { memcpy(x1_010Mem+memPos,s->data8,paddedLen); } @@ -824,7 +824,7 @@ void DivEngine::playSub(bool preserveDrift, int goalRow) { skipping=false; cmdStream.clear(); std::chrono::high_resolution_clock::time_point timeEnd=std::chrono::high_resolution_clock::now(); - logV("playSub() tool %dµs\n",std::chrono::duration_cast(timeEnd-timeStart).count()); + logV("playSub() tool %dµs",std::chrono::duration_cast(timeEnd-timeStart).count()); } /* @@ -1346,7 +1346,7 @@ bool DivEngine::addWaveFromFile(const char* path) { } buf=new unsigned char[len]; if (fread(buf,1,len,f)!=(size_t)len) { - logW("did not read entire wavetable file buffer!\n"); + logW("did not read entire wavetable file buffer!"); delete[] buf; return false; } @@ -1386,22 +1386,22 @@ bool DivEngine::addWaveFromFile(const char* path) { wave->max=(unsigned char)reader.readC(); if (wave->max==255) { // new wavetable format unsigned char waveVersion=reader.readC(); - logI("reading modern .dmw...\n"); - logD("wave version %d\n",waveVersion); + logI("reading modern .dmw..."); + logD("wave version %d",waveVersion); wave->max=reader.readC(); for (int i=0; idata[i]=reader.readI(); } } else if (reader.size()==(size_t)(len+5)) { // read as .dmw - logI("reading .dmw...\n"); + logI("reading .dmw..."); if (len>256) len=256; for (int i=0; idata[i]=(unsigned char)reader.readC(); } } else { // read as binary - logI("reading binary...\n"); + logI("reading binary..."); len=reader.size(); if (len>256) len=256; reader.seek(0,SEEK_SET); @@ -1414,7 +1414,7 @@ bool DivEngine::addWaveFromFile(const char* path) { } catch (EndOfFileException& e) { // read as binary len=reader.size(); - logI("reading binary for being too small...\n"); + logI("reading binary for being too small..."); if (len>256) len=256; reader.seek(0,SEEK_SET); for (int i=0; idata,oldPat->data,256*32*sizeof(short)); - logD("found at %d\n",j); + logD("found at %d",j); didNotFind=false; break; } @@ -1953,7 +1953,7 @@ bool DivEngine::switchMaster() { disCont[i].setQuality(lowQuality); } if (!output->setRun(true)) { - logE("error while activating audio!\n"); + logE("error while activating audio!"); return false; } } else { @@ -2071,9 +2071,9 @@ void DivEngine::quitDispatch() { #define CHECK_CONFIG_DIR_MAC() \ configPath+="/Library/Application Support/Furnace"; \ if (stat(configPath.c_str(),&st)<0) { \ - logI("creating config dir...\n"); \ + logI("creating config dir..."); \ if (mkdir(configPath.c_str(),0755)<0) { \ - logW("could not make config dir! (%s)\n",strerror(errno)); \ + logW("could not make config dir! (%s)",strerror(errno)); \ configPath="."; \ } \ } @@ -2081,18 +2081,18 @@ void DivEngine::quitDispatch() { #define CHECK_CONFIG_DIR() \ configPath+="/.config"; \ if (stat(configPath.c_str(),&st)<0) { \ - logI("creating user config dir...\n"); \ + logI("creating user config dir..."); \ if (mkdir(configPath.c_str(),0755)<0) { \ - logW("could not make user config dir! (%s)\n",strerror(errno)); \ + logW("could not make user config dir! (%s)",strerror(errno)); \ configPath="."; \ } \ } \ if (configPath!=".") { \ configPath+="/furnace"; \ if (stat(configPath.c_str(),&st)<0) { \ - logI("creating config dir...\n"); \ + logI("creating config dir..."); \ if (mkdir(configPath.c_str(),0755)<0) { \ - logW("could not make config dir! (%s)\n",strerror(errno)); \ + logW("could not make config dir! (%s)",strerror(errno)); \ configPath="."; \ } \ } \ @@ -2114,7 +2114,7 @@ bool DivEngine::initAudioBackend() { switch (audioEngine) { case DIV_AUDIO_JACK: #ifndef HAVE_JACK - logE("Furnace was not compiled with JACK support!\n"); + logE("Furnace was not compiled with JACK support!"); setConf("audioEngine","SDL"); saveConf(); output=new TAAudioSDL; @@ -2129,7 +2129,7 @@ bool DivEngine::initAudioBackend() { output=new TAAudio; break; default: - logE("invalid audio engine!\n"); + logE("invalid audio engine!"); return false; } @@ -2147,7 +2147,7 @@ bool DivEngine::initAudioBackend() { output->setCallback(process,this); if (!output->init(want,got)) { - logE("error while initializing audio!\n"); + logE("error while initializing audio!"); delete output; output=NULL; audioEngine=DIV_AUDIO_NULL; @@ -2158,15 +2158,15 @@ bool DivEngine::initAudioBackend() { midiIns=output->midiIn->listDevices(); midiOuts=output->midiOut->listDevices(); } else { - logW("error while initializing MIDI!\n"); + logW("error while initializing MIDI!"); } if (output->midiIn) { String inName=getConfString("midiInDevice",""); if (!inName.empty()) { // try opening device - logI("opening MIDI input.\n"); + logI("opening MIDI input."); if (!output->midiIn->openDevice(inName)) { - logW("could not open MIDI input device!\n"); + logW("could not open MIDI input device!"); } } } @@ -2174,9 +2174,9 @@ bool DivEngine::initAudioBackend() { String outName=getConfString("midiOutDevice",""); if (!outName.empty()) { // try opening device - logI("opening MIDI output.\n"); + logI("opening MIDI output."); if (!output->midiOut->openDevice(outName)) { - logW("could not open MIDI output device!\n"); + logW("could not open MIDI output device!"); } } } @@ -2188,13 +2188,13 @@ bool DivEngine::deinitAudioBackend() { if (output!=NULL) { if (output->midiIn) { if (output->midiIn->isDeviceOpen()) { - logI("closing MIDI input.\n"); + logI("closing MIDI input."); output->midiIn->closeDevice(); } } if (output->midiOut) { if (output->midiOut->isDeviceOpen()) { - logI("closing MIDI output.\n"); + logI("closing MIDI output."); output->midiOut->closeDevice(); } } @@ -2222,7 +2222,7 @@ bool DivEngine::init() { int uid=getuid(); struct passwd* entry=getpwuid(uid); if (entry==NULL) { - logW("unable to determine config directory! (%s)\n",strerror(errno)); + logW("unable to determine config directory! (%s)",strerror(errno)); configPath="."; } else { configPath=entry->pw_dir; @@ -2241,21 +2241,21 @@ bool DivEngine::init() { #endif } #endif - logD("config path: %s\n",configPath.c_str()); + logD("config path: %s",configPath.c_str()); loadConf(); // init the rest of engine bool haveAudio=false; if (!initAudioBackend()) { - logE("no audio output available!\n"); + logE("no audio output available!"); } else { haveAudio=true; } samp_bb=blip_new(32768); if (samp_bb==NULL) { - logE("not enough memory!\n"); + logE("not enough memory!"); return false; } @@ -2290,7 +2290,7 @@ bool DivEngine::init() { return false; } else { if (!output->setRun(true)) { - logE("error while activating!\n"); + logE("error while activating!"); return false; } } @@ -2300,7 +2300,7 @@ bool DivEngine::init() { bool DivEngine::quit() { deinitAudioBackend(); quitDispatch(); - logI("saving config.\n"); + logI("saving config."); saveConf(); active=false; delete[] oscBuf[0]; diff --git a/src/engine/fileOps.cpp b/src/engine/fileOps.cpp index eb5e31e4..8514d91a 100644 --- a/src/engine/fileOps.cpp +++ b/src/engine/fileOps.cpp @@ -62,15 +62,15 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { ds.isDMF=true; if (!reader.seek(16,SEEK_SET)) { - logE("premature end of file!\n"); + logE("premature end of file!"); lastError="incomplete file"; delete[] file; return false; } ds.version=(unsigned char)reader.readC(); - logI("module version %d (0x%.2x)\n",ds.version,ds.version); + logI("module version %d (0x%.2x)",ds.version,ds.version); if (ds.version>0x1a) { - logE("this version is not supported by Furnace yet!\n"); + logE("this version is not supported by Furnace yet!"); lastError="this version is not supported by Furnace yet"; delete[] file; return false; @@ -106,23 +106,23 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { ds.manInfo=reader.readString((unsigned char)reader.readC()); ds.createdDate=reader.readString((unsigned char)reader.readC()); ds.revisionDate=reader.readString((unsigned char)reader.readC()); - logI("%s by %s\n",ds.name.c_str(),ds.author.c_str()); - logI("has YMU-specific data:\n"); - logI("- carrier: %s\n",ds.carrier.c_str()); - logI("- category: %s\n",ds.category.c_str()); - logI("- vendor: %s\n",ds.vendor.c_str()); - logI("- writer: %s\n",ds.writer.c_str()); - logI("- composer: %s\n",ds.composer.c_str()); - logI("- arranger: %s\n",ds.arranger.c_str()); - logI("- copyright: %s\n",ds.copyright.c_str()); - logI("- management group: %s\n",ds.manGroup.c_str()); - logI("- management info: %s\n",ds.manInfo.c_str()); - logI("- created on: %s\n",ds.createdDate.c_str()); - logI("- revision date: %s\n",ds.revisionDate.c_str()); + logI("%s by %s",ds.name.c_str(),ds.author.c_str()); + logI("has YMU-specific data:"); + logI("- carrier: %s",ds.carrier.c_str()); + logI("- category: %s",ds.category.c_str()); + logI("- vendor: %s",ds.vendor.c_str()); + logI("- writer: %s",ds.writer.c_str()); + logI("- composer: %s",ds.composer.c_str()); + logI("- arranger: %s",ds.arranger.c_str()); + logI("- copyright: %s",ds.copyright.c_str()); + logI("- management group: %s",ds.manGroup.c_str()); + logI("- management info: %s",ds.manInfo.c_str()); + logI("- created on: %s",ds.createdDate.c_str()); + logI("- revision date: %s",ds.revisionDate.c_str()); } else { ds.name=reader.readString((unsigned char)reader.readC()); ds.author=reader.readString((unsigned char)reader.readC()); - logI("%s by %s\n",ds.name.c_str(),ds.author.c_str()); + logI("%s by %s",ds.name.c_str(),ds.author.c_str()); } // compatibility flags @@ -164,7 +164,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { ds.tuning=443.23; } - logI("reading module data...\n"); + logI("reading module data..."); if (ds.version>0x0c) { ds.hilightA=reader.readC(); ds.hilightB=reader.readC(); @@ -186,7 +186,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { try { ds.hz=std::stoi(hz); } catch (std::exception& e) { - logW("invalid custom Hz!\n"); + logW("invalid custom Hz!"); ds.hz=60; } } @@ -199,25 +199,25 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { ds.ordersLen=(unsigned char)reader.readC(); if (ds.patLen<0) { - logE("pattern length is negative!\n"); + logE("pattern length is negative!"); lastError="pattern lengrh is negative!"; delete[] file; return false; } if (ds.patLen>256) { - logE("pattern length is too large!\n"); + logE("pattern length is too large!"); lastError="pattern length is too large!"; delete[] file; return false; } if (ds.ordersLen<0) { - logE("song length is negative!\n"); + logE("song length is negative!"); lastError="song length is negative!"; delete[] file; return false; } if (ds.ordersLen>127) { - logE("song is too long!\n"); + logE("song is too long!"); lastError="song is too long!"; delete[] file; return false; @@ -258,12 +258,12 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { addWarning("Yamaha YMU759 emulation is incomplete! please migrate your song to the OPL3 system."); } - logI("reading pattern matrix (%d)...\n",ds.ordersLen); + logI("reading pattern matrix (%d)...",ds.ordersLen); for (int i=0; i0x7f) { - logE("order at %d, %d out of range! (%d)\n",i,j,ds.orders.ord[i][j]); + logE("order at %d, %d out of range! (%d)",i,j,ds.orders.ord[i][j]); lastError=fmt::sprintf("order at %d, %d out of range! (%d)",i,j,ds.orders.ord[i][j]); delete[] file; return false; @@ -279,19 +279,19 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { } else { ds.insLen=16; } - logI("reading instruments (%d)...\n",ds.insLen); + logI("reading instruments (%d)...",ds.insLen); for (int i=0; i0x03) { ins->name=reader.readString((unsigned char)reader.readC()); } - logD("%d name: %s\n",i,ins->name.c_str()); + logD("%d name: %s",i,ins->name.c_str()); if (ds.version<0x0b) { // instruments in ancient versions were all FM or STD. ins->mode=1; } else { unsigned char mode=reader.readC(); - if (mode>1) logW("%d: invalid instrument mode %d!\n",i,mode); + if (mode>1) logW("%d: invalid instrument mode %d!",i,mode); ins->mode=mode; } ins->type=ins->mode?DIV_INS_FM:DIV_INS_STD; @@ -336,7 +336,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { ins->fm.ops=4; } if (ins->fm.ops!=2 && ins->fm.ops!=4) { - logE("invalid op count %d. did we read it wrong?\n",ins->fm.ops); + logE("invalid op count %d. did we read it wrong?",ins->fm.ops); lastError="file is corrupt or unreadable at operators"; delete[] file; return false; @@ -399,7 +399,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { } } - logD("OP%d: AM %d AR %d DAM %d DR %d DVB %d EGT %d KSL %d MULT %d RR %d SL %d SUS %d TL %d VIB %d WS %d RS %d DT %d D2R %d SSG-EG %d\n",j, + logD("OP%d: AM %d AR %d DAM %d DR %d DVB %d EGT %d KSL %d MULT %d RR %d SL %d SUS %d TL %d VIB %d WS %d RS %d DT %d D2R %d SSG-EG %d",j, ins->fm.op[j].am, ins->fm.op[j].ar, ins->fm.op[j].dam, @@ -532,7 +532,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { ins->gb.soundLen=reader.readC(); ins->std.volMacro.open=false; - logD("GB data: vol %d dir %d len %d sl %d\n",ins->gb.envVol,ins->gb.envDir,ins->gb.envLen,ins->gb.soundLen); + logD("GB data: vol %d dir %d len %d sl %d",ins->gb.envVol,ins->gb.envDir,ins->gb.envLen,ins->gb.soundLen); } else if (ds.system[0]==DIV_SYSTEM_GB) { // try to convert macro to envelope if (ins->std.volMacro.len>0) { @@ -553,7 +553,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { if (ds.version>0x0b) { ds.waveLen=(unsigned char)reader.readC(); - logI("reading wavetables (%d)...\n",ds.waveLen); + logI("reading wavetables (%d)...",ds.waveLen); for (int i=0; ilen=(unsigned char)reader.readI(); @@ -564,12 +564,12 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { wave->max=63; } if (wave->len>65) { - logE("invalid wave length %d. are we doing something wrong?\n",wave->len); + logE("invalid wave length %d. are we doing something wrong?",wave->len); lastError="file is corrupt or unreadable at wavetables"; delete[] file; return false; } - logD("%d length %d\n",i,wave->len); + logD("%d length %d",i,wave->len); for (int j=0; jlen; j++) { if (ds.version<0x0e) { wave->data[j]=reader.readC(); @@ -588,7 +588,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { } } - logI("reading patterns (%d channels, %d orders)...\n",getChannelCount(ds.system[0]),ds.ordersLen); + logI("reading patterns (%d channels, %d orders)...",getChannelCount(ds.system[0]),ds.ordersLen); for (int i=0; i4 || chan.effectRows<1) { - logE("invalid effect row count %d. are you sure everything is ok?\n",chan.effectRows); + logE("invalid effect row count %d. are you sure everything is ok?",chan.effectRows); lastError="file is corrupt or unreadable at effect rows"; delete[] file; return false; @@ -629,7 +629,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { pat->data[k][1]+=2; } if (pat->data[k][0]==0 && pat->data[k][1]!=0) { - logD("what? %d:%d:%d note %d octave %d\n",i,j,k,pat->data[k][0],pat->data[k][1]); + logD("what? %d:%d:%d note %d octave %d",i,j,k,pat->data[k][0],pat->data[k][1]); pat->data[k][0]=12; pat->data[k][1]--; } @@ -676,7 +676,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { } ds.sampleLen=(unsigned char)reader.readC(); - logI("reading samples (%d)...\n",ds.sampleLen); + logI("reading samples (%d)...",ds.sampleLen); if (ds.version<0x0b && ds.sampleLen>0) { // TODO what is this for? reader.readC(); } @@ -687,7 +687,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { int vol=50; short* data; if (length<0) { - logE("invalid sample length %d. are we doing something wrong?\n",length); + logE("invalid sample length %d. are we doing something wrong?",length); lastError="file is corrupt or unreadable at samples"; delete[] file; return false; @@ -697,7 +697,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { } else { sample->name=""; } - logD("%d name %s (%d)\n",i,sample->name.c_str(),length); + logD("%d name %s (%d)",i,sample->name.c_str(),length); sample->rate=22050; if (ds.version>=0x0b) { sample->rate=fileToDivRate(reader.readC()); @@ -707,7 +707,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { if (ds.version>0x15) { sample->depth=reader.readC(); if (sample->depth!=8 && sample->depth!=16) { - logW("%d: sample depth is wrong! (%d)\n",i,sample->depth); + logW("%d: sample depth is wrong! (%d)",i,sample->depth); sample->depth=16; } } else { @@ -724,12 +724,12 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { } if (pitch!=5) { - logD("%d: scaling from %d...\n",i,pitch); + logD("%d: scaling from %d...",i,pitch); } // render data if (!sample->init((double)length/samplePitches[pitch])) { - logE("%d: error while initializing sample!\n",i); + logE("%d: error while initializing sample!",i); } unsigned int k=0; @@ -754,7 +754,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { if (reader.tell()DIV_ENGINE_VERSION) { - logW("this module was created with a more recent version of Furnace!\n"); + logW("this module was created with a more recent version of Furnace!"); addWarning("this module was created with a more recent version of Furnace!"); } @@ -903,7 +903,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { int infoSeek=reader.readI(); if (!reader.seek(infoSeek,SEEK_SET)) { - logE("couldn't seek to info header at %d!\n",infoSeek); + logE("couldn't seek to info header at %d!",infoSeek); lastError="couldn't seek to info header!"; delete[] file; return false; @@ -912,7 +912,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { // read header reader.read(magic,4); if (strcmp(magic,"INFO")!=0) { - logE("invalid info header!\n"); + logE("invalid info header!"); lastError="invalid info header!"; delete[] file; return false; @@ -939,49 +939,49 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { int numberOfPats=reader.readI(); if (ds.patLen<0) { - logE("pattern length is negative!\n"); + logE("pattern length is negative!"); lastError="pattern lengrh is negative!"; delete[] file; return false; } if (ds.patLen>256) { - logE("pattern length is too large!\n"); + logE("pattern length is too large!"); lastError="pattern length is too large!"; delete[] file; return false; } if (ds.ordersLen<0) { - logE("song length is negative!\n"); + logE("song length is negative!"); lastError="song length is negative!"; delete[] file; return false; } if (ds.ordersLen>256) { - logE("song is too long!\n"); + logE("song is too long!"); lastError="song is too long!"; delete[] file; return false; } if (ds.insLen<0 || ds.insLen>256) { - logE("invalid instrument count!\n"); + logE("invalid instrument count!"); lastError="invalid instrument count!"; delete[] file; return false; } if (ds.waveLen<0 || ds.waveLen>256) { - logE("invalid wavetable count!\n"); + logE("invalid wavetable count!"); lastError="invalid wavetable count!"; delete[] file; return false; } if (ds.sampleLen<0 || ds.sampleLen>256) { - logE("invalid sample count!\n"); + logE("invalid sample count!"); lastError="invalid sample count!"; delete[] file; return false; } if (numberOfPats<0) { - logE("invalid pattern count!\n"); + logE("invalid pattern count!"); lastError="invalid pattern count!"; delete[] file; return false; @@ -991,7 +991,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { unsigned char sysID=reader.readC(); ds.system[i]=systemFromFileFur(sysID); if (sysID!=0 && systemToFileFur(ds.system[i])==0) { - logE("unrecognized system ID %.2x\n",ds.system[i]); + logE("unrecognized system ID %.2x",ds.system[i]); lastError=fmt::sprintf("unrecognized system ID %.2x!",ds.system[i]); delete[] file; return false; @@ -1004,7 +1004,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { } if (tchans>DIV_MAX_CHANS) { tchans=DIV_MAX_CHANS; - logW("too many channels!\n"); + logW("too many channels!"); } // system volume @@ -1061,7 +1061,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { ds.name=reader.readString(); ds.author=reader.readString(); - logI("%s by %s\n",ds.name.c_str(),ds.author.c_str()); + logI("%s by %s",ds.name.c_str(),ds.author.c_str()); if (ds.version>=33) { ds.tuning=reader.readF(); @@ -1167,7 +1167,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { reader.read(samplePtr,ds.sampleLen*4); for (int i=0; i8) { - logE("channel %d has zero or too many effect columns! (%d)\n",i,ds.pat[i].effectRows); + logE("channel %d has zero or too many effect columns! (%d)",i,ds.pat[i].effectRows); lastError=fmt::sprintf("channel %d has too many effect columns! (%d)",i,ds.pat[i].effectRows); delete[] file; return false; @@ -1242,9 +1242,9 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { // read instruments for (int i=0; iname=reader.readString(); sample->samples=reader.readI(); @@ -1348,12 +1348,12 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { reader.read(data,2*length); if (pitch!=5) { - logD("%d: scaling from %d...\n",i,pitch); + logD("%d: scaling from %d...",i,pitch); } // render data if (sample->depth!=8 && sample->depth!=16) { - logW("%d: sample depth is wrong! (%d)\n",i,sample->depth); + logW("%d: sample depth is wrong! (%d)",i,sample->depth); sample->depth=16; } sample->samples=(double)sample->samples/samplePitches[pitch]; @@ -1383,16 +1383,16 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { // read patterns for (int i: patPtr) { if (!reader.seek(i,SEEK_SET)) { - logE("couldn't seek to pattern in %x!\n",i); + logE("couldn't seek to pattern in %x!",i); lastError=fmt::sprintf("couldn't seek to pattern in %x!",i); ds.unload(); delete[] file; return false; } reader.read(magic,4); - logD("reading pattern in %x...\n",i); + logD("reading pattern in %x...",i); if (strcmp(magic,"PATR")!=0) { - logE("%x: invalid pattern header!\n",i); + logE("%x: invalid pattern header!",i); lastError="invalid pattern header!"; ds.unload(); delete[] file; @@ -1404,17 +1404,17 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { int index=reader.readS(); reader.readI(); - logD("- %d, %d\n",chan,index); + logD("- %d, %d",chan,index); if (chan<0 || chan>=tchans) { - logE("pattern channel out of range!\n",i); + logE("pattern channel out of range!",i); lastError="pattern channel out of range!"; ds.unload(); delete[] file; return false; } if (index<0 || index>255) { - logE("pattern index out of range!\n",i); + logE("pattern index out of range!",i); lastError="pattern index out of range!"; ds.unload(); delete[] file; @@ -1440,7 +1440,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { if (reader.tell()='1' && magic[0]<='9') { - logD("detected a FastTracker module\n"); + logD("detected a FastTracker module"); chCount=magic[0]-'0'; } else if (memcmp(magic,"FLT",3)==0 && magic[3]>='1' && magic[3]<='9') { - logD("detected a Fairlight module\n"); + logD("detected a Fairlight module"); chCount=magic[3]-'0'; } else if (memcmp(magic,"TDZ",3)==0 && magic[3]>='1' && magic[3]<='9') { - logD("detected a TakeTracker module\n"); + logD("detected a TakeTracker module"); chCount=magic[3]-'0'; } else if ((memcmp(magic+2,"CH",2)==0 || memcmp(magic+2,"CN",2)==0) && (magic[0]>='1' && magic[0]<='9' && magic[1]>='0' && magic[1]<='9')) { - logD("detected a Fast/TakeTracker module\n"); + logD("detected a Fast/TakeTracker module"); chCount=((magic[0]-'0')*10)+(magic[1]-'0'); } else { // TODO: Soundtracker MOD? @@ -1832,10 +1832,10 @@ bool DivEngine::loadMod(unsigned char* file, size_t len) { } success=true; } catch (EndOfFileException& e) { - //logE("premature end of file!\n"); + //logE("premature end of file!"); lastError="incomplete file"; } catch (InvalidHeaderException& e) { - //logE("invalid info header!\n"); + //logE("invalid info header!"); lastError="invalid info header!"; } return success; @@ -1853,14 +1853,14 @@ bool DivEngine::load(unsigned char* f, size_t slen) { if (memcmp(f,DIV_DMF_MAGIC,16)!=0 && memcmp(f,DIV_FUR_MAGIC,16)!=0) { // try loading as a .mod first before trying to decompress // TODO: move to a different location? - logD("loading as .mod...\n"); + logD("loading as .mod..."); if (loadMod(f,slen)) { delete[] f; return true; } lastError="not a .mod song"; - logD("loading as zlib...\n"); + logD("loading as zlib..."); // try zlib z_stream zl; memset(&zl,0,sizeof(z_stream)); @@ -1875,9 +1875,9 @@ bool DivEngine::load(unsigned char* f, size_t slen) { nextErr=inflateInit(&zl); if (nextErr!=Z_OK) { if (zl.msg==NULL) { - logE("zlib error: unknown! %d\n",nextErr); + logE("zlib error: unknown! %d",nextErr); } else { - logE("zlib error: %s\n",zl.msg); + logE("zlib error: %s",zl.msg); } inflateEnd(&zl); delete[] f; @@ -1894,10 +1894,10 @@ bool DivEngine::load(unsigned char* f, size_t slen) { nextErr=inflate(&zl,Z_SYNC_FLUSH); if (nextErr!=Z_OK && nextErr!=Z_STREAM_END) { if (zl.msg==NULL) { - logE("zlib error: unknown error! %d\n",nextErr); + logE("zlib error: unknown error! %d",nextErr); lastError="unknown decompression error"; } else { - logE("zlib inflate: %s\n",zl.msg); + logE("zlib inflate: %s",zl.msg); lastError=fmt::sprintf("decompression error: %s",zl.msg); } for (InflateBlock* i: blocks) delete i; @@ -1916,10 +1916,10 @@ bool DivEngine::load(unsigned char* f, size_t slen) { nextErr=inflateEnd(&zl); if (nextErr!=Z_OK) { if (zl.msg==NULL) { - logE("zlib end error: unknown error! %d\n",nextErr); + logE("zlib end error: unknown error! %d",nextErr); lastError="unknown decompression finish error"; } else { - logE("zlib end: %s\n",zl.msg); + logE("zlib end: %s",zl.msg); lastError=fmt::sprintf("decompression finish error: %s",zl.msg); } for (InflateBlock* i: blocks) delete i; @@ -1934,7 +1934,7 @@ bool DivEngine::load(unsigned char* f, size_t slen) { finalSize+=i->blockSize; } if (finalSize<1) { - logE("compressed too small!\n"); + logE("compressed too small!"); lastError="file too small"; for (InflateBlock* i: blocks) delete i; blocks.clear(); @@ -1951,7 +1951,7 @@ bool DivEngine::load(unsigned char* f, size_t slen) { len=finalSize; delete[] f; } else { - logD("loading as uncompressed\n"); + logD("loading as uncompressed"); file=(unsigned char*)f; len=slen; } @@ -1960,7 +1960,7 @@ bool DivEngine::load(unsigned char* f, size_t slen) { } else if (memcmp(file,DIV_FUR_MAGIC,16)==0) { return loadFur(file,len); } - logE("not a valid module!\n"); + logE("not a valid module!"); lastError="not a compatible song"; delete[] file; return false; @@ -2227,7 +2227,7 @@ SafeWriter* DivEngine::saveFur(bool notPrimary) { SafeWriter* DivEngine::saveDMF(unsigned char version) { // fail if version is not supported if (version<24 || version>26) { - logE("cannot save in this version!\n"); + logE("cannot save in this version!"); lastError="invalid version to save in! this is a bug!"; return NULL; } @@ -2255,60 +2255,60 @@ SafeWriter* DivEngine::saveDMF(unsigned char version) { } // fail if more than one system if (!isFlat && song.systemLen!=1) { - logE("cannot save multiple systems in this format!\n"); + logE("cannot save multiple systems in this format!"); lastError="multiple systems not possible on .dmf"; return NULL; } // fail if this is an YMU759 song if (song.system[0]==DIV_SYSTEM_YMU759) { - logE("cannot save YMU759 song!\n"); + logE("cannot save YMU759 song!"); lastError="YMU759 song saving is not supported"; return NULL; } // fail if the system is SMS+OPLL and version<25 if (version<25 && song.system[0]==DIV_SYSTEM_SMS && song.system[1]==DIV_SYSTEM_OPLL) { - logE("Master System FM expansion not supported in 1.0/legacy .dmf!\n"); + logE("Master System FM expansion not supported in 1.0/legacy .dmf!"); lastError="Master System FM expansion not supported in 1.0/legacy .dmf!"; return NULL; } // fail if the system is NES+VRC7 and version<25 if (version<25 && song.system[0]==DIV_SYSTEM_NES && song.system[1]==DIV_SYSTEM_VRC7) { - logE("NES + VRC7 not supported in 1.0/legacy .dmf!\n"); + logE("NES + VRC7 not supported in 1.0/legacy .dmf!"); lastError="NES + VRC7 not supported in 1.0/legacy .dmf!"; return NULL; } // fail if the system is FDS and version<25 if (version<25 && song.system[0]==DIV_SYSTEM_NES && song.system[1]==DIV_SYSTEM_FDS) { - logE("FDS not supported in 1.0/legacy .dmf!\n"); + logE("FDS not supported in 1.0/legacy .dmf!"); lastError="FDS not supported in 1.0/legacy .dmf!"; return NULL; } // fail if the system is Furnace-exclusive if (!isFlat && systemToFileDMF(song.system[0])==0) { - logE("cannot save Furnace-exclusive system song!\n"); + logE("cannot save Furnace-exclusive system song!"); lastError="this system is not possible on .dmf"; return NULL; } // fail if values are out of range if (song.ordersLen>127) { - logE("maximum .dmf song length is 127!\n"); + logE("maximum .dmf song length is 127!"); lastError="maximum .dmf song length is 127"; return NULL; } if (song.ins.size()>128) { - logE("maximum number of instruments in .dmf is 128!\n"); + logE("maximum number of instruments in .dmf is 128!"); lastError="maximum number of instruments in .dmf is 128"; return NULL; } if (song.wave.size()>64) { - logE("maximum number of wavetables in .dmf is 64!\n"); + logE("maximum number of wavetables in .dmf is 64!"); lastError="maximum number of wavetables in .dmf is 64"; return NULL; } for (int i=0; i0x7f) { - logE("order %d, %d is out of range (0-127)!\n",song.orders.ord[i][j]); + logE("order %d, %d is out of range (0-127)!",song.orders.ord[i][j]); lastError=fmt::sprintf("order %d, %d is out of range (0-127)",song.orders.ord[i][j]); return NULL; } @@ -2486,7 +2486,7 @@ SafeWriter* DivEngine::saveDMF(unsigned char version) { w->writeC(i->c64.s); w->writeC(i->c64.r); - logW("duty and cutoff precision will be lost!\n"); + logW("duty and cutoff precision will be lost!"); w->writeC((i->c64.duty*100)/4095); w->writeC(i->c64.ringMod); diff --git a/src/engine/fileOpsIns.cpp b/src/engine/fileOpsIns.cpp index 6658eea9..b88da310 100644 --- a/src/engine/fileOpsIns.cpp +++ b/src/engine/fileOpsIns.cpp @@ -41,10 +41,10 @@ void DivEngine::loadDMP(SafeReader& reader, std::vector& ret, St try { reader.seek(0,SEEK_SET); version=reader.readC(); - logD(".dmp version %d\n",version); + logD(".dmp version %d",version); } catch (EndOfFileException& e) { lastError="premature end of file"; - logE("premature end of file!\n"); + logE("premature end of file!"); delete ins; return; } @@ -64,38 +64,38 @@ void DivEngine::loadDMP(SafeReader& reader, std::vector& ret, St switch (sys) { case 1: // YMU759 ins->type=DIV_INS_FM; - logD("instrument type is YMU759\n"); + logD("instrument type is YMU759"); break; case 2: // Genesis ins->type=DIV_INS_FM; - logD("instrument type is Genesis\n"); + logD("instrument type is Genesis"); break; case 3: // SMS ins->type=DIV_INS_STD; - logD("instrument type is SMS\n"); + logD("instrument type is SMS"); break; case 4: // Game Boy ins->type=DIV_INS_GB; - logD("instrument type is Game Boy\n"); + logD("instrument type is Game Boy"); break; case 5: // PC Engine ins->type=DIV_INS_PCE; - logD("instrument type is PC Engine\n"); + logD("instrument type is PC Engine"); break; case 6: // NES ins->type=DIV_INS_STD; - logD("instrument type is NES\n"); + logD("instrument type is NES"); break; case 7: case 0x17: // C64 ins->type=DIV_INS_C64; - logD("instrument type is C64\n"); + logD("instrument type is C64"); break; case 8: // Arcade ins->type=DIV_INS_FM; - logD("instrument type is Arcade\n"); + logD("instrument type is Arcade"); break; default: - logD("instrument type is unknown\n"); + logD("instrument type is unknown"); lastError="unknown instrument type!"; delete ins; return; @@ -103,7 +103,7 @@ void DivEngine::loadDMP(SafeReader& reader, std::vector& ret, St } } catch (EndOfFileException& e) { lastError="premature end of file"; - logE("premature end of file!\n"); + logE("premature end of file!"); delete ins; return; } @@ -113,7 +113,7 @@ void DivEngine::loadDMP(SafeReader& reader, std::vector& ret, St bool mode=true; if (version>1) { mode=reader.readC(); - logD("instrument mode is %d\n",mode); + logD("instrument mode is %d",mode); if (mode==0) { if (version<11) { ins->type=DIV_INS_STD; @@ -126,7 +126,7 @@ void DivEngine::loadDMP(SafeReader& reader, std::vector& ret, St } if (mode) { // FM - logD("reading FM data...\n"); + logD("reading FM data..."); if (version<10) { if (version>1) { // bullcrap! no way to determine the instrument type other than a vague FM/STD! @@ -151,7 +151,7 @@ void DivEngine::loadDMP(SafeReader& reader, std::vector& ret, St if (sys!=1) ins->fm.ams=reader.readC(); for (int j=0; jfm.ops; j++) { - logD("OP%d is at %d\n",j,reader.tell()); + logD("OP%d is at %d",j,reader.tell()); ins->fm.op[j].mult=reader.readC(); ins->fm.op[j].tl=reader.readC(); ins->fm.op[j].ar=reader.readC(); @@ -179,7 +179,7 @@ void DivEngine::loadDMP(SafeReader& reader, std::vector& ret, St } } } else { // STD - logD("reading STD data...\n"); + logD("reading STD data..."); if (ins->type!=DIV_INS_GB) { ins->std.volMacro.len=reader.readC(); if (version>5) { @@ -295,7 +295,7 @@ void DivEngine::loadDMP(SafeReader& reader, std::vector& ret, St } } catch (EndOfFileException& e) { lastError="premature end of file"; - logE("premature end of file!\n"); + logE("premature end of file!"); delete ins; return; } @@ -330,7 +330,7 @@ void DivEngine::loadTFI(SafeReader& reader, std::vector& ret, St } } catch (EndOfFileException& e) { lastError="premature end of file"; - logE("premature end of file!\n"); + logE("premature end of file!"); delete ins; return; } @@ -372,7 +372,7 @@ void DivEngine::loadVGI(SafeReader& reader, std::vector& ret, St } } catch (EndOfFileException& e) { lastError="premature end of file"; - logE("premature end of file!\n"); + logE("premature end of file!"); delete ins; return; } @@ -453,7 +453,7 @@ void DivEngine::loadS3I(SafeReader& reader, std::vector& ret, St }; } catch (EndOfFileException& e) { lastError = "premature end of file"; - logE("premature end of file!\n"); + logE("premature end of file!"); delete ins; return; } @@ -623,7 +623,7 @@ void DivEngine::loadSBI(SafeReader& reader, std::vector& ret, St } catch (EndOfFileException& e) { lastError = "premature end of file"; - logE("premature end of file!\n"); + logE("premature end of file!"); delete ins; return; } @@ -640,7 +640,7 @@ void DivEngine::loadOPM(SafeReader& reader, std::vector& ret, St } catch (EndOfFileException& e) { lastError="premature end of file"; - logE("premature end of file!\n"); + logE("premature end of file!"); return; } } @@ -695,7 +695,7 @@ std::vector DivEngine::instrumentFromFile(const char* path) { } buf=new unsigned char[len]; if (fread(buf,1,len,f)!=(size_t)len) { - logW("did not read entire instrument file buffer!\n"); + logW("did not read entire instrument file buffer!"); lastError="did not read entire instrument file!"; delete[] buf; return ret; @@ -738,7 +738,7 @@ std::vector DivEngine::instrumentFromFile(const char* path) { } } catch (EndOfFileException& e) { lastError="premature end of file"; - logE("premature end of file!\n"); + logE("premature end of file!"); delete ins; delete[] buf; return ret; diff --git a/src/engine/filter.cpp b/src/engine/filter.cpp index 8e0ac02e..8b0e5a2e 100644 --- a/src/engine/filter.cpp +++ b/src/engine/filter.cpp @@ -30,7 +30,7 @@ float* DivFilterTables::sincIntegralTable=NULL; // licensed under same license as this program. float* DivFilterTables::getCubicTable() { if (cubicTable==NULL) { - logD("initializing cubic spline table.\n"); + logD("initializing cubic spline table."); cubicTable=new float[4096]; for (int i=0; i<1024; i++) { @@ -46,7 +46,7 @@ float* DivFilterTables::getCubicTable() { float* DivFilterTables:: getSincTable() { if (sincTable==NULL) { - logD("initializing sinc table.\n"); + logD("initializing sinc table."); sincTable=new float[65536]; sincTable[0]=1.0f; @@ -66,7 +66,7 @@ float* DivFilterTables:: getSincTable() { float* DivFilterTables::getSincIntegralTable() { if (sincIntegralTable==NULL) { - logD("initializing sinc integral table.\n"); + logD("initializing sinc integral table."); sincIntegralTable=new float[65536]; sincIntegralTable[0]=-0.5f; diff --git a/src/engine/instrument.cpp b/src/engine/instrument.cpp index 8f87e460..68896a45 100644 --- a/src/engine/instrument.cpp +++ b/src/engine/instrument.cpp @@ -486,7 +486,7 @@ DivDataErrors DivInstrument::readInsData(SafeReader& reader, short version) { char magic[4]; reader.read(magic,4); if (memcmp(magic,"INST",4)!=0) { - logE("invalid instrument header!\n"); + logE("invalid instrument header!"); return DIV_DATA_INVALID_HEADER; } reader.readI(); @@ -949,12 +949,12 @@ bool DivInstrument::save(const char* path) { FILE* outFile=ps_fopen(path,"wb"); if (outFile==NULL) { - logE("could not save instrument: %s!\n",strerror(errno)); + logE("could not save instrument: %s!",strerror(errno)); w->finish(); return false; } if (fwrite(w->getFinalBuf(),1,w->size(),outFile)!=w->size()) { - logW("did not write entire instrument!\n"); + logW("did not write entire instrument!"); } fclose(outFile); w->finish(); diff --git a/src/engine/platform/ay.cpp b/src/engine/platform/ay.cpp index 30a83812..727a1440 100644 --- a/src/engine/platform/ay.cpp +++ b/src/engine/platform/ay.cpp @@ -431,11 +431,11 @@ int DivPlatformAY8910::dispatch(DivCommand c) { if (c.value) { // port B ioPortB=true; portBVal=c.value2; - logI("AY I/O port B write: %x\n",portBVal); + logI("AY I/O port B write: %x",portBVal); } else { // port A ioPortA=true; portAVal=c.value2; - logI("AY I/O port A write: %x\n",portAVal); + logI("AY I/O port A write: %x",portAVal); } updateOutSel(true); immWrite(14+(c.value?1:0),(c.value?portBVal:portAVal)); diff --git a/src/engine/platform/ay8930.cpp b/src/engine/platform/ay8930.cpp index a470dceb..e9af64fc 100644 --- a/src/engine/platform/ay8930.cpp +++ b/src/engine/platform/ay8930.cpp @@ -456,11 +456,11 @@ int DivPlatformAY8930::dispatch(DivCommand c) { if (c.value) { // port B ioPortB=true; portBVal=c.value2; - logI("AY I/O port B write: %x\n",portBVal); + logI("AY I/O port B write: %x",portBVal); } else { // port A ioPortA=true; portAVal=c.value2; - logI("AY I/O port A write: %x\n",portAVal); + logI("AY I/O port A write: %x",portAVal); } updateOutSel(true); immWrite(14+(c.value?1:0),(c.value?portBVal:portAVal)); diff --git a/src/engine/platform/qsound.cpp b/src/engine/platform/qsound.cpp index a63ca9e5..0fd25ec7 100644 --- a/src/engine/platform/qsound.cpp +++ b/src/engine/platform/qsound.cpp @@ -336,7 +336,7 @@ void DivPlatformQSound::tick() { rWrite(q1_reg_map[Q1V_LOOP][i], qsound_loop); rWrite(q1_reg_map[Q1V_START][i], qsound_addr); rWrite(q1_reg_map[Q1V_PHASE][i], 0x8000); - //logW("ch %d bank=%04x, addr=%04x, end=%04x, loop=%04x!\n",i,qsound_bank,qsound_addr,qsound_end,qsound_loop); + //logV("ch %d bank=%04x, addr=%04x, end=%04x, loop=%04x!",i,qsound_bank,qsound_addr,qsound_end,qsound_loop); // Write sample address. Enable volume if (!chan[i].std.vol.had) { rWrite(q1_reg_map[Q1V_VOL][i], chan[i].vol << 4); @@ -347,7 +347,7 @@ void DivPlatformQSound::tick() { rWrite(q1_reg_map[Q1V_VOL][i], 0); rWrite(q1_reg_map[Q1V_FREQ][i], 0); } else if (chan[i].active) { - //logW("ch %d frequency set to %04x, off=%f, note=%d, %04x!\n",i,chan[i].freq,off,chan[i].note,QS_NOTE_FREQUENCY(chan[i].note)); + //logV("ch %d frequency set to %04x, off=%f, note=%d, %04x!",i,chan[i].freq,off,chan[i].note,QS_NOTE_FREQUENCY(chan[i].note)); rWrite(q1_reg_map[Q1V_FREQ][i], chan[i].freq); } if (chan[i].keyOn) chan[i].keyOn=false; diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index a9497d66..97047b64 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -1660,7 +1660,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi if (softLocked) { if (!isBusy.try_lock()) { - logV("audio is soft-locked (%d)\n",softLockCount++); + logV("audio is soft-locked (%d)",softLockCount++); return; } } else { @@ -1712,7 +1712,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi } } } - logD("%.2x\n",msg.type); + logD("%.2x",msg.type); output->midiIn->queue.pop(); } @@ -1845,7 +1845,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi if (remainingLoops>0) { remainingLoops--; if (!remainingLoops) { - logI("end of song!\n"); + logI("end of song!"); remainingLoops=-1; playing=false; freelance=false; @@ -1881,9 +1881,9 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi return; } - //logD("attempts: %d\n",attempts); + //logD("attempts: %d",attempts); if (attempts>=100) { - logE("hang detected! stopping! at %d seconds %d micro\n",totalSeconds,totalTicks); + logE("hang detected! stopping! at %d seconds %d micro",totalSeconds,totalTicks); freelance=false; playing=false; extValuePresent=false; diff --git a/src/engine/safeReader.cpp b/src/engine/safeReader.cpp index 9add1b5a..7fa66e8b 100644 --- a/src/engine/safeReader.cpp +++ b/src/engine/safeReader.cpp @@ -57,7 +57,7 @@ size_t SafeReader::size() { int SafeReader::read(void* where, size_t count) { #ifdef READ_DEBUG - logD("SR: reading %d bytes at %x\n",count,curSeek); + logD("SR: reading %d bytes at %x",count,curSeek); #endif if (count==0) return 0; if (curSeek+count>len) throw EndOfFileException(this,len); @@ -68,23 +68,23 @@ int SafeReader::read(void* where, size_t count) { signed char SafeReader::readC() { #ifdef READ_DEBUG - logD("SR: reading char %x:\n",curSeek); + logD("SR: reading char %x:",curSeek); #endif if (curSeek+1>len) throw EndOfFileException(this,len); #ifdef READ_DEBUG - logD("SR: %.2x\n",buf[curSeek]); + logD("SR: %.2x",buf[curSeek]); #endif return (signed char)buf[curSeek++]; } short SafeReader::readS() { #ifdef READ_DEBUG - logD("SR: reading short %x:\n",curSeek); + logD("SR: reading short %x:",curSeek); #endif if (curSeek+2>len) throw EndOfFileException(this,len); short ret=*(short*)(&buf[curSeek]); #ifdef READ_DEBUG - logD("SR: %.4x\n",ret); + logD("SR: %.4x",ret); #endif curSeek+=2; return ret; @@ -99,13 +99,13 @@ short SafeReader::readS_BE() { int SafeReader::readI() { #ifdef READ_DEBUG - logD("SR: reading int %x:\n",curSeek); + logD("SR: reading int %x:",curSeek); #endif if (curSeek+4>len) throw EndOfFileException(this,len); int ret=*(int*)(&buf[curSeek]); curSeek+=4; #ifdef READ_DEBUG - logD("SR: %.8x\n",ret); + logD("SR: %.8x",ret); #endif return ret; } @@ -141,7 +141,7 @@ double SafeReader::readD() { String SafeReader::readString(size_t stlen) { String ret; #ifdef READ_DEBUG - logD("SR: reading string len %d at %x\n",stlen,curSeek); + logD("SR: reading string len %d at %x",stlen,curSeek); #endif size_t curPos=0; while (curPosdepth,h->samples); \ samples=h->samples; \ \ - if (h->length!=getCurBufLen()) logW("undo buffer length not equal to current buffer length! %d != %d\n",h->length,getCurBufLen()); \ + if (h->length!=getCurBufLen()) logW("undo buffer length not equal to current buffer length! %d != %d",h->length,getCurBufLen()); \ \ void* buf=getCurBuf(); \ \ diff --git a/src/engine/vgmOps.cpp b/src/engine/vgmOps.cpp index 68df49c5..b2081348 100644 --- a/src/engine/vgmOps.cpp +++ b/src/engine/vgmOps.cpp @@ -415,7 +415,7 @@ void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write } if (write.addr>=0xffff0000) { // Furnace special command unsigned char streamID=streamOff+((write.addr&0xff00)>>8); - logD("writing stream command %x:%x with stream ID %d\n",write.addr,write.val,streamID); + logD("writing stream command %x:%x with stream ID %d",write.addr,write.val,streamID); switch (write.addr&0xff) { case 0: // play sample if (write.valoff8=sampleSeek; sampleSeek+=sample->length8; } @@ -1447,7 +1447,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version) { if (waitTime>0) { w->writeC(0x61); w->writeS(waitTime); - printf("wait is: %f\n",waitTime); + logV("wait is: %f",waitTime); totalWait-=waitTime; tickCount+=waitTime; } @@ -1561,7 +1561,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version) { freelance=false; extValuePresent=false; - logI("%d register writes total.\n",writeCount); + logI("%d register writes total.",writeCount); BUSY_END; return w; diff --git a/src/engine/wavetable.cpp b/src/engine/wavetable.cpp index 5d8c8a1d..db6c33b2 100644 --- a/src/engine/wavetable.cpp +++ b/src/engine/wavetable.cpp @@ -73,12 +73,12 @@ bool DivWavetable::save(const char* path) { FILE* outFile=ps_fopen(path,"wb"); if (outFile==NULL) { - logE("could not save wavetable: %s!\n",strerror(errno)); + logE("could not save wavetable: %s!",strerror(errno)); w->finish(); return false; } if (fwrite(w->getFinalBuf(),1,w->size(),outFile)!=w->size()) { - logW("did not write entire wavetable!\n"); + logW("did not write entire wavetable!"); } fclose(outFile); w->finish(); diff --git a/src/engine/winStuff.cpp b/src/engine/winStuff.cpp index 1830a301..79065e88 100644 --- a/src/engine/winStuff.cpp +++ b/src/engine/winStuff.cpp @@ -33,15 +33,15 @@ String getWinConfigPath() { configPath=path; configPath+=L"\\furnace"; if (!PathIsDirectoryW(configPath.c_str())) { - logI("creating config dir...\n"); + logI("creating config dir..."); int mkdirRet; if ((mkdirRet=SHCreateDirectory(NULL,configPath.c_str()))!=ERROR_SUCCESS) { - logW("could not make config dir! (%.8x)\n",mkdirRet); + logW("could not make config dir! (%.8x)",mkdirRet); configPath=L"."; } } } else { - logW("unable to determine config directory! (%.8x)\n",configHR); + logW("unable to determine config directory! (%.8x)",configHR); configPath=L"."; } return utf16To8(configPath.c_str()); diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index f9ae0428..a1b974e3 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -212,6 +212,9 @@ void FurnaceGUI::doAction(int what) { case GUI_ACTION_WINDOW_REGISTER_VIEW: nextWindow=GUI_WINDOW_REGISTER_VIEW; break; + case GUI_ACTION_WINDOW_LOG: + nextWindow=GUI_WINDOW_LOG; + break; case GUI_ACTION_COLLAPSE_WINDOW: collapseWindow=true; diff --git a/src/gui/editing.cpp b/src/gui/editing.cpp index 034ca441..96f827f3 100644 --- a/src/gui/editing.cpp +++ b/src/gui/editing.cpp @@ -546,8 +546,8 @@ void FurnaceGUI::doPaste(PasteMode mode) { } if (invalidData) { - logW("invalid clipboard data! failed at line %d char %d\n",i,charPos); - logW("%s\n",line.c_str()); + logW("invalid clipboard data! failed at line %d char %d",i,charPos); + logW("%s",line.c_str()); break; } j++; diff --git a/src/gui/fileDialog.cpp b/src/gui/fileDialog.cpp index 95a6ac7b..a0a10103 100644 --- a/src/gui/fileDialog.cpp +++ b/src/gui/fileDialog.cpp @@ -65,7 +65,7 @@ bool FurnaceGUIFileDialog::render(const ImVec2& min, const ImVec2& max) { if (dialogS!=NULL) { if (dialogS->ready(0)) { fileName=dialogS->result(); - logD("returning %s\n",fileName.c_str()); + logD("returning %s",fileName.c_str()); return true; } } @@ -74,10 +74,10 @@ bool FurnaceGUIFileDialog::render(const ImVec2& min, const ImVec2& max) { if (dialogO->ready(0)) { if (dialogO->result().empty()) { fileName=""; - logD("returning nothing\n"); + logD("returning nothing"); } else { fileName=dialogO->result()[0]; - logD("returning %s\n",fileName.c_str()); + logD("returning %s",fileName.c_str()); } return true; } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 66930051..ee69ae00 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -815,10 +815,10 @@ void FurnaceGUI::prepareLayout() { } // copy initial layout - logI("loading default layout.\n"); + logI("loading default layout."); check=ps_fopen(finalLayoutPath,"w"); if (check==NULL) { - logW("could not write default layout!\n"); + logW("could not write default layout!"); return; } @@ -1539,7 +1539,7 @@ int FurnaceGUI::save(String path, int dmfVersion) { memset(&zl,0,sizeof(z_stream)); ret=deflateInit(&zl,Z_DEFAULT_COMPRESSION); if (ret!=Z_OK) { - logE("zlib error!\n"); + logE("zlib error!"); lastError="compression error"; fclose(outFile); w->finish(); @@ -1551,7 +1551,7 @@ int FurnaceGUI::save(String path, int dmfVersion) { zl.avail_out=131072; zl.next_out=zbuf; if ((ret=deflate(&zl,Z_NO_FLUSH))==Z_STREAM_ERROR) { - logE("zlib stream error!\n"); + logE("zlib stream error!"); lastError="zlib stream error"; deflateEnd(&zl); fclose(outFile); @@ -1561,7 +1561,7 @@ int FurnaceGUI::save(String path, int dmfVersion) { size_t amount=131072-zl.avail_out; if (amount>0) { if (fwrite(zbuf,1,amount,outFile)!=amount) { - logE("did not write entirely: %s!\n",strerror(errno)); + logE("did not write entirely: %s!",strerror(errno)); lastError=strerror(errno); deflateEnd(&zl); fclose(outFile); @@ -1573,7 +1573,7 @@ int FurnaceGUI::save(String path, int dmfVersion) { zl.avail_out=131072; zl.next_out=zbuf; if ((ret=deflate(&zl,Z_FINISH))==Z_STREAM_ERROR) { - logE("zlib finish stream error!\n"); + logE("zlib finish stream error!"); lastError="zlib finish stream error"; deflateEnd(&zl); fclose(outFile); @@ -1582,7 +1582,7 @@ int FurnaceGUI::save(String path, int dmfVersion) { } if (131072-zl.avail_out>0) { if (fwrite(zbuf,1,131072-zl.avail_out,outFile)!=(131072-zl.avail_out)) { - logE("did not write entirely: %s!\n",strerror(errno)); + logE("did not write entirely: %s!",strerror(errno)); lastError=strerror(errno); deflateEnd(&zl); fclose(outFile); @@ -1593,7 +1593,7 @@ int FurnaceGUI::save(String path, int dmfVersion) { deflateEnd(&zl); #else if (fwrite(w->getFinalBuf(),1,w->size(),outFile)!=w->size()) { - logE("did not write entirely: %s!\n",strerror(errno)); + logE("did not write entirely: %s!",strerror(errno)); lastError=strerror(errno); fclose(outFile); w->finish(); @@ -1613,7 +1613,7 @@ int FurnaceGUI::save(String path, int dmfVersion) { int FurnaceGUI::load(String path) { if (!path.empty()) { - logI("loading module...\n"); + logI("loading module..."); FILE* f=ps_fopen(path.c_str(),"rb"); if (f==NULL) { perror("error"); @@ -1635,7 +1635,7 @@ int FurnaceGUI::load(String path) { } if (len<1) { if (len==0) { - logE("that file is empty!\n"); + logE("that file is empty!"); lastError="file is empty"; } else { perror("tell error"); @@ -1662,7 +1662,7 @@ int FurnaceGUI::load(String path) { fclose(f); if (!e->load(file,(size_t)len)) { lastError=e->getLastError(); - logE("could not open file!\n"); + logE("could not open file!"); return 1; } } @@ -2076,7 +2076,7 @@ bool FurnaceGUI::loop() { macroLoopDragActive=false; waveDragActive=false; if (sampleDragActive) { - logD("stopping sample drag\n"); + logD("stopping sample drag"); if (sampleDragMode) { e->renderSamplesP(); } else { @@ -2506,6 +2506,7 @@ bool FurnaceGUI::loop() { if (ImGui::MenuItem("oscilloscope",BIND_FOR(GUI_ACTION_WINDOW_OSCILLOSCOPE),oscOpen)) oscOpen=!oscOpen; if (ImGui::MenuItem("volume meter",BIND_FOR(GUI_ACTION_WINDOW_VOL_METER),volMeterOpen)) volMeterOpen=!volMeterOpen; if (ImGui::MenuItem("register view",BIND_FOR(GUI_ACTION_WINDOW_REGISTER_VIEW),regViewOpen)) regViewOpen=!regViewOpen; + if (ImGui::MenuItem("log viewer",BIND_FOR(GUI_ACTION_WINDOW_LOG),logOpen)) logOpen=!logOpen; if (ImGui::MenuItem("statistics",BIND_FOR(GUI_ACTION_WINDOW_STATS),statsOpen)) statsOpen=!statsOpen; ImGui::EndMenu(); @@ -2613,6 +2614,7 @@ bool FurnaceGUI::loop() { drawNotes(); drawChannels(); drawRegView(); + drawLog(); if (inspectorOpen) ImGui::ShowMetricsWindow(&inspectorOpen); @@ -2713,7 +2715,7 @@ bool FurnaceGUI::loop() { } break; case GUI_FILE_SAVE: { - logD("saving: %s\n",copyOfName.c_str()); + logD("saving: %s",copyOfName.c_str()); String lowerCase=fileName; for (char& i: lowerCase) { if (i>='A' && i<='Z') i+='a'-'A'; @@ -2730,7 +2732,7 @@ bool FurnaceGUI::loop() { break; } case GUI_FILE_SAVE_DMF_LEGACY: - logD("saving: %s\n",copyOfName.c_str()); + logD("saving: %s",copyOfName.c_str()); if (save(copyOfName,24)>0) { showError(fmt::sprintf("Error while saving file! (%s)",lastError)); } @@ -2865,7 +2867,7 @@ bool FurnaceGUI::loop() { if (aboutOpen) drawAbout(); if (ImGui::BeginPopupModal("Rendering...",NULL,ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::Text("Please wait...\n"); + ImGui::Text("Please wait..."); if (ImGui::Button("Abort")) { if (e->haltAudioFile()) { ImGui::CloseCurrentPopup(); @@ -2947,22 +2949,22 @@ bool FurnaceGUI::loop() { if (backupTimer<=0) { backupTask=std::async(std::launch::async,[this]() -> bool { if (backupPath==curFileName) { - logD("backup file open. not saving backup.\n"); + logD("backup file open. not saving backup."); return true; } - logD("saving backup...\n"); + logD("saving backup..."); SafeWriter* w=e->saveFur(true); if (w!=NULL) { FILE* outFile=ps_fopen(backupPath.c_str(),"wb"); if (outFile!=NULL) { if (fwrite(w->getFinalBuf(),1,w->size(),outFile)!=w->size()) { - logW("did not write backup entirely: %s!\n",strerror(errno)); + logW("did not write backup entirely: %s!",strerror(errno)); w->finish(); } fclose(outFile); } else { - logW("could not save backup: %s!\n",strerror(errno)); + logW("could not save backup: %s!",strerror(errno)); w->finish(); } } @@ -3037,6 +3039,7 @@ bool FurnaceGUI::init() { notesOpen=e->getConfBool("notesOpen",false); channelsOpen=e->getConfBool("channelsOpen",false); regViewOpen=e->getConfBool("regViewOpen",false); + logOpen=e->getConfBool("logOpen",false); tempoView=e->getConfBool("tempoView",true); waveHex=e->getConfBool("waveHex",false); @@ -3066,7 +3069,7 @@ bool FurnaceGUI::init() { sdlWin=SDL_CreateWindow("Furnace",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,scrW*dpiScale,scrH*dpiScale,SDL_WINDOW_RESIZABLE|SDL_WINDOW_ALLOW_HIGHDPI); if (sdlWin==NULL) { - logE("could not open window! %s\n",SDL_GetError()); + logE("could not open window! %s",SDL_GetError()); return false; } @@ -3091,14 +3094,14 @@ bool FurnaceGUI::init() { SDL_FreeSurface(icon); free(furIcon); } else { - logW("could not create icon!\n"); + logW("could not create icon!"); } #endif sdlRend=SDL_CreateRenderer(sdlWin,-1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_TARGETTEXTURE); if (sdlRend==NULL) { - logE("could not init renderer! %s\n",SDL_GetError()); + logE("could not init renderer! %s",SDL_GetError()); return false; } @@ -3115,14 +3118,14 @@ bool FurnaceGUI::init() { applyUISettings(); if (!ImGui::GetIO().Fonts->Build()) { - logE("error while building font atlas!\n"); + logE("error while building font atlas!"); showError("error while loading fonts! please check your settings."); ImGui::GetIO().Fonts->Clear(); mainFont=ImGui::GetIO().Fonts->AddFontDefault(); patFont=mainFont; ImGui_ImplSDLRenderer_DestroyFontsTexture(); if (!ImGui::GetIO().Fonts->Build()) { - logE("error again while building font atlas!\n"); + logE("error again while building font atlas!"); } } @@ -3199,6 +3202,7 @@ bool FurnaceGUI::finish() { e->setConf("notesOpen",notesOpen); e->setConf("channelsOpen",channelsOpen); e->setConf("regViewOpen",regViewOpen); + e->setConf("logOpen",logOpen); // commit last window size e->setConf("lastWindowWidth",scrW); @@ -3298,6 +3302,7 @@ FurnaceGUI::FurnaceGUI(): notesOpen(false), channelsOpen(false), regViewOpen(false), + logOpen(false), /* editControlsDocked(false), ordersDocked(false), diff --git a/src/gui/gui.h b/src/gui/gui.h index 641cf7c0..bcb7deee 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -167,6 +167,12 @@ enum FurnaceGUIColors { GUI_COLOR_PATTERN_EFFECT_SYS_SECONDARY, GUI_COLOR_PATTERN_EFFECT_MISC, + GUI_COLOR_LOGLEVEL_ERROR, + GUI_COLOR_LOGLEVEL_WARNING, + GUI_COLOR_LOGLEVEL_INFO, + GUI_COLOR_LOGLEVEL_DEBUG, + GUI_COLOR_LOGLEVEL_TRACE, + GUI_COLOR_EE_VALUE, GUI_COLOR_PLAYBACK_STAT, GUI_COLOR_MAX @@ -195,7 +201,8 @@ enum FurnaceGUIWindows { GUI_WINDOW_PIANO, GUI_WINDOW_NOTES, GUI_WINDOW_CHANNELS, - GUI_WINDOW_REGISTER_VIEW + GUI_WINDOW_REGISTER_VIEW, + GUI_WINDOW_LOG }; enum FurnaceGUIFileDialogs { @@ -290,6 +297,7 @@ enum FurnaceGUIActions { GUI_ACTION_WINDOW_NOTES, GUI_ACTION_WINDOW_CHANNELS, GUI_ACTION_WINDOW_REGISTER_VIEW, + GUI_ACTION_WINDOW_LOG, GUI_ACTION_COLLAPSE_WINDOW, GUI_ACTION_CLOSE_WINDOW, @@ -848,7 +856,7 @@ class FurnaceGUI { bool editControlsOpen, ordersOpen, insListOpen, songInfoOpen, patternOpen, insEditOpen; bool waveListOpen, waveEditOpen, sampleListOpen, sampleEditOpen, aboutOpen, settingsOpen; bool mixerOpen, debugOpen, inspectorOpen, oscOpen, volMeterOpen, statsOpen, compatFlagsOpen; - bool pianoOpen, notesOpen, channelsOpen, regViewOpen; + bool pianoOpen, notesOpen, channelsOpen, regViewOpen, logOpen; /* there ought to be a better way... bool editControlsDocked, ordersDocked, insListDocked, songInfoDocked, patternDocked, insEditDocked; @@ -1044,6 +1052,7 @@ class FurnaceGUI { void drawSettings(); void drawDebug(); void drawNewSong(); + void drawLog(); void parseKeybinds(); void promptKey(int which); diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index c3a7c72b..1b292638 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -191,6 +191,7 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={ D("WINDOW_NOTES", "Song Comments", 0), D("WINDOW_CHANNELS", "Channels", 0), D("WINDOW_REGISTER_VIEW", "Register View", 0), + D("WINDOW_LOG", "Log Viewer", 0), D("COLLAPSE_WINDOW", "Collapse/expand current window", 0), D("CLOSE_WINDOW", "Close current window", FURKMOD_SHIFT|SDLK_ESCAPE), @@ -473,6 +474,12 @@ const FurnaceGUIColorDef guiColors[GUI_COLOR_MAX]={ D(GUI_COLOR_PATTERN_EFFECT_SYS_SECONDARY,"",ImVec4(0.0f,1.0f,0.5f,1.0f)), D(GUI_COLOR_PATTERN_EFFECT_MISC,"",ImVec4(0.3f,0.3f,1.0f,1.0f)), + D(GUI_COLOR_LOGLEVEL_ERROR,"",ImVec4(1.0f,0.2f,0.2f,1.0f)), + D(GUI_COLOR_LOGLEVEL_WARNING,"",ImVec4(1.0f,1.0f,0.2f,1.0f)), + D(GUI_COLOR_LOGLEVEL_INFO,"",ImVec4(0.4f,1.0f,0.4f,1.0f)), + D(GUI_COLOR_LOGLEVEL_DEBUG,"",ImVec4(0.3f,0.5f,1.0f,1.0f)), + D(GUI_COLOR_LOGLEVEL_TRACE,"",ImVec4(0.8f,0.8f,0.8f,1.0f)), + D(GUI_COLOR_EE_VALUE,"",ImVec4(0.0f,1.0f,1.0f,1.0f)), D(GUI_COLOR_PLAYBACK_STAT,"",ImVec4(0.6f,0.6f,0.6f,1.0f)), }; diff --git a/src/gui/log.cpp b/src/gui/log.cpp new file mode 100644 index 00000000..2b83ab90 --- /dev/null +++ b/src/gui/log.cpp @@ -0,0 +1,71 @@ +#include "gui.h" +#include "../ta-log.h" +#include +#include + +const char* logLevels[5]={ + "ERROR", + "warning", + "info", + "debug", + "trace" +}; + +FurnaceGUIColors logColors[5]={ + GUI_COLOR_LOGLEVEL_ERROR, + GUI_COLOR_LOGLEVEL_WARNING, + GUI_COLOR_LOGLEVEL_INFO, + GUI_COLOR_LOGLEVEL_DEBUG, + GUI_COLOR_LOGLEVEL_TRACE +}; + +void FurnaceGUI::drawLog() { + if (nextWindow==GUI_WINDOW_LOG) { + logOpen=true; + ImGui::SetNextWindowFocus(); + nextWindow=GUI_WINDOW_NOTHING; + } + if (!logOpen) return; + if (ImGui::Begin("Log Viewer",&logOpen)) { + ImGui::Text("Level"); + ImGui::SameLine(); + ImGui::Combo("##LogLevel",&logLevel,logLevels,5); + if (ImGui::BeginTable("LogView",3,ImGuiTableFlags_ScrollY|ImGuiTableFlags_BordersInnerV)) { + ImGui::PushFont(patFont); + + float timeChars=ImGui::CalcTextSize("00:00:00").x; + float levelChars=ImGui::CalcTextSize("warning").x; + + ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed,timeChars); + ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed,levelChars); + ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch); + + ImGui::TableNextRow(ImGuiTableRowFlags_Headers); + ImGui::TableNextColumn(); + ImGui::TextUnformatted("time"); + ImGui::TableNextColumn(); + ImGui::TextUnformatted("level"); + ImGui::TableNextColumn(); + ImGui::TextUnformatted("message"); + + int pos=logPosition; + for (int i=0; i(logEntry.time).time_since_epoch().count(); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + // this will fail on 32-bit :< + ImGui::Text("%02ld:%02ld:%02ld",(t/3600)%24,(t/60)%60,t%60); + ImGui::TableNextColumn(); + ImGui::TextColored(uiColors[logColors[logEntry.loglevel]],"%s",logLevels[logEntry.loglevel]); + ImGui::TableNextColumn(); + ImGui::TextWrapped("%s",logEntry.text.c_str()); + } + ImGui::PopFont(); + ImGui::EndTable(); + } + } + ImGui::End(); +} \ No newline at end of file diff --git a/src/gui/midiMap.cpp b/src/gui/midiMap.cpp index 071540f9..568bf16e 100644 --- a/src/gui/midiMap.cpp +++ b/src/gui/midiMap.cpp @@ -64,7 +64,7 @@ int MIDIMap::at(const TAMidiMessage& where) { #define UNDERSTAND_ARRAY_OPTION(x,yMax) if (optionNameS==#x) { \ if (optionIndex<0 || optionIndex>=yMax) { \ - logW("MIDI map array option %d out of range (0-%d) at line %d: %s\n",optionIndex,yMax,curLine,line); \ + logW("MIDI map array option %d out of range (0-%d) at line %d: %s",optionIndex,yMax,curLine,line); \ break; \ } \ x[optionIndex]=std::stoi(optionValueS); \ @@ -76,7 +76,7 @@ bool MIDIMap::read(String path) { FILE* f=fopen(path.c_str(),"rb"); if (f==NULL) { if (errno!=ENOENT) { - logE("error while loading MIDI mapping! %s\n",strerror(errno)); + logE("error while loading MIDI mapping! %s",strerror(errno)); } return false; } @@ -93,7 +93,7 @@ bool MIDIMap::read(String path) { int result=sscanf(line,"aOption %255s %d %255s",optionName,&optionIndex,optionValue); if (result!=3) { - logW("MIDI map garbage data at line %d: %s\n",curLine,line); + logW("MIDI map garbage data at line %d: %s",curLine,line); break; } @@ -105,12 +105,12 @@ bool MIDIMap::read(String path) { UNDERSTAND_ARRAY_OPTION(valueInputSpecificMSB,18) else UNDERSTAND_ARRAY_OPTION(valueInputSpecificLSB,18) else UNDERSTAND_ARRAY_OPTION(valueInputSpecificSingle,18) else { - logW("MIDI map unknown array option %s at line %d: %s\n",optionName,curLine,line); + logW("MIDI map unknown array option %s at line %d: %s",optionName,curLine,line); } } catch (std::out_of_range& e) { - logW("MIDI map invalid value %s for array option %s at line %d: %s\n",optionValue,optionName,curLine,line); + logW("MIDI map invalid value %s for array option %s at line %d: %s",optionValue,optionName,curLine,line); } catch (std::invalid_argument& e) { - logW("MIDI map invalid value %s for array option %s at line %d: %s\n",optionValue,optionName,curLine,line); + logW("MIDI map invalid value %s for array option %s at line %d: %s",optionValue,optionName,curLine,line); } curLine++; @@ -122,7 +122,7 @@ bool MIDIMap::read(String path) { String optionNameS, optionValueS; int result=sscanf(line,"option %255s %255s",optionName,optionValue); if (result!=2) { - logW("MIDI map garbage data at line %d: %s\n",curLine,line); + logW("MIDI map garbage data at line %d: %s",curLine,line); break; } @@ -143,12 +143,12 @@ bool MIDIMap::read(String path) { UNDERSTAND_OPTION(valueInputControlLSB) else UNDERSTAND_OPTION(valueInputControlSingle) else UNDERSTAND_FLOAT_OPTION(volExp) else { - logW("MIDI map unknown option %s at line %d: %s\n",optionName,curLine,line); + logW("MIDI map unknown option %s at line %d: %s",optionName,curLine,line); } } catch (std::out_of_range& e) { - logW("MIDI map invalid value %s for option %s at line %d: %s\n",optionValue,optionName,curLine,line); + logW("MIDI map invalid value %s for option %s at line %d: %s",optionValue,optionName,curLine,line); } catch (std::invalid_argument& e) { - logW("MIDI map invalid value %s for option %s at line %d: %s\n",optionValue,optionName,curLine,line); + logW("MIDI map invalid value %s for option %s at line %d: %s",optionValue,optionName,curLine,line); } curLine++; @@ -159,7 +159,7 @@ bool MIDIMap::read(String path) { MIDIBind bind; int result=sscanf(line,"%d %d %d %d %255s",&bind.type,&bind.channel,&bind.data1,&bind.data2,bindAction); if (result!=5 || result==EOF) { - logW("MIDI map garbage data at line %d: %s\n",curLine,line); + logW("MIDI map garbage data at line %d: %s",curLine,line); break; } @@ -172,7 +172,7 @@ bool MIDIMap::read(String path) { } } if (!foundAction) { - logW("MIDI map unknown action %s at line %d: %s\n",bindAction,curLine,line); + logW("MIDI map unknown action %s at line %d: %s",bindAction,curLine,line); break; } @@ -191,7 +191,7 @@ bool MIDIMap::read(String path) { bool MIDIMap::write(String path) { FILE* f=fopen(path.c_str(),"wb"); if (f==NULL) { - logE("error while saving MIDI mapping! %s\n",strerror(errno)); + logE("error while saving MIDI mapping! %s",strerror(errno)); return false; } @@ -218,7 +218,7 @@ bool MIDIMap::write(String path) { for (MIDIBind& i: binds) { if (fprintf(f,"%d %d %d %d %s\n",i.type,i.channel,i.data1,i.data2,guiActions[i.action].name)<0) { - logW("did not write MIDI mapping entirely! %s\n",strerror(errno)); + logW("did not write MIDI mapping entirely! %s",strerror(errno)); break; } } @@ -274,6 +274,6 @@ void MIDIMap::compile() { } map[i.type-8][i.channel][i.data1][i.data2]=i.action; - logD("MIDI mapping %d %d %d %d to %d\n",i.type-8,i.channel,i.data1,i.data2,i.action); + logD("MIDI mapping %d %d %d %d to %d",i.type-8,i.channel,i.data1,i.data2,i.action); } } diff --git a/src/gui/pattern.cpp b/src/gui/pattern.cpp index d56196d6..0decef97 100644 --- a/src/gui/pattern.cpp +++ b/src/gui/pattern.cpp @@ -874,6 +874,6 @@ void FurnaceGUI::drawPattern() { if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_PATTERN; ImGui::End(); //int delta1=SDL_GetPerformanceCounter(); - //logV("render time: %dµs\n",(delta1-delta0)/(SDL_GetPerformanceFrequency()/1000000)); + //logV("render time: %dµs",(delta1-delta0)/(SDL_GetPerformanceFrequency()/1000000)); } diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 18a91e29..04af4cab 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -579,12 +579,12 @@ void FurnaceGUI::drawSampleEdit() { sampleTex=NULL; } if (avail.x>=1 && avail.y>=1) { - logD("recreating sample texture.\n"); + logD("recreating sample texture."); sampleTex=SDL_CreateTexture(sdlRend,SDL_PIXELFORMAT_ABGR8888,SDL_TEXTUREACCESS_STREAMING,avail.x,avail.y); sampleTexW=avail.x; sampleTexH=avail.y; if (sampleTex==NULL) { - logE("error while creating sample texture! %s\n",SDL_GetError()); + logE("error while creating sample texture! %s",SDL_GetError()); } else { updateSampleTex=true; } @@ -595,9 +595,9 @@ void FurnaceGUI::drawSampleEdit() { if (updateSampleTex) { unsigned int* data=NULL; int pitch=0; - logD("updating sample texture.\n"); + logD("updating sample texture."); if (SDL_LockTexture(sampleTex,NULL,(void**)&data,&pitch)!=0) { - logE("error while locking sample texture! %s\n",SDL_GetError()); + logE("error while locking sample texture! %s",SDL_GetError()); } else { ImU32 bgColor=ImGui::GetColorU32(ImGuiCol_FrameBg); ImU32 bgColorLoop=ImAlphaBlendColors(bgColor,ImGui::GetColorU32(ImGuiCol_FrameBgHovered,0.5)); diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index 316e3ef5..2727c3a3 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -384,8 +384,8 @@ void FurnaceGUI::drawSettings() { TAAudioDesc& audioWant=e->getAudioDescWant(); TAAudioDesc& audioGot=e->getAudioDescGot(); - ImGui::Text("want: %d samples @ %.0fHz\n",audioWant.bufsize,audioWant.rate); - ImGui::Text("got: %d samples @ %.0fHz\n",audioGot.bufsize,audioGot.rate); + ImGui::Text("want: %d samples @ %.0fHz",audioWant.bufsize,audioWant.rate); + ImGui::Text("got: %d samples @ %.0fHz",audioGot.bufsize,audioGot.rate); ImGui::Separator(); @@ -1053,6 +1053,14 @@ void FurnaceGUI::drawSettings() { UI_COLOR_CONFIG(GUI_COLOR_EE_VALUE,"External command output"); ImGui::TreePop(); } + if (ImGui::TreeNode("Log Viewer")) { + UI_COLOR_CONFIG(GUI_COLOR_LOGLEVEL_ERROR,"Log level: Error"); + UI_COLOR_CONFIG(GUI_COLOR_LOGLEVEL_WARNING,"Log level: Warning"); + UI_COLOR_CONFIG(GUI_COLOR_LOGLEVEL_INFO,"Log level: Info"); + UI_COLOR_CONFIG(GUI_COLOR_LOGLEVEL_DEBUG,"Log level: Debug"); + UI_COLOR_CONFIG(GUI_COLOR_LOGLEVEL_TRACE,"Log level: Trace/Verbose"); + ImGui::TreePop(); + } ImGui::TreePop(); } @@ -1126,6 +1134,7 @@ void FurnaceGUI::drawSettings() { UI_KEYBIND_CONFIG(GUI_ACTION_WINDOW_NOTES); UI_KEYBIND_CONFIG(GUI_ACTION_WINDOW_CHANNELS); UI_KEYBIND_CONFIG(GUI_ACTION_WINDOW_REGISTER_VIEW); + UI_KEYBIND_CONFIG(GUI_ACTION_WINDOW_LOG); UI_KEYBIND_CONFIG(GUI_ACTION_COLLAPSE_WINDOW); UI_KEYBIND_CONFIG(GUI_ACTION_CLOSE_WINDOW); @@ -1633,14 +1642,14 @@ void FurnaceGUI::commitSettings() { ImGui_ImplSDLRenderer_DestroyFontsTexture(); if (!ImGui::GetIO().Fonts->Build()) { - logE("error while building font atlas!\n"); + logE("error while building font atlas!"); showError("error while loading fonts! please check your settings."); ImGui::GetIO().Fonts->Clear(); mainFont=ImGui::GetIO().Fonts->AddFontDefault(); patFont=mainFont; ImGui_ImplSDLRenderer_DestroyFontsTexture(); if (!ImGui::GetIO().Fonts->Build()) { - logE("error again while building font atlas!\n"); + logE("error again while building font atlas!"); } } } @@ -1648,7 +1657,7 @@ void FurnaceGUI::commitSettings() { bool FurnaceGUI::importColors(String path) { FILE* f=ps_fopen(path.c_str(),"rb"); if (f==NULL) { - logW("error while opening color file for import: %s\n",strerror(errno)); + logW("error while opening color file for import: %s",strerror(errno)); return false; } resetColors(); @@ -1689,7 +1698,7 @@ bool FurnaceGUI::importColors(String path) { break; } } - if (!found) logW("line invalid: %s\n",line); + if (!found) logW("line invalid: %s",line); } } fclose(f); @@ -1699,12 +1708,12 @@ bool FurnaceGUI::importColors(String path) { bool FurnaceGUI::exportColors(String path) { FILE* f=ps_fopen(path.c_str(),"wb"); if (f==NULL) { - logW("error while opening color file for export: %s\n",strerror(errno)); + logW("error while opening color file for export: %s",strerror(errno)); return false; } for (int i=0; i6) settings.patFont=0; if (settings.mainFont==6 && settings.mainFontPath.empty()) { - logW("UI font path is empty! reverting to default font\n"); + logW("UI font path is empty! reverting to default font"); settings.mainFont=0; } if (settings.patFont==6 && settings.patFontPath.empty()) { - logW("pattern font path is empty! reverting to default font\n"); + logW("pattern font path is empty! reverting to default font"); settings.patFont=0; } @@ -2113,10 +2122,10 @@ void FurnaceGUI::applyUISettings() { if (settings.mainFont==6) { // custom font if ((mainFont=ImGui::GetIO().Fonts->AddFontFromFileTTF(settings.mainFontPath.c_str(),e->getConfInt("mainFontSize",18)*dpiScale,NULL,fontRange))==NULL) { - logW("could not load UI font! reverting to default font\n"); + logW("could not load UI font! reverting to default font"); settings.mainFont=0; if ((mainFont=ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(builtinFont[settings.mainFont],builtinFontLen[settings.mainFont],e->getConfInt("mainFontSize",18)*dpiScale,NULL,fontRange))==NULL) { - logE("could not load UI font! falling back to Proggy Clean.\n"); + logE("could not load UI font! falling back to Proggy Clean."); mainFont=ImGui::GetIO().Fonts->AddFontDefault(); } } @@ -2124,10 +2133,10 @@ void FurnaceGUI::applyUISettings() { if ((mainFont=ImGui::GetIO().Fonts->AddFontFromFileTTF(SYSTEM_FONT_PATH_1,e->getConfInt("mainFontSize",18)*dpiScale,NULL,fontRange))==NULL) { if ((mainFont=ImGui::GetIO().Fonts->AddFontFromFileTTF(SYSTEM_FONT_PATH_2,e->getConfInt("mainFontSize",18)*dpiScale,NULL,fontRange))==NULL) { if ((mainFont=ImGui::GetIO().Fonts->AddFontFromFileTTF(SYSTEM_FONT_PATH_3,e->getConfInt("mainFontSize",18)*dpiScale,NULL,fontRange))==NULL) { - logW("could not load UI font! reverting to default font\n"); + logW("could not load UI font! reverting to default font"); settings.mainFont=0; if ((mainFont=ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(builtinFont[settings.mainFont],builtinFontLen[settings.mainFont],e->getConfInt("mainFontSize",18)*dpiScale,NULL,fontRange))==NULL) { - logE("could not load UI font! falling back to Proggy Clean.\n"); + logE("could not load UI font! falling back to Proggy Clean."); mainFont=ImGui::GetIO().Fonts->AddFontDefault(); } } @@ -2135,7 +2144,7 @@ void FurnaceGUI::applyUISettings() { } } else { if ((mainFont=ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(builtinFont[settings.mainFont],builtinFontLen[settings.mainFont],e->getConfInt("mainFontSize",18)*dpiScale,NULL,fontRange))==NULL) { - logE("could not load UI font! falling back to Proggy Clean.\n"); + logE("could not load UI font! falling back to Proggy Clean."); mainFont=ImGui::GetIO().Fonts->AddFontDefault(); } } @@ -2149,18 +2158,18 @@ void FurnaceGUI::applyUISettings() { fc.GlyphMinAdvanceX=e->getConfInt("iconSize",16)*dpiScale; static const ImWchar fontRangeIcon[]={ICON_MIN_FA,ICON_MAX_FA,0}; if ((iconFont=ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(iconFont_compressed_data,iconFont_compressed_size,e->getConfInt("iconSize",16)*dpiScale,&fc,fontRangeIcon))==NULL) { - logE("could not load icon font!\n"); + logE("could not load icon font!"); } if (settings.mainFontSize==settings.patFontSize && settings.patFont<5 && builtinFontM[settings.patFont]==builtinFont[settings.mainFont]) { - logD("using main font for pat font.\n"); + logD("using main font for pat font."); patFont=mainFont; } else { if (settings.patFont==6) { // custom font if ((patFont=ImGui::GetIO().Fonts->AddFontFromFileTTF(settings.patFontPath.c_str(),e->getConfInt("patFontSize",18)*dpiScale,NULL,upTo800))==NULL) { - logW("could not load pattern font! reverting to default font\n"); + logW("could not load pattern font! reverting to default font"); settings.patFont=0; if ((patFont=ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(builtinFontM[settings.patFont],builtinFontMLen[settings.patFont],e->getConfInt("patFontSize",18)*dpiScale,NULL,upTo800))==NULL) { - logE("could not load pattern font! falling back to Proggy Clean.\n"); + logE("could not load pattern font! falling back to Proggy Clean."); patFont=ImGui::GetIO().Fonts->AddFontDefault(); } } @@ -2168,10 +2177,10 @@ void FurnaceGUI::applyUISettings() { if ((patFont=ImGui::GetIO().Fonts->AddFontFromFileTTF(SYSTEM_PAT_FONT_PATH_1,e->getConfInt("patFontSize",18)*dpiScale,NULL,upTo800))==NULL) { if ((patFont=ImGui::GetIO().Fonts->AddFontFromFileTTF(SYSTEM_PAT_FONT_PATH_2,e->getConfInt("patFontSize",18)*dpiScale,NULL,upTo800))==NULL) { if ((patFont=ImGui::GetIO().Fonts->AddFontFromFileTTF(SYSTEM_PAT_FONT_PATH_3,e->getConfInt("patFontSize",18)*dpiScale,NULL,upTo800))==NULL) { - logW("could not load pattern font! reverting to default font\n"); + logW("could not load pattern font! reverting to default font"); settings.patFont=0; if ((patFont=ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(builtinFontM[settings.patFont],builtinFontMLen[settings.patFont],e->getConfInt("patFontSize",18)*dpiScale,NULL,upTo800))==NULL) { - logE("could not load pattern font! falling back to Proggy Clean.\n"); + logE("could not load pattern font! falling back to Proggy Clean."); patFont=ImGui::GetIO().Fonts->AddFontDefault(); } } @@ -2179,13 +2188,13 @@ void FurnaceGUI::applyUISettings() { } } else { if ((patFont=ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(builtinFontM[settings.patFont],builtinFontMLen[settings.patFont],e->getConfInt("patFontSize",18)*dpiScale,NULL,upTo800))==NULL) { - logE("could not load pattern font!\n"); + logE("could not load pattern font!"); patFont=ImGui::GetIO().Fonts->AddFontDefault(); } } } if ((bigFont=ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(font_plexSans_compressed_data,font_plexSans_compressed_size,40*dpiScale))==NULL) { - logE("could not load big UI font!\n"); + logE("could not load big UI font!"); } mainFont->FallbackChar='?'; diff --git a/src/log.cpp b/src/log.cpp index 1f77925b..a3a6000c 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -17,12 +17,16 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -// TODO: improve these routines to allow logging to memory for eventual log window! - #include "ta-log.h" int logLevel=LOGLEVEL_INFO; +std::atomic logPosition; + +LogEntry logEntries[TA_LOG_SIZE]; + +static constexpr unsigned int TA_LOG_MASK=TA_LOG_SIZE-1; + int logV(const char* format, ...) { va_list va; int ret; @@ -55,21 +59,6 @@ int logD(const char* format, ...) { return ret; } -int logI(const char* format, ...) { - va_list va; - int ret; - if (logLevelgetFinalBuf(),1,w->size(),f); fclose(f); } else { - logE("could not open file! %s\n",strerror(errno)); + logE("could not open file! %s",strerror(errno)); } w->finish(); delete w; } else { - logE("could not write VGM!\n"); + logE("could not write VGM!"); } } if (outName!="") { @@ -391,7 +392,7 @@ int main(int argc, char** argv) { } if (consoleMode) { - logI("playing...\n"); + logI("playing..."); e.play(); #ifdef HAVE_GUI SDL_Event ev; @@ -417,7 +418,7 @@ int main(int argc, char** argv) { if (!g.init()) return 1; if (displayEngineFailError) { - logE("displaying engine fail error.\n"); + logE("displaying engine fail error."); g.showError("error while initializing audio!"); } @@ -426,13 +427,13 @@ int main(int argc, char** argv) { } g.loop(); - logI("closing GUI.\n"); + logI("closing GUI."); g.finish(); #else - logE("GUI requested but GUI not compiled!\n"); + logE("GUI requested but GUI not compiled!"); #endif - logI("stopping engine.\n"); + logI("stopping engine."); e.quit(); return 0; } diff --git a/src/ta-log.h b/src/ta-log.h index e7867de5..666dfa48 100644 --- a/src/ta-log.h +++ b/src/ta-log.h @@ -19,8 +19,12 @@ #ifndef _TA_LOG_H #define _TA_LOG_H +#include #include #include +#include +#include +#include #define LOGLEVEL_ERROR 0 #define LOGLEVEL_WARN 1 @@ -28,11 +32,51 @@ #define LOGLEVEL_DEBUG 3 #define LOGLEVEL_TRACE 4 +// this has to be a power of 2 +#define TA_LOG_SIZE 2048 + extern int logLevel; -int logV(const char* format, ...); -int logD(const char* format, ...); -int logI(const char* format, ...); -int logW(const char* format, ...); -int logE(const char* format, ...); +extern std::atomic logPosition; + +struct LogEntry { + int loglevel; + std::chrono::system_clock::time_point time; + std::string text; + bool ready; + LogEntry(): + loglevel(0), + ready(false) {} +}; + +int writeLog(int level, const char* msg, fmt::printf_args& args); + +extern LogEntry logEntries[TA_LOG_SIZE]; + +template int logV(const char* msg, const T&... args) { + fmt::printf_args a=fmt::make_printf_args(args...); + return writeLog(LOGLEVEL_TRACE,msg,a); +} + +template int logD(const char* msg, const T&... args) { + fmt::printf_args a=fmt::make_printf_args(args...); + return writeLog(LOGLEVEL_DEBUG,msg,a); +} + +template int logI(const char* msg, const T&... args) { + fmt::printf_args a=fmt::make_printf_args(args...); + return writeLog(LOGLEVEL_INFO,msg,a); +} + +template int logW(const char* msg, const T&... args) { + fmt::printf_args a=fmt::make_printf_args(args...); + return writeLog(LOGLEVEL_WARN,msg,a); +} + +template int logE(const char* msg, const T&... args) { + fmt::printf_args a=fmt::make_printf_args(args...); + return writeLog(LOGLEVEL_ERROR,msg,a); +} + +void initLog(); #endif