home *** CD-ROM | disk | FTP | other *** search
Java Source | 2017-09-21 | 8.3 KB | 253 lines |
- /*
- typedef enum {
- final static int DIM_COHESION=0;
- final static int DIM_KEY=1;
- final static int DIM_NUM_LAYERS=2;
- final static int DIM_RTHM_CONSISTENCY=3;
- final static int DIM_RTHM_DENSITY=4;
- final static int DIM_RTHM_LENGTH=5;
- final static int DIM_SCALE=6;
- final static int DIM_SECTION_CHANGE=7;
- final static int DIM_TEMPO=8;
- } DIM_NAME; // Hungarian: dim
- typedef enum {
- final static int LDIM_ACTIVE=0;
- final static int LDIM_CONSONANCE=1;
- final static int LDIM_DIRECTION=2;
- final static int LDIM_INSTRUMENT=3;
- final static int LDIM_PITCH_MAGNET=4;
- final static int LDIM_RTHM_CONSISTENCY=5;
- final static int LDIM_RTHM_DENSITY=6;
- final static int LDIM_RTHM_LENGTH=7;
- final static int LDIM_RTHM_STYLE=8;
- final static int LDIM_RTHM_STYLE_ARG=9;
- final static int LDIM_TEMPO=10;
- } LAYER_DIM_NAME; // Hungarian: ldim
- */
-
- public class CGenPoint
- { // constants
- final static int DIM_COHESION=0;
- final static int DIM_KEY=1;
- final static int DIM_NUM_LAYERS=2;
- final static int DIM_RTHM_CONSISTENCY=3;
- final static int DIM_RTHM_DENSITY=4;
- final static int DIM_RTHM_LENGTH=5;
- final static int DIM_SCALE=6;
- final static int DIM_SECTION_CHANGE=7;
- final static int DIM_TEMPO=8;
- // More constants
- final static int LDIM_ACTIVE=0;
- final static int LDIM_CONSONANCE=1;
- final static int LDIM_DIRECTION=2;
- final static int LDIM_INSTRUMENT=3;
- final static int LDIM_PITCH_MAGNET=4;
- final static int LDIM_RTHM_CONSISTENCY=5;
- final static int LDIM_RTHM_DENSITY=6;
- final static int LDIM_RTHM_LENGTH=7;
- final static int LDIM_RTHM_STYLE=8;
- final static int LDIM_RTHM_STYLE_ARG=9;
- final static int LDIM_TEMPO=10;
- final static int NUM_KEYS = 12;
-
- static CSection g_secTest;
- //======bogus global functions=====
- static public void assert(boolean b) { if (!b) (new int[1])[-1] = 0; }
- static public int rand() { return (int)(Math.random() * 9747); }
- //================================
- // Operations
- //-----------------------
- public static int iRandomTweak ()
- {
- int iTarget = rand() % 13;
- switch (iTarget) {
- case 0: return iSetCoord(DIM_COHESION, (char)(rand()%80 + 10));
- case 1: return iSetCoord(DIM_KEY, (char)(rand()%NUM_KEYS));
- case 2: return iSetCoord(DIM_SCALE, (char)(rand()%120));
- case 3: return iSetCoord(DIM_TEMPO, (char)(rand()%64 + 18));
- //(rand()%127 + 1 + pvGetCoord(DIM_TEMPO))/2);
- case 4: return iSetCoord(DIM_RTHM_CONSISTENCY, (char)(rand()%128));
- case 5: return iSetCoord(DIM_RTHM_DENSITY, (char)(rand()%88 + 20));
- case 6: return iSetCoord(DIM_RTHM_LENGTH, (char)(rand()%30 + 5));
- }
- int iLayer = rand() % pvGetCoord(DIM_NUM_LAYERS);
- switch (iTarget) {
- case 7: return iSetLayerCoord(LDIM_CONSONANCE, iLayer, (char)(rand()%50 + 25));
- case 8: return iSetLayerCoord(LDIM_DIRECTION, iLayer, (char)(rand()%40 + 40));
- case 9: return 1;//iSetLayerCoord(LDIM_INSTRUMENT, iLayer, (char)(rand()%128));
- case 10: return iSetLayerCoord(LDIM_PITCH_MAGNET, iLayer, (char)(rand()%24 + 45));
- case 11: if (0==iSetLayerCoord(LDIM_RTHM_STYLE, iLayer, (char)(rand()%4)))
- return 0; // Else keep going:
- }
- assert(iTarget == 11 || iTarget == 12);
- switch (pvGetLayerCoord(LDIM_RTHM_STYLE, iLayer)) {
- case 0: return iSetLayerCoord(LDIM_RTHM_STYLE_ARG, iLayer, (char)(rand()%42));
- case 1: return iSetLayerCoord(LDIM_RTHM_STYLE, iLayer, (char)3); // Between.normal
- case 2: return iSetLayerCoord(LDIM_RTHM_STYLE_ARG, iLayer, (char)(rand()%64 +20));
- case 3: return 1;
- }
- assert(false);
- return 0;
- }
-
- // Access to dimension coordinates:
- //-----------------------
- public static char pvGetCoord (int dim)
- {
- switch (dim) {
- case DIM_COHESION:
- return g_secTest.pvGetCohesion();
- case DIM_KEY:
- return g_secTest.pvGetKey();
- case DIM_NUM_LAYERS:
- return (char)g_secTest.pstzGetPrevStanza(1).iNumLayers();
- case DIM_SCALE:
- return g_secTest.sclGetScale().pvGet();
- case DIM_SECTION_CHANGE:
- return g_secTest.pvChangeRate();
- case DIM_TEMPO:
- { double f = g_secTest.pstzGetPrevStanza(1).
- rthmGetRhythm(0).pvGetTempo() - 1;
- return (char)(int)(.5 + f*127.0/11.0);
- }
- default: assert(false); break;
- }
- assert(false);
- return (char)0;
- }
- //-----------------------
- public static int iSetCoord (int dim, char pvNewCoord)
- {
- switch (dim) {
- case DIM_COHESION:
- g_secTest.SetCohesion(pvNewCoord);
- return 1;
-
- case DIM_KEY: g_secTest.SetKey(pvNewCoord);
- break;
-
- case DIM_RTHM_CONSISTENCY:
- { CStanza pStz = g_secTest.pstzGetPrevStanza(1);
- CRhythm rthm = pStz.rthmGetRhythm(0);
- if (!rthm.bGenerate((char)0,(char)0,pvNewCoord)) return 0;
- for (int C = 1; C<pStz.iNumLayers(); C++)
- if (!pStz.rthmGetRhythm(C).bSet(rthm)) return 0;
- break;
- }
- case DIM_RTHM_DENSITY:
- { CStanza pStz = g_secTest.pstzGetPrevStanza(1);
- CRhythm rthm = pStz.rthmGetRhythm(0);
- if (!rthm.bGenerate(pvNewCoord,(char)0,(char)0)) return 0;
- for (int C = 1; C<pStz.iNumLayers(); C++)
- if (!pStz.rthmGetRhythm(C).bSet(rthm)) return 0;
- break;
- }
- case DIM_RTHM_LENGTH:
- { CStanza pStz = g_secTest.pstzGetPrevStanza(1);
- CRhythm rthm = pStz.rthmGetRhythm(0);
- if (!rthm.bGenerate((char)0,pvNewCoord,(char)0)) return 0;
- for (int C = 1; C<pStz.iNumLayers(); C++)
- if (!pStz.rthmGetRhythm(C).bSet(rthm)) return 0;
- break;
- }
- case DIM_SCALE:
- return g_secTest.sclGetScale().bSet2(pvNewCoord) ?1:0;
- case DIM_SECTION_CHANGE:
- return g_secTest.bSetChangeRate(pvNewCoord) ?1:0;
-
- case DIM_TEMPO:
- pvNewCoord = (char)(int)(1.5 + 11.0*(float)(pvNewCoord)/127.0);
- return g_secTest.bSetCurrentTempo(pvNewCoord, -1)?1:0;
-
- default: assert(false); break;
- }
- return 1;
- }
-
- //-----------------------
- public static char pvGetLayerCoord (int dim,
- int iLayerNum)
- {
- switch (dim) {
- case LDIM_ACTIVE:
- return g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).bActive() ?(char)1:(char)0;
- case LDIM_CONSONANCE:
- return g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).pvConsonance();
- case LDIM_DIRECTION:
- return g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).pvDirection();
- case LDIM_INSTRUMENT:
- return g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).pvInstrument();
- case LDIM_PITCH_MAGNET:
- return g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).pvPitchMagnet();
-
- case LDIM_RTHM_CONSISTENCY:
- return g_secTest.pstzGetPrevStanza(1).
- rthmGetRhythm(iLayerNum).pvConsistency();
- case LDIM_RTHM_DENSITY:
- return g_secTest.pstzGetPrevStanza(1).
- rthmGetRhythm(iLayerNum).pvDensity();
- case LDIM_RTHM_LENGTH:
- return g_secTest.pstzGetPrevStanza(1).
- rthmGetRhythm(iLayerNum).pvLength();
-
- case LDIM_RTHM_STYLE:
- return (char)(int)g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).rymodRthmStatus();
- case LDIM_RTHM_STYLE_ARG:
- return g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).pvRthmStatusArg();
- default: assert(false); break;
- }
- assert(false);
- return (char)0;
- }
- //-----------------------
- public static int iSetLayerCoord (int dim, int iLayerNum,
- char pvNewCoord)
- {
- switch (dim) {
- case LDIM_ACTIVE:
- return g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).bSetActive((char)0!=pvNewCoord)
- ?1:0;
- case LDIM_CONSONANCE:
- return g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).bSetConsonance(pvNewCoord)
- ?1:0;
- case LDIM_DIRECTION:
- return g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).bSetDirection(pvNewCoord)?1:0;
- case LDIM_INSTRUMENT:
- return g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).bSetInstrument(pvNewCoord)?1:0;
- case LDIM_PITCH_MAGNET:
- return g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).bSetPitchMagnet(pvNewCoord)?1:0;
-
- case LDIM_RTHM_CONSISTENCY:
- return g_secTest.pstzGetPrevStanza(1).
- rthmGetRhythm(iLayerNum).bGenerate((char)0,(char)0,pvNewCoord)?1:0;
- case LDIM_RTHM_DENSITY:
- return g_secTest.pstzGetPrevStanza(1).
- rthmGetRhythm(iLayerNum).bGenerate(pvNewCoord,(char)0,(char)0)?1:0;
- case LDIM_RTHM_LENGTH:
- return g_secTest.pstzGetPrevStanza(1).
- rthmGetRhythm(iLayerNum).bGenerate((char)0,pvNewCoord,(char)0)?1:0;
-
- case LDIM_RTHM_STYLE:
- return g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).
- bSetRthmStatus((int)pvNewCoord)?1:0;
- case LDIM_RTHM_STYLE_ARG:
- return g_secTest.pstzGetPrevStanza(1).
- plyrGetLayer(iLayerNum).bSetRthmStatusArg(pvNewCoord)?1:0;
- default: assert(false); break;
- }
- return 1;
- }
- } // end class