Lines Matching +full:full +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
17 message_length = -1; in midibuf_message_length()
21 message_length = length[(code >> 4) - 8]; in midibuf_message_length()
28 static const int length[] = { -1, 2, -1, 2, -1, -1, 1, 1, 1, 1, in midibuf_message_length()
29 1, 1, 1, -1, 1, 1 in midibuf_message_length()
39 return (this->pos_read == this->pos_write) && !this->full; in midibuf_is_empty()
44 return this->full; in midibuf_is_full()
49 this->pos_read = this->pos_write = this->full = 0; in line6_midibuf_reset()
50 this->command_prev = -1; in line6_midibuf_reset()
53 int line6_midibuf_init(struct midi_buffer *this, int size, int split) in line6_midibuf_init() argument
55 this->buf = kmalloc(size, GFP_KERNEL); in line6_midibuf_init()
57 if (this->buf == NULL) in line6_midibuf_init()
58 return -ENOMEM; in line6_midibuf_init()
60 this->size = size; in line6_midibuf_init()
61 this->split = split; in line6_midibuf_init()
71 (this->pos_read - this->pos_write + this->size - 1) % this->size + in line6_midibuf_bytes_free()
80 (this->pos_write - this->pos_read + this->size - 1) % this->size + in line6_midibuf_bytes_used()
95 if (data[length - 1] == 0xfe) { in line6_midibuf_write()
96 --length; in line6_midibuf_write()
106 length1 = this->size - this->pos_write; in line6_midibuf_write()
110 memcpy(this->buf + this->pos_write, data, length); in line6_midibuf_write()
111 this->pos_write += length; in line6_midibuf_write()
114 length2 = length - length1; in line6_midibuf_write()
115 memcpy(this->buf + this->pos_write, data, length1); in line6_midibuf_write()
116 memcpy(this->buf, data + length1, length2); in line6_midibuf_write()
117 this->pos_write = length2; in line6_midibuf_write()
120 if (this->pos_write == this->pos_read) in line6_midibuf_write()
121 this->full = 1; in line6_midibuf_write()
139 return -EINVAL; in line6_midibuf_read()
149 length1 = this->size - this->pos_read; in line6_midibuf_read()
152 command = this->buf[this->pos_read]; in line6_midibuf_read()
156 this->command_prev = command; in line6_midibuf_read()
158 if (this->command_prev > 0) { in line6_midibuf_read()
160 midibuf_message_length(this->command_prev); in line6_midibuf_read()
163 midi_length = midi_length_prev - 1; in line6_midibuf_read()
166 midi_length = -1; in line6_midibuf_read()
168 midi_length = -1; in line6_midibuf_read()
176 if (this->buf[this->pos_read + i] & 0x80) in line6_midibuf_read()
182 length2 = length - length1; in line6_midibuf_read()
185 if (this->buf[this->pos_read + i] & 0x80) in line6_midibuf_read()
192 if (this->buf[i] & 0x80) in line6_midibuf_read()
200 midi_length = -1; /* end of message not found */ in line6_midibuf_read()
204 if (!this->split) in line6_midibuf_read()
215 memcpy(data + repeat, this->buf + this->pos_read, length); in line6_midibuf_read()
216 this->pos_read += length; in line6_midibuf_read()
219 length2 = length - length1; in line6_midibuf_read()
220 memcpy(data + repeat, this->buf + this->pos_read, length1); in line6_midibuf_read()
221 memcpy(data + repeat + length1, this->buf, length2); in line6_midibuf_read()
222 this->pos_read = length2; in line6_midibuf_read()
226 data[0] = this->command_prev; in line6_midibuf_read()
228 this->full = 0; in line6_midibuf_read()
239 this->pos_read = (this->pos_read + length) % this->size; in line6_midibuf_ignore()
240 this->full = 0; in line6_midibuf_ignore()
246 kfree(this->buf); in line6_midibuf_destroy()
247 this->buf = NULL; in line6_midibuf_destroy()