VuPartMeter.h (1839B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 VuPartMeter.h - OSC Controlled VU Meter 5 Copyright (C) 2016 Mark McCurry 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License 9 as published by the Free Software Foundation; either version 2 10 of the License, or (at your option) any later version. 11 */ 12 #include "VuMeter.h" 13 #define MIN_DB (-48) 14 15 class VuPartMeter: public VuMeter 16 { 17 public: 18 VuPartMeter(int x,int y, int w, int h, const char *label=0) 19 :VuMeter(x,y,w,h,label), db(0.0f) 20 {} 21 22 void draw(void) 23 { 24 const int X = x(), Y = y(), W = w(), H = h(); 25 26 //XXX perhaps re-enable this later on 27 //if (!active_r()){ 28 // int fakedb=master->fakepeakpart[npart]; 29 // fl_rectf(X,Y,W,H,140,140,140); 30 // if (fakedb>0){ 31 // fakedb=(int)(fakedb/255.0*H)+4; 32 // fl_rectf(X+2,Y+H-fakedb,W-4,fakedb,0,0,0); 33 // } 34 // return; 35 //} 36 37 //draw the vu lines 38 const int idb = db*(H-2); 39 40 fl_rectf(X,Y+H-idb,W,idb,0,200,255); 41 fl_rectf(X,Y,W,H-idb,0,0,0); 42 43 //draw the scales 44 const float tmp=H*1.0/MIN_DB; 45 for (int i = 1; i < 1 - MIN_DB; i++) { 46 const int ty = H+(int) (tmp*i); 47 if(i%5 == 0) fl_rectf(X, Y+H-ty, W, 1,0, 160, 200); 48 if(i%10 == 0) fl_rectf(X, Y+H-ty, W, 1,0, 230, 240); 49 } 50 } 51 52 void update(float x) 53 { 54 const float _db = limit((MIN_DB-rap2dB(x))/MIN_DB); 55 56 if(db != _db) { 57 db = _db; 58 damage(FL_DAMAGE_USER1); 59 } 60 } 61 62 private: 63 float db; 64 };