[xmp] Add information display key commands

COMMAND KEYS SUMMARY
     Space      Pause/unpause
    F, Right    Advance to next order
    B, Left     Return to previous order
    N, Up       Advance to next module
    P, Down     Return to previous module
    1 - 0       Mute/unmute channels
      !         Unmute all channels
      ?         Display available commands
      m         Display module information
      i         Display instrument list

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
master
Claudio Matsuoka 14 years ago
parent 4d11dc1df5
commit e85819d86f
  1. 23
      src/commands.c
  2. 5
      src/common.h
  3. 46
      src/info.c
  4. 80
      src/main.c

@ -87,7 +87,7 @@ static int read_key()
* ESC [ C - right arrow * ESC [ C - right arrow
* ESC [ D - left arrow * ESC [ D - left arrow
*/ */
void read_command(xmp_context ctx, struct control *ctl) void read_command(xmp_context handle, struct control *ctl)
{ {
int cmd; int cmd;
@ -115,29 +115,29 @@ void read_command(xmp_context ctx, struct control *ctl)
break; break;
case 'q': /* quit */ case 'q': /* quit */
cmd_quit: cmd_quit:
xmp_mod_stop(ctx); xmp_mod_stop(handle);
ctl->pause = 0; ctl->pause = 0;
ctl->skip = -2; ctl->skip = -2;
break; break;
case 'f': /* jump to next order */ case 'f': /* jump to next order */
cmd_next_ord: cmd_next_ord:
xmp_ord_next(ctx); xmp_ord_next(handle);
ctl->pause = 0; ctl->pause = 0;
break; break;
case 'b': /* jump to previous order */ case 'b': /* jump to previous order */
cmd_prev_ord: cmd_prev_ord:
xmp_ord_prev(ctx); xmp_ord_prev(handle);
ctl->pause = 0; ctl->pause = 0;
break; break;
case 'n': /* skip to next module */ case 'n': /* skip to next module */
cmd_next_mod: cmd_next_mod:
xmp_mod_stop(ctx); xmp_mod_stop(handle);
ctl->pause = 0; ctl->pause = 0;
ctl->skip = 1; ctl->skip = 1;
break; break;
case 'p': /* skip to previous module */ case 'p': /* skip to previous module */
cmd_prev_mod: cmd_prev_mod:
xmp_mod_stop(ctx); xmp_mod_stop(handle);
ctl->pause = 0; ctl->pause = 0;
ctl->skip = -1; ctl->skip = -1;
break; break;
@ -156,16 +156,21 @@ void read_command(xmp_context ctx, struct control *ctl)
case '7': case '7':
case '8': case '8':
case '9': case '9':
xmp_channel_mute(ctx, cmd - '1', -1); xmp_channel_mute(handle, cmd - '1', -1);
break; break;
case '0': case '0':
xmp_channel_mute(ctx, 9, -1); xmp_channel_mute(handle, 9, -1);
break; break;
case '!': { case '!': {
int i; int i;
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
xmp_channel_mute(ctx, i, 0); xmp_channel_mute(handle, i, 0);
} }
break; } break; }
case '?':
case 'i':
case 'm':
ctl->display = cmd;
break;
} }
} }

@ -20,6 +20,7 @@ struct control {
int skip; int skip;
int loop; int loop;
int pause; int pause;
int display;
}; };
@ -32,9 +33,9 @@ int reset_tty(void);
/* info */ /* info */
void info_mod(struct xmp_module_info *); void info_mod(struct xmp_module_info *);
void info_frame(struct xmp_module_info *, int, int); void info_frame(struct xmp_module_info *, struct control *, int);
void info_pause(struct xmp_module_info *, int);
void info_instruments_compact(struct xmp_module_info *); void info_instruments_compact(struct xmp_module_info *);
void info_help(void);
/* commands */ /* commands */
void read_command(xmp_context, struct control *); void read_command(xmp_context, struct control *);

@ -1,9 +1,27 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <xmp.h> #include <xmp.h>
#include "common.h"
static int max_channels = -1; static int max_channels = -1;
void info_help(void)
{
printf(
"COMMAND KEYS SUMMARY\n"
" Space Pause/unpause\n"
" F, Right Advance to next order\n"
" B, Left Return to previous order\n"
" N, Up Advance to next module\n"
" P, Down Return to previous module\n"
" 1 - 0 Mute/unmute channels\n"
" ! Unmute all channels\n"
" ? Display available commands\n"
" m Display module information\n"
" i Display instrument list\n"
);
}
void info_mod(struct xmp_module_info *mi) void info_mod(struct xmp_module_info *mi)
{ {
int i; int i;
@ -26,7 +44,7 @@ void info_mod(struct xmp_module_info *mi)
} }
void info_frame(struct xmp_module_info *mi, int loop, int reset) void info_frame(struct xmp_module_info *mi, struct control *ctl, int reset)
{ {
static int ord = -1, tpo = -1, bpm = -1; static int ord = -1, tpo = -1, bpm = -1;
int time; int time;
@ -39,7 +57,7 @@ void info_frame(struct xmp_module_info *mi, int loop, int reset)
if (mi->virt_used > max_channels) if (mi->virt_used > max_channels)
max_channels = mi->virt_used; max_channels = mi->virt_used;
if (mi->frame != 0) if (!reset && mi->frame != 0)
return; return;
time = mi->current_time / 100; time = mi->current_time / 100;
@ -56,21 +74,17 @@ void info_frame(struct xmp_module_info *mi, int loop, int reset)
} }
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" 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"
"%02X/%02X] Chn[%02X/%02X] %c %3d:%02d:%02d.%d", "%02X/%02X] Chn[%02X/%02X] %c ",
mi->row, mi->num_rows - 1, mi->virt_used, max_channels, mi->row, mi->num_rows - 1, mi->virt_used, max_channels,
loop ? 'L' : ' ', ctl->loop ? 'L' : ' ');
(int)(time / (60 * 600)), (int)((time / 600) % 60),
(int)((time / 10) % 60), (int)(time % 10)); if (ctl->pause) {
printf(" - PAUSED -");
fflush(stdout); } else {
} printf("%3d:%02d:%02d.%d",
(int)(time / (60 * 600)), (int)((time / 600) % 60),
void info_pause(struct xmp_module_info *mi, int loop) (int)((time / 10) % 60), (int)(time % 10));
{ }
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"
"%02X/%02X] Chn[%02X/%02X] %c - PAUSED -",
mi->row, mi->num_rows - 1, mi->virt_used, max_channels,
loop ? 'L' : ' ');
fflush(stdout); fflush(stdout);
} }

