home *** CD-ROM | disk | FTP | other *** search
- #define DEMO_OBJS
-
- #include <windows.h>
- #include "amber.hpp"
- #include "demo.hpp"
- #include "intxmsg.hpp"
-
- #define X 0
- #define Y 1
- #define Z 2
-
- int channel=0, lastChannel=0, lastNote=0, patch=0;
- void keyBounce(void *obj)
- {
- geometryClass *geo = (geometryClass *)obj;
- quatClass q;
- V3 euler;
-
- geo->getOrientation(q);
- q.getEuler(euler);
-
- if (euler[0] <= 0.0) return;
-
- if (euler[0] <= 0.018) {
- q.init();
- geo->setOrientation(q);
- }
- else {
- geo->rotate(0, -0.018);
- }
-
- }
- void init(channelClass *ch)
- {
- int i;
- V3 ext, piv, pos;
- geometryClass *g;
-
- keys = new geometryClass("piano.wrl");
- keys->setCollisionState(TRUE,TRUE,TRUE);
- audio = new audioClass();
- audio->midiOpenFX();
-
- for (i=3; i<28; i++) {
- g = amber->getGeometry(i);
- g->getExtents(ext);
- g->getPosition(pos);
- piv[0] = pos[0];
- piv[1] = pos[1];
- piv[2] = pos[2] - ext[2]/2.0;
- g->setPivot(piv);
- g->addAction(keyBounce);
-
- }
-
- keys->getHierarchyBounds(pos, ext);
- pos[2] += 12;
- pos[1] += 5;
- ch->rotate(0, 0.34);
- ch->setPosition(pos);
- }
-
- void cleanup()
- {
- delete audio;
- }
-
- void processChar(unsigned int nChar)
- {
- intxMsgClass *msg;
- int id, note;
- quatClass q;
-
- switch(nChar) {
- case 'M':
- patch++;
- if (patch>127) patch=0;
- audio->midiChangePatch(0, patch);
- break;
- case '0':
- audio->midiChangePatch(0, 0);
- //channel=0;
- break;
- case '1':
- //channel=1;
- audio->midiChangePatch(0, 9);
- break;
- case '2':
- channel=2;
- break;
- case '3':
- channel=3;
- break;
- case '4':
- channel=4;
- break;
- case '5':
- channel=5;
- break;
- case '6':
- channel=6;
- break;
- case '7':
- channel=7;
- break;
- case '8':
- channel=8;
- break;
- case '9':
- channel=9;
- break;
- case 'A':
- channel=10;
- break;
- case 'B':
- channel=11;
- break;
- case 'C':
- channel=12;
- break;
- case 'D':
- channel=13;
- break;
- case 'E':
- channel=14;
- break;
- case 'F':
- channel=15;
- break;
- case ' ':
- msg = ch->pick(mouse->pos);
- if (msg) {
- id = msg->iGeo->getId();
- note = 50 + id;
- audio->midiNoteOff(lastChannel, lastNote, 127);
- audio->midiNoteOn(channel, note, 127);
- lastChannel=channel;
- lastNote=note;
- q.rotate(0, 0.09);
- msg->iGeo->setOrientation(q);
- delete msg;
- break;
- }
- }
- }
-
-