rawmidi.h 5.9 KB

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