AudioPort.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * AudioPort.h - base-class for objects providing sound at a port
  3. *
  4. * Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef AUDIO_PORT_H
  25. #define AUDIO_PORT_H
  26. #include <memory>
  27. #include <QtCore/QString>
  28. #include <QtCore/QMutex>
  29. #include <QtCore/QMutexLocker>
  30. #include "MemoryManager.h"
  31. #include "PlayHandle.h"
  32. class EffectChain;
  33. class FloatModel;
  34. class BoolModel;
  35. class AudioPort : public ThreadableJob
  36. {
  37. MM_OPERATORS
  38. public:
  39. AudioPort( const QString & _name, bool _has_effect_chain = true,
  40. FloatModel * volumeModel = nullptr, FloatModel * panningModel = nullptr,
  41. BoolModel * mutedModel = nullptr );
  42. virtual ~AudioPort();
  43. inline sampleFrame * buffer()
  44. {
  45. return m_portBuffer;
  46. }
  47. inline void lockBuffer()
  48. {
  49. m_portBufferLock.lock();
  50. }
  51. inline void unlockBuffer()
  52. {
  53. m_portBufferLock.unlock();
  54. }
  55. // indicate whether JACK & Co should provide output-buffer at ext. port
  56. inline bool extOutputEnabled() const
  57. {
  58. return m_extOutputEnabled;
  59. }
  60. void setExtOutputEnabled( bool _enabled );
  61. // next mixer-channel after this audio-port
  62. // (-1 = none 0 = master)
  63. inline mix_ch_t nextMixerChannel() const
  64. {
  65. return m_nextMixerChannel;
  66. }
  67. inline EffectChain * effects()
  68. {
  69. return m_effects.get();
  70. }
  71. void setNextMixerChannel( const mix_ch_t _chnl )
  72. {
  73. m_nextMixerChannel = _chnl;
  74. }
  75. const QString & name() const
  76. {
  77. return m_name;
  78. }
  79. void setName( const QString & _new_name );
  80. bool processEffects();
  81. // ThreadableJob stuff
  82. void doProcessing() override;
  83. bool requiresProcessing() const override
  84. {
  85. return true;
  86. }
  87. void addPlayHandle( PlayHandle * handle );
  88. void removePlayHandle( PlayHandle * handle );
  89. private:
  90. volatile bool m_bufferUsage;
  91. sampleFrame * m_portBuffer;
  92. QMutex m_portBufferLock;
  93. bool m_extOutputEnabled;
  94. mix_ch_t m_nextMixerChannel;
  95. QString m_name;
  96. std::unique_ptr<EffectChain> m_effects;
  97. PlayHandleList m_playHandles;
  98. QMutex m_playHandleLock;
  99. FloatModel * m_volumeModel;
  100. FloatModel * m_panningModel;
  101. BoolModel * m_mutedModel;
  102. friend class AudioEngine;
  103. friend class AudioEngineWorkerThread;
  104. } ;
  105. #endif