/[pidim]/src/pidim_common.c
ViewVC logotype

Annotation of /src/pidim_common.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (hide annotations)
Thu Aug 26 01:09:50 2010 UTC (9 years, 5 months ago) by ben
File MIME type: text/plain
File size: 1952 byte(s)
new module: pidim_arpeggiate
1 ben 1 #include <alsa/asoundlib.h>
2    
3     /* create a client handle */
4     snd_seq_t* alsa_open_client (const char* name)
5     {
6     snd_seq_t* handle;
7     int err;
8    
9     err = snd_seq_open(&handle, "default", SND_SEQ_OPEN_INPUT|SND_SEQ_OPEN_OUTPUT, 0);
10     if (err < 0) {
11     return NULL;
12     }
13     snd_seq_set_client_name(handle, name);
14     return handle;
15     }
16    
17     /* create an input port */
18     int alsa_open_input_port(snd_seq_t *handle, const char* name)
19     {
20     return snd_seq_create_simple_port(handle, name,
21     SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE,
22     SND_SEQ_PORT_TYPE_APPLICATION);
23     }
24    
25     /* create an output port */
26     int alsa_open_output_port(snd_seq_t *handle, const char* name)
27     {
28     return snd_seq_create_simple_port(handle, name,
29     SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ,
30     SND_SEQ_PORT_TYPE_APPLICATION);
31     }
32    
33 ben 3 /* init and return a queue */
34     int alsa_init_queue(snd_seq_t *handle, int seq_len)
35 ben 1 {
36     int queue_id;
37     queue_id = snd_seq_alloc_queue(handle);
38 ben 3 snd_seq_set_client_pool_output(handle, (seq_len<<1) + 4);
39     return queue_id;
40 ben 1 }
41    
42     void alsa_clear_queue(snd_seq_t *handle, int queue_id)
43     {
44 ben 3 snd_seq_remove_events_t *remove_ev;
45    
46     snd_seq_remove_events_malloc(&remove_ev);
47     snd_seq_remove_events_set_queue(remove_ev, queue_id);
48     snd_seq_remove_events_set_condition(remove_ev, SND_SEQ_REMOVE_OUTPUT | SND_SEQ_REMOVE_IGNORE_OFF);
49     snd_seq_remove_events(handle, remove_ev);
50     snd_seq_remove_events_free(remove_ev);
51 ben 1 }
52    
53     /* get the file descriptor of the first MIDI input port */
54     #if SND_LIB_MAJOR > 0 || SND_LIB_MINOR >= 6
55     /* FIXME: this is a dirty hack form XMBC code */
56     int alsa_get_fd(snd_seq_t *handle)
57     {
58     int pfds = snd_seq_poll_descriptors_count(handle, POLLIN);
59     if (pfds > 0) {
60     struct pollfd pfd;
61     if (snd_seq_poll_descriptors(handle, &pfd, 1, POLLIN) >= 0)
62     return pfd.fd;
63     }
64     return -1;
65     }
66     #endif

  ViewVC Help
Powered by ViewVC 1.1.26