diff options
author | Chris Xiong <chirs241097@gmail.com> | 2017-01-15 22:08:35 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2017-01-15 22:08:35 +0800 |
commit | 8a0d671e1a77c58142d0cbe82f40ee64bcae2be5 (patch) | |
tree | cb7ce958d02f2bb9e00581a56c28120800521a93 | |
parent | b7842ae90b28618affdad6977c9c814aa573a3fe (diff) | |
download | QMidiPlayer-8a0d671e1a77c58142d0cbe82f40ee64bcae2be5.tar.xz |
A little code refactoring.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | core/qmpmidimapperrtmidi.cpp | 2 | ||||
-rw-r--r-- | core/qmpmidiplay.cpp | 6 | ||||
-rw-r--r-- | core/qmpmidiread.cpp | 4 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpplistwindow.cpp | 2 | ||||
-rw-r--r-- | visualization/qmpvisualization.cpp | 787 | ||||
-rw-r--r-- | visualization/qmpvisualization.hpp | 2 |
7 files changed, 383 insertions, 423 deletions
@@ -1,3 +1,6 @@ +2017-01-15 0.8.3 alpha +A little code refactoring. + 2017-01-02 0.8.3 alpha Can show measure indicators now. Added new options to specify custom fonts. diff --git a/core/qmpmidimapperrtmidi.cpp b/core/qmpmidimapperrtmidi.cpp index 9515a0b..2d4fc26 100644 --- a/core/qmpmidimapperrtmidi.cpp +++ b/core/qmpmidimapperrtmidi.cpp @@ -30,7 +30,7 @@ int qmpMidiMapperRtMidi::deviceInit(int id) ports[i]=new RtMidiOut(); ports[i]->openPort(id); } - catch(RtMidiError e) + catch(RtMidiError &e) { printf("Device initialization failure: %s\n",e.what()); ports[i]=NULL; diff --git a/core/qmpmidiplay.cpp b/core/qmpmidiplay.cpp index 1d32501..9cd7782 100644 --- a/core/qmpmidiplay.cpp +++ b/core/qmpmidiplay.cpp @@ -211,11 +211,7 @@ void CMidiPlayer::playEvents() if(resumed)resumed=false; else if(sendtime.count()<(midiFile->getEvent(tceptr)->time-ct)*dpt) -#if _WIN32 - w32usleep((midiFile->getEvent(tceptr)->time-ct)*(dpt/1000)); -#else std::this_thread::sleep_for(std::chrono::nanoseconds((midiFile->getEvent(tceptr)->time-ct)*dpt-sendtime.count())); -#endif if(tcstop||!midiFile)break; ct=midiFile->getEvent(tceptr)->time; } @@ -463,7 +459,7 @@ void CMidiPlayer::setChannelPreset(int ch,int b,int p) } //16MSB..LSB1 void CMidiPlayer::setBit(uint16_t &n, uint16_t bn, uint16_t b) -{n^=(-b^n)&(1<<bn);} +{n^=(((~b)+1)^n)&(1<<bn);} void CMidiPlayer::setMute(int ch,bool m) {setBit(mute,ch,m?1:0);} void CMidiPlayer::setSolo(int ch,bool s) diff --git a/core/qmpmidiread.cpp b/core/qmpmidiread.cpp index 58a9786..a8bdabb 100644 --- a/core/qmpmidiread.cpp +++ b/core/qmpmidiread.cpp @@ -209,7 +209,7 @@ int CMidiFile::chunkReader(int hdrXp) char hdr[6]; if(!fgets(hdr,5,f))error(1,"E: Unexpected EOF."); if(hdrXp) - if(strncmp(hdr,"MThd",4)){error(1,"E: Wrong MIDI header.");throw;} + if(strncmp(hdr,"MThd",4)){error(1,"E: Wrong MIDI header.");throw 1;} else return headerChunkReader(),0; else if(strncmp(hdr,"MTrk",4)) @@ -243,7 +243,7 @@ CMidiFile::CMidiFile(const char* fn,CMidiPlayer* par) std::sort(eventList.begin(),eventList.end(),cmp); par->maxtk=eventList[eventList.size()-1]->time; } - catch(int){fprintf(stderr,"E: %s is not a supported file.\n",fn);valid=0;} + catch(int&){fprintf(stderr,"E: %s is not a supported file.\n",fn);valid=0;} } CMidiFile::~CMidiFile() { diff --git a/qmidiplayer-desktop/qmpplistwindow.cpp b/qmidiplayer-desktop/qmpplistwindow.cpp index 00eec59..75e2e44 100644 --- a/qmidiplayer-desktop/qmpplistwindow.cpp +++ b/qmidiplayer-desktop/qmpplistwindow.cpp @@ -285,7 +285,7 @@ void qmpPlistWindow::on_pbLoad_clicked() QSettings* plist=new QSettings(QFileDialog::getOpenFileName(this,tr("Load playlist"),""), QSettings::IniFormat); int fc=plist->value("Playlist/FileCount",0).toInt(); - if(!fc)return; + if(!fc){delete plist;return;} ui->lwFiles->clear();for(int i=1;i<=fc;++i) ui->lwFiles->addItem(plist->value("Playlist/File"+QString("%1").arg(i,5,10,QChar('0')),"").toString()); repeat=plist->value("Playlist/Repeat",0).toInt(); diff --git a/visualization/qmpvisualization.cpp b/visualization/qmpvisualization.cpp index 11abb3f..ca7e8d6 100644 --- a/visualization/qmpvisualization.cpp +++ b/visualization/qmpvisualization.cpp @@ -242,476 +242,435 @@ void qmpVisualization::reset() void qmpVisualization::start(){playing=true;} void qmpVisualization::stop(){playing=false;} void qmpVisualization::pause(){playing=!playing;} -bool qmpVisualization::update() +void qmpVisualization::updateVisualization3D() { smQuad q; - if(sm->smGetKeyState(SMK_RIGHT)==SMKST_HIT) - api->playerSeek(api->getCurrentPlaybackPercentage()+(sm->smGetKeyState(SMK_SHIFT)?5:1)); - if(sm->smGetKeyState(SMK_LEFT)==SMKST_HIT) - api->playerSeek(api->getCurrentPlaybackPercentage()-(sm->smGetKeyState(SMK_SHIFT)?5:1)); - if(!flat) + if(sm->smGetKeyState(SMK_D))pos[0]+=cos(smMath::deg2rad(rot[2]-90)),pos[1]+=sin(smMath::deg2rad(rot[2]-90)); + if(sm->smGetKeyState(SMK_A))pos[0]-=cos(smMath::deg2rad(rot[2]-90)),pos[1]-=sin(smMath::deg2rad(rot[2]-90)); + if(sm->smGetKeyState(SMK_S))pos[0]+=cos(smMath::deg2rad(rot[2])),pos[1]+=sin(smMath::deg2rad(rot[2])); + if(sm->smGetKeyState(SMK_W))pos[0]-=cos(smMath::deg2rad(rot[2])),pos[1]-=sin(smMath::deg2rad(rot[2])); + if(sm->smGetKeyState(SMK_Q))pos[2]+=1; + if(sm->smGetKeyState(SMK_E))pos[2]-=1; + if(sm->smGetKeyState(SMK_R)) { - for(int i=0;i<4;++i) - {q.v[i].col=chkrtint;q.v[i].z=(showpiano&&!horizontal)?-5:0;} - q.tex=chequer;q.blend=BLEND_ALPHABLEND; - 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; if(horizontal) { - for(int i=0;i<4;++i)q.v[i].x=-20; - q.v[0].y=q.v[3].y=-120;q.v[1].y=q.v[2].y=120; - q.v[0].z=q.v[1].z=-120;q.v[2].z=q.v[3].z=120; + pos[0]=-20;pos[1]=45;pos[2]=0; + rot[0]=0;rot[1]=90;rot[2]=90; } - 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,true,tdscn); - sm->sm3DCamera6f2v(pos,rot); - sm->smClrscr(0,1,1); - sm->smRenderQuad(&q); - if(sm->smGetKeyState(SMK_D))pos[0]+=cos(smMath::deg2rad(rot[2]-90)),pos[1]+=sin(smMath::deg2rad(rot[2]-90)); - if(sm->smGetKeyState(SMK_A))pos[0]-=cos(smMath::deg2rad(rot[2]-90)),pos[1]-=sin(smMath::deg2rad(rot[2]-90)); - if(sm->smGetKeyState(SMK_S))pos[0]+=cos(smMath::deg2rad(rot[2])),pos[1]+=sin(smMath::deg2rad(rot[2])); - if(sm->smGetKeyState(SMK_W))pos[0]-=cos(smMath::deg2rad(rot[2])),pos[1]-=sin(smMath::deg2rad(rot[2])); - if(sm->smGetKeyState(SMK_Q))pos[2]+=1; - if(sm->smGetKeyState(SMK_E))pos[2]-=1; - if(sm->smGetKeyState(SMK_R)) - { - if(horizontal) - { - pos[0]=-20;pos[1]=45;pos[2]=0; - rot[0]=0;rot[1]=90;rot[2]=90; - } - else - { - pos[0]=0;pos[1]=120;pos[2]=70; - rot[0]=0;rot[1]=75;rot[2]=90; - } - } - if(sm->smGetKeyState(SMK_LBUTTON)==SMKST_HIT) - sm->smSetMouseGrab(true),sm->smGetMouse2f(&lastx,&lasty); - if(sm->smGetKeyState(SMK_LBUTTON)==SMKST_KEEP) + else { - float x,y; - sm->smGetMouse2f(&x,&y); - rot[1]-=(y-lasty)*0.01; - rot[2]+=(x-lastx)*0.01; - while(rot[1]>360)rot[1]-=360; - while(rot[1]<0)rot[1]+=360; - while(rot[2]>360)rot[2]-=360; - while(rot[2]<0)rot[2]+=360; + pos[0]=0;pos[1]=120;pos[2]=70; + rot[0]=0;rot[1]=75;rot[2]=90; } - if(sm->smGetKeyState(SMK_LBUTTON)==SMKST_RELEASE) + } + if(sm->smGetKeyState(SMK_LBUTTON)==SMKST_HIT) + sm->smSetMouseGrab(true),sm->smGetMouse2f(&lastx,&lasty); + if(sm->smGetKeyState(SMK_LBUTTON)==SMKST_KEEP) + { + float x,y; + sm->smGetMouse2f(&x,&y); + rot[1]-=(y-lasty)*0.01; + rot[2]+=(x-lastx)*0.01; + while(rot[1]>360)rot[1]-=360; + while(rot[1]<0)rot[1]+=360; + while(rot[2]>360)rot[2]-=360; + while(rot[2]<0)rot[2]+=360; + } + if(sm->smGetKeyState(SMK_LBUTTON)==SMKST_RELEASE) + { sm->smSetMouseGrab(false); - if(sm->smGetKeyState(SMK_I))rot[1]+=1; - if(sm->smGetKeyState(SMK_K))rot[1]-=1; - if(sm->smGetKeyState(SMK_L))rot[0]+=1; - if(sm->smGetKeyState(SMK_J))rot[0]-=1; - if(sm->smGetKeyState(SMK_U))rot[2]+=1; - if(sm->smGetKeyState(SMK_O))rot[2]-=1; - //printf("pos: %f %f %f\n",pos[0],pos[1],pos[2]); - //printf("rot: %f %f %f\n",rot[0],rot[1],rot[2]); - double lpt=(double)notestretch/api->getDivision()/10.*(horizontal?0.25:1); - memcpy(lastnotestatus,notestatus,sizeof(notestatus)); - memset(notestatus,0,sizeof(notestatus)); - for(uint32_t i=elb;i<pool.size();++i) + sm->smSetMouse2f(wwidth/2,wheight/2); + } + if(sm->smGetKeyState(SMK_I))rot[1]+=1; + if(sm->smGetKeyState(SMK_K))rot[1]-=1; + if(sm->smGetKeyState(SMK_L))rot[0]+=1; + if(sm->smGetKeyState(SMK_J))rot[0]-=1; + if(sm->smGetKeyState(SMK_U))rot[2]+=1; + if(sm->smGetKeyState(SMK_O))rot[2]-=1; + for(int i=0;i<4;++i) + {q.v[i].col=chkrtint;q.v[i].z=(showpiano&&!horizontal)?-5:0;} + q.tex=chequer;q.blend=BLEND_ALPHABLEND; + 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; + if(horizontal) + { + for(int i=0;i<4;++i)q.v[i].x=-20; + q.v[0].y=q.v[3].y=-120;q.v[1].y=q.v[2].y=120; + q.v[0].z=q.v[1].z=-120;q.v[2].z=q.v[3].z=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,true,tdscn); + sm->sm3DCamera6f2v(pos,rot); + sm->smClrscr(0,1,1); + sm->smRenderQuad(&q); + double lpt=(double)notestretch/api->getDivision()/10.*(horizontal?0.25:1); + memcpy(lastnotestatus,notestatus,sizeof(notestatus)); + memset(notestatus,0,sizeof(notestatus)); + for(uint32_t i=elb;i<pool.size();++i) + { + if(((double)pool[i]->tcs-ctk)*lpt>viewdist*2)break; + if(fabs((double)pool[i]->tcs-ctk)*lpt<viewdist*2||fabs((double)pool[i]->tce-ctk)*lpt<viewdist*2) { - if(((double)pool[i]->tcs-ctk)*lpt>viewdist*2)break; - if(fabs((double)pool[i]->tcs-ctk)*lpt<viewdist*2||fabs((double)pool[i]->tce-ctk)*lpt<viewdist*2) - { - if(pool[i]->ch==999){ - if(!horizontal&&stairpiano){ - for(int ch=0;ch<16;++ch){ - smvec3d a(0.63*(-80)+.1,(stairpiano?(56-ch*7.):(64-ch*8.))-1,((double)pool[i]->tce+1-ctk)*lpt+(stairpiano&&showpiano&&!horizontal)*ch*2.); - smvec3d b(0.63*80+.7,(stairpiano?(56-ch*7.):(64-ch*8.))+4,((double)pool[i]->tcs-ctk)*lpt+(stairpiano&&showpiano&&!horizontal)*ch*2.); - if(horizontal){ - a=smvec3d(((double)pool[i]->tcs-ctk)*lpt-20,(16-ch*2.),0.63*(-64)+.1); - b=smvec3d(((double)pool[i]->tce+1-ctk)*lpt-20,(16-ch*2.)+.4,0.63*64+.7); - } - if(showmeasure)drawCube(a,b,0x80808080,0); - } - } - else{ - smvec3d a(0.63*(-64)+.1,(stairpiano?(56-0*7.):(64-0*8.)),((double)pool[i]->tce+1-ctk)*lpt+(stairpiano&&showpiano&&!horizontal)*0*2.); - smvec3d b(0.63*64+.7,(stairpiano?(56-15*7.):(64-15*8.))+.4,((double)pool[i]->tcs-ctk)*lpt+(stairpiano&&showpiano&&!horizontal)*15*2.); + if(pool[i]->ch==999){ + if(!horizontal&&stairpiano){ + for(int ch=0;ch<16;++ch){ + smvec3d a(0.63*(-80)+.1,(stairpiano?(56-ch*7.):(64-ch*8.))-1,((double)pool[i]->tce+1-ctk)*lpt+(stairpiano&&showpiano&&!horizontal)*ch*2.); + smvec3d b(0.63*80+.7,(stairpiano?(56-ch*7.):(64-ch*8.))+4,((double)pool[i]->tcs-ctk)*lpt+(stairpiano&&showpiano&&!horizontal)*ch*2.); if(horizontal){ - a=smvec3d(((double)pool[i]->tcs-ctk)*lpt-20,(16-0*2.),0.63*(-64)+.1); - b=smvec3d(((double)pool[i]->tce+1-ctk)*lpt-20,(16-15*2.)+.4,0.63*64+.7); + a=smvec3d(((double)pool[i]->tcs-ctk)*lpt-20,(16-ch*2.),0.63*(-64)+.1); + b=smvec3d(((double)pool[i]->tce+1-ctk)*lpt-20,(16-ch*2.)+.4,0.63*64+.7); } if(showmeasure)drawCube(a,b,0x80808080,0); } - continue; } - if(api->getChannelMask(pool[i]->ch))continue; - smvec3d a(0.63*((double)pool[i]->key-64)+.1,(stairpiano?(56-pool[i]->ch*7.):(64-pool[i]->ch*8.)),((double)pool[i]->tce-ctk)*lpt+(stairpiano&&showpiano&&!horizontal)*pool[i]->ch*2.); - smvec3d b(0.63*((double)pool[i]->key-64)+.7,(stairpiano?(56-pool[i]->ch*7.):(64-pool[i]->ch*8.))+.4,((double)pool[i]->tcs-ctk)*lpt+(stairpiano&&showpiano&&!horizontal)*pool[i]->ch*2.); - bool isnoteon=pool[i]->tcs<=ctk&&pool[i]->tce>=ctk;if(isnoteon) - a.x=0.63*((double)pool[i]->key-64+api->getPitchBend(pool[i]->ch))+.1, - b.x=0.63*((double)pool[i]->key-64+api->getPitchBend(pool[i]->ch))+.7; - notestatus[pool[i]->ch][pool[i]->key]|=isnoteon;a.x*=1.2;b.x*=1.2; - if(horizontal) - { - a=smvec3d(((double)pool[i]->tcs-ctk)*lpt-20,(16-pool[i]->ch*2.),0.63*((double)pool[i]->key-64)+.1); - b=smvec3d(((double)pool[i]->tce-ctk)*lpt-20,(16-pool[i]->ch*2.)+.4,0.63*((double)pool[i]->key-64)+.7); - if(isnoteon) - a.z=0.63*((double)pool[i]->key-64+api->getPitchBend(pool[i]->ch))+.1, - b.z=0.63*((double)pool[i]->key-64+api->getPitchBend(pool[i]->ch))+.7; - } - if(showparticle&&!horizontal) - { - if(notestatus[pool[i]->ch][pool[i]->key]&&!lastnotestatus[pool[i]->ch][pool[i]->key]) - { - pss[pool[i]->ch][pool[i]->key]->startPS(); - pss[pool[i]->ch][pool[i]->key]->setPos(smvec3d(0.756*((double)pool[i]->key-64)+.48,(stairpiano?(56-pool[i]->ch*7.):(64-pool[i]->ch*8.)),stairpiano*pool[i]->ch*2+0.1)); + else{ + smvec3d a(0.63*(-64)+.1,(stairpiano?(56-0*7.):(64-0*8.)),((double)pool[i]->tce+1-ctk)*lpt+(stairpiano&&showpiano&&!horizontal)*0*2.); + smvec3d b(0.63*64+.7,(stairpiano?(56-15*7.):(64-15*8.))+.4,((double)pool[i]->tcs-ctk)*lpt+(stairpiano&&showpiano&&!horizontal)*15*2.); + if(horizontal){ + a=smvec3d(((double)pool[i]->tcs-ctk)*lpt-20,(16-0*2.),0.63*(-64)+.1); + b=smvec3d(((double)pool[i]->tce+1-ctk)*lpt-20,(16-15*2.)+.4,0.63*64+.7); } - else pss[pool[i]->ch][pool[i]->key]->stopPS(); + if(showmeasure)drawCube(a,b,0x80808080,0); } - if(((double)pool[i]->tce-pool[i]->tcs)*lpt<minnotelength*(horizontal?0.0025:0.01)) - {if(horizontal)a.x=((double)pool[i]->tcs-ctk)*lpt-minnotelength/100.-20; - else a.z=((double)pool[i]->tcs-ctk)*lpt-minnotelength/100.+stairpiano*pool[i]->ch*2;} - if(usespectrum) - { - if(notestatus[pool[i]->ch][pool[i]->key]&&!lastnotestatus[pool[i]->ch][pool[i]->key]) - spectra[pool[i]->ch][pool[i]->key]=pool[i]->vel*(api->getChannelCC(pool[i]->ch,7)/127.); - } - else - drawCube(a,b,SETA(isnoteon?accolors[pool[i]->ch]:iccolors[pool[i]->ch],int(pool[i]->vel*1.6+(isnoteon?52:32))),0); + continue; } - } - if(usespectrum&&playing) - for(int i=0;i<16;++i)for(int j=0;j<128;++j) - { - if(sustaininst.find(api->getChannelPreset(i))!=sustaininst.end()) - { - if(!notestatus[i][j]&&spectra[i][j]) - spectra[i][j]=.95*spectra[i][j]; - }else if(spectra[i][j])spectra[i][j]=.95*spectra[i][j]; - if(spectrar[i][j]<spectra[i][j]*0.9)spectrar[i][j]+=spectra[i][j]*0.2; - else spectrar[i][j]=spectra[i][j]; - if(spectrar[i][j]) + if(api->getChannelMask(pool[i]->ch))continue; + smvec3d a(0.63*((double)pool[i]->key-64)+.1,(stairpiano?(56-pool[i]->ch*7.):(64-pool[i]->ch*8.)),((double)pool[i]->tce-ctk)*lpt+(stairpiano&&showpiano&&!horizontal)*pool[i]->ch*2.); + smvec3d b(0.63*((double)pool[i]->key-64)+.7,(stairpiano?(56-pool[i]->ch*7.):(64-pool[i]->ch*8.))+.4,((double)pool[i]->tcs-ctk)*lpt+(stairpiano&&showpiano&&!horizontal)*pool[i]->ch*2.); + bool isnoteon=pool[i]->tcs<=ctk&&pool[i]->tce>=ctk;if(isnoteon) + a.x=0.63*((double)pool[i]->key-64+api->getPitchBend(pool[i]->ch))+.1, + b.x=0.63*((double)pool[i]->key-64+api->getPitchBend(pool[i]->ch))+.7; + notestatus[pool[i]->ch][pool[i]->key]|=isnoteon;a.x*=1.2;b.x*=1.2; + if(horizontal) { - smvec3d a(0.756*((double)j-64+api->getPitchBend(i))+.12, - (stairpiano?(56-i*7.):(64-i*8.)), - spectrar[i][j]*1.2*(1+0.02*sin(sm->smGetTime()*32))+(stairpiano&&showpiano&&!horizontal)*i*2.); - smvec3d b(0.756*((double)j-64+api->getPitchBend(i))+.84, - (stairpiano?(56-i*7.):(64-i*8.))+.4, - (stairpiano&&showpiano&&!horizontal)*i*2.); - drawCube(a,b,SETA(iccolors[i],204),0); + a=smvec3d(((double)pool[i]->tcs-ctk)*lpt-20,(16-pool[i]->ch*2.),0.63*((double)pool[i]->key-64)+.1); + b=smvec3d(((double)pool[i]->tce-ctk)*lpt-20,(16-pool[i]->ch*2.)+.4,0.63*((double)pool[i]->key-64)+.7); + if(isnoteon) + a.z=0.63*((double)pool[i]->key-64+api->getPitchBend(pool[i]->ch))+.1, + b.z=0.63*((double)pool[i]->key-64+api->getPitchBend(pool[i]->ch))+.7; } - } - if(noteappearance)nebuf->drawBatch(); - if(showpiano&&!horizontal) - for(int i=0;i<16;++i) - { - for(int j=0;j<128;++j) + if(showparticle&&!horizontal) { - 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.); + if(notestatus[pool[i]->ch][pool[i]->key]&&!lastnotestatus[pool[i]->ch][pool[i]->key]) + { + pss[pool[i]->ch][pool[i]->key]->startPS(); + pss[pool[i]->ch][pool[i]->key]->setPos(smvec3d(0.756*((double)pool[i]->key-64)+.48,(stairpiano?(56-pool[i]->ch*7.):(64-pool[i]->ch*8.)),stairpiano*pool[i]->ch*2+0.1)); + } + else pss[pool[i]->ch][pool[i]->key]->stopPS(); } - p3d[i]->render(smvec3d(0.756*api->getPitchBend(i),stairpiano?55-i*7:62-i*8,stairpiano*i*2)); - if(showlabel) + if(((double)pool[i]->tce-pool[i]->tcs)*lpt<minnotelength*(horizontal?0.0025:0.01)) + {if(horizontal)a.x=((double)pool[i]->tcs-ctk)*lpt-minnotelength/100.-20; + else a.z=((double)pool[i]->tcs-ctk)*lpt-minnotelength/100.+stairpiano*pool[i]->ch*2;} + if(usespectrum) { - std::string s=api->getChannelPresetString(i); - wchar_t ws[1024];mbstowcs(ws,s.c_str(),1024); - fonthdpi.updateString(ws); - fonthdpi.render(-49,stairpiano?56-i*7:63-i*8,stairpiano*i*2+0.1,0xFFFFFFFF,ALIGN_RIGHT,.008,0.01); - fonthdpi.render(-49.05,stairpiano?56.05-i*7:63.05-i*8,stairpiano*i*2+0.2,0xFF000000,ALIGN_RIGHT,.008,0.01); + if(notestatus[pool[i]->ch][pool[i]->key]&&!lastnotestatus[pool[i]->ch][pool[i]->key]) + spectra[pool[i]->ch][pool[i]->key]=pool[i]->vel*(api->getChannelCC(pool[i]->ch,7)/127.); } + else + drawCube(a,b,SETA(isnoteon?accolors[pool[i]->ch]:iccolors[pool[i]->ch],int(pool[i]->vel*1.6+(isnoteon?52:32))),0); } - if(playing)ctk+=(int)1e6/((double)api->getRawTempo()/api->getDivision())*sm->smGetDelta(); - while(pool.size()&&elb<pool.size()&&((double)ctk-pool[elb]->tce)*lpt>viewdist*2)++elb; - sm->smRenderEnd(); - if(showparticle&&!horizontal) + } + if(usespectrum&&playing) + for(int i=0;i<16;++i)for(int j=0;j<128;++j) + { + if(sustaininst.find(api->getChannelPreset(i))!=sustaininst.end()) { - sm->smRenderBegin3D(fov,false,tdparticles); - sm->sm3DCamera6f2v(pos,rot); - sm->smClrscr(0,1,1); - for(int i=0;i<16;++i)for(int j=0;j<128;++j) - { - pss[i][j]->setPSLookAt(smvec3d(pos[0],pos[1],pos[2])); - pss[i][j]->updatePS();pss[i][j]->renderPS(); - } - sm->smRenderEnd(); + if(!notestatus[i][j]&&spectra[i][j]) + spectra[i][j]=.95*spectra[i][j]; + }else if(spectra[i][j])spectra[i][j]=.95*spectra[i][j]; + if(spectrar[i][j]<spectra[i][j]*0.9)spectrar[i][j]+=spectra[i][j]*0.2; + else spectrar[i][j]=spectra[i][j]; + if(spectrar[i][j]) + { + smvec3d a(0.756*((double)j-64+api->getPitchBend(i))+.12, + (stairpiano?(56-i*7.):(64-i*8.)), + spectrar[i][j]*1.2*(1+0.02*sin(sm->smGetTime()*32))+(stairpiano&&showpiano&&!horizontal)*i*2.); + smvec3d b(0.756*((double)j-64+api->getPitchBend(i))+.84, + (stairpiano?(56-i*7.):(64-i*8.))+.4, + (stairpiano&&showpiano&&!horizontal)*i*2.); + drawCube(a,b,SETA(iccolors[i],204),0); } } - sm->smRenderBegin2D(); - sm->smClrscr(0xFF666666);q.blend=BLEND_ALPHABLEND; - for(int i=0;i<4;++i){q.v[i].col=0xFFFFFFFF;q.v[i].z=0;} - if(bgtex) + if(noteappearance)nebuf->drawBatch(); + if(showpiano&&!horizontal) + for(int i=0;i<16;++i) { - q.tex=bgtex; - q.v[0].x=q.v[3].x=0;q.v[1].x=q.v[2].x=wwidth; - q.v[0].y=q.v[1].y=0;q.v[2].y=q.v[3].y=wheight; - q.v[0].tx=q.v[3].tx=0;q.v[1].tx=q.v[2].tx=1; - q.v[0].ty=q.v[1].ty=0;q.v[2].ty=q.v[3].ty=1; - sm->smRenderQuad(&q); + 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(0.756*api->getPitchBend(i),stairpiano?55-i*7:62-i*8,stairpiano*i*2)); + if(showlabel) + { + std::string s=api->getChannelPresetString(i); + wchar_t ws[1024];mbstowcs(ws,s.c_str(),1024); + fonthdpi.updateString(ws); + fonthdpi.render(-49,stairpiano?56-i*7:63-i*8,stairpiano*i*2+0.1,0xFFFFFFFF,ALIGN_RIGHT,.008,0.01); + fonthdpi.render(-49.05,stairpiano?56.05-i*7:63.05-i*8,stairpiano*i*2+0.2,0xFF000000,ALIGN_RIGHT,.008,0.01); + } } - if(flat) + if(playing)ctk+=(int)1e6/((double)api->getRawTempo()/api->getDivision())*sm->smGetDelta(); + while(pool.size()&&elb<pool.size()&&((double)ctk-pool[elb]->tce)*lpt>viewdist*2)++elb; + sm->smRenderEnd(); + if(showparticle&&!horizontal) { - double lpt=-(double)notestretch/api->getDivision()/2.; - memset(notestatus,0,sizeof(notestatus)); - if(!horizontal) + sm->smRenderBegin3D(fov,false,tdparticles); + sm->sm3DCamera6f2v(pos,rot); + sm->smClrscr(0,1,1); + for(int i=0;i<16;++i)for(int j=0;j<128;++j) { - double notew=wwidth/128,nh=showpiano?wwidth/2048.*172.:0; - smQuad nq;nq.blend=BLEND_ALPHABLEND;nq.tex=0; - for(int i=0;i<4;++i)nq.v[i].z=0,nq.v[i].tx=nq.v[i].ty=0; - for(uint32_t i=elb;i<pool.size();++i) - { - if(((double)pool[i]->tcs-ctk)*lpt+wheight-nh<0)break; - if(fabs((double)pool[i]->tcs-ctk)*lpt+wheight-nh>0||fabs((double)pool[i]->tce-ctk)*lpt+wheight-nh<wheight) + pss[i][j]->setPSLookAt(smvec3d(pos[0],pos[1],pos[2])); + pss[i][j]->updatePS();pss[i][j]->renderPS(); + } + sm->smRenderEnd(); + } +} +void qmpVisualization::updateVisualization2D() +{ + double lpt=-(double)notestretch/api->getDivision()/2.; + memset(notestatus,0,sizeof(notestatus)); + double notew=wwidth/128,nh=showpiano?wwidth/2048.*172.:0; + if(horizontal){notew=wheight/128;nh=showpiano?wheight/2048.*172.:0;lpt=-lpt;} + smQuad nq;nq.blend=BLEND_ALPHABLEND;nq.tex=0; + for(int i=0;i<4;++i)nq.v[i].z=0,nq.v[i].tx=nq.v[i].ty=0; + for(uint32_t i=elb;i<pool.size();++i) + { + bool upperbound=fabs((double)pool[i]->tcs-ctk)*lpt+wheight-nh<0; + bool lowerbound=fabs((double)pool[i]->tce-ctk)*lpt+wheight-nh<wheight; + if(horizontal) + { + upperbound=fabs((double)pool[i]->tcs-ctk)*lpt+nh>wwidth; + lowerbound=fabs((double)pool[i]->tce-ctk)*lpt+nh>0; + } + if(upperbound)break; + if(!upperbound||lowerbound) + { + if(pool[i]->ch==999){ + smvec2d a(0,((double)pool[i]->tcs-ctk)*lpt+wheight-nh-minnotelength*0.02); + smvec2d b(wwidth,((double)pool[i]->tcs-ctk)*lpt+wheight-nh); + if(horizontal) { - if(pool[i]->ch==999){ - smvec2d a(0,((double)pool[i]->tcs-ctk)*lpt+wheight-nh-minnotelength*0.02); - smvec2d b(wwidth,((double)pool[i]->tcs-ctk)*lpt+wheight-nh); - nq.v[0].x=nq.v[3].x=a.x;nq.v[0].y=nq.v[1].y=a.y; - nq.v[1].x=nq.v[2].x=b.x;nq.v[2].y=nq.v[3].y=b.y;for(int j=0;j<4;++j) - nq.v[j].col=0xC0000000; - if(showmeasure)sm->smRenderQuad(&nq); - continue; - } - if(api->getChannelMask(pool[i]->ch))continue; - smvec2d a((froffsets[12]*(pool[i]->key/12)+froffsets[pool[i]->key%12])*wwidth/2048.,((double)pool[i]->tce-ctk)*lpt+wheight-nh); - smvec2d b(a.x+notew*0.9,((double)pool[i]->tcs-ctk)*lpt+wheight-nh); - bool isnoteon=pool[i]->tcs<=ctk&&pool[i]->tce>=ctk;if(isnoteon) - { - uint32_t newkey=pool[i]->key+(int)floor(api->getPitchBend(pool[i]->ch)); - double fpb=api->getPitchBend(pool[i]->ch)-floor(api->getPitchBend(pool[i]->ch)); - a.x=(froffsets[12]*(newkey/12)+froffsets[newkey%12])*wwidth/2048.+notew*fpb; - b.x=a.x+notew*0.9; - } - notestatus[pool[i]->ch][pool[i]->key]|=isnoteon; - if(((double)pool[i]->tcs-pool[i]->tce)*lpt<minnotelength*0.04) - a.y=((double)pool[i]->tcs-ctk)*lpt+wheight-nh-minnotelength*0.04; - nq.v[0].x=nq.v[3].x=a.x;nq.v[0].y=nq.v[1].y=a.y; - nq.v[1].x=nq.v[2].x=b.x;nq.v[2].y=nq.v[3].y=b.y;for(int j=0;j<4;++j) - nq.v[j].col=SETA(isnoteon?accolors[pool[i]->ch]:iccolors[pool[i]->ch],int(pool[i]->vel*1.6+(isnoteon?52:32))); - if(usespectrum) - { - if(notestatus[pool[i]->ch][pool[i]->key]&&!lastnotestatus[pool[i]->ch][pool[i]->key]) - spectra[pool[i]->ch][pool[i]->key]=pool[i]->vel*(api->getChannelCC(pool[i]->ch,7)/127.); - } - else sm->smRenderQuad(&nq); + a=smvec2d(((double)pool[i]->tcs-ctk)*lpt+nh-minnotelength*0.02,0); + b=smvec2d(((double)pool[i]->tcs-ctk)*lpt+nh,wheight); } + nq.v[0].x=nq.v[3].x=a.x;nq.v[0].y=nq.v[1].y=a.y; + nq.v[1].x=nq.v[2].x=b.x;nq.v[2].y=nq.v[3].y=b.y;for(int j=0;j<4;++j) + nq.v[j].col=0xC0000000; + if(showmeasure)sm->smRenderQuad(&nq); + continue; } - while(pool.size()&&elb<pool.size()&&fabs((double)pool[elb]->tce-ctk)*lpt+wheight-nh>wheight)++elb; - q.tex=pianotex; - q.v[0].ty=q.v[3].ty=0;q.v[1].ty=q.v[2].ty=172./256.; - q.v[0].tx=q.v[1].tx=0;q.v[2].tx=q.v[3].tx=1.; - q.v[0].x=q.v[1].x=0;q.v[2].x=q.v[3].x=wwidth; - q.v[0].y=q.v[3].y=wheight-nh;q.v[1].y=q.v[2].y=wheight; - sm->smRenderQuad(&q); - for(int i=0,j;i<128;++i) + if(api->getChannelMask(pool[i]->ch))continue; + smvec2d a((froffsets[12]*(pool[i]->key/12)+froffsets[pool[i]->key%12])*wwidth/2048.,((double)pool[i]->tce-ctk)*lpt+wheight-nh); + smvec2d b(a.x+notew*0.9,((double)pool[i]->tcs-ctk)*lpt+wheight-nh); + if(horizontal) { - DWORD c=0;for(j=0;j<16;++j)if(notestatus[j][i]){c=SETA(iccolors[j],0xFF);break;} - q.v[0].x=q.v[1].x=(fpoffsets[12]*(i/12)+fpoffsets[i%12])*wwidth/2048.; - q.v[2].x=q.v[3].x=q.v[0].x; - q.v[0].y=q.v[3].y=wheight-nh;q.v[1].y=q.v[2].y=wheight; - if(!c)continue;for(int j=0;j<4;++j)q.v[j].col=c; - switch(i%12) - { - case 1:case 3:case 6:case 8:case 10: - q.v[1].y=q.v[2].y=wheight-nh+115*wwidth/2048.; - q.v[2].x+=15.*wwidth/2048;q.v[3].x+=15.*wwidth/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-15/256.; - q.v[0].tx=q.v[3].tx=1344/2048.;q.v[1].tx=q.v[2].tx=1459/2048.; - break; - case 0: - q.v[2].x+=27.*wwidth/2048;q.v[3].x+=27.*wwidth/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-27/256.; - q.v[0].tx=q.v[3].tx=0/2048.;q.v[1].tx=q.v[2].tx=172/2048.; - break; - case 2: - q.v[2].x+=29.*wwidth/2048;q.v[3].x+=29.*wwidth/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-29/256.; - q.v[0].tx=q.v[3].tx=192/2048.;q.v[1].tx=q.v[2].tx=364/2048.; - break; - case 4: - q.v[2].x+=28.*wwidth/2048;q.v[3].x+=28.*wwidth/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-28/256.; - q.v[0].tx=q.v[3].tx=384/2048.;q.v[1].tx=q.v[2].tx=556/2048.; - break; - case 5: - q.v[2].x+=28.*wwidth/2048;q.v[3].x+=28.*wwidth/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-28/256.; - q.v[0].tx=q.v[3].tx=576/2048.;q.v[1].tx=q.v[2].tx=748/2048.; - break; - case 7: - q.v[2].x+=29.*wwidth/2048;q.v[3].x+=29.*wwidth/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-29/256.; - q.v[0].tx=q.v[3].tx=768/2048.;q.v[1].tx=q.v[2].tx=940/2048.; - break; - case 9: - q.v[2].x+=28.*wwidth/2048;q.v[3].x+=28.*wwidth/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-28/256.; - q.v[0].tx=q.v[3].tx=960/2048.;q.v[1].tx=q.v[2].tx=1132/2048.; - break; - case 11: - q.v[2].x+=28.*wwidth/2048;q.v[3].x+=28.*wwidth/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-28/256.; - q.v[0].tx=q.v[3].tx=1152/2048.;q.v[1].tx=q.v[2].tx=1324/2048.; - break; - } - sm->smRenderQuad(&q); + a=smvec2d(((double)pool[i]->tce-ctk)*lpt+nh,(froffsets[12]*(pool[i]->key/12)+froffsets[pool[i]->key%12])*wheight/2048.); + b=smvec2d(((double)pool[i]->tcs-ctk)*lpt+nh,a.y+notew*0.9); } - if(usespectrum&&playing) - for(int i=0;i<16;++i)for(int j=0;j<128;++j) + bool isnoteon=pool[i]->tcs<=ctk&&pool[i]->tce>=ctk;if(isnoteon) { - if(sustaininst.find(api->getChannelPreset(i))!=sustaininst.end()) + uint32_t newkey=pool[i]->key+(int)floor(api->getPitchBend(pool[i]->ch)); + double fpb=api->getPitchBend(pool[i]->ch)-floor(api->getPitchBend(pool[i]->ch)); + if(horizontal) { - if(!notestatus[i][j]&&spectra[i][j]) - spectra[i][j]=.95*spectra[i][j]; - }else if(spectra[i][j])spectra[i][j]=.95*spectra[i][j]; - if(spectrar[i][j]<spectra[i][j]*0.9)spectrar[i][j]+=spectra[i][j]*0.2; - else spectrar[i][j]=spectra[i][j]; - if(spectrar[i][j]) + a.y=(froffsets[12]*(newkey/12)+froffsets[newkey%12])*wheight/2048.+notew*fpb; + b.y=a.y+notew*0.9; + } + else { - smvec2d a((froffsets[12]*(j/12)+froffsets[j%12])*wwidth/2048.,spectrar[i][j]/-128.*(wheight-nh)*(1+0.02*sin(sm->smGetTime()*32))+wheight-nh); - smvec2d b(a.x+notew*0.9,lpt+wheight-nh); - uint32_t newkey=j+(int)floor(api->getPitchBend(i)); - double fpb=api->getPitchBend(i)-floor(api->getPitchBend(i)); a.x=(froffsets[12]*(newkey/12)+froffsets[newkey%12])*wwidth/2048.+notew*fpb; b.x=a.x+notew*0.9; - nq.v[0].x=nq.v[3].x=a.x;nq.v[0].y=nq.v[1].y=a.y; - nq.v[1].x=nq.v[2].x=b.x;nq.v[2].y=nq.v[3].y=b.y;for(int j=0;j<4;++j) - nq.v[j].col=SETA(iccolors[i],204); - sm->smRenderQuad(&nq); } } - } - else - { - double notew=wheight/128,nh=showpiano?wheight/2048.*172.:0;lpt=-lpt; - smQuad nq;nq.blend=BLEND_ALPHABLEND;nq.tex=0; - for(int i=0;i<4;++i)nq.v[i].z=0,nq.v[i].tx=nq.v[i].ty=0; - for(uint32_t i=elb;i<pool.size();++i) + if(horizontal)a.y=wheight-a.y;b.y=wheight-b.y; + notestatus[pool[i]->ch][pool[i]->key]|=isnoteon; + if(horizontal) { - if(((double)pool[i]->tcs-ctk)*lpt+nh>wwidth)break; - if(fabs((double)pool[i]->tcs-ctk)*lpt+nh<wwidth||fabs((double)pool[i]->tce-ctk)*lpt+nh>0) - { - if(pool[i]->ch==999){ - smvec2d a(((double)pool[i]->tcs-ctk)*lpt+nh-minnotelength*0.02,0); - smvec2d b(((double)pool[i]->tcs-ctk)*lpt+nh,wheight); - nq.v[0].x=nq.v[3].x=a.x;nq.v[0].y=nq.v[1].y=a.y; - nq.v[1].x=nq.v[2].x=b.x;nq.v[2].y=nq.v[3].y=b.y;for(int j=0;j<4;++j) - nq.v[j].col=0xC0000000; - if(showmeasure)sm->smRenderQuad(&nq); - continue; - } - if(api->getChannelMask(pool[i]->ch))continue; - smvec2d a(((double)pool[i]->tce-ctk)*lpt+nh,(froffsets[12]*(pool[i]->key/12)+froffsets[pool[i]->key%12])*wheight/2048.); - smvec2d b(((double)pool[i]->tcs-ctk)*lpt+nh,a.y+notew*0.9); - bool isnoteon=pool[i]->tcs<=ctk&&pool[i]->tce>=ctk;if(isnoteon) - { - uint32_t newkey=pool[i]->key+(int)floor(api->getPitchBend(pool[i]->ch)); - double fpb=api->getPitchBend(pool[i]->ch)-floor(api->getPitchBend(pool[i]->ch)); - a.y=(froffsets[12]*(newkey/12)+froffsets[newkey%12])*wheight/2048.+notew*fpb; - b.y=a.y+notew*0.9; - } - a.y=wheight-a.y;b.y=wheight-b.y; - notestatus[pool[i]->ch][pool[i]->key]|=isnoteon; - if(((double)pool[i]->tce-pool[i]->tcs)*lpt<minnotelength*0.04) + if(((double)pool[i]->tce-pool[i]->tcs)*lpt<minnotelength*0.04) a.x=((double)pool[i]->tcs-ctk)*lpt+nh-minnotelength*0.04; - nq.v[0].x=nq.v[3].x=a.x;nq.v[0].y=nq.v[1].y=a.y; - nq.v[1].x=nq.v[2].x=b.x;nq.v[2].y=nq.v[3].y=b.y;for(int j=0;j<4;++j) - nq.v[j].col=SETA(isnoteon?accolors[pool[i]->ch]:iccolors[pool[i]->ch],int(pool[i]->vel*1.6+(isnoteon?52:32))); - if(usespectrum) - { - if(notestatus[pool[i]->ch][pool[i]->key]&&!lastnotestatus[pool[i]->ch][pool[i]->key]) - spectra[pool[i]->ch][pool[i]->key]=pool[i]->vel*(api->getChannelCC(pool[i]->ch,7)/127.); - }else sm->smRenderQuad(&nq); - } } - while(pool.size()&&elb<pool.size()&&fabs((double)pool[elb]->tce-ctk)*lpt+nh<0)++elb; - q.tex=pianotex; - q.v[0].tx=q.v[3].tx=0;q.v[1].tx=q.v[2].tx=1; - q.v[0].ty=q.v[1].ty=0;q.v[2].ty=q.v[3].ty=172./256.; - q.v[0].x=q.v[1].x=nh;q.v[2].x=q.v[3].x=0; - q.v[0].y=q.v[3].y=wheight;q.v[1].y=q.v[2].y=0; - sm->smRenderQuad(&q); - for(int i=0,j;i<128;++i) + else { - DWORD c=0;for(j=0;j<16;++j)if(notestatus[j][i]){c=SETA(iccolors[j],0xFF);break;} - q.v[0].y=q.v[1].y=(fpoffsets[12]*(i/12)+fpoffsets[i%12])*wheight/2048.; - q.v[2].y=q.v[3].y=q.v[0].y; - q.v[0].x=q.v[3].x=nh;q.v[1].x=q.v[2].x=0; - if(!c)continue;for(int j=0;j<4;++j)q.v[j].col=c; - switch(i%12) - { - case 1:case 3:case 6:case 8:case 10: - q.v[1].x=q.v[2].x=nh-115*wheight/2048.; - q.v[2].y+=15.*wheight/2048;q.v[3].y+=15.*wheight/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-15/256.; - q.v[0].tx=q.v[3].tx=1344/2048.;q.v[1].tx=q.v[2].tx=1459/2048.; - break; - case 0: - q.v[2].y+=27.*wheight/2048;q.v[3].y+=27.*wheight/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-27/256.; - q.v[0].tx=q.v[3].tx=0/2048.;q.v[1].tx=q.v[2].tx=172/2048.; - break; - case 2: - q.v[2].y+=29.*wheight/2048;q.v[3].y+=29.*wheight/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-29/256.; - q.v[0].tx=q.v[3].tx=192/2048.;q.v[1].tx=q.v[2].tx=364/2048.; - break; - case 4: - q.v[2].y+=28.*wheight/2048;q.v[3].y+=28.*wheight/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-28/256.; - q.v[0].tx=q.v[3].tx=384/2048.;q.v[1].tx=q.v[2].tx=556/2048.; - break; - case 5: - q.v[2].y+=28.*wheight/2048;q.v[3].y+=28.*wheight/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-28/256.; - q.v[0].tx=q.v[3].tx=576/2048.;q.v[1].tx=q.v[2].tx=748/2048.; - break; - case 7: - q.v[2].y+=29.*wheight/2048;q.v[3].y+=29.*wheight/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-29/256.; - q.v[0].tx=q.v[3].tx=768/2048.;q.v[1].tx=q.v[2].tx=940/2048.; - break; - case 9: - q.v[2].y+=28.*wheight/2048;q.v[3].y+=28.*wheight/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-28/256.; - q.v[0].tx=q.v[3].tx=960/2048.;q.v[1].tx=q.v[2].tx=1132/2048.; - break; - case 11: - q.v[2].y+=28.*wheight/2048;q.v[3].y+=28.*wheight/2048; - q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-28/256.; - q.v[0].tx=q.v[3].tx=1152/2048.;q.v[1].tx=q.v[2].tx=1324/2048.; - break; - } - for(int j=0;j<4;++j)q.v[j].y=wheight-q.v[j].y; - sm->smRenderQuad(&q); + if(((double)pool[i]->tcs-pool[i]->tce)*lpt<minnotelength*0.04) + a.y=((double)pool[i]->tcs-ctk)*lpt+wheight-nh-minnotelength*0.04; } - if(usespectrum&&playing) - for(int i=0;i<16;++i)for(int j=0;j<128;++j) + nq.v[0].x=nq.v[3].x=a.x;nq.v[0].y=nq.v[1].y=a.y; + nq.v[1].x=nq.v[2].x=b.x;nq.v[2].y=nq.v[3].y=b.y;for(int j=0;j<4;++j) + nq.v[j].col=SETA(isnoteon?accolors[pool[i]->ch]:iccolors[pool[i]->ch],int(pool[i]->vel*1.6+(isnoteon?52:32))); + if(usespectrum) { - if(sustaininst.find(api->getChannelPreset(i))!=sustaininst.end()) + if(notestatus[pool[i]->ch][pool[i]->key]&&!lastnotestatus[pool[i]->ch][pool[i]->key]) + spectra[pool[i]->ch][pool[i]->key]=pool[i]->vel*(api->getChannelCC(pool[i]->ch,7)/127.); + }else sm->smRenderQuad(&nq); + } + } + if(horizontal) + while(pool.size()&&elb<pool.size()&&fabs((double)pool[elb]->tce-ctk)*lpt+nh<0)++elb; + else + while(pool.size()&&elb<pool.size()&&fabs((double)pool[elb]->tce-ctk)*lpt+wheight-nh>wheight)++elb; + smQuad q; + q.tex=pianotex; + q.v[0].ty=q.v[3].ty=0;q.v[1].ty=q.v[2].ty=172./256.; + q.v[0].tx=q.v[1].tx=0;q.v[2].tx=q.v[3].tx=1.; + q.v[0].x=q.v[1].x=0;q.v[2].x=q.v[3].x=wwidth; + q.v[0].y=q.v[3].y=wheight-nh;q.v[1].y=q.v[2].y=wheight; + if(horizontal) + { + q.v[0].tx=q.v[3].tx=0;q.v[1].tx=q.v[2].tx=1; + q.v[0].ty=q.v[1].ty=0;q.v[2].ty=q.v[3].ty=172./256.; + q.v[0].x=q.v[1].x=nh;q.v[2].x=q.v[3].x=0; + q.v[0].y=q.v[3].y=wheight;q.v[1].y=q.v[2].y=0; + } + sm->smRenderQuad(&q); + for(int i=0,j;i<128;++i) + { + DWORD c=0;for(j=0;j<16;++j)if(notestatus[j][i]){c=SETA(iccolors[j],0xFF);break;} + q.v[0].x=q.v[1].x=(fpoffsets[12]*(i/12)+fpoffsets[i%12])*wwidth/2048.; + q.v[2].x=q.v[3].x=q.v[0].x; + q.v[0].y=q.v[3].y=wheight-nh;q.v[1].y=q.v[2].y=wheight; + if(!c)continue;for(int j=0;j<4;++j)q.v[j].col=c; + switch(i%12) + { + case 1:case 3:case 6:case 8:case 10: + if(horizontal) { - if(!notestatus[i][j]&&spectra[i][j]) - spectra[i][j]=.95*spectra[i][j]; - }else if(spectra[i][j])spectra[i][j]=.95*spectra[i][j]; - if(spectrar[i][j]<spectra[i][j]*0.9)spectrar[i][j]+=spectra[i][j]*0.2; - else spectrar[i][j]=spectra[i][j]; - if(spectrar[i][j]) + q.v[1].x=q.v[2].x=nh-115*wheight/2048.; + q.v[2].y+=15.*wheight/2048;q.v[3].y+=15.*wheight/2048; + } + else { - smvec2d a(spectrar[i][j]/128.*(wwidth-nh)*(1+0.02*sin(sm->smGetTime()*32))+nh,(froffsets[12]*(j/12)+froffsets[j%12])*wheight/2048.); - smvec2d b(nh,a.y+notew*0.9); - uint32_t newkey=j+(int)floor(api->getPitchBend(i)); - double fpb=api->getPitchBend(pool[i]->ch)-floor(api->getPitchBend(pool[i]->ch)); - a.y=(froffsets[12]*(newkey/12)+froffsets[newkey%12])*wheight/2048.+notew*fpb; - b.y=a.y+notew*0.9; - a.y=wheight-a.y;b.y=wheight-b.y; - nq.v[0].x=nq.v[3].x=a.x;nq.v[0].y=nq.v[1].y=a.y; - nq.v[1].x=nq.v[2].x=b.x;nq.v[2].y=nq.v[3].y=b.y;for(int j=0;j<4;++j) - nq.v[j].col=SETA(iccolors[i],204); - sm->smRenderQuad(&nq); + q.v[1].y=q.v[2].y=wheight-nh+115*wwidth/2048.; + q.v[2].x+=15.*wwidth/2048;q.v[3].x+=15.*wwidth/2048; } + q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-15/256.; + q.v[0].tx=q.v[3].tx=1344/2048.;q.v[1].tx=q.v[2].tx=1459/2048.; + break; + case 0: + if(horizontal) + {q.v[2].y+=27.*wheight/2048;q.v[3].y+=27.*wheight/2048;} + else + {q.v[2].x+=27.*wwidth/2048;q.v[3].x+=27.*wwidth/2048;} + q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-27/256.; + q.v[0].tx=q.v[3].tx=0/2048.;q.v[1].tx=q.v[2].tx=172/2048.; + break; + case 2: + if(horizontal) + {q.v[2].y+=29.*wheight/2048;q.v[3].y+=29.*wheight/2048;} + else + {q.v[2].x+=29.*wwidth/2048;q.v[3].x+=29.*wwidth/2048;} + q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-29/256.; + q.v[0].tx=q.v[3].tx=192/2048.;q.v[1].tx=q.v[2].tx=364/2048.; + break; + case 4: + if(horizontal) + {q.v[2].y+=28.*wheight/2048;q.v[3].y+=28.*wheight/2048;} + else + {q.v[2].x+=28.*wwidth/2048;q.v[3].x+=28.*wwidth/2048;} + q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-28/256.; + q.v[0].tx=q.v[3].tx=384/2048.;q.v[1].tx=q.v[2].tx=556/2048.; + break; + case 5: + if(horizontal) + {q.v[2].y+=28.*wheight/2048;q.v[3].y+=28.*wheight/2048;} + else + {q.v[2].x+=28.*wwidth/2048;q.v[3].x+=28.*wwidth/2048;} + q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-28/256.; + q.v[0].tx=q.v[3].tx=576/2048.;q.v[1].tx=q.v[2].tx=748/2048.; + break; + case 7: + if(horizontal) + {q.v[2].y+=29.*wheight/2048;q.v[3].y+=29.*wheight/2048;} + else + {q.v[2].x+=29.*wwidth/2048;q.v[3].x+=29.*wwidth/2048;} + q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-29/256.; + q.v[0].tx=q.v[3].tx=768/2048.;q.v[1].tx=q.v[2].tx=940/2048.; + break; + case 9: + if(horizontal) + {q.v[2].y+=28.*wheight/2048;q.v[3].y+=28.*wheight/2048;} + else + {q.v[2].x+=28.*wwidth/2048;q.v[3].x+=28.*wwidth/2048;} + q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-28/256.; + q.v[0].tx=q.v[3].tx=960/2048.;q.v[1].tx=q.v[2].tx=1132/2048.; + break; + case 11: + if(horizontal) + {q.v[2].y+=28.*wheight/2048;q.v[3].y+=28.*wheight/2048;} + else + {q.v[2].x+=28.*wwidth/2048;q.v[3].x+=28.*wwidth/2048;} + q.v[0].ty=q.v[1].ty=1.;q.v[2].ty=q.v[3].ty=1.-28/256.; + q.v[0].tx=q.v[3].tx=1152/2048.;q.v[1].tx=q.v[2].tx=1324/2048.; + break; + } + if(horizontal)for(int j=0;j<4;++j)q.v[j].y=wheight-q.v[j].y; + sm->smRenderQuad(&q); + } + if(usespectrum&&playing) + for(int i=0;i<16;++i)for(int j=0;j<128;++j) + { + if(sustaininst.find(api->getChannelPreset(i))!=sustaininst.end()) + { + if(!notestatus[i][j]&&spectra[i][j]) + spectra[i][j]=.95*spectra[i][j]; + }else if(spectra[i][j])spectra[i][j]=.95*spectra[i][j]; + if(spectrar[i][j]<spectra[i][j]*0.9)spectrar[i][j]+=spectra[i][j]*0.2; + else spectrar[i][j]=spectra[i][j]; + if(spectrar[i][j]) + { + smvec2d a((froffsets[12]*(j/12)+froffsets[j%12])*wwidth/2048.,spectrar[i][j]/-128.*(wheight-nh)*(1+0.02*sin(sm->smGetTime()*32))+wheight-nh); + smvec2d b(a.x+notew*0.9,lpt+wheight-nh); + uint32_t newkey=j+(int)floor(api->getPitchBend(i)); + double fpb=api->getPitchBend(i)-floor(api->getPitchBend(i)); + if(horizontal) + { + a=smvec2d(spectrar[i][j]/128.*(wwidth-nh)*(1+0.02*sin(sm->smGetTime()*32))+nh,(froffsets[12]*(j/12)+froffsets[j%12])*wheight/2048.); + b=smvec2d(nh,a.y+notew*0.9); + a.y=(froffsets[12]*(newkey/12)+froffsets[newkey%12])*wheight/2048.+notew*fpb; + b.y=a.y+notew*0.9; + a.y=wheight-a.y;b.y=wheight-b.y; + } + else + { + a.x=(froffsets[12]*(newkey/12)+froffsets[newkey%12])*wwidth/2048.+notew*fpb; + b.x=a.x+notew*0.9; } + nq.v[0].x=nq.v[3].x=a.x;nq.v[0].y=nq.v[1].y=a.y; + nq.v[1].x=nq.v[2].x=b.x;nq.v[2].y=nq.v[3].y=b.y;for(int j=0;j<4;++j) + nq.v[j].col=SETA(iccolors[i],204); + sm->smRenderQuad(&nq); } - if(playing)ctk+=(int)1e6/((double)api->getRawTempo()/api->getDivision())*sm->smGetDelta(); } + if(playing)ctk+=(int)1e6/((double)api->getRawTempo()/api->getDivision())*sm->smGetDelta(); +} +bool qmpVisualization::update() +{ + smQuad q; + if(sm->smGetKeyState(SMK_RIGHT)==SMKST_HIT) + api->playerSeek(api->getCurrentPlaybackPercentage()+(sm->smGetKeyState(SMK_SHIFT)?5:1)); + if(sm->smGetKeyState(SMK_LEFT)==SMKST_HIT) + api->playerSeek(api->getCurrentPlaybackPercentage()-(sm->smGetKeyState(SMK_SHIFT)?5:1)); + if(!flat) + updateVisualization3D(); + sm->smRenderBegin2D(); + sm->smClrscr(0xFF666666);q.blend=BLEND_ALPHABLEND; + for(int i=0;i<4;++i){q.v[i].col=0xFFFFFFFF;q.v[i].z=0;} + if(bgtex) + { + q.tex=bgtex; + q.v[0].x=q.v[3].x=0;q.v[1].x=q.v[2].x=wwidth; + q.v[0].y=q.v[1].y=0;q.v[2].y=q.v[3].y=wheight; + q.v[0].tx=q.v[3].tx=0;q.v[1].tx=q.v[2].tx=1; + q.v[0].ty=q.v[1].ty=0;q.v[2].ty=q.v[3].ty=1; + sm->smRenderQuad(&q); + } + if(flat) + updateVisualization2D(); else { q.tex=sm->smTargetTexture(tdscn); diff --git a/visualization/qmpvisualization.hpp b/visualization/qmpvisualization.hpp index fea96f4..6a66785 100644 --- a/visualization/qmpvisualization.hpp +++ b/visualization/qmpvisualization.hpp @@ -78,6 +78,8 @@ class qmpVisualization:public qmpPluginIntf void showThread(); void pushNoteOn(uint32_t tc,uint32_t ch,uint32_t key,uint32_t vel); void pushNoteOff(uint32_t tc,uint32_t ch,uint32_t key); + void updateVisualization3D(); + void updateVisualization2D(); public: qmpVisualization(qmpPluginAPI* _api); ~qmpVisualization(); |