seq_ports.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * ALSA sequencer Ports
  3. * Copyright (c) 1998 by Frank van de Pol <fvdpol@coil.demon.nl>
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #ifndef __SND_SEQ_PORTS_H
  22. #define __SND_SEQ_PORTS_H
  23. #include <sound/seq_kernel.h>
  24. #include "seq_lock.h"
  25. /* list of 'exported' ports */
  26. /* Client ports that are not exported are still accessible, but are
  27. anonymous ports.
  28. If a port supports SUBSCRIPTION, that port can send events to all
  29. subscribersto a special address, with address
  30. (queue==SNDRV_SEQ_ADDRESS_SUBSCRIBERS). The message is then send to all
  31. recipients that are registered in the subscription list. A typical
  32. application for these SUBSCRIPTION events is handling of incoming MIDI
  33. data. The port doesn't 'know' what other clients are interested in this
  34. message. If for instance a MIDI recording application would like to receive
  35. the events from that port, it will first have to subscribe with that port.
  36. */
  37. struct snd_seq_subscribers {
  38. struct snd_seq_port_subscribe info; /* additional info */
  39. struct list_head src_list; /* link of sources */
  40. struct list_head dest_list; /* link of destinations */
  41. atomic_t ref_count;
  42. };
  43. struct snd_seq_port_subs_info {
  44. struct list_head list_head; /* list of subscribed ports */
  45. unsigned int count; /* count of subscribers */
  46. unsigned int exclusive: 1; /* exclusive mode */
  47. struct rw_semaphore list_mutex;
  48. rwlock_t list_lock;
  49. int (*open)(void *private_data, struct snd_seq_port_subscribe *info);
  50. int (*close)(void *private_data, struct snd_seq_port_subscribe *info);
  51. };
  52. struct snd_seq_client_port {
  53. struct snd_seq_addr addr; /* client/port number */
  54. struct module *owner; /* owner of this port */
  55. char name[64]; /* port name */
  56. struct list_head list; /* port list */
  57. snd_use_lock_t use_lock;
  58. /* subscribers */
  59. struct snd_seq_port_subs_info c_src; /* read (sender) list */
  60. struct snd_seq_port_subs_info c_dest; /* write (dest) list */
  61. int (*event_input)(struct snd_seq_event *ev, int direct, void *private_data,
  62. int atomic, int hop);
  63. void (*private_free)(void *private_data);
  64. void *private_data;
  65. unsigned int closing : 1;
  66. unsigned int timestamping: 1;
  67. unsigned int time_real: 1;
  68. int time_queue;
  69. /* capability, inport, output, sync */
  70. unsigned int capability; /* port capability bits */
  71. unsigned int type; /* port type bits */
  72. /* supported channels */
  73. int midi_channels;
  74. int midi_voices;
  75. int synth_voices;
  76. };
  77. struct snd_seq_client;
  78. /* return pointer to port structure and lock port */
  79. struct snd_seq_client_port *snd_seq_port_use_ptr(struct snd_seq_client *client, int num);
  80. /* search for next port - port is locked if found */
  81. struct snd_seq_client_port *snd_seq_port_query_nearest(struct snd_seq_client *client,
  82. struct snd_seq_port_info *pinfo);
  83. /* unlock the port */
  84. #define snd_seq_port_unlock(port) snd_use_lock_free(&(port)->use_lock)
  85. /* create a port, port number is returned (-1 on failure) */
  86. struct snd_seq_client_port *snd_seq_create_port(struct snd_seq_client *client, int port_index);
  87. /* delete a port */
  88. int snd_seq_delete_port(struct snd_seq_client *client, int port);
  89. /* delete all ports */
  90. int snd_seq_delete_all_ports(struct snd_seq_client *client);
  91. /* set port info fields */
  92. int snd_seq_set_port_info(struct snd_seq_client_port *port,
  93. struct snd_seq_port_info *info);
  94. /* get port info fields */
  95. int snd_seq_get_port_info(struct snd_seq_client_port *port,
  96. struct snd_seq_port_info *info);
  97. /* add subscriber to subscription list */
  98. int snd_seq_port_connect(struct snd_seq_client *caller,
  99. struct snd_seq_client *s, struct snd_seq_client_port *sp,
  100. struct snd_seq_client *d, struct snd_seq_client_port *dp,
  101. struct snd_seq_port_subscribe *info);
  102. /* remove subscriber from subscription list */
  103. int snd_seq_port_disconnect(struct snd_seq_client *caller,
  104. struct snd_seq_client *s, struct snd_seq_client_port *sp,
  105. struct snd_seq_client *d, struct snd_seq_client_port *dp,
  106. struct snd_seq_port_subscribe *info);
  107. /* subscribe port */
  108. int snd_seq_port_subscribe(struct snd_seq_client_port *port,
  109. struct snd_seq_port_subscribe *info);
  110. /* get matched subscriber */
  111. struct snd_seq_subscribers *snd_seq_port_get_subscription(struct snd_seq_port_subs_info *src_grp,
  112. struct snd_seq_addr *dest_addr);
  113. #endif