MidiApple.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * MidiApple.h - Apple raw MIDI client
  3. *
  4. * Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. * Copyright (c) 2015 Maurizio Lo Bosco (rageboge on github)
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #ifndef MIDI_APPLE_H
  26. #define MIDI_APPLE_H
  27. #include "lmmsconfig.h"
  28. #ifdef LMMS_BUILD_APPLE
  29. #include "MidiClient.h"
  30. #include "MidiPort.h"
  31. #include <CoreMIDI/CoreMIDI.h>
  32. class QLineEdit;
  33. class MidiApple : public QObject, public MidiClient
  34. {
  35. Q_OBJECT
  36. public:
  37. MidiApple();
  38. virtual ~MidiApple();
  39. inline static QString probeDevice()
  40. {
  41. return QString(); // no midi device name
  42. }
  43. inline static QString name()
  44. {
  45. return QT_TRANSLATE_NOOP( "MidiSetupWidget", "Apple MIDI" );
  46. }
  47. inline static QString configSection()
  48. {
  49. return QString(); // no configuration settings
  50. }
  51. virtual void processOutEvent( const MidiEvent & _me,
  52. const TimePos & _time,
  53. const MidiPort * _port );
  54. virtual void applyPortMode( MidiPort * _port );
  55. virtual void removePort( MidiPort * _port );
  56. // list devices as ports
  57. virtual QStringList readablePorts() const
  58. {
  59. return m_inputDevices.keys();
  60. }
  61. virtual QStringList writablePorts() const
  62. {
  63. return m_outputDevices.keys();
  64. }
  65. // return name of port which specified MIDI event came from
  66. virtual QString sourcePortName( const MidiEvent & ) const;
  67. // (un)subscribe given MidiPort to/from destination-port
  68. virtual void subscribeReadablePort( MidiPort * _port,
  69. const QString & _dest,
  70. bool _subscribe = true );
  71. virtual void subscribeWritablePort( MidiPort * _port,
  72. const QString & _dest,
  73. bool _subscribe = true );
  74. virtual void connectRPChanged( QObject * _receiver,
  75. const char * _member )
  76. {
  77. connect( this, SIGNAL( readablePortsChanged() ),
  78. _receiver, _member );
  79. }
  80. virtual void connectWPChanged( QObject * _receiver,
  81. const char * _member )
  82. {
  83. connect( this, SIGNAL( writablePortsChanged() ),
  84. _receiver, _member );
  85. }
  86. virtual bool isRaw() const
  87. {
  88. return false;
  89. }
  90. private:// slots:
  91. void updateDeviceList();
  92. private:
  93. void openDevices();
  94. void closeDevices();
  95. void openMidiReference( MIDIEndpointRef reference, QString refName,bool isIn );
  96. MIDIClientRef getMidiClientRef();
  97. void midiInClose( MIDIEndpointRef reference );
  98. static void NotifyCallback( const MIDINotification *message, void *refCon );
  99. static void ReadCallback( const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon );
  100. void HandleReadCallback( const MIDIPacketList *pktlist, void *srcConnRefCon );
  101. void notifyMidiPortList( MidiPortList portList, MidiEvent midiEvent);
  102. char * getFullName( MIDIEndpointRef &endpoint_ref );
  103. void sendMidiOut( MIDIEndpointRef & endPointRef, const MidiEvent& event );
  104. MIDIPacketList createMidiPacketList( const MidiEvent& event );
  105. MIDIClientRef mClient = 0;
  106. QMap<QString, MIDIEndpointRef> m_inputDevices;
  107. QMap<QString, MIDIEndpointRef> m_outputDevices;
  108. QMap<MIDIEndpointRef, MIDIPortRef> m_sourcePortRef;
  109. // subscriptions
  110. typedef QMap<QString, MidiPortList> SubMap;
  111. SubMap m_inputSubs;
  112. SubMap m_outputSubs;
  113. signals:
  114. void readablePortsChanged();
  115. void writablePortsChanged();
  116. } ;
  117. #endif
  118. #endif