home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / Cdrom / Pavilions / BrainOpera / online / net-music / net-instrument / CGenPoint.java < prev    next >
Encoding:
Java Source  |  2017-09-21  |  8.3 KB  |  253 lines

  1. /*
  2.     typedef enum {
  3.     final static int DIM_COHESION=0;
  4.     final static int DIM_KEY=1;
  5.     final static int DIM_NUM_LAYERS=2;
  6.     final static int DIM_RTHM_CONSISTENCY=3;
  7.     final static int DIM_RTHM_DENSITY=4;
  8.     final static int DIM_RTHM_LENGTH=5;
  9.     final static int DIM_SCALE=6;
  10.     final static int DIM_SECTION_CHANGE=7;
  11.     final static int DIM_TEMPO=8;
  12.     } DIM_NAME;    // Hungarian: dim
  13.     typedef enum {
  14.     final static int LDIM_ACTIVE=0;
  15.     final static int LDIM_CONSONANCE=1;
  16.     final static int LDIM_DIRECTION=2;
  17.     final static int LDIM_INSTRUMENT=3;
  18.     final static int LDIM_PITCH_MAGNET=4;
  19.     final static int LDIM_RTHM_CONSISTENCY=5;
  20.     final static int LDIM_RTHM_DENSITY=6;
  21.     final static int LDIM_RTHM_LENGTH=7;
  22.     final static int LDIM_RTHM_STYLE=8;
  23.     final static int LDIM_RTHM_STYLE_ARG=9;
  24.     final static int LDIM_TEMPO=10;
  25.     } LAYER_DIM_NAME;    // Hungarian: ldim
  26. */
  27.  
  28. public class CGenPoint
  29. {    // constants
  30.     final static int DIM_COHESION=0;
  31.     final static int DIM_KEY=1;
  32.     final static int DIM_NUM_LAYERS=2;
  33.     final static int DIM_RTHM_CONSISTENCY=3;
  34.     final static int DIM_RTHM_DENSITY=4;
  35.     final static int DIM_RTHM_LENGTH=5;
  36.     final static int DIM_SCALE=6;
  37.     final static int DIM_SECTION_CHANGE=7;
  38.     final static int DIM_TEMPO=8;
  39.     // More constants
  40.     final static int LDIM_ACTIVE=0;
  41.     final static int LDIM_CONSONANCE=1;
  42.     final static int LDIM_DIRECTION=2;
  43.     final static int LDIM_INSTRUMENT=3;
  44.     final static int LDIM_PITCH_MAGNET=4;
  45.     final static int LDIM_RTHM_CONSISTENCY=5;
  46.     final static int LDIM_RTHM_DENSITY=6;
  47.     final static int LDIM_RTHM_LENGTH=7;
  48.     final static int LDIM_RTHM_STYLE=8;
  49.     final static int LDIM_RTHM_STYLE_ARG=9;
  50.     final static int LDIM_TEMPO=10;
  51.     final static int NUM_KEYS = 12;
  52.  
  53.     static CSection g_secTest;
  54. //======bogus global functions=====
  55. static public void assert(boolean b) { if (!b) (new int[1])[-1] = 0; }
  56. static public int rand() { return (int)(Math.random() * 9747); }
  57. //================================
  58. // Operations
  59. //-----------------------
  60. public static int iRandomTweak ()
  61. {
  62.     int iTarget = rand() % 13;
  63.     switch (iTarget) {
  64.     case 0: return iSetCoord(DIM_COHESION, (char)(rand()%80 + 10));
  65.     case 1: return iSetCoord(DIM_KEY, (char)(rand()%NUM_KEYS));
  66.     case 2: return iSetCoord(DIM_SCALE, (char)(rand()%120));
  67.     case 3: return iSetCoord(DIM_TEMPO, (char)(rand()%64 + 18));
  68.         //(rand()%127 + 1 + pvGetCoord(DIM_TEMPO))/2);
  69.     case 4:    return iSetCoord(DIM_RTHM_CONSISTENCY, (char)(rand()%128));
  70.     case 5: return iSetCoord(DIM_RTHM_DENSITY, (char)(rand()%88 + 20));
  71.     case 6:    return iSetCoord(DIM_RTHM_LENGTH, (char)(rand()%30 + 5));
  72.     }
  73.     int iLayer = rand() % pvGetCoord(DIM_NUM_LAYERS);
  74.     switch (iTarget) {
  75.     case 7: return iSetLayerCoord(LDIM_CONSONANCE, iLayer, (char)(rand()%50 + 25));
  76.     case 8: return iSetLayerCoord(LDIM_DIRECTION, iLayer, (char)(rand()%40 + 40));
  77.     case 9: return 1;//iSetLayerCoord(LDIM_INSTRUMENT, iLayer, (char)(rand()%128));
  78.     case 10: return iSetLayerCoord(LDIM_PITCH_MAGNET, iLayer, (char)(rand()%24 + 45));
  79.     case 11: if (0==iSetLayerCoord(LDIM_RTHM_STYLE, iLayer, (char)(rand()%4)))
  80.                  return 0;    // Else keep going:
  81.     }
  82.     assert(iTarget == 11 || iTarget == 12);
  83.     switch (pvGetLayerCoord(LDIM_RTHM_STYLE, iLayer)) {
  84.     case 0: return iSetLayerCoord(LDIM_RTHM_STYLE_ARG, iLayer, (char)(rand()%42));
  85.     case 1: return iSetLayerCoord(LDIM_RTHM_STYLE, iLayer, (char)3);    // Between.normal
  86.     case 2: return iSetLayerCoord(LDIM_RTHM_STYLE_ARG, iLayer, (char)(rand()%64 +20));
  87.     case 3: return 1;
  88.     }
  89.     assert(false);
  90.     return 0;
  91. }
  92.  
  93. // Access to dimension coordinates:
  94. //-----------------------
  95. public static char pvGetCoord (int dim)
  96. {
  97.     switch (dim) {
  98.     case DIM_COHESION:
  99.         return g_secTest.pvGetCohesion();
  100.     case DIM_KEY:
  101.         return g_secTest.pvGetKey();
  102.     case DIM_NUM_LAYERS:
  103.         return (char)g_secTest.pstzGetPrevStanza(1).iNumLayers();
  104.     case DIM_SCALE:
  105.         return g_secTest.sclGetScale().pvGet();
  106.     case DIM_SECTION_CHANGE:
  107.         return g_secTest.pvChangeRate();
  108.     case DIM_TEMPO:
  109.     {    double f = g_secTest.pstzGetPrevStanza(1).
  110.             rthmGetRhythm(0).pvGetTempo() - 1;
  111.         return (char)(int)(.5 + f*127.0/11.0);
  112.     }
  113.     default: assert(false); break;
  114.     }
  115.     assert(false);
  116.     return (char)0;
  117. }
  118. //-----------------------
  119. public static int iSetCoord (int dim, char pvNewCoord)
  120. {
  121.     switch (dim) {
  122.     case DIM_COHESION:
  123.         g_secTest.SetCohesion(pvNewCoord);
  124.         return 1;
  125.         
  126.     case DIM_KEY:    g_secTest.SetKey(pvNewCoord);
  127.         break;
  128.     
  129.     case DIM_RTHM_CONSISTENCY:
  130.     {    CStanza pStz = g_secTest.pstzGetPrevStanza(1);
  131.         CRhythm rthm = pStz.rthmGetRhythm(0);
  132.         if (!rthm.bGenerate((char)0,(char)0,pvNewCoord)) return 0;
  133.         for (int C = 1; C<pStz.iNumLayers(); C++)
  134.             if (!pStz.rthmGetRhythm(C).bSet(rthm)) return 0;
  135.         break;
  136.     }
  137.     case DIM_RTHM_DENSITY:
  138.     {    CStanza pStz = g_secTest.pstzGetPrevStanza(1);
  139.         CRhythm rthm = pStz.rthmGetRhythm(0);
  140.         if (!rthm.bGenerate(pvNewCoord,(char)0,(char)0)) return 0;
  141.         for (int C = 1; C<pStz.iNumLayers(); C++)
  142.             if (!pStz.rthmGetRhythm(C).bSet(rthm)) return 0;
  143.         break;
  144.     }
  145.     case DIM_RTHM_LENGTH:
  146.     {    CStanza pStz = g_secTest.pstzGetPrevStanza(1);
  147.         CRhythm rthm = pStz.rthmGetRhythm(0);
  148.         if (!rthm.bGenerate((char)0,pvNewCoord,(char)0)) return 0;
  149.         for (int C = 1; C<pStz.iNumLayers(); C++)
  150.             if (!pStz.rthmGetRhythm(C).bSet(rthm)) return 0;
  151.         break;
  152.     }
  153.     case DIM_SCALE:
  154.         return g_secTest.sclGetScale().bSet2(pvNewCoord) ?1:0;
  155.     case DIM_SECTION_CHANGE:
  156.         return g_secTest.bSetChangeRate(pvNewCoord) ?1:0;
  157.         
  158.     case DIM_TEMPO:
  159.         pvNewCoord = (char)(int)(1.5 + 11.0*(float)(pvNewCoord)/127.0);
  160.         return g_secTest.bSetCurrentTempo(pvNewCoord, -1)?1:0;
  161.         
  162.     default: assert(false); break;
  163.     }
  164.     return 1;
  165. }
  166.     
  167. //-----------------------
  168. public static char pvGetLayerCoord (int dim,
  169.         int iLayerNum)
  170. {
  171.     switch (dim) {
  172.     case LDIM_ACTIVE:
  173.         return g_secTest.pstzGetPrevStanza(1).
  174.             plyrGetLayer(iLayerNum).bActive() ?(char)1:(char)0;
  175.     case LDIM_CONSONANCE:
  176.         return g_secTest.pstzGetPrevStanza(1).
  177.             plyrGetLayer(iLayerNum).pvConsonance();
  178.     case LDIM_DIRECTION:
  179.         return g_secTest.pstzGetPrevStanza(1).
  180.             plyrGetLayer(iLayerNum).pvDirection();
  181.     case LDIM_INSTRUMENT:
  182.         return g_secTest.pstzGetPrevStanza(1).
  183.             plyrGetLayer(iLayerNum).pvInstrument();
  184.     case LDIM_PITCH_MAGNET:
  185.         return g_secTest.pstzGetPrevStanza(1).
  186.             plyrGetLayer(iLayerNum).pvPitchMagnet();
  187.  
  188.     case LDIM_RTHM_CONSISTENCY:
  189.         return g_secTest.pstzGetPrevStanza(1).
  190.             rthmGetRhythm(iLayerNum).pvConsistency();
  191.     case LDIM_RTHM_DENSITY:
  192.         return g_secTest.pstzGetPrevStanza(1).
  193.             rthmGetRhythm(iLayerNum).pvDensity();
  194.     case LDIM_RTHM_LENGTH:
  195.         return g_secTest.pstzGetPrevStanza(1).
  196.             rthmGetRhythm(iLayerNum).pvLength();
  197.  
  198.     case LDIM_RTHM_STYLE:
  199.         return (char)(int)g_secTest.pstzGetPrevStanza(1).
  200.             plyrGetLayer(iLayerNum).rymodRthmStatus();
  201.     case LDIM_RTHM_STYLE_ARG:
  202.         return g_secTest.pstzGetPrevStanza(1).
  203.             plyrGetLayer(iLayerNum).pvRthmStatusArg();
  204.     default: assert(false); break;
  205.     }
  206.     assert(false);
  207.     return (char)0;
  208. }
  209. //-----------------------
  210. public static int iSetLayerCoord (int dim, int iLayerNum,
  211.         char pvNewCoord)
  212. {
  213.     switch (dim) {
  214.     case LDIM_ACTIVE:
  215.         return g_secTest.pstzGetPrevStanza(1).
  216.             plyrGetLayer(iLayerNum).bSetActive((char)0!=pvNewCoord)
  217.             ?1:0;
  218.     case LDIM_CONSONANCE:
  219.         return g_secTest.pstzGetPrevStanza(1).
  220.             plyrGetLayer(iLayerNum).bSetConsonance(pvNewCoord)
  221.             ?1:0;
  222.     case LDIM_DIRECTION:
  223.         return g_secTest.pstzGetPrevStanza(1).
  224.             plyrGetLayer(iLayerNum).bSetDirection(pvNewCoord)?1:0;
  225.     case LDIM_INSTRUMENT:
  226.         return g_secTest.pstzGetPrevStanza(1).
  227.             plyrGetLayer(iLayerNum).bSetInstrument(pvNewCoord)?1:0;
  228.     case LDIM_PITCH_MAGNET:
  229.         return g_secTest.pstzGetPrevStanza(1).
  230.             plyrGetLayer(iLayerNum).bSetPitchMagnet(pvNewCoord)?1:0;
  231.  
  232.     case LDIM_RTHM_CONSISTENCY:
  233.         return g_secTest.pstzGetPrevStanza(1).
  234.             rthmGetRhythm(iLayerNum).bGenerate((char)0,(char)0,pvNewCoord)?1:0;
  235.     case LDIM_RTHM_DENSITY:
  236.         return g_secTest.pstzGetPrevStanza(1).
  237.             rthmGetRhythm(iLayerNum).bGenerate(pvNewCoord,(char)0,(char)0)?1:0;
  238.     case LDIM_RTHM_LENGTH:
  239.         return g_secTest.pstzGetPrevStanza(1).
  240.             rthmGetRhythm(iLayerNum).bGenerate((char)0,pvNewCoord,(char)0)?1:0;
  241.             
  242.     case LDIM_RTHM_STYLE:
  243.         return g_secTest.pstzGetPrevStanza(1).
  244.             plyrGetLayer(iLayerNum).
  245.                 bSetRthmStatus((int)pvNewCoord)?1:0;
  246.     case LDIM_RTHM_STYLE_ARG:
  247.         return g_secTest.pstzGetPrevStanza(1).
  248.             plyrGetLayer(iLayerNum).bSetRthmStatusArg(pvNewCoord)?1:0;
  249.     default:    assert(false); break;
  250.     }
  251.     return 1;
  252. }
  253. }    // end class