hydrogen 1.2.6
JackMidiDriver.h
Go to the documentation of this file.
1/*-
2 * Copyright (c) 2011 Hans Petter Selasky <hselasky@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#ifndef JACK_MIDI_DRIVER_H
28#define JACK_MIDI_DRIVER_H
29
30#include <core/IO/MidiInput.h>
31#include <core/IO/MidiOutput.h>
32
33#if defined(H2CORE_HAVE_JACK) || _DOXYGEN_
34
35#include <pthread.h>
36
37#include <jack/jack.h>
38#include <jack/midiport.h>
39#include <jack/ringbuffer.h>
40
41#include <string>
42#include <vector>
43
44#define JACK_MIDI_BUFFER_MAX 64 /* events */
45
46namespace H2Core
47{
48
50class JackMidiDriver : public Object<JackMidiDriver>, public virtual MidiInput, public virtual MidiOutput
51{
53public:
55 virtual ~JackMidiDriver();
56
57 virtual void open() override;
58 virtual void close() override;
59 virtual std::vector<QString> getInputPortList() override;
60 virtual std::vector<QString> getOutputPortList() override;
61
62 void getPortInfo( const QString& sPortName, int& nClient, int& nPort );
63 void JackMidiWrite(jack_nframes_t nframes);
64 void JackMidiRead(jack_nframes_t nframes);
65
66 virtual void handleQueueNote(Note* pNote) override;
67 virtual void handleQueueNoteOff( int channel, int key, int velocity ) override;
68 virtual void handleQueueAllNoteOff() override;
69 virtual void handleOutgoingControlChange( int param, int value, int channel ) override;
70
71private:
72 void JackMidiOutEvent(uint8_t *buf, uint8_t len);
73
74 void lock();
75 void unlock();
76
77 jack_port_t *output_port;
78 jack_port_t *input_port;
79 jack_client_t *jack_client;
80 pthread_mutex_t mtx;
83 uint32_t rx_in_pos;
84 uint32_t rx_out_pos;
85};
86
87};
88
89#endif /* H2CORE_HAVE_JACK */
90
91#endif
#define JACK_MIDI_BUFFER_MAX
#define H2_OBJECT(name)
Definition Object.h:227
void JackMidiOutEvent(uint8_t *buf, uint8_t len)
jack_port_t * output_port
void getPortInfo(const QString &sPortName, int &nClient, int &nPort)
virtual void open() override
void JackMidiWrite(jack_nframes_t nframes)
void JackMidiRead(jack_nframes_t nframes)
uint8_t jack_buffer[JACK_MIDI_BUFFER_MAX *4]
virtual std::vector< QString > getInputPortList() override
virtual void close() override
virtual void handleQueueNoteOff(int channel, int key, int velocity) override
virtual std::vector< QString > getOutputPortList() override
virtual void handleQueueAllNoteOff() override
virtual void handleOutgoingControlChange(int param, int value, int channel) override
jack_client_t * jack_client
virtual void handleQueueNote(Note *pNote) override
A note plays an associated instrument with a velocity left and right pan.
Definition Note.h:101