From edc5bc38ec1d346c309db50444fd571cfe83be76 Mon Sep 17 00:00:00 2001 From: joq Date: Sun, 8 Jun 2003 17:30:34 +0000 Subject: [PATCH] jack_transport, jack_showtime enhancements git-svn-id: svn+ssh://jackaudio.org/trunk/jack@413 0c269be4-1314-0410-8aa9-9f06e86f4224 --- configure.in | 2 +- example-clients/showtime.c | 33 ++++++++++++------ example-clients/transport.c | 69 ++++++++++++++++++++++++++----------- 3 files changed, 73 insertions(+), 31 deletions(-) diff --git a/configure.in b/configure.in index ad23922..c2e3786 100644 --- a/configure.in +++ b/configure.in @@ -14,7 +14,7 @@ dnl changes are made dnl --- JACK_MAJOR_VERSION=0 JACK_MINOR_VERSION=72 -JACK_MICRO_VERSION=1 +JACK_MICRO_VERSION=2 dnl --- dnl HOWTO: updating the jack protocal version diff --git a/example-clients/showtime.c b/example-clients/showtime.c index 5f43378..6329745 100644 --- a/example-clients/showtime.c +++ b/example-clients/showtime.c @@ -39,23 +39,36 @@ showtime () } while (current.guard1 != current.guard2); if (current.info.valid & JackTransportPosition) - printf ("frame: %lu ", current.info.frame); + printf ("frame: %7lu\t", current.info.frame); else - printf ("frame: [-] "); - - if (current.info.valid & JackTransportState) - printf ("state: %d ", current.info.transport_state); + printf ("frame: [-]\t"); + + if (current.info.valid & JackTransportState) { + switch (current.info.transport_state) { + case JackTransportStopped: + printf ("state: Stopped\t"); + break; + case JackTransportRolling: + printf ("state: Rolling\t"); + break; + case JackTransportLooping: + printf ("state: Looping\t"); + break; + default: + printf ("state: [unknown]\t"); + } + } else - printf ("state: [-] "); + printf ("state: [-]\t"); if (current.info.valid & JackTransportLoop) - printf ("loop: %lu-%lu ", current.info.loop_start, + printf ("loop: %lu-%lu\t", current.info.loop_start, current.info.loop_end); else - printf ("loop: [-] "); + printf ("loop: [-]\t"); if (current.info.valid & JackTransportBBT) - printf ("BBT: %d|%d|%d\n", current.info.bar, + printf ("BBT: %3d|%d|%04d\n", current.info.bar, current.info.beat, current.info.tick); else printf ("BBT: [-]\n"); @@ -68,7 +81,7 @@ process (jack_nframes_t nframes, void *arg) * high resolution, that showtime() can detect whether the * last update is complete. */ now.guard1 = jack_frame_time(client); - jack_get_transport_info (client, &now.info); + jack_get_transport_info (client, (jack_transport_info_t *) &now.info); now.guard2 = now.guard1; return 0; diff --git a/example-clients/transport.c b/example-clients/transport.c index 729045d..6b6fffd 100644 --- a/example-clients/transport.c +++ b/example-clients/transport.c @@ -18,10 +18,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* To compile: - * cc -o transport transport.c -lhistory -lreadline `pkg-config --libs jack` - */ - #include #include #include @@ -48,8 +44,18 @@ int process(jack_nframes_t nframes, void *arg) jack_set_transport_info(client, &tinfo); /* frame number for next cycle */ - if (tinfo.transport_state == JackTransportRolling) - tinfo.frame += nframes; + if (tinfo.transport_state != JackTransportStopped) { + tinfo.frame += nframes; + + /* When looping, adjust the frame number periodically. Make + * sure improper loop limits don't lock up the system in an + * infinite while(). */ + if ((tinfo.transport_state == JackTransportLooping) && + (tinfo.loop_end > tinfo.loop_start)) { + while (tinfo.frame >= tinfo.loop_end) + tinfo.frame -= (tinfo.loop_end - tinfo.loop_start); + } + } return 0; } @@ -76,6 +82,11 @@ void com_exit(char *arg) void com_help(char *); /* forward declaration */ +void com_loop(char *arg) +{ + tinfo.transport_state = JackTransportLooping; +} + void com_play(char *arg) { tinfo.transport_state = JackTransportRolling; @@ -103,10 +114,12 @@ typedef struct { cmd_function_t *func; /* Function to call to do the job. */ char *doc; /* Documentation for this function. */ } command_t; - + +/* command list, must be in order */ command_t commands[] = { { "exit", com_exit, "Exit transport program" }, { "help", com_help, "Display help text" }, + { "loop", com_loop, "Start transport looping" }, { "play", com_play, "Start transport rolling" }, { "quit", com_exit, "Synonym for `exit'"}, { "rewind", com_rewind, "Reset transport position to beginning" }, @@ -118,10 +131,22 @@ command_t commands[] = { command_t *find_command(char *name) { register int i; - + size_t namelen; + + if ((name == NULL) || (*name == '\0')) + return ((command_t *)NULL); + + namelen = strlen(name); for (i = 0; commands[i].name; i++) - if (strcmp (name, commands[i].name) == 0) - return (&commands[i]); + if (strncmp(name, commands[i].name, namelen) == 0) { + + /* make sure the match is unique */ + if ((commands[i+1].name) && + (strncmp(name, commands[i+1].name, namelen) == 0)) + return ((command_t *)NULL); + else + return (&commands[i]); + } return ((command_t *)NULL); } @@ -129,17 +154,19 @@ command_t *find_command(char *name) void com_help(char *arg) { register int i; - int printed = 0; + command_t *cmd; - /* print help for command arg */ - for (i = 0; commands[i].name; i++) { - if (!*arg || (strcmp (arg, commands[i].name) == 0)) { + if (!*arg) { + /* print help for all commands */ + for (i = 0; commands[i].name; i++) { printf("%s\t\t%s.\n", commands[i].name, commands[i].doc); - printed++; } - } - if (!printed) { + } else if ((cmd = find_command(arg))) { + printf("%s\t\t%s.\n", cmd->name, cmd->doc); + + } else { + int printed = 0; printf("No `%s' command. Valid command names are:\n", arg); @@ -154,7 +181,7 @@ void com_help(char *arg) printed++; } - printf("\n\nType `help [command]\' for more information.\n"); + printf("\n\nTry `help [command]\' for more information.\n"); } } @@ -237,7 +264,7 @@ char *command_generator (const char *text, int state) /* Return the next name which partially matches from the command list. */ - while (name = commands[list_index].name) { + while ((name = commands[list_index].name)) { list_index++; if (strncmp(name, text, len) == 0) @@ -288,7 +315,9 @@ void command_loop() void initialize_transport() { /* must run before jack_activate */ - tinfo.valid = JackTransportState | JackTransportPosition; + tinfo.loop_start = 0; /* default loop is one second */ + tinfo.loop_end = jack_get_sample_rate(client); + tinfo.valid = JackTransportState|JackTransportPosition|JackTransportLoop; com_rewind(NULL); }