AudioJack.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * AudioJack.h - support for JACK-transport
  3. *
  4. * Copyright (c) 2005-2009 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_JACK_H
  25. #define AUDIO_JACK_H
  26. #include "lmmsconfig.h"
  27. #ifdef LMMS_HAVE_JACK
  28. #ifndef LMMS_HAVE_WEAKJACK
  29. #include <jack/jack.h>
  30. #else
  31. #include "weak_libjack.h"
  32. #endif
  33. #include <atomic>
  34. #include <QtCore/QVector>
  35. #include <QtCore/QList>
  36. #include <QtCore/QMap>
  37. #include "AudioDevice.h"
  38. #include "AudioDeviceSetupWidget.h"
  39. class QLineEdit;
  40. class LcdSpinBox;
  41. class MidiJack;
  42. class AudioJack : public QObject, public AudioDevice
  43. {
  44. Q_OBJECT
  45. public:
  46. AudioJack( bool & _success_ful, AudioEngine* audioEngine );
  47. virtual ~AudioJack();
  48. // this is to allow the jack midi connection to use the same jack client connection
  49. // the jack callback is handled here, we call the midi client so that it can read
  50. // it's midi data during the callback
  51. AudioJack * addMidiClient(MidiJack *midiClient);
  52. void removeMidiClient(void) { m_midiClient = nullptr; }
  53. jack_client_t * jackClient() {return m_client;};
  54. inline static QString name()
  55. {
  56. return QT_TRANSLATE_NOOP( "AudioDeviceSetupWidget",
  57. "JACK (JACK Audio Connection Kit)" );
  58. }
  59. class setupWidget : public AudioDeviceSetupWidget
  60. {
  61. public:
  62. setupWidget( QWidget * _parent );
  63. virtual ~setupWidget();
  64. virtual void saveSettings();
  65. private:
  66. QLineEdit * m_clientName;
  67. LcdSpinBox * m_channels;
  68. } ;
  69. private slots:
  70. void restartAfterZombified();
  71. private:
  72. bool initJackClient();
  73. virtual void startProcessing();
  74. virtual void stopProcessing();
  75. virtual void applyQualitySettings();
  76. virtual void registerPort( AudioPort * _port );
  77. virtual void unregisterPort( AudioPort * _port );
  78. virtual void renamePort( AudioPort * _port );
  79. int processCallback( jack_nframes_t _nframes, void * _udata );
  80. static int staticProcessCallback( jack_nframes_t _nframes,
  81. void * _udata );
  82. static void shutdownCallback( void * _udata );
  83. jack_client_t * m_client;
  84. bool m_active;
  85. std::atomic<bool> m_stopped;
  86. std::atomic<MidiJack *> m_midiClient;
  87. QVector<jack_port_t *> m_outputPorts;
  88. jack_default_audio_sample_t * * m_tempOutBufs;
  89. surroundSampleFrame * m_outBuf;
  90. f_cnt_t m_framesDoneInCurBuf;
  91. f_cnt_t m_framesToDoInCurBuf;
  92. #ifdef AUDIO_PORT_SUPPORT
  93. struct StereoPort
  94. {
  95. jack_port_t * ports[2];
  96. } ;
  97. typedef QMap<AudioPort *, StereoPort> JackPortMap;
  98. JackPortMap m_portMap;
  99. #endif
  100. signals:
  101. void zombified();
  102. } ;
  103. #endif
  104. #endif