From f062189c8219041fad45cfd340c367e5c4796933 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 19 Mar 2017 09:13:46 +0100 Subject: Shrink status bar text and fix initial DSP load display --- src/server/Load.hpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/server/Load.hpp (limited to 'src/server/Load.hpp') diff --git a/src/server/Load.hpp b/src/server/Load.hpp new file mode 100644 index 00000000..ed9ee406 --- /dev/null +++ b/src/server/Load.hpp @@ -0,0 +1,57 @@ +/* + This file is part of Ingen. + Copyright 2007-2017 David Robillard + + Ingen is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or any later version. + + Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for details. + + You should have received a copy of the GNU Affero General Public License + along with Ingen. If not, see . +*/ + +#ifndef INGEN_ENGINE_LOAD_HPP +#define INGEN_ENGINE_LOAD_HPP + +namespace Ingen { +namespace Server { + +struct Load +{ + void update(uint64_t time, uint64_t available) { + const uint64_t load = time * 100 / available; + if (load < min) { + min = load; + changed = true; + } + if (load > max) { + max = load; + changed = true; + } + if (++n == 1) { + mean = load; + changed = true; + } else { + const float a = mean + ((float)load - mean) / (float)++n; + if (a != mean) { + changed = floorf(a) != floorf(mean); + mean = a; + } + } + } + + uint64_t min = std::numeric_limits::max(); + uint64_t max = 0; + float mean = 0.0f; + uint64_t n = 0; + bool changed = false; +}; + +} // namespace Server +} // namespace Ingen + +#endif // INGEN_ENGINE_LOAD_HPP -- cgit v1.2.1