iOS 0.6.0: milestone 5 (recording, MIDI, input bindings, themes, bundles, backups)

- Master recording (MasterSink ring + writer thread) and the sample recorder
- CoreMIDI in/out: sound module, clock send/follow, virtual "Sizzle" ports;
  platform-free parser/module/clock in core (midi_test)
- Hardware keyboard and gamepads via GameController; rebindable keyboard,
  gamepad and MIDI CC actions; per-parameter MIDI learn
- Colour themes (.szt), project bundles (.szgz), backup & restore;
  ZIP in core with zlib (zip_test against jar and unzip)
- Persistent app settings; audio pauses in the background unless sound module

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-11-16 14:26:01 +01:00
co-authored by Claude Opus 5.5
parent 435305e42a
commit 64e21e0bcc
54 changed files with 3303 additions and 97 deletions
+73
View File
@@ -0,0 +1,73 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
// sizzle/Midi.hpp against the behaviour the Android unit tests pin down
// (MidiByteParserTest, MidiSoundModuleTest) and MidiClock's tempo follow.
#include "sizzle/Midi.hpp"
#include <cstdio>
#include <string>
#include <vector>
using namespace sizzle::midi;
static int failures = 0;
#define CHECK(c) do { if (!(c)) { std::printf("FAIL %s:%d %s\n", __FILE__, __LINE__, #c); ++failures; } } while (0)
struct Rec : NoteSink {
std::vector<std::string> log;
void busNoteOn(int ch, int n, int v) override { log.push_back("on " + std::to_string(ch) + " " + std::to_string(n) + " " + std::to_string(v)); }
void busNoteOff(int ch, int n) override { log.push_back("off " + std::to_string(ch) + " " + std::to_string(n)); }
};
int main() {
// ---- parser
std::vector<std::vector<int>> msgs;
std::vector<int> rt;
MidiByteParser p([&](int s, int a, int b) { msgs.push_back({s, a, b}); }, [&](int s) { rt.push_back(s); });
const uint8_t a[] = {0x90, 60, 100, 62, 90}; // running status
p.feed(a, sizeof a);
CHECK(msgs.size() == 2 && msgs[1] == (std::vector<int>{0x90, 62, 90}));
const uint8_t b1[] = {0x80, 60}, b2[] = {0xF8, 0}; // split + realtime inside
p.feed(b1, 2); p.feed(b2, 2);
CHECK(msgs.size() == 3 && msgs[2] == (std::vector<int>{0x80, 60, 0}) && rt == std::vector<int>{0xF8});
const uint8_t c[] = {0xC3, 5, 0xF0, 1, 2, 3, 0xF7, 7}; // program change, SysEx skipped, stray byte
p.feed(c, sizeof c);
CHECK(msgs.size() == 4 && msgs[3] == (std::vector<int>{0xC3, 5, 0}));
const uint8_t d[] = {0xF2, 1, 2, 64, 0xB0, 123, 0}; // system common cancels running status
msgs.clear(); p.feed(d, sizeof d);
CHECK(msgs.size() == 1 && msgs[0] == (std::vector<int>{0xB0, 123, 0}));
// ---- sound module
Rec r;
MidiSoundModule m(r);
std::vector<std::string> mirror;
m.listener = [&](bool on, int ch, int n, int) { mirror.push_back((on ? "+" : "-") + std::to_string(ch) + ":" + std::to_string(n)); };
m.sourceConnected(1); m.sourceConnected(2);
CHECK(m.onChannelMessage(1, 0x90, 60, 100));
CHECK(m.onChannelMessage(2, 0x91, 64, 80));
CHECK(m.onChannelMessage(1, 0x90, 60, 0)); // velocity 0 = off
CHECK(m.heldNotes(1).empty() && m.heldNotes(2).size() == 1);
CHECK(!m.onChannelMessage(1, 0xB0, 7, 100)); // other CCs are the caller's
m.onChannelMessage(1, 0x92, 70, 90);
CHECK(m.onChannelMessage(2, 0xB2, 123, 0)); // channel 3 off from any source
CHECK(m.heldNotes(1).empty());
r.log.clear();
m.sourceDisconnected(2); // releases its held note
CHECK(r.log == std::vector<std::string>{"off 2 64"} && m.sourceCount() == 1);
CHECK(mirror.front() == "+1:60" && mirror.back() == "-2:64");
// ---- clock follow: 24 pulses at 125 BPM = 20 ms each
ClockFollower f;
float bpm = 0; int starts = 0, stops = 0;
f.onTempo = [&](float b) { bpm = b; };
f.onTransport = [&](bool s) { s ? ++starts : ++stops; };
f.realtime(0xFA, 0);
for (int i = 0; i <= 24; ++i) f.realtime(0xF8, 1'000'000'000LL + i * 20'000'000LL);
f.realtime(0xFC, 0);
CHECK(starts == 1 && stops == 1 && bpm > 124.99f && bpm < 125.01f);
std::printf(failures ? "midi_test: %d failure(s)\n" : "midi_test: ok\n", failures);
return failures ? 1 : 0;
}
+54
View File
@@ -0,0 +1,54 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
// io/Zip: round trips, damage, unsafe names; argv[1]: an archive java.util.zip wrote
// (with data descriptors, as Android's ZipOutputStream does), holding a.txt = "hello\n"
// and dir/b.bin; argv[2]: where to write an archive for `unzip -t`.
#include "io/Zip.hpp"
#include <cstdio>
#include <fstream>
#include <iterator>
using namespace sizzle::io;
static int failures = 0;
#define CHECK(c) do { if (!(c)) { std::printf("FAIL %s:%d %s\n", __FILE__, __LINE__, #c); ++failures; } } while (0)
int main(int argc, char **argv) {
std::vector<zip::Entry> in = {{"project.szg", std::vector<uint8_t>(5000, 'x')}, {"empty", {}},
{"samples/0.wav", {}}};
for (int i = 0; i < 3000; ++i) in[2].data.push_back((uint8_t)(i * 7919 >> 3));
auto bytes = zip::write(in);
std::vector<zip::Entry> out;
CHECK(zip::read(bytes.data(), bytes.size(), out));
CHECK(out.size() == 3 && out[0].name == "project.szg" && out[0].data == in[0].data && out[1].data.empty() && out[2].data == in[2].data);
CHECK(bytes.size() < 5000); // deflated
auto bad = bytes;
bad[50] ^= 0xFF; // inside the first entry's data
CHECK(!zip::read(bad.data(), bad.size(), out) && out.empty());
CHECK(!zip::read(bytes.data(), bytes.size() - 10, out));
CHECK(!zip::read(bytes.data(), bytes.size(), out, 1000)); // over the size budget
CHECK(!zip::read(bytes.data(), bytes.size(), out, 1 << 30, 2));
CHECK(zip::safeName("songs/a b.szg") && zip::safeName("x"));
CHECK(!zip::safeName("../x") && !zip::safeName("a/../../x") && !zip::safeName("/etc/x") && !zip::safeName("a\\b") && !zip::safeName(""));
if (argc > 1) {
std::ifstream f(argv[1], std::ios::binary);
std::vector<uint8_t> j((std::istreambuf_iterator<char>(f)), {});
CHECK(zip::read(j.data(), j.size(), out));
bool a = false, b = false;
for (auto &e : out) {
if (e.name == "a.txt") a = std::string(e.data.begin(), e.data.end()) == "hello\n";
if (e.name == "dir/b.bin") b = e.data.size() == 4096;
}
CHECK(a && b);
}
if (argc > 2) { std::ofstream o(argv[2], std::ios::binary); o.write((const char *)bytes.data(), (std::streamsize)bytes.size()); }
std::printf(failures ? "zip_test: %d failure(s)\n" : "zip_test: ok\n", failures);
return failures ? 1 : 0;
}