From 4191e78012ad4cd5fc216aa355ee97a682065ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Fri, 17 Apr 2020 23:32:32 +0200 Subject: Initial design of the Powermap class. --- src/powermap.cc | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/powermap.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 src/powermap.cc create mode 100644 src/powermap.h diff --git a/src/powermap.cc b/src/powermap.cc new file mode 100644 index 0000000..6a5bba0 --- /dev/null +++ b/src/powermap.cc @@ -0,0 +1,66 @@ +/* -*- Mode: c++ -*- */ +/*************************************************************************** + * powermap.cc + * + * Fri Apr 17 23:06:12 CEST 2020 + * Copyright 2020 André Nusser + * andre.nusser@googlemail.com + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "powermap.h" + +#include + +Power Powermap::map(Power in) const +{ + if (in < fixed_map.in) { + return a1*pow(in,3) + b1*pow(in,2) + c1*in + d1; + } + else { + return a2*pow(in,3) + b2*pow(in,2) + c2*in + d2; + } +} + +void Powermap::reset() +{ + min_input = 0.; + max_input = 1.; + fixed_map = {.5, .5}; +} + +void Powermap::setMinInput(Power min_input) +{ + this->min_input = min_input; +} + +void Powermap::setMaxInput(Power max_input) +{ + this->max_input = max_input; +} + +void Powermap::setFixed(PowerPair fixed) +{ + this->fixed = fixed; +} + +void Powermap::updateSpline() +{ + // TODO +} diff --git a/src/powermap.h b/src/powermap.h new file mode 100644 index 0000000..8dcccc9 --- /dev/null +++ b/src/powermap.h @@ -0,0 +1,59 @@ +/* -*- Mode: c++ -*- */ +/*************************************************************************** + * powermap.h + * + * Fri Apr 17 23:06:12 CEST 2020 + * Copyright 2020 André Nusser + * andre.nusser@googlemail.com + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#pragma once + +class Powermap +{ + using Power = float; + struct PowerPair { + Power in; + Power out; + }; + +public: + Powermap() = default; + + Power map(Power in) const; + void reset(); + + // set parameters + void setMinInput(Power min_input); + void setMaxInput(Power max_input); + void setFixed(PowerPair fixed); + +private: + // input parameters + Power min_input; + Power max_input; + PowerPair fixed; + + // spline parameters + float a1, b1, c1, d1; + float a2, b2, c2, d2; + + void updateSpline(); +}; -- cgit v1.2.3