162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci#ifndef __SOUND_SEQ_VIRMIDI_H
362306a36Sopenharmony_ci#define __SOUND_SEQ_VIRMIDI_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci/*
662306a36Sopenharmony_ci *  Virtual Raw MIDI client on Sequencer
762306a36Sopenharmony_ci *  Copyright (c) 2000 by Takashi Iwai <tiwai@suse.de>,
862306a36Sopenharmony_ci *                        Jaroslav Kysela <perex@perex.cz>
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <sound/rawmidi.h>
1262306a36Sopenharmony_ci#include <sound/seq_midi_event.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/*
1562306a36Sopenharmony_ci * device file instance:
1662306a36Sopenharmony_ci * This instance is created at each time the midi device file is
1762306a36Sopenharmony_ci * opened.  Each instance has its own input buffer and MIDI parser
1862306a36Sopenharmony_ci * (buffer), and is associated with the device instance.
1962306a36Sopenharmony_ci */
2062306a36Sopenharmony_cistruct snd_virmidi {
2162306a36Sopenharmony_ci	struct list_head list;
2262306a36Sopenharmony_ci	int seq_mode;
2362306a36Sopenharmony_ci	int client;
2462306a36Sopenharmony_ci	int port;
2562306a36Sopenharmony_ci	bool trigger;
2662306a36Sopenharmony_ci	struct snd_midi_event *parser;
2762306a36Sopenharmony_ci	struct snd_seq_event event;
2862306a36Sopenharmony_ci	struct snd_virmidi_dev *rdev;
2962306a36Sopenharmony_ci	struct snd_rawmidi_substream *substream;
3062306a36Sopenharmony_ci	struct work_struct output_work;
3162306a36Sopenharmony_ci};
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#define SNDRV_VIRMIDI_SUBSCRIBE		(1<<0)
3462306a36Sopenharmony_ci#define SNDRV_VIRMIDI_USE		(1<<1)
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci/*
3762306a36Sopenharmony_ci * device record:
3862306a36Sopenharmony_ci * Each virtual midi device has one device instance.  It contains
3962306a36Sopenharmony_ci * common information and the linked-list of opened files,
4062306a36Sopenharmony_ci */
4162306a36Sopenharmony_cistruct snd_virmidi_dev {
4262306a36Sopenharmony_ci	struct snd_card *card;		/* associated card */
4362306a36Sopenharmony_ci	struct snd_rawmidi *rmidi;		/* rawmidi device */
4462306a36Sopenharmony_ci	int seq_mode;			/* SNDRV_VIRMIDI_XXX */
4562306a36Sopenharmony_ci	int device;			/* sequencer device */
4662306a36Sopenharmony_ci	int client;			/* created/attached client */
4762306a36Sopenharmony_ci	int port;			/* created/attached port */
4862306a36Sopenharmony_ci	unsigned int flags;		/* SNDRV_VIRMIDI_* */
4962306a36Sopenharmony_ci	rwlock_t filelist_lock;
5062306a36Sopenharmony_ci	struct rw_semaphore filelist_sem;
5162306a36Sopenharmony_ci	struct list_head filelist;
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci/* sequencer mode:
5562306a36Sopenharmony_ci * ATTACH = input/output events from midi device are routed to the
5662306a36Sopenharmony_ci *          attached sequencer port.  sequencer port is not created
5762306a36Sopenharmony_ci *          by virmidi itself.
5862306a36Sopenharmony_ci *          the input to rawmidi must be processed by passing the
5962306a36Sopenharmony_ci *          incoming events via snd_virmidi_receive()
6062306a36Sopenharmony_ci * DISPATCH = input/output events are routed to subscribers.
6162306a36Sopenharmony_ci *            sequencer port is created in virmidi.
6262306a36Sopenharmony_ci */
6362306a36Sopenharmony_ci#define SNDRV_VIRMIDI_SEQ_NONE		0
6462306a36Sopenharmony_ci#define SNDRV_VIRMIDI_SEQ_ATTACH	1
6562306a36Sopenharmony_ci#define SNDRV_VIRMIDI_SEQ_DISPATCH	2
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ciint snd_virmidi_new(struct snd_card *card, int device, struct snd_rawmidi **rrmidi);
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci#endif /* __SOUND_SEQ_VIRMIDI */
70