home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / SoundApps / Patchmix / Source / Coordinator.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  5.0 KB  |  210 lines

  1. /*
  2.     Coordinator.m
  3.     by Joe Freeman, David LaVallee
  4.     Subprocess Example, Release 2.0
  5.     NeXT Computer, Inc.
  6.  
  7.     You may freely copy, distribute and reuse the code in this example.
  8.     NeXT disclaims any warranty of any kind, expressed or implied, as to
  9.     its fitness for any particular use.
  10. */
  11.  
  12. #import "Subprocess.h"
  13. #import "Coordinator.h"
  14. #import "CommandScroll.h"
  15. #import <stdio.h>
  16. #import <appkit/nextstd.h>
  17. #import <appkit/Application.h>
  18. #import <appkit/Panel.h>
  19. #import <objc/NXStringTable.h>
  20. #import <strings.h>
  21. #import <appkit/Form.h>
  22. #import "Instrum.h"
  23.  
  24. @implementation Coordinator
  25.  
  26. id Inst = nil; 
  27.  
  28. + initialize
  29. {
  30.     Inst = [[Instrum alloc] init];
  31.     return self;
  32. }
  33.  
  34. - subprocessOutput:(char *)buffer
  35. {
  36.     [commandView appendString:buffer];
  37.     return self;
  38. }
  39. /*===============================================================*/
  40.  
  41. - subprocessDone
  42.     [NXApp terminate:self];
  43.     return self;
  44. }
  45.  
  46. - subprocessError:(const char *)errorString
  47.     // uses stringTable to localize error messages as appropriate,
  48.     // and then displays the message in an alert panel
  49. {
  50.     const char *returnedString;
  51.     
  52.     if (returnedString = [stringTable valueForStringKey:errorString])
  53.     {
  54.     NXRunAlertPanel(0, returnedString, 0, 0, 0);
  55.     }
  56.     else
  57.     {
  58.     NXRunAlertPanel(0, errorString, 0, 0, 0);
  59.     }
  60.     return self;
  61. }
  62.  
  63. - writeCode:(char *)buffer
  64. {
  65.     char instDir[80];
  66.     char instFile[80];
  67.     char cmdDir[80];
  68.     char cmixDir[80];
  69.     
  70.     strcpy(instFile,[instName stringValueAt:0]);
  71.     strcpy(instDir,[instPath stringValueAt:0]);
  72.     strcpy(cmdDir,[pathNames stringValueAt:4]);
  73.     strcpy(cmixDir,[pathNames stringValueAt:5]);
  74.     //printf("coordinator: writeCode\n");
  75.     [Inst writeCodeWithName:instFile andDir:instDir andCmd:cmdDir andCmix:cmixDir];
  76.     return self;
  77. }
  78.  
  79. - compileInst:(char *)buffer
  80. {
  81.     char str[300];
  82.     char instDir[80];
  83.     
  84.     strcpy(instDir,[instPath stringValueAt:0]);
  85.     sprintf(str,"cd %s;make", instDir);
  86.     //printf("str: %s\n",str);
  87.     theSubprocess =
  88.     [[Subprocess alloc]
  89.         init:str withDelegate:self andPtySupport:YES andStdErr:YES];
  90.     return self;
  91.  
  92. }
  93. - runIt:(char *)buffer
  94. {
  95.     char str[300];
  96.     char scoreFile[80];
  97.     char instDir[80];
  98.     char instFile[80];
  99.     char soundFile[80];
  100.     char soundDir[80];
  101.     char scoreDir[80];
  102.     char cmdDir[80];
  103.     long sr;
  104.     int  nchans;
  105.     
  106.     
  107.     strcpy(scoreFile,[pathNames stringValueAt:2]);
  108.     strcpy(scoreDir,[pathNames stringValueAt:3]);
  109.     strcpy(soundFile,[pathNames stringValueAt:0]);
  110.     strcpy(soundDir,[pathNames stringValueAt:1]);
  111.     strcpy(instFile,[instName stringValueAt:0]);
  112.     strcpy(instDir,[instPath stringValueAt:0]);
  113.     strcpy(cmdDir,[pathNames stringValueAt:4]);
  114.     if([sampRate selectedRow] == 0)
  115.         sr = 44100;
  116.     else
  117.         sr = 22050;
  118.     nchans = [numChans selectedRow] + 1;
  119.     sprintf(str,"%s/sfcreate -r %ld -c %d -f %s/%s;%s/%s < %s/%s.sco", cmdDir,sr,nchans,soundDir,soundFile,instDir,instFile,scoreDir,scoreFile);
  120.     //printf("str: %s\n",str);
  121.     theSubprocess =
  122.     [[Subprocess alloc]
  123.         init:str withDelegate:self andPtySupport:YES andStdErr:YES];
  124.     return self;
  125.  
  126. }
  127. - rescaleIt:(char *)buffer
  128. {
  129.     char str[200];
  130.     char soundFile[100];
  131.     char soundDir[80];
  132.     char cmdDir[80];
  133.     
  134.     strcpy(soundFile,[pathNames stringValueAt:0]);
  135.     strcpy(soundDir,[pathNames stringValueAt:1]);
  136.     strcpy(cmdDir,[pathNames stringValueAt:4]);
  137.     sprintf(str,"%s/rescale %s/%s", cmdDir, soundDir, soundFile);
  138.     //printf("str: %s\n",str);
  139.     theSubprocess =
  140.     [[Subprocess alloc]
  141.         init:str withDelegate:self andPtySupport:YES andStdErr:YES];
  142.     return self;
  143.  
  144. }
  145.  
  146. - playIt:(char *)buffer
  147. {
  148.     char str[200];
  149.     char soundFile[100];
  150.     char soundDir[80];
  151.     char cmdDir[80];
  152.     
  153.     strcpy(soundFile,[pathNames stringValueAt:0]);
  154.     strcpy(soundDir,[pathNames stringValueAt:1]);
  155.     strcpy(cmdDir,[pathNames stringValueAt:4]);
  156.     sprintf(str,"%s/play %s/%s.short", cmdDir, soundDir, soundFile);
  157.     //printf("str: %s\n",str);
  158.     theSubprocess =
  159.     [[Subprocess alloc]
  160.         init:str withDelegate:self andPtySupport:YES andStdErr:YES];
  161.     return self;
  162.  
  163. }
  164.  
  165. - writeScore:(char *)buffer
  166. {
  167.     int i;
  168.     char p[17][10];
  169.     char scoreFile[80];
  170.     char scoreDir[80];
  171.     char scofile[160];
  172.     char soundFile[80];
  173.     char soundDir[80];
  174.     char inst[80];
  175.     FILE *fp;
  176.         
  177.     strcpy(soundFile,[pathNames stringValueAt:0]);
  178.     strcpy(soundDir,[pathNames stringValueAt:1]);
  179.     strcpy(scoreFile, [pathNames stringValueAt:2]);
  180.     strcpy(scoreDir, [pathNames stringValueAt:3]);
  181.     strcpy(inst, [instName stringValueAt:0]);
  182.     sprintf(scofile, "%s/%s.sco", scoreDir, scoreFile);
  183.     for(i = 0; i < 17; i++) {
  184.         strcpy(p[i],[scoreData stringValueAt:i]);
  185.         //printf("%s %d %s\n",scofile,i,p[i]);
  186.     }
  187.  
  188.     fp = fopen(scofile,"w");
  189.     if(!fp) {
  190.         NXRunAlertPanel("write score:","This file can't be opened. Check out the directory. %s","OK",NULL,NULL,scofile);
  191.         return 0;
  192.     }
  193.     fprintf(fp,"output(\"%s/%s\",0)\n",soundDir,soundFile);
  194.     fprintf(fp,"sfclean(0)\n");
  195.     fprintf(fp,"makegen(1,10,1024,1)\n");         // sine
  196.     fprintf(fp,"makegen(2,7,512,0,512,1)\n");    // linear
  197.     fprintf(fp,"makegen(3,5,512,.01,512,1)\n");    // exponential
  198.     fprintf(fp,"%s(%s",inst,p[0]);
  199.     for(i = 1; i < 17; i++) {
  200.         if(strcmp("",p[i]))
  201.             fprintf(fp,", %s",p[i]);
  202.     }
  203.     fprintf(fp,")\n");
  204.  
  205.     fclose(fp);
  206.     return self;
  207. }
  208. @end
  209.