162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  Main header file for the ALSA sequencer
462306a36Sopenharmony_ci *  Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl>
562306a36Sopenharmony_ci *            (c) 1998-1999 by Jaroslav Kysela <perex@perex.cz>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci#ifndef __SOUND_ASEQUENCER_H
862306a36Sopenharmony_ci#define __SOUND_ASEQUENCER_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/ioctl.h>
1162306a36Sopenharmony_ci#include <sound/asound.h>
1262306a36Sopenharmony_ci#include <uapi/sound/asequencer.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/* helper macro */
1562306a36Sopenharmony_ci#define snd_seq_event_bounce_ext_data(ev) ((void*)((char *)(ev)->data.ext.ptr + sizeof(struct snd_seq_event_bounce)))
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/*
1862306a36Sopenharmony_ci * type check macros
1962306a36Sopenharmony_ci */
2062306a36Sopenharmony_ci/* result events: 0-4 */
2162306a36Sopenharmony_ci#define snd_seq_ev_is_result_type(ev)	((ev)->type < 5)
2262306a36Sopenharmony_ci/* channel specific events: 5-19 */
2362306a36Sopenharmony_ci#define snd_seq_ev_is_channel_type(ev)	((ev)->type >= 5 && (ev)->type < 20)
2462306a36Sopenharmony_ci/* note events: 5-9 */
2562306a36Sopenharmony_ci#define snd_seq_ev_is_note_type(ev)	((ev)->type >= 5 && (ev)->type < 10)
2662306a36Sopenharmony_ci/* control events: 10-19 */
2762306a36Sopenharmony_ci#define snd_seq_ev_is_control_type(ev)	((ev)->type >= 10 && (ev)->type < 20)
2862306a36Sopenharmony_ci/* queue control events: 30-39 */
2962306a36Sopenharmony_ci#define snd_seq_ev_is_queue_type(ev)	((ev)->type >= 30 && (ev)->type < 40)
3062306a36Sopenharmony_ci/* system status messages */
3162306a36Sopenharmony_ci#define snd_seq_ev_is_message_type(ev)	((ev)->type >= 60 && (ev)->type < 69)
3262306a36Sopenharmony_ci/* sample messages */
3362306a36Sopenharmony_ci#define snd_seq_ev_is_sample_type(ev)	((ev)->type >= 70 && (ev)->type < 79)
3462306a36Sopenharmony_ci/* user-defined messages */
3562306a36Sopenharmony_ci#define snd_seq_ev_is_user_type(ev)	((ev)->type >= 90 && (ev)->type < 99)
3662306a36Sopenharmony_ci/* fixed length events: 0-99 */
3762306a36Sopenharmony_ci#define snd_seq_ev_is_fixed_type(ev)	((ev)->type < 100)
3862306a36Sopenharmony_ci/* variable length events: 130-139 */
3962306a36Sopenharmony_ci#define snd_seq_ev_is_variable_type(ev)	((ev)->type >= 130 && (ev)->type < 140)
4062306a36Sopenharmony_ci/* reserved for kernel */
4162306a36Sopenharmony_ci#define snd_seq_ev_is_reserved(ev)	((ev)->type >= 150)
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/* direct dispatched events */
4462306a36Sopenharmony_ci#define snd_seq_ev_is_direct(ev)	((ev)->queue == SNDRV_SEQ_QUEUE_DIRECT)
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci/*
4762306a36Sopenharmony_ci * macros to check event flags
4862306a36Sopenharmony_ci */
4962306a36Sopenharmony_ci/* prior events */
5062306a36Sopenharmony_ci#define snd_seq_ev_is_prior(ev)		(((ev)->flags & SNDRV_SEQ_PRIORITY_MASK) == SNDRV_SEQ_PRIORITY_HIGH)
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/* event length type */
5362306a36Sopenharmony_ci#define snd_seq_ev_length_type(ev)	((ev)->flags & SNDRV_SEQ_EVENT_LENGTH_MASK)
5462306a36Sopenharmony_ci#define snd_seq_ev_is_fixed(ev)		(snd_seq_ev_length_type(ev) == SNDRV_SEQ_EVENT_LENGTH_FIXED)
5562306a36Sopenharmony_ci#define snd_seq_ev_is_variable(ev)	(snd_seq_ev_length_type(ev) == SNDRV_SEQ_EVENT_LENGTH_VARIABLE)
5662306a36Sopenharmony_ci#define snd_seq_ev_is_varusr(ev)	(snd_seq_ev_length_type(ev) == SNDRV_SEQ_EVENT_LENGTH_VARUSR)
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/* time-stamp type */
5962306a36Sopenharmony_ci#define snd_seq_ev_timestamp_type(ev)	((ev)->flags & SNDRV_SEQ_TIME_STAMP_MASK)
6062306a36Sopenharmony_ci#define snd_seq_ev_is_tick(ev)		(snd_seq_ev_timestamp_type(ev) == SNDRV_SEQ_TIME_STAMP_TICK)
6162306a36Sopenharmony_ci#define snd_seq_ev_is_real(ev)		(snd_seq_ev_timestamp_type(ev) == SNDRV_SEQ_TIME_STAMP_REAL)
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci/* time-mode type */
6462306a36Sopenharmony_ci#define snd_seq_ev_timemode_type(ev)	((ev)->flags & SNDRV_SEQ_TIME_MODE_MASK)
6562306a36Sopenharmony_ci#define snd_seq_ev_is_abstime(ev)	(snd_seq_ev_timemode_type(ev) == SNDRV_SEQ_TIME_MODE_ABS)
6662306a36Sopenharmony_ci#define snd_seq_ev_is_reltime(ev)	(snd_seq_ev_timemode_type(ev) == SNDRV_SEQ_TIME_MODE_REL)
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/* check whether the given event is a UMP event */
6962306a36Sopenharmony_ci#define snd_seq_ev_is_ump(ev) \
7062306a36Sopenharmony_ci	(IS_ENABLED(CONFIG_SND_SEQ_UMP) && ((ev)->flags & SNDRV_SEQ_EVENT_UMP))
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/* queue sync port */
7362306a36Sopenharmony_ci#define snd_seq_queue_sync_port(q)	((q) + 16)
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#endif /* __SOUND_ASEQUENCER_H */
76