sound/core/seq/seq_midi_event.c
Source file repositories/reference/linux-study-clean/sound/core/seq/seq_midi_event.c
File Facts
- System
- Linux kernel
- Corpus path
sound/core/seq/seq_midi_event.c- Extension
.c- Size
- 13442 bytes
- Lines
- 452
- Domain
- Driver Families
- Bucket
- sound/core
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/slab.hlinux/errno.hlinux/string.hlinux/module.hsound/core.hsound/seq_kernel.hsound/seq_midi_event.hsound/asoundef.h
Detected Declarations
function snd_midi_event_newfunction snd_midi_event_freefunction reset_encodefunction snd_midi_event_reset_encodefunction snd_midi_event_reset_decodefunction snd_midi_event_no_statusfunction snd_midi_event_encode_bytefunction note_eventfunction one_param_ctrl_eventfunction pitchbend_ctrl_eventfunction two_param_ctrl_eventfunction one_param_eventfunction songpos_eventfunction snd_midi_event_decodefunction note_decodefunction one_param_decodefunction pitchbend_decodefunction two_param_decodefunction songpos_decodefunction extra_decode_ctrl14function extra_decode_xrpnexport snd_midi_event_newexport snd_midi_event_freeexport snd_midi_event_reset_encodeexport snd_midi_event_reset_decodeexport snd_midi_event_no_statusexport snd_midi_event_encode_byteexport snd_midi_event_decode
Annotated Snippet
if (dev->buf == NULL) {
kfree(dev);
return -ENOMEM;
}
}
dev->bufsize = bufsize;
dev->lastcmd = 0xff;
dev->type = ST_INVALID;
spin_lock_init(&dev->lock);
*rdev = dev;
return 0;
}
EXPORT_SYMBOL(snd_midi_event_new);
void snd_midi_event_free(struct snd_midi_event *dev)
{
if (dev != NULL) {
kfree(dev->buf);
kfree(dev);
}
}
EXPORT_SYMBOL(snd_midi_event_free);
/*
* initialize record
*/
static inline void reset_encode(struct snd_midi_event *dev)
{
dev->read = 0;
dev->qlen = 0;
dev->type = ST_INVALID;
}
void snd_midi_event_reset_encode(struct snd_midi_event *dev)
{
guard(spinlock_irqsave)(&dev->lock);
reset_encode(dev);
}
EXPORT_SYMBOL(snd_midi_event_reset_encode);
void snd_midi_event_reset_decode(struct snd_midi_event *dev)
{
guard(spinlock_irqsave)(&dev->lock);
dev->lastcmd = 0xff;
}
EXPORT_SYMBOL(snd_midi_event_reset_decode);
void snd_midi_event_no_status(struct snd_midi_event *dev, int on)
{
dev->nostat = on ? 1 : 0;
}
EXPORT_SYMBOL(snd_midi_event_no_status);
/*
* read one byte and encode to sequencer event:
* return true if MIDI bytes are encoded to an event
* false data is not finished
*/
bool snd_midi_event_encode_byte(struct snd_midi_event *dev, unsigned char c,
struct snd_seq_event *ev)
{
bool rc = false;
if (c >= MIDI_CMD_COMMON_CLOCK) {
/* real-time event */
ev->type = status_event[ST_SPECIAL + c - 0xf0].event;
ev->flags &= ~SNDRV_SEQ_EVENT_LENGTH_MASK;
ev->flags |= SNDRV_SEQ_EVENT_LENGTH_FIXED;
return ev->type != SNDRV_SEQ_EVENT_NONE;
}
guard(spinlock_irqsave)(&dev->lock);
if ((c & 0x80) &&
(c != MIDI_CMD_COMMON_SYSEX_END || dev->type != ST_SYSEX)) {
/* new command */
dev->buf[0] = c;
if ((c & 0xf0) == 0xf0) /* system messages */
dev->type = (c & 0x0f) + ST_SPECIAL;
else
dev->type = (c >> 4) & 0x07;
dev->read = 1;
dev->qlen = status_event[dev->type].qlen;
} else {
if (dev->qlen > 0) {
/* rest of command */
dev->buf[dev->read++] = c;
if (dev->type != ST_SYSEX)
dev->qlen--;
} else {
/* running status */
Annotation
- Immediate include surface: `linux/slab.h`, `linux/errno.h`, `linux/string.h`, `linux/module.h`, `sound/core.h`, `sound/seq_kernel.h`, `sound/seq_midi_event.h`, `sound/asoundef.h`.
- Detected declarations: `function snd_midi_event_new`, `function snd_midi_event_free`, `function reset_encode`, `function snd_midi_event_reset_encode`, `function snd_midi_event_reset_decode`, `function snd_midi_event_no_status`, `function snd_midi_event_encode_byte`, `function note_event`, `function one_param_ctrl_event`, `function pitchbend_ctrl_event`.
- Atlas domain: Driver Families / sound/core.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.