SDL_CDStatus(3)

πŸ’Ώ SDL_CDStatus πŸ’Ώ

okay bestie, this one's from the SDL API Reference β€” it's the lil function that tells you what your CD drive is even doing right now. she's nosy in the best way. πŸŽ€


✨ NAME ✨

SDL_CDStatus β€” Returns the current status of the given drive. that's it, that's the whole job, and she does it flawlessly. πŸ’…


🌸 SYNOPSIS 🌸

#include "SDL.h"

CDstatus SDL_CDStatus(SDL_CD *cdrom); /* Given a status, returns true if
there's a disk in the drive */ #define CD_INDRIVE(status)
((int)status > 0)

like. you hand her a CD drive, she hands you back the vibe check on it. iconic behavior tbh. ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

So this function returns the current status of the given drive. and the status is described like this β€” the whole enum, no gatekeeping:

typedef enum {
  CD_TRAYEMPTY,
  CD_STOPPED,
  CD_PLAYING,
  CD_PAUSED,
  CD_ERROR = -1
} CDstatus;

If the drive has a CD in it, the table of contents of the CD and the current play position of the CD get stored in the SDL_CD structure. so she's not just telling you the tea, she's writing it down for you. 🫢

The macro CD_INDRIVE is provided for convenience, and given a status it returns true if there's a disk in the drive. tiny helper, big main character energy. πŸ‘‘

Note: SDL_CDStatus also updates the SDL_CD structure passed to it. so like, heads up β€” she's mutating your struct while you're not looking. it's fine, it's on purpose, but bestie. be aware. 😭

πŸ”₯ EXAMPLE πŸ”₯

here's the whole thing, copied exactly, no notes:

int playTrack(int track)
{
  int playing = 0;

  if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
  /* clamp to the actual number of tracks on the CD */
    if (track >= cdrom->numtracks) {
      track = cdrom->numtracks-1;
    }

    if ( SDL_CDPlayTracks(cdrom, track, 0, 1, 0) == 0 ) {
      playing = 1;
    }
  }
  return playing;
}

look at her. checks the drive, clamps the track so you don't go asking for track 99 on a 12-track CD, plays the thing, tells you if it worked. that's a complete thought. we love a function that finishes what it starts. 🌈


πŸ‘€ SEE ALSO πŸ‘€

  • SDL_CD β€” the structure she keeps updating behind your back. go read up, iykyk. πŸ’œ

k bye ily, go check ur drives πŸ’–

this has been your girl from the SDL crew β€” page dated Tue 11 Sep 2001, 22:58, so yeah, vintage, retro, archival even. still serving. periodt. πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from