Skip to content

Commit d8f5d92

Browse files
committed
Allow choice of push or pull mode for floating text updates
1 parent 308061b commit d8f5d92

File tree

13 files changed

+167
-141
lines changed

13 files changed

+167
-141
lines changed

include/CustomTextKnob.h

Lines changed: 0 additions & 58 deletions
This file was deleted.

include/FloatModelEditorBase.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,38 @@ class LMMS_EXPORT FloatModelEditorBase : public QWidget, public FloatModelView
7272
m_volumeKnob = val;
7373
}
7474

75+
//! In this mode, floating text is obtained by calling `pullFloatingText`.
76+
void setFloatingTextPullMode()
77+
{
78+
m_floatingTextPushMode = false;
79+
m_floatingTextRefreshRate = 0;
80+
}
81+
82+
/**
83+
* In this mode, floating text must be set manually by calling `pushFloatingText`.
84+
*
85+
* @param refreshRate How many times per second `floatingTextUpdateRequested` will be emitted
86+
*/
87+
void setFloatingTextPushMode(std::uint8_t refreshRate = 0)
88+
{
89+
m_floatingTextPushMode = true;
90+
m_floatingTextRefreshRate = refreshRate;
91+
}
92+
93+
//! Manually updates the text float's text
94+
void pushFloatingText(const QString& text);
95+
7596
signals:
7697
void sliderPressed();
7798
void sliderReleased();
7899
void sliderMoved(float value);
79100

101+
/**
102+
* May be emitted periodically when the text float is visible.
103+
* Upon receiving this signal, call `pushFloatingText()` to update the
104+
* text float's text.
105+
*/
106+
void floatingTextUpdateRequested();
80107

81108
protected:
82109
void contextMenuEvent(QContextMenuEvent * me) override;
@@ -98,7 +125,11 @@ class LMMS_EXPORT FloatModelEditorBase : public QWidget, public FloatModelView
98125
void leaveEvent(QEvent *event) override;
99126

100127
virtual float getValue(const QPoint & p);
101-
virtual QString displayValue() const;
128+
129+
//! Retreives floating text in a "pull" fashion
130+
virtual QString pullFloatingText() const;
131+
132+
void updateFloatingText();
102133

103134
void doConnections() override;
104135

@@ -121,6 +152,9 @@ class LMMS_EXPORT FloatModelEditorBase : public QWidget, public FloatModelView
121152

122153
DirectionOfManipulation m_directionOfManipulation;
123154

155+
bool m_floatingTextPushMode = false;
156+
std::uint8_t m_floatingTextRefreshRate = 0; //! times per second
157+
124158
private slots:
125159
virtual void enterValue();
126160
void friendlyUpdate();

include/SimpleTextFloat.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
#ifndef LMMS_GUI_SIMPLE_TEXT_FLOAT_H
2727
#define LMMS_GUI_SIMPLE_TEXT_FLOAT_H
2828

29+
#include <QTimer>
2930
#include <QWidget>
3031

3132
#include "lmms_export.h"
3233

3334
class QLabel;
34-
class QTimer;
3535

3636
namespace lmms::gui
3737
{
@@ -57,12 +57,28 @@ class LMMS_EXPORT SimpleTextFloat : public QWidget
5757
move(w->mapToGlobal(QPoint(0, 0)) + offset);
5858
}
5959

60+
void show();
6061
void hide();
6162

63+
void setRefreshRate(int timesPerSecond);
64+
65+
template<class T>
66+
void setRefreshConnection(T* receiver, void(T::* slot)(), Qt::ConnectionType type = Qt::AutoConnection)
67+
{
68+
if (auto connection = m_refreshTimer->callOnTimeout(receiver, slot,
69+
static_cast<Qt::ConnectionType>(type | Qt::UniqueConnection)))
70+
{
71+
m_textUpdateConnection = connection;
72+
}
73+
}
74+
6275
private:
6376
QLabel * m_textLabel;
6477
QTimer * m_showTimer;
6578
QTimer * m_hideTimer;
79+
QTimer* m_refreshTimer;
80+
81+
QMetaObject::Connection m_textUpdateConnection;
6682
};
6783

6884
} // namespace lmms::gui

plugins/Vestige/Vestige.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@
4343

