blob: f6fff18b40cd0fa4db39b62bb24f6aa852a3ccea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/*
* Copyright (c) 2020-2021 Vasile Vilvoiu <vasi@vilvoiu.ro>
*
* specgram is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef _CONFIGURATION_HPP_
#define _CONFIGURATION_HPP_
#include "color-map.hpp"
#include "value-map.hpp"
#include "window-function.hpp"
#include <SFML/Graphics/Color.hpp>
#include <string>
#include <optional>
#include <tuple>
class Configuration {
private:
std::optional<std::string> input_filename_;
std::optional<std::string> output_filename_;
bool dump_to_stdout_;
std::size_t block_size_;
double rate_;
DataType datatype_;
bool has_complex_input_;
double prescale_factor_;
std::size_t fft_width_;
std::size_t fft_stride_;
WindowFunctionType window_function_;
std::size_t average_count_;
bool alias_negative_;
bool no_resampling_;
std::size_t width_;
double min_freq_;
double max_freq_;
ValueMapType scale_type_;
std::string scale_unit_;
double scale_lower_bound_;
double scale_upper_bound_;
ColorMapType color_map_;
sf::Color color_map_custom_color_;
sf::Color background_color_;
sf::Color foreground_color_;
bool has_axes_;
bool has_legend_;
bool is_horizontal_;
bool print_input_;
bool print_fft_;
bool print_output_;
bool live_;
std::size_t count_;
std::string title_;
bool has_live_window_;
std::size_t margin_size_;
std::size_t live_margin_size_;
std::size_t minimum_margin_size_;
std::size_t legend_height_;
std::size_t live_fft_height_;
std::size_t axis_font_size_;
Configuration();
static sf::Color StringToColor(const std::string& str);
using OptionalBound = std::optional<double>;
using ScaleProperties = std::tuple<OptionalBound, OptionalBound, std::string>;
static ScaleProperties StringToScale(const std::string& str);
public:
/* parse command line arguments and return a configuration object */
static std::tuple<Configuration, int, bool> FromArgs(int argc, char **argv);
/* generic getters */
Configuration GetForLive() const;
const auto & GetInputFilename() const { return input_filename_; }
const auto & GetOutputFilename() const { return output_filename_; }
const auto MustDumpToStdout() const { return dump_to_stdout_; }
/* input getters */
auto GetBlockSize() const { return block_size_; }
auto GetRate() const { return rate_; }
auto GetDataType() const { return datatype_; }
auto HasComplexInput() const { return has_complex_input_; }
auto GetPrescaleFactor() const { return prescale_factor_; }
/* FFT getters */
auto GetFFTWidth() const { return fft_width_; }
auto GetFFTStride() const { return fft_stride_; }
auto GetWindowFunction() const { return window_function_; }
auto IsAliasingNegativeFrequencies() const { return alias_negative_; }
auto GetAverageCount() const { return average_count_; }
/* display getters */
auto CanResample() const { return !no_resampling_; }
auto GetWidth() const { return width_; }
auto GetMinFreq() const { return min_freq_; }
auto GetMaxFreq() const { return max_freq_; }
auto GetScaleType() const { return scale_type_; }
auto GetScaleUnit() const { return scale_unit_; }
auto GetScaleLowerBound() const { return scale_lower_bound_; }
auto GetScaleUpperBound() const { return scale_upper_bound_; }
auto GetColorMap() const { return color_map_; }
auto GetColorMapCustomColor() const { return color_map_custom_color_; }
auto GetBackgroundColor() const { return background_color_; }
auto GetForegroundColor() const { return foreground_color_; }
auto HasAxes() const { return has_axes_ || has_legend_; }
auto HasLegend() const { return has_legend_; }
auto IsHorizontal() const { return is_horizontal_; }
auto MustPrintInput() const { return print_input_; }
auto MustPrintFFT() const { return print_fft_; }
auto MustPrintOutput() const { return print_output_; }
/* live options */
auto IsLive() const { return live_; }
auto GetCount() const { return count_; }
auto GetTitle() const { return title_; }
/* internal options */
auto HasLiveWindow() const { return has_live_window_; }
auto GetMarginSize() const { return margin_size_; }
auto GetLiveMarginSize() const { return live_margin_size_; }
auto GetMinimumMarginSize() const { return minimum_margin_size_; }
auto GetLegendHeight() const { return legend_height_; }
auto GetLiveFFTHeight() const { return live_fft_height_; }
auto GetAxisFontSize() const { return axis_font_size_; }
sf::Color GetLiveGuidelinesColor() const;
};
#endif
|