change MidiPlaylist::dump() into ::render(); change type of initial argument
[ardour.git] / libs / ardour / ardour / rt_midibuffer.h
1 /*
2  * Copyright (C) 2007-2016 David Robillard <d@drobilla.net>
3  * Copyright (C) 2007-2018 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2009 Hans Baier <hansfbaier@googlemail.com>
6  * Copyright (C) 2014-2016 Robin Gareus <robin@gareus.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #ifndef __ardour_rt_midi_buffer_h__
24 #define __ardour_rt_midi_buffer_h__
25
26 #include <map>
27
28 #include <glibmm/threads.h>
29
30 #include "evoral/Event.hpp"
31 #include "evoral/EventSink.hpp"
32 #include "ardour/types.h"
33
34 namespace ARDOUR {
35
36 class MidiBuffer;
37 class MidiStateTracker;
38
39 /**  */
40 class LIBARDOUR_API RTMidiBuffer : public Evoral::EventSink<samplepos_t>
41 {
42   public:
43         typedef samplepos_t TimeType;
44
45         RTMidiBuffer (size_t capacity);
46         ~RTMidiBuffer();
47
48         void clear();
49         void resize(size_t);
50         size_t size() const { return _size; }
51
52         uint32_t write (TimeType time, Evoral::EventType type, uint32_t size, const uint8_t* buf);
53         uint32_t read (MidiBuffer& dst, samplepos_t start, samplepos_t end, MidiStateTracker& tracker, samplecnt_t offset = 0);
54
55         void dump (uint32_t);
56
57         struct Item {
58                 samplepos_t timestamp;
59                 union {
60                         uint8_t  bytes[4];
61                         uint32_t offset;
62                 };
63         };
64
65   private:
66
67         struct Blob {
68                 uint32_t size;
69                 uint8_t data[0];
70         };
71
72         /* The main store. Holds Items (timestamp+up to 3 bytes of data OR
73          * offset into secondary storage below)
74          */
75
76         size_t _size;
77         size_t _capacity;
78         Item*  _data;
79
80         /* secondary blob storage. Holds Blobs (arbitrary size + data) */
81
82         uint32_t alloc_blob (uint32_t size);
83         uint32_t store_blob (uint32_t size, uint8_t const * data);
84         uint32_t _pool_size;
85         uint32_t _pool_capacity;
86         uint8_t* _pool;
87
88         mutable Glib::Threads::RWLock _lock;
89 };
90
91 } // namespace ARDOUR
92
93 #endif // __ardour_rt_midi_buffer_h__