Skip to content

Commit

Permalink
Use layouts for the instrument sound shaping tab / Extract classes fo…
Browse files Browse the repository at this point in the history
…r Envelope and LFO graphs (LMMS#7193)

Move the envelope and LFO graphs into their own classes.

Besides the improved code organization this step had to be done to be able to use layouts in `EnvelopeAndLfoView`. The class previously had fixed layouts mixed with custom rendering in the paint event. Mouse events are now also handled in both new classes instead of in `EnvelopeAndLfoView`.

## Layouts in EnvelopeAndLfoView
Use layouts to align the elements of the `EnvelopeAndLfoView`. This removes lots of hard-coded values. Add helper lambdas for the repeated creation of `Knob` and `PixmapButton` instances.

The spacing that is explicitly introduced between the envelope and LFO should be removed once there is a more open layout.

## Layouts for InstrumentSoundShapingView
Use layouts to align the elements of the `InstrumentSoundShapingView`.

## Info text improvements in LFO graph
Draw the info text at around 20% of the LFO graph's height. This prepares the dialog to be scaled later.

Write "1000 ms/LFO" instead of "ms/LFO: 1000" with a larger gap.

## Accessors for EnvelopeAndLfoParameters
Make the enum `LfoShape` in `EnvelopeAndLfoParameters` public so that it can be used without friend declarations. Add accessor methods for the model of the LFO.

## Other improvements
* Adjust include orders
* Variable initialization in headers
* Prevention of most vexing parses
  • Loading branch information
michaelgregorius authored and enp2s0 committed Apr 12, 2024
1 parent 750880f commit b8c2653
Show file tree
Hide file tree
Showing 10 changed files with 646 additions and 412 deletions.
45 changes: 34 additions & 11 deletions include/EnvelopeAndLfoParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,18 @@ class LMMS_EXPORT EnvelopeAndLfoParameters : public Model, public JournallingObj
using LfoList = QList<EnvelopeAndLfoParameters*>;
LfoList m_lfos;

} ;
};

enum class LfoShape
{
SineWave,
TriangleWave,
SawWave,
SquareWave,
UserDefinedWave,
RandomWave,
Count
};

EnvelopeAndLfoParameters( float _value_for_zero_amount,
Model * _parent );
Expand Down Expand Up @@ -114,6 +125,28 @@ class LMMS_EXPORT EnvelopeAndLfoParameters : public Model, public JournallingObj
return m_rFrames;
}

// Envelope
const FloatModel& getPredelayModel() const { return m_predelayModel; }
const FloatModel& getAttackModel() const { return m_attackModel; }
const FloatModel& getHoldModel() const { return m_holdModel; }
const FloatModel& getDecayModel() const { return m_decayModel; }
const FloatModel& getSustainModel() const { return m_sustainModel; }
const FloatModel& getReleaseModel() const { return m_releaseModel; }
const FloatModel& getAmountModel() const { return m_amountModel; }
FloatModel& getAmountModel() { return m_amountModel; }


// LFO
inline f_cnt_t getLfoPredelayFrames() const { return m_lfoPredelayFrames; }
inline f_cnt_t getLfoAttackFrames() const { return m_lfoAttackFrames; }
inline f_cnt_t getLfoOscillationFrames() const { return m_lfoOscillationFrames; }

const FloatModel& getLfoAmountModel() const { return m_lfoAmountModel; }
FloatModel& getLfoAmountModel() { return m_lfoAmountModel; }
const TempoSyncKnobModel& getLfoSpeedModel() const { return m_lfoSpeedModel; }
const BoolModel& getX100Model() const { return m_x100Model; }
const IntModel& getLfoWaveModel() const { return m_lfoWaveModel; }
std::shared_ptr<const SampleBuffer> getLfoUserWave() const { return m_userWave; }

public slots:
void updateSampleVars();
Expand Down Expand Up @@ -170,16 +203,6 @@ public slots:
bool m_bad_lfoShapeData;
std::shared_ptr<const SampleBuffer> m_userWave = SampleBuffer::emptyBuffer();

enum class LfoShape
{
SineWave,
TriangleWave,
SawWave,
SquareWave,
UserDefinedWave,
RandomWave,
Count
} ;
constexpr static auto NumLfoShapes = static_cast<std::size_t>(LfoShape::Count);

sample_t lfoShapeSample( fpp_t _frame_offset );
Expand Down
16 changes: 4 additions & 12 deletions include/EnvelopeAndLfoView.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
#include <QWidget>

