LMMS
Loading...
Searching...
No Matches
Controller.h
Go to the documentation of this file.
1/*
2 * Controller.h - declaration of class controller, which provides a
3 * standard for all controllers and controller plugins
4 *
5 * Copyright (c) 2008-2009 Paul Giblock <pgllama/at/gmail.com>
6 *
7 * This file is part of LMMS - https://lmms.io
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program (see COPYING); if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA.
23 *
24 */
25
26#ifndef LMMS_CONTROLLER_H
27#define LMMS_CONTROLLER_H
28
29#include "lmms_export.h"
30#include "Engine.h"
31#include "Model.h"
32#include "JournallingObject.h"
33#include "ValueBuffer.h"
34
35namespace lmms
36{
37
38class Controller;
40
41namespace gui
42{
43
45
46} // namespace gui
47
48using ControllerVector = std::vector<Controller*>;
49
50class LMMS_EXPORT Controller : public Model, public JournallingObject
51{
52 Q_OBJECT
53public:
54 enum class ControllerType
55 {
56 Dummy,
58 Midi,
59 Peak,
60 /*
61 XY,
62 Equation
63 */
64 } ;
65
66 Controller( ControllerType _type, Model * _parent,
67 const QString & _display_name );
68
69 ~Controller() override;
70
71 virtual float currentValue( int _offset );
72 // The per-controller get-value-in-buffers function
73 virtual ValueBuffer * valueBuffer();
74
75 inline bool isSampleExact() const
76 {
77 return m_sampleExact;
78 }
79
80 void setSampleExact( bool _exact )
81 {
82 m_sampleExact = _exact;
83 }
84
85 inline ControllerType type() const
86 {
87 return( m_type );
88 }
89
90 // return whether this controller updates models frequently - used for
91 // determining when to update GUI
92 inline bool frequentUpdates() const
93 {
94 switch( m_type )
95 {
96 case ControllerType::Lfo: return( true );
97 case ControllerType::Peak: return( true );
98 default:
99 break;
100 }
101 return( false );
102 }
103
104 virtual const QString & name() const
105 {
106 return( m_name );
107 }
108
109
110 void saveSettings( QDomDocument & _doc, QDomElement & _this ) override;
111 void loadSettings( const QDomElement & _this ) override;
112 QString nodeName() const override;
113
114 static Controller * create( ControllerType _tt, Model * _parent );
115 static Controller * create( const QDomElement & _this,
116 Model * _parent );
117
118 inline static float fittedValue( float _val )
119 {
120 return std::clamp(_val, 0.0f, 1.0f);
121 }
122
123 static long runningPeriods()
124 {
125 return s_periods;
126 }
127 static unsigned int runningFrames();
128 static float runningTime();
129
130 static void triggerFrameCounter();
131 static void resetFrameCounter();
132
133 //Accepts a ControllerConnection * as it may be used in the future.
134 void addConnection( ControllerConnection * );
135 void removeConnection( ControllerConnection * );
136 int connectionCount() const;
137
138 bool hasModel( const Model * m ) const;
139
140public slots:
141 virtual gui::ControllerDialog * createDialog( QWidget * _parent );
142
143 virtual void setName( const QString & _new_name )
144 {
145 m_name = _new_name;
146 }
147
148
149protected:
150 // The internal per-controller get-value function
151 virtual float value( int _offset );
152
153 virtual void updateValueBuffer();
154
155 // buffer for storing sample-exact values in case there
156 // are more than one model wanting it, so we don't have to create it
157 // again every time
159 // when we last updated the valuebuffer - so we know if we have to update it
161
165
166 QString m_name;
168
170
171 static long s_periods;
172
173
174signals:
175 // The value changed while the audio engine isn't running (i.e: MIDI CC)
177
179
180} ;
181
182
183} // namespace lmms
184
185#endif // LMMS_CONTROLLER_H
Definition ControllerConnection.h:53
Definition Controller.h:51
ControllerType type() const
Definition Controller.h:85
long m_bufferLastUpdated
Definition Controller.h:160
Controller(ControllerType _type, Model *_parent, const QString &_display_name)
Definition Controller.cpp:47
virtual void setName(const QString &_new_name)
Definition Controller.h:143
bool m_sampleExact
Definition Controller.h:163
ValueBuffer m_valueBuffer
Definition Controller.h:158
static long runningPeriods()
Definition Controller.h:123
static long s_periods
Definition Controller.h:171
void setSampleExact(bool _exact)
Definition Controller.h:80
virtual const QString & name() const
Definition Controller.h:104
ControllerType m_type
Definition Controller.h:167
ControllerType
Definition Controller.h:55
@ Lfo
Definition Controller.h:57
@ Peak
Definition Controller.h:59
bool frequentUpdates() const
Definition Controller.h:92
int m_connectionCount
Definition Controller.h:164
bool isSampleExact() const
Definition Controller.h:75
static float fittedValue(float _val)
Definition Controller.h:118
static ControllerVector s_controllers
Definition Controller.h:169
QString m_name
Definition Controller.h:166
float m_currentValue
Definition Controller.h:162
JournallingObject()
Definition JournallingObject.cpp:36
Definition Lfo.h:36
Definition Model.h:37
Model(Model *parent, QString displayName=QString(), bool defaultConstructed=false)
Definition Model.cpp:30
Definition ValueBuffer.h:38
Definition ControllerDialog.h:42
unsigned * m
Definition inflate.c:1559
static PuglViewHint int value
Definition pugl.h:1708
Definition AudioPortAudio.cpp:223
Definition AudioAlsa.cpp:35
std::vector< Controller * > ControllerVector
Definition Controller.h:48