aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2016-05-06 00:07:27 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2016-05-06 00:07:27 +0800
commit8da0f5c82fb91c2731cd2e90a875fe92c6557407 (patch)
treef8ef262d66bd8fdc4b455da3fcceaed58d2b4d80
parent56eaa27d4daca9264dac2e822b1126cf6eb8cbf4 (diff)
downloadQMidiPlayer-8da0f5c82fb91c2731cd2e90a875fe92c6557407.tar.xz
Use the new SMELT rendering API.
-rw-r--r--ChangeLog3
-rw-r--r--visualization/extrasmeltutils.cpp126
-rw-r--r--visualization/extrasmeltutils.hpp30
-rw-r--r--visualization/qmpvirtualpiano3d.cpp268
-rw-r--r--visualization/qmpvirtualpiano3d.hpp1
-rw-r--r--visualization/qmpvisualization.cpp43
-rw-r--r--visualization/qmpvisualization.hpp4
7 files changed, 272 insertions, 203 deletions
diff --git a/ChangeLog b/ChangeLog
index 9caf977..182c603 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2016-05-05 0.8.1 pre
+Use the new SMELT rendering API.
+
2016-05-04 0.8.1 pre
Piano keyboard: first steps.
diff --git a/visualization/extrasmeltutils.cpp b/visualization/extrasmeltutils.cpp
index 3e86549..d77cc4b 100644
--- a/visualization/extrasmeltutils.cpp
+++ b/visualization/extrasmeltutils.cpp
@@ -1,91 +1,61 @@
+#include <cstdarg>
#include "extrasmeltutils.hpp"
-SMELT *smEntity3D::sm=NULL;
-smEntity3D::smEntity3D()
+SMELT* smEntity3DBuffer::sm=NULL;
+smVertex makeVertex(float x,float y,float z,DWORD color,float tx,float ty)
+{smVertex v;v.x=x;v.y=y;v.z=z;v.col=color;v.tx=tx;v.ty=ty;return v;}
+void smEntity3D::addVerices(int n,...)
{
- sm=smGetInterface(SMELT_APILEVEL);
- surfaces.clear();
-}
-void smEntity3D::pushSurface(smQuad q)
-{surfaces.push_back(q);}
-void smEntity3D::pushCube(smvec3d a,smvec3d b,DWORD color,DWORD mask)
-{
- //a: top left corner b: bottom right corner
- smQuad q;q.blend=BLEND_ALPHABLEND;q.tex=0;
- for(int i=0;i<4;++i)q.v[i].col=color,q.v[i].tx=q.v[i].ty=0;
- //top
- if(mask&1)
- {
- q.v[0].x=a.x;q.v[0].y=a.y;q.v[0].z=a.z;
- q.v[1].x=b.x;q.v[1].y=a.y;q.v[1].z=a.z;
- q.v[2].x=b.x;q.v[2].y=b.y;q.v[2].z=a.z;
- q.v[3].x=a.x;q.v[3].y=b.y;q.v[3].z=a.z;
- pushSurface(q);
- }
- //bottom
- if(mask&2)
- {
- q.v[0].x=a.x;q.v[0].y=a.y;q.v[0].z=b.z;
- q.v[1].x=b.x;q.v[1].y=a.y;q.v[1].z=b.z;
- q.v[2].x=b.x;q.v[2].y=b.y;q.v[2].z=b.z;
- q.v[3].x=a.x;q.v[3].y=b.y;q.v[3].z=b.z;
- pushSurface(q);
- }
- //left
- if(mask&4)
- {
- q.v[0].x=a.x;q.v[0].y=b.y;q.v[0].z=a.z;
- q.v[1].x=a.x;q.v[1].y=b.y;q.v[1].z=b.z;
- q.v[2].x=a.x;q.v[2].y=a.y;q.v[2].z=b.z;
- q.v[3].x=a.x;q.v[3].y=a.y;q.v[3].z=a.z;
- pushSurface(q);
- }
- //right
- if(mask&8)
- {
- q.v[0].x=b.x;q.v[0].y=b.y;q.v[0].z=a.z;
- q.v[1].x=b.x;q.v[1].y=b.y;q.v[1].z=b.z;
- q.v[2].x=b.x;q.v[2].y=a.y;q.v[2].z=b.z;
- q.v[3].x=b.x;q.v[3].y=a.y;q.v[3].z=a.z;
- pushSurface(q);
- }
- //front
- if(mask&16)
- {
- q.v[0].x=a.x;q.v[0].y=b.y;q.v[0].z=a.z;
- q.v[1].x=b.x;q.v[1].y=b.y;q.v[1].z=a.z;
- q.v[2].x=b.x;q.v[2].y=b.y;q.v[2].z=b.z;
- q.v[3].x=a.x;q.v[3].y=b.y;q.v[3].z=b.z;
- pushSurface(q);
- }
- //back
- if(mask&32)
+ va_list vl;va_start(vl,n);
+ for(int i=0;i<n;++i)
{
- q.v[0].x=a.x;q.v[0].y=a.y;q.v[0].z=a.z;
- q.v[1].x=b.x;q.v[1].y=a.y;q.v[1].z=a.z;
- q.v[2].x=b.x;q.v[2].y=a.y;q.v[2].z=b.z;
- q.v[3].x=a.x;q.v[3].y=a.y;q.v[3].z=b.z;
- pushSurface(q);
+ smVertex v=va_arg(vl,smVertex);
+ vertices.push_back(v);
}
+ va_end(vl);
}
-void smEntity3D::drawAt(smvec3d p)
+void smEntity3D::addIndices(int n,...)
{
- for(unsigned i=0;i<surfaces.size();++i)
+ va_list vl;va_start(vl,n);
+ for(int i=0;i<n;++i)
{
- smQuad tq=surfaces[i];
- for(unsigned j=0;j<4;++j)tq.v[j].x+=p.x,tq.v[j].y+=p.y,tq.v[j].z+=p.z;
- sm->smRenderQuad(&tq);
+ int idx=va_arg(vl,int);
+ indices.push_back((WORD)idx);
}
+ va_end(vl);
+}
+smEntity3D smEntity3D::cube(smvec3d a,smvec3d b,DWORD color)
+{
+ //a: top left corner b: bottom right corner
+ smEntity3D ret;
+ ret.addVerices(8,
+ makeVertex(a.x,a.y,a.z,color,0,0),makeVertex(b.x,a.y,a.z,color,0,0),
+ makeVertex(b.x,b.y,a.z,color,0,0),makeVertex(a.x,b.y,a.z,color,0,0),
+ makeVertex(a.x,a.y,b.z,color,0,0),makeVertex(b.x,a.y,b.z,color,0,0),
+ makeVertex(b.x,b.y,b.z,color,0,0),makeVertex(a.x,b.y,b.z,color,0,0));
+ ret.addIndices(36,
+ 0,1,3,1,2,3, 4,5,7,5,6,7,
+ 0,3,7,0,4,7, 1,2,6,1,5,6,
+ 2,3,7,2,6,7, 0,1,4,1,4,5);
+ return ret;
}
-void smEntity3D::drawWithTransformation(smMatrix t,smvec3d p)
+smEntity3DBuffer::smEntity3DBuffer()
{
- for(unsigned i=0;i<surfaces.size();++i)
+ sm=smGetInterface(SMELT_APILEVEL);
+ vertices.clear();indices.clear();
+}
+void smEntity3DBuffer::addTransformedEntity(smEntity3D *entity,smMatrix t,smvec3d p)
+{
+ if(entity->vertices.size()+vertices.size()>4000)drawBatch();
+ for(unsigned i=0;i<entity->indices.size();++i)
+ indices.push_back(entity->indices[i]+vertices.size());
+ for(unsigned i=0;i<entity->vertices.size();++i)
{
- smQuad tq=surfaces[i];
- for(unsigned j=0;j<4;++j)
- {
- smvec3d tp=t*smvec3d(tq.v[j].x,tq.v[j].y,tq.v[j].z);
- tq.v[j].x=tp.x+p.x;tq.v[j].y=tp.y+p.y;tq.v[j].z=tp.z+p.z;
- }
- sm->smRenderQuad(&tq);
+ smvec3d tp=smvec3d(entity->vertices[i].x,entity->vertices[i].y,entity->vertices[i].z);
+ tp=t*tp;tp=tp+p;vertices.push_back(makeVertex(tp.x,tp.y,tp.z,entity->vertices[i].col,entity->vertices[i].tx,entity->vertices[i].ty));
}
}
+void smEntity3DBuffer::drawBatch()
+{
+ sm->smDrawCustomIndexedVertices(&vertices[0],&indices[0],vertices.size(),indices.size(),BLEND_ALPHABLEND,0);
+ vertices.clear();indices.clear();
+}
diff --git a/visualization/extrasmeltutils.hpp b/visualization/extrasmeltutils.hpp
index 4b6c167..8a4a1bc 100644
--- a/visualization/extrasmeltutils.hpp
+++ b/visualization/extrasmeltutils.hpp
@@ -5,15 +5,29 @@
#include <smmath.hpp>
class smEntity3D
{
+ friend class smEntity3DBuffer;
private:
- std::vector<smQuad> surfaces;
- static SMELT *sm;
+ std::vector<smVertex> vertices;
+ std::vector<WORD> indices;
public:
- smEntity3D();
- ~smEntity3D(){surfaces.clear();sm->smRelease();}
- void pushSurface(smQuad q);
- void pushCube(smvec3d a,smvec3d b,DWORD color,DWORD mask);
- void drawAt(smvec3d p);
- void drawWithTransformation(smMatrix t,smvec3d p);
+ smEntity3D(){vertices.clear();indices.clear();}
+ ~smEntity3D(){vertices.clear();indices.clear();}
+ void addVerices(int n,...);
+ void addIndices(int n,...);
+ static smEntity3D cube(smvec3d tl,smvec3d br,DWORD color);
};
+class smEntity3DBuffer
+{
+ private:
+ std::vector<smVertex> vertices;
+ std::vector<WORD> indices;
+ static SMELT* sm;
+ public:
+ smEntity3DBuffer();
+ ~smEntity3DBuffer(){sm->smRelease();}
+ void addTransformedEntity(smEntity3D *entity,smMatrix t,smvec3d p);
+ void drawBatch();
+
+};
+extern smVertex makeVertex(float x,float y,float z,DWORD color,float tx,float ty);
#endif // EXTRASMELTUTILS_H
diff --git a/visualization/qmpvirtualpiano3d.cpp b/visualization/qmpvirtualpiano3d.cpp
index 458d3ef..dca9086 100644
--- a/visualization/qmpvirtualpiano3d.cpp
+++ b/visualization/qmpvirtualpiano3d.cpp
@@ -7,11 +7,12 @@ const double gap[]={WK_TALWIDTH/2*0.92,WK_TALWIDTH/2*1.23,WK_TALWIDTH/2*1.2,
WK_TALWIDTH/2*1.3,WK_TALWIDTH/2*0.85,WK_TALWIDTH*1.1};
qmpVirtualPiano3D::qmpVirtualPiano3D()
{
- buildKeys();memset(traveld,0,sizeof(traveld));
+ ebuf=new smEntity3DBuffer();buildKeys();memset(traveld,0,sizeof(traveld));
}
qmpVirtualPiano3D::~qmpVirtualPiano3D()
{
delete wkcf;delete wkeb;delete wkd;delete wkg;delete wka;delete bk;
+ wkcf=wkeb=wkd=wkg=wka=bk=NULL;delete ebuf;ebuf=NULL;
}
void qmpVirtualPiano3D::render(smvec3d p)
{
@@ -22,26 +23,27 @@ void qmpVirtualPiano3D::render(smvec3d p)
switch(i%12)
{
case 0:case 5:
- wkcf->drawWithTransformation(m,p);
+ if(wkcf)ebuf->addTransformedEntity(wkcf,m,p);
break;
case 2:
- wkd->drawWithTransformation(m,p);
+ if(wkd)ebuf->addTransformedEntity(wkd,m,p);
break;
case 4:case 11:
- wkeb->drawWithTransformation(m,p);
+ if(wkeb)ebuf->addTransformedEntity(wkeb,m,p);
break;
case 7:
- wkg->drawWithTransformation(m,p);
+ if(wkg)ebuf->addTransformedEntity(wkg,m,p);
break;
case 9:
- wka->drawWithTransformation(m,p);
+ if(wka)ebuf->addTransformedEntity(wka,m,p);
break;
case 1:case 3:case 6:case 8:case 10:
- bk->drawWithTransformation(m,p);
+ if(bk)ebuf->addTransformedEntity(bk,m,p);
break;
}
p.x+=gap[i%12];
}
+ ebuf->drawBatch();
}
void qmpVirtualPiano3D::setKeyTravelDist(int k,double td)
{traveld[k]=td;}
@@ -49,93 +51,169 @@ void qmpVirtualPiano3D::setKeyTravelDist(int k,double td)
void qmpVirtualPiano3D::buildKeys()
{
wkcf=new smEntity3D();wkeb=new smEntity3D();wkd=new smEntity3D();
- wkg=new smEntity3D();wka=new smEntity3D();
- smQuad q;q.blend=BLEND_ALPHABLEND;q.tex=0;
- for(int i=0;i<4;++i)q.v[i].col=0xFFFFFFFF,q.v[i].tx=q.v[i].ty=0;
- //TAL
- configureVertex(q.v,0,-WK_TALWIDTH/2,WK_PRELEN ,WK_HEIGHT);
- configureVertex(q.v,1, WK_TALWIDTH/2,WK_PRELEN ,WK_HEIGHT);
- configureVertex(q.v,2, WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,WK_HEIGHT);
- configureVertex(q.v,3,-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,WK_HEIGHT);
- wkcf->pushSurface(q);wkeb->pushSurface(q);wkd->pushSurface(q);
- wkg->pushSurface(q);wka->pushSurface(q);
- wkcf->pushCube(
- smvec3d(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT),
- smvec3d( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN-WK_WING,0),
- 0xFFCCCCCC,30);
- wkeb->pushCube(
- smvec3d(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT),
- smvec3d( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN-WK_WING,0),
- 0xFFCCCCCC,30);
- wkd->pushCube(
- smvec3d(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT),
- smvec3d( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN-WK_WING,0),
- 0xFFCCCCCC,30);
- wkg->pushCube(
- smvec3d(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT),
- smvec3d( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN-WK_WING,0),
- 0xFFCCCCCC,30);
- wka->pushCube(
- smvec3d(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT),
- smvec3d( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN-WK_WING,0),
- 0xFFCCCCCC,30);
- //PRE
- configureVertex(q.v,0,-WK_TALWIDTH/2,0 ,WK_HEIGHT);
- configureVertex(q.v,1, WK_TALWIDTH/2,0 ,WK_HEIGHT);
- configureVertex(q.v,2, WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT);
- configureVertex(q.v,3,-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT);
- wkcf->pushSurface(q);wkeb->pushSurface(q);wkd->pushSurface(q);
- wkg->pushSurface(q);wka->pushSurface(q);
- wkcf->pushCube(
- smvec3d(-WK_TALWIDTH/2,0,WK_HEIGHT),
- smvec3d(-WK_TALWIDTH/2+WK_PREWIDTH,WK_PRELEN,0),
- 0xFFCCCCCC,46);
- wkeb->pushCube(
- smvec3d(WK_TALWIDTH/2-WK_PREWIDTH,0,WK_HEIGHT),
- smvec3d(WK_TALWIDTH/2,WK_PRELEN,0),
- 0xFFCCCCCC,46);
- wkd->pushCube(
- smvec3d(-WK_TALWIDTH/2+(WK_TALWIDTH-WK_PREWIDTH)/2,0,WK_HEIGHT),
- smvec3d( WK_TALWIDTH/2-(WK_TALWIDTH-WK_PREWIDTH)/2,WK_PRELEN,0),
- 0xFFCCCCCC,46);
- wkg->pushCube(
- smvec3d(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12,0,WK_HEIGHT),
- smvec3d(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12+WK_PREWIDTH,WK_PRELEN,0),
- 0xFFCCCCCC,46);
- wka->pushCube(
- smvec3d(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24,0,WK_HEIGHT),
- smvec3d(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24-WK_PREWIDTH,WK_PRELEN,0),
- 0xFFCCCCCC,46);
+ wkg=new smEntity3D();wka=new smEntity3D();bk=new smEntity3D();
+ wkcf->addVerices(19,
+ makeVertex(-WK_TALWIDTH/2,0,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_PREWIDTH,0,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_PREWIDTH,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN+WK_WING,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN+WK_WING,WK_HEIGHT,0xFFFFFFFF,0,0),////
+ makeVertex(-WK_TALWIDTH/2,0,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_PREWIDTH,0,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_PREWIDTH,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,0,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_PREWIDTH,0,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_PREWIDTH,WK_PRELEN,0,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN,0,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,0,0xFFCCCCCC,0,0));
+ wkcf->addIndices(48,
+ 0,1,3, 1,2,3, 3,4,6, 4,5,6,
+ 7,8,13, 8,13,14, 8,14,15, 8,9,15,
+ 9,10,15, 10,15,16, 10,11,17, 10,16,17,
+ 11,12,18, 11,17,18, 18,12,13, 12,13,7);
- bk=new smEntity3D();
- for(int i=0;i<4;++i)q.v[i].col=0xFF000000;
- bk->pushCube(
- smvec3d(-BK_WIDTH/2,0,BK_HEIGHT+BK_BOTTOM),
- smvec3d( BK_WIDTH/2,BK_PRELEN,BK_BOTTOM),
- 0xFF000000,47);
- configureVertex(q.v,0,-BK_WIDTH/2,BK_PRELEN,BK_HEIGHT+BK_BOTTOM);
- configureVertex(q.v,1, BK_WIDTH/2,BK_PRELEN,BK_HEIGHT+BK_BOTTOM);
- configureVertex(q.v,2, BK_WIDTH/2,WK_PRELEN*0.95,BK_DBOTTOM+BK_BOTTOM);
- configureVertex(q.v,3,-BK_WIDTH/2,WK_PRELEN*0.95,BK_DBOTTOM+BK_BOTTOM);
- bk->pushSurface(q);
- configureVertex(q.v,0,-BK_WIDTH/2,BK_PRELEN,BK_HEIGHT+BK_BOTTOM);
- configureVertex(q.v,1,-BK_WIDTH/2,WK_PRELEN*0.95,BK_DBOTTOM+BK_BOTTOM);
- configureVertex(q.v,2,-BK_WIDTH/2,WK_PRELEN*0.95,BK_BOTTOM);
- configureVertex(q.v,3,-BK_WIDTH/2,BK_PRELEN,BK_BOTTOM);
- bk->pushSurface(q);
- configureVertex(q.v,0, BK_WIDTH/2,BK_PRELEN,BK_HEIGHT+BK_BOTTOM);
- configureVertex(q.v,1, BK_WIDTH/2,WK_PRELEN*0.95,BK_DBOTTOM+BK_BOTTOM);
- configureVertex(q.v,2, BK_WIDTH/2,WK_PRELEN*0.95,BK_BOTTOM);
- configureVertex(q.v,3, BK_WIDTH/2,BK_PRELEN,BK_BOTTOM);
- bk->pushSurface(q);
- configureVertex(q.v,0,-BK_WIDTH/2,WK_PRELEN*0.95,BK_DBOTTOM+BK_BOTTOM);
- configureVertex(q.v,1, BK_WIDTH/2,WK_PRELEN*0.95,BK_DBOTTOM+BK_BOTTOM);
- configureVertex(q.v,2, BK_WIDTH/2,WK_PRELEN*0.95,BK_BOTTOM);
- configureVertex(q.v,3,-BK_WIDTH/2,WK_PRELEN*0.95,BK_BOTTOM);
- bk->pushSurface(q);
- configureVertex(q.v,0,-BK_WIDTH/2,BK_PRELEN,BK_BOTTOM);
- configureVertex(q.v,1, BK_WIDTH/2,BK_PRELEN,BK_BOTTOM);
- configureVertex(q.v,2, BK_WIDTH/2,WK_PRELEN*0.95,BK_BOTTOM);
- configureVertex(q.v,3,-BK_WIDTH/2,WK_PRELEN*0.95,BK_BOTTOM);
- bk->pushSurface(q);
+ wkeb->addVerices(19,
+ makeVertex( WK_TALWIDTH/2,0,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2-WK_PREWIDTH,0,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2-WK_PREWIDTH,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN+WK_WING,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN+WK_WING,WK_HEIGHT,0xFFFFFFFF,0,0),////
+ makeVertex( WK_TALWIDTH/2,0,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2-WK_PREWIDTH,0,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2-WK_PREWIDTH,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,0,0,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2-WK_PREWIDTH,0,0,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2-WK_PREWIDTH,WK_PRELEN,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,0,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,0,0xFFCCCCCC,0,0));
+ wkeb->addIndices(48,
+ 0,1,3, 1,2,3, 3,4,6, 4,5,6,
+ 7,8,13, 8,13,14, 8,14,15, 8,9,15,
+ 9,10,15, 10,15,16, 10,11,17, 10,16,17,
+ 11,12,18, 11,17,18, 18,12,13, 12,13,7);
+
+ wkd->addVerices(24,
+ makeVertex(-WK_TALWIDTH/2+(WK_TALWIDTH-WK_PREWIDTH)/2,0,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2-(WK_TALWIDTH-WK_PREWIDTH)/2,0,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2-(WK_TALWIDTH-WK_PREWIDTH)/2,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2+(WK_TALWIDTH-WK_PREWIDTH)/2,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN+WK_WING,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN+WK_WING,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),////
+ makeVertex(-WK_TALWIDTH/2+(WK_TALWIDTH-WK_PREWIDTH)/2,0,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2-(WK_TALWIDTH-WK_PREWIDTH)/2,0,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2-(WK_TALWIDTH-WK_PREWIDTH)/2,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2+(WK_TALWIDTH-WK_PREWIDTH)/2,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),////
+ makeVertex(-WK_TALWIDTH/2+(WK_TALWIDTH-WK_PREWIDTH)/2,0,0,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2-(WK_TALWIDTH-WK_PREWIDTH)/2,0,0,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2-(WK_TALWIDTH-WK_PREWIDTH)/2,WK_PRELEN,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2+(WK_TALWIDTH-WK_PREWIDTH)/2,WK_PRELEN,0,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN,0,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN,0,0xFFCCCCCC,0,0));
+ wkd->addIndices(60,
+ 0,1,2, 0,2,3, 4,5,6, 4,6,7,
+ 8,9,16, 9,16,17, 9,10,18, 9,17,18,
+ 10,12,18, 12,18,19, 12,13,20, 12,19,20,
+ 13,14,21, 13,20,21, 14,15,21, 15,21,22,
+ 15,11,22, 11,22,23, 11,23,8, 23,16,8);
+
+ wkg->addVerices(24,
+ makeVertex(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12,0,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12+WK_PREWIDTH,0,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12+WK_PREWIDTH,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN+WK_WING,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN+WK_WING,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),////
+ makeVertex(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12,0,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12+WK_PREWIDTH,0,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12+WK_PREWIDTH,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),////
+ makeVertex(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12,0,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12+WK_PREWIDTH,0,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12+WK_PREWIDTH,WK_PRELEN,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2+WK_WING+WK_TALWIDTH/12,WK_PRELEN,0,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN,0,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN,0,0xFFCCCCCC,0,0));
+ wkg->addIndices(60,
+ 0,1,2, 0,2,3, 4,5,6, 4,6,7,
+ 8,9,16, 9,16,17, 9,10,18, 9,17,18,
+ 10,12,18, 12,18,19, 12,13,20, 12,19,20,
+ 13,14,21, 13,20,21, 14,15,21, 15,21,22,
+ 15,11,22, 11,22,23, 11,23,8, 23,16,8);
+
+ wka->addVerices(24,
+ makeVertex(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24-WK_PREWIDTH,0,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24,0,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24-WK_PREWIDTH,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN+WK_WING,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN+WK_WING,WK_HEIGHT,0xFFFFFFFF,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFFFFFFF,0,0),////
+ makeVertex(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24-WK_PREWIDTH,0,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24,0,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24-WK_PREWIDTH,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,WK_HEIGHT,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN,WK_HEIGHT,0xFFCCCCCC,0,0),////
+ makeVertex(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24-WK_PREWIDTH,0,0,0xFFCCCCCC,0,0),
+ makeVertex(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24,0,0,0xFFCCCCCC,0,0),
+ makeVertex(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24,WK_PRELEN,0,0xFFCCCCCC,0,0),
+ makeVertex(WK_TALWIDTH/2-WK_WING-WK_TALWIDTH/24-WK_PREWIDTH,WK_PRELEN,0,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN,0,0xFFCCCCCC,0,0),
+ makeVertex( WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN+WK_TALLEN,0,0xFFCCCCCC,0,0),
+ makeVertex(-WK_TALWIDTH/2,WK_PRELEN,0,0xFFCCCCCC,0,0));
+ wka->addIndices(60,
+ 0,1,2, 0,2,3, 4,5,6, 4,6,7,
+ 8,9,16, 9,16,17, 9,10,18, 9,17,18,
+ 10,12,18, 12,18,19, 12,13,20, 12,19,20,
+ 13,14,21, 13,20,21, 14,15,21, 15,21,22,
+ 15,11,22, 11,22,23, 11,23,8, 23,16,8);
+
+ bk->addVerices(10,
+ makeVertex(-BK_WIDTH/2,0,BK_HEIGHT+BK_BOTTOM,0xFF000000,0,0),
+ makeVertex( BK_WIDTH/2,0,BK_HEIGHT+BK_BOTTOM,0xFF000000,0,0),
+ makeVertex( BK_WIDTH/2,BK_PRELEN,BK_HEIGHT+BK_BOTTOM,0xFF000000,0,0),
+ makeVertex(-BK_WIDTH/2,BK_PRELEN,BK_HEIGHT+BK_BOTTOM,0xFF000000,0,0),
+ makeVertex(-BK_WIDTH/2,WK_PRELEN*0.95,BK_DBOTTOM+BK_BOTTOM,0xFF000000,0,0),
+ makeVertex( BK_WIDTH/2,WK_PRELEN*0.95,BK_DBOTTOM+BK_BOTTOM,0xFF000000,0,0),
+ makeVertex( BK_WIDTH/2,WK_PRELEN*0.95,BK_BOTTOM,0xFF000000,0,0),
+ makeVertex(-BK_WIDTH/2,WK_PRELEN*0.95,BK_BOTTOM,0xFF000000,0,0),
+ makeVertex(-BK_WIDTH/2,0,BK_BOTTOM,0xFF000000,0,0),
+ makeVertex( BK_WIDTH/2,0,BK_BOTTOM,0xFF000000,0,0));
+ bk->addIndices(48,
+ 0,1,3, 1,2,3, 2,3,4, 2,4,5,
+ 4,5,7, 5,6,7, 6,7,8, 6,8,9,
+ 0,1,8, 1,8,9, 2,5,6, 2,6,9,
+ 2,9,1, 3,4,7, 3,7,8, 3,8,0);
}
diff --git a/visualization/qmpvirtualpiano3d.hpp b/visualization/qmpvirtualpiano3d.hpp
index 5c30718..cecd992 100644
--- a/visualization/qmpvirtualpiano3d.hpp
+++ b/visualization/qmpvirtualpiano3d.hpp
@@ -18,6 +18,7 @@ class qmpVirtualPiano3D
{
private:
smEntity3D *wkcf,*wkeb,*wkd,*wkg,*wka,*bk;
+ smEntity3DBuffer *ebuf;
void buildKeys();
double traveld[128];
public:
diff --git a/visualization/qmpvisualization.cpp b/visualization/qmpvisualization.cpp
index 8efe07a..f271507 100644
--- a/visualization/qmpvisualization.cpp
+++ b/visualization/qmpvisualization.cpp
@@ -63,7 +63,8 @@ void qmpVisualization::showThread()
sm->smInit();shouldclose=false;
sm->smTextureOpt(TPOT_POT,TFLT_LINEAR);
chequer=sm->smTextureLoad("chequerboard.png");
- p3d=new qmpVirtualPiano3D();
+ for(int i=0;i<16;++i)p3d[i]=new qmpVirtualPiano3D();
+ memset(traveld,0,sizeof(traveld));
if(!chequer)
chequer=sm->smTextureLoad("/usr/share/qmidiplayer/img/chequerboard.png");
tdscn=sm->smTargetCreate(wwidth*wsupersample,wheight*wsupersample);
@@ -71,7 +72,7 @@ void qmpVisualization::showThread()
printf("W: Font load failed.\n");
if(!font2.loadTTF("/usr/share/fonts/truetype/wqy/wqy-microhei.ttc",16))
printf("W: Font load failed.\n");
- pos[0]=-0;pos[1]=70;pos[2]=20;
+ pos[0]=0;pos[1]=100;pos[2]=20;
rot[0]=0;rot[1]=90;rot[2]=90;ctk=0;
sm->smMainLoop();
}
@@ -82,8 +83,8 @@ void qmpVisualization::show()
void qmpVisualization::close()
{
shouldclose=true;
- delete p3d;
rendererTh->join();
+ for(int i=0;i<16;++i)delete p3d[i];
sm->smFinale();
font.releaseTTF();
font2.releaseTTF();
@@ -108,12 +109,12 @@ bool qmpVisualization::update()
{
smQuad q;
for(int i=0;i<4;++i)
- {q.v[i].col=0xFF999999;q.v[i].z=0;}
+ {q.v[i].col=0xFF999999;q.v[i].z=-5;}
q.tex=chequer;q.blend=BLEND_ALPHABLEND;
- q.v[0].x=q.v[3].x=-60;q.v[1].x=q.v[2].x=60;
- q.v[0].y=q.v[1].y=-60;q.v[2].y=q.v[3].y=60;
- q.v[0].tx=q.v[3].tx=0;q.v[1].tx=q.v[2].tx=15;
- q.v[0].ty=q.v[1].ty=0;q.v[2].ty=q.v[3].ty=15;
+ q.v[0].x=q.v[3].x=-120;q.v[1].x=q.v[2].x=120;
+ q.v[0].y=q.v[1].y=-120;q.v[2].y=q.v[3].y=120;
+ q.v[0].tx=q.v[3].tx=0;q.v[1].tx=q.v[2].tx=30;
+ q.v[0].ty=q.v[1].ty=0;q.v[2].ty=q.v[3].ty=30;
sm->smRenderBegin3D(fov,tdscn);
sm->sm3DCamera6f2v(pos,rot);
sm->smClrscr(0xFF666666);
@@ -155,26 +156,28 @@ bool qmpVisualization::update()
if(fabs((double)pool[i]->tcs-ctk)*lpt<viewdist*2||fabs((double)pool[i]->tce-ctk)*lpt<viewdist*2)
{
if(api->getChannelMask(pool[i]->ch))continue;
- smvec3d a(((double)pool[i]->key-64),15+pool[i]->ch*-3.,((double)pool[i]->tce-ctk)*lpt);
- smvec3d b(((double)pool[i]->key-64)+.9,15+pool[i]->ch*-3.+.6,((double)pool[i]->tcs-ctk)*lpt);
+ smvec3d a(0.63*((double)pool[i]->key-64),64-pool[i]->ch*8.,((double)pool[i]->tce-ctk)*lpt);
+ smvec3d b(0.63*((double)pool[i]->key-64)+0.6,64-pool[i]->ch*8.+.4,((double)pool[i]->tcs-ctk)*lpt);
bool isnoteon=pool[i]->tcs<=ctk&&pool[i]->tce>=ctk;if(isnoteon)
- a.x=((double)pool[i]->key-64+api->getPitchBend(pool[i]->ch)),
- b.x=((double)pool[i]->key-64+api->getPitchBend(pool[i]->ch))+.9;
- notestatus[pool[i]->ch][pool[i]->key]|=isnoteon;
+ a.x=0.63*((double)pool[i]->key-64+api->getPitchBend(pool[i]->ch)),
+ b.x=0.63*((double)pool[i]->key-64+api->getPitchBend(pool[i]->ch))+0.6;
+ notestatus[pool[i]->ch][pool[i]->key]|=isnoteon;a.x*=1.2;b.x*=1.2;
if(((double)pool[i]->tce-pool[i]->tcs)*lpt<minnotelength/100.)a.z=((double)pool[i]->tcs-ctk)*lpt-minnotelength/100.;
drawCube(a,b,SETA(isnoteon?accolors[pool[i]->ch]:iccolors[pool[i]->ch],int(pool[i]->vel*(isnoteon?2.0:1.6))),0);
}
}
for(int i=0;i<16;++i)
- for(int j=0;j<128;++j)
{
- if(notestatus[i][j])
- if(traveld[i][j]<1)traveld[i][j]+=0.2;else traveld[i][j]=1;
- else
- if(traveld[i][j]>0)traveld[i][j]-=0.2;else traveld[i][j]=0;
+ for(int j=0;j<128;++j)
+ {
+ if(notestatus[i][j])
+ if(traveld[i][j]<10)traveld[i][j]+=2;else traveld[i][j]=10;
+ else
+ if(traveld[i][j]>0)traveld[i][j]-=2;else traveld[i][j]=0;
+ p3d[i]->setKeyTravelDist(j,traveld[i][j]/10.);
+ }
+ p3d[i]->render(smvec3d(api->getPitchBend(i),62-i*8,0));
}
- for(int j=0;j<128;++j)p3d->setKeyTravelDist(j,traveld[0][j]);
- //p3d->render(smvec3d(0,15,10));
if(playing)ctk+=(int)(1e6/(api->getRawTempo()/api->getDivision())*sm->smGetDelta());
while(pool.size()&&((double)ctk-pool[elb]->tce)*lpt>viewdist*2)++elb;
sm->smRenderEnd();
diff --git a/visualization/qmpvisualization.hpp b/visualization/qmpvisualization.hpp
index a161111..ecbfd7a 100644
--- a/visualization/qmpvisualization.hpp
+++ b/visualization/qmpvisualization.hpp
@@ -50,13 +50,13 @@ class qmpVisualization:public qmpPluginIntf
SMTRG tdscn;
SMTEX chequer;
smTTFont font,font2;
- qmpVirtualPiano3D* p3d;
+ qmpVirtualPiano3D* p3d[16];
float pos[3],rot[3],lastx,lasty;
uint32_t ctc,ctk,fintk,elb;
double etps;
bool shouldclose,playing;
int hvif,herif,hehif;
- double traveld[16][128];bool notestatus[16][128];
+ int traveld[16][128];bool notestatus[16][128];
void drawCube(smvec3d a,smvec3d b,DWORD col,SMTEX tex);
void showThread();
public: