Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scalable envelope graph #7194

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions include/ColorHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* ColorHelper.h - Helper methods for color related algorithms, etc.
*
* Copyright (c) 2024- Michael Gregorius
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#ifndef LMMS_GUI_COLOR_HELPER_H
#define LMMS_GUI_COLOR_HELPER_H

#include <QColor>

namespace lmms::gui
{

class ColorHelper
{
public:
static QColor interpolateInRgb(const QColor& a, const QColor& b, float t)
{
qreal ar, ag, ab, aa;
a.getRgbF(&ar, &ag, &ab, &aa);

qreal br, bg, bb, ba;
b.getRgbF(&br, &bg, &bb, &ba);

const float interH = lerp(ar, br, t);
const float interS = lerp(ag, bg, t);
const float interV = lerp(ab, bb, t);
const float interA = lerp(aa, ba, t);

return QColor::fromRgbF(interH, interS, interV, interA);
}
};

} // namespace lmms::gui

#endif // LMMS_GUI_COLOR_HELPER_H
17 changes: 14 additions & 3 deletions include/EnvelopeGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,33 @@ namespace gui

class EnvelopeGraph : public QWidget, public ModelView
{
public:
enum class ScalingMode
{
Dynamic,
Absolute,
Relative
};

public:
EnvelopeGraph(QWidget* parent);

protected:
void modelChanged() override;

void mousePressEvent(QMouseEvent* me) override;
void paintEvent(QPaintEvent* pe) override;
void mousePressEvent(QMouseEvent*) override;
void contextMenuEvent(QContextMenuEvent*) override;
void paintEvent(QPaintEvent*) override;

private:
void toggleAmountModel();

private:
QPixmap m_envGraph = embed::getIconPixmap("envelope_graph");

EnvelopeAndLfoParameters* m_params;
EnvelopeAndLfoParameters* m_params = nullptr;

ScalingMode m_scaling = ScalingMode::Dynamic;
};

} // namespace gui
Expand Down
7 changes: 7 additions & 0 deletions include/lmms_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ static inline T absMin( T a, T b )
return std::abs(a) < std::abs(b) ? a : b;
}

//! Returns the linear interpolation of the two values
template<class T, class F>
constexpr T lerp(T a, T b, F t)
{
return (1. - t) * a + t * b;
}

// @brief Calculate number of digits which LcdSpinBox would show for a given number
// @note Once we upgrade to C++20, we could probably use std::formatted_size
static inline int numDigitsAsInt(float f)
Expand Down
Loading
Loading