jack1 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7KB

  1. /* -*- Mode: C ; c-basic-offset: 2 -*- */
  2. /*
  3. * ALSA SEQ < - > JACK MIDI bridge
  4. *
  5. * Copyright (c) 2006,2007 Dmitry S. Baikov <c0ff@konstruktiv.org>
  6. * Copyright (c) 2007,2008,2009 Nedko Arnaudov <nedko@arnaudov.name>
  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; version 2 of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <stdbool.h>
  22. #include <semaphore.h>
  23. #include <alsa/asoundlib.h>
  24. #include <jack/jack.h>
  25. #include <jack/ringbuffer.h>
  26. #include "list.h"
  27. #include "a2j.h"
  28. #include "port_hash.h"
  29. static inline
  30. int
  31. a2j_port_hash(
  32. snd_seq_addr_t addr)
  33. {
  34. return (addr.client + addr.port) % PORT_HASH_SIZE;
  35. }
  36. struct a2j_port *
  37. a2j_port_get(
  38. a2j_port_hash_t hash,
  39. snd_seq_addr_t addr)
  40. {
  41. struct a2j_port **pport = &hash[a2j_port_hash(addr)];
  42. while (*pport) {
  43. struct a2j_port *port = *pport;
  44. if (port->remote.client == addr.client && port->remote.port == addr.port)
  45. return port;
  46. pport = &port->next;
  47. }
  48. return NULL;
  49. }
  50. void
  51. a2j_port_insert(
  52. a2j_port_hash_t hash,
  53. struct a2j_port * port)
  54. {
  55. struct a2j_port **pport = &hash[a2j_port_hash(port->remote)];
  56. port->next = *pport;
  57. *pport = port;
  58. }