[BACK]Return to aucat.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / aucat

Diff for /src/usr.bin/aucat/aucat.c between version 1.115 and 1.116

version 1.115, 2011/05/26 07:18:40 version 1.116, 2011/06/03 10:05:27
Line 269 
Line 269 
   
 SLIST_HEAD(cfnetlist, cfnet);  SLIST_HEAD(cfnetlist, cfnet);
   
 void  struct cfdev *
 cfdev_add(struct cfdevlist *list, struct cfdev *templ, char *path)  cfdev_new(struct cfdev *templ)
 {  {
         struct cfdev *cd;          struct cfdev *cd;
   
Line 279 
Line 279 
                 perror("malloc");                  perror("malloc");
                 abort();                  abort();
         }          }
         *cd = *templ;          if (templ)
                   memcpy(cd, templ, sizeof(struct cfdev));
           else {
                   aparams_init(&cd->ipar, 0, 1, DEFAULT_RATE);
                   aparams_init(&cd->opar, 0, 1, DEFAULT_RATE);
                   cd->bufsz = 0;
                   cd->round = 0;
                   cd->hold = 1;
                   cd->autovol = 1;
           }
           SLIST_INIT(&cd->ins);
           SLIST_INIT(&cd->outs);
           SLIST_INIT(&cd->opts);
           SLIST_INIT(&cd->mids);
           cd->path = NULL;
           return cd;
   }
   
   void
   cfdev_add(struct cfdevlist *list, struct cfdev *cd, char *path)
   {
         cd->path = path;          cd->path = path;
         SLIST_INSERT_HEAD(list, cd, entry);          SLIST_INSERT_HEAD(list, cd, entry);
         SLIST_INIT(&templ->ins);  
         SLIST_INIT(&templ->outs);  
         SLIST_INIT(&templ->opts);  
         SLIST_INIT(&templ->mids);  
 }  }
   
 void  struct cfstr *
 cfstr_add(struct cfstrlist *list, struct cfstr *templ, char *path)  cfstr_new(struct cfstr *templ)
 {  {
         size_t len;  
         struct cfstr *cs;          struct cfstr *cs;
         unsigned hdr;  
   
         if (templ->hdr == HDR_AUTO) {  
                 len = strlen(path);  
                 if (len >= 4 && strcasecmp(path + len - 4, ".wav") == 0)  
                         hdr = HDR_WAV;  
                 else  
                         hdr = HDR_RAW;  
         } else  
                 hdr = templ->hdr;  
         cs = malloc(sizeof(struct cfstr));          cs = malloc(sizeof(struct cfstr));
         if (cs == NULL) {          if (cs == NULL) {
                 perror("malloc");                  perror("malloc");
                 abort();                  abort();
         }          }
         *cs = *templ;          if (templ)
                   memcpy(cs, templ, sizeof(struct cfstr));
           else {
                   aparams_init(&cs->ipar, 0, 1, DEFAULT_RATE);
                   aparams_init(&cs->opar, 0, 1, DEFAULT_RATE);
                   cs->mmc = 0;
                   cs->hdr = HDR_AUTO;
                   cs->xrun = XRUN_IGNORE;
                   cs->vol = MIDI_MAXCTL;
                   cs->mode = MODE_PLAY | MODE_REC;
                   cs->join = 1;
           }
           cs->path = NULL;
           return cs;
   }
   
   void
   cfstr_add(struct cfstrlist *list, struct cfstr *cs, char *path)
   {
         cs->path = path;          cs->path = path;
         cs->hdr = hdr;  
         SLIST_INSERT_HEAD(list, cs, entry);          SLIST_INSERT_HEAD(list, cs, entry);
 }  }
   
