diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e1e853..72efc51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -296,6 +296,10 @@ loopercat_core_test(sysex_tests) loopercat_core_test(storage_register_tests) loopercat_core_test(catalog_tests) loopercat_core_test(commands_tests) +# Push on the two-track model: into a memory with no take on any track, nowhere else. +loopercat_core_test(rc500_push_tests) +# Play Count-In on the two-track model: the RHYTHM triple with the RC-5's numbers (2026-11-07). +loopercat_core_test(rc500_count_in_tests) # A card as a folder on disk (#77): the factory pair, export by restore, import by the scan. loopercat_core_test(card_folder_tests) loopercat_core_test(slot_story_tests) diff --git a/app/CardPermissions.h b/app/CardPermissions.h index 9bca210..fe1696a 100644 --- a/app/CardPermissions.h +++ b/app/CardPermissions.h @@ -42,9 +42,10 @@ struct CardPermissions { bool downmix = false; // The one short sentence a closed control says on a card whose model has // some operations open and others not ("On the RC-500, LooperCat does - // rename, set one-shot, pull, clear and restore only"), or, on a model this app only - // reads, what it writes to. Empty when every operation is open, and when - // no card the table knows is in front of the app. + // rename, set one-shot, set count-in, push, pull, clear and restore + // only"), or, on a model this app only reads, what it writes to. Empty + // when every operation is open, and when no card the table knows is in + // front of the app. std::string closed; bool anyWrite() const diff --git a/app/MainComponent.cpp b/app/MainComponent.cpp index 92db4d8..0fa4bcb 100644 --- a/app/MainComponent.cpp +++ b/app/MainComponent.cpp @@ -316,8 +316,10 @@ MainComponent::MainComponent(std::string explicitVolume, juce::File dataOverride } })); }; table.onAudioDropped = [this](int slot, juce::String path) { + // Occupied on any track: the one-track model replaces, the two-track + // model is refused by the core in its own words (catalog::uploadOffered). if (const SlotRow* row = pedalBusy ? nullptr : slotRowFor(slot)) - pushWav(slot, path, row->info.hasAudio); + pushWav(slot, path, catalog::holdsAudio(row->info)); }; table.onSwapRequested = [this](int from, int to) { if (pedalBusy || slotRowFor(from) == nullptr || slotRowFor(to) == nullptr) @@ -2096,10 +2098,18 @@ void MainComponent::showSlotMenu(int slot, juce::Point screenPosition) // panel now (and the two lamp columns still flip on click), so this menu // stopped being a second copy of them. juce::PopupMenu menu; + // A replace is the one-track model's; a two-track memory with a take on + // any track, or a file in either folder, is not offered an upload + // (offersUpload) - and since push is open on the model, the greyed item + // says why itself: the "closed" sentence is for closed operations. + const bool offered = offersUpload(row); menu.addItem(3, - occupied ? juce::String::fromUTF8("Replace audio\xe2\x80\xa6") - : juce::String::fromUTF8("Push audio here\xe2\x80\xa6"), - can.push); + !occupied && row.wavFile.empty() + ? juce::String::fromUTF8("Push audio here\xe2\x80\xa6") + : offered ? juce::String::fromUTF8("Replace audio\xe2\x80\xa6") + : juce::String::fromUTF8("Replace audio\xe2\x80\xa6 (not offered on a used ") + + utf8(snapshot.family) + " memory yet)", + can.push && offered); menu.addItem(4, juce::String::fromUTF8("Pull to folder\xe2\x80\xa6"), can.pull && occupied); juce::PopupMenu downmix; downmix.addItem(6, juce::String::fromUTF8("Both outputs\xe2\x80\xa6")); diff --git a/app/PedalWorker.h b/app/PedalWorker.h index ce52b77..f1935b0 100644 --- a/app/PedalWorker.h +++ b/app/PedalWorker.h @@ -61,6 +61,18 @@ struct SlotRow bool operator==(const SlotRow&) const = default; }; +// Whether the row's memory is offered an upload: the config's say +// (catalog::uploadOffered) and the folders' as the scan listed them. The core +// refuses a two-track memory with a take on either track, configured or +// merely in its folder (commands::push); the menu, the drag's highlight, the +// drop and the empty-slot hint all ask this, so the player is not offered a +// push the core refuses. On the one-track model every row is offered one: +// an occupied slot takes a replace. +inline bool offersUpload(const SlotRow& row) +{ + return catalog::uploadOffered(row.info) && (row.info.tracks.size() <= 1 || row.wavFile.empty()); +} + struct PedalSnapshot { std::string volume; // mount path; empty = no pedal found diff --git a/app/SlotTable.cpp b/app/SlotTable.cpp index e281e6f..3c40e4a 100644 --- a/app/SlotTable.cpp +++ b/app/SlotTable.cpp @@ -8,6 +8,7 @@ #include +#include #include #include @@ -379,10 +380,11 @@ void SlotTable::cellClicked(int row, int columnId, const juce::MouseEvent& e) onCountInToggled(slotOfRow(row)); return; } - // The empty-slot hint is a button: click opens the WAV chooser. + // The empty-slot hint is a button: click opens the WAV chooser. Empty on + // every track, the second alone counts (catalog::holdsAudio). if (columnId == kWavFile && onEmptyWavCellClicked && slotOfRow(row) > 0 && allowed().push) { const SlotRow& r = rows_[static_cast(row)]; - if (!r.info.hasAudio && r.wavFile.empty()) + if (!catalog::holdsAudio(r.info) && r.wavFile.empty()) onEmptyWavCellClicked(r.info.slot); } } @@ -453,11 +455,22 @@ bool SlotTable::isInterestedInFileDrag(const juce::StringArray& files) return false; } +// A row takes a file when its memory is offered an upload (offersUpload, +// PedalWorker.h): every row of a one-track model, a memory of a two-track one +// with nothing on either track — the highlight under the drag, the drop and +// the empty-slot hint agree on it. +bool SlotTable::takesAudio(int row) const +{ + return row >= 0 && static_cast(row) < rows_.size() + && offersUpload(rows_[static_cast(row)]); +} + void SlotTable::fileDragMove(const juce::StringArray&, int x, int y) { const int row = rowAt(x, y); - if (row != dragRow_) { - dragRow_ = row; + const int target = takesAudio(row) ? row : -1; + if (target != dragRow_) { + dragRow_ = target; table_.repaint(); } } @@ -473,7 +486,7 @@ void SlotTable::filesDropped(const juce::StringArray& files, int x, int y) const int row = rowAt(x, y); dragRow_ = -1; table_.repaint(); - if (slotOfRow(row) <= 0 || !onAudioDropped || !allowed().push) + if (slotOfRow(row) <= 0 || !onAudioDropped || !allowed().push || !takesAudio(row)) return; for (const auto& file : files) if (isImportableAudio(file)) { @@ -587,8 +600,9 @@ void SlotTable::paintCell(juce::Graphics& g, int row, int columnId, int width, i case kLufs: break; // drawn from the loudness cells below case kWavFile: // The empty-slot hint invites a push; a card this app only reads - // gets no invitation. - text = r.wavFile.empty() && !loaded + // gets no invitation, and neither does a memory with a take on any + // track - the second alone counts (catalog::holdsAudio). + text = r.wavFile.empty() && !catalog::holdsAudio(r.info) ? (allowed().push ? juce::String::fromUTF8("\xe2\x80\x94 drop audio here, or click to choose") : juce::String()) diff --git a/app/SlotTable.h b/app/SlotTable.h index 8e303ae..87aa33d 100644 --- a/app/SlotTable.h +++ b/app/SlotTable.h @@ -144,6 +144,7 @@ class SlotTable final : public juce::Component, void updateSwapTarget(); CardPermissions allowed() const { return permissions ? permissions() : CardPermissions {}; } + bool takesAudio(int row) const; // the row's memory is offered an upload (catalog::uploadOffered) int rowAt(int x, int y); int rowOfSlot(int slot) const; int slotOfRow(int rowIndex) const; // 0 when out of range diff --git a/core/include/loopercat/Catalog.hpp b/core/include/loopercat/Catalog.hpp index 9eddd17..0e0dc9e 100644 --- a/core/include/loopercat/Catalog.hpp +++ b/core/include/loopercat/Catalog.hpp @@ -95,6 +95,18 @@ inline bool holdsAudio(const SlotInfo& info) [](const TrackInfo& track) { return track.hasAudio; }); } +// Whether the config offers an upload into a memory, as push decides it +// (Commands.hpp): on a one-track model always — an occupied slot takes a +// replace — and on a model with more tracks only while no track holds a +// take, because what the pedal makes of a second take of another length +// beside a pushed first one has not been asked of it. The config's half: +// push looks into the track folders too, and so does the app before it +// offers one (offersUpload, PedalWorker.h), with the folders the scan read. +inline bool uploadOffered(const SlotInfo& info) +{ + return info.tracks.size() <= 1 || !holdsAudio(info); +} + // One track's facts, read from its own section (rc0::sectionField). A memory // that lacks a section its model promises is refused by name, not read as // empty. diff --git a/core/include/loopercat/Commands.hpp b/core/include/loopercat/Commands.hpp index 142b238..4f94182 100644 --- a/core/include/loopercat/Commands.hpp +++ b/core/include/loopercat/Commands.hpp @@ -696,13 +696,38 @@ inline PushResult push(const fs::path& volume, const fs::path& wavPath, int slot if (options.landedName) assertLandedName(*options.landedName); + // The gate, on every path: a drop-only push lands a file on the card as + // a configured one does, so the same profile refuses it, before a byte + // moves — and the memory it lands in is read for the rule below, config + // written or not. + const std::string memoryText = readMemoryFor(volume, profile::Operation::push); + const profile::DeviceProfile& family = rc0::profileOf(memoryText); + std::string body = rc0::slotBody(memoryText, slot); + + // A memory of a model with more tracks than one takes an upload only + // while no track holds a take — configured or merely in its folder — and + // force does not change that. The take lands on track 1 as the memory's + // first recording; what the pedal makes of a second take of another + // length beside it has not been asked of it (hardware reading 2026-09-23: + // a track 2 recorded after track 1 came out exactly half its length; a + // non-multiple length is unknown), so until it has, a used memory is not + // offered, and the refusal names the track that is in the way (decided + // 2026-10-29). The one-track model keeps its replace below. + if (family.trackCount > 1) + for (int track = 1; track <= family.trackCount; ++track) { + const bool configured = + rc0::sectionField(body, rc0::trackSectionName(track), "WavStat") == 1; + if (configured || !volume::listTrackWavs(volume, family, slot, track).empty()) + throw Error("push refused: memory " + std::to_string(slot) + " holds a take on track " + + std::to_string(track) + " - upload into a used \"" + + std::string(family.familyName) + "\" memory is not offered yet"); + } + std::optional slotParams; std::string newDocument; bool noteLengthReplaced = false; if (options.writeConfig) { slotParams = params::computeSlotParams(info.frames); - const std::string memoryText = readMemoryFor(volume, profile::Operation::push); - std::string body = rc0::slotBody(memoryText, slot); // The new take defines a new length, so the field becomes a bar count. // If it was a note value, that mode is gone — reported, never silent. // Only a memory that HOLDS a loop can have a length to replace: a @@ -717,6 +742,16 @@ inline PushResult push(const fs::path& volume, const fs::path& wavPath, int slot slotParams->measureField()); body = rc0::setSectionField(body, rc0::kSectionTrack1, "RecTmp", slotParams->tempoTenths); body = rc0::setSectionField(body, rc0::kSectionMaster, "Tempo", slotParams->tempoTenths); + // LpLen is the length of the memory's first recording, on the + // two-track model too (hardware reading 2026-09-23: a memory recorded + // track 1 first at 8 bars then track 2 at 4 carries LpLen 8; one + // recorded on track 2 alone carries that track's length). Into an + // empty memory the pushed take is that recording. The two-track + // model's MASTER also carries CurrentTrack and LpMod, and neither is + // written: single-track recordings off the pedal (2026-09-22) carry + // CurrentTrack 0, the factory value an empty memory already holds, + // and LpMod 0 on one such memory and 1 on another, so it is not the + // recording's doing — what it is remains a checkpoint question. body = rc0::setSectionField(body, rc0::kSectionMaster, "LpLen", slotParams->measures); if (options.oneShot) body = rc0::setSectionField(body, rc0::kSectionTrack1, "One", 1); @@ -725,7 +760,10 @@ inline PushResult push(const fs::path& volume, const fs::path& wavPath, int slot newDocument = rc0::replaceSlotBody(memoryText, slot, body); } - const std::vector existing = volume::listSlotWavs(volume, slot); + // The take's track, on every model: the first (kFirstTrack); the + // one-track model's folder is that track's. + const std::vector existing = + volume::listTrackWavs(volume, family, slot, kFirstTrack); if (!existing.empty() && !options.force) { std::string files; for (const auto& f : existing) @@ -744,7 +782,7 @@ inline PushResult push(const fs::path& volume, const fs::path& wavPath, int slot requireMemoryJournal(options.write); if (options.write.journal.slotsChanging) options.write.journal.slotsChanging({ slot }); - const fs::path dir = volume::wavDir(volume, slot); + const fs::path dir = volume::trackDir(volume, family, slot, kFirstTrack); std::error_code ec; fs::create_directories(dir, ec); if (ec) diff --git a/core/include/loopercat/DeviceProfile.hpp b/core/include/loopercat/DeviceProfile.hpp index 3560140..125af56 100644 --- a/core/include/loopercat/DeviceProfile.hpp +++ b/core/include/loopercat/DeviceProfile.hpp @@ -16,12 +16,13 @@ // // The operation set is the guard's other half. Knowing a model is not the // same as being allowed to touch its card: the two-track model is known here -// and opened one operation at a time, for the ones that carry every track — -// pull, rename, clear and restore — and One Shot, which names its track. The -// others work on the first track alone -// (push, trim, downmix, normalize, tempo) or move only its audio (swap), and -// would corrupt such a card silently; on this table they are not untested on -// it, they are unreachable. +// and opened one operation at a time — for the ones that carry every track +// (pull, rename, clear and restore), for One Shot, which names its track, +// for push into a memory with no take on either track, and for Play +// Count-In, whose section the card lays out as the RC-5 does. The others +// work on the first track alone (trim, downmix, normalize, tempo) or move +// only its audio (swap), and would corrupt such a card silently; on this +// table they are not untested on it, they are unreachable. #pragma once @@ -368,12 +369,23 @@ inline constexpr std::string_view kRc500FactorySections = R"( // (model id 00 00 00 77 answers, 76 and 78 are silent; Identity Reply family // 0x0377), ioreg (product id 0x0252). Open: reading, the operations that // carry every track of a memory — pull, rename, clear, restore (decided for -// 0.9.6, 2026-10-18) — and One Shot, which the pedal keeps per track and the -// app sets per track (decided 2026-10-29). Everything else is refused. +// 0.9.6, 2026-10-18) — One Shot, which the pedal keeps per track and the +// app sets per track (decided 2026-10-29), push, which this model takes +// into a memory with no take on any track and refuses elsewhere (decided +// 2026-10-29; the rule is push's, Commands.hpp), and Play Count-In, whose +// three fields live in — a section this card lays out as the RC-5 +// does, field for field, with the RC-5's numbers where they were read: a +// memory saved on the pedal with the rhythm on, pattern Blank, beat 4/4 +// reads State 1, Pattern 57, Beat 2 (hardware, 2026-11-07; Rc0.hpp, +// Beat.hpp). PlayCount's 1 = 1MEAS is the RC-5's reading (2026-08-10) +// carried over on that layout, and the first count heard from this pedal +// is what confirms it. The pattern and kit lists themselves are charted +// for the RC-5 only, so the rhythm card stays closed. Everything else is +// refused. inline constexpr DeviceProfile kRc500 { "RC-500", { 0x00, 0x00, 0x00, 0x77 }, 0x0252, 2, 99, kRc500FactorySections, operations({ Operation::read, Operation::pull, Operation::rename, Operation::setOneShot, - Operation::clear, Operation::restore }) + Operation::setCountIn, Operation::push, Operation::clear, Operation::restore }) }; inline constexpr std::array kAll { &kRc5, &kRc500 }; diff --git a/tests/card_permissions_tests.cpp b/tests/card_permissions_tests.cpp index 3d65008..ab6b874 100644 --- a/tests/card_permissions_tests.cpp +++ b/tests/card_permissions_tests.cpp @@ -31,11 +31,12 @@ int main() CHECK_EQ(rc5.footer(true), std::string("Disconnect to hear the changes.")); const CardPermissions rc500 = CardPermissions::of("RC-500"); - CHECK(rc500.rename && rc500.oneShot && rc500.pull && rc500.clear && rc500.restore); - CHECK(!rc500.tempo && !rc500.countIn && !rc500.push && !rc500.swap + CHECK(rc500.rename && rc500.oneShot && rc500.countIn && rc500.push && rc500.pull + && rc500.clear && rc500.restore); + CHECK(!rc500.tempo && !rc500.swap && !rc500.normalize && !rc500.trim && !rc500.rhythm && !rc500.playStop && !rc500.downmix); CHECK(rc500.anyWrite()); // a rename is a write; the sweep and the face follow it - const std::string sentence = "On the RC-500, LooperCat does rename, set one-shot, pull, clear and restore only"; + const std::string sentence = "On the RC-500, LooperCat does rename, set one-shot, set count-in, push, pull, clear and restore only"; CHECK_EQ(rc500.closed, sentence); // The inspector can rename: it promises the change, and says what stays closed. CHECK_EQ(rc500.footer(true), "Disconnect to hear the changes. " + sentence + "."); diff --git a/tests/commands_tests.cpp b/tests/commands_tests.cpp index 12d2743..d9f5e51 100644 --- a/tests/commands_tests.cpp +++ b/tests/commands_tests.cpp @@ -29,6 +29,7 @@ #include "support.hpp" #include "archive_support.hpp" #include "two_track_card.hpp" +#include "field_changes.hpp" #include "../app/OperationId.h" @@ -288,99 +289,6 @@ fs::path makePedalFromCard(const fs::path& root) return volume; } -// One line of a memory body is one field — a tab, then value — or -// one section's opener or closer on a line of its own: the shape every RC-5 -// writes (the card fixture; golden.json's factory slot). A field line taken -// apart, or nothing for any other line. -struct FieldLine { - std::string tag; - long long value; -}; - -std::optional parseFieldLine(const std::string& line) -{ - if (line.size() < 2 || line[0] != '\t' || line[1] != '<') - return std::nullopt; - const auto tagEnd = line.find('>', 2); - if (tagEnd == std::string::npos) - return std::nullopt; - const std::string tag = line.substr(2, tagEnd - 2); - const std::string close = ""; - const std::size_t valueBegin = tagEnd + 1; - if (line.size() < valueBegin + close.size() - || line.compare(line.size() - close.size(), close.size(), close) != 0) - return std::nullopt; - const std::string digits = line.substr(valueBegin, line.size() - close.size() - valueBegin); - std::size_t i = (!digits.empty() && digits[0] == '-') ? 1 : 0; - if (i == digits.size()) - return std::nullopt; - for (; i < digits.size(); ++i) - if (digits[i] < '0' || digits[i] > '9') - return std::nullopt; - return FieldLine { tag, std::stoll(digits) }; -} - -// What changed between two bodies of one memory, as "SECTION.Tag before->after" -// in the body's own order — or "shape" when the bodies differ in anything but -// field values: a line added or lost, a tag renamed, a line outside any -// section touched. A field's value is the only unit a mutation may change; -// everything else about the body is the pedal's, byte for byte. -std::string fieldChanges(const std::string& before, const std::string& after) -{ - const auto lines = [](const std::string& text) { - std::vector out; - std::size_t from = 0; - while (true) { - const auto nl = text.find('\n', from); - if (nl == std::string::npos) { - out.push_back(text.substr(from)); - return out; - } - out.push_back(text.substr(from, nl - from)); - from = nl + 1; - } - }; - const std::vector a = lines(before); - const std::vector b = lines(after); - if (a.size() != b.size()) - return "shape"; - std::string section; - std::string out; - for (std::size_t i = 0; i < a.size(); ++i) { - if (a[i] == b[i]) { - // on a line of its own opens section X; closes it. - if (a[i].size() > 2 && a[i].front() == '<' && a[i].back() == '>' - && a[i].find('<', 1) == std::string::npos) { - if (a[i][1] == '/') - section.clear(); - else - section = a[i].substr(1, a[i].size() - 2); - } - continue; - } - const auto fa = parseFieldLine(a[i]); - const auto fb = parseFieldLine(b[i]); - if (!fa || !fb || fa->tag != fb->tag || section.empty()) - return "shape"; - if (!out.empty()) - out += ", "; - out += section + "." + fa->tag + " " + std::to_string(fa->value) + "->" - + std::to_string(fb->value); - } - return out; -} - -// What one mutation of `slot` did to the memory document: that memory's field -// changes, with every byte outside the memory asserted identical (the trailer -// aside — every write stamps it). -std::string slotChangesOnCard(const std::string& before, const std::string& after, int slot) -{ - const std::string afterBody = rc0::slotBody(after, slot); - CHECK(rc0::splitFile(rc0::replaceSlotBody(before, slot, afterBody)).document - == rc0::splitFile(after).document); - return fieldChanges(rc0::slotBody(before, slot), afterBody); -} - } // namespace int main() @@ -2691,13 +2599,13 @@ int main() // setOneShot: TRACK1's , on and off again — and the card's own // document is back, to the byte. commands::setOneShot(volume, { 11 }, 1, true, writeOpts(tmp.path)); - CHECK_EQ(slotChangesOnCard(card, memory(), 11), "TRACK1.One 0->1"); + CHECK_EQ(testkit::slotChangesOnCard(card, memory(), 11), "TRACK1.One 0->1"); const std::string oneShotOn = memory(); commands::setOneShot(volume, { 11 }, 1, false, writeOpts(tmp.path)); // The RC-5 has one track: a second is not one of its tracks. CHECK_THROWS(commands::setOneShot(volume, { 11 }, 2, true, writeOpts(tmp.path)), "set one-shot: track 2, but an \"RC-5\" memory holds one track"); - CHECK_EQ(slotChangesOnCard(oneShotOn, memory(), 11), "TRACK1.One 1->0"); + CHECK_EQ(testkit::slotChangesOnCard(oneShotOn, memory(), 11), "TRACK1.One 1->0"); CHECK(rc0::splitFile(memory()).document == rc0::splitFile(card).document); // setTempo on the loop: 120.0 BPM over 10888139 frames is 246.90 s, @@ -2705,7 +2613,7 @@ int main() // TRACK1. const std::string beforeTempo = memory(); commands::setTempo(volume, 11, 1200, writeOpts(tmp.path)); - CHECK_EQ(slotChangesOnCard(beforeTempo, memory(), 11), + CHECK_EQ(testkit::slotChangesOnCard(beforeTempo, memory(), 11), "TRACK1.Measure 97->130, TRACK1.MeasLen 90->123, TRACK1.RecTmp 870->1200, " "MASTER.Tempo 870->1200"); @@ -2713,7 +2621,7 @@ int main() // bars — there is no loop to derive them from. const std::string beforeEmptyTempo = memory(); commands::setTempo(volume, 42, 905, writeOpts(tmp.path)); - CHECK_EQ(slotChangesOnCard(beforeEmptyTempo, memory(), 42), + CHECK_EQ(testkit::slotChangesOnCard(beforeEmptyTempo, memory(), 42), "TRACK1.RecTmp 1200->905, MASTER.Tempo 1200->905"); // push into the empty memory: a 30 s take, one-shot. Boot indexing @@ -2726,7 +2634,7 @@ int main() commands::writeFileBytes(source, bytesOf(take)); const std::string beforePush = memory(); commands::push(volume, source, 42, { .oneShot = true, .write = writeOpts(tmp.path) }); - CHECK_EQ(slotChangesOnCard(beforePush, memory(), 42), + CHECK_EQ(testkit::slotChangesOnCard(beforePush, memory(), 42), "TRACK1.One 0->1, TRACK1.Measure 1->23, TRACK1.MeasLen 0->16, " "TRACK1.RecTmp 905->1280, TRACK1.WavStat 0->1, TRACK1.WavLen 0->1323000, " "MASTER.Tempo 905->1280, MASTER.LpLen 0->16"); @@ -2741,7 +2649,7 @@ int main() const std::string beforeTrim = memory(); commands::trim(volume, 11, 0, 441000, { .write = writeOpts(tmp.path) }); const std::string afterTrim = memory(); - CHECK_EQ(slotChangesOnCard(beforeTrim, afterTrim, 11), + CHECK_EQ(testkit::slotChangesOnCard(beforeTrim, afterTrim, 11), "TRACK1.Measure 130->12, TRACK1.MeasLen 123->5, TRACK1.WavLen 10888139->441000, " "MASTER.LpLen 128->5"); @@ -2755,11 +2663,11 @@ int main() }; commands::setTempo(volume, 11, 905, writeOpts(tmp.path)); const std::string beforeRestore = memory(); - CHECK_EQ(slotChangesOnCard(afterTrim, beforeRestore, 11), + CHECK_EQ(testkit::slotChangesOnCard(afterTrim, beforeRestore, 11), "TRACK1.Measure 12->11, TRACK1.MeasLen 5->4, TRACK1.RecTmp 1200->905, " "MASTER.Tempo 1200->905"); commands::restore(volume, 11, trimmed, writeOpts(tmp.path)); - CHECK_EQ(slotChangesOnCard(beforeRestore, memory(), 11), + CHECK_EQ(testkit::slotChangesOnCard(beforeRestore, memory(), 11), "TRACK1.Measure 11->12, TRACK1.MeasLen 4->5, TRACK1.RecTmp 905->1200, " "MASTER.Tempo 905->1200"); CHECK(commands::readFileBytes(volume::wavDir(volume, 11) / "011_1.WAV") @@ -2796,11 +2704,11 @@ int main() std::string before = memory(); commands::setOneShot(volume, { 5 }, 1, true, writeOpts(tmp.path)); - CHECK_EQ(slotChangesOnCard(before, memory(), 5), "TRACK1.One 0->1"); + CHECK_EQ(testkit::slotChangesOnCard(before, memory(), 5), "TRACK1.One 0->1"); before = memory(); commands::setTempo(volume, 5, 905, writeOpts(tmp.path)); - CHECK_EQ(slotChangesOnCard(before, memory(), 5), + CHECK_EQ(testkit::slotChangesOnCard(before, memory(), 5), "TRACK1.RecTmp 1200->905, MASTER.Tempo 1200->905"); // push: a 30 s take, 16 bars at 128.0 BPM (see the card block above). @@ -2810,7 +2718,7 @@ int main() before = memory(); commands::push(volume, source, 5, { .write = writeOpts(tmp.path) }); const std::string pushed = memory(); - CHECK_EQ(slotChangesOnCard(before, pushed, 5), + CHECK_EQ(testkit::slotChangesOnCard(before, pushed, 5), "TRACK1.Measure 0->23, TRACK1.MeasLen 0->16, TRACK1.RecTmp 905->1280, " "TRACK1.WavStat 0->1, TRACK1.WavLen 0->1323000, MASTER.Tempo 905->1280, " "MASTER.LpLen 0->16"); @@ -2823,7 +2731,7 @@ int main() // trim to 10 s at the kept 128.0 BPM: 21.3 beats, 5 bars. commands::trim(volume, 5, 0, 441000, { .write = writeOpts(tmp.path) }); - CHECK_EQ(slotChangesOnCard(pushed, memory(), 5), + CHECK_EQ(testkit::slotChangesOnCard(pushed, memory(), 5), "TRACK1.Measure 23->12, TRACK1.MeasLen 16->5, TRACK1.WavLen 1323000->441000, " "MASTER.LpLen 16->5"); @@ -2831,7 +2739,7 @@ int main() // the foreign section's pair would not match the take it brings. before = memory(); commands::restore(volume, 5, pushedState, writeOpts(tmp.path)); - CHECK_EQ(slotChangesOnCard(before, memory(), 5), + CHECK_EQ(testkit::slotChangesOnCard(before, memory(), 5), "TRACK1.Measure 12->23, TRACK1.MeasLen 5->16, TRACK1.WavLen 441000->1323000, " "MASTER.LpLen 5->16"); @@ -2843,8 +2751,11 @@ int main() // --- a two-track card: what is open carries every track --- // // The two-track RC model's card (root "RC-500", two per memory, - // NNN_1 and NNN_2 audio folders) has open what carries a memory whole: - // reading, pull, rename, clear and restore. The rest works on the first + // NNN_1 and NNN_2 audio folders) has open what carries a memory whole — + // reading, pull, rename, clear and restore — and what the two tracks + // share or that knows them: One Shot per track, push into an empty memory + // (rc500_push_tests) and Play Count-In, the RHYTHM triple with the RC-5's + // numbers (rc500_count_in_tests). The rest works on the first // track alone or moves only its audio, and is refused in its own name, // saying what is open, before a byte of the card has moved — the // settings pair included, whose only writer is the controls. @@ -2899,10 +2810,13 @@ int main() commands::writeFileBytes( source, bytesOf(testkit::syntheticWav({ .tag = 3, .bits = 32, .frames = 1323000 }))); const std::string refused = " refused on an \"RC-500\" card - on this model LooperCat" - " does rename, set one-shot, pull, clear and restore only"; + " does rename, set one-shot, set count-in, push, pull, clear and restore only"; CHECK_THROWS(commands::setTempo(volume, 1, 1200, write), "set tempo" + refused); - CHECK_THROWS(commands::setCountIn(volume, { 1 }, true, write), "set count-in" + refused); - CHECK_THROWS(commands::push(volume, source, 42, { .write = write }), "push" + refused); + // Push is open on this model, into a memory with no take on any + // track only (rc500_push_tests): memory 1 holds two, so it is refused + // by push's own rule, before a byte moves. + CHECK_THROWS(commands::push(volume, source, 1, { .write = write }), + "memory 1 holds a take on track 1"); CHECK_THROWS(commands::trim(volume, 1, 0, 22050, { .write = write }), "trim" + refused); CHECK_THROWS(commands::downmixToMono(volume, 1, { .write = write }), "downmix" + refused); CHECK_THROWS(commands::normalize(volume, 1, { .targetLufs = -18.0, .write = write }), @@ -2951,11 +2865,11 @@ int main() const std::string start = commands::readMemory(volume); commands::setOneShot(volume, { 1 }, 2, true, writeOpts(tmp.path, "oneshot-t2")); const std::string second = commands::readMemory(volume); - CHECK_EQ(slotChangesOnCard(start, second, 1), "TRACK2.One 0->1"); + CHECK_EQ(testkit::slotChangesOnCard(start, second, 1), "TRACK2.One 0->1"); commands::setOneShot(volume, { 1, 3 }, 1, true, writeOpts(tmp.path, "oneshot-t1")); const std::string both = commands::readMemory(volume); - CHECK_EQ(fieldChanges(rc0::slotBody(second, 1), rc0::slotBody(both, 1)), "TRACK1.One 0->1"); - CHECK_EQ(fieldChanges(rc0::slotBody(second, 3), rc0::slotBody(both, 3)), "TRACK1.One 0->1"); + CHECK_EQ(testkit::fieldChanges(rc0::slotBody(second, 1), rc0::slotBody(both, 1)), "TRACK1.One 0->1"); + CHECK_EQ(testkit::fieldChanges(rc0::slotBody(second, 3), rc0::slotBody(both, 3)), "TRACK1.One 0->1"); for (int slot = 1; slot <= rc0::kSlotCount; ++slot) if (slot != 1 && slot != 3) CHECK(rc0::slotBody(both, slot) == rc0::slotBody(start, slot)); @@ -2964,7 +2878,7 @@ int main() CHECK(one.oneShot); // the flat field is track 1's CHECK(!catalog::readSlot(both, 3).tracks[1].oneShot); // slot 3's second track: not asked commands::setOneShot(volume, { 1 }, 2, false, writeOpts(tmp.path, "oneshot-t2-off")); - CHECK_EQ(slotChangesOnCard(both, commands::readMemory(volume), 1), "TRACK2.One 1->0"); + CHECK_EQ(testkit::slotChangesOnCard(both, commands::readMemory(volume), 1), "TRACK2.One 1->0"); // A track the model has not, and no track at all: refused by name, // the card as it was. const auto settled = volumeBytes(volume); @@ -3115,7 +3029,7 @@ int main() // recompute and no mode to lose. commands::setTempo(volume, 40, 1000, writeOpts(tmp.path)); const std::string afterNote = commands::readMemory(volume); - CHECK_EQ(slotChangesOnCard(start, afterNote, 40), + CHECK_EQ(testkit::slotChangesOnCard(start, afterNote, 40), std::string("TRACK1.RecTmp 973->1000, MASTER.Tempo 973->1000")); // On a memory whose length IS a bar count, the same edit still @@ -3124,7 +3038,7 @@ int main() rc0::sectionField(rc0::slotBody(afterNote, 8), rc0::kSectionTrack1, "WavLen"); const long long bars8 = commands::barsFromTempo(1000, frames8); commands::setTempo(volume, 8, 1000, writeOpts(tmp.path)); - CHECK_EQ(slotChangesOnCard(afterNote, commands::readMemory(volume), 8), + CHECK_EQ(testkit::slotChangesOnCard(afterNote, commands::readMemory(volume), 8), "TRACK1.Measure 100->" + std::to_string(bars8 + params::kMeasureFieldOffset) + ", TRACK1.MeasLen 93->" + std::to_string(bars8) + ", TRACK1.RecTmp 1250->1000, MASTER.Tempo 1250->1000"); diff --git a/tests/device_profile_tests.cpp b/tests/device_profile_tests.cpp index f69e3c1..012e5e2 100644 --- a/tests/device_profile_tests.cpp +++ b/tests/device_profile_tests.cpp @@ -14,8 +14,10 @@ // - a document's track sections must fit its model: an "RC-5" with a // is refused (the guard's oldest promise), an "RC-500" with a // or with no the same way -// - the RC-5 is open for everything; the two-track model for nothing, and -// each refusal names the model and the operation +// - the RC-5 is open for everything; the two-track model for what carries +// every track or knows them (read, pull, rename, One Shot, count-in, +// push, clear, restore), and each refusal names the model, the +// operation and what is open instead #include "support.hpp" @@ -92,16 +94,21 @@ int main() CHECK(rc500.hasFactoryBody()); CHECK(rc500.allowsWrites()); // Reading, what carries a memory whole, every track of it — pull, - // rename, clear, restore — and One Shot, which names its track. - // Nothing that works on the first track alone. + // rename, clear, restore — One Shot, which names its track, push into + // an empty memory, and Play Count-In, whose RHYTHM section this card + // writes with the RC-5's numbers (hardware, 2026-11-07). Nothing that + // works on the first track alone, and not the rhythm card: its lists + // are charted for the RC-5 only. using profile::Operation; const auto open = [](Operation op) { return op == Operation::read || op == Operation::pull || op == Operation::rename - || op == Operation::setOneShot || op == Operation::clear || op == Operation::restore; + || op == Operation::setOneShot || op == Operation::setCountIn + || op == Operation::push || op == Operation::clear || op == Operation::restore; }; for (const auto op : kEveryOp) CHECK(rc500.allows(op) == open(op)); - CHECK_EQ(profile::openOperations(rc500), std::string("rename, set one-shot, pull, clear and restore")); + CHECK_EQ(profile::openOperations(rc500), + std::string("rename, set one-shot, set count-in, push, pull, clear and restore")); } // Two entries, distinct names, distinct ids: a lookup can never answer twice. { @@ -167,19 +174,20 @@ int main() "this is an \"RC-500\" card, not an RC-5 - LooperCat only speaks RC-5"); for (const auto op : { profile::Operation::read, profile::Operation::pull, profile::Operation::rename, profile::Operation::setOneShot, profile::Operation::clear, + profile::Operation::push, profile::Operation::setCountIn, profile::Operation::restore }) profile::require(profile::kRc500, op); // open: no throw // A closed operation on a model this app reads names itself, the model, - // and what is open there instead. + // and what is open there instead — the open set in the enum's order, + // the count-in (opened 2026-11-07) between One Shot and push. for (const auto op : { profile::Operation::setTempo, - profile::Operation::setCountIn, profile::Operation::push, profile::Operation::trim, profile::Operation::downmix, profile::Operation::normalize, profile::Operation::swap, profile::Operation::setControls, profile::Operation::setRhythm, profile::Operation::setPlayStop }) CHECK_THROWS(profile::require(profile::kRc500, op), std::string(profile::operationName(op)) + " refused on an \"RC-500\" card -" - " on this model LooperCat does rename, set one-shot, pull, clear and restore only"); + " on this model LooperCat does rename, set one-shot, set count-in, push, pull, clear and restore only"); // With nothing open, a mutation still says what the app speaks. CHECK_THROWS(profile::require(closed, profile::Operation::push), "LooperCat only speaks RC-5"); CHECK_EQ(profile::openOperations(closed), std::string()); diff --git a/tests/field_changes.hpp b/tests/field_changes.hpp new file mode 100644 index 0000000..f989333 --- /dev/null +++ b/tests/field_changes.hpp @@ -0,0 +1,115 @@ +// Copyright (c) 2026 Darwin's Cat. Part of Looper Cat — see LICENSE. +// SPDX-License-Identifier: AGPL-3.0-or-later +// +// The exact-changed-set view of a memory write: what one mutation did to a +// memory, named field by field, with every other byte of the document +// asserted identical. A field's value is the only unit a mutation may +// change; everything else about the body is the pedal's, byte for byte. +// Shared by the suites that hold a write to that standard. + +#pragma once + +#include "support.hpp" + +#include + +#include +#include +#include + +namespace testkit { + +// One line of a memory body is one field — a tab, then value — or +// one section's opener or closer on a line of its own: the shape every RC-5 +// writes (the card fixture; golden.json's factory slot). A field line taken +// apart, or nothing for any other line. +struct FieldLine { + std::string tag; + long long value; +}; + +inline std::optional parseFieldLine(const std::string& line) +{ + if (line.size() < 2 || line[0] != '\t' || line[1] != '<') + return std::nullopt; + const auto tagEnd = line.find('>', 2); + if (tagEnd == std::string::npos) + return std::nullopt; + const std::string tag = line.substr(2, tagEnd - 2); + const std::string close = ""; + const std::size_t valueBegin = tagEnd + 1; + if (line.size() < valueBegin + close.size() + || line.compare(line.size() - close.size(), close.size(), close) != 0) + return std::nullopt; + const std::string digits = line.substr(valueBegin, line.size() - close.size() - valueBegin); + std::size_t i = (!digits.empty() && digits[0] == '-') ? 1 : 0; + if (i == digits.size()) + return std::nullopt; + for (; i < digits.size(); ++i) + if (digits[i] < '0' || digits[i] > '9') + return std::nullopt; + return FieldLine { tag, std::stoll(digits) }; +} + +// What changed between two bodies of one memory, as "SECTION.Tag before->after" +// in the body's own order — or "shape" when the bodies differ in anything but +// field values: a line added or lost, a tag renamed, a line outside any +// section touched. A field's value is the only unit a mutation may change; +// everything else about the body is the pedal's, byte for byte. +inline std::string fieldChanges(const std::string& before, const std::string& after) +{ + const auto lines = [](const std::string& text) { + std::vector out; + std::size_t from = 0; + while (true) { + const auto nl = text.find('\n', from); + if (nl == std::string::npos) { + out.push_back(text.substr(from)); + return out; + } + out.push_back(text.substr(from, nl - from)); + from = nl + 1; + } + }; + const std::vector a = lines(before); + const std::vector b = lines(after); + if (a.size() != b.size()) + return "shape"; + std::string section; + std::string out; + for (std::size_t i = 0; i < a.size(); ++i) { + if (a[i] == b[i]) { + // on a line of its own opens section X; closes it. + if (a[i].size() > 2 && a[i].front() == '<' && a[i].back() == '>' + && a[i].find('<', 1) == std::string::npos) { + if (a[i][1] == '/') + section.clear(); + else + section = a[i].substr(1, a[i].size() - 2); + } + continue; + } + const auto fa = parseFieldLine(a[i]); + const auto fb = parseFieldLine(b[i]); + if (!fa || !fb || fa->tag != fb->tag || section.empty()) + return "shape"; + if (!out.empty()) + out += ", "; + out += section + "." + fa->tag + " " + std::to_string(fa->value) + "->" + + std::to_string(fb->value); + } + return out; +} + +// What one mutation of `slot` did to the memory document: that memory's field +// changes, with every byte outside the memory asserted identical (the trailer +// aside — every write stamps it). +inline std::string slotChangesOnCard(const std::string& before, const std::string& after, int slot) +{ + const std::string afterBody = loopercat::rc0::slotBody(after, slot); + CHECK(loopercat::rc0::splitFile(loopercat::rc0::replaceSlotBody(before, slot, afterBody)).document + == loopercat::rc0::splitFile(after).document); + return fieldChanges(loopercat::rc0::slotBody(before, slot), afterBody); +} + +} // namespace testkit diff --git a/tests/rc500_count_in_tests.cpp b/tests/rc500_count_in_tests.cpp new file mode 100644 index 0000000..2ddf69b --- /dev/null +++ b/tests/rc500_count_in_tests.cpp @@ -0,0 +1,307 @@ +// Copyright (c) 2026 Darwin's Cat. Part of Looper Cat — see LICENSE. +// SPDX-License-Identifier: AGPL-3.0-or-later +// +// Play Count-In on the two-track model (opened 2026-11-07). +// +// The theory: the feature owns three fields of - PlayCount, State, +// Pattern - and the two-track card lays that section out as the RC-5 does, +// with the RC-5's numbers: a memory saved on the pedal with the rhythm on, +// pattern Blank, beat 4/4 read State 1, Pattern 57, Beat 2, and against the +// memory's earlier reading exactly State and Pattern had moved (hardware, +// 2026-11-07). So the switch does on this card what it does on the RC-5 and +// not a byte more: on over a silent section borrows it (the triple), on over +// a playing groove moves the count alone, off hands a borrowed section back +// and leaves a groove where it was; neither track section is its business; +// the #149 rule stands at any beat but 4/4; and the pair is written as every +// write writes it - both banks, one document, stamped past the highest +// generation on the card. The pattern and kit lists stay uncharted for this +// model, so the rhythm card stays closed, and the sentence a closed command +// says now lists the count-in among what is open. + +#include "support.hpp" +#include "archive_support.hpp" +#include "field_changes.hpp" +#include "two_track_card.hpp" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace loopercat; +namespace fs = std::filesystem; + +namespace { + +struct TempDir { + fs::path path = fs::temp_directory_path() + / ("loopercat-rc500-count-in-" + + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count())); + TempDir() { fs::create_directories(path); } + ~TempDir() + { + std::error_code ec; + fs::remove_all(path, ec); + if (ec) + testkit::fail("scratch folder left behind: " + ec.message(), __FILE__, __LINE__); + } +}; + +commands::WriteOptions writeOpts(const fs::path& root, std::string opId) +{ + commands::Archive archive = testkit::fileArchive(root / "archive", opId); + return { .opId = std::move(opId), .archive = std::move(archive), .journal = testkit::noOpJournal() }; +} + +// The 2026-11-07 reading of memory 5 on the two-track pedal, saved there with +// the rhythm on, pattern Blank, beat 4/4: what the card stored. Stated here +// as read, not as the code names it - the test's premise is that the two +// coincide. +constexpr long long kReadRhythmOn = 1; +constexpr long long kReadBlank = 57; +constexpr long long kReadFourFour = 2; + +// The hardware pairing of #147 for the uncharted beat: Beat 4 reads 6/4, and +// Rock2 chosen on the pedal is stored as 3 there, as 12 in the 4/4 list. +constexpr long long kSixFour = 4; +constexpr long long kRock2At64 = 3; +constexpr long long kRock2At44 = 12; + +// Every file of the volume with its bytes: the card as a whole, to say +// "nothing moved" after a refusal. +std::map volumeBytes(const fs::path& volume) +{ + std::map out; + for (const auto& entry : fs::recursive_directory_iterator(volume)) + if (entry.is_regular_file()) + out[fs::relative(entry.path(), volume).generic_string()] = + commands::readFileBytes(entry.path()); + return out; +} + +// The takes alone: every file of the volume but the memory pair, which a +// write stamps by design. +std::map takeBytes(const fs::path& volume) +{ + std::map out = volumeBytes(volume); + for (const int fileNo : { 1, 2 }) + out.erase(fs::relative(volume::memoryPath(volume, fileNo), volume).generic_string()); + return out; +} + +// One section's bytes, opener to closer - the unit of "untouched". +std::string section(const std::string& body, const std::string& tag) +{ + const auto open = body.find("<" + tag + ">"); + const auto close = body.find("", open); + if (open == std::string::npos || close == std::string::npos) + throw Error("test fixture: missing section <" + tag + ">"); + return body.substr(open, close - open + tag.size() + 3); +} + +// RHYTHM fields as the pedal's own screens would have left them in one +// memory, in the document the two banks are about to carry. +std::string withRhythm(std::string text, int slot, + std::initializer_list> fields) +{ + std::string body = rc0::slotBody(text, slot); + for (const auto& [tag, value] : fields) + body = rc0::setSectionField(body, rc0::kSectionRhythm, tag, value); + return rc0::replaceSlotBody(text, slot, body); +} + +// The factory pair, as a fresh card carries it: one generation per bank. +void stampFactoryPair(const fs::path& volume, const std::string& text) +{ + for (const int fileNo : { 1, 2 }) + commands::writeFileBytes(volume::memoryPath(volume, fileNo), rc0::setTailMarker(text, fileNo)); +} + +long long rhythmField(const std::string& text, int slot, const char* tag) +{ + return rc0::sectionField(rc0::slotBody(text, slot), rc0::kSectionRhythm, tag); +} + +} // namespace + +int main() +{ + // --- the premise: the card's numbers are the RC-5's --- + + CHECK_EQ(kReadRhythmOn, rc0::kRhythmStateOn); + CHECK_EQ(kReadBlank, rc0::kRhythmPatternBlank); + CHECK_EQ(kReadFourFour, usecases::beat::kBeatFourFour); + CHECK(usecases::beat::patternListCharted(kReadFourFour)); + CHECK(!usecases::beat::patternListCharted(kSixFour)); + + // --- the profile: the bit is open, and a closed command's sentence lists + // it where the enum puts it - between One Shot and push. The expected + // words are the brief's list laid in that order, not the code's own + // output copied back. + + profile::require(profile::kRc500, profile::Operation::setCountIn); // no throw + CHECK(profile::kRc500.allows(profile::Operation::setCountIn)); + CHECK_EQ(profile::openOperations(profile::kRc500), + std::string("rename, set one-shot, set count-in, push, pull, clear and restore")); + for (const auto op : { profile::Operation::setRhythm, profile::Operation::setPlayStop, + profile::Operation::setTempo }) + CHECK_THROWS(profile::require(profile::kRc500, op), + std::string(profile::operationName(op)) + " refused on an \"RC-500\" card -" + " on this model LooperCat does rename, set one-shot, set count-in, push," + " pull, clear and restore only"); + + // --- the card --- + // + // Memory 1: a take on each track, the rhythm silent at 4/4 (the factory + // shape). Memory 3: a groove playing at 4/4 - Rock2 on kit 3, the + // player's. Memory 7: the same groove playing at 6/4. Memory 11: track 2 + // alone, silent at 6/4 with the pedal's Rock2 there. Memory 42: as the + // factory left it. + TempDir tmp; + const fs::path volume = testkit::makeTwoTrackCard( + tmp.path, { { 1, 1, "001_1.WAV", 44100, 1 }, { 1, 2, "001_2.WAV", 22050, 2 }, + { 11, 2, "011_2.WAV", 8820, 5 } }); + { + std::string text = commands::readMemory(volume); + text = withRhythm(text, 3, { { "State", kReadRhythmOn }, { "Pattern", kRock2At44 }, { "Kit", 3 } }); + text = withRhythm(text, 7, { { "State", kReadRhythmOn }, { "Beat", kSixFour }, { "Pattern", kRock2At64 } }); + text = withRhythm(text, 11, { { "Beat", kSixFour }, { "Pattern", kRock2At64 } }); + stampFactoryPair(volume, text); + } + const std::string card = commands::readMemory(volume); + const auto memory = [&volume] { return commands::readMemory(volume); }; + const auto bank = [&volume](int fileNo) { + return commands::readFileBytes(volume::memoryPath(volume, fileNo)); + }; + const auto takesBefore = takeBytes(volume); + const std::uint32_t factoryNewest = std::max(rc0::tailMarkerFor(1), rc0::tailMarkerFor(2)); + + // The catalog's view before a click: a switch on the silent memory, a + // switch beside the groove (nothing at risk: the groove stays), a lamp on + // the 6/4 memory whose borrow the core would refuse. + { + const auto memories = catalog::listSlots(card); + CHECK(!memories.at(0).countIn && !memories.at(0).countInRefused + && !memories.at(0).countInTakesPattern); + CHECK(!memories.at(2).countIn && !memories.at(2).countInRefused + && !memories.at(2).countInTakesPattern); + CHECK(!memories.at(6).countInRefused); // the count alone is open at 6/4 + CHECK(memories.at(10).countInRefused == usecases::countin::Refusal::onBorrowsSection); + CHECK_EQ(memories.at(0).tracks.size(), 2u); + } + + // --- on over a silent section: the triple, and not one byte elsewhere --- + + commands::setCountIn(volume, { 1 }, true, writeOpts(tmp.path, "on-1")); + const std::string onOne = memory(); + CHECK_EQ(testkit::slotChangesOnCard(card, onOne, 1), + std::string("RHYTHM.Pattern 0->57, RHYTHM.PlayCount 0->1, RHYTHM.State 0->1")); + CHECK(catalog::readSlot(onOne, 1).countIn); + CHECK(section(rc0::slotBody(onOne, 1), "TRACK1") == section(rc0::slotBody(card, 1), "TRACK1")); + CHECK(section(rc0::slotBody(onOne, 1), "TRACK2") == section(rc0::slotBody(card, 1), "TRACK2")); + CHECK(takeBytes(volume) == takesBefore); + // The pair: one document in both banks, each stamped past the highest + // generation the card held - the fixture's factory pair. + CHECK(rc0::splitFile(bank(1)).document == rc0::splitFile(bank(2)).document); + CHECK_EQ(rc0::tailMarker(bank(1)).value(), factoryNewest + 1); + CHECK_EQ(rc0::tailMarker(bank(2)).value(), factoryNewest + 2); + + // --- on over a playing groove: the count alone, the groove untouched --- + + commands::setCountIn(volume, { 3 }, true, writeOpts(tmp.path, "on-3")); + const std::string onThree = memory(); + CHECK_EQ(testkit::slotChangesOnCard(onOne, onThree, 3), std::string("RHYTHM.PlayCount 0->1")); + CHECK(catalog::readSlot(onThree, 3).countIn); + CHECK_EQ(rhythmField(onThree, 3, "Pattern"), kRock2At44); + CHECK_EQ(rhythmField(onThree, 3, "Kit"), 3); + CHECK_EQ(rc0::tailMarker(bank(1)).value(), factoryNewest + 3); + CHECK_EQ(rc0::tailMarker(bank(2)).value(), factoryNewest + 4); + + // --- off: the groove stays where it was; the borrowed section goes back --- + + commands::setCountIn(volume, { 3 }, false, writeOpts(tmp.path, "off-3")); + const std::string offThree = memory(); + CHECK_EQ(testkit::slotChangesOnCard(onThree, offThree, 3), std::string("RHYTHM.PlayCount 1->0")); + CHECK(rc0::slotBody(offThree, 3) == rc0::slotBody(card, 3)); + commands::setCountIn(volume, { 1 }, false, writeOpts(tmp.path, "off-1")); + const std::string offOne = memory(); + CHECK_EQ(testkit::slotChangesOnCard(offThree, offOne, 1), + std::string("RHYTHM.Pattern 57->0, RHYTHM.PlayCount 1->0, RHYTHM.State 1->0")); + // The feature keeps no hidden state: the document is back to the byte. + CHECK(rc0::splitFile(offOne).document == rc0::splitFile(card).document); + CHECK(takeBytes(volume) == takesBefore); + + // --- at 6/4 the borrow is refused with the #149 words, and nothing moves --- + + { + const auto before = volumeBytes(volume); + CHECK_THROWS(commands::setCountIn(volume, { 11 }, true, writeOpts(tmp.path, "on-11")), + "Switching the count-in on at 6/4"); + CHECK_THROWS(commands::setCountIn(volume, { 11 }, true, writeOpts(tmp.path, "on-11b")), + std::string(usecases::beat::kOnlyFourFourCharted)); + CHECK(volumeBytes(volume) == before); + CHECK_EQ(rhythmField(memory(), 11, "Pattern"), kRock2At64); + // One refused memory refuses the batch: a 4/4 memory ahead of it in + // the list does not land first. + CHECK_THROWS(commands::setCountIn(volume, { 42, 11 }, true, writeOpts(tmp.path, "on-42-11")), + "at 6/4"); + CHECK(volumeBytes(volume) == before); + CHECK(!catalog::readSlot(memory(), 42).countIn); + CHECK(!fs::exists(tmp.path / "archive")); + } + + // --- the count alone at 6/4 is still the player's --- + + commands::setCountIn(volume, { 7 }, true, writeOpts(tmp.path, "on-7")); + const std::string onSeven = memory(); + CHECK_EQ(testkit::slotChangesOnCard(offOne, onSeven, 7), std::string("RHYTHM.PlayCount 0->1")); + CHECK(catalog::readSlot(onSeven, 7).countIn); + CHECK_EQ(rhythmField(onSeven, 7, "Pattern"), kRock2At64); + CHECK_EQ(rhythmField(onSeven, 7, "Beat"), kSixFour); + commands::setCountIn(volume, { 7 }, false, writeOpts(tmp.path, "off-7")); + CHECK(rc0::splitFile(memory()).document == rc0::splitFile(card).document); + + // --- what stays closed says so, the count-in now among what is open --- + + { + const auto before = volumeBytes(volume); + CHECK_THROWS(commands::setTempo(volume, 1, 1200, writeOpts(tmp.path, "tempo")), + "set tempo refused on an \"RC-500\" card - on this model LooperCat does rename," + " set one-shot, set count-in, push, pull, clear and restore only"); + CHECK_THROWS(commands::setRhythm(volume, 1, { .on = true }, writeOpts(tmp.path, "rhythm")), + "set rhythm refused on an \"RC-500\" card"); + CHECK(volumeBytes(volume) == before); + } + + // --- the bit is this model's: a card of a model this app does not know + // is refused at the door, the count-in included --- + + { + TempDir foreign; + const fs::path unknown = testkit::makeTwoTrackCard(foreign.path, {}, "RC-505"); + const std::string root = ""; + for (const int fileNo : { 1, 2 }) { + std::string text = commands::readFileBytes(volume::memoryPath(unknown, fileNo)); + text.replace(text.find(root), root.size(), ""); + commands::writeFileBytes(volume::memoryPath(unknown, fileNo), text); + } + const auto before = volumeBytes(unknown); + CHECK_THROWS(commands::setCountIn(unknown, { 1 }, true, writeOpts(foreign.path, "foreign")), + "this is an \"RC-505\" card, not an RC-5"); + CHECK(volumeBytes(unknown) == before); + } + + return testkit::summary("rc500_count_in"); +} diff --git a/tests/rc500_push_tests.cpp b/tests/rc500_push_tests.cpp new file mode 100644 index 0000000..7e04dc5 --- /dev/null +++ b/tests/rc500_push_tests.cpp @@ -0,0 +1,263 @@ +// Copyright (c) 2026 Darwin's Cat. Part of Looper Cat - see LICENSE. +// SPDX-License-Identifier: AGPL-3.0-or-later +// +// Push on the two-track model: into a memory with no take on any track, and +// nowhere else (decided 2026-10-29). +// +// The theory, from the pedal's own files (2026-09-22/23 readings): a take +// lands on track 1 as the memory's first recording, with the body the +// one-track model gets - TRACK1 WavStat, WavLen, MeasLen, Measure, RecTmp; +// MASTER Tempo and LpLen, the length of the first recording; track 2 and +// the MASTER fields the pedal keeps for itself (CurrentTrack, LpMod) +// untouched. What the pedal makes of a second take of another length beside +// a pushed one has not been asked of it, so a memory with a take on either +// track - configured or merely in its folder - is refused in a sentence that +// names the track, force or not, config written or not; and the profile gate +// stands on the drop-only path as on the configured one. The state before +// the push is a unit a restore takes back: both tracks empty again. + +#include "support.hpp" +#include "archive_support.hpp" +#include "two_track_card.hpp" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace loopercat; +namespace fs = std::filesystem; + +namespace { + +struct TempDir { + fs::path path = fs::temp_directory_path() + / ("loopercat-rc500-push-" + + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count())); + TempDir() { fs::create_directories(path); } + ~TempDir() + { + std::error_code ec; + fs::remove_all(path, ec); + if (ec) + testkit::fail("scratch folder left behind: " + ec.message(), __FILE__, __LINE__); + } +}; + +commands::WriteOptions writeOpts(const fs::path& root, std::string opId) +{ + commands::Archive archive = testkit::fileArchive(root / "archive", opId); + return { .opId = std::move(opId), .archive = std::move(archive), .journal = testkit::noOpJournal() }; +} + +// Every file of the volume with its bytes: the card as a whole, to say +// "nothing moved" after a refusal. +std::map volumeBytes(const fs::path& volume) +{ + std::map out; + for (const auto& entry : fs::recursive_directory_iterator(volume)) + if (entry.is_regular_file()) + out[fs::relative(entry.path(), volume).generic_string()] = + commands::readFileBytes(entry.path()); + return out; +} + +// A source long enough for a real tempo: 30 s -> 8 measures, 96.0 BPM by the +// pedal's formula (params::computeSlotParams), the pedal's own format. +constexpr int kFrames = 1323000; + +fs::path writeSource(const fs::path& dir, const std::string& name) +{ + const auto bytes = testkit::syntheticWav({ .tag = 3, .bits = 32, .frames = kFrames }); + const fs::path source = dir / name; + commands::writeFileBytes(source, std::string_view(reinterpret_cast(bytes.data()), + bytes.size())); + return source; +} + +long long trackField(const std::string& body, int track, const char* tag) +{ + return rc0::sectionField(body, rc0::trackSectionName(track), tag); +} + +} // namespace + +int main() +{ + // The card: memory 1 recorded on both tracks, memory 11 on track 2 + // alone, memory 42 as the factory left it. + TempDir tmp; + const fs::path volume = testkit::makeTwoTrackCard( + tmp.path, { { 1, 1, "001_1.WAV", 44100, 1 }, { 1, 2, "001_2.WAV", 22050, 2 }, + { 11, 2, "011_2.WAV", 8820, 5 } }); + const fs::path source = writeSource(tmp.path, "take.wav"); + const auto trackFiles = [&volume](int slot, int track) { + return volume::listTrackWavs(volume, profile::kRc500, slot, track); + }; + { + // The pedal's MASTER carries CurrentTrack beside LpMod (the 2026-09-22 + // card: 0 and 0 on an untouched memory); the synthetic text has the + // latter and not the former, so memory 42 gets it here, as the card + // has it, and the push can be seen leaving both alone. + std::string text = commands::readMemory(volume); + std::string body = rc0::slotBody(text, 42); + const std::string_view after = ""; + const auto at = body.find(after); + CHECK(at != std::string::npos); + body.insert(at + after.size(), "\n\t0"); + commands::writeMemoryPair(volume, rc0::replaceSlotBody(text, 42, body), + testkit::unrecordedWrite()); + } + + // --- what the catalog offers, before anything is pushed --- + + { + const auto memories = catalog::listSlots(commands::readMemory(volume)); + CHECK(!catalog::uploadOffered(memories.at(0))); // both tracks recorded + CHECK(!catalog::uploadOffered(memories.at(10))); // track 2 alone is a used memory + CHECK(catalog::uploadOffered(memories.at(41))); // nothing on either track + // The one-track model is offered a push whatever the slot holds: an + // occupied slot takes a replace there. + auto one = catalog::listSlots(testkit::syntheticMemoryText()).at(0); + CHECK(catalog::uploadOffered(one)); + one.tracks.at(0).hasAudio = true; + CHECK(catalog::uploadOffered(one)); + } + + // --- an empty memory takes the upload, on track 1, with the RC-5 body rules --- + + const commands::SlotState before { rc0::slotBody(commands::readMemory(volume), 42), {} }; + { + const std::string bodyBefore = before.body; + const auto result = + commands::push(volume, source, 42, { .name = "Pushed", .write = writeOpts(tmp.path, "op-1") }); + CHECK(result.configured); + CHECK(result.dest == volume::trackDir(volume, profile::kRc500, 42, 1) / "take.wav"); + CHECK_EQ(trackFiles(42, 1).size(), 1u); + CHECK(trackFiles(42, 2).empty()); // track 2's folder is as it was: empty + + const std::string text = commands::readMemory(volume); + const std::string body = rc0::slotBody(text, 42); + const auto expected = params::computeSlotParams(kFrames); + CHECK_EQ(trackField(body, 1, "WavStat"), 1); + CHECK_EQ(trackField(body, 1, "WavLen"), kFrames); + CHECK_EQ(trackField(body, 1, "MeasLen"), expected.measures); + CHECK_EQ(trackField(body, 1, "Measure"), expected.measureField()); + CHECK_EQ(trackField(body, 1, "RecTmp"), expected.tempoTenths); + CHECK_EQ(rc0::sectionField(body, rc0::kSectionMaster, "Tempo"), expected.tempoTenths); + CHECK_EQ(rc0::sectionField(body, rc0::kSectionMaster, "LpLen"), expected.measures); + CHECK_EQ(rc0::decodeName(body), "Pushed "); + // Track 2's section and the MASTER fields the pedal keeps for itself + // are byte for byte what the factory left. + for (const char* tag : { "WavStat", "WavLen", "MeasLen", "Measure", "RecTmp" }) + CHECK_EQ(trackField(body, 2, tag), trackField(bodyBefore, 2, tag)); + for (const char* tag : { "CurrentTrack", "LpMod" }) + CHECK_EQ(rc0::sectionField(body, rc0::kSectionMaster, tag), + rc0::sectionField(bodyBefore, rc0::kSectionMaster, tag)); + CHECK_EQ(rc0::sectionField(body, rc0::kSectionMaster, "CurrentTrack"), 0); // track 1, zero-based + + // Both banks carry it, and the catalog reads a memory recorded on + // track 1 - which is a used memory now. + CHECK(rc0::slotBody(commands::readMemory(volume, 1), 42) + == rc0::slotBody(commands::readMemory(volume, 2), 42)); + const auto memory = catalog::listSlots(text).at(41); + CHECK(memory.tracks.at(0).hasAudio && !memory.tracks.at(1).hasAudio); + CHECK(catalog::holdsAudio(memory) && !catalog::uploadOffered(memory)); + } + + // --- a used memory is refused, naming the track in the way; nothing moves --- + + { + const auto untouched = volumeBytes(volume); + CHECK_THROWS(commands::push(volume, source, 1, { .write = writeOpts(tmp.path, "op-2") }), + "memory 1 holds a take on track 1"); + CHECK_THROWS(commands::push(volume, source, 1, { .write = writeOpts(tmp.path, "op-2") }), + "upload into a used \"RC-500\" memory is not offered yet"); + // Force is the one-track model's replace; here it changes nothing. + CHECK_THROWS(commands::push(volume, source, 1, + { .force = true, .write = writeOpts(tmp.path, "op-2") }), + "not offered yet"); + // Track 2 alone, the flat fields saying "empty": the sentence names + // the second track. + CHECK_THROWS(commands::push(volume, source, 11, { .write = writeOpts(tmp.path, "op-2") }), + "memory 11 holds a take on track 2"); + // The memory just pushed is used now, like one the pedal recorded. + CHECK_THROWS(commands::push(volume, source, 42, + { .force = true, .write = writeOpts(tmp.path, "op-2") }), + "memory 42 holds a take on track 1"); + CHECK(volumeBytes(volume) == untouched); + CHECK(!fs::exists(tmp.path / "archive" / "op-2")); + } + + // --- a take in the folder alone is a used memory too --- + + { + // Memory 7's body says empty; a file sits in its track 2 folder (a + // hand copy, or a take the pedal has not indexed). Not offered: what + // the pedal would make of the pair is the same unknown. + commands::writeFileBytes(volume::trackDir(volume, profile::kRc500, 7, 2) / "stray.wav", + testkit::floatTake(4410, 9)); + const auto untouched = volumeBytes(volume); + CHECK_THROWS(commands::push(volume, source, 7, { .write = writeOpts(tmp.path, "op-3") }), + "memory 7 holds a take on track 2"); + CHECK(volumeBytes(volume) == untouched); + } + + // --- the drop-only path is ruled and gated like the configured one --- + + { + // No config written, the same rule: a used memory takes no file. + const auto untouched = volumeBytes(volume); + CHECK_THROWS(commands::push(volume, source, 11, + { .writeConfig = false, .write = writeOpts(tmp.path, "op-4") }), + "memory 11 holds a take on track 2"); + CHECK(volumeBytes(volume) == untouched); + } + { + // A card the gate does not read - a model the table does not know - + // refuses the drop-only push before the file lands: the memory is + // read first on every path, so no model this app does not open for + // push ever gets a file dropped into its folders. + TempDir foreign; + const fs::path card = testkit::makeTwoTrackCard(foreign.path, {}); + const std::string root = ""; + for (const int fileNo : { 1, 2 }) { + std::string text = commands::readFileBytes(volume::memoryPath(card, fileNo)); + text.replace(text.find(root), root.size(), ""); + commands::writeFileBytes(volume::memoryPath(card, fileNo), text); + } + const fs::path foreignSource = writeSource(foreign.path, "take.wav"); + const auto untouched = volumeBytes(card); + CHECK_THROWS(commands::push(card, foreignSource, 42, + { .writeConfig = false, .write = writeOpts(foreign.path, "op-5") }), + "RC-505"); + CHECK(volumeBytes(card) == untouched); + CHECK(volume::listTrackWavs(card, profile::kRc500, 42, 1).empty()); + } + + // --- the state before the push is a unit a restore takes back --- + + { + const commands::WriteOptions restoring = writeOpts(tmp.path, "op-6"); + const auto result = commands::restore(volume, 42, before, restoring); + CHECK_EQ(result.archived.size(), 1u); // the pushed take, kept first + CHECK_EQ(result.frames.size(), 2u); + if (result.frames.size() == 2) + CHECK(result.frames.at(0) == 0 && result.frames.at(1) == 0); + CHECK(trackFiles(42, 1).empty() && trackFiles(42, 2).empty()); + CHECK(rc0::slotBody(commands::readMemory(volume), 42) == before.body); + const auto memory = catalog::listSlots(commands::readMemory(volume)).at(41); + CHECK(!catalog::holdsAudio(memory) && catalog::uploadOffered(memory)); + } + + return testkit::summary("rc500_push_tests"); +} diff --git a/tests/slot_table_harness.cpp b/tests/slot_table_harness.cpp index e4697c8..644762a 100644 --- a/tests/slot_table_harness.cpp +++ b/tests/slot_table_harness.cpp @@ -78,10 +78,11 @@ int main() CHECK(rc5.closed.empty()); // The two-track model: what carries every track of a memory, nothing else. const CardPermissions rc500 = CardPermissions::of("RC-500"); - CHECK(rc500.rename && rc500.oneShot && rc500.pull && rc500.clear && rc500.restore); - CHECK(!rc500.tempo && !rc500.countIn && !rc500.push && !rc500.swap + CHECK(rc500.rename && rc500.oneShot && rc500.countIn && rc500.push && rc500.pull + && rc500.clear && rc500.restore); + CHECK(!rc500.tempo && !rc500.swap && !rc500.normalize && !rc500.trim && !rc500.downmix && !rc500.rhythm && !rc500.playStop); - CHECK_EQ(rc500.closed, "On the RC-500, LooperCat does rename, set one-shot, pull, clear and restore only"); + CHECK_EQ(rc500.closed, "On the RC-500, LooperCat does rename, set one-shot, set count-in, push, pull, clear and restore only"); for (const char* name : { "RC-505", "", "rc-5" }) { const CardPermissions none = CardPermissions::of(name); CHECK(!none.anyWrite()); @@ -169,16 +170,25 @@ int main() doubleClick(nameColumn); CHECK_EQ(activations, 1); - // The two-track model: Count-In and push stay closed — a lamp, no drag - // — while One Shot is open (a flag of each track) and its click goes - // through; the name, also open, takes the editing path on a double-click - // instead of playing. + // The two-track model: One Shot (a flag of each track) and Count-In + // (the RHYTHM triple, the RC-5's numbers on this card too — hardware + // 2026-11-07) are open, and their clicks go through; push is open, so + // the drag is wanted (which rows take the drop is below); the name, also + // open, takes the editing path on a double-click instead of playing. table.permissions = [] { return CardPermissions::of("RC-500"); }; click(oneShotColumn); click(countInColumn); CHECK_EQ(oneShotClicks, 1); - CHECK_EQ(countInClicks, 0); - CHECK(!table.isInterestedInFileDrag({ "/somewhere/loop.wav" })); + CHECK_EQ(countInClicks, 1); + // The beat rule is the core's, not the model's: the dot the core would + // refuse at 6/4 is a lamp on this card as on the RC-5, with the same + // hover, and the one beside it, over a playing rhythm, is a button. + model->cellClicked(1, countInColumn, clickAt(table)); + CHECK_EQ(countInClicks, 1); + CHECK(model->getCellTooltip(1, countInColumn).contains("6/4")); + model->cellClicked(2, countInColumn, clickAt(table)); + CHECK_EQ(countInClicks, 2); + CHECK(table.isInterestedInFileDrag({ "/somewhere/loop.wav" })); table.onRenameCommitted = nullptr; doubleClick(nameColumn); CHECK_EQ(activations, 1); // unchanged: the edit path, no play @@ -193,7 +203,7 @@ int main() click(countInColumn); click(wavColumn); CHECK_EQ(oneShotClicks, 2); - CHECK_EQ(countInClicks, 1); + CHECK_EQ(countInClicks, 3); CHECK_EQ(hintClicks, 1); CHECK(table.isInterestedInFileDrag({ "/somewhere/loop.wav" })); table.onRenameCommitted = nullptr; @@ -204,11 +214,11 @@ int main() // too, and its hover says why in the card's words; a dot that can be // clicked, and every other cell, says nothing. model->cellClicked(1, countInColumn, clickAt(table)); - CHECK_EQ(countInClicks, 1); + CHECK_EQ(countInClicks, 3); CHECK(model->getCellTooltip(1, countInColumn).contains("6/4")); CHECK(model->getCellTooltip(1, countInColumn).contains("switch the rhythm on at the pedal")); model->cellClicked(2, countInColumn, clickAt(table)); - CHECK_EQ(countInClicks, 2); + CHECK_EQ(countInClicks, 4); CHECK(model->getCellTooltip(2, countInColumn).isEmpty()); CHECK(model->getCellTooltip(0, countInColumn).isEmpty()); CHECK(model->getCellTooltip(1, oneShotColumn).isEmpty()); @@ -376,5 +386,68 @@ int main() CHECK(model->getCellTooltip(0, oneShotColumn).isEmpty()); } + // --- a drop lands only where an upload is offered --- + // + // On the two-track model push is open, but a memory with a take on + // either track is not offered one (catalog::uploadOffered): a drop on + // such a row calls nobody, while an empty memory takes the file - the + // second track alone, which the flat fields call empty, counts. On the + // one-track model every row takes the drop: an occupied slot's is a + // replace. + { + // The two-track text as measured on the pedal: memory 11 recorded on + // track 2 alone, memory 5 factory-empty. + std::vector twoRows; + for (auto& info : catalog::listSlots(testkit::syntheticTwoTrackMemoryText())) + twoRows.push_back({ std::move(info), "", "", { "" }, std::nullopt }); + CHECK(!twoRows.at(10).info.hasAudio && catalog::holdsAudio(twoRows.at(10).info)); + CHECK(!catalog::holdsAudio(twoRows.at(4).info)); + table.setRows(twoRows); + table.permissions = [] { return CardPermissions::of("RC-500"); }; + std::vector landed; + table.onAudioDropped = [&landed](int slot, juce::String) { landed.push_back(slot); }; + // A point on the row, in the table's own space wherever the list box + // sits inside it. + const auto rowPoint = [&box, &table](int row) { + const auto r = box->getRowPosition(row, true); + CHECK_EQ(box->getRowContainingPosition(40, r.getCentreY()), row); // the point is on the row + return table.getLocalPoint(box, juce::Point(40, r.getCentreY())); + }; + const juce::StringArray files { "/somewhere/loop.wav" }; + CHECK(table.isInterestedInFileDrag(files)); + // The empty-slot hint's click: memory 11's flat fields say empty + // and its folder list is empty, but track 2 holds a take - no + // chooser; memory 5's opens one. + const int hintsBefore = hintClicks; + model->cellClicked(10, wavColumn, clickAt(table)); + CHECK_EQ(hintClicks, hintsBefore); + model->cellClicked(4, wavColumn, clickAt(table)); + CHECK_EQ(hintClicks, hintsBefore + 1); + table.filesDropped(files, rowPoint(10).x, rowPoint(10).y); // memory 11: track 2 holds a take + CHECK(landed.empty()); + table.filesDropped(files, rowPoint(4).x, rowPoint(4).y); // memory 5: nothing on either track + CHECK((landed == std::vector { 5 })); + // A file in a folder with the config saying empty - a hand copy, or + // a take the pedal has not indexed - is a used memory to the core, so + // neither the drop nor the hint offers it. + twoRows.at(4).wavFile = "T1 stray.wav"; + table.setRows(twoRows); + table.filesDropped(files, rowPoint(4).x, rowPoint(4).y); + CHECK((landed == std::vector { 5 })); + model->cellClicked(4, wavColumn, clickAt(table)); + CHECK_EQ(hintClicks, hintsBefore + 1); + + std::string oneText = testkit::syntheticMemoryText(); + oneText = rc0::replaceSlotBody(oneText, 1, + rc0::setField(rc0::slotBody(oneText, 1), "WavStat", 1)); + std::vector oneRows; + for (auto& info : catalog::listSlots(oneText)) + oneRows.push_back({ std::move(info), "", "", { "" }, std::nullopt }); + table.setRows(oneRows); + table.permissions = [] { return CardPermissions::of("RC-5"); }; + table.filesDropped(files, rowPoint(0).x, rowPoint(0).y); // slot 1 holds a take: a replace + CHECK((landed == std::vector { 5, 1 })); + } + return testkit::summary("slot_table_harness"); } diff --git a/tests/usecase_controls_tests.cpp b/tests/usecase_controls_tests.cpp index d4aad41..501b0fa 100644 --- a/tests/usecase_controls_tests.cpp +++ b/tests/usecase_controls_tests.cpp @@ -306,7 +306,7 @@ int main() CHECK_THROWS(controls::readAll(twoTrack), notOnRecord); CHECK_THROWS(controls::set(twoTrack, controls::Control::pedal, 28), "set controls refused on an \"RC-500\" card - on this model LooperCat" - " does rename, set one-shot, pull, clear and restore only"); + " does rename, set one-shot, set count-in, push, pull, clear and restore only"); const std::string unknown = withRoot(system, "RC-505"); CHECK_THROWS(controls::read(unknown, controls::Control::pedal), "this is an \"RC-505\" card, not an RC-5");