1 /*
2     Drumstick MIDI realtime input-output
3     Copyright (C) 2009-2021 Pedro Lopez-Cabanillas <plcl@users.sf.net>
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef MIDIINPUT_H
20 #define MIDIINPUT_H
21 
22 #include <QObject>
23 #include <QString>
24 #include <QStringList>
25 #include <QtPlugin>
26 #include <QSettings>
27 
28 #include "macros.h"
29 #include "rtmidioutput.h"
30 
31 /**
32  * @file rtmidiinput.h
33  * Realtime MIDI input interface
34  */
35 
36 namespace drumstick { namespace rt {
37 
38     /**
39      * @addtogroup RT
40      * @{
41      *
42      * @class MIDIInput
43      * @brief MIDI IN interface
44      */
45     class DRUMSTICK_EXPORT MIDIInput : public QObject
46     {
47         Q_OBJECT
48 
49     public:
50         /**
51          * @brief MIDIInput constructor
52          * @param parent
53          */
QObject(parent)54         explicit MIDIInput(QObject *parent = nullptr) : QObject(parent) {}
55         /**
56          * @brief ~MIDIInput destructor
57          */
58         virtual ~MIDIInput() = default;
59         /**
60          * @brief initialize
61          * @param settings
62          */
63         virtual void initialize(QSettings* settings) = 0;
64         /**
65          * @brief backendName
66          * @return plugin name
67          */
68         virtual QString backendName() = 0;
69         /**
70          * @brief publicName
71          * @return MIDI port name
72          */
73         virtual QString publicName() = 0;
74         /**
75          * @brief setPublicName
76          * @param name MIDI port name
77          */
78         virtual void setPublicName(QString name) = 0;
79         /**
80          * @brief connections
81          * @param advanced whether the advanced connections are included or not
82          * @return list of available MIDI ports
83          */
84         virtual QList<MIDIConnection> connections(bool advanced = false) = 0;
85         /**
86          * @brief setExcludedConnections
87          * @param conns
88          */
89         virtual void setExcludedConnections(QStringList conns) = 0;
90         /**
91          * @brief open the MIDI port by name
92          * @param conn Connection to open
93          */
94         virtual void open(const MIDIConnection& conn) = 0;
95         /**
96          * @brief close the MIDI port
97          */
98         virtual void close() = 0;
99         /**
100          * @brief currentConnection
101          * @return name of the current connection if it is opened
102          */
103         virtual MIDIConnection currentConnection() = 0;
104         /**
105          * @brief setMIDIThruDevice
106          * @param device
107          */
108         virtual void setMIDIThruDevice(MIDIOutput* device) = 0;
109         /**
110          * @brief enableMIDIThru
111          * @param enable
112          */
113         virtual void enableMIDIThru(bool enable) = 0;
114         /**
115          * @brief isEnabledMIDIThru
116          * @return MIDI Thru is enabled
117          */
118         virtual bool isEnabledMIDIThru() = 0;
119 
120     Q_SIGNALS:
121         /**
122          * @brief midiNoteOff 0x8
123          * @param chan
124          * @param note
125          * @param vel
126          */
127         void midiNoteOff(const int chan, const int note, const int vel);
128 
129         /**
130          * @brief midiNoteOn 0x9
131          * @param chan
132          * @param note
133          * @param vel
134          */
135         void midiNoteOn(const int chan, const int note, const int vel);
136 
137         /**
138          * @brief midiKeyPressure 0xA
139          * @param chan
140          * @param note
141          * @param value
142          */
143         void midiKeyPressure(const int chan, const int note, const int value);
144 
145         /**
146          * @brief midiController 0xB
147          * @param chan
148          * @param control
149          * @param value
150          */
151         void midiController(const int chan, const int control, const int value);
152 
153         /**
154          * @brief midiProgram 0xC
155          * @param chan
156          * @param program
157          */
158         void midiProgram(const int chan, const int program);
159 
160         /**
161          * @brief midiChannelPressure 0xD
162          * @param chan
163          * @param value
164          */
165         void midiChannelPressure(const int chan, const int value);
166 
167         /**
168          * @brief midiPitchBend 0xE
169          * @param chan
170          * @param value
171          */
172         void midiPitchBend(const int chan, const int value);
173 
174         /**
175          * @brief midiSysex
176          * @param data 0xF0 ... 0xF7
177          */
178         void midiSysex(const QByteArray &data);
179 
180         /**
181          * @brief midiSystemCommon
182          * @param status 0xF (1..6)
183          */
184         void midiSystemCommon(const int status);
185 
186         /**
187          * @brief midiSystemRealtime
188          * @param status 0xF (8..F)
189          */
190         void midiSystemRealtime(const int status);
191     };
192 
193 /** @} */
194 
195 }} // namespace drumstick::rt
196 
197 Q_DECLARE_INTERFACE(drumstick::rt::MIDIInput, "net.sourceforge.drumstick.rt.MIDIInput/2.0")
198 
199 #endif // MIDIINPUT_H
200