7 constexpr const char* stub_text =
"#pragma once\n";
9 std::vector<unsigned> include_lines(
const std::string& text,
const std::string& quoted)
11 std::vector<unsigned> includes;
12 std::istringstream lines(text);
15 while (std::getline(lines, line)) {
17 const auto first =
line.find_first_not_of(
" \t");
18 if (first == std::string::npos || line[first] !=
'#') {
21 if (
line.find(
"include", first) != std::string::npos &&
line.find(quoted) != std::string::npos) {
22 includes.push_back(number);
30std::optional<std::string>
read_text(
const std::filesystem::path& path)
32 std::ifstream stream(path, std::ios::binary);
36 std::ostringstream content;
37 content << stream.rdbuf();
43 unsigned last_marker = 0;
45 last_marker = std::max(last_marker,
record.line);
50bool insert_include(
const std::filesystem::path& header,
unsigned last_marker,
51 std::string_view suffix,
bool& inserted, std::string& error)
54 const std::string file =
sidecar_path(header, suffix).filename().string();
57 error =
"cannot read " + header.string();
60 if (!include_lines(*text, file +
"\"").empty()) {
64 const std::string newline = text->find(
"\r\n") != std::string::npos ?
"\r\n" :
"\n";
65 const std::string line =
"#include \"" + file +
"\"" + newline;
67 std::size_t offset = 0;
68 for (
unsigned i = 0; i < last_marker && offset != std::string::npos; ++i) {
69 const auto next = text->find(
'\n', offset);
70 offset = next == std::string::npos ? std::string::npos : next + 1;
72 if (offset == std::string::npos) {
73 *text += newline + line;
75 text->insert(offset, line);
85std::filesystem::path
sidecar_path(
const std::filesystem::path& header)
90std::filesystem::path
sidecar_path(
const std::filesystem::path& header, std::string_view suffix)
92 return header.parent_path() / (header.stem().
string() + std::string(suffix));
97 std::vector<const RecordRequest*> records;
98 records.reserve(requests.
records.size());
100 records.push_back(&
record);
105 out +=
"#pragma once\n\n";
106 out +=
"#include \"MayaFlux/Transitive/Reflect/Describe.hpp\"\n\n";
107 out +=
"#ifndef MAYAFLUX_REFLECT_SCAN\n\n";
108 out +=
"namespace MayaFlux::Reflect::Generated {\n\n";
110 out +=
"template <>\n";
111 out +=
"struct Description<::" +
record->name +
"> {\n";
112 out +=
" static constexpr std::string_view name = \"" +
record->name +
"\";\n\n";
113 out +=
" static constexpr auto members()\n {\n return std::tuple {\n";
114 for (
const std::string& member :
record->members) {
115 out +=
" Member<&::";
123 out +=
" };\n }\n};\n\n";
125 out +=
"}\n\n#endif\n";
129bool ensure_stub(
const std::filesystem::path& path, std::string& error)
131 if (std::filesystem::exists(path)) {
137bool write_if_changed(
const std::filesystem::path& path,
const std::string& content, std::string& error)
139 if (
read_text(path) == std::optional<std::string>(content)) {
142 const std::filesystem::path staged = path.string() +
".tmp";
144 std::ofstream stream(staged, std::ios::binary | std::ios::trunc);
147 error =
"cannot write " + staged.string();
151 std::error_code code;
152 std::filesystem::rename(staged, path, code);
154 std::filesystem::remove(staged, code);
155 error =
"cannot replace " + path.string();
163 unsigned last_marker = 0;
165 last_marker = std::max(last_marker,
record.line);
171 const std::filesystem::path& header,
unsigned last_marker, std::string_view suffix)
173 const std::string file =
sidecar_path(header, suffix).filename().string();
174 const std::string quoted = file +
"\"";
178 return header.string() +
": cannot read the header to check its sidecar include";
181 const std::vector<unsigned> includes = include_lines(*text, quoted);
183 const std::string where = header.string() +
": ";
184 if (includes.empty()) {
185 return where +
"add #include \"" + file +
"\" after line " + std::to_string(last_marker);
187 if (includes.size() > 1) {
188 return where +
"#include \"" + file +
"\" appears more than once";
190 if (includes.front() <= last_marker) {
191 return where +
"#include \"" + file +
"\" at line " + std::to_string(includes.front())
192 +
" must come after line " + std::to_string(last_marker)
193 +
", the end of the namespace holding the last MF_DESCRIBE";
Vruta::SoundRoutine line(float start_value, float end_value, float duration_seconds, uint32_t step_duration, bool restartable)
Creates a continuous interpolation generator between two values over time.
std::pair< std::shared_ptr< Kriya::BufferPipeline >, std::shared_ptr< Buffers::AudioBuffer > > record(const std::shared_ptr< Kakshya::DynamicSoundStream > &stream, uint32_t input_channel, double seconds, std::optional< uint32_t > monitor, uint32_t channel)
Record a live input channel into a stream for a number of seconds.