MidiPort.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * MidiPort.h - abstraction of MIDI ports which are part of LMMS' MIDI
  3. * sequencing system
  4. *
  5. * Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  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_PORT_H
  26. #define MIDI_PORT_H
  27. #include <QtCore/QString>
  28. #include <QtCore/QList>
  29. #include <QtCore/QMap>
  30. #include "Midi.h"
  31. #include "MidiTime.h"
  32. #include "AutomatableModel.h"
  33. class MidiClient;
  34. class MidiEvent;
  35. class MidiEventProcessor;
  36. class MidiPortMenu;
  37. // class for abstraction of MIDI-port
  38. class MidiPort : public Model, public SerializingObject
  39. {
  40. Q_OBJECT
  41. mapPropertyFromModel(int,inputChannel,setInputChannel,m_inputChannelModel);
  42. mapPropertyFromModel(int,outputChannel,setOutputChannel,m_outputChannelModel);
  43. mapPropertyFromModel(int,inputController,setInputController,m_inputControllerModel);
  44. mapPropertyFromModel(int,outputController,setOutputController,m_outputControllerModel);
  45. mapPropertyFromModel(int,fixedInputVelocity,setFixedInputVelocity,m_fixedInputVelocityModel);
  46. mapPropertyFromModel(int,fixedOutputVelocity,setFixedOutputVelocity,m_fixedOutputVelocityModel);
  47. mapPropertyFromModel(int,fixedOutputNote,setFixedOutputNote,m_fixedOutputNoteModel);
  48. mapPropertyFromModel(int,outputProgram,setOutputProgram,m_outputProgramModel);
  49. mapPropertyFromModel(int,baseVelocity,setBaseVelocity,m_baseVelocityModel);
  50. mapPropertyFromModel(bool,isReadable,setReadable,m_readableModel);
  51. mapPropertyFromModel(bool,isWritable,setWritable,m_writableModel);
  52. public:
  53. typedef QMap<QString, bool> Map;
  54. enum Modes
  55. {
  56. Disabled, // don't route any MIDI-events (default)
  57. Input, // from MIDI-client to MIDI-event-processor
  58. Output, // from MIDI-event-processor to MIDI-client
  59. Duplex // both directions
  60. } ;
  61. typedef Modes Mode;
  62. MidiPort( const QString& name,
  63. MidiClient* client,
  64. MidiEventProcessor* eventProcessor,
  65. Model* parent = NULL,
  66. Mode mode = Disabled );
  67. virtual ~MidiPort();
  68. void setName( const QString& name );
  69. Mode mode() const
  70. {
  71. return m_mode;
  72. }
  73. void setMode( Mode mode );
  74. bool isInputEnabled() const
  75. {
  76. return mode() == Input || mode() == Duplex;
  77. }
  78. bool isOutputEnabled() const
  79. {
  80. return mode() == Output || mode() == Duplex;
  81. }
  82. int realOutputChannel() const
  83. {
  84. return outputChannel() - 1;
  85. }
  86. void processInEvent( const MidiEvent& event, const MidiTime& time = MidiTime() );
  87. void processOutEvent( const MidiEvent& event, const MidiTime& time = MidiTime() );
  88. void saveSettings( QDomDocument& doc, QDomElement& thisElement ) override;
  89. void loadSettings( const QDomElement& thisElement ) override;
  90. QString nodeName() const override
  91. {
  92. return "midiport";
  93. }
  94. void subscribeReadablePort( const QString& port, bool subscribe = true );
  95. void subscribeWritablePort( const QString& port, bool subscribe = true );
  96. const Map& readablePorts() const
  97. {
  98. return m_readablePorts;
  99. }
  100. const Map& writablePorts() const
  101. {
  102. return m_writablePorts;
  103. }
  104. void invalidateCilent();
  105. MidiPortMenu* m_readablePortsMenu;
  106. MidiPortMenu* m_writablePortsMenu;
  107. public slots:
  108. void updateMidiPortMode();
  109. private slots:
  110. void updateReadablePorts();
  111. void updateWritablePorts();
  112. void updateOutputProgram();
  113. private:
  114. MidiClient* m_midiClient;
  115. MidiEventProcessor* m_midiEventProcessor;
  116. Mode m_mode;
  117. IntModel m_inputChannelModel;
  118. IntModel m_outputChannelModel;
  119. IntModel m_inputControllerModel;
  120. IntModel m_outputControllerModel;
  121. IntModel m_fixedInputVelocityModel;
  122. IntModel m_fixedOutputVelocityModel;
  123. IntModel m_fixedOutputNoteModel;
  124. IntModel m_outputProgramModel;
  125. IntModel m_baseVelocityModel;
  126. BoolModel m_readableModel;
  127. BoolModel m_writableModel;
  128. Map m_readablePorts;
  129. Map m_writablePorts;
  130. friend class ControllerConnectionDialog;
  131. friend class InstrumentMidiIOView;
  132. signals:
  133. void readablePortsChanged();
  134. void writablePortsChanged();
  135. void modeChanged();
  136. } ;
  137. typedef QList<MidiPort *> MidiPortList;
  138. #endif