MidiPort.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 "TimePos.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 = nullptr,
  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. // There's a possibility of outputChannel being 0 ("--"), which is used to keep all
  85. // midi channels when forwarding. In that case, realOutputChannel will return the
  86. // default channel 1 (whose value is 0).
  87. return outputChannel() ? outputChannel() - 1 : 0;
  88. }
  89. void processInEvent( const MidiEvent& event, const TimePos& time = TimePos() );
  90. void processOutEvent( const MidiEvent& event, const TimePos& time = TimePos() );
  91. void saveSettings( QDomDocument& doc, QDomElement& thisElement ) override;
  92. void loadSettings( const QDomElement& thisElement ) override;
  93. QString nodeName() const override
  94. {
  95. return "midiport";
  96. }
  97. void subscribeReadablePort( const QString& port, bool subscribe = true );
  98. void subscribeWritablePort( const QString& port, bool subscribe = true );
  99. const Map& readablePorts() const
  100. {
  101. return m_readablePorts;
  102. }
  103. const Map& writablePorts() const
  104. {
  105. return m_writablePorts;
  106. }
  107. void invalidateCilent();
  108. MidiPortMenu* m_readablePortsMenu;
  109. MidiPortMenu* m_writablePortsMenu;
  110. public slots:
  111. void updateMidiPortMode();
  112. private slots:
  113. void updateReadablePorts();
  114. void updateWritablePorts();
  115. void updateOutputProgram();
  116. private:
  117. MidiClient* m_midiClient;
  118. MidiEventProcessor* m_midiEventProcessor;
  119. Mode m_mode;
  120. IntModel m_inputChannelModel;
  121. IntModel m_outputChannelModel;
  122. IntModel m_inputControllerModel;
  123. IntModel m_outputControllerModel;
  124. IntModel m_fixedInputVelocityModel;
  125. IntModel m_fixedOutputVelocityModel;
  126. IntModel m_fixedOutputNoteModel;
  127. IntModel m_outputProgramModel;
  128. IntModel m_baseVelocityModel;
  129. BoolModel m_readableModel;
  130. BoolModel m_writableModel;
  131. Map m_readablePorts;
  132. Map m_writablePorts;
  133. friend class ControllerConnectionDialog;
  134. friend class InstrumentMidiIOView;
  135. signals:
  136. void readablePortsChanged();
  137. void writablePortsChanged();
  138. void modeChanged();
  139. } ;
  140. typedef QList<MidiPort *> MidiPortList;
  141. #endif