#include "ModelView.h"
#include "embed.h"

class QPaintEvent;
class QPixmap;

namespace lmms
{
Expand All @@ -47,6 +43,8 @@ class Knob;
class LedCheckBox;
class PixmapButton;
class TempoSyncKnob;
class EnvelopeGraph;
class LfoGraph;



Expand All @@ -63,22 +61,17 @@ class EnvelopeAndLfoView : public QWidget, public ModelView

void dragEnterEvent( QDragEnterEvent * _dee ) override;
void dropEvent( QDropEvent * _de ) override;
void mousePressEvent( QMouseEvent * _me ) override;
void paintEvent( QPaintEvent * _pe ) override;


protected slots:
void lfoUserWaveChanged();


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

EnvelopeAndLfoParameters * m_params;


// envelope stuff
EnvelopeGraph* m_envelopeGraph;
Knob * m_predelayKnob;
Knob * m_attackKnob;
Knob * m_holdKnob;
Expand All @@ -88,6 +81,7 @@ protected slots:
Knob * m_amountKnob;

// LFO stuff
LfoGraph* m_lfoGraph;
Knob * m_lfoPredelayKnob;
Knob * m_lfoAttackKnob;
TempoSyncKnob * m_lfoSpeedKnob;
Expand All @@ -97,8 +91,6 @@ protected slots:

LedCheckBox * m_x100Cb;
LedCheckBox * m_controlEnvAmountCb;

float m_randomGraph;
} ;

} // namespace gui
Expand Down
66 changes: 66 additions & 0 deletions include/EnvelopeGraph.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* EnvelopeGraph.h - Displays envelope graphs
*
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* 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_ENVELOPE_GRAPH_H
#define LMMS_GUI_ENVELOPE_GRAPH_H

#include <QWidget>

#include "ModelView.h"
#include "embed.h"

namespace lmms
{

class EnvelopeAndLfoParameters;

namespace gui
{

class EnvelopeGraph : public QWidget, public ModelView
{
public:
EnvelopeGraph(QWidget* parent);

protected:
void modelChanged() override;

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

private:
void toggleAmountModel();

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

EnvelopeAndLfoParameters* m_params;
};

} // namespace gui

} // namespace lmms

#endif // LMMS_GUI_ENVELOPE_GRAPH_H
2 changes: 1 addition & 1 deletion include/InstrumentSoundShapingView.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class InstrumentSoundShapingView : public QWidget, public ModelView
void modelChanged() override;


InstrumentSoundShaping * m_ss;
InstrumentSoundShaping * m_ss = nullptr;
TabWidget * m_targetsTabWidget;
EnvelopeAndLfoView * m_envLfoViews[InstrumentSoundShaping::NumTargets];

Expand Down
68 changes: 68 additions & 0 deletions include/LfoGraph.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* LfoGraph.h - Displays LFO graphs
*
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* 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_LFO_GRAPH_H
#define LMMS_GUI_LFO_GRAPH_H

#include <QWidget>

#include "ModelView.h"
#include "embed.h"

namespace lmms
{

class EnvelopeAndLfoParameters;

namespace gui
{

class LfoGraph : public QWidget, public ModelView
{
public:
LfoGraph(QWidget* parent);

protected:
void modelChanged() override;

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

private:
void toggleAmountModel();

private:
QPixmap m_lfoGraph = embed::getIconPixmap("lfo_graph");

EnvelopeAndLfoParameters* m_params = nullptr;

float m_randomGraph {0.};
};

} // namespace gui

} // namespace lmms

#endif // LMMS_GUI_LFO_GRAPH_H
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ SET(LMMS_SRCS
gui/editors/TrackContainerView.cpp

gui/instrument/EnvelopeAndLfoView.cpp
gui/instrument/EnvelopeGraph.cpp
gui/instrument/InstrumentFunctionViews.cpp
gui/instrument/InstrumentMidiIOView.cpp
gui/instrument/InstrumentTuningView.cpp
gui/instrument/InstrumentSoundShapingView.cpp
gui/instrument/InstrumentTrackWindow.cpp
gui/instrument/InstrumentView.cpp
gui/instrument/LfoGraph.cpp
gui/instrument/PianoView.cpp

gui/menus/MidiPortMenu.cpp
Expand Down
Loading

0 comments on commit b8c2653

Please sign in to comment.