libcdio  2.1.0
About: GNU libcdio is a library for CD-ROM and CD image access.
  Fossies Dox: libcdio-2.1.0.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

cdda-player.c File Reference
#include <signal.h>
#include <term.h>
#include <cdio/cdio.h>
#include <cdio/mmc.h>
#include <cdio/util.h>
#include <cdio/cd_types.h>
#include <cdio/logging.h>
#include "cddb.h"
#include "getopt.h"
Include dependency graph for cdda-player.c:

Go to the source code of this file.

Data Structures

struct  cd_track_info_rec_t
 

Macros

#define MAX_KEY_STR   50
 
#define UNUSED(x)   (void)(x)
 
#define add_cdtext_disc_info(format_str, info_field, FIELD)
 
#define add_cdtext_track_info(format_str, info_field, FIELD)
 
#define display_line(LINE_NO, COL_NO, format_str, field)
 
#define ENCODING_TRICKS
 

Enumerations

enum  track_line_t {
  LINE_STATUS = 0, LINE_CDINFO = 1, LINE_ARTIST = 3, LINE_CDNAME = 4,
  LINE_GENRE = 5, LINE_YEAR = 6, LINE_TRACK_PREV = 8, LINE_TRACK_TITLE = 9,
  LINE_TRACK_ARTIST = 10, LINE_TRACK_NEXT = 11
}
 
enum  cd_operation_t {
  NO_OP =0, PLAY_CD =1, PLAY_TRACK =2, STOP_PLAYING =3,
  EJECT_CD =4, CLOSE_CD =5, SET_VOLUME =6, LIST_SUBCHANNEL =7,
  LIST_KEYS =8, LIST_TRACKS =9, PS_LIST_TRACKS =10, TOGGLE_PAUSE =11,
  EXIT_PROGRAM =12
}
 

Functions

static void action (const char *psz_action)
 
static void display_cdinfo (CdIo_t *p_cdio, track_t i_tracks, track_t i_first_track)
 
static void display_tracks (void)
 
static void get_cddb_track_info (track_t i_track)
 
static void get_cdtext_track_info (track_t i_track)
 
static void get_track_info (track_t i_track)
 
static bool play_track (track_t t1, track_t t2)
 
static int rounded_div (unsigned int i_a, unsigned int i_b)
 
static void tty_raw (void)
 
static void tty_restore (void)
 
static void sigwinch (int dummy)
 
static void ctrlc (int signal_num)
 
static int select_wait (int sec)
 
static void xperror (const char *psz_msg)
 
static void finish (const char *psz_msg, int rc)
 
static bool set_volume_level (CdIo_t *p_cdio, uint8_t i_level)
 
static bool decrease_volume_level (CdIo_t *p_cdio)
 
static bool increase_volume_level (CdIo_t *p_cdio)
 
static bool cd_stop (CdIo_t *p_cdio)
 
static bool cd_eject (void)
 
static bool cd_close (const char *psz_device)
 
static bool cd_pause (CdIo_t *p_cdio)
 
static bool read_subchannel (CdIo_t *p_cdio)
 
static void get_cddb_disc_info (CdIo_t *p_cdio)
 
static void get_cdtext_disc_info (CdIo_t *p_cdio)
 
static void get_disc_info (CdIo_t *p_cdio)
 
static void read_toc (CdIo_t *p_cdio)
 
static void skip (int diff)
 
static bool toggle_pause (void)
 
static void display_status (bool b_status_only)
 
static void usage (char *prog)
 
static void print_keys (void)
 
static void keypress_wait (CdIo_t *p_cdio)
 
static void list_keys (void)
 
static void ps_list_tracks (void)
 
static void list_tracks (void)
 
int main (int argc, char *argv[])
 

Variables

TERMINAL * cur_term
 
static WINDOW * cur_window = NULL
 
static CdIo_tp_cdio_global
 
static driver_id_t driver_id = DRIVER_DEVICE
 
static int b_sig = false
 
static track_t i_first_track_global
 
static track_t i_last_track
 
static track_t i_first_audio_track
 
static track_t i_last_audio_track
 
static track_t i_last_display_track = CDIO_INVALID_TRACK
 