Line 463 
Line 486 
         int autostart;          int autostart;
         struct dev *d, *dnext;          struct dev *d, *dnext;
         unsigned active;          unsigned active;
         unsigned nsock, nfile;          unsigned nsock;
   
         /*          /*
          * global options defaults           * global options defaults
Line 475 
Line 498 
         n_flag = 0;          n_flag = 0;
         SLIST_INIT(&cfdevs);          SLIST_INIT(&cfdevs);
         SLIST_INIT(&cfnets);          SLIST_INIT(&cfnets);
         nfile = nsock = 0;          nsock = 0;
   
         /*          /*
          * default stream params           * default device and stream
          */           */
         cs = malloc(sizeof(struct cfstr));          cd = cfdev_new(NULL);
         if (cs == NULL) {          cs = cfstr_new(NULL);
                 perror("malloc");  
                 exit(1);  
         }  
         aparams_init(&cs->ipar, 0, 1, DEFAULT_RATE);  
         aparams_init(&cs->opar, 0, 1, DEFAULT_RATE);  
         cs->mmc = 0;  
         cs->hdr = HDR_AUTO;  
         cs->xrun = XRUN_IGNORE;  
         cs->vol = MIDI_MAXCTL;  
         cs->mode = MODE_PLAY | MODE_REC;  
         cs->join = 1;  
   
         /*  
          * default device  
          */  
         cd = malloc(sizeof(struct cfdev));  
         if (cd == NULL) {  
                 perror("malloc");  
                 exit(1);  
         }  
         aparams_init(&cd->ipar, 0, 1, DEFAULT_RATE);  
         aparams_init(&cd->opar, 0, 1, DEFAULT_RATE);  
         SLIST_INIT(&cd->ins);  
         SLIST_INIT(&cd->outs);  
         SLIST_INIT(&cd->opts);  
         SLIST_INIT(&cd->mids);  
         cd->path = NULL;  
         cd->bufsz = 0;  
         cd->round = 0;  
         cd->hold = 1;  
         cd->autovol = 1;  
   
         while ((c = getopt(argc, argv, "a:w:dnb:c:C:e:r:h:x:v:i:o:f:m:luq:s:U:L:t:j:z:")) != -1) {          while ((c = getopt(argc, argv, "a:w:dnb:c:C:e:r:h:x:v:i:o:f:m:luq:s:U:L:t:j:z:")) != -1) {
                 switch (c) {                  switch (c) {
                 case 'd':                  case 'd':
Line 539 
Line 531 
                         break;                          break;
                 case 'm':                  case 'm':
                         cs->mode = opt_mode();                          cs->mode = opt_mode();
                         cd->mode = cs->mode;  
                         break;                          break;
                 case 'h':                  case 'h':
                         cs->hdr = opt_hdr();                          cs->hdr = opt_hdr();
Line 581 
Line 572 
                         break;                          break;
                 case 'i':                  case 'i':
                         cfstr_add(&cd->ins, cs, optarg);                          cfstr_add(&cd->ins, cs, optarg);
                         nfile++;                          cs = cfstr_new(cs);
                         break;                          break;
                 case 'o':                  case 'o':
                         cfstr_add(&cd->outs, cs, optarg);                          cfstr_add(&cd->outs, cs, optarg);
                         nfile++;                          cs = cfstr_new(cs);
                         break;                          break;
                 case 's':                  case 's':
                         cfstr_add(&cd->opts, cs, optarg);                          cfstr_add(&cd->opts, cs, optarg);
                           cs = cfstr_new(cs);
                         nsock++;                          nsock++;
                         break;                          break;
                 case 'a':                  case 'a':
Line 615 
Line 607 
                             SLIST_EMPTY(&cd->ins) &&                              SLIST_EMPTY(&cd->ins) &&
                             SLIST_EMPTY(&cd->outs)) {                              SLIST_EMPTY(&cd->outs)) {
                                 cfstr_add(&cd->opts, cs, DEFAULT_OPT);                                  cfstr_add(&cd->opts, cs, DEFAULT_OPT);
                                   cs = cfstr_new(cs);
                                 nsock++;                                  nsock++;
                         }                          }
                         cfdev_add(&cfdevs, cd, optarg);                          cfdev_add(&cfdevs, cd, optarg);
                           cd = cfdev_new(cd);
                         break;                          break;
                 case 'l':                  case 'l':
                         l_flag = 1;                          l_flag = 1;
Line 662 
Line 656 
                     SLIST_EMPTY(&cd->outs)) {                      SLIST_EMPTY(&cd->outs)) {
                         cfstr_add(&cd->opts, cs, DEFAULT_OPT);                          cfstr_add(&cd->opts, cs, DEFAULT_OPT);
                         nsock++;                          nsock++;
                 }                  } else
                           free(cs);
                 if (!cd->hold)                  if (!cd->hold)
                         errx(1, "-a off not compatible with default device");                          errx(1, "-a off not compatible with default device");
                 cfdev_add(&cfdevs, cd, "default");                  cfdev_add(&cfdevs, cd, "default");
           } else {
                   if (!SLIST_EMPTY(&cd->opts) ||
                       !SLIST_EMPTY(&cd->ins) ||
                       !SLIST_EMPTY(&cd->outs) ||
                       !SLIST_EMPTY(&cd->outs))
                           errx(1, "no device to attach last stream to");
                   free(cs);
                   free(cd);
         }          }
         if ((cs = SLIST_FIRST(&cd->opts)) ||  
             (cs = SLIST_FIRST(&cd->ins)) ||  
             (cs = SLIST_FIRST(&cd->outs)))  
                 errx(1, "%s: no device to attach the stream to", cs->path);  
   
         /*          /*
          * Check modes and calculate "best" device parameters. Iterate over all           * Check modes and calculate "best" device parameters. Iterate over all
Line 898 
Line 897 
         nsock = 0;          nsock = 0;
   
         /*          /*
          * default stream params           * default device and stream
          */           */
         cs = malloc(sizeof(struct cfstr));          cs = cfstr_new(NULL);
         if (cs == NULL) {          cd = cfdev_new(NULL);
                 perror("malloc");  
                 exit(1);  
         }  
         cs->hdr = HDR_RAW;  
   
         /*  
          * default device  
          */  
         cd = malloc(sizeof(struct cfdev));  
         if (cd == NULL) {  
                 perror("malloc");  
                 exit(1);  
         }  
         SLIST_INIT(&cd->ins);  
         SLIST_INIT(&cd->outs);  
         SLIST_INIT(&cd->opts);  
         SLIST_INIT(&cd->mids);  
         cd->path = NULL;  
   
   
         while ((c = getopt(argc, argv, "di:o:ls:q:U:L:")) != -1) {          while ((c = getopt(argc, argv, "di:o:ls:q:U:L:")) != -1) {
                 switch (c) {                  switch (c) {
                 case 'd':                  case 'd':
Line 933 
Line 913 
                         break;                          break;
                 case 'i':                  case 'i':
                         cfstr_add(&cd->ins, cs, optarg);                          cfstr_add(&cd->ins, cs, optarg);
                           cs = cfstr_new(cs);
                         break;                          break;
                 case 'o':                  case 'o':
                         cfstr_add(&cd->outs, cs, optarg);                          cfstr_add(&cd->outs, cs, optarg);
                           cs = cfstr_new(cs);
                         break;                          break;
                 case 'q':                  case 'q':
                         cfmid_add(&cd->mids, optarg);                          cfmid_add(&cd->mids, optarg);
Line 943 
Line 925 
                 case 's':                  case 's':
                         cfstr_add(&cd->opts, cs, optarg);                          cfstr_add(&cd->opts, cs, optarg);
                         cfdev_add(&cfdevs, cd, optarg);                          cfdev_add(&cfdevs, cd, optarg);
                           cd = cfdev_new(cd);
                           cs = cfstr_new(NULL);
                         nsock++;                          nsock++;
                         break;                          break;
                 case 'l':                  case 'l':
Line 985 
Line 969 
          */           */
         if (SLIST_EMPTY(&cfdevs)) {          if (SLIST_EMPTY(&cfdevs)) {
                 if (SLIST_EMPTY(&cd->mids)) {                  if (SLIST_EMPTY(&cd->mids)) {
                         if (!SLIST_EMPTY(&cd->ins) || !SLIST_EMPTY(&cd->outs))                          if (SLIST_EMPTY(&cd->ins) && SLIST_EMPTY(&cd->outs)) {
                                 cfmid_add(&cd->mids, "default");  
                         else {  
                                 cfstr_add(&cd->opts, cs, DEFAULT_OPT);                                  cfstr_add(&cd->opts, cs, DEFAULT_OPT);
                                 nsock++;                                  nsock++;
                           } else {
                                   cfmid_add(&cd->mids, "default");
                                   free(cs);
                         }                          }
                 }                  } else
                           free(cs);
                 cfdev_add(&cfdevs, cd, "default");                  cfdev_add(&cfdevs, cd, "default");
           } else {
                   free(cs);
                   free(cd);
         }          }
         if (nsock > 0) {          if (nsock > 0) {
                 getbasepath(base, sizeof(path));                  getbasepath(base, sizeof(path));
Line 1009 
Line 998 
                 d = dev_new_thru();                  d = dev_new_thru();
                 if (d == NULL)                  if (d == NULL)
                         errx(1, "%s: can't open device", cd->path);                          errx(1, "%s: can't open device", cd->path);
                 if (!dev_ref(d))  
                         errx(1, "couldn't open midi thru box");  
                 if (SLIST_EMPTY(&cd->opts) && APROC_OK(d->midi))                  if (SLIST_EMPTY(&cd->opts) && APROC_OK(d->midi))
                         d->midi->flags |= APROC_QUIT;                          d->midi->flags |= APROC_QUIT;
   

Legend:
Removed from v.1.115  
changed lines
  Added in v.1.116