21 #include <QStringList>
23 #include <QMutexLocker>
28 #include "alsamidioutput.h"
33 static QString DEFAULT_PUBLIC_NAME(QLatin1String(
"MIDI Out"));
35 class ALSAMIDIOutput::ALSAMIDIOutputPrivate {
37 ALSAMIDIOutput *m_out;
44 QString m_currentOutput;
45 QStringList m_outputDevices;
46 QStringList m_excludedNames;
49 ALSAMIDIOutputPrivate(ALSAMIDIOutput *q):
56 m_publicName(DEFAULT_PUBLIC_NAME)
58 m_runtimeAlsaNum = getRuntimeALSALibraryNumber();
59 m_client =
new MidiClient(m_out);
61 m_client->setClientName(m_publicName);
62 m_port = m_client->createPort();
63 m_port->setPortName(
"out");
64 m_port->setCapability( SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ );
65 m_port->setPortType( SND_SEQ_PORT_TYPE_APPLICATION | SND_SEQ_PORT_TYPE_MIDI_GENERIC );
66 m_portId = m_port->getPortId();
69 ~ALSAMIDIOutputPrivate()
71 if (m_client != NULL) {
80 bool clientIsAdvanced(
int clientId)
83 if (m_runtimeAlsaNum < 0x01000B)
85 return (clientId < 64);
88 return (clientId < 16);
91 void reloadDeviceList(
bool advanced)
93 m_clientFilter = !advanced;
94 m_outputDevices.clear();
95 QListIterator<PortInfo> it(m_client->getAvailableOutputs());
97 bool excluded =
false;
98 PortInfo p = it.next();
99 QString name = QString(
"%1:%2").arg(p.getClientName()).arg(p.getPort());
100 if (m_clientFilter && clientIsAdvanced(p.getClient()))
102 if ( m_clientFilter && name.startsWith(QLatin1String(
"Virtual Raw MIDI")) )
104 if ( name.startsWith(m_publicName) )
106 foreach(
const QString& n, m_excludedNames) {
107 if ( name.startsWith(n) ) {
113 m_outputDevices << name;
115 if (!m_currentOutput.isEmpty() &&
116 !m_outputDevices.contains(m_currentOutput)) {
117 m_currentOutput.clear();
121 bool setSubscription(
const QString &newOutputDevice)
124 if (m_outputDevices.contains(newOutputDevice)) {
125 m_currentOutput = newOutputDevice;
126 m_port->unsubscribeAll();
127 m_port->subscribeTo(newOutputDevice);
133 void clearSubscription()
135 if (!m_currentOutput.isEmpty()) {
136 m_port->unsubscribeAll();
137 m_currentOutput.clear();
141 void sendEvent(SequencerEvent *ev)
143 QMutexLocker locker(&m_outMutex);
144 ev->setSource(m_portId);
145 ev->setSubscribers();
147 m_client->outputDirect(ev);
150 void setPublicName(QString newName)
152 if (newName != m_publicName) {
153 m_client->setClientName(newName);
154 m_publicName = newName;
160 ALSAMIDIOutput::ALSAMIDIOutput(
QObject *parent) : MIDIOutput(parent),
161 d(new ALSAMIDIOutputPrivate(this))
164 ALSAMIDIOutput::~ALSAMIDIOutput()
169 void ALSAMIDIOutput::initialize(QSettings* settings)
176 void ALSAMIDIOutput::sendNoteOn(
int chan,
int note,
int vel)
178 NoteOnEvent ev(chan, note, vel);
182 void ALSAMIDIOutput::sendNoteOff(
int chan,
int note,
int vel)
184 NoteOffEvent ev(chan, note, vel);
188 void ALSAMIDIOutput::sendController(
int chan,
int control,
int value)
190 ControllerEvent ev(chan, control, value);
194 void ALSAMIDIOutput::sendKeyPressure(
int chan,
int note,
int value)
196 KeyPressEvent ev(chan, note, value);
200 void ALSAMIDIOutput::sendProgram(
int chan,
int program)
202 ProgramChangeEvent ev(chan, program);
206 void ALSAMIDIOutput::sendChannelPressure(
int chan,
int value)
208 ChanPressEvent ev(chan, value);
212 void ALSAMIDIOutput::sendPitchBend(
int chan,
int value)
214 PitchBendEvent ev(chan, value);
218 void ALSAMIDIOutput::sendSysex(
const QByteArray& data)
224 void ALSAMIDIOutput::sendSystemMsg(
const int status)
226 SystemEvent ev(status);
230 QString ALSAMIDIOutput::backendName()
235 QString ALSAMIDIOutput::publicName()
237 return d->m_publicName;
240 void ALSAMIDIOutput::setPublicName(QString name)
242 d->setPublicName(name);
245 QStringList ALSAMIDIOutput::connections(
bool advanced)
247 d->reloadDeviceList(advanced);
248 return d->m_outputDevices;
251 void ALSAMIDIOutput::setExcludedConnections(QStringList conns)
253 d->m_excludedNames = conns;
256 QString ALSAMIDIOutput::currentConnection()
258 return d->m_currentOutput;
261 void ALSAMIDIOutput::open(QString name)
263 d->setSubscription(name);
266 void ALSAMIDIOutput::close()
268 d->clearSubscription();
Classes managing ALSA Sequencer clients.
The QObject class is the base class of all Qt objects.
Classes managing ALSA Sequencer ports.
Classes managing ALSA Sequencer events.