rawmidi.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 snd_rawmidi_ops {
  43. int (*open) (struct snd_rawmidi_substream * substream);
  44. int (*close) (struct snd_rawmidi_substream * substream);
  45. void (*trigger) (struct snd_rawmidi_substream * substream, int up);
  46. void (*drain) (struct snd_rawmidi_substream * substream);
  47. };
  48. struct snd_rawmidi_global_ops {
  49. int (*dev_register) (struct snd_rawmidi * rmidi);
  50. int (*dev_unregister) (struct snd_rawmidi * rmidi);
  51. void (*get_port_info)(struct snd_rawmidi *rmidi, int number,
  52. struct snd_seq_port_info *info);
  53. };
  54. struct snd_rawmidi_runtime {
  55. unsigned int drain: 1, /* drain stage */
  56. oss: 1; /* OSS compatible mode */
  57. /* midi stream buffer */
  58. unsigned char *buffer; /* buffer for MIDI data */
  59. size_t buffer_size; /* size of buffer */
  60. size_t appl_ptr; /* application pointer */
  61. size_t hw_ptr; /* hardware pointer */
  62. size_t avail_min; /* min avail for wakeup */
  63. size_t avail; /* max used buffer for wakeup */
  64. size_t xruns; /* over/underruns counter */
  65. /* misc */
  66. spinlock_t lock;
  67. wait_queue_head_t sleep;
  68. /* event handler (new bytes, input only) */
  69. void (*event)(struct snd_rawmidi_substream *substream);
  70. /* defers calls to event [input] or ops->trigger [output] */
  71. struct tasklet_struct tasklet;
  72. /* private data */
  73. void *private_data;
  74. void (*private_free)(struct snd_rawmidi_substream *substream);
  75. };
  76. struct snd_rawmidi_substream {
  77. struct list_head list; /* list of all substream for given stream */
  78. int stream; /* direction */
  79. int number; /* substream number */
  80. unsigned int opened: 1, /* open flag */
  81. append: 1, /* append flag (merge more streams) */
  82. active_sensing: 1; /* send active sensing when close */
  83. int use_count; /* use counter (for output) */
  84. size_t bytes;
  85. struct snd_rawmidi *rmidi;
  86. struct snd_rawmidi_str *pstr;
  87. char name[32];
  88. struct snd_rawmidi_runtime *runtime;
  89. /* hardware layer */
  90. struct snd_rawmidi_ops *ops;
  91. };
  92. struct snd_rawmidi_file {
  93. struct snd_rawmidi *rmidi;
  94. struct snd_rawmidi_substream *input;
  95. struct snd_rawmidi_substream *output;
  96. };
  97. struct snd_rawmidi_str {
  98. unsigned int substream_count;
  99. unsigned int substream_opened;
  100. struct list_head substreams;
  101. };
  102. struct snd_rawmidi {
  103. struct snd_card *card;
  104. struct list_head list;
  105. unsigned int device; /* device number */
  106. unsigned int info_flags; /* SNDRV_RAWMIDI_INFO_XXXX */
  107. char id[64];
  108. char name[80];
  109. #ifdef CONFIG_SND_OSSEMUL
  110. int ossreg;
  111. #endif
  112. struct snd_rawmidi_global_ops *ops;
  113. struct snd_rawmidi_str streams[2];
  114. void *private_data;
  115. void (*private_free) (struct snd_rawmidi *rmidi);
  116. struct mutex open_mutex;
  117. wait_queue_head_t open_wait;
  118. struct snd_info_entry *dev;
  119. struct snd_info_entry *proc_entry;
  120. #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
  121. struct snd_seq_device *seq_dev;
  122. #endif
  123. };
  124. /* main rawmidi functions */
  125. int snd_rawmidi_new(struct snd_card *card, char *id, int device,
  126. int output_count, int input_count,
  127. struct snd_rawmidi **rmidi);
  128. void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
  129. struct snd_rawmidi_ops *ops);
  130. /* callbacks */
  131. void snd_rawmidi_receive_reset(struct snd_rawmidi_substream *substream);
  132. int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
  133. const unsigned char *buffer, int count);
  134. void snd_rawmidi_transmit_reset(struct snd_rawmidi_substream *substream);
  135. int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream);
  136. int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
  137. unsigned char *buffer, int count);
  138. int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count);
  139. int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
  140. unsigned char *buffer, int count);
  141. /* main midi functions */
  142. int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info);
  143. int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice,
  144. int mode, struct snd_rawmidi_file *rfile);
  145. int snd_rawmidi_kernel_release(struct snd_rawmidi_file *rfile);
  146. int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
  147. struct snd_rawmidi_params *params);
  148. int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
  149. struct snd_rawmidi_params *params);
  150. int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream);
  151. int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream);
  152. int snd_rawmidi_drain_input(struct snd_rawmidi_substream *substream);
  153. long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream,
  154. unsigned char *buf, long count);
  155. long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream,
  156. const unsigned char *buf, long count);
  157. #endif /* __SOUND_RAWMIDI_H */