From 402935bcac077241b32bf45119257c6adf4c8348 Mon Sep 17 00:00:00 2001 From: Valentin Boettcher Date: Tue, 27 Mar 2018 18:05:18 +0200 Subject: [PATCH] A bit of a string performance trick. --- src/avtk/clipselector.cxx | 8 +++----- src/avtk/clipselector.hxx | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/avtk/clipselector.cxx b/src/avtk/clipselector.cxx index b56e55b..90b8b68 100644 --- a/src/avtk/clipselector.cxx +++ b/src/avtk/clipselector.cxx @@ -211,14 +211,12 @@ void ClipSelector::draw() // clip bars if(!_master) { - int bars = clips[i].getBeats() / 4; - int barsToRecord = clips[i].getBarsToRecord(); - bars = (bars == 0) ? barsToRecord : bars; - if(bars > 0) { + const char * bars = clips[i].getBarsString(); + if(bars) { 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_font_size( cr, 8 ); - cairo_show_text( cr, std::to_string(bars).c_str()); + cairo_show_text( cr, bars); } } diff --git a/src/avtk/clipselector.hxx b/src/avtk/clipselector.hxx index 5c7caa2..c89ace7 100644 --- a/src/avtk/clipselector.hxx +++ b/src/avtk/clipselector.hxx @@ -71,23 +71,31 @@ public: // we wrap it here, so there may be no // fuzz with the looperclip - int getBeats(){ + const char * getBarsString(){ if(!lclip) return 0; - return lclip->getBeats(); - } + int beats = lclip->getBeats(); + int barsToRecord = lclip->getBarsToRecord(); + int bars = (beats == 0) ? barsToRecord : beats / 4; - int getBarsToRecord(){ - if(!lclip) + if (bars <= 0) return 0; - return lclip->getBarsToRecord(); + + if(bars != lastBars) + barsText = std::to_string(bars); + + return barsText.c_str(); } private: GridLogic::State state; std::string name; LooperClip* lclip; + std::string barsText; + + // tmp + int lastBars; }; class ClipSelector : public Fl_Button