iOS 0.3.1: engine, model and file formats in C++, verified against Kotlin; longer settings
Engine (sequencer, mixer, FX chains, MIDI effects) renders four whole songs like AudioEngine.kt (two bit-exact, two within 9e-6). ProjectIo / SngFormat / PresetIo round-trip the Kotlin-written files; Float.toString is JDK 17's, checked on all 2^32 floats. Params now holds 255-character values (sample ids were cut). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
b1dc5ed8db
commit
7bc54e6466
@@ -0,0 +1,69 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "io/PresetIo.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "io/KotlinText.hpp"
|
||||
#include "sizzle/Specs.hpp"
|
||||
|
||||
namespace sizzle::io {
|
||||
|
||||
using namespace model;
|
||||
|
||||
std::string PresetIo::exportText(const ToolboxSlot &slot) {
|
||||
if (slot.isEmpty()) return std::string(HEADER) + "\nTYPE=EMPTY";
|
||||
const DeviceSpec *spec = findDevice(slot.type.c_str());
|
||||
std::string o;
|
||||
auto line = [&](const std::string &s) { o += s; o += '\n'; };
|
||||
line(HEADER);
|
||||
line("TYPE=" + slot.type);
|
||||
line("NAME=" + slot.name);
|
||||
// Params in the type's declared order, then any extra keys the slot holds.
|
||||
const int n = spec ? spec->paramCount : 0;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
const ParamSpec &p = spec->params[i];
|
||||
line(std::string(p.key) + "=" + slot.s(p.key, kotlinFloatToString(p.def).c_str()));
|
||||
}
|
||||
for (int i = 0; i < slot.values.size(); ++i) {
|
||||
const char *key = slot.values.keyAt(i);
|
||||
bool declared = false;
|
||||
for (int k = 0; k < n && !declared; ++k) declared = std::strcmp(spec->params[k].key, key) == 0;
|
||||
if (!declared) line(std::string(key) + "=" + slot.values.valueAt(i));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
bool PresetIo::importText(ToolboxSlot &slot, const std::string &text) {
|
||||
std::vector<std::pair<std::string, std::string>> map; // a LinkedHashMap
|
||||
std::unordered_map<std::string, size_t> index;
|
||||
std::string type;
|
||||
bool hasType = false;
|
||||
for (const std::string &raw : kt::lines(text)) {
|
||||
const std::string line = kt::trim(raw);
|
||||
if (line.empty() || line == HEADER) continue;
|
||||
const size_t eq = line.find('=');
|
||||
if (eq == std::string::npos) continue;
|
||||
std::string key = line.substr(0, eq), value = line.substr(eq + 1);
|
||||
if (key == "TYPE") {
|
||||
hasType = value.find('\0') == std::string::npos && findDevice(value.c_str()) != nullptr;
|
||||
type = hasType ? value : std::string();
|
||||
} else if (key == "NAME") {
|
||||
slot.name = value;
|
||||
} else {
|
||||
auto it = index.find(key);
|
||||
if (it != index.end()) map[it->second].second = std::move(value);
|
||||
else { index.emplace(key, map.size()); map.emplace_back(std::move(key), std::move(value)); }
|
||||
}
|
||||
}
|
||||
if (!hasType) return false;
|
||||
slot.fill(type); // reset to defaults for the type (and its display name) ...
|
||||
if (kt::trim(slot.name).empty()) slot.name = findDevice(type.c_str())->displayName;
|
||||
for (const auto &kv : map) slot.set(kv.first.c_str(), kv.second.c_str()); // ... then the saved values
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sizzle::io
|
||||
Reference in New Issue
Block a user