Ardour  8.12
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 #ifndef __ardour_midi_ring_buffer_h__
22 #define __ardour_midi_ring_buffer_h__
23 
24 #include <iostream>
25 #include <algorithm>
26 
29 #include "ardour/types.h"
31 
32 namespace ARDOUR {
33 
34 class MidiBuffer;
35 
44 template<typename T>
45 class /*LIBARDOUR_API*/ MidiRingBuffer : public EventRingBuffer<T> {
46 public:
49 
50  inline bool read_prefix(T* time, Evoral::EventType* type, uint32_t* size);
51  inline bool read_contents(uint32_t size, uint8_t* buf);
52 
53  size_t read(MidiBuffer& dst, samplepos_t start, samplepos_t end, samplecnt_t offset=0, bool stop_on_overflow_in_destination=false);
55 
56  void dump(std::ostream& dst);
58 
59  void reset_tracker ();
62 
63 private:
65 };
66 
67 
71 template<typename T>
72 inline bool
73 MidiRingBuffer<T>::read_prefix(T* time, Evoral::EventType* type, uint32_t* size)
74 {
75  if (PBD::RingBufferNPT<uint8_t>::read((uint8_t*)time, sizeof(T)) != sizeof (T)) {
76  return false;
77  }
78 
79  if (PBD::RingBufferNPT<uint8_t>::read((uint8_t*)type, sizeof(Evoral::EventType)) != sizeof (Evoral::EventType)) {
80  return false;
81  }
82 
83  if (PBD::RingBufferNPT<uint8_t>::read((uint8_t*)size, sizeof(uint32_t)) != sizeof (uint32_t)) {
84  return false;
85  }
86 
87  return true;
88 }
89 
90 
94 template<typename T>
95 inline bool
96 MidiRingBuffer<T>::read_contents(uint32_t size, uint8_t* buf)
97 {
98  return PBD::RingBufferNPT<uint8_t>::read(buf, size) == size;
99 }
100 
101 } // namespace ARDOUR
102 
103 #endif // __ardour_midi_ring_buffer_h__
104 
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