@@ -115,7 +115,7 @@ MidiBuffer::read_from (const Buffer& src, samplecnt_t nframes, sampleoffset_t ds
115
115
const Evoral::Event<TimeType> ev (*i, false );
116
116
117
117
if (ev.time () >= 0 && ev.time () < nframes) {
118
- push_back (ev.time (), ev.size (), ev.buffer ());
118
+ push_back (ev.time (), ev.size (), ev.buffer (), ev. event_type () );
119
119
} else {
120
120
cerr << " \t !!!! MIDI event @ " << ev.time () << " skipped, not within range 0 .. " << nframes << endl;
121
121
PBD::stacktrace (cerr, 30 );
@@ -146,7 +146,7 @@ MidiBuffer::merge_from (const Buffer& src, samplecnt_t /*nframes*/, sampleoffset
146
146
bool
147
147
MidiBuffer::push_back (const Evoral::Event<TimeType>& ev)
148
148
{
149
- return push_back (ev.time (), ev.size (), ev.buffer ());
149
+ return push_back (ev.time (), ev.size (), ev.buffer (), ev. event_type () );
150
150
}
151
151
152
152
@@ -158,9 +158,10 @@ MidiBuffer::push_back(const Evoral::Event<TimeType>& ev)
158
158
* @return false if operation failed (not enough room)
159
159
*/
160
160
bool
161
- MidiBuffer::push_back (TimeType time, size_t size, const uint8_t * data)
161
+ MidiBuffer::push_back (TimeType time, size_t size, const uint8_t * data, Evoral::EventType event_type )
162
162
{
163
163
const size_t stamp_size = sizeof (TimeType);
164
+ const size_t etype_size = sizeof (Evoral::EventType);
164
165
165
166
#ifndef NDEBUG
166
167
if (DEBUG_ENABLED (DEBUG::MidiIO)) {
@@ -177,7 +178,7 @@ MidiBuffer::push_back(TimeType time, size_t size, const uint8_t* data)
177
178
}
178
179
#endif
179
180
180
- if (_size + stamp_size + size >= _capacity) {
181
+ if (_size + stamp_size + etype_size + size >= _capacity) {
181
182
return false ;
182
183
}
183
184
@@ -187,9 +188,10 @@ MidiBuffer::push_back(TimeType time, size_t size, const uint8_t* data)
187
188
188
189
uint8_t * const write_loc = _data + _size;
189
190
*(reinterpret_cast <TimeType*>((uintptr_t )write_loc)) = time;
190
- memcpy (write_loc + stamp_size, data, size);
191
+ *(reinterpret_cast <Evoral::EventType*>((uintptr_t )(write_loc + stamp_size))) = event_type;
192
+ memcpy (write_loc + stamp_size + etype_size, data, size);
191
193
192
- _size += stamp_size + size;
194
+ _size += stamp_size + etype_size + size;
193
195
_silent = false ;
194
196
195
197
return true ;
@@ -205,7 +207,9 @@ MidiBuffer::insert_event(const Evoral::Event<TimeType>& ev)
205
207
}
206
208
207
209
const size_t stamp_size = sizeof (TimeType);
208
- const size_t bytes_to_merge = stamp_size + ev.size ();
210
+ const size_t etype_size = sizeof (Evoral::EventType);
211
+
212
+ const size_t bytes_to_merge = stamp_size + etype_size + ev.size ();
209
213
210
214
if (_size + bytes_to_merge >= _capacity) {
211
215
cerr << string_compose (" MidiBuffer::push_back failed (buffer is full: size: %1 capacity %2 new bytes %3)" , _size, _capacity, bytes_to_merge) << endl;
@@ -243,7 +247,8 @@ MidiBuffer::insert_event(const Evoral::Event<TimeType>& ev)
243
247
244
248
uint8_t * const write_loc = _data + insert_offset;
245
249
*(reinterpret_cast <TimeType*>((uintptr_t )write_loc)) = t;
246
- memcpy (write_loc + stamp_size, ev.buffer (), ev.size ());
250
+ *(reinterpret_cast <Evoral::EventType*>((uintptr_t )(write_loc + stamp_size))) = ev.event_type ();
251
+ memcpy (write_loc + stamp_size + etype_size, ev.buffer (), ev.size ());
247
252
248
253
_size += bytes_to_merge;
249
254
@@ -265,21 +270,23 @@ MidiBuffer::write(TimeType time, Evoral::EventType type, uint32_t size, const ui
265
270
* location, or the buffer will be corrupted and very nasty things will happen.
266
271
*/
267
272
uint8_t *
268
- MidiBuffer::reserve (TimeType time, size_t size)
273
+ MidiBuffer::reserve (TimeType time, Evoral::EventType event_type, size_t size)
269
274
{
270
275
const size_t stamp_size = sizeof (TimeType);
271
- if (_size + stamp_size + size >= _capacity) {
276
+ const size_t etype_size = sizeof (Evoral::EventType);
277
+ if (_size + stamp_size + etype_size + size >= _capacity) {
272
278
return 0 ;
273
279
}
274
280
275
- // write timestamp
281
+ // write timestamp and event-type
276
282
uint8_t * write_loc = _data + _size;
277
283
*(reinterpret_cast <TimeType*>((uintptr_t )write_loc)) = time;
284
+ *(reinterpret_cast <Evoral::EventType*>((uintptr_t )(write_loc + stamp_size))) = event_type;
278
285
279
286
// move write_loc to begin of MIDI buffer data to write to
280
- write_loc += stamp_size;
287
+ write_loc += stamp_size + etype_size ;
281
288
282
- _size += stamp_size + size;
289
+ _size += stamp_size + etype_size + size;
283
290
_silent = false ;
284
291
285
292
return write_loc;
@@ -422,6 +429,8 @@ MidiBuffer::second_simultaneous_midi_byte_is_first (uint8_t a, uint8_t b)
422
429
bool
423
430
MidiBuffer::merge_in_place (const MidiBuffer &other)
424
431
{
432
+ const size_t header_size = sizeof (TimeType) + sizeof (Evoral::EventType);
433
+
425
434
if (other.size () && size ()) {
426
435
DEBUG_TRACE (DEBUG::MidiIO, string_compose (" merge in place, sizes %1/%2\n " , size (), other.size ()));
427
436
}
@@ -458,7 +467,7 @@ MidiBuffer::merge_in_place (const MidiBuffer &other)
458
467
if (merge_offset == -1 ) {
459
468
merge_offset = them.offset ;
460
469
}
461
- bytes_to_merge += sizeof (TimeType) + (*them).size ();
470
+ bytes_to_merge += header_size + (*them).size ();
462
471
++them;
463
472
}
464
473
@@ -505,11 +514,11 @@ MidiBuffer::merge_in_place (const MidiBuffer &other)
505
514
DEBUG_TRACE (DEBUG::MidiIO,
506
515
string_compose (" simultaneous MIDI events discovered during merge, times %1/%2 status %3/%4\n " ,
507
516
(*us).time (), (*them).time (),
508
- (int ) *(_data + us.offset + sizeof (TimeType) ),
509
- (int ) *(other._data + them.offset + sizeof (TimeType) )));
517
+ (int ) *(_data + us.offset + header_size ),
518
+ (int ) *(other._data + them.offset + header_size )));
510
519
511
- uint8_t our_midi_status_byte = *(_data + us.offset + sizeof (TimeType) );
512
- uint8_t their_midi_status_byte = *(other._data + them.offset + sizeof (TimeType) );
520
+ uint8_t our_midi_status_byte = *(_data + us.offset + header_size );
521
+ uint8_t their_midi_status_byte = *(other._data + them.offset + header_size );
513
522
bool them_first = second_simultaneous_midi_byte_is_first (our_midi_status_byte, their_midi_status_byte);
514
523
515
524
DEBUG_TRACE (DEBUG::MidiIO, string_compose (" other message came first ? %1\n " , them_first));
@@ -519,7 +528,7 @@ MidiBuffer::merge_in_place (const MidiBuffer &other)
519
528
++us;
520
529
}
521
530
522
- bytes_to_merge = sizeof (TimeType) + (*them).size ();
531
+ bytes_to_merge = header_size + (*them).size ();
523
532
524
533
/* move our remaining events later in the buffer by
525
534
* enough to fit the one message we're going to merge
0 commit comments