[CM] reading characters from keyboard in s7

Orm Finnendahl o.finnendahl at inm.mh-freiburg.de
Fri Jul 27 02:48:37 PDT 2012


Hi Bill,

 thanks a lot, your thorough answer is very appreciated!

Yours,
Orm


On Thu, 26 Jul 2012 10:36:59 -0700, Bill Schottstaedt wrote:
>
>
> (read-char *stdin*)
>
> will wait for you to type something in the terminal, then
> return it.  There's a fancier example in s7.html (under 
> begin-hook) which
> watches for C-C to break out of a loop.  It uses tcgetattr
> and friends; here's a stand-alone C program that is very
> similar:
>
>
> #include <stdlib.h>
> #include <signal.h>
> #include <stdio.h>
> #include <termios.h>
>
> static struct termios saveit;
>
> static int tty_reset(int fd)
> {
>   if (tcsetattr(fd, TCSAFLUSH, &saveit) < 0)
>     return(-1);
>   return(0);
> }
>
> static void sigcatch(int no)
> {
>   tty_reset(fileno(stdin));
>   exit(0);
> }
>
> int main (int argc, char **argv)
> {
>   struct termios buf;
>   int i;
>   char c;
>
>   if (signal(SIGINT, sigcatch) == SIG_ERR) exit(1);
>   if (signal(SIGQUIT, sigcatch) == SIG_ERR) exit(1);
>   if (signal(SIGTERM, sigcatch) == SIG_ERR) exit(1);
>
>   if (tcgetattr(fileno(stdin), &saveit) < 0)
>     exit(1);
>   buf = saveit;
>   buf.c_lflag &= ~(ECHO | ICANON);
>   buf.c_cc[VMIN] = 1;
>   buf.c_cc[VTIME] = 0;
  
>   if (tcsetattr(fileno(stdin), TCSAFLUSH, &buf) < 0)
>     exit(1);
>   while ((i = read(fileno(stdin), &c, 1)) == 1) /* Ctrl-C to exit */
>     {
>       c &= 255;
>       fprintf(stderr,"got %c\n", c);
>     }
>   tty_reset(fileno(stdin));
>   return(0);
> }
>
> In the Snd listener, read-hook might be what you want (except it waits
> for carriage-return).  To do something fancier in the listener would
> probably require hacking the XmNmodifyVerify callback (in Motif)
> or its equivalent in gtk as applied to the listener text widget.
> snd-motif.scm has some code that might give you a start.
>
> _______________________________________________
> Cmdist mailing list
> Cmdist at ccrma.stanford.edu
> http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist



More information about the Cmdist mailing list