File: seq_system.c

package info (click to toggle)
alsadriver 0.2.0-pre8-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 2,808 kB
  • ctags: 6,550
  • sloc: ansic: 43,490; sh: 916; makefile: 759; perl: 54
file content (144 lines) | stat: -rw-r--r-- 4,154 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 *   ALSA sequencer System services Client
 *   Copyright (c) 1998 by Frank van de Pol <F.K.W.van.de.Pol@inter.nl.net>
 *
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include "driver.h"
#include "seq_system.h"
#include "seq_timer.h"
#include "seq_queue.h"

/* internal client that provide system services, access to timer etc. */

/*
 * Port "Timer"
 *      - send tempo /start/stop etc. events to this port to manipulate the 
 *        queue's timer. The queue address is specified in the destination
 *        part of the address
 *      - this port supports subscription. The received timer events are 
 *        broadcasted to all subscribed clients.
 *
 * Port "Announce"
 *      - does not receive message
 *      - supports supscription. For each client or port attaching to or 
 *        detaching from the system an announcement is send to the subscribed
 *        clients.
 *
 * Idea: the subscription mechanism might also work handy for distributing 
 * synchronisation and timing information. In this case we would ideally have
 * a list of subscribers for each type of sync (time, tick), for each timing
 * queue.
 *
 */


/* client id of our system client */
static int sysclient;


static int timer_port;
static int announce_port;




/* call-back handler for timer events */
static int event_input_timer(snd_seq_event_t * ev, void *private_data)
{
	/* handle Timer events */
	switch (ev->type) {
			/* timer stuff */
		case SND_SEQ_EVENT_START:
			//snd_printk("start playing!\n");
			snd_seq_queue_timer_start(ev->dest.queue, ev->source.client);
			break;

		case SND_SEQ_EVENT_CONTINUE:
			//snd_printk("continue playing!\n");
			snd_seq_queue_timer_continue(ev->dest.queue, ev->source.client);
			break;

		case SND_SEQ_EVENT_STOP:
			//snd_printk("stop playing!\n");
			snd_seq_queue_timer_stop(ev->dest.queue, ev->source.client);
			break;

		case SND_SEQ_EVENT_TEMPO:
			//snd_printk("tempo change!\n");
			snd_seq_queue_timer_set_tempo(ev->dest.queue, ev->source.client, ev->data.control.value);
			break;
	}
	return 1;		/* success */
}


/* call-back function for event input */
static int event_input(snd_seq_event_t * ev, void *private_data)
{
	if (ev) {
		if (ev->dest.port == timer_port) {
			/* handle Timer events */
			event_input_timer(ev, private_data);
		}
	}
	return 1;		/* success */
}

/* register our internal client */
void snd_seq_system_client_init(void)
{

	snd_seq_client_callback_t callbacks;
	snd_seq_client_info_t inf;
	snd_seq_port_info_t port;

	/* register client */
	callbacks.input = event_input;
	sysclient = snd_seq_register_kernel_client(&callbacks, NULL);

	/* set our name */
	strcpy(inf.name, "System");
	snd_seq_kernel_client_ctl(sysclient, SND_SEQ_IOCTL_SET_CLIENT_INFO, &inf);

	/* register timer */
	strcpy(port.name, "Timer");
	port.capability = SND_SEQ_PORT_CAP_SUBSCRIPTION;
	port.port_type = 0;
	snd_seq_kernel_client_ctl(sysclient, SND_SEQ_IOCTL_CREATE_PORT, &port);
	timer_port = port.port;

	//snd_printk("Registered %s as port %d\n", port.name, timer_port);


	/* register announcement port */
	strcpy(port.name, "Announce");
	port.capability = SND_SEQ_PORT_CAP_SUBSCRIPTION;
	port.port_type = 0;
	snd_seq_kernel_client_ctl(sysclient, SND_SEQ_IOCTL_CREATE_PORT, &port);
	announce_port = port.port;

	//snd_printk("Registered %s as port %d\n", port.name, timer_port);
}


/* unregister our internal client */
void snd_seq_system_client_done(void)
{
	snd_seq_unregister_kernel_client(sysclient);
}