Coding style...

This commit is contained in:
Jaroslav Kysela 1998-11-27 15:17:45 +00:00
parent fbbaa7239e
commit 8773d373f0
4 changed files with 1827 additions and 1849 deletions

File diff suppressed because it is too large Load diff

View file

@ -27,17 +27,17 @@
char *rc_file(void)
{
static char rc_path[1024];
char *p;
p = getenv("HOME");
if (p) {
sprintf(rc_path, "%s/%s", p, MIXER_RC);
} else {
printf("Error reading HOME env. variable\n");
return NULL;
}
return rc_path;
static char rc_path[1024];
char *p;
p = getenv("HOME");
if (p) {
sprintf(rc_path, "%s/%s", p, MIXER_RC);
} else {
printf("Error reading HOME env. variable\n");
return NULL;
}
return rc_path;
}
void copyright()
@ -47,72 +47,74 @@ void copyright()
void usage()
{
printf("\n"
"Usage: amixer [-c card] [-d dev] device [vol|L:R] [mute|unmute] [rec|norec]\n\n"
" amixer [-p path] -r\tRead %s or <path> settings\n"
" amixer -w\t\tWrite %s settings\n"
" amixer -q ...\t\tQuiet mode\n"
" amixer -h\t\tHelp\n\n"
"Example: amixer line-out 80:50 unmute rec\n\n", rc_file(), rc_file());
printf("\n"
"Usage: amixer [-c card] [-d dev] device [vol|L:R] [mute|unmute] [rec|norec]\n\n"
" amixer [-p path] -r\tRead %s or <path> settings\n"
" amixer -w\t\tWrite %s settings\n"
" amixer -q ...\t\tQuiet mode\n"
" amixer -h\t\tHelp\n\n"
"Example: amixer line-out 80:50 unmute rec\n\n", rc_file(), rc_file());
}
void read_config(Mixer *mix, const char *path)
void read_config(Mixer * mix, const char *path)
{
FILE *rc;
char buf[1024];
int opt1;
int opt2;
int left, right;
int dev;
int count = 0;
int flags;
if ((rc = fopen(path ? path : rc_file(), "r")) == NULL) {
printf("Mixer values not read\n");
return;
}
while (!feof(rc) && fgets(buf, 1024, rc)) {
count++;
if (buf[0] == '\n')
continue;
if (buf[0] == '#' || strlen(buf) == 0)
continue;
if (sscanf(buf, "%d %d:%d %d %d\n", &dev, &left, &right, &opt1, &opt2) != 5) {
printf("WARNING: unable to make out line %d of .rc file -> \"%s\"\n", count, buf);
continue;
FILE *rc;
char buf[1024];
int opt1;
int opt2;
int left, right;
int dev;
int count = 0;
int flags;
if ((rc = fopen(path ? path : rc_file(), "r")) == NULL) {
printf("Mixer values not read\n");
return;
}
flags = 0;
if (opt1) flags |= E_MIXER_MUTE;
if (opt2) flags |= E_MIXER_RECORD;
// Set mixer settings
mix->DeviceSet(dev);
mix->Write(left, right, flags);
}
fclose(rc);
return;
while (!feof(rc) && fgets(buf, 1024, rc)) {
count++;
if (buf[0] == '\n')
continue;
if (buf[0] == '#' || strlen(buf) == 0)
continue;
if (sscanf(buf, "%d %d:%d %d %d\n", &dev, &left, &right, &opt1, &opt2) != 5) {
printf("WARNING: unable to make out line %d of .rc file -> \"%s\"\n", count, buf);
continue;
}
flags = 0;
if (opt1)
flags |= E_MIXER_MUTE;
if (opt2)
flags |= E_MIXER_RECORD;
// Set mixer settings
mix->DeviceSet(dev);
mix->Write(left, right, flags);
}
fclose(rc);
return;
}
void write_config(Mixer *mix)
void write_config(Mixer * mix)
{
FILE *rc;
int32 left, right, flags;
FILE *rc;
int32 left, right, flags;
if ((rc = fopen(rc_file(), "w+")) == NULL) {
printf("Mixer values not written\n");
if ((rc = fopen(rc_file(), "w+")) == NULL) {
printf("Mixer values not written\n");
return;
}
fprintf(rc, "# CLI ALSA mixer settings file. Autogenerated\n"
"# Modify at your own risk :)\n\n");
for (int i = 0; i < mix->NumDevices(); i++) {
mix->DeviceSet(i);
mix->Read(&left, &right, &flags);
fprintf(rc, "%d %d:%d %d %d\n", i, mix->Left(), mix->Right(), flags & E_MIXER_MUTE ? 1 : 0, flags & E_MIXER_RECORD ? 1 : 0);
}
fclose(rc);
return;
}
fprintf(rc, "# CLI ALSA mixer settings file. Autogenerated\n"
"# Modify at your own risk :)\n\n");
for (int i=0; i < mix->NumDevices(); i++) {
mix->DeviceSet(i);
mix->Read(&left, &right, &flags);
fprintf(rc, "%d %d:%d %d %d\n", i, mix->Left(), mix->Right(), flags & E_MIXER_MUTE ? 1 : 0, flags & E_MIXER_RECORD ? 1 : 0);
}
fclose(rc);
return;
}
int main(int argc, char **argv)
@ -123,30 +125,30 @@ int main(int argc, char **argv)
int32 left_dB, right_dB;
int32 cur_left, cur_right, cur_flags;
int count, quiet = 0;
int i,add;
int i, add;
int pathind = 0;
Mixer *the_mixer;
exact = mute = rec = norec = unmute = device_index = left = right = -1;
left_dB = right_dB = -1;
for (add = 0; add + 1 < argc; i++) {
if (!strcmp(argv[add+1],"--help")) {
if (!strcmp(argv[add + 1], "--help")) {
usage();
return 0;
}
if (argv[add+1][0] == '-') {
if (argv[add + 1][0] == '-') {
add++;
if (argv[add][1] == 'c') {
card = snd_card_name(argv[++add]);
if (card < 0) {
fprintf(stderr, "Invalid card: %s\n",argv[2]);
fprintf(stderr, "Invalid card: %s\n", argv[2]);
exit(1);
}
} else if (argv[add][1] == 'd') {
device = atoi(argv[++add]);
if (device < 0 || device > 128) {
fprintf(stderr, "Invalid device: %s\n",argv[2]);
fprintf(stderr, "Invalid device: %s\n", argv[2]);
exit(1);
}
} else if (argv[add][1] == 'h') {
@ -155,80 +157,88 @@ int main(int argc, char **argv)
} else if (argv[add][1] == 'p') {
pathind = ++add;
} else if (argv[add][1] == 'r') {
the_mixer = new Mixer(card,device);
if (the_mixer && the_mixer->Init()) read_config(the_mixer, pathind ? argv[pathind] : (const char *)NULL);
delete the_mixer;
return 0;
the_mixer = new Mixer(card, device);
if (the_mixer && the_mixer->Init())
read_config(the_mixer, pathind ? argv[pathind] : (const char *) NULL);
delete the_mixer;
return 0;
} else if (argv[add][1] == 'w') {
the_mixer = new Mixer(card,device);
if (the_mixer && the_mixer->Init()) write_config(the_mixer);
the_mixer = new Mixer(card, device);
if (the_mixer && the_mixer->Init())
write_config(the_mixer);
delete the_mixer;
return 0;
} else if (argv[add][1] == 'q') {
quiet = 1;
} else {
fprintf(stderr, "Invalid option: %s\n", argv[add]+1);
fprintf(stderr, "Invalid option: %s\n", argv[add] + 1);
return 1;
}
} else {
break;
}
}
for (i=1+add; i < argc; i++) {
if (strcmp(argv[i],"exact")==0) {
}
for (i = 1 + add; i < argc; i++) {
if (strcmp(argv[i], "exact") == 0) {
exact = 1;
} else if (strcmp(argv[i],"mute")==0) {
} else if (strcmp(argv[i], "mute") == 0) {
mute = 1;
} else if (strcmp(argv[i],"unmute")==0) {
} else if (strcmp(argv[i], "unmute") == 0) {
unmute = 1;
} else if (strcmp(argv[i],"rec")==0) {
} else if (strcmp(argv[i], "rec") == 0) {
rec = 1;
} else if (strcmp(argv[i],"norec")==0) {
} else if (strcmp(argv[i], "norec") == 0) {
norec = 1;
} else if (sscanf(argv[i], "%d:%d", &left, &right)==2) {
} else if (sscanf(argv[i], "%d", &left)==1) {
} else if (sscanf(argv[i], "%d:%d", &left, &right) == 2) {
} else if (sscanf(argv[i], "%d", &left) == 1) {
right = left;
} else {
strncpy(device_name, argv[i], sizeof(device_name));
device_name[sizeof(device_name)-1] = 0;
device_name[sizeof(device_name) - 1] = 0;
}
}
Mixer mixer(card,device);
Mixer mixer(card, device);
if (mixer.Init() == false) {
fprintf(stderr, "Failed to open mixer device\n");
return 1;
}
count = mixer.NumDevices();
for (i=0; i < count; i++) {
for (i = 0; i < count; i++) {
mixer.DeviceSet(i);
if (strcasecmp(device_name, mixer.Name())==0)
device_index = i;
if (strcasecmp(device_name, mixer.Name()) == 0)
device_index = i;
}
if ( !quiet )
if (!quiet)
copyright();
if (device_index >= 0) {
mixer.DeviceSet(device_index);
mixer.Read(&cur_left, &cur_right, &cur_flags);
if (left >= 0) cur_left = left;
if (right >= 0) cur_right = right;
if (rec == 1) cur_flags |= E_MIXER_RECORD;
else if (norec == 1) cur_flags &= ~E_MIXER_RECORD;
if (mute == 1) cur_flags |= E_MIXER_MUTE;
else if (unmute == 1) cur_flags &= ~E_MIXER_MUTE;
if (left >= 0)
cur_left = left;
if (right >= 0)
cur_right = right;
if (rec == 1)
cur_flags |= E_MIXER_RECORD;
else if (norec == 1)
cur_flags &= ~E_MIXER_RECORD;
if (mute == 1)
cur_flags |= E_MIXER_MUTE;
else if (unmute == 1)
cur_flags &= ~E_MIXER_MUTE;
if (left != -1 || rec != -1 || norec != -1 || mute != -1 || unmute != -1) {
mixer.Write(cur_left, cur_right, cur_flags);
}
if ( !quiet ) {
if (!quiet) {
printf("%-16s", mixer.Name());
mixer.Read(&left, &right, &flags);
mixer.Read_dB(&left_dB, &right_dB);
printf("%-3d%% (%6.2fdB) : %-3d%% (%6.2fdB) %s %s\n\n",
left, ((float)left_dB) / 100.0,
right, ((float)right_dB) / 100.0,
(flags & E_MIXER_MUTE) ? "Mute" : " ",
(flags & E_MIXER_RECORD) ? "Rec" : " " );
left, ((float) left_dB) / 100.0,
right, ((float) right_dB) / 100.0,
(flags & E_MIXER_MUTE) ? "Mute" : " ",
(flags & E_MIXER_RECORD) ? "Rec" : " ");
}
} else {
if (quiet) {
@ -236,19 +246,19 @@ int main(int argc, char **argv)
return 1;
}
if (strlen(device_name))
printf("Device not found: %s\n\n", device_name);
for (i=0; i < count; i++) {
printf("Device not found: %s\n\n", device_name);
for (i = 0; i < count; i++) {
mixer.DeviceSet(i);
printf("%-16s", mixer.Name());
mixer.Read(&left, &right, &flags);
mixer.Read_dB(&left_dB, &right_dB);
printf("%-3d%% (%6.2fdB) : %-3d%% (%6.2fdB) %s %s\n",
left, ((float)left_dB)/100.0, right, ((float)right_dB)/100.0,
printf("%-3d%% (%6.2fdB) : %-3d%% (%6.2fdB) %s %s\n",
left, ((float) left_dB) / 100.0, right, ((float) right_dB) / 100.0,
(flags & E_MIXER_MUTE) ? "Mute" : " ",
(flags & E_MIXER_RECORD) ? "Rec" : " ");
}
return 0;
}
return 0;
}

File diff suppressed because it is too large Load diff

View file

@ -17,33 +17,33 @@
((u_long)(bp->datalen_h) << 16) )
typedef struct voc_header {
u_char magic[20]; /* must be MAGIC_STRING */
u_short headerlen; /* Headerlength, should be 0x1A */
u_short version; /* VOC-file version */
u_short coded_ver; /* 0x1233-version */
u_char magic[20]; /* must be MAGIC_STRING */
u_short headerlen; /* Headerlength, should be 0x1A */
u_short version; /* VOC-file version */
u_short coded_ver; /* 0x1233-version */
} VocHeader;
typedef struct voc_blocktype {
u_char type;
u_char datalen; /* low-byte */
u_char datalen_m; /* medium-byte */
u_char datalen_h; /* high-byte */
u_char type;
u_char datalen; /* low-byte */
u_char datalen_m; /* medium-byte */
u_char datalen_h; /* high-byte */
} VocBlockType;
typedef struct voc_voice_data {
u_char tc;
u_char pack;
u_char tc;
u_char pack;
} VocVoiceData;
typedef struct voc_ext_block {
u_short tc;
u_char pack;
u_char mode;
u_short tc;
u_char pack;
u_char mode;
} VocExtBlock;
/* Definitions for Microsoft WAVE format */
#define WAV_RIFF 0x46464952
#define WAV_RIFF 0x46464952
#define WAV_WAVE 0x45564157
#define WAV_FMT 0x20746D66
#define WAV_DATA 0x61746164
@ -52,23 +52,23 @@ typedef struct voc_ext_block {
/* it's in chunks like .voc and AMIGA iff, but my source say there
are in only in this combination, so I combined them in one header;
it works on all WAVE-file I have
*/
*/
typedef struct wav_header {
u_int main_chunk; /* 'RIFF' */
u_int length; /* filelen */
u_int chunk_type; /* 'WAVE' */
u_int main_chunk; /* 'RIFF' */
u_int length; /* filelen */
u_int chunk_type; /* 'WAVE' */
u_int sub_chunk; /* 'fmt ' */
u_int sc_len; /* length of sub_chunk, =16 */
u_short format; /* should be 1 for PCM-code */
u_short modus; /* 1 Mono, 2 Stereo */
u_int sample_fq; /* frequence of sample */
u_int byte_p_sec;
u_short byte_p_spl; /* samplesize; 1 or 2 bytes */
u_short bit_p_spl; /* 8, 12 or 16 bit */
u_int sub_chunk; /* 'fmt ' */
u_int sc_len; /* length of sub_chunk, =16 */
u_short format; /* should be 1 for PCM-code */
u_short modus; /* 1 Mono, 2 Stereo */
u_int sample_fq; /* frequence of sample */
u_int byte_p_sec;
u_short byte_p_spl; /* samplesize; 1 or 2 bytes */
u_short bit_p_spl; /* 8, 12 or 16 bit */
u_int data_chunk; /* 'data' */
u_int data_length; /* samplecount */
u_int data_chunk; /* 'data' */
u_int data_length; /* samplecount */
} WaveHeader;
/* Definitions for Sparc .au header */
@ -80,12 +80,12 @@ typedef struct wav_header {
#define AU_FMT_LIN16 3
typedef struct au_header {
u_int magic; /* magic '.snd' */
u_int hdr_size; /* size of header (min 24) */
u_int data_size; /* size of data */
u_int encoding; /* see to AU_FMT_XXXX */
u_int sample_rate; /* sample rate */
u_int channels; /* number of channels (voices) */
u_int magic; /* magic '.snd' */
u_int hdr_size; /* size of header (min 24) */
u_int data_size; /* size of data */
u_int encoding; /* see to AU_FMT_XXXX */
u_int sample_rate; /* sample rate */
u_int channels; /* number of channels (voices) */
} AuHeader;
#endif /* FORMATS */
#endif /* FORMATS */