4444
#include "AudioEngine.h"
4545
#include "ConfigManager.h"
46-
#include "CustomTextKnob.h"
4746
#include "Engine.h"
4847
#include "FileDialog.h"
4948
#include "GuiApplication.h"
5049
#include "FontHelper.h"
5150
#include "InstrumentPlayHandle.h"
5251
#include "InstrumentTrack.h"
52+
#include "Knob.h"
5353
#include "LocaleHelper.h"
5454
#include "MainWindow.h"
5555
#include "PathUtil.h"
@@ -60,7 +60,6 @@
6060
#include "TextFloat.h"
6161
#include "Clipboard.h"
6262

63-
6463
#include "embed.h"
6564

6665
namespace lmms
@@ -981,8 +980,13 @@ ManageVestigeInstrumentView::ManageVestigeInstrumentView( Instrument * _instrume
981980

982981
const auto & description = s_dumpValues.at(1);
983982

984-
auto knob = new CustomTextKnob(KnobType::Bright26, description.left(15), this, description);
983+
auto knob = new Knob(KnobType::Bright26, description.left(15), SMALL_FONT_SIZE, this, description);
985984
knob->setDescription(description + ":");
985+
knob->setFloatingTextPushMode(10);
986+
connect(knob, &Knob::floatingTextUpdateRequested, this, [i, this]() {
987+
updateParameterText(i);
988+
}, Qt::DirectConnection);
989+
986990
m_vstKnobs.push_back(knob);
987991

988992
if( !hasKnobModel )
@@ -1128,7 +1132,6 @@ void ManageVestigeInstrumentView::setParameter( Model * action )
11281132

11291133
if ( m_vi->m_plugin != nullptr ) {
11301134
m_vi->m_plugin->setParam( knobUNID, m_vi->knobFModel[knobUNID]->value() );
1131-
syncParameterText();
11321135
}
11331136
}
11341137

@@ -1143,11 +1146,24 @@ void ManageVestigeInstrumentView::syncParameterText()
11431146

11441147
for (std::size_t i = 0; i < paramLabels.size(); ++i)
11451148
{
1146-
m_vstKnobs[i]->setValueText(paramDisplays[i] + ' ' + paramLabels[i]);
1149+
m_vstKnobs[i]->pushFloatingText(paramDisplays[i] + ' ' + paramLabels[i]);
11471150
}
11481151
}
11491152

11501153

1154+
void ManageVestigeInstrumentView::updateParameterText(int index)
1155+
{
1156+
m_vi->m_plugin->updateParameterLabel(index);
1157+
m_vi->m_plugin->updateParameterDisplay(index);
1158+
1159+
const auto& paramLabels = m_vi->m_plugin->allParameterLabels();
1160+
const auto& paramDisplays = m_vi->m_plugin->allParameterDisplays();
1161+
assert(paramLabels.size() == paramDisplays.size());
1162+
1163+
m_vstKnobs.at(index)->pushFloatingText(paramDisplays[index] + ' ' + paramLabels[index]);
1164+
}
1165+
1166+
11511167

11521168
void ManageVestigeInstrumentView::dragEnterEvent( QDragEnterEvent * _dee )
11531169
{

plugins/Vestige/Vestige.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class VstPlugin;
4646

4747
namespace gui
4848
{
49+
class Knob;
4950
class PixmapButton;
50-
class CustomTextKnob;
5151
class VestigeInstrumentView;
5252
class ManageVestigeInstrumentView;
5353
} // namespace gui
@@ -115,6 +115,7 @@ protected slots:
115115
void displayAutomatedOnly();
116116
void setParameter( lmms::Model * action );
117117
void syncParameterText();
118+
void updateParameterText(int index);
118119
void closeWindow();
119120

120121

@@ -132,7 +133,7 @@ protected slots:
132133
QPushButton * m_syncButton;
133134
QPushButton * m_displayAutomatedOnly;
134135
QPushButton * m_closeButton;
135-
std::vector<CustomTextKnob*> m_vstKnobs;
136+
std::vector<Knob*> m_vstKnobs;
136137
};
137138

138139

plugins/VstBase/VstPlugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,11 @@ bool VstPlugin::processMessage( const message & _m )
483483
}
484484

485485
case IdVstUpdateParameterLabel:
486-
m_allParameterLabels.at(static_cast<std::size_t>(_m.getInt())) = _m.getQString();
486+
m_allParameterLabels.at(static_cast<std::size_t>(_m.getInt(0))) = _m.getQString(1);
487487
break;
488488

