MidiJack.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * MidiJack.h - MIDI client for Jack
  3. *
  4. * Copyright (c) 2015 Shane Ambler <develop/at/shaneware.biz>
  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 MIDIJACK_H
  25. #define MIDIJACK_H
  26. #include "lmmsconfig.h"
  27. #ifdef LMMS_HAVE_JACK
  28. #ifndef LMMS_HAVE_WEAKJACK
  29. #include <jack/jack.h>
  30. #include <jack/midiport.h>
  31. #else
  32. #include "weak_libjack.h"
  33. #endif
  34. #include <QtCore/QThread>
  35. #include <QMutex>
  36. #include <QtCore/QFile>
  37. #include "MidiClient.h"
  38. #include "AudioJack.h"
  39. constexpr size_t JACK_MIDI_BUFFER_MAX = 64; /* events */
  40. class QLineEdit;
  41. class MidiJack : public QThread, public MidiClientRaw
  42. {
  43. Q_OBJECT
  44. public:
  45. MidiJack();
  46. virtual ~MidiJack();
  47. jack_client_t* jackClient();
  48. static QString probeDevice();
  49. inline static QString name()
  50. {
  51. return( QT_TRANSLATE_NOOP( "MidiSetupWidget",
  52. "Jack-MIDI" ) );
  53. }
  54. void JackMidiWrite(jack_nframes_t nframes);
  55. void JackMidiRead(jack_nframes_t nframes);
  56. inline static QString configSection()
  57. {
  58. return "MidiJack";
  59. }
  60. protected:
  61. virtual void sendByte( const unsigned char c );
  62. virtual void run();
  63. private:
  64. AudioJack *m_jackAudio;
  65. jack_client_t *m_jackClient;
  66. jack_port_t *m_input_port;
  67. jack_port_t *m_output_port;
  68. uint8_t m_jack_buffer[JACK_MIDI_BUFFER_MAX * 4];
  69. void JackMidiOutEvent(uint8_t *buf, uint8_t len);
  70. void lock();
  71. void unlock();
  72. void getPortInfo( const QString& sPortName, int& nClient, int& nPort );
  73. volatile bool m_quit;
  74. };
  75. #endif // LMMS_HAVE_JACK
  76. #endif // MIDIJACK_H