Controller.h 4.0 KB

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