home *** CD-ROM | disk | FTP | other *** search
Java Source | 2017-09-21 | 24.0 KB | 667 lines |
- import java.util.Hashtable;
- import java.util.Enumeration;
- import java.util.BitSet;
- import java.util.Date;
-
- import java.io.*;
- import java.awt.*;
- import java.net.*;
- import java.applet.Applet;
-
- import java.lang.Math; // sin, cos
-
- // Next time: extend everything off a static global class
-
- public class Sharle extends Applet implements Runnable
- {
- Thread m_thread = null;
- int m_iLayerNumber = -1;
- int m_iMMUDRed=128, m_iMMUDGreen=128, m_iMMUDBlue=128;
- int m_iBaseRed=128, m_iBaseGreen=128, m_iBaseBlue=128;
- int m_x=0, m_y=0; double m_fMM=0, m_fUD=0;
- boolean m_bClearDots=false;
- Image offscreenImage;
- Graphics offscreenGraphics;
-
- RectButton m_rbMain, m_rbBlue, m_rbGreen, m_rbRed, m_rbViolet;
- final static int g_iNumParams=16;
- RectSlider marr_rsParams[];
-
- CMIDI m_midi;
-
- // Constants
- int SECOND = 1000;
- int BEATS_PER_SEC = 24;
- int BEAT_TIME = (SECOND/BEATS_PER_SEC);
-
- static int g_iMinWidth = 40;
- static double g_fBorderWidth = .15, g_fBorderHeight = .15; // With respect to applet
- static double g_f4ColorDim = .25; // With respect to border
- static double g_fSliderWidth = .15; // With respect to distance b/w sliders
-
- static int g_i4ColorWidth = 20, g_iWidthSliders = 10;
- static int g_iMinHeight = 10;
- static int g_iWindowWidth;
- static int g_iWindowHeight;
- static int g_iMainWidth;
-
- // Globals
- int g_iLastTime = -1;
- int sm_iMIDIvolume = 64;
-
- final int BST_NO_NOTE=0; // No note on this beat
- final int BST_WHISPER=1;
- final int BST_LIGHT=2; // Faint note
- final int BST_MEDIUM=3; // Normal note
- final int BST_HEAVY=4; // Emphsized note
- final int BST_BANG=5;
- // 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;
-
- void assert (boolean b) { if (!b) (new int[1])[-1] = 0; }
-
- //---------------------------------------------
- public int iGetParameter (String str)
- { return (new Integer(getParameter(str))).intValue(); }
- //---------------------------------------------
-
- public void initGUI ()
- { //resize(g_iWindowWidth, g_iWindowHeight);
- int iWidth = this.size().width;
- int iHeight = this.size().height;
- m_x = iWidth/2; m_y = iHeight/2;
- m_fMM=0.5; m_fUD=0.5;
-
- offscreenImage = createImage(iWidth,iHeight);
- offscreenGraphics = offscreenImage.getGraphics();
-
- if (iWidth > g_iMinWidth) g_iWindowWidth = iWidth;
- else g_iWindowWidth = g_iMinWidth;
- if (iHeight > g_iMinHeight) g_iWindowHeight = iHeight;
- else g_iWindowHeight = g_iMinHeight;
-
- int iBorderWidth = (int)( (double)(g_iWindowWidth) * g_fBorderWidth + .5);
- int iBorderHeight = (int)( (double)(g_iWindowHeight) * g_fBorderHeight + .5);
-
- m_rbMain = new RectButton(iBorderWidth, iBorderHeight,
- g_iWindowWidth - 2*iBorderWidth, g_iWindowHeight - 2*iBorderHeight);
- m_rbMain.m_iBorderWidth=2;
-
- int i4ColorWidth = (int)( (double)(iBorderWidth)*g_f4ColorDim + .5);
- int i4ColorHeight = (int)( (double)(iBorderHeight)*g_f4ColorDim + .5);
- m_rbBlue = new RectButton(m_rbMain.m_iXPos + m_rbMain.m_iWidth,
- m_rbMain.m_iYPos + m_rbMain.m_iHeight, i4ColorWidth, i4ColorHeight);
- m_rbBlue.m_cMain = new Color(120,120,255);
- m_rbGreen=new RectButton(m_rbMain.m_iXPos + m_rbMain.m_iWidth,
- m_rbMain.m_iYPos - i4ColorHeight, i4ColorWidth, i4ColorHeight);
- m_rbGreen.m_cMain = new Color(120,255,120);
- m_rbRed = new RectButton(m_rbMain.m_iXPos - i4ColorWidth,
- m_rbMain.m_iYPos - i4ColorHeight, i4ColorWidth, i4ColorHeight);
- m_rbRed.m_cMain = new Color(255,120,120);
- m_rbViolet=new RectButton(m_rbMain.m_iXPos - i4ColorWidth,
- m_rbMain.m_iYPos + m_rbMain.m_iHeight, i4ColorWidth, i4ColorHeight);
- m_rbViolet.m_cMain = new Color(160,120,160);
-
- marr_rsParams = new RectSlider[g_iNumParams];
- int iEnd = 0;
- for (int iSide=0; iSide<4; iSide++) {
- int iStart = iEnd;
- iEnd = (iSide+1)*(g_iNumParams/4) + ((iSide<g_iNumParams%4)? iSide+1 : 0);
- boolean bVert = iSide == 0 || iSide == 2;
- boolean bBottomLeft = iSide == 0 || iSide == 1;
- double fGapWidth; int iSliderWidth;
- if (iSide == 0 || iSide == 2)
- fGapWidth = (double)(m_rbMain.m_iWidth)/(double)(iEnd-iStart+1);
- else fGapWidth = (double)(m_rbMain.m_iHeight)/(double)(iEnd-iStart+1);
- iSliderWidth = (int)(fGapWidth * g_fSliderWidth + .5);
- for (int C=iStart; C<iEnd; C++) {
- switch (iSide) {
- case 0: marr_rsParams[C] = new RectSlider(
- (int)(iBorderWidth + (1+C-iStart)*fGapWidth - iSliderWidth/2), 0,
- iSliderWidth, iBorderHeight);
- break;
- case 1: marr_rsParams[C] = new RectSlider(g_iWindowWidth - iBorderWidth,
- (int)(iBorderHeight + (1+C-iStart)*fGapWidth - iSliderWidth/2),
- iBorderWidth, iSliderWidth);
- break;
- case 2: marr_rsParams[C] = new RectSlider(
- (int)(iBorderWidth + (iEnd-C)*fGapWidth - iSliderWidth/2),
- g_iWindowHeight - iBorderHeight,
- iSliderWidth, iBorderHeight);
- break;
- case 3: marr_rsParams[C] = new RectSlider(0,
- (int)(iBorderHeight + (iEnd-C)*fGapWidth - iSliderWidth/2),
- iBorderWidth, iSliderWidth);
- break;
- }
- marr_rsParams[C].m_bVert = bVert;
- marr_rsParams[C].m_bBottomLeft = bBottomLeft;
- marr_rsParams[C].m_fValue = .5;
- }
- }
- }
-
- //---------------------------------------------
-
- public void init ()
- { System.out.println("Initializing...");
-
- CMIDI.sm_applet = this;
- m_midi = new CMIDI();
- m_midi.OnInit();
-
- // Misc
- CGenPoint.g_secTest = new CSection(this);
- System.out.println("Done initializing...");
- }
-
- public void start ()
- { if (m_thread == null) {
- m_thread = new Thread(this);
- m_thread.start();
- }
- m_midi.OnStart();
- }
- public void stop ()
- { m_thread.stop();
- m_thread = null;
- m_midi.OnStop();
- }
- public void run ()
- { Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
- initGUI();
- long lTime = (new Date()).getTime();
- LoopThis((int)lTime);
- m_bClearDots = true; repaint();
- ReadHTMLParams();
- while (m_thread != null) {
- lTime = (new Date()).getTime();
- //showStatus("While " + lTime);
- try LoopThis((int)lTime);
- catch (Exception e);
- }
- }
-
- //-----------------------------------------
- void ReadHTMLEvent (int iEventNum)
- { int iIndex = iGetParameter("event" + iEventNum);
- int iArg = iGetParameter("event" + iEventNum + "Arg");
-
- System.out.print("Event" + iEventNum + ": ");
- if (iIndex != -1)
- ProcessInput(iIndex, (char)iArg);
- else ChangeActiveLayer(iArg);
- }
-
- public void ReadHTMLParams ()
- { ProcessInput(17, (char)42);
- for (int C=0; true; C++) {
- try ReadHTMLEvent(C);
- catch(NumberFormatException e)
- return; // If out of events, stop reading.
- }
- }
-
- //-----------------------
- void ChangeActiveLayer (int iLayerIndex)
- { CStanza pstzCurrStanza = CGenPoint.g_secTest.pstzGetPrevStanza(1);
- if (iLayerIndex >= pstzCurrStanza.iNumLayers()) {
- m_iLayerNumber = pstzCurrStanza.iNumLayers();
- CGenPoint.g_secTest.AppendLayerClone(pstzCurrStanza.plyrGetLayer(0));
- } else m_iLayerNumber = iLayerIndex;
- System.out.println("Current layer " +
- m_iLayerNumber);
- }
-
- //-----------------------
- public void LoopThis (int fTime)
- { //showStatus("Loop " + (int)fTime);
- char pvNoteNum, pvVolume, pvChannel;
- int iNewTime = (int)(fTime)/BEAT_TIME;
- if (g_iLastTime != -1 && iNewTime <= g_iLastTime)
- return;
- g_iLastTime = iNewTime;
-
- CNote pNote;
- // Which notes to stop playing?
- while ((pNote = CGenPoint.g_secTest.pNoteToEnd(g_iLastTime))
- != null)
- { pvChannel = (char)m_midi.iGetInstrumentChannel(pNote.pvInstrument);
- //tw.spr("off(%d,%d,%d,%d)\t", pvChannel, pNote.iNoteNum,
- // pNote.iBeatNum, pNote.iDuration);
- m_midi.MidiOutNoteOFF(pNote.iNoteNum, pvChannel);
- }
-
- boolean bPlayedNote = false;
- // Which notes to start playing?
- while ((pNote = CGenPoint.g_secTest.pNoteToPlay(g_iLastTime))
- != null)
- {
- pvNoteNum = (char)pNote.iNoteNum;
- switch (pNote.bstStress)
- { case BST_WHISPER: pvVolume = (char)(sm_iMIDIvolume/4); break;
- case BST_LIGHT: pvVolume = (char)(sm_iMIDIvolume*3/4); break;
- case BST_MEDIUM: pvVolume = (char)(sm_iMIDIvolume); break;
- case BST_HEAVY: pvVolume = (char)((sm_iMIDIvolume*3 + 127)/4);
- break;
- case BST_BANG: pvVolume = (char)((sm_iMIDIvolume + 127*3)/4);
- break;
- default: pvVolume=0; System.out.println("Eh?"); break;
- }
- pvChannel = (char)m_midi.iGetInstrumentChannel(pNote.pvInstrument);
- //tw.spr("note(%d,%d,%d,%d,%d)\r", pvChannel,
- // pvNoteNum, pvVolume, pNote.iBeatNum, pNote.iDuration);
- //showStatus(g_iLastTime + " On " + (int)pvNoteNum);
- m_midi.MidiOutNoteON(pvNoteNum, pvVolume, pvChannel, fTime);
- bPlayedNote = true;
- }
- if (bPlayedNote || g_iLastTime % 12 == 0) {
- repaint();
- }
- m_midi.LoopThis(fTime);
- try { Thread.sleep(25); } catch(Exception e) {}
- }
-
- //=====================================
-
- char pvGetLastInput (int iParamNum)
- { int iLyr = (m_iLayerNumber < 0) ? 0 : m_iLayerNumber;
- switch (iParamNum) {
- case 15: // no break;
- case -1: return (char)m_iLayerNumber;
- case 0: return CGenPoint.pvGetCoord(DIM_COHESION);
- case 1: return CGenPoint.pvGetCoord(DIM_KEY);
- case 2: return CGenPoint.pvGetCoord(DIM_SCALE);
- case 3: return CGenPoint.pvGetCoord(DIM_TEMPO);
- case 4: return CGenPoint.pvGetLayerCoord(LDIM_RTHM_CONSISTENCY, 0);
- case 5: return CGenPoint.pvGetLayerCoord(LDIM_RTHM_DENSITY, 0);
- case 6: return CGenPoint.pvGetLayerCoord(LDIM_RTHM_LENGTH, 0);
- case 7: return CGenPoint.pvGetLayerCoord(LDIM_CONSONANCE, iLyr);
- case 8: return CGenPoint.pvGetLayerCoord(LDIM_DIRECTION, iLyr);
- case 9: return CGenPoint.pvGetLayerCoord(LDIM_INSTRUMENT, iLyr);
- case 10: return CGenPoint.pvGetLayerCoord(LDIM_ACTIVE, iLyr);
- case 11: return CGenPoint.pvGetLayerCoord(LDIM_RTHM_STYLE, iLyr);
- case 12: return CGenPoint.pvGetLayerCoord(LDIM_RTHM_STYLE_ARG, iLyr);
- case 13: // no break;
- case 17: return CGenPoint.pvGetCoord(DIM_SECTION_CHANGE);
- case 14: return CGenPoint.pvGetLayerCoord(LDIM_PITCH_MAGNET, iLyr);
- default: assert(false);
- }
- return 0;
- }
-
- void ProcessInput (int iParamNum, char pvInput)
- {System.out.println("Processing " + iParamNum + "," + (int)pvInput);
- switch (iParamNum) {
- case 0: CGenPoint.iSetCoord(DIM_COHESION, pvInput); return;
- case 1: CGenPoint.iSetCoord(DIM_KEY, pvInput); return;
- case 2: CGenPoint.iSetCoord(DIM_SCALE, pvInput); return;
- case 3: CGenPoint.iSetCoord(DIM_TEMPO, pvInput); return;
- case 4: CGenPoint.iSetCoord(DIM_RTHM_CONSISTENCY, pvInput); return;
- case 5: CGenPoint.iSetCoord(DIM_RTHM_DENSITY, pvInput); return;
- case 6: CGenPoint.iSetCoord(DIM_RTHM_LENGTH, pvInput); return;
- case 13: // no break;
- case 17: CGenPoint.iSetCoord(DIM_SECTION_CHANGE, pvInput); return;
- case 15: ChangeActiveLayer(pvInput); return;
- }
-
- int iStart, iEnd;
- if (m_iLayerNumber >= 0) {
- iStart = m_iLayerNumber;
- iEnd = m_iLayerNumber;
- if (iParamNum == 10 && pvInput == 0 && iStart==0) iStart++; // First layer always active
- } else {
- iStart = 0;
- iEnd = CGenPoint.g_secTest.pstzGetPrevStanza(1).iNumLayers() - 1;
- if (iParamNum == 10 && pvInput == 0) iStart++; // First layer always active
- }
- for (int C=iStart; C<=iEnd; C++) {
- switch (iParamNum) {
- case 7: CGenPoint.iSetLayerCoord(LDIM_CONSONANCE, C, pvInput); break;
- case 8: CGenPoint.iSetLayerCoord(LDIM_DIRECTION, C, pvInput); break;
- case 9: CGenPoint.iSetLayerCoord(LDIM_INSTRUMENT, C, pvInput); break;
- case 10: CGenPoint.iSetLayerCoord(LDIM_ACTIVE, C, pvInput); break;
- case 11: CGenPoint.iSetLayerCoord(LDIM_RTHM_STYLE, C, pvInput);
- CGenPoint.iSetLayerCoord(LDIM_RTHM_STYLE_ARG, C, (char)64);
- break;
- case 12: CGenPoint.iSetLayerCoord(LDIM_RTHM_STYLE_ARG, C, pvInput); break;
- case 14: CGenPoint.iSetLayerCoord(LDIM_PITCH_MAGNET, C, pvInput); break;
- default: assert(false);
- }
- }
- }
-
- //=================================================
-
- void OnButtonBlue()
- { showStatus("Blue");
- m_iBaseRed=120;m_iBaseGreen=120;m_iBaseBlue=255;
- m_iMMUDRed=120;m_iMMUDGreen=120;m_iMMUDBlue=255;
- m_x = m_rbMain.m_iXPos + m_rbMain.m_iWidth;
- m_y = m_rbMain.m_iYPos + m_rbMain.m_iHeight;
- m_fMM = 1; m_fUD = 1;
- ProcessInput(0, (char)30); // Cohesion
- ProcessInput(1, (char)61); // Key
- ProcessInput(2, (char)50); // Scale
- ProcessInput(3, (char)105); // Tempo
- ProcessInput(4, (char)10); // R. Consistency
- ProcessInput(5, (char)17); // R. Density
- ProcessInput(6, (char)50); // R. Length
- ChangeActiveLayer(0);
- ProcessInput(7, (char)74); // Consonance
- ProcessInput(8, (char)50); // Direction
- // 20.ReedOrgan 53:Oohs 72:Piccolo 49.StrEns2
- ProcessInput(9, (char)m_midi.iGetDefaultInst(5, this)); // Instrument
- ProcessInput(10, (char)1); // Active
- ProcessInput(11, (char)3); // R. Style
- ProcessInput(12, (char)0); // R. Style Arg
- ProcessInput(14, (char)43); // Pitch Magnet
- for (int C=1; C<(int)CGenPoint.pvGetCoord(DIM_NUM_LAYERS); C++) {
- ChangeActiveLayer(C);
- ProcessInput(10, (char)0); // Inactive
- }
- m_bClearDots = true; repaint();
- }
-
- void OnButtonGreen()
- { showStatus("Green");
- m_iBaseRed=120;m_iBaseGreen=255;m_iBaseBlue=120;
- m_iMMUDRed=120;m_iMMUDGreen=255;m_iMMUDBlue=120;
- m_x = m_rbMain.m_iXPos + m_rbMain.m_iWidth;
- m_y = m_rbMain.m_iYPos;
- m_fMM = 1; m_fUD = 0;
- ProcessInput(0, (char)64); // Cohesion
- ProcessInput(1, (char)72); // Key
- ProcessInput(2, (char)10); // Scale
- ProcessInput(3, (char)81); // Tempo
- ProcessInput(4, (char)50); // R. Consistency
- ProcessInput(5, (char)8); // R. Density
- ProcessInput(6, (char)25); // R. Length
- ChangeActiveLayer(0); // 1st Layer...
- ProcessInput(7, (char)64); // Consonance
- ProcessInput(8, (char)54); // Direction
- // 50:SynthStr1 97:Soundtrack
- ProcessInput(9, (char)m_midi.iGetDefaultInst(3, this)); // Instrument
- ProcessInput(10, (char)1); // Active
- ProcessInput(11, (char)3); // R. Style
- ProcessInput(12, (char)0); // R. Style Arg
- ProcessInput(14, (char)65); // Pitch Magnet
- ChangeActiveLayer(1); // 2nd Layer...
- ProcessInput(7, (char)94); // Consonance
- ProcessInput(8, (char)32); // Direction
- // 94:Halo 102:Echoes
- ProcessInput(9, (char)m_midi.iGetDefaultInst(4, this)); // Instrument
- ProcessInput(10, (char)1); // Active
- ProcessInput(11, (char)1); // R. Style
- ProcessInput(12, (char)64); // R. Style Arg
- ProcessInput(14, (char)84); // Pitch Magnet
- /*if (m_sliLayer.GetRangeMax() <= 1)
- m_sliLayer.SetRangeMax(2, TRUE); // Update slider
- else*/ for (int C=2; C<(int)CGenPoint.pvGetCoord(DIM_NUM_LAYERS); C++) {
- ChangeActiveLayer(C);
- ProcessInput(10, (char)0); // Inactive
- }
- m_bClearDots = true; repaint();
- }
-
- void OnButtonRed()
- { showStatus("Red");
- m_iBaseRed=255;m_iBaseGreen=120;m_iBaseBlue=120;
- m_iMMUDRed=255;m_iMMUDGreen=120;m_iMMUDBlue=120;
- m_x = m_rbMain.m_iXPos;
- m_y = m_rbMain.m_iYPos;
- m_fMM = 0; m_fUD = 0;
- ProcessInput(0, (char)80); // Cohesion
- ProcessInput(1, (char)60); // Key
- ProcessInput(2, (char)30); // Scale
- ProcessInput(3, (char)23); // Tempo
- ProcessInput(4, (char)90); // R. Consistency
- ProcessInput(5, (char)64); // R. Density
- ProcessInput(6, (char)15); // R. Length
- ChangeActiveLayer(0); // 1st Layer...
- ProcessInput(7, (char)54); // Consonance
- ProcessInput(8, (char)54); // Direction
- // 96:Rain 25:GuitSteel
- ProcessInput(9, (char)m_midi.iGetDefaultInst(0, this)); // Instrument
- ProcessInput(10, (char)1); // Active
- ProcessInput(11, (char)3); // R. Style
- ProcessInput(12, (char)0); // R. Style Arg
- ProcessInput(14, (char)72); // Pitch Magnet
- ChangeActiveLayer(1); // 2nd Layer...
- ProcessInput(7, (char)94); // Consonance
- ProcessInput(8, (char)64); // Direction
- // 88:NewAge
- ProcessInput(9, (char)m_midi.iGetDefaultInst(1, this)); // Instrument
- ProcessInput(10, (char)1); // Active
- ProcessInput(11, (char)0); // R. Style
- ProcessInput(12, (char)0); // R. Style Arg
- ProcessInput(14, (char)48); // Pitch Magnet
- ChangeActiveLayer(2); // 3rd Layer...
- ProcessInput(7, (char)94); // Consonance
- ProcessInput(8, (char)54); // Direction
- // 127:GunShot 117:TaikoDrum
- ProcessInput(9, (char)m_midi.iGetDefaultInst(2, this)); // Instrument
- ProcessInput(10, (char)1); // Active
- ProcessInput(11, (char)3); // R. Style
- ProcessInput(12, (char)0); // R. Style Arg
- ProcessInput(14, (char)55); // Pitch Magnet
- /*if (m_sliLayer.GetRangeMax() <= 2)
- m_sliLayer.SetRangeMax(3, TRUE); // Update slider
- else*/ for (int C=3; C<(int)CGenPoint.pvGetCoord(DIM_NUM_LAYERS); C++) {
- ChangeActiveLayer(C);
- ProcessInput(10, (char)0); // Inactive
- }
- m_bClearDots = true; repaint();
- }
-
- void OnButtonViolet()
- { showStatus("Violet (cyu@mit.edu v5.0)");
- m_iBaseRed=160;m_iBaseGreen=120;m_iBaseBlue=160;
- m_iMMUDRed=160;m_iMMUDGreen=120;m_iMMUDBlue=160;
- m_x = m_rbMain.m_iXPos;
- m_y = m_rbMain.m_iYPos + m_rbMain.m_iHeight;
- m_fMM = 0; m_fUD = 1;
- //m_sliMM.SetPos(0);
- ProcessInput(0, (char)20); // Cohesion
- ProcessInput(1, (char)59); // Key
- ProcessInput(2, (char)79); // Scale
- ProcessInput(3, (char)31); // Tempo
- ProcessInput(4, (char)10); // R. Consistency
- ProcessInput(5, (char)80); // R. Density
- ProcessInput(6, (char)20); // R. Length
- ChangeActiveLayer(0); // 1st Layer...
- ProcessInput(7, (char)44); // Consonance
- ProcessInput(8, (char)60); // Direction
- // 30.DistGuit 39:SynthBass2
- ProcessInput(9, (char)m_midi.iGetDefaultInst(6, this)); // Instrument
- ProcessInput(10, (char)1); // Active
- ProcessInput(11, (char)3); // R. Style
- ProcessInput(12, (char)0); // R. Style Arg
- ProcessInput(14, (char)48); // Pitch Magnet
- ChangeActiveLayer(1); // 1nd Layer...
- ProcessInput(7, (char)64); // Consonance
- ProcessInput(8, (char)30); // Direction
- // 114:SteelDrum 100.Bright
- ProcessInput(9, (char)m_midi.iGetDefaultInst(7, this)); // Instrument
- ProcessInput(10, (char)1); // Active
- ProcessInput(11, (char)2); // R. Style
- ProcessInput(12, (char)42); // R. Style Arg
- ProcessInput(14, (char)64); // Pitch Magnet
- ChangeActiveLayer(2); // 3rd Layer...
- ProcessInput(7, (char)64); // Consonance
- ProcessInput(8, (char)44); // Direction
- // 124:TeleRing 115:Woodblock 118:SynthDrum
- ProcessInput(9, (char)m_midi.iGetDefaultInst(8, this)); // Instrument
- ProcessInput(10, (char)1); // Active
- ProcessInput(11, (char)0); // R. Style
- ProcessInput(12, (char)0); // R. Style Arg
- ProcessInput(14, (char)72); // Pitch Magnet
- /*if (m_sliLayer.GetRangeMax() <= 2)
- m_sliLayer.SetRangeMax(3, TRUE); // Update slider
- else*/ for (int C=3; C<(int)CGenPoint.pvGetCoord(DIM_NUM_LAYERS); C++) {
- ChangeActiveLayer(C);
- ProcessInput(10, (char)0); // Inactive
- }
- m_bClearDots = true; repaint();
- }
-
- int i24Scale (double f01, double f10, int i00, int i01, int i10, int i11)
- {
- int iRange0001 = i01 - i00;
- int iRange1011 = i11 - i10;
- double fNewRange = (double)(iRange0001) +
- f10*(double)(iRange1011 - iRange0001);
- double fNewStart = (double)(i00) + f10*(double)(i10 - i00);
- return (int)(fNewStart + f01*fNewRange);
- }
-
- void OnMMUD (double fMM, double fUD)
- { showStatus ("MM " + fMM + ", UD " + fUD);
- ProcessInput(0, (char)i24Scale(fMM,fUD, 80,64,20,30)); // Cohesion
- ProcessInput(2, (char)(int)(fUD*79)); // Scale
- ProcessInput(3, (char)i24Scale(fMM,fUD, 23,81,31,105)); // Tempo
- ProcessInput(4, (char)i24Scale(fMM,fUD, 90,50,10,10)); // R. Consistency
- ProcessInput(5, (char)i24Scale(fMM,fUD, 64,8,80,17)); // R. Density
- ProcessInput(6, (char)i24Scale(fMM,fUD, 15,25,20,50)); // R. Length
- ChangeActiveLayer(-1);
- m_iMMUDRed = i24Scale(fMM,fUD, 255, 120, 160, 120);
- m_iMMUDGreen = i24Scale(fMM,fUD, 120, 255, 120, 120);
- m_iMMUDBlue = i24Scale(fMM,fUD, 120, 120, 160, 255);
- CGenPoint.g_secTest.m_bMutateUpdate = true; repaint();
- //ProcessInput(7, i24Scale(fMM,fUD, 64,64,44,74)); // Consonance
- //UpdateSliderVals();
- }
-
- //=============================================
-
- public boolean mouseDown (java.awt.Event evt, int x, int y)
- { if (m_rbMain.bMouseOver(x,y)) {
- m_x = x; m_y = y;
- m_fMM = (double)(x-m_rbMain.m_iXPos)/(double)(m_rbMain.m_iWidth);
- m_fUD = (double)(y-m_rbMain.m_iYPos)/(double)m_rbMain.m_iHeight;
- OnMMUD(m_fMM, m_fUD);
- }
- else if (m_rbBlue.bMouseOver(x,y)) OnButtonBlue();
- else if (m_rbGreen.bMouseOver(x,y)) OnButtonGreen();
- else if (m_rbRed.bMouseOver(x,y)) OnButtonRed();
- else if (m_rbViolet.bMouseOver(x,y)) OnButtonViolet();
- else for (int C=0; C<g_iNumParams; C++)
- if (marr_rsParams[C].bMouseOver(x,y)) {
- CGenPoint.g_secTest.m_bMutateUpdate = true; repaint();
- int iVal = (int)(marr_rsParams[C].m_fValue*127);
- switch (C) {
- case 10: iVal = iVal>64 ? 1 : 0; break;
- case 11: iVal /= 33; break;
- case 15: iVal = (int)(.5 + marr_rsParams[C].m_fValue *
- (CGenPoint.g_secTest.pstzGetPrevStanza(1).iNumLayers()));
- }
- ProcessInput(C, (char)iVal);
- break;
- }
- return true;
- }
-
- //-----------------------
- /*public boolean mouseDrag (java.awt.Event evt, int x, int y)
- {
- if (m_rbMain.bMouseOver(x,y)) {
- m_x = x; m_y = y;
- m_fMM = (double)(x-m_rbMain.m_iXPos)/(double)(m_rbMain.m_iWidth);
- m_fUD = (double)(y-m_rbMain.m_iYPos)/(double)m_rbMain.m_iHeight;
- if (rand()%20 == 0) // Usually, don't update music.
- mouseDown(evt, x, y);
- }
- return true;
- }
- */
- //-----------------------
- public void update (Graphics g)
- { paintDots(offscreenGraphics);
- if (m_bClearDots || CGenPoint.g_secTest.m_bMutateUpdate)
- paint(offscreenGraphics);
- g.drawImage(offscreenImage, 0, 0, this);
- }
- public void paint (Graphics g)
- { //Color cMain = new Color((m_iBaseRed+m_iMMUDRed)/2,
- // (m_iBaseGreen+m_iMMUDGreen)/2, (m_iBaseBlue+m_iMMUDBlue)/2);
- Color cBorder = new Color(m_iBaseRed,m_iBaseGreen,m_iBaseBlue);
- if (m_bClearDots) {
- //m_rbMain.paint(g, Color.black, Color.black);
- g.setColor(Color.black);
- g.fillRect(0,0,this.size().width,this.size().height);
- }
- m_rbBlue.paint(g, null, cBorder);
- m_rbGreen.paint(g, null, cBorder);
- m_rbRed.paint(g, null, cBorder);
- m_rbViolet.paint(g, null, cBorder);
- try {
- if (m_bClearDots || CGenPoint.g_secTest.m_bMutateUpdate) {
- for (int C=0; C<g_iNumParams; C++) {
- switch (C) {
- case 10: marr_rsParams[C].m_fValue = pvGetLastInput(C); break;
- case 11: marr_rsParams[C].m_fValue = (double)(pvGetLastInput(C))/3.0; break;
- case 15: marr_rsParams[C].m_fValue = (double)(m_iLayerNumber+1) /
- (1+CGenPoint.g_secTest.pstzGetPrevStanza(1).iNumLayers()); break;
- default: marr_rsParams[C].m_fValue = (double)(pvGetLastInput(C))/127.0; break;
- }
- marr_rsParams[C].paint(g, cBorder, Color.black);
- //if (C==3) m_x += (marr_rsParams[C].m_fValue - .5)*10;
- //if (C==2) m_y += (marr_rsParams[C].m_fValue - .5)*10;
- }
- } else for (int C=0; C<g_iNumParams; C++) {
- marr_rsParams[C].paint(g, cBorder, Color.black);
- }
- } catch(Exception e);
- m_bClearDots = false;
- CGenPoint.g_secTest.m_bMutateUpdate = false;
- }
-
- public int rand() { return (int)(Math.random() * 9747); }
- public void paintDots (Graphics g)
- { boolean bBlack = rand()%4 == 0;
- int iArmArc = 628 / ((m_x+m_y) % 8 + 1);
- int iOffset = (m_x + m_y)%iArmArc;
- for (int C=0; C<25; C++) {
- int iDist = rand() % (1 + rand() % (m_rbMain.m_iWidth/4));
- float fRadians = (float)(rand() % 628);
- iDist = (int)((float)(iDist) * (float)((int)(fRadians+iOffset) % iArmArc)/(float)(iArmArc));
- fRadians /= (float)(100);
- int x = (int)(Math.sin(fRadians)*iDist + m_x);
- int y = (int)(Math.cos(fRadians)*iDist + m_y);
- if (bBlack) {
- g.setColor(Color.black);
- g.drawLine(x,y, x+1,y);
- continue;
- }
- int r = i24Scale(m_fMM,m_fUD, 255, 120, 160, 120);
- int gn = i24Scale(m_fMM,m_fUD, 120, 255, 120, 120);
- int b = i24Scale(m_fMM,m_fUD, 120, 120, 160, 255);
- //COLORREF cr = dcBmp.GetPixel(x,y);
- Color cr = new Color((r+rand()%256)/2, (gn+rand()%256)/2, (b+rand()%256)/2);
- g.setColor(cr);
- g.drawLine(x,y, x+1,y);
- }
- }
-
- } // end class Sharle
-