Files
ReSkate/Extension/Music/spotify_web.h
T
AyeZeeBB 86aa8d38fb Music: local files, online radio, equaliser, queue, and a Music page in the menu
Sources
- Local Files: add a folder of music from the setup page (MP3, M4A, AAC, Ogg,
  FLAC, WAV; up to 200 songs a folder, 12 folders). Names and covers come from
  the files' tags. Each folder is a tile in its own row.
- Online Radio: find stations by name (radio-browser.info) or add a stream's
  address (MP3, AAC, .pls, .m3u; no HLS). Each station is a tile in its own
  row; the track name follows what the station sends. Up to 24.
- Both are decoded by the library built into the DLL (SpotifyHelper), which
  now plays files and HTTP streams as well as a program's output, reads tags
  and embedded pictures, and accepts MPEG-2 ADTS from AAC stations.

Sound
- Five-band equaliser (60 Hz, 250 Hz, 1 kHz, 4 kHz, 12 kHz) and loudness
  levelling, applied to every source on its way into the game.
- Loudness, the speakers option, the equaliser and levelling are now kept in
  music-settings.json between sessions.

Setup page
- Remade in the mod's own colours and type, with numbered steps per source.
- Queue pinned to the right: now playing, the playlist's songs with covers,
  find, and press to jump. Spotify's own queue shows once signed in.
- Cards for Local files and Online radio; equaliser and levelling under Sound.

In game
- MUSIC page in the menu: player and queue, sound settings, source status and
  a button for the setup page.
- "Loading song..." notice in the corner for songs that take a moment, with a
  switch to hide it. Presses made while a song is loading no longer restart it.
- The Spotify row is hidden when Spotify is not in use.
- Console: "spotify ..." is now "music ..." (music, music setup, music gain,
  music through, music spotify client|login|logout).

Logs
- The music sources' working lines (traces, per-song and per-bind lines,
  librespot's own) are debug only; stack captures are skipped unless debug
  logging is on. Grind exits: the per-pop line is debug only too.
- A "Pace:" line when the game takes the sound faster or slower than real
  time, to find why music sounds fast after tabbing back in.

Chat filter
- A run of digits is a number, not a word spelled with look-alikes: a race
  time such as 2:55.0 is no longer masked.
2026-10-12 16:03:35 -05:00

56 lines
2.5 KiB
C++

#pragma once
#include <cstdint>
#include <string>
#include <vector>
// The player's Spotify account, through Spotify's Web API: their playlists, for the music
// screen's Spotify row (spotify_station.h), and starting one of them in their Spotify app.
//
// Spotify gives this to an application registered with it, by its client id. ReSkate has
// none of its own built in: the id is a setting ("music spotify client <id>" in the console), of an
// application whose redirect address is http://127.0.0.1:47824/callback. The player signs in
// once in their browser ("music spotify login"); what is kept is the token that renews the sign-in,
// encrypted for their Windows account, in <Local AppData>\ReSkate\spotify.json. Starting a
// playlist needs Spotify Premium (Spotify's rule) and the Spotify app open.
namespace dingosdk::spotify_web {
inline constexpr unsigned short callback_port = 47824;
// The id Liked Songs goes by here (Spotify does not count it among the playlists).
inline constexpr char liked_songs[] = "liked";
struct Track {
std::string artist, title, uri;
};
struct Playlist {
std::string id, name;
std::string artwork; // served by the artwork server (music_artwork.h), or empty
std::vector<Track> tracks; // its first fifty
};
// A song of what Spotify has lined up, with where its album's picture is (Spotify's address).
struct Queued {
std::string artist, title, uri, cover;
};
struct State {
bool has_client{}, signed_in{}, busy{};
std::string user, problem;
std::size_t playlists{};
};
// Reads what was kept and, when the player had signed in, fetches their playlists. Once, on a
// thread of its own, which does everything below.
void start() noexcept;
void set_client(const std::string& id);
std::string client();
void login(); // opens the browser
void logout(); // forgets the sign-in
void refresh(); // fetches the playlists again
// The playlists as last fetched. Any thread.
std::vector<Playlist> playlists();
// Starts a playlist in the player's Spotify app, at one of its tracks when `track` (its
// Spotify address) is given.
void play(const std::string& playlist, const std::string& track = {});
// What Spotify has lined up, as last fetched: the song that is playing, then those after it
// (Spotify tells of twenty or so). Empty when the player has not signed in. `want_queue` has
// it fetched again, no more often than every few seconds unless `now`; any thread.
std::vector<Queued> queue();
void want_queue(bool now = false);
State state();
}