Lines Matching +full:full +full:- +full:size
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2004-2010 Markus Grabner (line6@grabner-graz.at)
18 message_length = -1; in midibuf_message_length()
22 message_length = length[(code >> 4) - 8]; in midibuf_message_length()
24 static const int length[] = { -1, 2, 2, 2, -1, -1, 1, 1, 1, -1, in midibuf_message_length()
25 1, 1, 1, -1, 1, 1 in midibuf_message_length()
35 return (this->pos_read == this->pos_write) && !this->full; in midibuf_is_empty()
40 return this->full; in midibuf_is_full()
45 this->pos_read = this->pos_write = this->full = 0; in line6_midibuf_reset()
46 this->command_prev = -1; in line6_midibuf_reset()
49 int line6_midibuf_init(struct midi_buffer *this, int size, int split) in line6_midibuf_init() argument
51 this->buf = kmalloc(size, GFP_KERNEL); in line6_midibuf_init()
53 if (this->buf == NULL) in line6_midibuf_init()
54 return -ENOMEM; in line6_midibuf_init()
56 this->size = size; in line6_midibuf_init()
57 this->split = split; in line6_midibuf_init()
67 (this->pos_read - this->pos_write + this->size - 1) % this->size + in line6_midibuf_bytes_free()
76 (this->pos_write - this->pos_read + this->size - 1) % this->size + in line6_midibuf_bytes_used()
91 if (data[length - 1] == 0xfe) { in line6_midibuf_write()
92 --length; in line6_midibuf_write()
102 length1 = this->size - this->pos_write; in line6_midibuf_write()
106 memcpy(this->buf + this->pos_write, data, length); in line6_midibuf_write()
107 this->pos_write += length; in line6_midibuf_write()
110 length2 = length - length1; in line6_midibuf_write()
111 memcpy(this->buf + this->pos_write, data, length1); in line6_midibuf_write()
112 memcpy(this->buf, data + length1, length2); in line6_midibuf_write()
113 this->pos_write = length2; in line6_midibuf_write()
116 if (this->pos_write == this->pos_read) in line6_midibuf_write()
117 this->full = 1; in line6_midibuf_write()
135 return -EINVAL; in line6_midibuf_read()
145 length1 = this->size - this->pos_read; in line6_midibuf_read()
147 command = this->buf[this->pos_read]; in line6_midibuf_read()
157 this->buf[this->pos_read] = fixed; in line6_midibuf_read()
165 this->command_prev = command; in line6_midibuf_read()
167 if (this->command_prev > 0) { in line6_midibuf_read()
169 midibuf_message_length(this->command_prev); in line6_midibuf_read()
172 midi_length = midi_length_prev - 1; in line6_midibuf_read()
175 midi_length = -1; in line6_midibuf_read()
177 midi_length = -1; in line6_midibuf_read()
185 if (this->buf[this->pos_read + i] & 0x80) in line6_midibuf_read()
191 length2 = length - length1; in line6_midibuf_read()
194 if (this->buf[this->pos_read + i] & 0x80) in line6_midibuf_read()
201 if (this->buf[i] & 0x80) in line6_midibuf_read()
209 midi_length = -1; /* end of message not found */ in line6_midibuf_read()
213 if (!this->split) in line6_midibuf_read()
224 memcpy(data + repeat, this->buf + this->pos_read, length); in line6_midibuf_read()
225 this->pos_read += length; in line6_midibuf_read()
228 length2 = length - length1; in line6_midibuf_read()
229 memcpy(data + repeat, this->buf + this->pos_read, length1); in line6_midibuf_read()
230 memcpy(data + repeat + length1, this->buf, length2); in line6_midibuf_read()
231 this->pos_read = length2; in line6_midibuf_read()
235 data[0] = this->command_prev; in line6_midibuf_read()
237 this->full = 0; in line6_midibuf_read()
248 this->pos_read = (this->pos_read + length) % this->size; in line6_midibuf_ignore()
249 this->full = 0; in line6_midibuf_ignore()
255 kfree(this->buf); in line6_midibuf_destroy()
256 this->buf = NULL; in line6_midibuf_destroy()