A bit of a string performance trick.

This commit is contained in:
Valentin Boettcher 2018-03-27 18:05:18 +02:00
parent 8cf5e19848
commit 402935bcac
2 changed files with 17 additions and 11 deletions

View file

@ -211,14 +211,12 @@ void ClipSelector::draw()
// clip bars // clip bars
if(!_master) { if(!_master) {
int bars = clips[i].getBeats() / 4; const char * bars = clips[i].getBarsString();
int barsToRecord = clips[i].getBarsToRecord(); if(bars) {
bars = (bars == 0) ? barsToRecord : bars;
if(bars > 0) {
cairo_move_to( cr, x + clipHeight + 5, drawY + textHeight + 8); cairo_move_to( cr, x + clipHeight + 5, drawY + textHeight + 8);
cairo_set_source_rgba( cr, 255 / 255.f, 255 / 255.f , 255 / 255.f , 0.9 ); cairo_set_source_rgba( cr, 255 / 255.f, 255 / 255.f , 255 / 255.f , 0.9 );
cairo_set_font_size( cr, 8 ); cairo_set_font_size( cr, 8 );
cairo_show_text( cr, std::to_string(bars).c_str()); cairo_show_text( cr, bars);
} }
} }

View file

@ -71,23 +71,31 @@ public:
// we wrap it here, so there may be no // we wrap it here, so there may be no
// fuzz with the looperclip // fuzz with the looperclip
int getBeats(){ const char * getBarsString(){
if(!lclip) if(!lclip)
return 0; return 0;
return lclip->getBeats(); int beats = lclip->getBeats();
} int barsToRecord = lclip->getBarsToRecord();
int bars = (beats == 0) ? barsToRecord : beats / 4;
int getBarsToRecord(){ if (bars <= 0)
if(!lclip)
return 0; return 0;
return lclip->getBarsToRecord();
if(bars != lastBars)
barsText = std::to_string(bars);
return barsText.c_str();
} }
private: private:
GridLogic::State state; GridLogic::State state;
std::string name; std::string name;
LooperClip* lclip; LooperClip* lclip;
std::string barsText;
// tmp
int lastBars;
}; };
class ClipSelector : public Fl_Button class ClipSelector : public Fl_Button