static track_t i_tracks_global
 
static msf_t toc [CDIO_CDROM_LEADOUT_TRACK+1]
 
static cdio_subchannel_t sub
 
static int i_data
 
static int start_track = 0
 
static int stop_track = 0
 
static int one_track = 0
 
static int i_vol_port = 5
 
static bool b_cd = false
 
static bool auto_mode = false
 
static bool b_verbose = false
 
static bool debug = false
 
static bool b_interactive = true
 
static bool b_prefer_cdtext = true
 
static bool b_db = false
 
static bool b_record = false
 
static bool b_all_tracks = false
 
static int8_t i_volume_level = -1
 
static char * psz_device_global =NULL
 
static char * psz_program
 
static cd_track_info_rec_t cd_info [CDIO_CD_MAX_TRACKS+2]
 
static char title [80]
 
static char artist [80]
 
static char genre [40]
 
static char category [40]
 
static char year [5]
 
static bool b_cdtext_title
 
static bool b_cdtext_artist
 
static bool b_cdtext_genre
 
static bool b_cdtext_year
 
static cdio_audio_volume_t audio_volume
 
static const char key_bindings [][50]
 
static const unsigned int i_key_bindings = sizeof(key_bindings) / 50
 
static unsigned int LINE_ACTION = 25
 
static unsigned int COLS_LAST
 
static char psz_action_line [300] = ""
 

Macro Definition Documentation

◆ add_cdtext_disc_info

#define add_cdtext_disc_info (   format_str,
  info_field,
  FIELD 
)
Value:
if (cdtext_get_const(p_cdtext, FIELD, 0) && !strlen(info_field)) { \
snprintf(info_field, sizeof(info_field), format_str, \
cdtext_get_const(p_cdtext, FIELD, 0)); \
b_cdtext_ ## info_field = true; \
}

Definition at line 555 of file cdda-player.c.

◆ add_cdtext_track_info

#define add_cdtext_track_info (   format_str,
  info_field,
  FIELD 
)
Value:
if (cdtext_get_const(p_cdtext, FIELD, i_track)) { \
snprintf(cd_info[i_track].info_field, \
sizeof(cd_info[i_track].info_field), \
format_str, cdtext_get_const(p_cdtext, FIELD, i_track)); \
cd_info[i_track].b_cdtext = true; \
}

Definition at line 852 of file cdda-player.c.

◆ display_line

