MidiAlsaSeq.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * MidiAlsaSeq.h - ALSA-sequencer-client
  3. *
  4. * Copyright (c) 2005-2013 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 MIDI_ALSA_SEQ_H
  25. #define MIDI_ALSA_SEQ_H
  26. #include "lmmsconfig.h"
  27. #ifdef LMMS_HAVE_ALSA
  28. #include <alsa/asoundlib.h>
  29. #include <QtCore/QMutex>
  30. #include <QtCore/QThread>
  31. #include <QtCore/QTimer>
  32. #include "MidiClient.h"
  33. struct pollfd;
  34. class MidiAlsaSeq : public QThread, public MidiClient
  35. {
  36. Q_OBJECT
  37. public:
  38. MidiAlsaSeq();
  39. virtual ~MidiAlsaSeq();
  40. static QString probeDevice();
  41. inline static QString name()
  42. {
  43. return QT_TRANSLATE_NOOP( "MidiSetupWidget",
  44. "ALSA-Sequencer (Advanced Linux Sound "
  45. "Architecture)" );
  46. }
  47. inline static QString configSection()
  48. {
  49. return "Midialsaseq";
  50. }
  51. virtual void processOutEvent( const MidiEvent & _me,
  52. const TimePos & _time,
  53. const MidiPort * _port ) override;
  54. void applyPortMode( MidiPort * _port ) override;
  55. void applyPortName( MidiPort * _port ) override;
  56. void removePort( MidiPort * _port ) override;
  57. // list seq-ports from ALSA
  58. QStringList readablePorts() const override
  59. {
  60. return m_readablePorts;
  61. }
  62. QStringList writablePorts() const override
  63. {
  64. return m_writablePorts;
  65. }
  66. // return name of port which specified MIDI event came from
  67. QString sourcePortName( const MidiEvent & ) const override;
  68. // (un)subscribe given MidiPort to/from destination-port
  69. virtual void subscribeReadablePort( MidiPort * _port,
  70. const QString & _dest,
  71. bool _subscribe = true ) override;
  72. virtual void subscribeWritablePort( MidiPort * _port,
  73. const QString & _dest,
  74. bool _subscribe = true ) override;
  75. virtual void connectRPChanged( QObject * _receiver,
  76. const char * _member ) override
  77. {
  78. connect( this, SIGNAL( readablePortsChanged() ),
  79. _receiver, _member );
  80. }
  81. virtual void connectWPChanged( QObject * _receiver,
  82. const char * _member ) override
  83. {
  84. connect( this, SIGNAL( writablePortsChanged() ),
  85. _receiver, _member );
  86. }
  87. private slots:
  88. void changeQueueTempo( bpm_t _bpm );
  89. void updatePortList();
  90. private:
  91. void run() override;
  92. #ifdef LMMS_HAVE_ALSA
  93. QMutex m_seqMutex;
  94. snd_seq_t * m_seqHandle;
  95. struct Ports
  96. {
  97. Ports() { p[0] = -1; p[1] = -1; }
  98. int & operator[]( const int _i ) { return p[_i]; }
  99. private: int p[2];
  100. } ;
  101. QMap<MidiPort *, Ports> m_portIDs;
  102. #endif
  103. int m_queueID;
  104. volatile bool m_quit;
  105. QTimer m_portListUpdateTimer;
  106. QStringList m_readablePorts;
  107. QStringList m_writablePorts;
  108. int m_pipe[2];
  109. signals:
  110. void readablePortsChanged();
  111. void writablePortsChanged();
  112. } ;
  113. #endif
  114. #endif