feat(modapi): songPlayed, and content flags bound to how a song was played #2658
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2658
Loading…
Reference in a new issue
No description provided.
Delete branch "ChloeNow/Longshot:feat/modapi-song-played"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Mods can't tell when the ocarina plays a song, or how it was played. A mod that wants to react to songs (a tracker, a
randomizer, a mod that changes what a song does) has nothing to listen to, and an event flow can't branch on whether a
song was sung or pressed on the buttons.
This adds two things to the Modding API:
songPlayedinlongshot/game:{ frame, song, source }for the first song the ocarina recognises in each try, keeping at most 16 songs between frames.songis one ofthe game's thirteen (
sunsSong,preludeOfLight,scarecrowsSong...),sourceis"microphone"(sung or played onan instrument through the game's Ocarina Mic Input option) or
"buttons". It arrives at the acquire phase like theother game events (order 28). A filter keeps a listener to the songs it wants, as
flagChangeddoes:songPlayed.on(fn, { song: "sunsSong", source: "microphone" }).bind: "ocarina.sung"on acontent.flagbool: the game side sets the flag on the game's own thread the momentthe song is recognised, before the event flow goes on, so a flow (with a flow patch, #2656) can branch on it with no
script in the way. It comes from the same site as
songPlayed, sohas("game.songPlayed")says whether a build setsit.
How it's found: the event flows ask the query node
QueryMelodyTypeForNormal(f_82a7c980) which song was recognised;a new core site
ocarina.melodysits just after its answer (w1), with an engine callback. A try is one run of thenote-wait action (the existing
ocarina.waitStart), told once. It's the buttons' when a note button went down in theword the game reads during the wait, including before the first controller read of the try; a button already held is
not a note until released and pressed again. It's the microphone's when no note button went down and the game listened
on the microphone at some point in the wait (the game stops its streams just before it recognises the song, so this is
kept for the whole try). If neither happened, it's the buttons'.
Read first:
game/crates/game-core/src/ocarina.rs(the try, the site's callback, the bound flags, what the API takes),the site's row in
game/sites/sites.toml, thengame_events_stepingame/crates/api/src/services/game.rsandcontent_bindsinservices/content.rs; the schema'ssongPlayed(game.toml) andSong,SongSource,SongPlayed,SongFilter(types.toml). The host's part is small:host/nn_hid.coc_trackhands each read's fivenote buttons and
host/nn_audio_in.c's newhos_mic_listeningtogame_ocarina_notes(game/game.h). The test gameplays a song with
game.playSong(song, { source }), through the samegame_core::ocarina::tellthe site uses.This is #2267's change, made again on the Rust mod API and the new hook sites; #2267 (the C mod API) can close. Part of
#1958's Modding API; targets
mod-api. Magic Singing (a mod that skips the song cutscene when you sing) uses it with theflow patches (#2656) and flags by id (#2657).
Testing
Tested: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24. In the game (a quick build of current
mod-apiwith this, #2656 and #2657;dev.py game-tests, the repository'skokiri-start): the lift placesocarina.melodyinf_82a7c980(gen/edits.txt); a mod thatrequiresgame.songPlayed, declares a flag withbind: "ocarina.sung"and listens tosongPlayed(once with a filter) starts,has("game.songPlayed")is true, itsbound flag is in the game, and its test passes. Checks:
cargo test -p game-core(ocarina: a try told once, on thebuttons or heard, a held button that is no note, none recognised, nothing kept while not watched),
-p content(thecontent vectors: a bound bool flag,
bindrefused on an int and for an unknown target),-p modtool(the test game:songPlayedand a filtered listener, the bound flag set at once each way, an unknown song refused),-p api,-p game-sites,-p sites --test repository;cargo check --workspace --all-targets;cargo run -p schema-gen -- --check; rustfmt. Tests that fail onmod-apiitself and here, on Windows:api'sa_content_mods_changed_module_runs_again_and_its_outputs_are_served,modtool'seden_and_ryujinx_mods_are_found_with_their_switches, andlongshot-game's three path tests(
a_folder_of_mods_tests_each_of_its_folders,a_mods_profile_sits_inside_the_launchers_save_folder,a_separate_mod_moves_the_saves_into_its_profile_and_records_it).The C version (#2267) was played: songs on the buttons told once as
"buttons"with the bound flag 0, songs sung toldas
"microphone"with the flag 1 and the flow taking the bound branch. The site and the offset are the same here.Still to test:
songPlayedand the bound flag each way (a playtest:the ocarina in hand)
mise run rustandmise run test(by hand, or CI)Measurements
Nothing to measure: the site runs once per recognised song and sets nothing while no mod listens or binds a flag; the
note tracking is a few loads and compares per controller read.
Risks
A new engine site in the melody query: if its signature stops matching on another build,
songPlayedis absent there(
has()false), a bound flag stays false, and nothing else changes. With no mod using it, nothing a player notices. Thegenerated docs' schema hash (
docs/modding/*.md), andtesting_game/tests.rsbeside #2657's new test, conflict with#2656 and #2657: whichever merges later needs
cargo run -p schema-genagain and both tests kept.Checklist
Ready for review
mod-api; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened. (builder/crates/sites/tests/site_owners.txtnames the new site)Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Mods can't tell when the ocarina plays a song, or how: a tracker, a randomizer or a mod that changes what a song does has nothing to listen to, and an event flow can't branch on whether a song was sung or pressed on the buttons. - longshot/game's songPlayed: { frame, song, source } for each song the ocarina recognises, once a try, at the acquire phase (order 28). song is one of the game's thirteen (the schema's Song, in the game's order), source "microphone" (heard through the game's own microphone option, no note button pressed in the try) or "buttons". A SongFilter keeps a listener to one song, one way of playing, or both. - content.flag's bind: "ocarina.sung" on a bool flag: the game side sets it as the song is recognised, on the game's thread, before the flow goes on (true heard, false on the buttons), so a flow patch can branch on it. The site ocarina.melody (game/sites/sites.toml) sits just after QueryMelodyTypeForNormal's answer (f_82a7c980, w1); game_core::ocarina tells a try's first song (a try: one run of the note-wait action, ocarina.waitStart), sets the bound flags and keeps it for the API. host/nn_hid.c hands each read's five note buttons, and whether the game listens on the microphone (host/nn_audio_in.c hos_mic_listening), to game_ocarina_notes. The API fires the event in game_events_step and hands the running mods' bound flags (content::plan::Content::binds) to the game side when they change; has("game.songPlayed") follows the site. The test game plays a song with game.playSong(song, { source }). Tests: game-core's ocarina (a try told once, buttons or heard, none recognised, not watched), the content vectors (a bound bool flag, bind refused on an int and for an unknown target), modtool's testing_game (songPlayed and a filter, the bound flag set at once each way, an unknown song refused). This replaces #2267, which made the same change to the C mod API. Co-Authored-By: Claude Opus 5.5 <[email protected]>Tested in game: Windows 11, RTX 4060 Laptop, a quick build of current mod-api with this, #2656 and #2657: the lift places ocarina.melody in f_82a7c980, and a mod that requires game.songPlayed, binds a flag to ocarina.sung and listens to songPlayed starts with has("game.songPlayed") true and its flag in the game; its test passes (dev.py game-tests, kokiri-start). A song played in this build is still to do (a playtest).
@review
Recommendation: Request changes. The new event can report the wrong input source, silently leaves some declared bound flags unchanged, and fires out of its declared order. The actual song-recognition path has not yet been played in this build.
Adds a song-recognition event and flags that let event flows branch on how a song was played. The API is useful, but its input tracking, flag limit, and event ordering need correction.
Blocking (2): must change before merging.
game/crates/game-core/src/ocarina.rs:79: The first controller sample after a try starts is always treated as already held, even if the button went down after the wait began. (more on the line) Do: Preserve a baseline from before the try starts and compare the first wait sample against it; add a test for a press between start and the first read.@​fixor@​rebasetry first). (for the author)Should fix (2): not blocking, but worth doing before merging.
game/crates/game-core/src/ocarina.rs:165: The binding list silently truncates valid declarations after 64 flags. (more on the line) Do: Support all accepted bindings, or enforce and report a shared limit before accepting declarations; test the boundary.game/crates/api/src/services/game.rs:229: songPlayed fires before paused, although the schema assigns it order 28, after paused at order 24. (more on the line) Do: Fire songPlayed after the lower-order game events and add an ordering test covering events in the same frame.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
game/sites/sites.toml:1090: The new recognition and binding path has not been exercised by playing a song in this build. (more on the line) Do: Play a song on buttons and through the microphone on this head, checking the event, its source, and the bound flow flag; also exercise the path on Linux.@fixcan do L1, L2 and L3.Checks: Still running:
Guide screenshots / Guide images and local UI source review (pull_request),Third-party parts / As their notes say (pull_request),Third-party parts / The same as upstream (pull_request).More: does it help, other systems, switches, what was read
Does it help: Unproven: the reported Windows run verifies hook placement and the fake-game test, but did not play a song through this build. No before-and-after performance numbers were reported.
Other systems: The hook and input tracking run on Windows and Linux and can affect controller reads even without a listening mod. The reported run covers Windows and one NVIDIA GPU; Linux and actual button and microphone song recognition remain untested. The fake game bypasses the hook and input tracking.
Switches: None.
Reviewed:
026d5d5084against3391f978eb: Read the supplied rules, PR description, comment and CI results; CONTRIBUTING.md, AGENTS.md, the PR template, standards, the diff and commit message. Read the new ocarina module and relevant wait, controller, flag and event code; skimmed generated documentation, schema, vectors and test changes. The requested review checklist and adjacent Tooling AGENTS.md were absent. The larger changed files and all surrounding callers were not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands from the project, builds, or tests were run, as requested. The author's reported tests and playtest limitations are described above.
Overlaps and merge order: The PR identifies #2656 and #2657 as overlapping generated docs and test changes; their merge order is not established here.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -212,6 +226,15 @@ impl Services {}}}if songs {L3 (should fix): songPlayed fires before paused, although the schema assigns it order 28, after paused at order 24.
When: When a pause change and a recognised song are delivered in the same frame, a mod subscribed to both observes songPlayed first, contrary to the documented frame order.
Do: Fire songPlayed after the lower-order game events and add an ordering test covering events in the same frame.
@ -0,0 +76,4 @@if SEEN_START.swap(starts, Ordering::AcqRel) != starts {HELD.store(held, Ordering::Relaxed);BUTTONS_USED.store(false, Ordering::Release);MIC_SEEN.store(false, Ordering::Release);L1 (blocking): The first controller sample after a try starts is always treated as already held, even if the button went down after the wait began.
When: With microphone listening, a note button pressed between waitStart and the next controller read is copied into HELD before the edge check. If no later button goes down, the recognised song is reported as microphone and the bound flag is true despite a note-button press.
Do: Preserve a baseline from before the try starts and compare the first wait sample against it; add a test for a press between start and the first read.
@ -0,0 +162,4 @@}/// The flags set at each recognised song (every running mod's content flags bound to `"ocarina.sung"`, by the game's/// hash of their names), in place of the last set; at most [`BINDS_MAX`]. Any thread.L2 (should fix): The binding list silently truncates valid declarations after 64 flags.
When: A mod can declare more than 64 bound bool flags, or several mods can exceed 64 together. content_binds returns them all, but binds keeps only the first 64, so the remaining flags retain old values and their flows take the wrong branch.
Do: Support all accepted bindings, or enforce and report a shared limit before accepting declarations; test the boundary.
@ -1086,0 +1087,4 @@# (game/crates/game-core/src/ocarina.rs on_ocarina_melody, registered in game/crates/game-core/src/engine.rs).[[site]]name = "ocarina.melody"engine = "hos_site_ocarina_melody"L4 (should fix): The new recognition and binding path has not been exercised by playing a song in this build.
When: The recorded run establishes site placement and exercises the fake game, whose playSong calls tell directly; it does not establish that actual button and microphone input reaches the hook with the correct song and source.
Do: Play a song on buttons and through the microphone on this head, checking the event, its source, and the bound flow flag; also exercise the path on Linux.
@fix
026d5d50847c99c02439Recommendation: Approve. The code is ready: only testing is left. The event and bound flag have not yet been exercised by playing songs in this build. The recorded automated checks and earlier C implementation playtest do not establish that the new integration works in game. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
7c99c02439. I rebased it ontomod-api(0c803d490c).Conflicts resolved
Changed
Nothing was built or run: the checks run again on the new head.
The change lets mods react to recognized songs and lets event flows branch on whether a song was heard through the microphone. The fix preserves that feature while correcting first-read tracking, the binding limit and event order; the integration still needs a playtest.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
game/sites/sites.toml:1090: The new recognition and binding path has not been exercised by playing a song in this build. When: The recorded run establishes site placement and exercises the fake game, whose playSong calls tell directly; it does not establish that actual button and microphone input reaches the hook with the correct song and source. Do: Play a song on buttons and through the microphone on this head, checking the event, its source, and the bound flow flag; also exercise the path on Linux.Checks: they run again on this head; a failure shows on the pull request.
Also noticed (1; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Unproven: the test game and mod startup were reported working on Windows, but neither a button-played nor a sung song has been tested in this build.
Other systems: The host input and microphone paths run on Windows and Linux. The reported integration check was on Windows; Linux and actual song recognition remain untested.
Switches: No switches added, changed or removed.
Reviewed:
7c99c02439against0c803d490c: Read game/crates/game-core/src/ocarina.rs in full and inspected the fix diff, event dispatch, the changed test, relevant callers, repository rules and reported runs. The large base diff, other changed files and generated documentation were not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run code were executed. The author reports Windows automated checks and a mod startup test; the song playtest and Linux checks remain outstanding, and CI has not run on this head.
Overlaps and merge order: #2656 and #2657 overlap in generated documentation and tests; whichever merges later needs conflict resolution and schema regeneration.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
@fix
7c99c02439b180af9425Recommendation: Approve. The code is ready: only testing is left (a run of the change itself). The API and bound flag are in place, but their actual recognition path still needs a playtest with both button and microphone input. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
b180af9425. I rebased it ontomod-api(3f47557067).Conflicts resolved
Nothing was built or run: the checks run again on the new head.
Mods can listen for recognised songs and branch on how they were played. The change adds input tracking and a recognition hook; its in-game behaviour remains to be demonstrated.
Testing before merging (1) (the change behaves the same on every system: one run of the change itself is enough; it doesn't hold the recommendation)
game/sites/sites.toml:1090: The new recognition and binding path has not been exercised by playing a song in this build. When: The recorded run establishes site placement and exercises the fake game, whose playSong calls tell directly; it does not establish that actual button and microphone input reaches the hook with the correct song and source. Do: Play a song on buttons and through the microphone on this head, checking the event, its source, and the bound flow flag; also exercise the path on Linux.Checks: they run again on this head (
Guide screenshots / Guide images and local UI source review (pull_request)failed on the last one); a failure shows on the pull request.More: does it help, other systems, switches, what was read
Does it help: Unproven: the reported Windows run verified the site, feature availability and mod startup, but did not play a song in this build.
Other systems: The host input and microphone paths run on Windows and Linux; Linux checks are still outstanding. The site is build-specific and feature availability reports whether it was found.
Switches: None added, changed or removed.
Reviewed:
b180af9425against3f47557067: Read AGENTS.md, CONTRIBUTING.md, the pull request template and game/crates/game-core/src/ocarina.rs in full. Examined the recognition site, host input and microphone changes, API event and binding changes, rebased documentation changes and recorded test results; the remaining changed files and generated documentation were not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands that run the project or tests were executed. The author reports game-free checks and a Windows startup integration run; the song playtest and Linux checks remain outstanding, and CI has not run on this head.
Overlaps and merge order: The description identifies potential generated documentation and test conflicts with #2656 and #2657; merge order is not established.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
@fix
b180af9425a8050b23baRecommendation: Approve. The code is ready: only testing is left. The new event and bound flag have not yet been exercised by playing songs in this build. A buttons-and-microphone playtest is needed before the feature is shown working. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
a8050b23ba. I rebased it ontomod-api(37c16741d7).Conflicts resolved
Nothing was built or run: the checks run again on the new head.
Adds a song recognition event and a content flag that lets mods branch on how a song was played. It gives mods a useful integration point, with added input tracking and a game hook whose real-game behavior remains unverified.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
game/sites/sites.toml:1090: The new recognition and binding path has not been exercised by playing a song in this build. When: The recorded run establishes site placement and exercises the fake game, whose playSong calls tell directly; it does not establish that actual button and microphone input reaches the hook with the correct song and source. Do: Play a song on buttons and through the microphone on this head, checking the event, its source, and the bound flow flag; also exercise the path on Linux.Checks: they run again on this head (
Guide screenshots / Guide images and local UI source review (pull_request)failed on the last one); a failure shows on the pull request.Also noticed (2; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Unproven: the recorded Windows run confirms that the site and mod start, but did not play a song through the new path. The test game exercises event delivery and flag binding without exercising recognition in the game.
Other systems: The path touches controller reads, microphone streams, the game thread and mod event delivery on Windows and Linux. The recorded Windows run did not exercise song recognition; Linux remains untested.
Switches: None.
Reviewed:
a8050b23baagainst37c16741d7: Read game/crates/game-core/src/ocarina.rs, the repository rules and pull request template; inspected the changed site, host input and microphone paths, API and content diffs, rebased schema and generated documentation changes. The remaining changed files and surrounding callers were not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run the project were executed. The author reports Windows game startup and game-free checks; the actual song playtest remains outstanding.
Overlaps and merge order: The description identifies documentation and test conflicts with #2656 and #2657; later merges need regenerated schema documentation and both tests retained.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
WIP: feat(modapi): songPlayed, and content flags bound to how a song was playedto feat(modapi): songPlayed, and content flags bound to how a song was played