From c9349b4dcca2cdddf888cb165a13d2f9ec76ce48 Mon Sep 17 00:00:00 2001 From: Valentin Boettcher Date: Thu, 5 Apr 2018 19:37:26 +0200 Subject: [PATCH] Some tweaks. --- src/avtk/clipselector.cxx | 38 ++++++++++++++++++++++++++------------ src/avtk/clipselector.hxx | 4 ++-- src/config.hxx | 1 + 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/avtk/clipselector.cxx b/src/avtk/clipselector.cxx index 07a3e5d..9b32687 100644 --- a/src/avtk/clipselector.cxx +++ b/src/avtk/clipselector.cxx @@ -18,7 +18,6 @@ #include "clipselector.hxx" -#include #include #pragma GCC diagnostic ignored "-Wmissing-field-initializers" @@ -219,8 +218,9 @@ void ClipSelector::draw() bool toRecord = clips[i].getBeatsToRecord() == -1; if(strlen(bars)) { - cairo_move_to( cr, x + clipWidth - 5 - getCairoTextWith(cr, bars), drawY + textHeight - 8); cairo_set_source_rgba( cr, 255 / 255.f, (toRecord) ? 255 / 255.f : 0 , 255 / 255.f , 0.9 ); + + cairo_move_to( cr, x + clipWidth - 5 - getCairoTextWith(cr, bars), drawY + textHeight - 8); cairo_set_font_size( cr, 11 ); cairo_show_text( cr, bars); @@ -239,6 +239,10 @@ void ClipSelector::draw() // trim the names while(getCairoTextWith(cr, tmp.c_str()) > clipWidth - (clipHeight + 15 + beatLen)){ + if(tmp.length() < 4){ + tmp = ""; + break; + } tmp = tmp.substr(0, tmp.length() - 4); tmp += "…"; } @@ -274,13 +278,18 @@ void ClipSelector::resize(int X, int Y, int W, int H) void setRecordBarsCb(Fl_Widget *w, void* data) { + if(!w || !data) + return; + ClipSelector *track = (ClipSelector*)w; long bars = (long)data; - if(bars == -2){ + if(bars == -2){ const char* answer = fl_input("Enter a custom number: "); - if(!answer) - bars = -1; - else + bars = atoi(answer); + if(!answer || bars <= 0|| bars > MAX_BARS) { + bars = -1; + fl_message("Invalid Input. You may enter a number smaller than %i!", MAX_BARS); + } else bars = atoi(answer); } @@ -351,14 +360,15 @@ int ClipSelector::handle(int event) RECORD_LENGTH_MENU_ITEM(32), RECORD_LENGTH_MENU_ITEM(64), {0}, - { "Bars to record", 0, 0, 0, FL_SUBMENU | FL_MENU_DIVIDER }, + { "Bars to record", 0, 0, 0, FL_SUBMENU | FL_MENU_DIVIDER}, RECORD_BARS_MENU_ITEM(1), RECORD_BARS_MENU_ITEM(2), RECORD_BARS_MENU_ITEM(4), RECORD_BARS_MENU_ITEM(6), RECORD_BARS_MENU_ITEM(8), - {"Endless", 0, setRecordBarsCb, (void*)-1, FL_MENU_DIVIDER | (clips[clipNum].getBeatsToRecord() < 0) ? FL_ACTIVATE : 0 }, - {"Custom", 0, setRecordBarsCb, (void*)-2}, + {"Endless", 0, setRecordBarsCb, (void*)-1, FL_MENU_DIVIDER | (clips[clipNum].getBeatsToRecord() <= 0) ? FL_ACTIVATE : 0 + | empty ? 0 : FL_MENU_INACTIVE}, + {"Custom", 0, setRecordBarsCb, (void*)-2, empty ? 0 : FL_MENU_INACTIVE}, {0}, //{ "Record" }, { "Use as tempo" }, @@ -454,9 +464,13 @@ void ClipState::setBeats(int numBeats, bool isBeatsToRecord) if(numBeats > 0) { beatsText = std::to_string(numBeats); barsText = std::to_string(numBeats/4); - beats = numBeats; - - beatsToRecord = (isBeatsToRecord) ? numBeats : -1; + if(isBeatsToRecord){ + beatsToRecord = numBeats; + } else { + beats = numBeats; + if(numBeats <= 0) + beatsToRecord = -1; + } } else barsText = beatsText = std::string(""); diff --git a/src/avtk/clipselector.hxx b/src/avtk/clipselector.hxx index c4228e0..34754c8 100644 --- a/src/avtk/clipselector.hxx +++ b/src/avtk/clipselector.hxx @@ -85,8 +85,8 @@ private: std::string beatsText; std::string barsText; - int beatsToRecord; - int beats; + int beatsToRecord = -1; + int beats = 0; }; class ClipSelector : public Fl_Button diff --git a/src/config.hxx b/src/config.hxx index b238204..30bb35d 100644 --- a/src/config.hxx +++ b/src/config.hxx @@ -65,6 +65,7 @@ #define LUPPP_RETURN_WARNING 1 #define LUPPP_RETURN_ERROR 2 +#define MAX_BARS 100 /// debug.hxx for printing convienience #include "debug.hxx"