home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume6 / glib / part05 / dw8000.mnu < prev    next >
Text File  |  1989-05-14  |  11KB  |  548 lines

  1. /* $Id: dw8000.mnu,v 1.6 89/05/06 17:13:21 lee Exp $
  2.  * GLIB - a Generic LIBrarian and editor for synths
  3.  *
  4.  * DW8000 Librarian
  5.  *
  6.  * Code completed 8/24/87 --  Steven A. Falco  moss!saf
  7.  * modifications: Greg Lee
  8.  * $Log:    dw8000.mnu,v $
  9.  * Revision 1.6  89/05/06  17:13:21  lee
  10.  * rel. to comp.sources.misc
  11.  * 
  12.  */
  13.  
  14. #define OVERLAY2
  15.  
  16. #include "glib.h"
  17.  
  18. #define DW8VSIZE 51
  19.  
  20. char *visnum(), *visd8wave(), *visd8oct(), *visd8trk();
  21. char *visd8ival(), *visd8detu(), *visdasel(), *dw8vnum(), *visdamod();
  22. char *visdmgw(), *visdmode(), *visd8pol(),*visd8sem(), *visonoff();
  23.  
  24. #define RESERVESIZE 20
  25.  
  26. #define visdw8vnum dw8vnum
  27. /* This array contains arbitrary screen labels */
  28. struct labelinfo  Ldw800[] =  {
  29. #MENU
  30.  
  31.  
  32. +----------------------------------+----------------+------------------+------+
  33. |         Osc 1     Osc 2     Noise|          ModGen|          AutoBend| Mode |
  34. |Octave   %         %              |Waveform  %     |Select    %       |%     |
  35. |Waveform %         %              |Frequency %     |Mode      %       |      |
  36. |Level    %         %         %    |Delay     %     |Time      %       |      |
  37. |Interval           %              |Osc       %     |Intensity %       |      |
  38. |Detune             %              |VCF       %     |                  |      |
  39. +------------------+---------------+----------------+------------------+------+
  40. |          VCF  VCA|          Delay|    Joystick    |     Portamento   |Key   |
  41. |Attack    %    %  |Time      %    |Osc %           |Time %            |Param |
  42. |Decay     %    %  |Factor    %    |VCF %           |                  |%     |
  43. |Break Pt. %    %  |Feedback  %    +----------------+------------------+------+
  44. |Slope     %    %  |Frequency %    |
  45. |Sustain   %    %  |Intensity %    | +-------------------------+--------------+
  46. |Release   %    %  |Eff.Level %    | |Space = Play Note        | Auto-Note    |
  47. |V.Sensitv %    %  +---------------+ |                         |              |
  48. |Cutoff    %       |       AftTouch| |h = left   q = quit      |Pitch    %    |
  49. |Resonance %       |Osc.MG %       | |j = down   N = Set Name  |Duration %    |
  50. |Tracking  %       |VCF    %       | |k = up     J = Decrement |Volume   %    |
  51. |Polarity  %       |VCA    %       | |l = right  K = Increment |Channel  %    |
  52. |EG.Intens %       |               | |                         |              |
  53. +------------------+---------------+ +-------------------------+--------------+
  54. #END
  55. -1,-1,NULL
  56. };
  57.  
  58. /* This array defines all the editable parameters. */
  59. struct paraminfo  Pdw800[] =  {
  60. /*
  61. NAME        TYPE    POS    MAX    OFFSET    MASK    SHIFT    ADHOC
  62.  */
  63. #O o1oct    d8oct    %%    3    0
  64. #O o2oct    d8oct    %%    3    7
  65. #O mgwave    dmgw    %%    3    34
  66. #O abndsel    dasel    %%    3    3
  67. #O mode        dmode    %%    3    13
  68. #O o1wave    d8wave    %%    15    1
  69. #O o2wave    d8wave    %%    15    8
  70. #O mgfrew    num    %%    31    35
  71. #O abndmod    damod    %%    1    4
  72. #O o1lev    num    %%    31    2
  73. #O o2lev    num    %%    31    9
  74. #O noise    num    %%    31    12
  75. #O mgdela    num    %%    31    36
  76. #O abndtim    num    %%    31    5
  77. #O o2ival    d8ival    %%    7    10
  78. #O mgosc    num    %%    31    37
  79. #O abndins    num    %%    31    6
  80. #O o2detu    d8detu    %%    7    11
  81. #O mgvcf    num    %%    31    38
  82. #O fatt        num    %%    31    20
  83. #O aatt        num    %%    31    27
  84. #O dtim        num    %%    7    41
  85. #O joyosc    d8sem    %%    15    39
  86. #O portam    num    %%    31    47
  87. #O fdec        num    %%    31    21
  88. #O adec        num    %%    31    28
  89. #O dfact    num    %%    15    42
  90. #O joyvcf    onoff    %%    1    40
  91. #O vnumb    dw8vnum    %%    63    14
  92. #O fbrk        num    %%    31    22
  93. #O abrk        num    %%    31    29
  94. #O dfeed    num    %%    15    43
  95. #O fslp        num    %%    31    23
  96. #O aslp        num    %%    31    30
  97. #O dfreq    num    %%    31    44
  98. #O fsus        num    %%    31    24
  99. #O asus        num    %%    31    31
  100. #O dintns    num    %%    31    45
  101. #O frel        num    %%    31    25
  102. #O arel        num    %%    31    32
  103. #O deff        num    %%    15    46
  104. #O asens    num    %%    7    33
  105. #O fsens    num    %%    7    26
  106. #O fcut        num    %%    63    15
  107. #O autopitch    num    %%    127    -60
  108. #O fres        num    %%    31    16
  109. #O autovol    num    %%    127    -63
  110. #O atosc    num    %%    3    48
  111. #O ftrk        d8trk    %%    3    17
  112. #O autodur    num    %%    20    -5    *5
  113. #O atvcf    num    %%    3    49
  114. #O fpol        d8pol    %%    1    18
  115. #O autochan    num    %%    16    -1    *5
  116. #O atvca    num    %%    3    50
  117. #O fegi        num    %%    31    19
  118. NULL,NULL,-1,-1,-1,-1,visnum,0,0,0,0
  119. };
  120.  
  121.  
  122. /*
  123.  * dw8vnum
  124.  *
  125.  * Convert a voice number (0 to 63) to the string displayed in the
  126.  * librarian (ie. 11 to 88).
  127.  */
  128. /* added vis to beginning of this name -- gl */
  129. char *
  130. dw8vnum(n)
  131. {
  132.     static char v[3];
  133.  
  134.     if ( n < 0 || n > 63 )
  135.         return("??");
  136.  
  137.     v[0] = n/8 + '1';
  138.     v[1] = n%8 + '1';
  139.     v[2] = '\0';
  140.     return(v);
  141. }
  142.  
  143. /*
  144.  * dw8numv
  145.  *
  146.  * Convert a display-style voice number (11 to 88) to internal
  147.  * format (0 - 63).
  148.  */
  149.  
  150. dw8numv(n)
  151. int n;
  152. {
  153.     int ld, rd;
  154.     
  155.     /* crack out the digits as octal codes */
  156.     ld = (n / 10) - 1; /* left digit */
  157.     rd = (n % 10) - 1; /* right digit */
  158.     
  159.     if(ld < 0 || ld > 7 || rd < 0 || rd > 7) {
  160.         return(-1);
  161.     } else {
  162.         return(ld * 8 + rd); /* combine as octal */
  163.     }
  164. }
  165.  
  166. /*
  167.  * dw8din
  168.  *
  169.  * Take library bank 'data' and stuff values in the P array, by using
  170.  * the setval function.
  171.  */
  172.  
  173. dw8din(data)
  174. char *data;
  175. {
  176.     /* The first 20 bytes are reserved (arbitrarily) for the voice name */
  177. #SETVAL
  178.     /* We set the 'auto-note' channel upon entry */
  179.     setval("autochan",Channel);
  180. }
  181.  
  182. /*
  183.  * dw8dout
  184.  *
  185.  * Take (possibly changed) parameters values out of the P array and
  186.  * put them back into the library bank 'data'.
  187.  */
  188.  
  189. dw8dout(data)
  190. char *data;
  191. {
  192. #GETVAL
  193.     /* If the autochan parameter has changed, update Channel */
  194.     Channel = getval("autochan");
  195. }
  196.  
  197. /*
  198.  * dw8sedit
  199.  *
  200.  * Send a single voice to the edit buffer of the DW8000.  This will be whatever
  201.  * voice is currently selected.
  202.  */
  203.  
  204. dw8sedit(data)
  205. char *data;
  206. {
  207.     int n;
  208.     
  209.     sendmidi(0xf0);
  210.     sendmidi(0x42);
  211.     sendmidi(0x30 | (Channel - 1));
  212.     sendmidi(0x03);
  213.     sendmidi(0x40);
  214.     for(n = 0; n < DW8VSIZE; n++) {
  215.         sendmidi(data[n + 20] & 0x7f);
  216.     }
  217.     sendmidi(EOX);
  218. }
  219.  
  220. /*
  221.  * dw8nof
  222.  *
  223.  * Return a pointer to the voice name buried in library bank data.
  224.  */
  225. char *
  226. dw8nof(data)
  227. char *data;
  228. {
  229.     static char currbuff[17];
  230.     char *p;
  231.     int m;
  232.  
  233.     p = currbuff;
  234.     for ( m=0; m<16; m++ )
  235.         *p++ = data[m];
  236.     *p = '\0';
  237.     return(currbuff);
  238. }
  239.  
  240. /*
  241.  * dw8snof
  242.  *
  243.  * Set the voice name buried in data to name.
  244.  */
  245. dw8snof(data,name)
  246. char *data;
  247. char *name;
  248. {
  249.     char *p;
  250.     int m;
  251.  
  252.     for ( p=name,m=0; *p!='\0' && m<16; p++,m++ )
  253.         data[m] = *p;
  254.     for ( ; m<16; m++ )
  255.         data[m] = ' ';
  256. }
  257.  
  258. /* dw8sone - send a single voice to the DW8000 */
  259. dw8sone(iv, data)
  260. int iv;
  261. char *data;
  262. {
  263.     int c, b2, ret = 1;
  264.     long begin, toolong;
  265.  
  266.     /* select voice n */
  267.     sendmidi(0xc0 | (Channel - 1));
  268.     sendmidi(iv);
  269.     
  270.     /* send data */
  271.     dw8sedit(data);
  272.     
  273.     /* request write */
  274.     sendmidi(0xf0);
  275.     sendmidi(0x42);
  276.     sendmidi(0x30 | (Channel - 1));
  277.     sendmidi(0x03);
  278.     sendmidi(0x11);    /* write request */
  279.     sendmidi(iv);    /* the now-current voice */
  280.     sendmidi(EOX);
  281.     
  282.     /* read the ack/nack - set up for timeout */
  283.     begin = milliclock();
  284.     toolong = begin + 1000 * TIMEOUT;
  285.  
  286.     /* wait for the 0x03 byte (dw8000 ID byte) */
  287.     while ( milliclock() < toolong ) {
  288.         if ( STATMIDI && (c=(getmidi() & 0xff)) == 0x03 )
  289.             break;
  290.     }
  291.     if ( c != 0x03 ) {
  292.         Reason = "Timeout waiting for 0x03";
  293.         goto getout;
  294.     }
  295.     
  296.     /* next byte is the result code */
  297.     while((b2 = getmidi() & 0xff) == 0xfe)
  298.         ; /* burn active sensing */
  299.     if(b2 != 0x21) {
  300.         Reason = "Write failed - check protect switch!";
  301.         goto getout;
  302.     }
  303.  
  304.     while((b2 = getmidi() & 0xff) == 0xfe)
  305.         ;    /* want EOX - burn active sensing */
  306.     if ( b2 != EOX )
  307.         Reason = "EOX not received";
  308.     else {
  309.         Reason = "";
  310.         ret = 0;    /* all's well */
  311.     }
  312.     
  313. getout:
  314.     return(ret);
  315. }
  316.  
  317. /* dw8gbulk - Request and read a bulk dump from the DW8000 */
  318. dw8gbulk(data)
  319. char *data;
  320. {
  321.     int c, n, v, b2, ret = 1;
  322.     long begin, toolong;
  323.  
  324.     flushmidi();
  325.  
  326.     for(v = 0; v < Nvoices; v++) {
  327.         /* select voice */
  328.         sendmidi(0xc0 | (Channel - 1));
  329.         sendmidi(v);
  330.         
  331.         /* request the voice */
  332.         sendmidi(0xf0);
  333.         sendmidi(0x42);
  334.         sendmidi(0x30 | (Channel-1));    /* Channel # */
  335.         sendmidi(0x03);
  336.         sendmidi(0x10);    
  337.         sendmidi(EOX);
  338.     
  339.         /* set up for timeout */
  340.         begin = milliclock();
  341.         toolong = begin + 1000 * TIMEOUT;
  342.     
  343.         /* wait for the x40 byte starting the dump */
  344.         while ( milliclock() < toolong ) {
  345.             if ( STATMIDI && (c=(getmidi() & 0xff)) == 0x40 )
  346.                 break;
  347.         }
  348.         if ( c != 0x40 ) {
  349.             Reason = "Timeout waiting for 0x40";
  350.             goto getout;
  351.         }
  352.         
  353.         /* now read 51 bytes of voice data */
  354.         for(n = 0; n < DW8VSIZE; n++) {
  355.             /* twiddle your thumbs, but not forever */
  356.             while ( ! STATMIDI ) {
  357.                 if ( milliclock() > toolong )
  358.                     goto timeout;    /* the end of an era */
  359.             }
  360.             while((b2 = getmidi() & 0xff) == 0xfe)
  361.                 ; /* burn active sensing */
  362.             VOICEBYTE(data,v,n + 20) = b2;    
  363.         }
  364.  
  365.     timeout:
  366.         if ( n != DW8VSIZE ) {
  367.             Reason = "Timeout while reading!";
  368.             goto getout;
  369.         }
  370.         while((b2 = getmidi() & 0xff) == 0xfe)
  371.             ;    /* want EOX - burn active sensing */
  372.         if ( b2 != EOX )
  373.             Reason = "EOX not received";
  374.         else {
  375.             Reason = "";
  376.             ret = 0;    /* all's well */
  377.         }
  378.     } /* go back for another voice */
  379.     
  380. getout:
  381.     return(ret);
  382. }
  383.  
  384. /*
  385.  * Below are functions used for display of parameter values
  386.  */
  387.  
  388. char *
  389. visd8wave(v)
  390. {
  391.     switch (v) {
  392.     case 0: return("ramp");
  393.     case 1: return("square");
  394.     case 2: return("ac. piano");
  395.     case 3: return("el. piano");
  396.     case 4: return("hd. piano");
  397.     case 5: return("clavinet");
  398.     case 6: return("organ");
  399.     case 7: return("brass");
  400.     case 8: return("sax");
  401.     case 9: return("violin");
  402.     case 10: return("a. guitar");
  403.     case 11: return("d. guitar");
  404.     case 12: return("el. bass");
  405.     case 13: return("dg. bass");
  406.     case 14: return("bell");
  407.     case 15: return("sine");
  408.     }
  409.     return("*");
  410. }
  411.  
  412. char *
  413. visd8oct(v)
  414. {
  415.     switch(v) {
  416.     case 0: return("16");
  417.     case 1: return("8");
  418.     case 2: return("4");
  419.     case 3: return("*");
  420.     }
  421.     return("*");
  422. }
  423.  
  424. char *
  425. visd8ival(v)
  426. {    
  427.     switch(v) {
  428.     case 0: return("unison");
  429.     case 1: return("min 3rd");
  430.     case 2: return("maj 3rd");
  431.     case 3: return("4th");
  432.     case 4: return("5th");
  433.     case 5: case 6: case 7: return("*");
  434.     }
  435.     return("*");
  436. }
  437.  
  438. char *
  439. visd8detu(v)
  440. {
  441.     switch(v) {
  442.     case 0: return("in tune");
  443.     case 1: return("1 cent");
  444.     case 2: return("2 cents");
  445.     case 3: return("3 cents");
  446.     case 4: return("4 cents");
  447.     case 5: return("5 cents");
  448.     case 6: return("6 cents");
  449.     case 7: return("*");
  450.     }
  451.     return("*");
  452. }
  453.  
  454. char *Semicode[] = {
  455.     "none",
  456.     "1 semitone",
  457.     "2 semitones",
  458.     "3 semitones",
  459.     "4 semitones",
  460.     "5 semitones",
  461.     "6 semitones",
  462.     "7 semitones",
  463.     "8 semitones",
  464.     "9 semitones",
  465.     "10 semitones",
  466.     "11 semitones",
  467.     "1 octave"
  468. };
  469.  
  470. char *
  471. visd8sem(v)
  472. {
  473.     if(v >= 0 && v <= 12) {
  474.         return(Semicode[v]);
  475.     }
  476.     return("*");
  477. }
  478.  
  479. char *
  480. visdasel(v)
  481. {
  482.     switch(v) {
  483.     case 0: return("off");
  484.     case 1: return("Osc 1");
  485.     case 2: return("Osc 2");
  486.     case 3: return("Osc 1+2");
  487.     }
  488.     return("*");
  489. }
  490.  
  491. char *
  492. visdamod(v)
  493. {
  494.     switch(v) {
  495.     case 0: return("Up");
  496.     case 1: return("Down");
  497.     }
  498.     return("*");
  499. }
  500.  
  501. char *
  502. visd8pol(v)
  503. {
  504.     switch(v) {
  505.     case 0: return("/-\\");
  506.     case 1: return("\\_/");
  507.     }
  508.     return("*");
  509. }
  510.  
  511. char *
  512. visdmode(v)
  513. {
  514.     switch(v) {
  515.     case 0: return("Poly 1");
  516.     case 1: return("Poly 2");
  517.     case 2: return("Uni 1");
  518.     case 3: return("Uni 2");
  519.     }
  520.     return("*");
  521. }
  522.  
  523. char *
  524. visdmgw(v)
  525. {
  526.     switch(v) {
  527.     case 0: return("/\\");
  528.     case 1: return("|\\");
  529.     case 2: return("/|");
  530.     case 3: return("_|-|");
  531.     }
  532.     return("*");
  533. }
  534.  
  535. char *
  536. visd8trk(v)
  537. {
  538.     switch(v) {
  539.     case 0: return("0");
  540.     case 1: return("1/4");
  541.     case 2: return("1/2");
  542.     case 3: return("1");
  543.     }
  544.     return("*");
  545. }
  546.  
  547. /* end */
  548.