From e7ae5b72e4dd261f7e2fa0bff56fe1971939da2b Mon Sep 17 00:00:00 2001 From: Vasile Vilvoiu Date: Sat, 17 Jul 2021 18:57:07 +0300 Subject: Remove spdlog as a dependency. Closes #19. --- .github/workflows/build.yml | 2 +- CMakeLists.txt | 5 ++-- README.md | 2 +- src/renderer.cpp | 2 +- src/specgram.cpp | 56 ++++++++++++++++++++++++--------------------- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cab5552..cd36af6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/checkout@v2 - name: Install dependencies - run: sudo apt-get install libfftw3-dev libspdlog-dev libsfml-dev + run: sudo apt-get install libfftw3-dev libsfml-dev - name: Create Build Environment # Some projects don't allow in-source building, so create a separate build directory diff --git a/CMakeLists.txt b/CMakeLists.txt index 1936bea..12953dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,8 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Dependencies -find_package (spdlog REQUIRED) +set (THREADS_PREFER_PTHREAD_FLAG ON) +find_package (Threads REQUIRED) find_package (SFML 2.5 COMPONENTS window graphics REQUIRED) find_library (FFTW3 fftw3) @@ -63,7 +64,7 @@ set (SPECGRAM_SOURCES # Executable target add_executable (${PROJECT_NAME} ${SPECGRAM_SOURCES}) -target_link_libraries (${PROJECT_NAME} spdlog::spdlog sfml-window sfml-graphics ${FFTW3}) +target_link_libraries (${PROJECT_NAME} Threads::Threads sfml-window sfml-graphics ${FFTW3}) # HTML manpage target add_custom_target(manpage diff --git a/README.md b/README.md index 0515af6..aeda2c6 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ sudo make install ## Dependencies -This program dynamically links against [FFTW](http://www.fftw.org/), [SFML 2.5](https://www.sfml-dev.org/), and [spdlog](https://github.com/gabime/spdlog). +This program dynamically links against [FFTW](http://www.fftw.org/) and [SFML 2.5](https://www.sfml-dev.org/). The source code of [Taywee/args](https://github.com/Taywee/args) is embedded in the program (see ```src/args.hxx```). diff --git a/src/renderer.cpp b/src/renderer.cpp index 31e5c51..b8303f5 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -383,7 +383,7 @@ Renderer::GetNiceTicks(double v_min, double v_max, const std::string& v_unit, un } iteration++; - } while (iteration < MAXIMUM_ITERATIONS); /* maybe we should spdlog::warn() if we reach max iterations? */ + } while (iteration < MAXIMUM_ITERATIONS); /* maybe we should issue warning if we reach max iterations? */ /* find the first nice value */ double fval = v_min / factor; diff --git a/src/specgram.cpp b/src/specgram.cpp index d70126f..4b37cd5 100644 --- a/src/specgram.cpp +++ b/src/specgram.cpp @@ -13,8 +13,6 @@ #include "fft.hpp" #include "live.hpp" -#include -#include #include #include #include @@ -22,6 +20,7 @@ #include #include #include +#include /* main loop exit condition */ volatile bool main_loop_running = true; @@ -29,6 +28,18 @@ volatile bool main_loop_running = true; /* temporary output file name */ std::string temp_file_name = ""; +/* + * logger - logging is minimal and only happens in this file + */ +#define RESET "\033[0m" +#define GREEN "\033[32m" +#define YELLOW "\033[33m" +#define RED "\033[31m" + +#define INFO(str) { std::cerr << "[" << GREEN << "INFO" << RESET << "] " << str << std::endl; } +#define WARN(str) { std::cerr << "[" << YELLOW << "WARN" << RESET << "] " << str << std::endl; } +#define ERROR(str) { std::cerr << "[" << RED << "ERROR" << RESET << "] " << str << std::endl; } + /* * SIGINT handler */ @@ -94,7 +105,7 @@ dump_to_stdout(const sf::Image& image) /* save */ temp_file_name = "/dev/shm/" + generate_random_string(TEMP_FILENAME_LENGTH) + ".png"; - spdlog::info("Temporary file: {}", temp_file_name); + INFO("Temporary file: " << temp_file_name); image.saveToFile(temp_file_name); /* from now on we have a leakable resource (the file); if using STDIN for input, we're here from a SIGINT, @@ -116,7 +127,7 @@ dump_to_stdout(const sf::Image& image) /* clean up */ if (std::remove(temp_file_name.c_str()) != 0) { - spdlog::warn("Failed to delete temp file {}", temp_file_name); + WARN("Failed to delete temp file " << temp_file_name); } } @@ -126,9 +137,6 @@ dump_to_stdout(const sf::Image& image) int main(int argc, char** argv) { - /* set spdlog to STDERR and make it multithreaded */ - spdlog::set_default_logger(spdlog::stderr_color_mt("stderr")); - /* parse command line arguments into global settings */ auto [conf, conf_rc, conf_must_exit] = Configuration::FromArgs(argc, argv); if (conf_must_exit) { @@ -142,15 +150,13 @@ main(int argc, char** argv) auto win_function = WindowFunction::FromType(conf.GetWindowFunction(), conf.GetFFTWidth()); /* create FFT */ - spdlog::info("Creating {}-wide FFTW plan", conf.GetFFTWidth()); + INFO("Creating " << conf.GetFFTWidth() << "-wide FFTW plan"); FFT fft(conf.GetFFTWidth(), win_function); /* create value map */ - spdlog::info("Scale {}, unit {}, bounds [{}, {}]", - conf.GetScaleType() == ValueMapType::kLinear ? "linear" : "decibel", - conf.GetScaleUnit(), - conf.GetScaleLowerBound(), - conf.GetScaleUpperBound()); + INFO("Scale " << (conf.GetScaleType() == ValueMapType::kLinear ? "linear" : "decibel") << + ", unit " << conf.GetScaleUnit() << ", bounds [" << conf.GetScaleLowerBound() << + ", " << conf.GetScaleUpperBound() << "]"); std::unique_ptr value_map = ValueMap::Build(conf.GetScaleType(), conf.GetScaleLowerBound(), conf.GetScaleUpperBound(), @@ -178,17 +184,17 @@ main(int argc, char** argv) std::istream *input_stream = nullptr; std::unique_ptr reader = nullptr; if (conf.GetInputFilename().has_value()) { - spdlog::info("Input: {}", *conf.GetInputFilename()); + INFO("Input: " << *conf.GetInputFilename()); input_stream = new std::ifstream(*conf.GetInputFilename(), std::ios::in | std::ios::binary); assert(input_stream != nullptr); if (!input_stream->good()) { - spdlog::error("Failed to open input file '{}'", *conf.GetInputFilename()); + ERROR("Failed to open input file " << *conf.GetInputFilename()); return 1; } reader = std::make_unique(input_stream, input->GetDataTypeSize() * conf.GetBlockSize()); } else { - spdlog::info("Input: STDIN"); + INFO("Input: STDIN"); input_stream = &std::cin; reader = std::make_unique(input_stream, input->GetDataTypeSize() * conf.GetBlockSize()); @@ -196,14 +202,12 @@ main(int argc, char** argv) /* display initialization info */ if (input->IsFloatingPoint()) { - spdlog::info("Input stream: {}{}bit floating point at {}Hz", - input->IsComplex() ? "complex " : "", - input->GetDataTypeSize() * 8, conf.GetRate()); + INFO("Input stream: " << (input->IsComplex() ? "complex " : "") << input->GetDataTypeSize() * 8 << + "bit floating point at " << conf.GetRate() << "Hz"); } else { - spdlog::info("Input stream: {}{} {}bit integer at {}Hz", - input->IsComplex() ? "complex " : "", - input->IsSigned() ? "signed" : "unsigned", - input->GetDataTypeSize() * 8, conf.GetRate()); + INFO("Input stream: " << (input->IsComplex() ? "complex " : "") << + (input->IsSigned() ? "signed " : "unsigned ") << input->GetDataTypeSize() * 8 << + "bit integer at " << conf.GetRate() << "Hz"); } /* install SIGINT handler for CTRL+C */ @@ -309,7 +313,7 @@ main(int argc, char** argv) v = 0.0f; } } - spdlog::info("Terminating ..."); + INFO("Terminating ..."); /* close input file */ if (conf.GetInputFilename().has_value()) { @@ -353,10 +357,10 @@ main(int argc, char** argv) /* dump to file or stdout */ if (conf.GetOutputFilename().has_value()) { - spdlog::info("Output: {}", *conf.GetOutputFilename()); + INFO("Output: " << *conf.GetOutputFilename()); image.saveToFile(*conf.GetOutputFilename()); } else if (conf.MustDumpToStdout()) { - spdlog::info("Output: STDOUT"); + INFO("Output: STDOUT"); dump_to_stdout(image); } else { throw std::runtime_error("don't know what to do with output"); -- cgit v1.2.3