[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. 25
      src/commands.c
  2. 5
      src/common.h
  3. 46
      src/info.c
  4. 80
      src/main.c

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

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

@ -1,9 +1,27 @@
#include <stdio.h>
#include <string.h>
#include <xmp.h>
#include "common.h"
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)
{
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;
int time;
@ -39,7 +57,7 @@ void info_frame(struct xmp_module_info *mi, int loop, int reset)
if (mi->virt_used > max_channels)
max_channels = mi->virt_used;
if (mi->frame != 0)
if (!reset && mi->frame != 0)
return;
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"
"%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,
loop ? 'L' : ' ',
(int)(time / (60 * 600)), (int)((time / 600) % 60),
(int)((time / 10) % 60), (int)(time % 10));
fflush(stdout);
}
void info_pause(struct xmp_module_info *mi, int loop)
{
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' : ' ');
ctl->loop ? 'L' : ' ');
if (ctl->pause) {
printf(" - PAUSED -");
} else {
printf("%3d:%02d:%02d.%d",
(int)(time / (60 * 600)), (int)((time / 600) % 60),
(int)((time / 10) % 60), (int)(time % 10));
}
fflush(stdout);
}

@ -34,6 +34,22 @@ static void cleanup(int sig)
}
#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)
{
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)
{
xmp_context ctx;
xmp_context handle;
struct xmp_module_info mi;
struct options options;
struct control control;
@ -95,7 +130,7 @@ int main(int argc, char **argv)
set_tty();
ctx = xmp_create_context();
handle = xmp_create_context();
skipprev = 0;
@ -103,7 +138,7 @@ int main(int argc, char **argv)
printf("\nLoading %s... (%d of %d)\n",
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],
argv[optind]);
if (skipprev) {
@ -116,18 +151,18 @@ int main(int argc, char **argv)
}
skipprev = 0;
if (xmp_player_start(ctx, options.start, 44100, 0) == 0) {
int new_mod = 1;
if (xmp_player_start(handle, options.start, 44100, 0) == 0) {
int refresh_line = 1;
/* Mute channels */
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 */
xmp_player_get_info(ctx, &mi);
xmp_player_get_info(handle, &mi);
if (options.verbose > 0) {
info_mod(&mi);
@ -139,35 +174,32 @@ int main(int argc, char **argv)
/* Play module */
while (xmp_player_frame(ctx) == 0) {
while (xmp_player_frame(handle) == 0) {
int old_loop = mi.loop_count;
xmp_player_get_info(ctx, &mi);
//printf("%d %d\n", old_loop, mi.loop_count);
xmp_player_get_info(handle, &mi);
if (!control.loop && old_loop != mi.loop_count)
break;
info_frame(&mi, control.loop, new_mod);
info_frame(&mi, &control, refresh_line);
sound->play(mi.buffer, mi.buffer_size);
read_command(ctx, &control);
if (control.pause) {
sound->pause();
info_pause(&mi, control.loop);
while (control.pause) {
usleep(100000);
read_command(ctx, &control);
}
sound->resume();
read_command(handle, &control);
if (control.display) {
show_info(control.display, &mi);
control.display = 0;
refresh_line = 1;
}
new_mod = 0;
check_pause(handle, &control, &mi);
options.start = 0;
}
xmp_player_end(ctx);
xmp_player_end(handle);
}
xmp_release_module(ctx);
xmp_release_module(handle);
printf("\n");
if (control.skip == -1) {
@ -182,7 +214,7 @@ int main(int argc, char **argv)
sound->flush();
end:
xmp_free_context(ctx);
xmp_free_context(handle);
reset_tty();
sound->deinit();

Loading…
Cancel
Save