add dbus command to allow checking of wether hardware is currently exported
[a2jmidid.git] / structs.h
blob76801fe58b8469dfbd2e854eeff433d04643c137
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * ALSA SEQ < - > JACK MIDI bridge
5 * Copyright (c) 2006,2007 Dmitry S. Baikov <c0ff@konstruktiv.org>
6 * Copyright (c) 2007,2008,2009 Nedko Arnaudov <nedko@arnaudov.name>
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.
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.
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
22 #ifndef STRUCTS_H__FD2CC895_411F_4ADE_9200_50FE395EDB72__INCLUDED
23 #define STRUCTS_H__FD2CC895_411F_4ADE_9200_50FE395EDB72__INCLUDED
25 #include <semaphore.h>
26 #include <jack/midiport.h>
28 #define JACK_INVALID_PORT NULL
30 #define MAX_PORTS 2048
31 #define MAX_EVENT_SIZE 1024
33 #define PORT_HASH_BITS 4
34 #define PORT_HASH_SIZE (1 << PORT_HASH_BITS)
36 typedef struct a2j_port * a2j_port_hash_t[PORT_HASH_SIZE];
38 struct a2j;
40 struct a2j_port
42 struct a2j_port * next; /* hash - jack */
43 struct list_head siblings; /* list - main loop */
44 struct a2j * a2j_ptr;
45 bool is_dead;
46 snd_seq_addr_t remote;
47 jack_port_t * jack_port;
49 jack_ringbuffer_t * inbound_events; // alsa_midi_event_t + data
50 int64_t last_out_time;
52 void * jack_buf;
53 char name[0];
56 struct a2j_stream
58 snd_midi_event_t *codec;
60 jack_ringbuffer_t *new_ports;
62 a2j_port_hash_t port_hash;
63 struct list_head list;
66 struct a2j
68 jack_client_t * jack_client;
70 snd_seq_t *seq;
71 pthread_t alsa_input_thread;
72 pthread_t alsa_output_thread;
73 int client_id;
74 int port_id;
75 int queue;
77 jack_ringbuffer_t *port_add; // snd_seq_addr_t
78 jack_ringbuffer_t *port_del; // struct a2j_port*
79 jack_ringbuffer_t * outbound_events; // struct a2j_delivery_event
80 jack_nframes_t cycle_start;
82 sem_t io_semaphore;
84 struct a2j_stream stream[2];
87 #define NSEC_PER_SEC ((int64_t)1000*1000*1000)
89 struct a2j_process_info
91 int dir;
92 jack_nframes_t nframes;
93 jack_nframes_t period_start;
94 jack_nframes_t sample_rate;
95 jack_nframes_t cur_frames;
96 int64_t alsa_time;
99 struct a2j_alsa_midi_event
101 int64_t time;
102 int size;
105 #define MAX_JACKMIDI_EV_SIZE 16
107 struct a2j_delivery_event
109 struct list_head siblings;
111 /* a jack MIDI event, plus the port its destined for: everything
112 the ALSA output thread needs to deliver the event. time is
113 part of the jack_event.
115 jack_midi_event_t jack_event;
116 jack_nframes_t time; /* realtime, not offset time */
117 struct a2j_port* port;
118 char midistring[MAX_JACKMIDI_EV_SIZE];
121 /* Beside enum use, these are indeces for (struct a2j).stream array */
122 #define A2J_PORT_CAPTURE 0 // ALSA playback port -> JACK capture port
123 #define A2J_PORT_PLAYBACK 1 // JACK playback port -> ALSA capture port
125 extern struct a2j * g_a2j;
127 extern size_t g_max_jack_port_name_size;
129 #endif /* #ifndef STRUCTS_H__FD2CC895_411F_4ADE_9200_50FE395EDB72__INCLUDED */