Ardour  9.0-pre0-582-g084a23a80d
raw_midi_parser.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
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 General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef _ardour_raw_midi_parser_h_
20 #define _ardour_raw_midi_parser_h_
21 
23 #include "ardour/types.h"
24 
25 namespace ARDOUR {
26 
28 {
29 public:
31 
32  void reset () {
33  _event_size = 0;
34  _unbuffered_bytes = 0;
35  _total_bytes = 0;
36  _expected_bytes = 0;
37  _status_byte = 0;
38  }
39 
40  uint8_t const * midi_buffer () const { return _parser_buffer; }
41  size_t buffer_size () const { return _event_size; }
42 
46  bool process_byte (const uint8_t byte);
47 
48 private:
49 
50  void record_byte (uint8_t byte) {
51  if (_total_bytes < sizeof (_parser_buffer)) {
52  _parser_buffer[_total_bytes] = byte;
53  } else {
54  ++_unbuffered_bytes;
55  }
56  ++_total_bytes;
57  }
58 
59  void prepare_byte_event (const uint8_t byte) {
60  _parser_buffer[0] = byte;
61  _event_size = 1;
62  }
63 
65  const bool result = _unbuffered_bytes == 0;
66  if (result) {
67  _event_size = _total_bytes;
68  }
69  _total_bytes = 0;
70  _unbuffered_bytes = 0;
71  if (_status_byte >= 0xf0) {
72  _expected_bytes = 0;
73  _status_byte = 0;
74  }
75  return result;
76  }
77 
78  size_t _event_size;
80  size_t _total_bytes;
82  uint8_t _status_byte;
83  uint8_t _parser_buffer[1024];
84 };
85 
86 } // namespace ARDOUR
87 
88 #endif /* _ardour_raw_midi_parser_h_ */
size_t buffer_size() const
void record_byte(uint8_t byte)
void prepare_byte_event(const uint8_t byte)
bool process_byte(const uint8_t byte)
uint8_t const * midi_buffer() const
#define LIBARDOUR_API