Replaced cout logs with log4cxx

This commit is contained in:
Jono Targett 2024-05-25 12:05:34 +09:30
parent c6d380b2c6
commit 40d78246bb
3 changed files with 14 additions and 4 deletions

View File

@ -0,0 +1,5 @@
#! /bin/sh
set -eux
usermod -a -G audio $(whoami)

View File

@ -3,7 +3,6 @@
#include <regex> #include <regex>
#include <iterator> #include <iterator>
#include <algorithm> #include <algorithm>
#include <iostream>
namespace SELCAL { namespace SELCAL {

View File

@ -5,6 +5,8 @@
#include <magic_enum.hpp> #include <magic_enum.hpp>
#include "midi.h" #include "midi.h"
#include <argparse/argparse.hpp> #include <argparse/argparse.hpp>
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
#include <thread> #include <thread>
#include <chrono> #include <chrono>
@ -14,6 +16,7 @@ constexpr int ALL_CHANNELS = -1;
constexpr double DEFAULT_TONE_DURATION = 1.0; constexpr double DEFAULT_TONE_DURATION = 1.0;
constexpr double DEFAULT_SILENCE_DURATION = 0.2; constexpr double DEFAULT_SILENCE_DURATION = 0.2;
static auto logger = log4cxx::Logger::getLogger("tone-generator");
/** /**
* The MIDI format only has a fixed number of notes it can play - 128 individual frequencies. * The MIDI format only has a fixed number of notes it can play - 128 individual frequencies.
@ -42,6 +45,9 @@ Tuning getSelcalTunings() {
int main(int argc, char** argv) { int main(int argc, char** argv) {
// Required to be up front before any logging occurs.
log4cxx::BasicConfigurator::configure();
double toneDuration = DEFAULT_TONE_DURATION; double toneDuration = DEFAULT_TONE_DURATION;
double silenceDuration = DEFAULT_SILENCE_DURATION; double silenceDuration = DEFAULT_SILENCE_DURATION;
bool listInstruments = false; bool listInstruments = false;
@ -88,13 +94,13 @@ int main(int argc, char** argv) {
auto tunings = getSelcalTunings(); auto tunings = getSelcalTunings();
if (!synth.setTuning(tunings)) { if (!synth.setTuning(tunings)) {
std::cerr << "Failed to set SELCAL tuning on synth" << std::endl; LOG4CXX_ERROR(logger, "Failed to set SELCAL tuning on synth");
return 1; return 1;
} }
auto files = parser.get<std::vector<std::string>>("--soundfont"); auto files = parser.get<std::vector<std::string>>("--soundfont");
for (auto file : files) { for (auto file : files) {
std::cout << "Loading soundfont from " << file << std::endl; LOG4CXX_INFO(logger, "Loading soundfont from " << file);
synth.loadSoundfont(file); synth.loadSoundfont(file);
} }
@ -108,7 +114,7 @@ int main(int argc, char** argv) {
else { else {
for (const Synth::Program& program : synth.getPrograms()) { for (const Synth::Program& program : synth.getPrograms()) {
if (program.name == parser.get("--instrument")) { if (program.name == parser.get("--instrument")) {
std::cout << "Loading program " << program.name << std::endl; LOG4CXX_INFO(logger, "Loading program " << program.name);
synth.loadProgram(program); synth.loadProgram(program);
break; break;
} }