rawmidi.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #ifndef __SOUND_RAWMIDI_H
  2. #define __SOUND_RAWMIDI_H
  3. /*
  4. * Abstract layer for MIDI v1.0 stream
  5. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <sound/asound.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/wait.h>
  27. #include <linux/mutex.h>
  28. #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
  29. #include "seq_device.h"
  30. #endif
  31. /*
  32. * Raw MIDI interface
  33. */
  34. #define SNDRV_RAWMIDI_DEVICES 8
  35. #define SNDRV_RAWMIDI_LFLG_OUTPUT (1<<0)
  36. #define SNDRV_RAWMIDI_LFLG_INPUT (1<<1)
  37. #define SNDRV_RAWMIDI_LFLG_OPEN (3<<0)
  38. #define SNDRV_RAWMIDI_LFLG_APPEND (1<<2)
  39. struct snd_rawmidi;
  40. struct snd_rawmidi_substream;
  41. struct snd_seq_port_info;
  42. struct pid;
  43. struct snd_rawmidi_ops {
  44. int (*open) (struct snd_rawmidi_substream * substream);
  45. int (*close) (struct snd_rawmidi_substream * substream);
  46. void (*trigger) (struct snd_rawmidi_substream * substream, int up);
  47. void (*drain) (struct snd_rawmidi_substream * substream);
  48. };
  49. struct snd_rawmidi_global_ops {
  50. int (*dev_register) (struct snd_rawmidi * rmidi);
  51. int (*dev_unregister) (struct snd_rawmidi * rmidi);
  52. void (*get_port_info)(struct snd_rawmidi *rmidi, int number,
  53. struct snd_seq_port_info *info);
  54. };
  55. struct snd_rawmidi_runtime {
  56. unsigned int drain: 1, /* drain stage */
  57. oss: 1; /* OSS compatible mode */
  58. /* midi stream buffer */
  59. unsigned char *buffer; /* buffer for MIDI data */
  60. size_t buffer_size; /* size of buffer */
  61. size_t appl_ptr; /* application pointer */
  62. size_t hw_ptr; /* hardware pointer */
  63. size_t avail_min; /* min avail for wakeup */
  64. size_t avail; /* max used buffer for wakeup */
  65. size_t xruns; /* over/underruns counter */
  66. /* misc */
  67. spinlock_t lock;
  68. wait_queue_head_t sleep;
  69. /* event handler (new bytes, input only) */
  70. void (*event)(struct snd_rawmidi_substream *substream);
  71. /* defers calls to event [input] or ops->trigger [output] */
  72. struct tasklet_struct tasklet;
  73. /* private data */
  74. void *private_data;
  75. void (*private_free)(struct snd_rawmidi_substream *substream);
  76. };
  77. struct snd_rawmidi_substream {
  78. struct list_head list; /* list of all substream for given stream */
  79. int stream; /* direction */
  80. int number; /* substream number */
  81. unsigned int opened: 1, /* open flag */
  82. append: 1, /* append flag (merge more streams) */
  83. active_sensing: 1; /* send active sensing when close */
  84. int use_count; /* use counter (for output) */
  85. size_t bytes;
  86. struct snd_rawmidi *rmidi;
  87. struct snd_rawmidi_str *pstr;
  88. char name[32];
  89. struct snd_rawmidi_runtime *runtime;
  90. struct pid *pid;
  91. /* hardware layer */
  92. struct snd_rawmidi_ops *ops;
  93. };
  94. struct snd_rawmidi_file {
  95. struct snd_rawmidi *rmidi;
  96. struct snd_rawmidi_substream *input;
  97. struct snd_rawmidi_substream *output;
  98. };
  99. struct snd_rawmidi_str {
  100. unsigned int substream_count;
  101. unsigned int substream_opened;
  102. struct list_head substreams;
  103. };
  104. struct snd_rawmidi {
  105. struct snd_card *card;
  106. struct list_head list;
  107. unsigned int device; /* device number */
  108. unsigned int info_flags; /* SNDRV_RAWMIDI_INFO_XXXX */
  109. char id[64];
  110. char name[80];
  111. #ifdef CONFIG_SND_OSSEMUL
  112. int ossreg;
  113. #endif
  114. struct snd_rawmidi_global_ops *ops;
  115. struct snd_rawmidi_str streams[2];
  116. void *private_data;
  117. void (*private_free) (struct snd_rawmidi *rmidi);
  118. struct mutex open_mutex;
  119. wait_queue_head_t open_wait;
  120. struct snd_info_entry *dev;
  121. struct snd_info_entry *proc_entry;
  122. #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
  123. struct snd_seq_device *seq_dev;
  124. #endif
  125. };
  126. /* main rawmidi functions */
  127. int snd_rawmidi_new(struct snd_card *card, char *id, int device,
  128. int output_count, int input_count,
  129. struct snd_rawmidi **rmidi);
  130. void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
  131. struct snd_rawmidi_ops *ops);
  132. /* callbacks */
  133. void snd_rawmidi_receive_reset(struct snd_rawmidi_substream *substream);
  134. int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
  135. const unsigned char *buffer, int count);
  136. void snd_rawmidi_transmit_reset(struct snd_rawmidi_substream *substream);
  137. int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream);
  138. int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
  139. unsigned char *buffer, int count);
  140. int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count);
  141. int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
  142. unsigned char *buffer, int count);
  143. /* main midi functions */
  144. int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info);
  145. int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice,
  146. int mode, struct snd_rawmidi_file *rfile);
  147. int snd_rawmidi_kernel_release(struct snd_rawmidi_file *rfile);
  148. int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
  149. struct snd_rawmidi_params *params);
  150. int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
  151. struct snd_rawmidi_params *params);
  152. int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream);
  153. int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream);
  154. int snd_rawmidi_drain_input(struct snd_rawmidi_substream *substream);
  155. long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream,
  156. unsigned char *buf, long count);
  157. long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream,
  158. const unsigned char *buf, long count);
  159. #endif /* __SOUND_RAWMIDI_H */