#define display_line (   LINE_NO,
  COL_NO,
  format_str,
  field 
)
Value:
if (field != NULL && field[0]) { \
mvprintw(LINE_NO, COL_NO, (char *) format_str " [%s]", \
field, \
b_cdtext_ ## field ? "CD-Text": "CDDB"); \
clrtoeol(); \
}

Definition at line 886 of file cdda-player.c.

◆ ENCODING_TRICKS

#define ENCODING_TRICKS

Definition at line 1045 of file cdda-player.c.

◆ MAX_KEY_STR

#define MAX_KEY_STR   50

Definition at line 171 of file cdda-player.c.

◆ UNUSED

#define UNUSED (   x)    (void)(x)

Definition at line 250 of file cdda-player.c.

Enumeration Type Documentation

◆ cd_operation_t

Enumerator
NO_OP 
PLAY_CD 
PLAY_TRACK 
STOP_PLAYING 
EJECT_CD 
CLOSE_CD 
SET_VOLUME 
LIST_SUBCHANNEL 
LIST_KEYS 
LIST_TRACKS 
PS_LIST_TRACKS 
TOGGLE_PAUSE 
EXIT_PROGRAM 

Definition at line 1385 of file cdda-player.c.

◆ track_line_t

Enumerator
LINE_STATUS 
LINE_CDINFO 
LINE_ARTIST 
LINE_CDNAME 
LINE_GENRE 
LINE_YEAR 
LINE_TRACK_PREV 
LINE_TRACK_TITLE 
LINE_TRACK_ARTIST 
LINE_TRACK_NEXT 

Definition at line 198 of file cdda-player.c.

Function Documentation

◆ action()

static void action ( const char *  psz_action)
static

◆ cd_close()

static bool cd_close ( const char *  psz_device)
static

Close CD tray

Definition at line 470 of file cdda-player.c.

References action(), b_cd, cdio_close_tray(), driver_id, DRIVER_OP_SUCCESS, and xperror().

Referenced by main().

◆ cd_eject()

static bool cd_eject ( void  )
static

Eject CD

Definition at line 452 of file cdda-player.c.

References action(), b_cd, cd_stop(), cdio_destroy(), cdio_eject_media(), DRIVER_OP_SUCCESS, NULL, p_cdio_global, and xperror().

Referenced by main(), and read_subchannel().

◆ cd_pause()

static bool cd_pause ( CdIo_t p_cdio)
static

Pause playing audio CD

Definition at line 484 of file cdda-player.c.

References cdio_subchannel_s::audio_status, cdio_audio_pause(), CDIO_MMC_READ_SUB_ST_PLAY, DRIVER_OP_SUCCESS, sub, and xperror().

Referenced by play_track(), and skip().

◆ cd_stop()

static bool cd_stop ( CdIo_t p_cdio)
static

Stop playing audio CD

Definition at line 436 of file cdda-player.c.

References action(), b_all_tracks, b_cd, cdio_audio_stop(), CDIO_INVALID_TRACK, display_tracks(), DRIVER_OP_SUCCESS, i_last_audio_track, and xperror().

Referenced by cd_eject(), and main().

◆ ctrlc()

static void ctrlc ( int  signal_num)
static

Definition at line 263 of file cdda-player.c.

References b_sig.

Referenced by main().

◆ decrease_volume_level()

static bool decrease_volume_level ( CdIo_t p_cdio)
static

Definition at line 404 of file cdda-player.c.

References i_volume_level, and set_volume_level().

Referenced by main().

◆ display_cdinfo()

static void display_cdinfo ( CdIo_t p_cdio,
track_t  i_tracks,
track_t  i_first_track 
)
static

◆ display_status()

◆ display_tracks()

◆ finish()

static void finish ( const char *  psz_msg,
int  rc 
)
static

◆ get_cddb_disc_info()

static void get_cddb_disc_info ( CdIo_t p_cdio)
static

Definition at line 538 of file cdda-player.c.

References artist, b_db, genre, i_first_track_global, i_tracks_global, title, xperror(), and year.

Referenced by get_disc_info().

◆ get_cddb_track_info()

static void get_cddb_track_info ( track_t  i_track)
static

Definition at line 837 of file cdda-player.c.

References artist, i_first_track_global, and title.

Referenced by get_track_info().

◆ get_cdtext_disc_info()

static void get_cdtext_disc_info ( CdIo_t p_cdio)
static

◆ get_cdtext_track_info()

static void get_cdtext_track_info ( track_t  i_track)
static

◆ get_disc_info()

static void get_disc_info ( CdIo_t p_cdio)
static

Definition at line 575 of file cdda-player.c.

References b_db, b_prefer_cdtext, get_cddb_disc_info(), and get_cdtext_disc_info().

Referenced by read_toc().

◆ get_track_info()

static void get_track_info ( track_t  i_track)
static

Definition at line 874 of file cdda-player.c.

References b_prefer_cdtext, get_cddb_track_info(), and get_cdtext_track_info().

Referenced by read_toc().

◆ increase_volume_level()

static bool increase_volume_level ( CdIo_t p_cdio)
static

Definition at line 426 of file cdda-player.c.

References i_volume_level, and set_volume_level().

Referenced by main().

◆ keypress_wait()

static void keypress_wait ( CdIo_t p_cdio)
static

◆ list_keys()

static void list_keys ( void  )
static

Definition at line 992 of file cdda-player.c.

References i, i_key_bindings, key_bindings, keypress_wait(), LINE_TRACK_PREV, and p_cdio_global.

Referenced by main().

◆ list_tracks()

static void list_tracks ( void  )
static

Definition at line 1369 of file cdda-player.c.

References artist, b_record, cd_info, cdio_audio_get_msf_seconds(), i, i_first_track_global, i_last_track, title, and toc.

Referenced by main().

◆ main()

◆ play_track()

static bool play_track ( track_t  i_start_track,
track_t  i_end_track 
)
static

◆ print_keys()

static void print_keys ( void  )
static

Definition at line 968 of file cdda-player.c.

References i, i_key_bindings, and key_bindings.

Referenced by main().

◆ ps_list_tracks()

static void ps_list_tracks ( void  )
static

◆ read_subchannel()

static bool read_subchannel ( CdIo_t p_cdio)
static

◆ read_toc()

◆ rounded_div()

static int rounded_div ( unsigned int  i_a,
unsigned int  i_b 
)
static

Definition at line 218 of file cdda-player.c.

Referenced by display_status(), and set_volume_level().

◆ select_wait()

static int select_wait ( int  sec)
static

Definition at line 270 of file cdda-player.c.

References NULL.

Referenced by keypress_wait(), main(), and xperror().

◆ set_volume_level()

static bool set_volume_level ( CdIo_t p_cdio,
uint8_t  i_level 
)
static

◆ sigwinch()

static void sigwinch ( int  dummy)
static

Definition at line 253 of file cdda-player.c.

References action(), NULL, tty_raw(), tty_restore(), and UNUSED.

Referenced by main().

◆ skip()

◆ toggle_pause()

static bool toggle_pause ( void  )
static

◆ tty_raw()

static void tty_raw ( void  )
static

Curses window initialization.

Definition at line 226 of file cdda-player.c.

References b_interactive, COLS_LAST, cur_window, and LINE_ACTION.

Referenced by main(), and sigwinch().

◆ tty_restore()

static void tty_restore ( void  )
static

Curses window finalization.

Definition at line 244 of file cdda-player.c.

References b_interactive.

Referenced by finish(), main(), and sigwinch().

◆ usage()

static void usage ( char *  prog)
static

Definition at line 926 of file cdda-player.c.

Referenced by main().

◆ xperror()

static void xperror ( const char *  psz_msg)
static

Variable Documentation

◆ artist

◆ audio_volume

cdio_audio_volume_t audio_volume
static

Definition at line 163 of file cdda-player.c.

Referenced by display_status(), read_toc(), and set_volume_level().

◆ auto_mode

bool auto_mode = false
static

Definition at line 118 of file cdda-player.c.

Referenced by display_status(), main(), read_subchannel(), and read_toc().

◆ b_all_tracks

bool b_all_tracks = false
static

Definition at line 129 of file cdda-player.c.

Referenced by cd_stop(), display_status(), keypress_wait(), main(), and read_toc().

◆ b_cd

◆ b_cdtext_artist

bool b_cdtext_artist
static

Definition at line 156 of file cdda-player.c.

◆ b_cdtext_genre

bool b_cdtext_genre
static

Definition at line 157 of file cdda-player.c.

◆ b_cdtext_title

bool b_cdtext_title
static

Definition at line 155 of file cdda-player.c.

◆ b_cdtext_year

bool b_cdtext_year
static

Definition at line 161 of file cdda-player.c.

◆ b_db

bool b_db = false
static

Definition at line 126 of file cdda-player.c.

Referenced by display_status(), get_cddb_disc_info(), and get_disc_info().

◆ b_interactive

bool b_interactive = true
static

◆ b_prefer_cdtext

bool b_prefer_cdtext = true
static

Definition at line 122 of file cdda-player.c.

Referenced by get_disc_info(), and get_track_info().

◆ b_record

bool b_record = false
static

Definition at line 127 of file cdda-player.c.

Referenced by display_tracks(), list_tracks(), main(), ps_list_tracks(), and read_toc().

◆ b_sig

int b_sig = false
static

Definition at line 95 of file cdda-player.c.

Referenced by ctrlc(), and main().

◆ b_verbose

bool b_verbose = false
static

Definition at line 119 of file cdda-player.c.

Referenced by action(), main(), and xperror().

◆ category

char category[40]
static

Definition at line 152 of file cdda-player.c.

Referenced by read_toc().

◆ cd_info

◆ COLS_LAST

unsigned int COLS_LAST
static

Definition at line 215 of file cdda-player.c.

Referenced by tty_raw().

◆ cur_term

TERMINAL* cur_term

Referenced by finish().

◆ cur_window

WINDOW* cur_window = NULL
static

Definition at line 83 of file cdda-player.c.

Referenced by finish(), and tty_raw().

◆ debug

bool debug = false
static

Definition at line 120 of file cdda-player.c.

Referenced by main(), and play_track().

◆ driver_id

◆ genre

char genre[40]
static

◆ i_data

int i_data
static

Definition at line 106 of file cdda-player.c.

Referenced by cdtext_data_init(), display_cdinfo(), and read_toc().

◆ i_first_audio_track

track_t i_first_audio_track
static

Definition at line 100 of file cdda-player.c.

Referenced by display_cdinfo(), display_status(), and read_toc().

◆ i_first_track_global

◆ i_key_bindings

const unsigned int i_key_bindings = sizeof(key_bindings) / 50
static

Definition at line 193 of file cdda-player.c.

Referenced by list_keys(), and print_keys().

◆ i_last_audio_track

track_t i_last_audio_track
static

Definition at line 101 of file cdda-player.c.

Referenced by cd_stop(), display_cdinfo(), display_status(), play_track(), read_toc(), and skip().

◆ i_last_display_track

track_t i_last_display_track = CDIO_INVALID_TRACK
static

Definition at line 102 of file cdda-player.c.

Referenced by display_status(), keypress_wait(), main(), and read_toc().

◆ i_last_track

track_t i_last_track
static

◆ i_tracks_global

track_t i_tracks_global
static

Definition at line 103 of file cdda-player.c.

Referenced by get_cddb_disc_info(), keypress_wait(), main(), and read_toc().

◆ i_vol_port

int i_vol_port = 5
static

Definition at line 110 of file cdda-player.c.

Referenced by display_status(), read_toc(), and set_volume_level().

◆ i_volume_level

int8_t i_volume_level = -1
static

Definition at line 130 of file cdda-player.c.

Referenced by decrease_volume_level(), display_status(), increase_volume_level(), and main().

◆ key_bindings

const char key_bindings[][50]
static
Initial value:
= {
" right play / next track",
" left previous track",
" up/down 10 sec forward / back",
" 1-9 jump to track 1-9",
" 0 jump to track 10",
" F1-F20 jump to track 11-30",
" ",
" k, h, ? show this key help",
" l, toggle listing all tracks",
" e eject",
" c close tray",
" p, space pause / resume",
" s stop",
" q, ^C quit",
" x quit and continue playing",
" a toggle auto-mode",
" - decrease volume level",
" + increase volume level",
}

Definition at line 172 of file cdda-player.c.

Referenced by list_keys(), and print_keys().

◆ LINE_ACTION

unsigned int LINE_ACTION = 25
static

Definition at line 214 of file cdda-player.c.

Referenced by action(), finish(), tty_raw(), and xperror().

◆ one_track

int one_track = 0
static

Definition at line 109 of file cdda-player.c.

Referenced by main().

◆ p_cdio_global

◆ psz_action_line

char psz_action_line[300] = ""
static

Definition at line 216 of file cdda-player.c.

Referenced by action().

◆ psz_device_global

char* psz_device_global =NULL
static

Definition at line 133 of file cdda-player.c.

Referenced by display_status(), finish(), and main().

◆ psz_program

char* psz_program
static

Definition at line 134 of file cdda-player.c.

Referenced by main().

◆ start_track

int start_track = 0
static

Definition at line 107 of file cdda-player.c.

Referenced by main().

◆ stop_track

int stop_track = 0
static

Definition at line 108 of file cdda-player.c.

Referenced by main().

◆ sub

◆ title

◆ toc

◆ year

char year[5]
static

Definition at line 153 of file cdda-player.c.

Referenced by display_cdinfo(), get_cddb_disc_info(), and read_toc().

cdtext_get_const
const char * cdtext_get_const(const cdtext_t *p_cdtext, cdtext_field_t field, track_t track)
Definition: cdtext.c:289
NULL
#define NULL
Definition: types.h:184
cd_info
static cd_track_info_rec_t cd_info[CDIO_CD_MAX_TRACKS+2]
Definition: cdda-player.c:147