rawmidi.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. typedef enum sndrv_rawmidi_stream snd_rawmidi_stream_t;
  35. typedef struct sndrv_rawmidi_info snd_rawmidi_info_t;
  36. typedef struct sndrv_rawmidi_params snd_rawmidi_params_t;
  37. typedef struct sndrv_rawmidi_status snd_rawmidi_status_t;
  38. #define SNDRV_RAWMIDI_DEVICES 8
  39. #define SNDRV_RAWMIDI_LFLG_OUTPUT (1<<0)
  40. #define SNDRV_RAWMIDI_LFLG_INPUT (1<<1)
  41. #define SNDRV_RAWMIDI_LFLG_OPEN (3<<0)
  42. #define SNDRV_RAWMIDI_LFLG_APPEND (1<<2)
  43. #define SNDRV_RAWMIDI_LFLG_NOOPENLOCK (1<<3)
  44. typedef struct _snd_rawmidi_runtime snd_rawmidi_runtime_t;
  45. typedef struct _snd_rawmidi_substream snd_rawmidi_substream_t;
  46. typedef struct _snd_rawmidi_str snd_rawmidi_str_t;
  47. typedef struct _snd_rawmidi_ops {
  48. int (*open) (snd_rawmidi_substream_t * substream);
  49. int (*close) (snd_rawmidi_substream_t * substream);
  50. void (*trigger) (snd_rawmidi_substream_t * substream, int up);
  51. void (*drain) (snd_rawmidi_substream_t * substream);
  52. } snd_rawmidi_ops_t;
  53. typedef struct _snd_rawmidi_global_ops {
  54. int (*dev_register) (snd_rawmidi_t * rmidi);
  55. int (*dev_unregister) (snd_rawmidi_t * rmidi);
  56. } snd_rawmidi_global_ops_t;
  57. struct _snd_rawmidi_runtime {
  58. unsigned int drain: 1, /* drain stage */
  59. oss: 1; /* OSS compatible mode */
  60. /* midi stream buffer */
  61. unsigned char *buffer; /* buffer for MIDI data */
  62. size_t buffer_size; /* size of buffer */
  63. size_t appl_ptr; /* application pointer */
  64. size_t hw_ptr; /* hardware pointer */
  65. size_t avail_min; /* min avail for wakeup */
  66. size_t avail; /* max used buffer for wakeup */
  67. size_t xruns; /* over/underruns counter */
  68. /* misc */
  69. spinlock_t lock;
  70. wait_queue_head_t sleep;
  71. /* event handler (new bytes, input only) */
  72. void (*event)(snd_rawmidi_substream_t *substream);
  73. /* defers calls to event [input] or ops->trigger [output] */
  74. struct tasklet_struct tasklet;
  75. /* private data */
  76. void *private_data;
  77. void (*private_free)(snd_rawmidi_substream_t *substream);
  78. };
  79. struct _snd_rawmidi_substream {
  80. struct list_head list; /* list of all substream for given stream */
  81. int stream; /* direction */
  82. int number; /* substream number */
  83. unsigned int opened: 1, /* open flag */
  84. append: 1, /* append flag (merge more streams) */
  85. active_sensing: 1; /* send active sensing when close */
  86. int use_count; /* use counter (for output) */
  87. size_t bytes;
  88. snd_rawmidi_t *rmidi;
  89. snd_rawmidi_str_t *pstr;
  90. char name[32];
  91. snd_rawmidi_runtime_t *runtime;
  92. /* hardware layer */
  93. snd_rawmidi_ops_t *ops;
  94. };
  95. typedef struct _snd_rawmidi_file {
  96. snd_rawmidi_t *rmidi;
  97. snd_rawmidi_substream_t *input;
  98. snd_rawmidi_substream_t *output;
  99. } snd_rawmidi_file_t;
  100. struct _snd_rawmidi_str {
  101. unsigned int substream_count;
  102. unsigned int substream_opened;
  103. struct list_head substreams;
  104. };
  105. struct _snd_rawmidi {
  106. snd_card_t *card;
  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. snd_rawmidi_global_ops_t *ops;
  115. snd_rawmidi_str_t streams[2];
  116. void *private_data;
  117. void (*private_free) (snd_rawmidi_t *rmidi);
  118. struct semaphore open_mutex;
  119. wait_queue_head_t open_wait;
  120. snd_info_entry_t *dev;
  121. snd_info_entry_t *proc_entry;
  122. #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
  123. snd_seq_device_t *seq_dev;
  124. #endif
  125. };
  126. /* main rawmidi functions */
  127. int snd_rawmidi_new(snd_card_t * card, char *id, int device,
  128. int output_count, int input_count,
  129. snd_rawmidi_t ** rmidi);
  130. void snd_rawmidi_set_ops(snd_rawmidi_t * rmidi, int stream, snd_rawmidi_ops_t * ops);
  131. /* callbacks */
  132. void snd_rawmidi_receive_reset(snd_rawmidi_substream_t * substream);
  133. int snd_rawmidi_receive(snd_rawmidi_substream_t * substream, const unsigned char *buffer, int count);
  134. void snd_rawmidi_transmit_reset(snd_rawmidi_substream_t * substream);
  135. int snd_rawmidi_transmit_empty(snd_rawmidi_substream_t * substream);
  136. int snd_rawmidi_transmit_peek(snd_rawmidi_substream_t * substream, unsigned char *buffer, int count);
  137. int snd_rawmidi_transmit_ack(snd_rawmidi_substream_t * substream, int count);
  138. int snd_rawmidi_transmit(snd_rawmidi_substream_t * substream, unsigned char *buffer, int count);
  139. /* main midi functions */
  140. int snd_rawmidi_info_select(snd_card_t *card, snd_rawmidi_info_t *info);
  141. int snd_rawmidi_kernel_open(int cardnum, int device, int subdevice, int mode, snd_rawmidi_file_t * rfile);
  142. int snd_rawmidi_kernel_release(snd_rawmidi_file_t * rfile);
  143. int snd_rawmidi_output_params(snd_rawmidi_substream_t * substream, snd_rawmidi_params_t * params);
  144. int snd_rawmidi_input_params(snd_rawmidi_substream_t * substream, snd_rawmidi_params_t * params);
  145. int snd_rawmidi_drop_output(snd_rawmidi_substream_t * substream);
  146. int snd_rawmidi_drain_output(snd_rawmidi_substream_t * substream);
  147. int snd_rawmidi_drain_input(snd_rawmidi_substream_t * substream);
  148. long snd_rawmidi_kernel_read(snd_rawmidi_substream_t * substream, unsigned char *buf, long count);
  149. long snd_rawmidi_kernel_write(snd_rawmidi_substream_t * substream, const unsigned char *buf, long count);
  150. #endif /* __SOUND_RAWMIDI_H */