Ardour  9.0-pre0-582-g084a23a80d
midi_ring_buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2015 David Robillard <d@drobilla.net>
3  * Copyright (C) 2007-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2008-2012 Hans Baier <hansfbaier@googlemail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #pragma once
22 
23 #include <iostream>
24 #include <algorithm>
25 
28 #include "ardour/types.h"
30 
31 namespace ARDOUR {
32 
33 class MidiBuffer;
34 
43 template<typename T>
44 class /*LIBARDOUR_API*/ MidiRingBuffer : public EventRingBuffer<T> {
45 public:
48 
49  inline bool read_prefix(T* time, Evoral::EventType* type, uint32_t* size);
50  inline bool read_contents(uint32_t size, uint8_t* buf);
51 
52  size_t read(MidiBuffer& dst, samplepos_t start, samplepos_t end, samplecnt_t offset=0, bool stop_on_overflow_in_destination=false);
54 
55  void dump(std::ostream& dst);
57 
58  void reset_tracker ();
61 
62 private:
64 };
65 
66 
70 template<typename T>
71 inline bool
72 MidiRingBuffer<T>::read_prefix(T* time, Evoral::EventType* type, uint32_t* size)
73 {
74  if (PBD::RingBufferNPT<uint8_t>::read((uint8_t*)time, sizeof(T)) != sizeof (T)) {
75  return false;
76  }
77 
78  if (PBD::RingBufferNPT<uint8_t>::read((uint8_t*)type, sizeof(Evoral::EventType)) != sizeof (Evoral::EventType)) {
79  return false;
80  }
81 
82  if (PBD::RingBufferNPT<uint8_t>::read((uint8_t*)size, sizeof(uint32_t)) != sizeof (uint32_t)) {
83  return false;
84  }
85 
86  return true;
87 }
88 
89 
93 template<typename T>
94 inline bool
95 MidiRingBuffer<T>::read_contents(uint32_t size, uint8_t* buf)
96 {
97  return PBD::RingBufferNPT<uint8_t>::read(buf, size) == size;
98 }
99 
100 } // namespace ARDOUR
101 
102 
MidiNoteTracker _tracker
bool read_contents(uint32_t size, uint8_t *buf)
void dump(std::ostream &dst)
void resolve_tracker(MidiBuffer &dst, samplepos_t)
void resolve_tracker(Evoral::EventSink< samplepos_t > &dst, samplepos_t)
void flush(samplepos_t start, samplepos_t end)
bool read_prefix(T *time, Evoral::EventType *type, uint32_t *size)
size_t skip_to(samplepos_t start)
size_t read(MidiBuffer &dst, samplepos_t start, samplepos_t end, samplecnt_t offset=0, bool stop_on_overflow_in_destination=false)
size_t read(T *dest, size_t cnt)
PBD::PropertyDescriptor< timepos_t > start
Temporal::samplecnt_t samplecnt_t
Temporal::samplepos_t samplepos_t