LMMS
Loading...
Searching...
No Matches
MidiClient.h
Go to the documentation of this file.
1/*
2 * MidiClient.h - base-class for MIDI clients like ALSA-sequencer-client
3 *
4 * Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_MIDI_CLIENT_H
26#define LMMS_MIDI_CLIENT_H
27
28#include <QStringList>
29#include <vector>
30
31
32#include "MidiEvent.h"
33
34class QObject;
35
36
37namespace lmms
38{
39
40class MidiPort;
41class TimePos;
42
43
44// base-class for all MIDI-clients
46{
47public:
48 MidiClient() = default;
49 virtual ~MidiClient();
50
51 // to be implemented by sub-classes
52 virtual void processOutEvent( const MidiEvent & _me,
53 const TimePos & _time,
54 const MidiPort * _port ) = 0;
55
56 // inheriting classes can re-implement this for being able to update
57 // their internal port-structures etc.
58 virtual void applyPortMode( MidiPort * _port );
59 virtual void applyPortName( MidiPort * _port );
60
61 virtual void addPort( MidiPort * _port );
62
63 // re-implemented methods HAVE to call removePort() of base-class!!
64 virtual void removePort( MidiPort * _port );
65
66
67 // returns whether client works with raw-MIDI, only needs to be
68 // re-implemented by MidiClientRaw for returning true
69 virtual bool isRaw() const
70 {
71 return false;
72 }
73
74 // if not raw-client, return all readable/writable ports
75 virtual QStringList readablePorts() const
76 {
77 return QStringList();
78 }
79 virtual QStringList writablePorts() const
80 {
81 return QStringList();
82 }
83
84 // return name of port which specified MIDI event came from
85 virtual QString sourcePortName( const MidiEvent & ) const
86 {
87 return QString();
88 }
89
90
91 // (un)subscribe given MidiPort to/from destination-port
92 virtual void subscribeReadablePort( MidiPort * _port,
93 const QString & _dest,
94 bool _subscribe = true );
95 virtual void subscribeWritablePort( MidiPort * _port,
96 const QString & _dest,
97 bool _subscribe = true );
98
99 // qobject-derived classes can use this for make a slot being
100 // connected to signal of non-raw-MIDI-client if port-lists change
101 virtual void connectRPChanged( QObject *, const char * )
102 {
103 }
104
105 virtual void connectWPChanged( QObject *, const char * )
106 {
107 }
108
109 // tries to open either MIDI-driver from config-file or (if it fails)
110 // any other working
112
113protected:
114 std::vector<MidiPort *> m_midiPorts;
115
116} ;
117
118
119
120
122
123
125{
126public:
127 MidiClientRaw() = default;
128 ~MidiClientRaw() override = default;
129
130 // we are raw-clients for sure!
131 bool isRaw() const override
132 {
133 return true;
134 }
135
136
137protected:
138 // generic raw-MIDI-parser which generates appropriate MIDI-events
139 void parseData( const unsigned char c );
140
141 // to be implemented by actual client-implementation
142 virtual void sendByte( const unsigned char c ) = 0;
143
144
145private:
146 // this does MIDI-event-process
147 void processParsedEvent();
148 void processOutEvent( const MidiEvent& event, const TimePos& time, const MidiPort* port ) override;
149
150 // small helper function returning length of a certain event - this
151 // is necessary for parsing raw-MIDI-data
152 static int eventLength( const unsigned char event );
153
154
155 // data being used for parsing
157 {
158 uint8_t m_status; // identifies the type of event, that
159 // is currently received ('Noteon',
160 // 'Pitch Bend' etc).
161 uint8_t m_channel; // The channel of the event that is
162 // received (in case of a channel event)
163 uint32_t m_bytes; // How many bytes have been read for
164 // the current event?
165 uint32_t m_bytesTotal; // How many bytes does the current
166 // event type include?
168 // buffer for incoming data
169 MidiEvent m_midiEvent; // midi-event
171
172} ;
173
174} // namespace lmms
175
176#endif // LMMS_MIDI_CLIENT_H
std::vector< MidiPort * > m_midiPorts
Definition MidiClient.h:114
virtual void removePort(MidiPort *_port)
Definition MidiClient.cpp:69
virtual void applyPortMode(MidiPort *_port)
Definition MidiClient.cpp:47
virtual void subscribeWritablePort(MidiPort *_port, const QString &_dest, bool _subscribe=true)
Definition MidiClient.cpp:93
virtual void connectWPChanged(QObject *, const char *)
Definition MidiClient.h:105
virtual void subscribeReadablePort(MidiPort *_port, const QString &_dest, bool _subscribe=true)
Definition MidiClient.cpp:86
virtual QStringList readablePorts() const
Definition MidiClient.h:75
virtual void addPort(MidiPort *_port)
Definition MidiClient.cpp:61
virtual void processOutEvent(const MidiEvent &_me, const TimePos &_time, const MidiPort *_port)=0
MidiClient()=default
virtual QString sourcePortName(const MidiEvent &) const
Definition MidiClient.h:85
virtual QStringList writablePorts() const
Definition MidiClient.h:79
virtual bool isRaw() const
Definition MidiClient.h:69
virtual void applyPortName(MidiPort *_port)
Definition MidiClient.cpp:54
virtual void connectRPChanged(QObject *, const char *)
Definition MidiClient.h:101
virtual ~MidiClient()
Definition MidiClient.cpp:35
static MidiClient * openMidiClient()
static int eventLength(const unsigned char event)
Definition MidiClient.cpp:301
MidiClientRaw()=default
void parseData(const unsigned char c)
Definition MidiClient.cpp:103
bool isRaw() const override
Definition MidiClient.h:131
void processParsedEvent()
Definition MidiClient.cpp:239
void processOutEvent(const MidiEvent &event, const TimePos &time, const MidiPort *port) override
Definition MidiClient.cpp:250
struct lmms::MidiClientRaw::midiParserData m_midiParseData
~MidiClientRaw() override=default
virtual void sendByte(const unsigned char c)=0
Definition MidiEvent.h:37
Definition MidiPort.h:56
Definition TimePos.h:68
unsigned int uint32_t
Definition mid.cpp:100
unsigned char uint8_t
Definition mid.cpp:98
Definition AudioAlsa.cpp:35
const uint32_t RAW_MIDI_PARSE_BUF_SIZE
Definition MidiClient.h:121
Definition MidiClient.h:157
uint32_t m_bytes
Definition MidiClient.h:163
uint32_t m_buffer[RAW_MIDI_PARSE_BUF_SIZE]
Definition MidiClient.h:167
uint8_t m_channel
Definition MidiClient.h:161
uint32_t m_bytesTotal
Definition MidiClient.h:165
uint8_t m_status
Definition MidiClient.h:158
MidiEvent m_midiEvent
Definition MidiClient.h:169
return c
Definition crypt.c:175