From 59b0a4f74fd358d44c65137e41594fc7dc8a106e Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Fri, 14 Feb 2020 00:30:42 +0800 Subject: New scheme for visualizing note velocity. Updated default color scheme for better results. New class smColor, which is going to replace smColorHSVA & smColorRGBA in the future. --- visualization/extrasmeltutils.cpp | 171 +++++++++++++++++++++++++++++++++++++ visualization/extrasmeltutils.hpp | 38 +++++++++ visualization/qmpvisualization.cpp | 17 ++-- 3 files changed, 219 insertions(+), 7 deletions(-) diff --git a/visualization/extrasmeltutils.cpp b/visualization/extrasmeltutils.cpp index c8b3446..2d0a807 100644 --- a/visualization/extrasmeltutils.cpp +++ b/visualization/extrasmeltutils.cpp @@ -196,3 +196,174 @@ void smParticleSystem::updatePS() } void smParticleSystem::renderPS() {for(unsigned i=0;irender();} + +smColor::smColor() +{r=g=b=h=s=v=a=0;} + +void smColor::update_rgb() +{ + auto f=[this](float n){ + float k=fmodf(n+6.0f*this->h,6.0f); + return this->v-this->v*this->s*max(0.0f,min(1.0f,min(k,4.0f-k))); + }; + r=f(5); + g=f(3); + b=f(1); +} +void smColor::update_hsv() +{ + v=max(r,max(g,b)); + float vm=min(r,min(g,b)); + float chroma=v-vm; + if(v-vmEPSF) + { + r=red; + update_hsv(); + } +} +void smColor::setGreen(float green) +{ + if(fabsf(g-green)>EPSF) + { + g=green; + update_hsv(); + } +} +void smColor::setBlue(float blue) +{ + if(fabsf(b-blue)>EPSF) + { + b=blue; + update_hsv(); + } +} +void smColor::setHue(float hue) +{ + if(fabsf(h-hue)>EPSF) + { + h=hue; + update_rgb(); + } +} +void smColor::setSaturation(float saturation) +{ + if(fabsf(s-saturation)>EPSF) + { + s=saturation; + update_rgb(); + } +} +void smColor::setHSLSaturation(float saturation) +{ + float ss=hslSaturation(); + float l=lightness(); + if(fabsf(ss-saturation)>EPSF) + { + ss=saturation; + v=l+ss*min(l,1-l); + if(vEPSF) + { + v=value; + update_rgb(); + } +} +void smColor::setLightness(float lightness) +{ + float ss=hslSaturation(); + float l=this->lightness(); + if(fabsf(l-lightness)>EPSF) + { + l=lightness; + v=l+ss*min(l,1-l); + if(v @@ -5,6 +10,7 @@ #include #include #include +#define EPSF 1e-6f class smEntity3D { friend class smEntity3DBuffer; @@ -34,6 +40,38 @@ class smEntity3DBuffer void drawBatch(); }; +class smColor +{ + private: + float r,g,b,h,s,v,a; + void update_rgb(); + void update_hsv(); + public: + smColor(); + void clamp(bool hsv); + float alpha()const; + float red()const; + float green()const; + float blue()const; + float hue()const; + float saturation()const; + float hslSaturation()const; + float value()const; + float lightness()const; + void setAlpha(float alpha); + void setRed(float red); + void setGreen(float green); + void setBlue(float blue); + void setHue(float hue); + void setSaturation(float saturation); + void setHSLSaturation(float saturation); + void setValue(float value); + void setLightness(float lightness); + smColor lighter(int factor); + smColor darker(int factor); + uint32_t toHWColor(); + static smColor fromHWColor(uint32_t color); +}; class smPSEmissionPositionGenerator { public: diff --git a/visualization/qmpvisualization.cpp b/visualization/qmpvisualization.cpp index e725263..5ada18f 100644 --- a/visualization/qmpvisualization.cpp +++ b/visualization/qmpvisualization.cpp @@ -18,13 +18,13 @@ const wchar_t* minors=L"abebbbf c g d a e b f#c#g#d#a#"; const wchar_t* majors=L"CbGbDbAbEbBbF C G D A E B F#C#"; double fpoffsets[]={1,18,28,50,55,82,98,109,130,137,161,164,191}; double froffsets[]={0,18,33,50,65,82,98,113,130,145,161,176,191}; -DWORD iccolors[]={0XFFFF0000,0XFFFF8000,0XFFFFBF00,0XFFFFFF00, - 0XFFBFFF00,0XFF80FF00,0XFF00FF00,0XFF00FFBF, - 0XFF00FFFF,0XFF333333,0XFF00BFFF,0XFF007FFF, +DWORD iccolors[]={0XFFFF0000,0XFFFF8000,0XFFFFBF00,0XFFF0F000, + 0XFFB2EE00,0XFF80FF00,0XFF00FF00,0XFF00EEB2, + 0XFF00EEEE,0XFF333333,0XFF00BFFF,0XFF007FFF, 0XFF0000FF,0XFF7F00FF,0XFFBF00FF,0XFFFF00BF}; -DWORD accolors[]={0XFFFF9999,0XFFFFCC99,0XFFFFEE99,0XFFFFFF99, - 0XFFEEFF99,0XFFCCFF99,0XFF99FF99,0XFF99FFCC, - 0XFF99FFFF,0XFF999999,0XFF99EEFF,0XFF99CCFF, +DWORD accolors[]={0XFFFF9999,0XFFFFCC99,0XFFFFF4D4,0XFFFFFFDD, + 0XFFF0FFC2,0XFFDDFFBB,0XFFBBFFBB,0XFFAAFFEA, + 0XFFBBFFFF,0XFF999999,0XFF99EEFF,0XFF99CCFF, 0XFF9999FF,0XFFCC99FF,0XFFEE99FF,0XFFFF99EE}; std::set sustaininst={16,17,18,19,20,21,22,23, @@ -329,7 +329,10 @@ void qmpVisualization::updateVisualization3D() 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); + { + smColor col=smColor::fromHWColor(isnoteon?accolors[pool[i]->ch]:iccolors[pool[i]->ch]); + drawCube(a,b,col.lighter(37+pool[i]->vel/2).toHWColor(),0); + } } } if(usespectrum&&playing) -- cgit v1.2.3