From 03b28f03c38b35bcc1bbd1ec28a7be17affd3d28 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 5 Jan 2025 22:32:01 +0100 Subject: Automatically access click sound file --- config.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'config.cpp') diff --git a/config.cpp b/config.cpp index 7b5a50a..f8bf89c 100644 --- a/config.cpp +++ b/config.cpp @@ -2,9 +2,6 @@ #include "log.h" -#include -#include - #include #include @@ -14,12 +11,21 @@ using namespace std::string_literals; +namespace fs = std::filesystem; + const char *device = "default"; // playback device std::string config_filename = "click.cfg"; -Config::Config() +fs::path click_data_filename = "media/click.s16le"; + +Config::Config(int argc, char** argv): + m_argv(argc) { + for (int i = 0; i < argc; ++i) { + m_argv[i] = argv[i]; + } + recover(); } @@ -81,7 +87,7 @@ void Config::persist() Reichwein::File::setFile(get_config_filename(), config); } -int Config::get_midi_channel() +int Config::get_midi_channel() const { return m_midi_channel; } @@ -92,7 +98,7 @@ void Config::set_midi_channel(int channel) signal_channel(channel); } -int Config::get_midi_note() +int Config::get_midi_note() const { return m_midi_note; } @@ -103,7 +109,7 @@ void Config::set_midi_note(int note) signal_note(note); } -int Config::get_bpm() +int Config::get_bpm() const { return m_bpm; } @@ -114,7 +120,7 @@ void Config::set_bpm(int bpm) signal_bpm(bpm); } -int Config::get_mode() +int Config::get_mode() const { return m_mode; } @@ -125,7 +131,7 @@ void Config::set_mode(int mode) signal_mode(mode); } -int Config::get_output() +int Config::get_output() const { return m_output; } @@ -136,7 +142,7 @@ void Config::set_output(int output) signal_output(output); } -std::string Config::get_config_filename() +std::string Config::get_config_filename() const { char* envvar = getenv("HOME"); if (envvar == nullptr || !std::filesystem::exists(envvar)) { @@ -145,3 +151,13 @@ std::string Config::get_config_filename() return std::filesystem::path(getenv("HOME")) / ("."s + config_filename); } } + +std::string Config::get_argv(int i) const +{ + return m_argv[i]; +} + +std::filesystem::path Config::get_click_data_filename() const +{ + return fs::path{m_argv[0]}.parent_path() / click_data_filename; +} -- cgit v1.2.3