Controller.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #ifndef CONTROLLER_H
  26. #define CONTROLLER_H
  27. #include "lmms_export.h"
  28. #include "Engine.h"
  29. #include "Model.h"
  30. #include "JournallingObject.h"
  31. #include "ValueBuffer.h"
  32. class ControllerDialog;
  33. class Controller;
  34. class ControllerConnection;
  35. typedef QVector<Controller *> ControllerVector;
  36. class LMMS_EXPORT Controller : public Model, public JournallingObject
  37. {
  38. Q_OBJECT
  39. public:
  40. enum ControllerTypes
  41. {
  42. DummyController,
  43. LfoController,
  44. MidiController,
  45. PeakController,
  46. /*
  47. XYController,
  48. EquationController
  49. */
  50. NumControllerTypes
  51. } ;
  52. Controller( ControllerTypes _type, Model * _parent,
  53. const QString & _display_name );
  54. virtual ~Controller();
  55. virtual float currentValue( int _offset );
  56. // The per-controller get-value-in-buffers function
  57. virtual ValueBuffer * valueBuffer();
  58. inline bool isSampleExact() const
  59. {
  60. return m_sampleExact;
  61. }
  62. void setSampleExact( bool _exact )
  63. {
  64. m_sampleExact = _exact;
  65. }
  66. inline ControllerTypes type() const
  67. {
  68. return( m_type );
  69. }
  70. // return whether this controller updates models frequently - used for
  71. // determining when to update GUI
  72. inline bool frequentUpdates() const
  73. {
  74. switch( m_type )
  75. {
  76. case LfoController: return( true );
  77. case PeakController: return( true );
  78. default:
  79. break;
  80. }
  81. return( false );
  82. }
  83. virtual const QString & name() const
  84. {
  85. return( m_name );
  86. }
  87. void saveSettings( QDomDocument & _doc, QDomElement & _this ) override;
  88. void loadSettings( const QDomElement & _this ) override;
  89. QString nodeName() const override;
  90. static Controller * create( ControllerTypes _tt, Model * _parent );
  91. static Controller * create( const QDomElement & _this,
  92. Model * _parent );
  93. inline static float fittedValue( float _val )
  94. {
  95. return qBound<float>( 0.0f, _val, 1.0f );
  96. }
  97. static long runningPeriods()
  98. {
  99. return s_periods;
  100. }
  101. static unsigned int runningFrames();
  102. static float runningTime();
  103. static void triggerFrameCounter();
  104. static void resetFrameCounter();
  105. //Accepts a ControllerConnection * as it may be used in the future.
  106. void addConnection( ControllerConnection * );
  107. void removeConnection( ControllerConnection * );
  108. int connectionCount() const;
  109. bool hasModel( const Model * m ) const;
  110. public slots:
  111. virtual ControllerDialog * createDialog( QWidget * _parent );
  112. virtual void setName( const QString & _new_name )
  113. {
  114. m_name = _new_name;
  115. }
  116. protected:
  117. // The internal per-controller get-value function
  118. virtual float value( int _offset );
  119. virtual void updateValueBuffer();
  120. // buffer for storing sample-exact values in case there
  121. // are more than one model wanting it, so we don't have to create it
  122. // again every time
  123. ValueBuffer m_valueBuffer;
  124. // when we last updated the valuebuffer - so we know if we have to update it
  125. long m_bufferLastUpdated;
  126. float m_currentValue;
  127. bool m_sampleExact;
  128. int m_connectionCount;
  129. QString m_name;
  130. ControllerTypes m_type;
  131. static ControllerVector s_controllers;
  132. static long s_periods;
  133. signals:
  134. // The value changed while the audio engine isn't running (i.e: MIDI CC)
  135. void valueChanged();
  136. friend class ControllerDialog;
  137. } ;
  138. #endif