@ -34,6 +34,22 @@ static void cleanup(int sig)
} }
#endif #endif
static void show_info(int what, struct xmp_module_info *mi)
{
printf("\r%78.78s\n", " ");
switch (what) {
case '?':
info_help();
break;
case 'i':
info_instruments_compact(mi);
break;
case 'm':
info_mod(mi);
break;
}
}
static void shuffle(int argc, char **argv) static void shuffle(int argc, char **argv)
{ {
int i, j; int i, j;
@ -47,9 +63,28 @@ static void shuffle(int argc, char **argv)
} }
} }
static void check_pause(xmp_context handle, struct control *ctl,
struct xmp_module_info *mi)
{
if (ctl->pause) {
sound->pause();
info_frame(mi, ctl, 1);
while (ctl->pause) {
usleep(100000);
read_command(handle, ctl);
if (ctl->display) {
show_info(ctl->display, mi);
info_frame(mi, ctl, 1);
ctl->display = 0;
}
}
sound->resume();
}
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
xmp_context ctx; xmp_context handle;
struct xmp_module_info mi; struct xmp_module_info mi;
struct options options; struct options options;
struct control control; struct control control;
@ -95,7 +130,7 @@ int main(int argc, char **argv)
set_tty(); set_tty();
ctx = xmp_create_context(); handle = xmp_create_context();
skipprev = 0; skipprev = 0;
@ -103,7 +138,7 @@ int main(int argc, char **argv)
printf("\nLoading %s... (%d of %d)\n", printf("\nLoading %s... (%d of %d)\n",
argv[optind], optind - first + 1, argc - first); argv[optind], optind - first + 1, argc - first);
if (xmp_load_module(ctx, argv[optind]) < 0) { if (xmp_load_module(handle, argv[optind]) < 0) {
fprintf(stderr, "%s: error loading %s\n", argv[0], fprintf(stderr, "%s: error loading %s\n", argv[0],
argv[optind]); argv[optind]);
if (skipprev) { if (skipprev) {
@ -116,18 +151,18 @@ int main(int argc, char **argv)
} }
skipprev = 0; skipprev = 0;
if (xmp_player_start(ctx, options.start, 44100, 0) == 0) { if (xmp_player_start(handle, options.start, 44100, 0) == 0) {
int new_mod = 1; int refresh_line = 1;
/* Mute channels */ /* Mute channels */
for (i = 0; i < XMP_MAX_CHANNELS; i++) { for (i = 0; i < XMP_MAX_CHANNELS; i++) {
xmp_channel_mute(ctx, i, options.mute[i]); xmp_channel_mute(handle, i, options.mute[i]);
} }
/* Show module data */ /* Show module data */
xmp_player_get_info(ctx, &mi); xmp_player_get_info(handle, &mi);
if (options.verbose > 0) { if (options.verbose > 0) {
info_mod(&mi); info_mod(&mi);
@ -139,35 +174,32 @@ int main(int argc, char **argv)
/* Play module */ /* Play module */
while (xmp_player_frame(ctx) == 0) { while (xmp_player_frame(handle) == 0) {
int old_loop = mi.loop_count; int old_loop = mi.loop_count;
xmp_player_get_info(ctx, &mi); xmp_player_get_info(handle, &mi);
//printf("%d %d\n", old_loop, mi.loop_count);
if (!control.loop && old_loop != mi.loop_count) if (!control.loop && old_loop != mi.loop_count)
break; break;
info_frame(&mi, control.loop, new_mod); info_frame(&mi, &control, refresh_line);
sound->play(mi.buffer, mi.buffer_size); sound->play(mi.buffer, mi.buffer_size);
read_command(ctx, &control); read_command(handle, &control);
if (control.pause) {
sound->pause(); if (control.display) {
info_pause(&mi, control.loop); show_info(control.display, &mi);
while (control.pause) { control.display = 0;
usleep(100000); refresh_line = 1;
read_command(ctx, &control);
}
sound->resume();
} }
new_mod = 0; check_pause(handle, &control, &mi);
options.start = 0; options.start = 0;
} }
xmp_player_end(ctx); xmp_player_end(handle);
} }
xmp_release_module(ctx); xmp_release_module(handle);
printf("\n"); printf("\n");
if (control.skip == -1) { if (control.skip == -1) {
@ -182,7 +214,7 @@ int main(int argc, char **argv)
sound->flush(); sound->flush();
end: end:
xmp_free_context(ctx); xmp_free_context(handle);
reset_tty(); reset_tty();
sound->deinit(); sound->deinit();

Loading…
Cancel
Save