489489
case IdVstUpdateParameterDisplay:
490-
m_allParameterDisplays.at(static_cast<std::size_t>(_m.getInt())) = _m.getQString();
490+
m_allParameterDisplays.at(static_cast<std::size_t>(_m.getInt(0))) = _m.getQString(1);
491491
break;
492492

493493
case IdVstPluginUniqueID:

plugins/VstEffect/VstEffectControls.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
#include <QScrollArea>
3434

3535
#include "embed.h"
36-
#include "CustomTextKnob.h"
36+
#include "FontHelper.h"
37+
#include "Knob.h"
3738
#include "VstEffectControlDialog.h"
3839
#include "VstEffect.h"
3940
#include "VstPlugin.h"
@@ -383,8 +384,13 @@ ManageVSTEffectView::ManageVSTEffectView( VstEffect * _eff, VstEffectControls *
383384

384385
const auto & description = s_dumpValues.at(1);
385386

386-
auto knob = new CustomTextKnob(KnobType::Bright26, description.left(15), widget, description);
387+
auto knob = new Knob(KnobType::Bright26, description.left(15), SMALL_FONT_SIZE, widget, description);
387388
knob->setDescription(description + ":");
389+
knob->setFloatingTextPushMode(10);
390+
connect(knob, &Knob::floatingTextUpdateRequested, this, [i, this]() {
391+
updateParameterText(i);
392+
}, Qt::DirectConnection);
393+
388394
m_vstKnobs.push_back(knob);
389395

390396
if( !hasKnobModel )
@@ -497,7 +503,6 @@ void ManageVSTEffectView::setParameter( Model * action )
497503

498504
if ( m_effect->m_plugin != nullptr ) {
499505
m_effect->m_plugin->setParam( knobUNID, m_vi2->knobFModel[knobUNID]->value() );
500-
syncParameterText();
501506
}
502507
}
503508

@@ -512,11 +517,21 @@ void ManageVSTEffectView::syncParameterText()
512517

513518
for (std::size_t i = 0; i < paramLabels.size(); ++i)
514519
{
515-
m_vstKnobs[i]->setValueText(paramDisplays[i] + ' ' + paramLabels[i]);
520+
m_vstKnobs[i]->pushFloatingText(paramDisplays[i] + ' ' + paramLabels[i]);
516521
}
517522
}
518523

524+
void ManageVSTEffectView::updateParameterText(int index)
525+
{
526+
m_effect->m_plugin->updateParameterLabel(index);
527+
m_effect->m_plugin->updateParameterDisplay(index);
519528

529+
const auto& paramLabels = m_effect->m_plugin->allParameterLabels();
530+
const auto& paramDisplays = m_effect->m_plugin->allParameterDisplays();
531+
assert(paramLabels.size() == paramDisplays.size());
532+
533+
m_vstKnobs.at(index)->pushFloatingText(paramDisplays[index] + ' ' + paramLabels[index]);
534+
}
520535

521536
ManageVSTEffectView::~ManageVSTEffectView()
522537
{

plugins/VstEffect/VstEffectControls.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class VstEffect;
4444

4545
namespace gui
4646
{
47-
class CustomTextKnob;
47+
class Knob;
4848
class ManageVSTEffectView;
4949
class VstEffectControlDialog;
5050
}
@@ -121,6 +121,7 @@ protected slots:
121121
void displayAutomatedOnly();
122122
void setParameter( lmms::Model * action );
123123
void syncParameterText();
124+
void updateParameterText(int index);
124125
void closeWindow();
125126

126127
private:
@@ -139,7 +140,7 @@ protected slots:
139140
QPushButton * m_syncButton;
140141
QPushButton * m_displayAutomatedOnly;
141142
QPushButton * m_closeButton;
142-
std::vector<CustomTextKnob*> m_vstKnobs;
143+
std::vector<Knob*> m_vstKnobs;
143144
};
144145

145146

src/gui/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ SET(LMMS_SRCS
104104
gui/widgets/CPULoadWidget.cpp
105105
gui/widgets/CaptionMenu.cpp
106106
gui/widgets/ComboBox.cpp
107-
gui/widgets/CustomTextKnob.cpp
108107
gui/widgets/Draggable.cpp
109108
gui/widgets/Fader.cpp
110109
gui/widgets/FloatModelEditorBase.cpp

0 commit comments

Comments
 (0)