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.

121 lines
3.0KB

  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. #ifndef STRUCTS_H__FD2CC895_411F_4ADE_9200_50FE395EDB72__INCLUDED
  22. #define STRUCTS_H__FD2CC895_411F_4ADE_9200_50FE395EDB72__INCLUDED
  23. #include <semaphore.h>
  24. #include <jack/midiport.h>
  25. #define JACK_INVALID_PORT NULL
  26. #define MAX_PORTS 2048
  27. #define MAX_EVENT_SIZE 1024
  28. #define PORT_HASH_BITS 4
  29. #define PORT_HASH_SIZE (1 << PORT_HASH_BITS)
  30. typedef struct a2j_port * a2j_port_hash_t[PORT_HASH_SIZE];
  31. struct a2j;
  32. struct a2j_port
  33. {
  34. struct a2j_port * next; /* hash - jack */
  35. struct list_head siblings; /* list - main loop */
  36. struct a2j * a2j_ptr;
  37. bool is_dead;
  38. char name[64];
  39. snd_seq_addr_t remote;
  40. jack_port_t * jack_port;
  41. jack_ringbuffer_t * inbound_events; // alsa_midi_event_t + data
  42. int64_t last_out_time;
  43. void * jack_buf;
  44. };
  45. struct a2j_stream
  46. {
  47. snd_midi_event_t *codec;
  48. jack_ringbuffer_t *new_ports;
  49. a2j_port_hash_t port_hash;
  50. struct list_head list;
  51. };
  52. struct a2j
  53. {
  54. jack_client_t * jack_client;
  55. snd_seq_t *seq;
  56. pthread_t alsa_io_thread;
  57. int client_id;
  58. int port_id;
  59. int queue;
  60. int input;
  61. int finishing;
  62. int ignore_hardware_ports;
  63. jack_ringbuffer_t* port_add; // snd_seq_addr_t
  64. jack_ringbuffer_t* port_del; // struct a2j_port*
  65. jack_ringbuffer_t* outbound_events; // struct a2j_delivery_event
  66. jack_nframes_t cycle_start;
  67. sem_t io_semaphore;
  68. struct a2j_stream stream;
  69. };
  70. #define NSEC_PER_SEC ((int64_t)1000*1000*1000)
  71. struct a2j_alsa_midi_event
  72. {
  73. int64_t time;
  74. int size;
  75. };
  76. #define MAX_JACKMIDI_EV_SIZE 16
  77. struct a2j_delivery_event
  78. {
  79. struct list_head siblings;
  80. /* a jack MIDI event, plus the port its destined for: everything
  81. the ALSA output thread needs to deliver the event. time is
  82. part of the jack_event.
  83. */
  84. jack_midi_event_t jack_event;
  85. jack_nframes_t time; /* realtime, not offset time */
  86. struct a2j_port* port;
  87. char midistring[MAX_JACKMIDI_EV_SIZE];
  88. };
  89. void a2j_info (const char* fmt, ...);
  90. void a2j_error (const char* fmt, ...);
  91. void a2j_debug (const char* fmt, ...);
  92. void a2j_warning (const char* fmt, ...);
  93. #endif /* #ifndef STRUCTS_H__FD2CC895_411F_4ADE_9200_50FE395EDB72__INCLUDED */