drumstick 2.10.0
C++ MIDI libraries using Qt objects, idioms, and style.
rtmidioutput.h
Go to the documentation of this file.
1/*
2 Drumstick MIDI realtime input-output
3 Copyright (C) 2009-2024 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 MIDIOUTPUT_H
20#define MIDIOUTPUT_H
21
22#include <QObject>
23#include <QString>
24#include <QStringList>
25#include <QtPlugin>
26#include <QSettings>
27#include "macros.h"
28
34#if defined(DRUMSTICK_STATIC)
35#define DRUMSTICK_RT_EXPORT
36#else
37#if defined(drumstick_rt_EXPORTS)
38#define DRUMSTICK_RT_EXPORT Q_DECL_EXPORT
39#else
40#define DRUMSTICK_RT_EXPORT Q_DECL_IMPORT
41#endif
42#endif
43
44namespace drumstick { namespace rt {
45
51const quint8 MIDI_STD_CHANNELS = 16;
52const quint8 MIDI_GM_STD_DRUM_CHANNEL = (10-1);
53const quint8 MIDI_CONTROL_MSB_BANK_SELECT = 0x00;
54const quint8 MIDI_CONTROL_MSB_MAIN_VOLUME = 0x07;
55const quint8 MIDI_CONTROL_LSB_BANK_SELECT = 0x20;
56const quint8 MIDI_CONTROL_REVERB_SEND = 0x5b;
57const quint8 MIDI_CONTROL_ALL_SOUNDS_OFF = 0x78;
58const quint8 MIDI_CONTROL_ALL_NOTES_OFF = 0x7b;
59const quint8 MIDI_CONTROL_RESET_CONTROLLERS = 0x79;
60
61const quint8 MIDI_STATUS_NOTEOFF = 0x80;
62const quint8 MIDI_STATUS_NOTEON = 0x90;
63const quint8 MIDI_STATUS_KEYPRESURE = 0xa0;
64const quint8 MIDI_STATUS_CONTROLCHANGE = 0xb0;
65const quint8 MIDI_STATUS_PROGRAMCHANGE = 0xc0;
66const quint8 MIDI_STATUS_CHANNELPRESSURE = 0xd0;
67const quint8 MIDI_STATUS_PITCHBEND = 0xe0;
68const quint8 MIDI_STATUS_SYSEX = 0xf0;
69const quint8 MIDI_STATUS_ENDSYSEX = 0xf7;
70const quint8 MIDI_STATUS_REALTIME = 0xf8;
71
72const quint8 MIDI_STATUS_MASK = 0xf0;
73const quint8 MIDI_CHANNEL_MASK = 0x0f;
74
75const quint8 MIDI_COMMON_QTRFRAME = 0xF1;
76const quint8 MIDI_COMMON_SONGPP = 0xF2;
77const quint8 MIDI_COMMON_SONGSELECT = 0xF3;
78const quint8 MIDI_COMMON_TUNEREQ = 0xF6;
79
80const quint8 MIDI_REALTIME_CLOCK = 0xF8;
81const quint8 MIDI_REALTIME_START = 0xFA;
82const quint8 MIDI_REALTIME_CONTINUE = 0xFB;
83const quint8 MIDI_REALTIME_STOP = 0xFC;
84const quint8 MIDI_REALTIME_SENSING = 0xFE;
85const quint8 MIDI_REALTIME_RESET = 0xFF;
86
92inline int MIDI_LSB(int x)
93{
94 return (x % 0x80);
95}
96
102inline int MIDI_MSB(int x)
103{
104 return (x / 0x80);
105}
106
116 typedef QPair<QString,QVariant> MIDIConnection;
117
121 class DRUMSTICK_RT_EXPORT MIDIOutput : public QObject
122 {
123 Q_OBJECT
124
125 public:
130 explicit MIDIOutput(QObject *parent = nullptr) : QObject(parent) {}
134 virtual ~MIDIOutput() = default;
139 virtual void initialize(QSettings* settings) = 0;
144 virtual QString backendName() = 0;
149 virtual QString publicName() = 0;
154 virtual void setPublicName(QString name) = 0;
160 virtual QList<MIDIConnection> connections(bool advanced = false) = 0;
165 virtual void setExcludedConnections(QStringList conns) = 0;
170 virtual void open(const MIDIConnection& conn) = 0;
174 virtual void close() = 0;
180
181 public Q_SLOTS:
188 virtual void sendNoteOff(int chan, int note, int vel) = 0;
189
196 virtual void sendNoteOn(int chan, int note, int vel) = 0;
197
204 virtual void sendKeyPressure(int chan, int note, int value) = 0;
205
212 virtual void sendController(int chan, int control, int value) = 0;
213
219 virtual void sendProgram(int chan, int program) = 0;
220
226 virtual void sendChannelPressure(int chan, int value) = 0;
227
233 virtual void sendPitchBend(int chan, int value) = 0;
234
239 virtual void sendSysex(const QByteArray& data) = 0;
240
245 virtual void sendSystemMsg(const int status) = 0;
246 };
247
250}} // namespace drumstick::rt
251
252Q_DECLARE_INTERFACE(drumstick::rt::MIDIOutput, "net.sourceforge.drumstick.rt.MIDIOutput/2.0")
253Q_DECLARE_METATYPE(drumstick::rt::MIDIConnection)
254
255#endif /* MIDIOUTPUT_H */
The QObject class is the base class of all Qt objects.
The QSettings class provides persistent platform-independent application settings.
MIDI OUT interface.
Definition: rtmidioutput.h:122
virtual ~MIDIOutput()=default
~MIDIOutput destructor
virtual void setExcludedConnections(QStringList conns)=0
setExcludedConnections
MIDIOutput(QObject *parent=nullptr)
MIDIOutput constructor.
Definition: rtmidioutput.h:130
virtual void initialize(QSettings *settings)=0
initialize
virtual QString backendName()=0
backendName
virtual MIDIConnection currentConnection()=0
currentConnection
virtual void sendPitchBend(int chan, int value)=0
sendPitchBend 0xE
virtual void sendNoteOn(int chan, int note, int vel)=0
sendNoteOn 0x9
virtual void sendChannelPressure(int chan, int value)=0
sendChannelPressure 0xD
virtual void sendKeyPressure(int chan, int note, int value)=0
sendKeyPressure 0xA
virtual QList< MIDIConnection > connections(bool advanced=false)=0
connections
virtual QString publicName()=0
publicName
virtual void sendController(int chan, int control, int value)=0
sendController 0xB
virtual void open(const MIDIConnection &conn)=0
open the MIDI port by name
virtual void sendProgram(int chan, int program)=0
sendProgram 0xC
virtual void sendNoteOff(int chan, int note, int vel)=0
sendNoteOff 0x8
virtual void close()=0
close the MIDI port
virtual void sendSystemMsg(const int status)=0
sendSystemMsg
virtual void sendSysex(const QByteArray &data)=0
sendSysex
virtual void setPublicName(QString name)=0
setPublicName
const quint8 MIDI_STATUS_CONTROLCHANGE
MIDI status byte for CONTROL change messages.
Definition: rtmidioutput.h:64
int MIDI_LSB(int x)
MIDI_LSB is a function to extract the least significative byte of a MIDI value.
Definition: rtmidioutput.h:92
const quint8 MIDI_COMMON_SONGPP
MIDI Song Position status message.
Definition: rtmidioutput.h:76
const quint8 MIDI_GM_STD_DRUM_CHANNEL
Number of the GM percussion channel.
Definition: rtmidioutput.h:52
const quint8 MIDI_COMMON_SONGSELECT
MIDI Song Select status message.
Definition: rtmidioutput.h:77
const quint8 MIDI_CONTROL_ALL_SOUNDS_OFF
MIDI Controller number for All sounds off.
Definition: rtmidioutput.h:57
const quint8 MIDI_REALTIME_CONTINUE
MIDI Continue status message.
Definition: rtmidioutput.h:82
QPair< QString, QVariant > MIDIConnection
MIDIConnection represents a connection identifier.
Definition: rtmidioutput.h:116
const quint8 MIDI_REALTIME_RESET
MIDI Reset status message.
Definition: rtmidioutput.h:85
const quint8 MIDI_STATUS_PROGRAMCHANGE
MIDI status byte for PROGRAM change messages.
Definition: rtmidioutput.h:65
const quint8 MIDI_STATUS_SYSEX
MIDI status byte for System Exclusive START messages.
Definition: rtmidioutput.h:68
const quint8 MIDI_STATUS_KEYPRESURE
MIDI status byte for KEY pressure messages.
Definition: rtmidioutput.h:63
const quint8 MIDI_STATUS_NOTEON
MIDI status byte for NOTE ON messages.
Definition: rtmidioutput.h:62
const quint8 MIDI_STD_CHANNELS
Standard number of MIDI channels.
Definition: rtmidioutput.h:51
const quint8 MIDI_CONTROL_LSB_BANK_SELECT
MIDI Controller number for LSB Bank number.
Definition: rtmidioutput.h:55
const quint8 MIDI_REALTIME_CLOCK
MIDI Clock status message.
Definition: rtmidioutput.h:80
int MIDI_MSB(int x)
MIDI_MSB is a function to extract the most significative byte of a MIDI value.
Definition: rtmidioutput.h:102
const quint8 MIDI_CONTROL_MSB_MAIN_VOLUME
MIDI Controller number for MSB volume.
Definition: rtmidioutput.h:54
const quint8 MIDI_STATUS_NOTEOFF
MIDI status byte for NOTE OFF messages.
Definition: rtmidioutput.h:61
const quint8 MIDI_COMMON_TUNEREQ
MIDI Tune Request status message.
Definition: rtmidioutput.h:78
const quint8 MIDI_CONTROL_RESET_CONTROLLERS
MIDI Controller number for Reset all controllers.
Definition: rtmidioutput.h:59
const quint8 MIDI_COMMON_QTRFRAME
MIDI Quarter frame status message.
Definition: rtmidioutput.h:75
const quint8 MIDI_STATUS_CHANNELPRESSURE
MIDI status byte for CHANNEL PRESSURE messages.
Definition: rtmidioutput.h:66
const quint8 MIDI_CONTROL_REVERB_SEND
MIDI Controller number for Reverb send.
Definition: rtmidioutput.h:56
const quint8 MIDI_STATUS_REALTIME
Minimum value for MIDI Realtime messages status.
Definition: rtmidioutput.h:70
const quint8 MIDI_CHANNEL_MASK
Mask to extract the MIDI channel byte from a MIDI message.
Definition: rtmidioutput.h:73
const quint8 MIDI_STATUS_PITCHBEND
MIDI status byte for PITCH bend messages.
Definition: rtmidioutput.h:67
const quint8 MIDI_CONTROL_ALL_NOTES_OFF
MIDI Controller number for All notes off.
Definition: rtmidioutput.h:58
const quint8 MIDI_CONTROL_MSB_BANK_SELECT
MIDI Controller number for MSB Bank number.
Definition: rtmidioutput.h:53
const quint8 MIDI_REALTIME_STOP
MIDI Stop status message.
Definition: rtmidioutput.h:83
const quint8 MIDI_REALTIME_SENSING
MIDI Active Sensing status message.
Definition: rtmidioutput.h:84
const quint8 MIDI_STATUS_ENDSYSEX
MIDI status byte for System Exclusive END messages.
Definition: rtmidioutput.h:69
const quint8 MIDI_STATUS_MASK
Mask to extract the MIDI status byte from a MIDI message.
Definition: rtmidioutput.h:72
const quint8 MIDI_REALTIME_START
MIDI Start status message.
Definition: rtmidioutput.h:81
Drumstick common.
Definition: alsaclient.cpp:71