1 2 module jack.midiport; 3 public import jack.port; 4 public import jack.types; 5 import jack.c.jack; 6 import jack.c.midiport; 7 8 JackMidiPortBuffer get_midi_buffer(JackPort port, jack_nframes_t nframes) 9 { 10 JackMidiPortBuffer buf; 11 buf.ptr_ = jack_port_get_buffer(port.handle, nframes); 12 return buf; 13 } 14 15 alias JackMidiEvent = jack_midi_event_t; 16 17 struct JackMidiPortBuffer { 18 void *ptr_ = null; 19 20 public: 21 22 uint32_t get_event_count() 23 { 24 return jack_midi_get_event_count(ptr_); 25 } 26 27 bool get_event(jack_midi_event_t *event, uint32_t event_index) 28 { 29 int ret = jack_midi_event_get(event, ptr_, event_index); 30 return ret == 0; 31 } 32 33 void clear() 34 { 35 jack_midi_clear_buffer(ptr_); 36 } 37 38 size_t max_event_size() 39 { 40 return jack_midi_max_event_size(ptr_); 41 } 42 43 jack_midi_data_t *reserve_event(jack_nframes_t time, size_t data_size) 44 { 45 return jack_midi_event_reserve(ptr_, time, data_size); 46 } 47 48 bool write_event(jack_nframes_t time, const(jack_midi_data_t) *data, size_t data_size) 49 { 50 int ret = jack_midi_event_write(ptr_, time, data, data_size); 51 return ret == 0; 52 } 53 54 uint32_t get_lost_event_count() 55 { 56 return jack_midi_get_lost_event_count(ptr_); 57 } 58 59 JackMidiPortBufferRange iter_events() 60 { 61 JackMidiPortBufferRange range; 62 range.ptr_ = ptr_; 63 range.index_ = 0; 64 range.count_ = get_event_count(); 65 return range; 66 } 67 68 }; 69 70 struct JackMidiPortBufferRange { 71 void *ptr_; 72 uint32_t index_; 73 uint32_t count_; 74 75 public: 76 77 bool empty() { 78 return index_ == count_; 79 } 80 81 JackMidiEvent front() { 82 JackMidiEvent ev; 83 int ret = jack_midi_event_get(&ev, ptr_, index_); 84 assert(ret == 0); 85 return ev; 86 } 87 88 void popFront() { 89 ++index_; 90 } 91 92 };