MidiAlsaSeq.h 3.3 KB

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