[xmp] Add console output function

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
master
Claudio Matsuoka 14 years ago
parent f872b445ed
commit dad13427a3
  1. 2
      src/common.h
  2. 68
      src/info.c
  3. 32
      src/main.c

@ -32,6 +32,8 @@ struct control {
};
int report(char *, ...);
/* option */
void get_options(int, char **, struct options *);

@ -7,7 +7,7 @@ static int max_channels = -1;
void info_help(void)
{
printf(
report(
"COMMAND KEYS SUMMARY\n"
" Space Pause/unpause\n"
" q, Esc Stop module and quit the player\n"
@ -30,24 +30,24 @@ void info_mod(struct xmp_module_info *mi)
int i;
int num_seq;
printf("Module name : %s\n", mi->mod->name);
printf("Module type : %s\n", mi->mod->type);
printf("Module length: %d patterns\n", mi->mod->len);
printf("Patterns : %d\n", mi->mod->pat);
printf("Instruments : %d\n", mi->mod->ins);
printf("Samples : %d\n", mi->mod->smp);
printf("Channels : %d [ ", mi->mod->chn);
report("Module name : %s\n", mi->mod->name);
report("Module type : %s\n", mi->mod->type);
report("Module length: %d patterns\n", mi->mod->len);
report("Patterns : %d\n", mi->mod->pat);
report("Instruments : %d\n", mi->mod->ins);
report("Samples : %d\n", mi->mod->smp);
report("Channels : %d [ ", mi->mod->chn);
for (i = 0; i < mi->mod->chn; i++) {
if (mi->mod->xxc[i].flg & XMP_CHANNEL_SYNTH) {
printf("S ");
report("S ");
} else {
printf("%x ", mi->mod->xxc[i].pan >> 4);
report("%x ", mi->mod->xxc[i].pan >> 4);
}
}
printf("]\n");
report("]\n");
printf("Duration : %dmin%02ds", (mi->total_time + 500) / 60000,
report("Duration : %dmin%02ds", (mi->total_time + 500) / 60000,
((mi->total_time + 500) / 1000) % 60);
/* Check non-zero-length sequences */
@ -58,7 +58,7 @@ void info_mod(struct xmp_module_info *mi)
}
if (num_seq > 1) {
printf(" (main sequence)\n");
report(" (main sequence)\n");
for (i = 1; i < mi->num_sequences; i++) {
int dur = mi->seq_data[i].duration;
@ -66,13 +66,13 @@ void info_mod(struct xmp_module_info *mi)
continue;
}
printf(" %dmin%02ds "
report(" %dmin%02ds "
"(sequence at position %d)\n",
(dur + 500) / 60000, ((dur + 500) / 1000) % 60,
mi->seq_data[i].entry_point);
}
} else {
printf("\n");
report("\n");
}
}
@ -95,7 +95,7 @@ void info_frame(struct xmp_module_info *mi, struct control *ctl, int reprint)
time = ctl->time / 100;
if (reprint || mi->order != ord || mi->bpm != bpm || mi->speed != spd) {
printf("\rSpeed[%02X] BPM[%02X] Pos[%02X/%02X] "
report("\rSpeed[%02X] BPM[%02X] Pos[%02X/%02X] "
"Pat[%02X/%02X] Row[ / ] Chn[ / ] 0:00:00.0",
mi->speed, mi->bpm,
mi->order, mi->mod->len - 1,
@ -105,15 +105,15 @@ void info_frame(struct xmp_module_info *mi, struct control *ctl, int reprint)
spd = mi->speed;
}
printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
report("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
"%02X/%02X] Chn[%02X/%02X] %c ",
mi->row, mi->num_rows - 1, mi->virt_used, max_channels,
ctl->loop ? 'L' : ' ');
if (ctl->pause) {
printf(" - PAUSED -");
report(" - PAUSED -");
} else {
printf("%3d:%02d:%02d.%d",
report("%3d:%02d:%02d.%d",
(int)(time / (60 * 600)), (int)((time / 600) % 60),
(int)((time / 10) % 60), (int)(time % 10));
}
@ -126,8 +126,8 @@ void info_ins_smp(struct xmp_module_info *mi)
int i, j;
struct xmp_module *mod = mi->mod;
printf("Instruments and samples:\n");
printf(" Instrument name Smp Size Loop End Vol Fine Xpo Pan\n");
report("Instruments and samples:\n");
report(" Instrument name Smp Size Loop End Vol Fine Xpo Pan\n");
for (i = 0; i < mod->ins; i++) {
struct xmp_instrument *ins = &mod->xxi[i];
@ -135,7 +135,7 @@ void info_ins_smp(struct xmp_module_info *mi)
continue;
}
printf("%02x %-32.32s ", i, ins->name);
report("%02x %-32.32s ", i, ins->name);
for (j = 0; j < ins->nsm; j++) {
struct xmp_subinstrument *sub = &ins->sub[j];
@ -145,10 +145,10 @@ void info_ins_smp(struct xmp_module_info *mi)
if (smp->len == 0) {
continue;
}
printf("%36.36s", " ");
report("%36.36s", " ");
}
printf("[%02x] %05x%c%05x %05x%c V%02x %+04d %+03d P%02x\n",
report("[%02x] %05x%c%05x %05x%c V%02x %+04d %+03d P%02x\n",
sub->sid,
smp->len,
smp->flg & XMP_SAMPLE_16BIT ? '+' : ' ',
@ -164,7 +164,7 @@ void info_ins_smp(struct xmp_module_info *mi)
}
if (j == 0) {
printf("[ ] ----- ----- ----- --- ---- --- ---\n");
report("[ ] ----- ----- ----- --- ---- --- ---\n");
}
}
@ -175,8 +175,8 @@ void info_instruments(struct xmp_module_info *mi)
int i, j;
struct xmp_module *mod = mi->mod;
printf("Instruments:\n");
printf(" Instrument name Vl Rls Env Ns Sub Gv Vl Fine Xpo Pan Sm\n");
report("Instruments:\n");
report(" Instrument name Vl Rls Env Ns Sub Gv Vl Fine Xpo Pan Sm\n");
for (i = 0; i < mod->ins; i++) {
struct xmp_instrument *ins = &mod->xxi[i];
@ -184,7 +184,7 @@ void info_instruments(struct xmp_module_info *mi)
continue;
}
printf("%02x %-32.32s %02x %04x %c%c%c %02x ", i, ins->name,
report("%02x %-32.32s %02x %04x %c%c%c %02x ", i, ins->name,
ins->vol, ins->rls,
ins->aei.flg & XMP_ENVELOPE_ON ? 'A' : '-',
ins->fei.flg & XMP_ENVELOPE_ON ? 'F' : '-',
@ -200,10 +200,10 @@ void info_instruments(struct xmp_module_info *mi)
if (smp->len == 0) {
continue;
}
printf("%51.51s", " ");
report("%51.51s", " ");
}
printf("[%02x] %02x %02x %+04d %+03d P%02x %02x\n",
report("[%02x] %02x %02x %+04d %+03d P%02x %02x\n",
j,
sub->gvl,
sub->vol,
@ -214,7 +214,7 @@ void info_instruments(struct xmp_module_info *mi)
}
if (j == 0) {
printf("[ ] -- -- ---- --- --- --\n");
report("[ ] -- -- ---- --- --- --\n");
}
}
@ -225,8 +225,8 @@ void info_samples(struct xmp_module_info *mi)
int i;
struct xmp_module *mod = mi->mod;
printf("Samples:\n");
printf(" Sample name Length Start End Flags\n");
report("Samples:\n");
report(" Sample name Length Start End Flags\n");
for (i = 0; i < mod->ins; i++) {
struct xmp_sample *smp = &mod->xxs[i];
@ -234,7 +234,7 @@ void info_samples(struct xmp_module_info *mi)
continue;
}
printf("%02x %-32.32s %06x %06x %06x %s %s %s\n",
report("%02x %-32.32s %06x %06x %06x %s %s %s\n",
i, smp->name,
smp->len,
smp->lps,

@ -7,6 +7,7 @@
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdarg.h>
#include <xmp.h>
#include "sound.h"
#include "common.h"
@ -21,6 +22,19 @@ static struct sound_driver *sound;
static int background = 0;
static int refresh_status;
int report(char *fmt, ...)
{
va_list a;
int n;
va_start(a, fmt);
n = vfprintf(stderr, fmt, a);
va_end(a);
return n;
}
#ifdef HAVE_SIGNAL_H
static void cleanup(int sig)
{
@ -45,7 +59,7 @@ static void cleanup(int sig)
#ifdef SIGTSTP
static void sigtstp_handler(int n)
{
fprintf(stderr, "\n");
report("\n");
signal(SIGTSTP, SIG_DFL);
#ifdef HAVE_KILL
kill(getpid(), SIGTSTP);
@ -71,7 +85,7 @@ static void sigcont_handler(int sig)
static void show_info(int what, struct xmp_module_info *mi)
{
printf("\r%78.78s\n", " ");
report("\r%78.78s\n", " ");
switch (what) {
case '?':
info_help();
@ -175,11 +189,13 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
printf("Using %s\n", sound->description);
if (options.verbose > 0) {
report("Using %s\n", sound->description);
printf("Mixer set to %d Hz, %dbit, %s\n", options.rate,
report("Mixer set to %d Hz, %dbit, %s\n", options.rate,
options.format & XMP_FORMAT_8BIT ? 8 : 16,
options.format & XMP_FORMAT_MONO ? "mono" : "stereo");
}
if (options.probeonly) {
exit(EXIT_SUCCESS);
@ -216,8 +232,10 @@ int main(int argc, char **argv)
skipprev = 0;
for (first = optind; optind < argc; optind++) {
printf("\nLoading %s... (%d of %d)\n",
argv[optind], optind - first + 1, argc - first);
if (options.verbose > 0) {
report("\nLoading %s... (%d of %d)\n",
argv[optind], optind - first + 1, argc - first);
}
val = xmp_load_module(handle, argv[optind]);
if (val < 0) {
@ -319,7 +337,7 @@ int main(int argc, char **argv)
xmp_release_module(handle);
if (!options.info) {
printf("\n");
report("\n");
}
if (control.skip == -1) {

Loading…
Cancel
Save