Init engine fields, cleanup.
[jack2.git] / common / JackPhysicalMidiInput.h
blob6ba3b471bb06ce0a0925cd19315fdcce9ef669a3
1 /*
2 Copyright (C) 2009 Devin Anderson
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef __JackPhysicalMidiInput__
21 #define __JackPhysicalMidiInput__
23 #include "JackMidiPort.h"
24 #include "ringbuffer.h"
26 namespace Jack {
28 class JackPhysicalMidiInput {
30 private:
32 size_t buffered_bytes;
33 size_t expected_data_bytes;
34 jack_ringbuffer_t *input_ring;
35 JackMidiBuffer *port_buffer;
36 jack_midi_data_t status_byte;
37 size_t unbuffered_bytes;
39 void
40 Clear();
42 void
43 WriteBufferedEvent(jack_nframes_t);
45 void
46 WriteBufferedSysexEvent(jack_nframes_t);
48 void
49 WriteByteEvent(jack_nframes_t, jack_midi_data_t);
51 protected:
53 /**
54 * Override to specify how to react when 1 or more bytes of a MIDI
55 * message are lost because there wasn't enough room in the input
56 * buffer. The first argument is the amount of bytes that couldn't be
57 * buffered, and the second argument is the total amount of bytes in
58 * the MIDI message. The default implementation calls 'jack_error'
59 * with a basic error message.
62 virtual void
63 HandleBufferFailure(size_t, size_t);
65 /**
66 * Override to specify how to react when a new status byte is received
67 * before all of the data bytes in a message are received. The
68 * argument is the number of bytes being discarded. The default
69 * implementation calls 'jack_error' with a basic error message.
72 virtual void
73 HandleIncompleteMessage(size_t);
75 /**
76 * Override to specify how to react when an invalid status byte (0xf4,
77 * 0xf5, 0xfd) is received. The argument contains the invalid status
78 * byte. The default implementation calls 'jack_error' with a basic
79 * error message.
82 virtual void
83 HandleInvalidStatusByte(jack_midi_data_t);
85 /**
86 * Override to specify how to react when a sysex end byte (0xf7) is
87 * received without first receiving a sysex start byte (0xf0). The
88 * argument contains the amount of bytes that will be discarded. The
89 * default implementation calls 'jack_error' with a basic error
90 * message.
93 virtual void
94 HandleUnexpectedSysexEnd(size_t);
96 /**
97 * Override to specify how to react when a MIDI message can not be
98 * written to the port buffer. The argument specifies the length of
99 * the MIDI message. The default implementation calls 'jack_error'
100 * with a basic error message.
103 virtual void
104 HandleWriteFailure(size_t);
107 * This method *must* be overridden to handle receiving MIDI bytes.
108 * The first argument is a pointer to the memory location at which the
109 * MIDI byte should be stored. The second argument is the last frame
110 * at which a MIDI byte was received, except at the beginning of the
111 * period when the value is 0. The third argument is the total number
112 * of frames in the period. The return value is the frame at which the
113 * MIDI byte is received at, or the value of the third argument is no
114 * more MIDI bytes can be received in this period.
117 virtual jack_nframes_t
118 Receive(jack_midi_data_t *, jack_nframes_t, jack_nframes_t) = 0;
120 public:
122 JackPhysicalMidiInput(size_t buffer_size=1024);
123 ~JackPhysicalMidiInput();
126 * Called to process MIDI data during a period.
129 void
130 Process(jack_nframes_t);
133 * Set the MIDI buffer that will receive incoming messages.
136 inline void
137 SetPortBuffer(JackMidiBuffer *port_buffer)
139 this->port_buffer = port_buffer;
146 #endif