Developers
Architecture
How the game is put together: the show runner, the media bridge, charts, timing, controllers, free songs and updates.
On this page
- The show runner (game/src/Main.cs)
- Media bridge (game/src/Bridge/)
- Songs and charts
- Learn audio
- Threads
- Timing
- Controllers (game/src/Main.Controllers.cs, game/src/Game/)
- Discover (game/src/Main.Market.cs)
- Links from the website (game/src/Platform/, game/src/Main.DeepLink.cs)
- Free songs (game/src/Catalog/, game/src/Main.Local.cs)
- Updates (game/src/Update/)
- Platform seams
The show runner (game/src/Main.cs)#
flowchart TD
Menu["Main menu"]
Learning["Learning: rewind, then listen"]
Analyzing["Analyzing: chart the audio"]
Setlist["Setlist"]
Part["Part: instrument, then difficulty"]
Cue["Cue: wait for the app to play the song"]
Intro["Intro: pause, count in, play"]
Playing["Playing"]
Paused["Paused"]
Results["Results"]
Other["Discover, Settings, Binding"]
Menu -- LEARN --> Learning
Learning --> Analyzing
Analyzing --> Menu
Menu -- PLAY --> Part
Menu --> Setlist
Setlist -- "pick a song" --> Part
Setlist -- "RE-LEARN" --> Cue
Part -- "song already playing" --> Intro
Part -- "anything else" --> Cue
Cue -- "to play" --> Intro
Cue -- "to re-learn" --> Learning
Intro --> Playing
Playing <--> Paused
Playing --> Results
Results -- "PLAY AGAIN" --> Intro
Results -- "CHANGE PART" --> Part
Menu --> Other
Nothing happens to the music app unless the player picks something from a menu.
-
Which app: the media bridge follows one session at a time (see below). From the moment a song is picked until the game is back at the menu, the bridge is locked to the app playing it, so another app starting up can't take over mid-song.
-
Unusable timelines: if the session reports no usable song position (
MediaSnapshot.TimelineOkis false), LEARN and PLAY are disabled with an explanation, and a learn pass in progress is cancelled. -
Learning: first rewinds to 0:00 if the song is more than ~3.5s in (see
RestartAsyncbelow) and presses play if needed. It aborts if the app pauses for more than a second, because WASAPI loopback stops delivering buffers while nothing renders, which would make the audio's timeline wrong. The end of the song, a track change or a stop finish learning, as long as at least 90% of the song was heard. -
Cue: SMTC can't choose a track, so the player starts the picked song in their app, and the show begins as soon as any app reports it.
-
Part: player 1 picks an instrument, then a difficulty; the last pick is offered first. A part that can't be played says why instead of starting (
PartState): the game can't play it yet (vocals), the chart predates that part (re-learning adds it), or nothing was heard for it. -
Intro stages:
sequenceDiagram participant G as Riffover participant A as Music app (SMTC) G->>A: restart if underway, then pause A-->>G: Paused, held for 350 ms Note over G: crowd roar, four clicks at the song's tempo, notes already scrolling G->>A: play, sent the app's start delay before the downbeat A-->>G: Playing Note over G: Playing: SMTC readings correct the song clock- Pausing: restart the track if it's underway, send pause, and wait until the snapshot shows Paused for 350ms. If it never pauses, the game jumps into Playing live, with no count-in.
- Counting: crowd roar, then four clicks at the chart's local beat length. The song clock runs from
resumePos - countInLength, so notes scroll in before the song starts. - Starting: play is sent the app's start delay (
Settings.PlayLatencyFor(app)) before the downbeat. Once the app reports Playing, control goes to Playing, and SMTC readings start correcting the clock.
-
Playing: a pause from the app itself (or a headset button) opens the pause menu; so does the window losing focus.
-
Results: the game pauses the app at the end, so autoplay doesn't roll into the next track behind the score screen. If your hits were consistently early or late, FIX MY TIMING shifts the audio offset by that much.
Media bridge (game/src/Bridge/)#
WindowsMediaBridge reads Windows' System Media Transport Controls. Session choice:
flowchart TD
Locked{"Locked to an app for this song? (LockedAppId)"}
Pinned{"App pinned in Settings? (PinnedPlayerAppId)"}
Current{"Windows has a current session?"}
Any{"Any session playing?"}
UseLocked["That app's session, or none"]
UsePinned["That app's session, or none"]
UseCurrent["Windows' current session"]
UsePlaying["The first playing session"]
UseAny["Any session, or none"]
Locked -- yes --> UseLocked
Locked -- no --> Pinned
Pinned -- yes --> UsePinned
Pinned -- no --> Current
Current -- yes --> UseCurrent
Current -- no --> Any
Any -- yes --> UsePlaying
Any -- no --> UseAny
A locked or pinned app that isn't open means no session, not a fallback to another app. When the pinned app is missing, the main menu offers USE ANY APP to go back to following whatever's playing.
The session list refreshes on SessionsChanged / CurrentSessionChanged, with a slow poll as a safety net.
- Timeline check (
TimelineCheck): flags a session when it reports no length, when its position stamp isn't refreshed after playback starts, when it restamps but the position barely moves, or when extrapolating runs far past the end. Browser players often do one of these. - App names (
PlayerApps): turnsSourceAppUserModelIdinto the name Windows gives the app (WindowsAppNames: a packaged app's display name viaAppInfo, or an exe's product name from its version resource; else a cleaned-up id) and a stable key for per-app settings (the exe or package name, lowercased). Riffover keeps no list of apps or brands. - Restart (
RestartAsync): seek to 0 if the app allows it and check that it landed; otherwise send Previous. Most apps restart the song once it's a few seconds in; if the title changes instead (it went back a track), send Next to get back to the song from the top. True only when the same track ends up near 0:00.
Songs and charts#
Charts and scores are keyed by song, not by app: TrackKeys.Make gives normalized artist + title + length in seconds ("queen|bohemian rhapsody|355"). Normalization folds case, Unicode forms, curly quotes, dashes and whitespace. SongLibrary.Find matches artist and title exactly (after normalization) and lengths within 2s, since apps often disagree by a second; Main.KeyOf resolves every snapshot through it. Charts and scores saved under the older "Artist — Title" key are migrated when the library is scanned.
SongLibrary.Scan lists learned and downloaded charts from user://charts and imported community charts from user://imported, keeping one chart per song (SongLibrary.Dedupe). Imported charts also match within 10s of length, and on artist and title alone when they don't know their length. The import scanner (game/src/Charts/Import/ImportScanner.cs) runs on the thread pool at startup and on Rescan, and Main.TickImport refreshes the setlist when it finishes. See importing charts.
Learn audio#
WasapiLoopbackRecorder captures the now-playing app's process tree (found by exe name, or by package app id for Store apps), falling back to the whole system mix. It downmixes to mono floats in memory (MonoAccumulator → LearnClip); no audio is written to disk. When the song ends, LearnRunner passes the clip to ChartGenerator (game/src/Charts/Learn/, engine-free; the only charter, tuned with tools/eval) and writes the chart through a temp file and a rename, so a crash never leaves half a chart. Startup sweeps WAVs older builds left in %TEMP%\Riffover\learn\, %TEMP%\Overdub\learn\ (before the rename to Riffover) and user://recordings.
Settings.KeepRecordings is a dev flag, off by default and not shown in the settings menu: set "keepRecordings": true in settings.json and each pass's audio is also saved to %TEMP%\Riffover\recordings\, for debugging the chart generator.
Threads#
| Thread | What runs there |
|---|---|
| Godot main | Everything in Main, Judge, StageScene, Crowd, Hud |
| Bridge poller | WindowsMediaBridge polls SMTC every 50ms and publishes immutable MediaSnapshots |
| WinRT/thread pool | play, pause, skip and seek commands; RestartAsync |
| NAudio capture | WasapiLoopbackRecorder.OnDataAvailable appends to the in-memory clip under a lock |
| Learn task | LearnRunner runs ChartGenerator in a Task (it parallelizes the heavy DSP internally); Main polls IsCompleted each frame |
| Catalog | SongCatalog fetches the catalog and downloads songs on the thread pool; finished downloads are queued for Main, which registers their charts |
| Import | ImportScanner walks the songs folders and converts new or changed charts in a Task; Main polls it each frame |
Timing#
- Input events are timestamped with
Time.GetTicksUsec()when they arrive (Input.UseAccumulatedInput = false, agile event flushing on), so judging isn't quantized to the frame rate. - Song time at an input =
SongClock.PositionAt(eventTime) - AudioOffsetMs. - Hit windows by Settings → Timing window: Relaxed ±130ms (perfect ±55), Standard ±100ms (±45), Strict ±75ms (±35).
Controllers (game/src/Main.Controllers.cs, game/src/Game/)#
Controls turns keyboard and joypad input into timestamped play inputs. Xbox 360 guitars come through Godot as XInput joypads; Xbox One and Series guitars are read through Windows.Gaming.Input (XboxOneGuitars), with tilt and whammy from GameInput (GuitarExtras). Anything else is mapped once in the binding wizard.
Every half second the game lists what it can see (those guitars plus every joypad Godot reports) for the controller pill on the menus: NO CONTROLLER · KEYBOARD READY, or GUITAR · <name> / CONTROLLER · <name> with +N for extras. The pill lights up while a controller is sending input, so a connected-but-silent controller is easy to spot. Plugging one in or pulling it out shows a toast.
Discover (game/src/Main.Market.cs)#
DISCOVER browses the songs from the player's sources: Riffover's own source today, others later. In code it's still Phase.Market. Four tabs. Free songs is live (below). The other three show the planned shape of player-shared charts and are marked as coming soon: for your setlist and top rated (empty, with a description), and Your charts, your own learned songs shown the way they'd be listed. Typing searches the tab (every word must match the title or artist), the mouse wheel scrolls it, and Esc clears the search before it leaves.
Links from the website (game/src/Platform/, game/src/Main.DeepLink.cs)#
The website's Open in Riffover buttons are riffover://song/<catalog id> and riffover://community/<submission id> links. DeepLink.TryParse accepts only those two shapes (lowercase ids, no query, fragment, port or escapes). The installer registers the protocol for the user (HKCU\Software\Classes\riffover, removed on uninstall), and exported builds re-register at startup when the keys are missing or point at another exe (UrlProtocol). Windows starts a second copy with the link; SingleInstance hands it to the running copy over a per-user named pipe and quits, and the running copy comes to the front.
A link opens the song in DISCOVER's FREE SONGS tab with a confirm on its card (title, artist, size, license, and "Creative Commons: free to download and keep" for CC, CC0 and public-domain licenses, judged from the license id only). Nothing downloads until the player presses Enter. A community song is fetched from the website's /discover/<id>/entry, a source-protocol Song with short-lived signed file URLs (SourceSong.Parse), then installed like a catalog song with the same size and SHA-256 checks; the URLs are refetched if they're over 3 minutes old when the download starts, and never saved.
To try it against a local site, start the game with -- --site=http://localhost:3101 (development builds only; exported builds always use riffover.com).
Free songs (game/src/Catalog/, game/src/Main.Local.cs)#
The catalog only lists free, openly licensed songs (CC0, CC BY, CC BY-SA, MIT; see catalog sources), so the audio can ship with the chart. It's served from R2 at content.riffover.com (see tools/catalog for the layout and publishing).
sequenceDiagram
participant G as Riffover
participant C as content.riffover.com
G->>C: GET catalog/v1/catalog.json (on opening DISCOVER, at most every 5 min)
C-->>G: songs: title, artist, license, credit, files with size and SHA-256
Note over G: saved to user://catalog/catalog.json for offline use
G->>C: GET each file of the picked song
Note over G: .part file, check size and SHA-256, move into user://songs/<id>/
Note over G: installed.json written last, chart.mid converted into user://charts
- Install (
SongCatalog): one download at a time, others queue; cancellable; progress shows on the listing.CatalogIndex.Parsedrops entries with unsafe ids or file names, missing song or chart files, or bad sizes and hashes. A song counts as installed only when itsinstalled.jsonis there and every file it lists exists. - Chart (
MidiChart): the song'snotes.mid(notes 60-64 Easy, 72-76 Medium, 84-88 Hard, 96-100 Expert) becomes a version 2 chart with a guitar part, the beat grid from the MIDI tempo map, and provenanceauthored, author "Frets on Fire pack" (or, when the catalog entry'schart.originisgenerated, provenancegeneratedwith the charter id and version it lists: songs without a hand-made chart are charted ahead of time bytools/chartgen),source.app"Riffover catalog",listingIdthe song id. Notes held a third of a beat or less are plain notes. Only the difficulties the file has are written; a missing one plays the nearest (Chart.NotesFor). It's keyed like any song (artist + title + length), so setlist, part select and scores need nothing special. - Generate (
OggMix, NVorbis):F5in DISCOVER (or RE-LEARN/F5 on the setlist, GENERATE CHART on results) decodes the backing track and guitar stem, mixes them to mono and runs the normalLearnRunner, replacing the song's own chart with a fresh one (guitar and drums).F5again puts the song's own chart back. Scores are kept either way. This doubles as a test bed for the charter against hand-made charts. - Play (
LocalAudioBridge,SwitchableBridge):Main._bridgeis aSwitchableBridgeover the Windows bridge and the in-game player. Starting a downloaded song loads it into the player (paused at 0:00), pauses the music app if it's playing, and switches every read and command to the player, so the music app can't change the song underneath. The intro then runs unchanged: pause, seek, count in, play. The play command goes out the audio output latency before the downbeat instead of the app's start delay. Going to the main menu, setlist or DISCOVER unloads it and switches back. - Position: both stems play through one
AudioStreamSynchronized, so they start, seek and stop on the same audio frame. Position isGetPlaybackPosition() + GetTimeSinceLastMix() - GetOutputLatency(), fresh every frame; measured againstSongClockit stays within about 12 ms, under its 30 ms deadband, so the clock rarely corrects. Commands from worker threads (the intro's restart and pause) are queued for the main thread; Godot's audio nodes belong to it. - Misses: the guitar stem ducks to -30 dB on a miss or overstrum and comes back on the next hit.
- Credit: the song's credit line (CC BY-SA asks for attribution) is on its listing, the intro and the results screen; the setlist shows its license.
Updates (game/src/Update/)#
Dev builds know which build they are from res://build_info.json, which the Dev build workflow writes before exporting (BuildInfo). A local or editor build has no such file and never checks for updates.
sequenceDiagram
participant W as Dev build workflow
participant R as GitHub dev release
participant G as Riffover
participant S as riffover.com/download
W->>R: upload RiffoverSetup.exe and the portable zip
W->>R: upload latest.json last
G->>R: GET latest.json at launch, then every 4 hours
R-->>G: build number, installer URL, size, SHA-256
Note over G: newer build: main menu shows UPDATE
G->>R: download RiffoverSetup.exe, check its SHA-256
Note over G: run it with /SILENT and quit, the installer starts the new build
S->>R: GET latest.json, cached about a minute
Updatercompares the manifest's build number (the workflow's run number) with its own. The check is one GET with nothing sent.- Only copies installed by the installer update in place (
unins000.exenext to the game). The portable zip's UPDATE entry opens the download page instead. - The installer (
tools/installer/riffover.iss, Inno Setup) installs per user to%LOCALAPPDATA%\Programs\Riffover, replaces the old build's data folder on update, and never touches%APPDATA%\Godot\app_userdata\Riffover, so songs, scores and settings survive updates and uninstalls.
Platform seams#
IMediaBridge and IAudioRecorder are the only OS-specific pieces. Everything else is plain Godot and C#. Non-Windows builds compile with null implementations, so the game boots anywhere and just can't see a music app.
- macOS: the system now-playing info for position and control, and ScreenCaptureKit to capture the now-playing app's audio. Since macOS 15.4 reading other apps' now-playing info needs an entitlement, so this needs research.
- Linux: MPRIS over D-Bus for position and control (already player-agnostic), and a PipeWire monitor of the player's stream for capture.