Files
sizzletracker-android/core/src/io/PresetIo.cpp
T
ReactorcoremeltdownandClaude Opus 5.5 2bc5cb1cbb 0.37.0 (71): one engine, one version for Android and iOS
- Three source trees: core/ (shared C++ engine, moved from ios/core),
  app/ (Android UI), ios/app/ (iOS UI)
- Android plays through core/ via JNI (EngineHost, jni_engine.cpp): the Oboe
  callback renders natively; the Kotlin model is mirrored as project text and
  applied as a diff, so playback continues through edits
- The Kotlin engine moves to the unit tests as ReferenceEngine (golden reference)
- Shared MasterRecorder in core/src/host, used by both apps; host_test
- versions.properties: one versionName/versionCode for both platforms,
  continuing Android's numbering (iOS 0.6.0/11 -> 0.37.0/71)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 14:49:46 +01:00

70 lines
2.7 KiB
C++

// 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