mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
Major change to sequencer API.
The sequencer API is totally recoded with the style of "encapsulation" in other api. The structure becomes opaque and accessed only via functions. Other changes: - There is no longer group in client and port info. - snd_seq_query_subs_t is renamed to snd_seq_query_subscribe_t. - snd_seq_delete_port takes only the port id argument instead of port_info structure. - snd_seq_input/output_buffer_size are renamed as snd_seq_get_input/output_buffer_size. Similarly snd_seq_resize_input/output_buffer are renamed as snd_seq_set_input/output_buffer_size. - snd_seq_get_named_queue is renamed to snd_seq_query_named_queue. - Sync codes are removed temporarily from API. - Subscription conditions are accessed via the corresponding functions. convert_time is named now as time_update. - snd_seq_get/set_queue_owner are removed. Use snd_seq_get/set_queue_info instead. - Instrument put/get/remove structure is unified as snd_instr_header_t.
This commit is contained in:
parent
d23ff765ad
commit
88e5e45151
20 changed files with 4410 additions and 1691 deletions
|
|
@ -114,13 +114,11 @@ static void write_ev(snd_seq_event_t *ev)
|
|||
return;
|
||||
}
|
||||
while ((rc = snd_seq_event_output(seq_handle, ev)) < 0) {
|
||||
int seqfd;
|
||||
fd_set fds;
|
||||
seqfd = snd_seq_poll_descriptor(seq_handle);
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(seqfd, &fds);
|
||||
if ((rc = select(seqfd + 1, NULL, &fds, NULL, NULL)) < 0) {
|
||||
printf("select error = %i (%s)\n", rc, snd_strerror(rc));
|
||||
int npfds = snd_seq_poll_descriptors_count(seq_handle, POLLOUT);
|
||||
struct pollfd *pfds = alloca(sizeof(*pfds) * npfds);
|
||||
snd_seq_poll_descriptors(seq_handle, pfds, npfds, POLLOUT);
|
||||
if ((rc = poll(pfds, npfds, -1)) < 0) {
|
||||
printf("poll error = %i (%s)\n", rc, snd_strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -147,7 +145,7 @@ static void mytext(int type, int leng, char *msg)
|
|||
|
||||
static void do_header(int format, int ntracks, int division)
|
||||
{
|
||||
snd_seq_queue_tempo_t tempo;
|
||||
snd_seq_queue_tempo_t *tempo;
|
||||
|
||||
if (verbose >= VERB_INFO)
|
||||
printf("smf format %d, %d tracks, %d ppq\n", format, ntracks, division);
|
||||
|
|
@ -159,15 +157,16 @@ static void do_header(int format, int ntracks, int division)
|
|||
exit(1);
|
||||
}
|
||||
/* set ppq */
|
||||
snd_seq_queue_tempo_alloca(&tempo);
|
||||
/* ppq must be set before starting timer */
|
||||
if (snd_seq_get_queue_tempo(seq_handle, dest_queue, &tempo) < 0) {
|
||||
if (snd_seq_get_queue_tempo(seq_handle, dest_queue, tempo) < 0) {
|
||||
perror("get_queue_tempo");
|
||||
exit(1);
|
||||
}
|
||||
if (tempo.ppq != ppq) {
|
||||
slave_ppq = tempo.ppq;
|
||||
tempo.ppq = ppq;
|
||||
if (snd_seq_set_queue_tempo(seq_handle, dest_queue, &tempo) < 0) {
|
||||
if (snd_seq_queue_tempo_get_ppq(tempo) != ppq) {
|
||||
slave_ppq = snd_seq_queue_tempo_get_ppq(tempo);
|
||||
snd_seq_queue_tempo_set_ppq(tempo, ppq);
|
||||
if (snd_seq_set_queue_tempo(seq_handle, dest_queue, tempo) < 0) {
|
||||
perror("set_queue_tempo");
|
||||
if (!slave)
|
||||
exit(1);
|
||||
|
|
@ -176,7 +175,7 @@ static void do_header(int format, int ntracks, int division)
|
|||
} else
|
||||
slave_ppq = ppq;
|
||||
if (verbose >= VERB_INFO)
|
||||
printf("ALSA Timer updated, PPQ = %d\n", tempo.ppq);
|
||||
printf("ALSA Timer updated, PPQ = %d\n", snd_seq_queue_tempo_get_ppq(tempo));
|
||||
}
|
||||
|
||||
/* start playing... */
|
||||
|
|
@ -364,13 +363,11 @@ static snd_seq_event_t *wait_for_event(void)
|
|||
/* read event - using select syscall */
|
||||
while ((left = snd_seq_event_input(seq_handle, &input_event)) >= 0 &&
|
||||
input_event == NULL) {
|
||||
int seqfd;
|
||||
fd_set fds;
|
||||
seqfd = snd_seq_poll_descriptor(seq_handle);
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(seqfd, &fds);
|
||||
if ((left = select(seqfd + 1, &fds, NULL, NULL, NULL)) < 0) {
|
||||
printf("select error = %i (%s)\n", left, snd_strerror(left));
|
||||
int npfds = snd_seq_poll_descriptors_count(seq_handle, POLLIN);
|
||||
struct pollfd *pfds = alloca(sizeof(*pfds) * npfds);
|
||||
snd_seq_poll_descriptors(seq_handle, pfds, npfds, POLLIN);
|
||||
if ((left = poll(pfds, npfds, -1)) < 0) {
|
||||
printf("poll error = %i (%s)\n", errno, snd_strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -525,13 +522,13 @@ int main(int argc, char *argv[])
|
|||
/* open sequencer device */
|
||||
/* Here we open the device read/write mode. */
|
||||
/* Because we write SND_SEQ_EVENT_ECHO to myself to sync. */
|
||||
tmp = snd_seq_open(&seq_handle, SND_SEQ_OPEN);
|
||||
tmp = snd_seq_open(&seq_handle, "hw", SND_SEQ_OPEN_DUPLEX, 0);
|
||||
if (tmp < 0) {
|
||||
perror("open /dev/snd/seq");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
tmp = snd_seq_block_mode(seq_handle, use_blocking_mode);
|
||||
tmp = snd_seq_nonblock(seq_handle, !use_blocking_mode);
|
||||
if (tmp < 0) {
|
||||
perror("block_mode");
|
||||
exit(1);
|
||||
|
|
@ -557,7 +554,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* setup queue */
|
||||
if (dest_queue >= 0) {
|
||||
if (snd_seq_use_queue(seq_handle, dest_queue, 1) < 0) {
|
||||
if (snd_seq_set_queue_usage(seq_handle, dest_queue, 1) < 0) {
|
||||
perror("use queue");
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -580,7 +577,7 @@ int main(int argc, char *argv[])
|
|||
if (slave) {
|
||||
tmp = snd_seq_connect_from(seq_handle, my_port,
|
||||
SND_SEQ_CLIENT_SYSTEM,
|
||||
snd_seq_queue_sync_port(dest_queue));
|
||||
dest_queue + 16 /*snd_seq_queue_sync_port(dest_queue)*/);
|
||||
if (tmp < 0) {
|
||||
perror("subscribe");
|
||||
exit(1);
|
||||
|
|
|
|||
|
|
@ -3,262 +3,99 @@
|
|||
*/
|
||||
|
||||
static char *event_names[256] = {
|
||||
/* 0 */ "System",
|
||||
/* 1 */ "Result",
|
||||
/* 2 */ "Reserved 2",
|
||||
/* 3 */ "Reserved 3",
|
||||
/* 4 */ "Reserved 4",
|
||||
/* 5 */ "Note",
|
||||
/* 6 */ "Note On",
|
||||
/* 7 */ "Note Off",
|
||||
/* 8 */ "Key Pressure",
|
||||
/* 9 */ "Reserved 9",
|
||||
/* 10 */ "Controller",
|
||||
/* 11 */ "Program Change",
|
||||
/* 12 */ "Channel Pressure",
|
||||
/* 13 */ "Pitchbend",
|
||||
/* 14 */ "Control14",
|
||||
/* 15 */ "Nonregparam",
|
||||
/* 16 */ "Regparam",
|
||||
/* 17 */ "Reserved 17",
|
||||
/* 18 */ "Reserved 18",
|
||||
/* 19 */ "Reserved 19",
|
||||
/* 20 */ "Song Position",
|
||||
/* 21 */ "Song Select",
|
||||
/* 22 */ "Qframe",
|
||||
/* 23 */ "SMF Time Signature",
|
||||
/* 24 */ "SMF Key Signature",
|
||||
/* 25 */ "Reserved 25",
|
||||
/* 26 */ "Reserved 26",
|
||||
/* 27 */ "Reserved 27",
|
||||
/* 28 */ "Reserved 28",
|
||||
/* 29 */ "Reserved 29",
|
||||
/* 30 */ "Start",
|
||||
/* 31 */ "Continue",
|
||||
/* 32 */ "Stop",
|
||||
/* 33 */ "Set Position Tick",
|
||||
/* 34 */ "Set Position Time",
|
||||
/* 35 */ "Tempo",
|
||||
/* 36 */ "Clock",
|
||||
/* 37 */ "Tick",
|
||||
/* 38 */ "Reserved 38",
|
||||
/* 39 */ "Reserved 39",
|
||||
/* 40 */ "Tune Request",
|
||||
/* 41 */ "Reset",
|
||||
/* 42 */ "Active Sensing",
|
||||
/* 43 */ "Reserved 43",
|
||||
/* 44 */ "Reserved 44",
|
||||
/* 45 */ "Reserved 45",
|
||||
/* 46 */ "Reserved 46",
|
||||
/* 47 */ "Reserved 47",
|
||||
/* 48 */ "Reserved 48",
|
||||
/* 49 */ "Reserved 49",
|
||||
/* 50 */ "Echo",
|
||||
/* 51 */ "OSS",
|
||||
/* 52 */ "Reserved 52",
|
||||
/* 53 */ "Reserved 53",
|
||||
/* 54 */ "Reserved 54",
|
||||
/* 55 */ "Reserved 55",
|
||||
/* 56 */ "Reserved 56",
|
||||
/* 57 */ "Reserved 57",
|
||||
/* 58 */ "Reserved 58",
|
||||
/* 59 */ "Reserved 59",
|
||||
/* 60 */ "Client Start",
|
||||
/* 61 */ "Client Exit",
|
||||
/* 62 */ "Client Change",
|
||||
/* 63 */ "Port Start",
|
||||
/* 64 */ "Port Exit",
|
||||
/* 65 */ "Port Change",
|
||||
/* 66 */ "Port Subscribed",
|
||||
/* 67 */ "Port Used",
|
||||
/* 68 */ "Port Unsubscribed",
|
||||
/* 69 */ "Port Unused",
|
||||
/* 70 */ "Sample",
|
||||
/* 71 */ "Sample Cluster",
|
||||
/* 72 */ "Sample Start",
|
||||
/* 73 */ "Sample Stop",
|
||||
/* 74 */ "Sample Freq",
|
||||
/* 75 */ "Sample Volume",
|
||||
/* 76 */ "Sample Loop",
|
||||
/* 77 */ "Sample Position",
|
||||
/* 78 */ "Sample Private1",
|
||||
/* 79 */ "Reserved 79",
|
||||
/* 80 */ "Reserved 80",
|
||||
/* 81 */ "Reserved 81",
|
||||
/* 82 */ "Reserved 82",
|
||||
/* 83 */ "Reserved 83",
|
||||
/* 84 */ "Reserved 84",
|
||||
/* 85 */ "Reserved 85",
|
||||
/* 86 */ "Reserved 86",
|
||||
/* 87 */ "Reserved 87",
|
||||
/* 88 */ "Reserved 88",
|
||||
/* 89 */ "Reserved 89",
|
||||
/* 90 */ "User 0",
|
||||
/* 91 */ "User 1",
|
||||
/* 92 */ "User 2",
|
||||
/* 93 */ "User 3",
|
||||
/* 94 */ "User 4",
|
||||
/* 95 */ "User 5",
|
||||
/* 96 */ "User 6",
|
||||
/* 97 */ "User 7",
|
||||
/* 98 */ "User 8",
|
||||
/* 99 */ "User 9",
|
||||
/* 100 */ "Instr Begin",
|
||||
/* 101 */ "Instr End",
|
||||
/* 102 */ "Instr Info",
|
||||
/* 103 */ "Instr Info Result",
|
||||
/* 104 */ "Instr Finfo",
|
||||
/* 105 */ "Instr Finfo Result",
|
||||
/* 106 */ "Instr Reset",
|
||||
/* 107 */ "Instr Status",
|
||||
/* 108 */ "Instr Status Result",
|
||||
/* 109 */ "Instr Put",
|
||||
/* 110 */ "Instr Get",
|
||||
/* 111 */ "Instr Get Result",
|
||||
/* 112 */ "Instr Free",
|
||||
/* 113 */ "Instr List",
|
||||
/* 114 */ "Instr List Result",
|
||||
/* 115 */ "Instr Cluster",
|
||||
/* 116 */ "Instr Cluster Get",
|
||||
/* 117 */ "Instr Cluster Result",
|
||||
/* 118 */ "Instr Change",
|
||||
/* 119 */ "Reserved 119",
|
||||
/* 120 */ "Reserved 120",
|
||||
/* 121 */ "Reserved 121",
|
||||
/* 122 */ "Reserved 122",
|
||||
/* 123 */ "Reserved 123",
|
||||
/* 124 */ "Reserved 124",
|
||||
/* 125 */ "Reserved 125",
|
||||
/* 126 */ "Reserved 126",
|
||||
/* 127 */ "Reserved 127",
|
||||
/* 128 */ "Reserved 128",
|
||||
/* 129 */ "Reserved 129",
|
||||
/* 130 */ "Sysex",
|
||||
/* 131 */ "Bounce",
|
||||
/* 132 */ "Reserved 132",
|
||||
/* 133 */ "Reserved 133",
|
||||
/* 134 */ "Reserved 134",
|
||||
/* 135 */ "User Var0",
|
||||
/* 136 */ "User Var1",
|
||||
/* 137 */ "User Var2",
|
||||
/* 138 */ "User Var3",
|
||||
/* 139 */ "User Var4",
|
||||
/* 140 */ "IPC Shm",
|
||||
/* 141 */ "Reserved 141",
|
||||
/* 142 */ "Reserved 142",
|
||||
/* 143 */ "Reserved 143",
|
||||
/* 144 */ "Reserved 144",
|
||||
/* 145 */ "User IPC0",
|
||||
/* 146 */ "User IPC1",
|
||||
/* 147 */ "User IPC2",
|
||||
/* 148 */ "User IPC3",
|
||||
/* 149 */ "User IPC4",
|
||||
/* 150 */ "Reserved 150",
|
||||
/* 151 */ "Reserved 151",
|
||||
/* 152 */ "Reserved 152",
|
||||
/* 153 */ "Reserved 153",
|
||||
/* 154 */ "Reserved 154",
|
||||
/* 155 */ "Reserved 155",
|
||||
/* 156 */ "Reserved 156",
|
||||
/* 157 */ "Reserved 157",
|
||||
/* 158 */ "Reserved 158",
|
||||
/* 159 */ "Reserved 159",
|
||||
/* 160 */ "Reserved 160",
|
||||
/* 161 */ "Reserved 161",
|
||||
/* 162 */ "Reserved 162",
|
||||
/* 163 */ "Reserved 163",
|
||||
/* 164 */ "Reserved 164",
|
||||
/* 165 */ "Reserved 165",
|
||||
/* 166 */ "Reserved 166",
|
||||
/* 167 */ "Reserved 167",
|
||||
/* 168 */ "Reserved 168",
|
||||
/* 169 */ "Reserved 169",
|
||||
/* 170 */ "Reserved 170",
|
||||
/* 171 */ "Reserved 171",
|
||||
/* 172 */ "Reserved 172",
|
||||
/* 173 */ "Reserved 173",
|
||||
/* 174 */ "Reserved 174",
|
||||
/* 175 */ "Reserved 175",
|
||||
/* 176 */ "Reserved 176",
|
||||
/* 177 */ "Reserved 177",
|
||||
/* 178 */ "Reserved 178",
|
||||
/* 179 */ "Reserved 179",
|
||||
/* 180 */ "Reserved 180",
|
||||
/* 181 */ "Reserved 181",
|
||||
/* 182 */ "Reserved 182",
|
||||
/* 183 */ "Reserved 183",
|
||||
/* 184 */ "Reserved 184",
|
||||
/* 185 */ "Reserved 185",
|
||||
/* 186 */ "Reserved 186",
|
||||
/* 187 */ "Reserved 187",
|
||||
/* 188 */ "Reserved 188",
|
||||
/* 189 */ "Reserved 189",
|
||||
/* 190 */ "Reserved 190",
|
||||
/* 191 */ "Reserved 191",
|
||||
/* 192 */ "Reserved 192",
|
||||
/* 193 */ "Reserved 193",
|
||||
/* 194 */ "Reserved 194",
|
||||
/* 195 */ "Reserved 195",
|
||||
/* 196 */ "Reserved 196",
|
||||
/* 197 */ "Reserved 197",
|
||||
/* 198 */ "Reserved 198",
|
||||
/* 199 */ "Reserved 199",
|
||||
/* 200 */ "Reserved 200",
|
||||
/* 201 */ "Reserved 201",
|
||||
/* 202 */ "Reserved 202",
|
||||
/* 203 */ "Reserved 203",
|
||||
/* 204 */ "Reserved 204",
|
||||
/* 205 */ "Reserved 205",
|
||||
/* 206 */ "Reserved 206",
|
||||
/* 207 */ "Reserved 207",
|
||||
/* 208 */ "Reserved 208",
|
||||
/* 209 */ "Reserved 209",
|
||||
/* 210 */ "Reserved 210",
|
||||
/* 211 */ "Reserved 211",
|
||||
/* 212 */ "Reserved 212",
|
||||
/* 213 */ "Reserved 213",
|
||||
/* 214 */ "Reserved 214",
|
||||
/* 215 */ "Reserved 215",
|
||||
/* 216 */ "Reserved 216",
|
||||
/* 217 */ "Reserved 217",
|
||||
/* 218 */ "Reserved 218",
|
||||
/* 219 */ "Reserved 219",
|
||||
/* 220 */ "Reserved 220",
|
||||
/* 221 */ "Reserved 221",
|
||||
/* 222 */ "Reserved 222",
|
||||
/* 223 */ "Reserved 223",
|
||||
/* 224 */ "Reserved 224",
|
||||
/* 225 */ "Reserved 225",
|
||||
/* 226 */ "Reserved 226",
|
||||
/* 227 */ "Reserved 227",
|
||||
/* 228 */ "Reserved 228",
|
||||
/* 229 */ "Reserved 229",
|
||||
/* 230 */ "Reserved 230",
|
||||
/* 231 */ "Reserved 231",
|
||||
/* 232 */ "Reserved 232",
|
||||
/* 233 */ "Reserved 233",
|
||||
/* 234 */ "Reserved 234",
|
||||
/* 235 */ "Reserved 235",
|
||||
/* 236 */ "Reserved 236",
|
||||
/* 237 */ "Reserved 237",
|
||||
/* 238 */ "Reserved 238",
|
||||
/* 239 */ "Reserved 239",
|
||||
/* 240 */ "Reserved 240",
|
||||
/* 241 */ "Reserved 241",
|
||||
/* 242 */ "Reserved 242",
|
||||
/* 243 */ "Reserved 243",
|
||||
/* 244 */ "Reserved 244",
|
||||
/* 245 */ "Reserved 245",
|
||||
/* 246 */ "Reserved 246",
|
||||
/* 247 */ "Reserved 247",
|
||||
/* 248 */ "Reserved 248",
|
||||
/* 249 */ "Reserved 249",
|
||||
/* 250 */ "Reserved 250",
|
||||
/* 251 */ "Reserved 251",
|
||||
/* 252 */ "Reserved 252",
|
||||
/* 253 */ "Reserved 253",
|
||||
/* 254 */ "Reserved 254",
|
||||
/* 255 */ "None"
|
||||
[SND_SEQ_EVENT_SYSTEM]= "System",
|
||||
[SND_SEQ_EVENT_RESULT]= "Result",
|
||||
[SND_SEQ_EVENT_NOTE]= "Note",
|
||||
[SND_SEQ_EVENT_NOTEON]= "Note On",
|
||||
[SND_SEQ_EVENT_NOTEOFF]= "Note Off",
|
||||
[SND_SEQ_EVENT_KEYPRESS]= "Key Pressure",
|
||||
[SND_SEQ_EVENT_CONTROLLER]= "Controller",
|
||||
[SND_SEQ_EVENT_PGMCHANGE]= "Program Change",
|
||||
[SND_SEQ_EVENT_CHANPRESS]= "Channel Pressure",
|
||||
[SND_SEQ_EVENT_PITCHBEND]= "Pitchbend",
|
||||
[SND_SEQ_EVENT_CONTROL14]= "Control14",
|
||||
[SND_SEQ_EVENT_NONREGPARAM]= "Nonregparam",
|
||||
[SND_SEQ_EVENT_REGPARAM]= "Regparam",
|
||||
[SND_SEQ_EVENT_SONGPOS]= "Song Position",
|
||||
[SND_SEQ_EVENT_SONGSEL]= "Song Select",
|
||||
[SND_SEQ_EVENT_QFRAME]= "Qframe",
|
||||
[SND_SEQ_EVENT_TIMESIGN]= "SMF Time Signature",
|
||||
[SND_SEQ_EVENT_KEYSIGN]= "SMF Key Signature",
|
||||
[SND_SEQ_EVENT_START]= "Start",
|
||||
[SND_SEQ_EVENT_CONTINUE]= "Continue",
|
||||
[SND_SEQ_EVENT_STOP]= "Stop",
|
||||
[SND_SEQ_EVENT_SETPOS_TICK]= "Set Position Tick",
|
||||
[SND_SEQ_EVENT_SETPOS_TIME]= "Set Position Time",
|
||||
[SND_SEQ_EVENT_TEMPO]= "Tempo",
|
||||
[SND_SEQ_EVENT_CLOCK]= "Clock",
|
||||
[SND_SEQ_EVENT_TICK]= "Tick",
|
||||
[SND_SEQ_EVENT_SYNC]= "Sync",
|
||||
[SND_SEQ_EVENT_SYNC_POS]= "Sync Position",
|
||||
[SND_SEQ_EVENT_TUNE_REQUEST]= "Tune Request",
|
||||
[SND_SEQ_EVENT_RESET]= "Reset",
|
||||
[SND_SEQ_EVENT_SENSING]= "Active Sensing",
|
||||
[SND_SEQ_EVENT_ECHO]= "Echo",
|
||||
[SND_SEQ_EVENT_OSS]= "OSS",
|
||||
[SND_SEQ_EVENT_CLIENT_START]= "Client Start",
|
||||
[SND_SEQ_EVENT_CLIENT_EXIT]= "Client Exit",
|
||||
[SND_SEQ_EVENT_CLIENT_CHANGE]= "Client Change",
|
||||
[SND_SEQ_EVENT_PORT_START]= "Port Start",
|
||||
[SND_SEQ_EVENT_PORT_EXIT]= "Port Exit",
|
||||
[SND_SEQ_EVENT_PORT_CHANGE]= "Port Change",
|
||||
[SND_SEQ_EVENT_PORT_SUBSCRIBED]= "Port Subscribed",
|
||||
[SND_SEQ_EVENT_PORT_UNSUBSCRIBED]= "Port Unsubscribed",
|
||||
[SND_SEQ_EVENT_SAMPLE]= "Sample",
|
||||
[SND_SEQ_EVENT_SAMPLE_CLUSTER]= "Sample Cluster",
|
||||
[SND_SEQ_EVENT_SAMPLE_START]= "Sample Start",
|
||||
[SND_SEQ_EVENT_SAMPLE_STOP]= "Sample Stop",
|
||||
[SND_SEQ_EVENT_SAMPLE_FREQ]= "Sample Freq",
|
||||
[SND_SEQ_EVENT_SAMPLE_VOLUME]= "Sample Volume",
|
||||
[SND_SEQ_EVENT_SAMPLE_LOOP]= "Sample Loop",
|
||||
[SND_SEQ_EVENT_SAMPLE_POSITION]= "Sample Position",
|
||||
[SND_SEQ_EVENT_SAMPLE_PRIVATE1]= "Sample Private1",
|
||||
[SND_SEQ_EVENT_USR0]= "User 0",
|
||||
[SND_SEQ_EVENT_USR1]= "User 1",
|
||||
[SND_SEQ_EVENT_USR2]= "User 2",
|
||||
[SND_SEQ_EVENT_USR3]= "User 3",
|
||||
[SND_SEQ_EVENT_USR4]= "User 4",
|
||||
[SND_SEQ_EVENT_USR5]= "User 5",
|
||||
[SND_SEQ_EVENT_USR6]= "User 6",
|
||||
[SND_SEQ_EVENT_USR7]= "User 7",
|
||||
[SND_SEQ_EVENT_USR8]= "User 8",
|
||||
[SND_SEQ_EVENT_USR9]= "User 9",
|
||||
[SND_SEQ_EVENT_INSTR_BEGIN]= "Instr Begin",
|
||||
[SND_SEQ_EVENT_INSTR_END]= "Instr End",
|
||||
[SND_SEQ_EVENT_INSTR_INFO]= "Instr Info",
|
||||
[SND_SEQ_EVENT_INSTR_INFO_RESULT]= "Instr Info Result",
|
||||
[SND_SEQ_EVENT_INSTR_FINFO]= "Instr Font Info",
|
||||
[SND_SEQ_EVENT_INSTR_FINFO_RESULT]= "Instr Font Info Result",
|
||||
[SND_SEQ_EVENT_INSTR_RESET]= "Instr Reset",
|
||||
[SND_SEQ_EVENT_INSTR_STATUS]= "Instr Status",
|
||||
[SND_SEQ_EVENT_INSTR_STATUS_RESULT]= "Instr Status Result",
|
||||
[SND_SEQ_EVENT_INSTR_PUT]= "Instr Put",
|
||||
[SND_SEQ_EVENT_INSTR_GET]= "Instr Get",
|
||||
[SND_SEQ_EVENT_INSTR_GET_RESULT]= "Instr Get Result",
|
||||
[SND_SEQ_EVENT_INSTR_FREE]= "Instr Free",
|
||||
[SND_SEQ_EVENT_INSTR_LIST]= "Instr List",
|
||||
[SND_SEQ_EVENT_INSTR_LIST_RESULT]= "Instr List Result",
|
||||
[SND_SEQ_EVENT_INSTR_CLUSTER]= "Instr Cluster",
|
||||
[SND_SEQ_EVENT_INSTR_CLUSTER_GET]= "Instr Cluster Get",
|
||||
[SND_SEQ_EVENT_INSTR_CLUSTER_RESULT]= "Instr Cluster Result",
|
||||
[SND_SEQ_EVENT_INSTR_CHANGE]= "Instr Change",
|
||||
[SND_SEQ_EVENT_SYSEX]= "Sysex",
|
||||
[SND_SEQ_EVENT_BOUNCE]= "Bounce",
|
||||
[SND_SEQ_EVENT_USR_VAR0]= "User Var0",
|
||||
[SND_SEQ_EVENT_USR_VAR1]= "User Var1",
|
||||
[SND_SEQ_EVENT_USR_VAR2]= "User Var2",
|
||||
[SND_SEQ_EVENT_USR_VAR3]= "User Var3",
|
||||
[SND_SEQ_EVENT_USR_VAR4]= "User Var4",
|
||||
[SND_SEQ_EVENT_IPCSHM]= "IPC Shm",
|
||||
[SND_SEQ_EVENT_USR_VARIPC0]= "User IPC0",
|
||||
[SND_SEQ_EVENT_USR_VARIPC1]= "User IPC1",
|
||||
[SND_SEQ_EVENT_USR_VARIPC2]= "User IPC2",
|
||||
[SND_SEQ_EVENT_USR_VARIPC3]= "User IPC3",
|
||||
[SND_SEQ_EVENT_USR_VARIPC4]= "User IPC4",
|
||||
[SND_SEQ_EVENT_NONE]= "None",
|
||||
};
|
||||
|
||||
int decode_event(snd_seq_event_t * ev)
|
||||
|
|
@ -267,15 +104,15 @@ int decode_event(snd_seq_event_t * ev)
|
|||
|
||||
printf("EVENT>>> Type = %d, flags = 0x%x", ev->type, ev->flags);
|
||||
switch (ev->flags & SND_SEQ_TIME_STAMP_MASK) {
|
||||
case SND_SEQ_TIME_STAMP_TICK:
|
||||
printf(", time = %d ticks",
|
||||
ev->time.tick);
|
||||
break;
|
||||
case SND_SEQ_TIME_STAMP_REAL:
|
||||
printf(", time = %d.%09d",
|
||||
(int)ev->time.time.tv_sec,
|
||||
(int)ev->time.time.tv_nsec);
|
||||
break;
|
||||
case SND_SEQ_TIME_STAMP_TICK:
|
||||
printf(", time = %d ticks",
|
||||
ev->time.tick);
|
||||
break;
|
||||
case SND_SEQ_TIME_STAMP_REAL:
|
||||
printf(", time = %d.%09d",
|
||||
(int)ev->time.time.tv_sec,
|
||||
(int)ev->time.time.tv_nsec);
|
||||
break;
|
||||
}
|
||||
printf("\n%sSource = %d.%d, dest = %d.%d, queue = %d\n",
|
||||
space,
|
||||
|
|
@ -285,114 +122,120 @@ int decode_event(snd_seq_event_t * ev)
|
|||
ev->dest.port,
|
||||
ev->queue);
|
||||
|
||||
printf("%sEvent = %s", space, event_names[ev->type]);
|
||||
if (event_names[ev->type])
|
||||
printf("%sEvent = %s", space, event_names[ev->type]);
|
||||
else
|
||||
printf("%sEvent = Reserved %d\n", space, ev->type);
|
||||
/* decode actual event data... */
|
||||
switch (ev->type) {
|
||||
case SND_SEQ_EVENT_NOTE:
|
||||
printf("; ch=%d, note=%d, velocity=%d, off_velocity=%d, duration=%d\n",
|
||||
ev->data.note.channel,
|
||||
ev->data.note.note,
|
||||
ev->data.note.velocity,
|
||||
ev->data.note.off_velocity,
|
||||
ev->data.note.duration);
|
||||
break;
|
||||
case SND_SEQ_EVENT_NOTE:
|
||||
printf("; ch=%d, note=%d, velocity=%d, off_velocity=%d, duration=%d\n",
|
||||
ev->data.note.channel,
|
||||
ev->data.note.note,
|
||||
ev->data.note.velocity,
|
||||
ev->data.note.off_velocity,
|
||||
ev->data.note.duration);
|
||||
break;
|
||||
|
||||
case SND_SEQ_EVENT_NOTEON:
|
||||
case SND_SEQ_EVENT_NOTEOFF:
|
||||
case SND_SEQ_EVENT_KEYPRESS:
|
||||
printf("; ch=%d, note=%d, velocity=%d\n",
|
||||
ev->data.note.channel,
|
||||
ev->data.note.note,
|
||||
ev->data.note.velocity);
|
||||
break;
|
||||
case SND_SEQ_EVENT_NOTEON:
|
||||
case SND_SEQ_EVENT_NOTEOFF:
|
||||
case SND_SEQ_EVENT_KEYPRESS:
|
||||
printf("; ch=%d, note=%d, velocity=%d\n",
|
||||
ev->data.note.channel,
|
||||
ev->data.note.note,
|
||||
ev->data.note.velocity);
|
||||
break;
|
||||
|
||||
case SND_SEQ_EVENT_CONTROLLER:
|
||||
printf("; ch=%d, param=%i, value=%i\n",
|
||||
ev->data.control.channel,
|
||||
ev->data.control.param,
|
||||
ev->data.control.value);
|
||||
break;
|
||||
case SND_SEQ_EVENT_CONTROLLER:
|
||||
printf("; ch=%d, param=%i, value=%i\n",
|
||||
ev->data.control.channel,
|
||||
ev->data.control.param,
|
||||
ev->data.control.value);
|
||||
break;
|
||||
|
||||
case SND_SEQ_EVENT_PGMCHANGE:
|
||||
printf("; ch=%d, program=%i\n",
|
||||
ev->data.control.channel,
|
||||
ev->data.control.value);
|
||||
break;
|
||||
case SND_SEQ_EVENT_PGMCHANGE:
|
||||
printf("; ch=%d, program=%i\n",
|
||||
ev->data.control.channel,
|
||||
ev->data.control.value);
|
||||
break;
|
||||
|
||||
case SND_SEQ_EVENT_CHANPRESS:
|
||||
case SND_SEQ_EVENT_PITCHBEND:
|
||||
printf("; ch=%d, value=%i\n",
|
||||
ev->data.control.channel,
|
||||
ev->data.control.value);
|
||||
break;
|
||||
case SND_SEQ_EVENT_CHANPRESS:
|
||||
case SND_SEQ_EVENT_PITCHBEND:
|
||||
printf("; ch=%d, value=%i\n",
|
||||
ev->data.control.channel,
|
||||
ev->data.control.value);
|
||||
break;
|
||||
|
||||
case SND_SEQ_EVENT_SYSEX:
|
||||
{
|
||||
unsigned char *sysex = (unsigned char *) ev + sizeof(snd_seq_event_t);
|
||||
int c;
|
||||
|
||||
printf("; len=%d [", ev->data.ext.len);
|
||||
|
||||
for (c = 0; c < ev->data.ext.len; c++) {
|
||||
printf("%02x%s", sysex[c], c < ev->data.ext.len - 1 ? ":" : "");
|
||||
}
|
||||
printf("]\n");
|
||||
case SND_SEQ_EVENT_SYSEX:
|
||||
{
|
||||
unsigned char *sysex = (unsigned char *) ev + sizeof(snd_seq_event_t);
|
||||
unsigned int c;
|
||||
|
||||
printf("; len=%d [", ev->data.ext.len);
|
||||
|
||||
for (c = 0; c < ev->data.ext.len; c++) {
|
||||
printf("%02x%s", sysex[c], c < ev->data.ext.len - 1 ? ":" : "");
|
||||
}
|
||||
break;
|
||||
printf("]\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case SND_SEQ_EVENT_QFRAME:
|
||||
printf("; frame=0x%02x\n", ev->data.control.value);
|
||||
break;
|
||||
|
||||
case SND_SEQ_EVENT_CLOCK:
|
||||
case SND_SEQ_EVENT_START:
|
||||
case SND_SEQ_EVENT_CONTINUE:
|
||||
case SND_SEQ_EVENT_STOP:
|
||||
printf("; queue = %i\n", ev->data.queue.queue);
|
||||
break;
|
||||
case SND_SEQ_EVENT_QFRAME:
|
||||
printf("; frame=0x%02x\n", ev->data.control.value);
|
||||
break;
|
||||
|
||||
case SND_SEQ_EVENT_CLOCK:
|
||||
case SND_SEQ_EVENT_START:
|
||||
case SND_SEQ_EVENT_CONTINUE:
|
||||
case SND_SEQ_EVENT_STOP:
|
||||
printf("; queue = %i\n", ev->data.queue.queue);
|
||||
break;
|
||||
|
||||
case SND_SEQ_EVENT_SENSING:
|
||||
printf("\n");
|
||||
break;
|
||||
case SND_SEQ_EVENT_SENSING:
|
||||
printf("\n");
|
||||
break;
|
||||
|
||||
case SND_SEQ_EVENT_ECHO:
|
||||
{
|
||||
int i;
|
||||
case SND_SEQ_EVENT_ECHO:
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("; ");
|
||||
for (i = 0; i < 8; i++) {
|
||||
printf("%02i%s", ev->data.raw8.d[i], i < 7 ? ":" : "\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
printf("; ");
|
||||
for (i = 0; i < 8; i++) {
|
||||
printf("%02i%s", ev->data.raw8.d[i], i < 7 ? ":" : "\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SND_SEQ_EVENT_CLIENT_START:
|
||||
case SND_SEQ_EVENT_CLIENT_EXIT:
|
||||
case SND_SEQ_EVENT_CLIENT_CHANGE:
|
||||
printf("; client=%i\n", ev->data.addr.client);
|
||||
break;
|
||||
case SND_SEQ_EVENT_CLIENT_START:
|
||||
case SND_SEQ_EVENT_CLIENT_EXIT:
|
||||
case SND_SEQ_EVENT_CLIENT_CHANGE:
|
||||
printf("; client=%i\n", ev->data.addr.client);
|
||||
break;
|
||||
|
||||
case SND_SEQ_EVENT_PORT_START:
|
||||
case SND_SEQ_EVENT_PORT_EXIT:
|
||||
case SND_SEQ_EVENT_PORT_CHANGE:
|
||||
case SND_SEQ_EVENT_PORT_SUBSCRIBED:
|
||||
case SND_SEQ_EVENT_PORT_USED:
|
||||
case SND_SEQ_EVENT_PORT_UNSUBSCRIBED:
|
||||
case SND_SEQ_EVENT_PORT_UNUSED:
|
||||
printf("; client=%i, port = %i\n", ev->data.addr.client, ev->data.addr.port);
|
||||
break;
|
||||
case SND_SEQ_EVENT_PORT_START:
|
||||
case SND_SEQ_EVENT_PORT_EXIT:
|
||||
case SND_SEQ_EVENT_PORT_CHANGE:
|
||||
printf("; client=%i, port = %i\n", ev->data.addr.client, ev->data.addr.port);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("; not implemented\n");
|
||||
case SND_SEQ_EVENT_PORT_SUBSCRIBED:
|
||||
case SND_SEQ_EVENT_PORT_UNSUBSCRIBED:
|
||||
printf("; %i:%i -> %i:%i\n",
|
||||
ev->data.connect.sender.client, ev->data.connect.sender.port,
|
||||
ev->data.connect.dest.client, ev->data.connect.dest.port);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("; not implemented\n");
|
||||
}
|
||||
|
||||
|
||||
switch (ev->flags & SND_SEQ_EVENT_LENGTH_MASK) {
|
||||
case SND_SEQ_EVENT_LENGTH_FIXED:
|
||||
return sizeof(snd_seq_event_t);
|
||||
case SND_SEQ_EVENT_LENGTH_FIXED:
|
||||
return sizeof(snd_seq_event_t);
|
||||
|
||||
case SND_SEQ_EVENT_LENGTH_VARIABLE:
|
||||
return sizeof(snd_seq_event_t) + ev->data.ext.len;
|
||||
case SND_SEQ_EVENT_LENGTH_VARIABLE:
|
||||
return sizeof(snd_seq_event_t) + ev->data.ext.len;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -411,11 +254,12 @@ void event_decoder_start_timer(snd_seq_t *handle, int queue, int client, int por
|
|||
void event_decoder(snd_seq_t *handle, int argc, char *argv[])
|
||||
{
|
||||
snd_seq_event_t *ev;
|
||||
snd_seq_port_info_t port;
|
||||
snd_seq_port_subscribe_t sub;
|
||||
fd_set in;
|
||||
int client, queue, max, err, v1, v2;
|
||||
snd_seq_port_info_t *pinfo;
|
||||
snd_seq_port_subscribe_t *sub;
|
||||
snd_seq_addr_t addr;
|
||||
int client, port, queue, max, err, v1, v2;
|
||||
char *ptr;
|
||||
struct pollfd *pfds;
|
||||
|
||||
if ((client = snd_seq_client_id(handle))<0) {
|
||||
fprintf(stderr, "Cannot determine client number: %s\n", snd_strerror(client));
|
||||
|
|
@ -427,33 +271,37 @@ void event_decoder(snd_seq_t *handle, int argc, char *argv[])
|
|||
return;
|
||||
}
|
||||
printf("Queue ID = %i\n", queue);
|
||||
if ((err = snd_seq_block_mode(handle, 0))<0)
|
||||
if ((err = snd_seq_nonblock(handle, 1))<0)
|
||||
fprintf(stderr, "Cannot set nonblock mode: %s\n", snd_strerror(err));
|
||||
bzero(&port, sizeof(port));
|
||||
strcpy(port.name, "Input");
|
||||
port.capability = SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_READ;
|
||||
port.capability |= SND_SEQ_PORT_CAP_SUBS_WRITE;
|
||||
if ((err = snd_seq_create_port(handle, &port)) < 0) {
|
||||
snd_seq_port_info_alloca(&pinfo);
|
||||
snd_seq_port_info_set_name(pinfo, "Input");
|
||||
snd_seq_port_info_set_capability(pinfo, SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_WRITE);
|
||||
if ((err = snd_seq_create_port(handle, pinfo)) < 0) {
|
||||
fprintf(stderr, "Cannot create input port: %s\n", snd_strerror(err));
|
||||
return;
|
||||
}
|
||||
event_decoder_start_timer(handle, queue, client, port.port);
|
||||
port = snd_seq_port_info_get_port(pinfo);
|
||||
event_decoder_start_timer(handle, queue, client, port);
|
||||
|
||||
bzero(&sub, sizeof(sub));
|
||||
sub.sender.client = SND_SEQ_CLIENT_SYSTEM;
|
||||
sub.sender.port = SND_SEQ_PORT_SYSTEM_ANNOUNCE;
|
||||
sub.dest.client = client;
|
||||
sub.dest.port = port.port;
|
||||
sub.queue = queue;
|
||||
sub.exclusive = 0;
|
||||
sub.convert_time = 1;
|
||||
sub.realtime = 1;
|
||||
if ((err = snd_seq_subscribe_port(handle, &sub))<0) {
|
||||
snd_seq_port_subscribe_alloca(&sub);
|
||||
addr.client = SND_SEQ_CLIENT_SYSTEM;
|
||||
addr.port = SND_SEQ_PORT_SYSTEM_ANNOUNCE;
|
||||
snd_seq_port_subscribe_set_sender(sub, &addr);
|
||||
addr.client = client;
|
||||
addr.port = port;
|
||||
snd_seq_port_subscribe_set_dest(sub, &addr);
|
||||
snd_seq_port_subscribe_set_queue(sub, queue);
|
||||
snd_seq_port_subscribe_set_time_update(sub, 1);
|
||||
snd_seq_port_subscribe_set_time_real(sub, 1);
|
||||
if ((err = snd_seq_subscribe_port(handle, sub))<0) {
|
||||
fprintf(stderr, "Cannot subscribe announce port: %s\n", snd_strerror(err));
|
||||
return;
|
||||
}
|
||||
sub.sender.port = SND_SEQ_PORT_SYSTEM_TIMER;
|
||||
if ((err = snd_seq_subscribe_port(handle, &sub))<0) {
|
||||
|
||||
addr.client = SND_SEQ_CLIENT_SYSTEM;
|
||||
addr.port = SND_SEQ_PORT_SYSTEM_TIMER;
|
||||
snd_seq_port_subscribe_set_sender(sub, &addr);
|
||||
if ((err = snd_seq_subscribe_port(handle, sub))<0) {
|
||||
fprintf(stderr, "Cannot subscribe timer port: %s\n", snd_strerror(err));
|
||||
return;
|
||||
}
|
||||
|
|
@ -462,27 +310,29 @@ void event_decoder(snd_seq_t *handle, int argc, char *argv[])
|
|||
ptr = argv[max];
|
||||
if (!ptr)
|
||||
continue;
|
||||
sub.realtime = 0;
|
||||
snd_seq_port_subscribe_set_time_real(sub, 0);
|
||||
if (tolower(*ptr) == 'r') {
|
||||
sub.realtime = 1;
|
||||
snd_seq_port_subscribe_set_time_real(sub, 1);
|
||||
ptr++;
|
||||
}
|
||||
if (sscanf(ptr, "%i.%i", &v1, &v2) != 2) {
|
||||
fprintf(stderr, "Wrong argument '%s'...\n", argv[max]);
|
||||
return;
|
||||
}
|
||||
sub.sender.client = v1;
|
||||
sub.sender.port = v2;
|
||||
if ((err = snd_seq_subscribe_port(handle, &sub))<0) {
|
||||
addr.client = v1;
|
||||
addr.port = v2;
|
||||
snd_seq_port_subscribe_set_sender(sub, &addr);
|
||||
if ((err = snd_seq_subscribe_port(handle, sub))<0) {
|
||||
fprintf(stderr, "Cannot subscribe port %i from client %i: %s\n", v2, v1, snd_strerror(err));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
max = snd_seq_poll_descriptors_count(handle, POLLIN);
|
||||
pfds = alloca(sizeof(*pfds) * max);
|
||||
while (1) {
|
||||
FD_ZERO(&in);
|
||||
FD_SET(max = snd_seq_poll_descriptor(handle), &in);
|
||||
if (select(max + 1, &in, NULL, NULL, NULL) < 0)
|
||||
snd_seq_poll_descriptors(handle, pfds, max, POLLIN);
|
||||
if (poll(pfds, max, -1) < 0)
|
||||
break;
|
||||
do {
|
||||
if ((err = snd_seq_event_input(handle, &ev))<0)
|
||||
|
|
|
|||
|
|
@ -1,57 +1,65 @@
|
|||
|
||||
#ifdef USE_PCM
|
||||
#ifdef USE_PCM // XXX not yet
|
||||
/*
|
||||
* PCM timer layer
|
||||
*/
|
||||
|
||||
int pcard = 0;
|
||||
int pdevice = 0;
|
||||
int pfragment_size = 4096;
|
||||
int period_size = 1024;
|
||||
|
||||
void set_format(snd_pcm_t *phandle)
|
||||
void set_hwparams(snd_pcm_t *phandle)
|
||||
{
|
||||
int err;
|
||||
snd_pcm_format_t format;
|
||||
snd_pcm_hw_params_t *params;
|
||||
|
||||
bzero(&format, sizeof(format));
|
||||
format.sfmt = SND_PCM_FORMAT_S16_LE;
|
||||
format.channels = 2;
|
||||
format.rate = 44100;
|
||||
if ((err = snd_pcm_playback_format(phandle, &format)) < 0) {
|
||||
fprintf(stderr, "Playback format error: %s\n", snd_strerror(err));
|
||||
err = snd_output_stdio_attach(&log, stderr, 0);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "cannot attach output stdio\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
void set_fragment(snd_pcm_t *phandle)
|
||||
{
|
||||
int err;
|
||||
snd_pcm_playback_params_t pparams;
|
||||
|
||||
bzero(&pparams, sizeof(pparams));
|
||||
pparams.fragment_size = pfragment_size;
|
||||
pparams.fragments_max = -1; /* maximum */
|
||||
pparams.fragments_room = 1;
|
||||
if ((err = snd_pcm_playback_params(phandle, &pparams)) < 0) {
|
||||
fprintf(stderr, "Fragment setup error: %s\n", snd_strerror(err));
|
||||
snd_pcm_hw_params_alloca(¶ms);
|
||||
err = snd_pcm_hw_params_any(phandle, params);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "Broken configuration for this PCM: no configurations available\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
void show_playback_status(snd_pcm_t *phandle)
|
||||
{
|
||||
int err;
|
||||
snd_pcm_playback_status_t pstatus;
|
||||
|
||||
if ((err = snd_pcm_playback_status(phandle, &pstatus)) < 0) {
|
||||
fprintf(stderr, "Playback status error: %s\n", snd_strerror(err));
|
||||
err = snd_pcm_hw_params_set_access(phandle, params,
|
||||
SND_PCM_ACCESS_RW_INTERLEAVED);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "Access type not available\n");
|
||||
exit(0);
|
||||
}
|
||||
printf("Playback status\n");
|
||||
printf(" Real rate : %u\n", pstatus.rate);
|
||||
printf(" Fragments : %i\n", pstatus.fragments);
|
||||
printf(" Fragment size : %i\n", pstatus.fragment_size);
|
||||
err = snd_pcm_hw_params_set_format(phandle, params, SND_PCM_FORMAT_S16_LE);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "cannot set format\n");
|
||||
exit(0);
|
||||
}
|
||||
err = snd_pcm_hw_params_set_channels(phandle, params, 2);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "cannot set channels 2\n");
|
||||
exit(0);
|
||||
}
|
||||
err = snd_pcm_hw_params_set_rate_near(phandle, params, 44100, 0);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "cannot set rate\n");
|
||||
exit(0);
|
||||
}
|
||||
err = snd_pcm_hw_params_set_period_size_near(phandle, params, period_size);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "cannot set period size\n");
|
||||
exit(0);
|
||||
}
|
||||
err = snd_pcm_hw_params(phandle, params);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "Unable to install hw params:\n");
|
||||
exit(0);
|
||||
}
|
||||
snd_pcm_hw_params_dump(params, log);
|
||||
}
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Simple event sender
|
||||
|
|
@ -89,23 +97,15 @@ void event_sender_start_timer(snd_seq_t *handle, int client, int queue, snd_pcm_
|
|||
void event_sender_filter(snd_seq_t *handle)
|
||||
{
|
||||
int err;
|
||||
snd_seq_client_info_t info;
|
||||
|
||||
if ((err = snd_seq_get_client_info(handle, &info)) < 0) {
|
||||
fprintf(stderr, "Unable to get client info: %s\n", snd_strerror(err));
|
||||
return;
|
||||
}
|
||||
info.filter = SND_SEQ_FILTER_USE_EVENT;
|
||||
memset(&info.event_filter, 0, sizeof(info.event_filter));
|
||||
snd_seq_set_bit(SND_SEQ_EVENT_ECHO, info.event_filter);
|
||||
if ((err = snd_seq_set_client_info(handle, &info)) < 0) {
|
||||
if ((err = snd_seq_set_client_event_filter(handle, SND_SEQ_EVENT_ECHO)) < 0) {
|
||||
fprintf(stderr, "Unable to set client info: %s\n", snd_strerror(err));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void send_event(snd_seq_t *handle, int queue, int client, int port,
|
||||
snd_seq_port_subscribe_t *sub, int *time)
|
||||
snd_seq_addr_t *dest, int *time)
|
||||
{
|
||||
int err;
|
||||
snd_seq_event_t ev;
|
||||
|
|
@ -119,8 +119,7 @@ void send_event(snd_seq_t *handle, int queue, int client, int port,
|
|||
ev.type = SND_SEQ_EVENT_ECHO;
|
||||
if ((err = snd_seq_event_output(handle, &ev))<0)
|
||||
fprintf(stderr, "Event output error: %s\n", snd_strerror(err));
|
||||
ev.dest.client = sub->dest.client;
|
||||
ev.dest.port = sub->dest.port;
|
||||
ev.dest = *dest;
|
||||
ev.type = SND_SEQ_EVENT_PGMCHANGE;
|
||||
ev.data.control.channel = 0;
|
||||
ev.data.control.value = 16;
|
||||
|
|
@ -141,10 +140,11 @@ void send_event(snd_seq_t *handle, int queue, int client, int port,
|
|||
void event_sender(snd_seq_t *handle, int argc, char *argv[])
|
||||
{
|
||||
snd_seq_event_t *ev;
|
||||
snd_seq_port_info_t port;
|
||||
snd_seq_port_subscribe_t sub;
|
||||
fd_set out, in;
|
||||
int client, queue, max, err, v1, v2, time = 0, pcm_flag = 0;
|
||||
snd_seq_port_info_t *pinfo;
|
||||
snd_seq_port_subscribe_t *sub;
|
||||
snd_seq_addr_t addr;
|
||||
struct pollfd *pfds;
|
||||
int client, port, queue, max, err, v1, v2, time = 0, pcm_flag = 0;
|
||||
char *ptr;
|
||||
snd_pcm_t *phandle = NULL;
|
||||
|
||||
|
|
@ -164,20 +164,22 @@ void event_sender(snd_seq_t *handle, int argc, char *argv[])
|
|||
}
|
||||
printf("Queue ID = %i\n", queue);
|
||||
event_sender_filter(handle);
|
||||
if ((err = snd_seq_block_mode(handle, 0))<0)
|
||||
if ((err = snd_seq_nonblock(handle, 1))<0)
|
||||
fprintf(stderr, "Cannot set nonblock mode: %s\n", snd_strerror(err));
|
||||
bzero(&port, sizeof(port));
|
||||
port.capability = SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_READ;
|
||||
strcpy(port.name, "Output");
|
||||
if ((err = snd_seq_create_port(handle, &port)) < 0) {
|
||||
|
||||
snd_seq_port_info_alloca(&pinfo);
|
||||
snd_seq_port_info_set_capability(pinfo, SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_READ);
|
||||
snd_seq_port_info_set_name(pinfo, "Output");
|
||||
if ((err = snd_seq_create_port(handle, pinfo)) < 0) {
|
||||
fprintf(stderr, "Cannot create output port: %s\n", snd_strerror(err));
|
||||
return;
|
||||
}
|
||||
port = snd_seq_port_info_get_port(pinfo);
|
||||
|
||||
bzero(&sub, sizeof(sub));
|
||||
sub.sender.client = client;
|
||||
sub.sender.port = port.port;
|
||||
sub.exclusive = 0;
|
||||
snd_seq_port_subscribe_alloca(&sub);
|
||||
addr.client = client;
|
||||
addr.port = port;
|
||||
snd_seq_port_subscribe_set_sender(sub, &addr);
|
||||
|
||||
for (max = 0; max < argc; max++) {
|
||||
ptr = argv[max];
|
||||
|
|
@ -191,26 +193,25 @@ void event_sender(snd_seq_t *handle, int argc, char *argv[])
|
|||
fprintf(stderr, "Wrong argument '%s'...\n", argv[max]);
|
||||
return;
|
||||
}
|
||||
sub.dest.client = v1;
|
||||
sub.dest.port = v2;
|
||||
if ((err = snd_seq_subscribe_port(handle, &sub))<0) {
|
||||
addr.client = v1;
|
||||
addr.port = v2;
|
||||
snd_seq_port_subscribe_set_dest(sub, &addr);
|
||||
if ((err = snd_seq_subscribe_port(handle, sub))<0) {
|
||||
fprintf(stderr, "Cannot subscribe port %i from client %i: %s\n", v2, v1, snd_strerror(err));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Destination client = %i, port = %i\n", sub.dest.client, sub.dest.port);
|
||||
printf("Destination client = %i, port = %i\n", addr.client, addr.port);
|
||||
|
||||
#ifdef USE_PCM
|
||||
if (pcm_flag) {
|
||||
if ((err = snd_pcm_open(&phandle, pcard, pdevice, SND_PCM_OPEN_PLAYBACK)) < 0) {
|
||||
if ((err = snd_pcm_open(&phandle, "default", SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
|
||||
fprintf(stderr, "Playback open error: %s\n", snd_strerror(err));
|
||||
exit(0);
|
||||
}
|
||||
set_format(phandle);
|
||||
set_fragment(phandle);
|
||||
show_playback_status(phandle);
|
||||
pbuf = calloc(1, pfragment_size);
|
||||
set_hwparams(phandle);
|
||||
pbuf = calloc(1, period_size * 4);
|
||||
if (pbuf == NULL) {
|
||||
fprintf(stderr, "No enough memory...\n");
|
||||
exit(0);
|
||||
|
|
@ -220,43 +221,46 @@ void event_sender(snd_seq_t *handle, int argc, char *argv[])
|
|||
event_sender_start_timer(handle, client, queue, phandle);
|
||||
|
||||
/* send the first event */
|
||||
send_event(handle, queue, client, port.port, &sub, &time);
|
||||
|
||||
send_event(handle, queue, client, port, &addr, &time);
|
||||
#ifdef USE_PCM
|
||||
if (phandle)
|
||||
max += snd_pcm_poll_descriptors_count(phandle);
|
||||
#endif
|
||||
pfds = alloca(sizeof(*pfds) * max);
|
||||
while (1) {
|
||||
FD_ZERO(&out);
|
||||
FD_ZERO(&in);
|
||||
max = snd_seq_poll_descriptor(handle);
|
||||
FD_SET(snd_seq_poll_descriptor(handle), &in);
|
||||
if (snd_seq_event_output_pending(handle)) {
|
||||
FD_SET(snd_seq_poll_descriptor(handle), &out);
|
||||
}
|
||||
int nseqs = snd_seq_poll_descriptors_count(handle, POLLOUT|POLLIN);
|
||||
if (snd_seq_event_output_pending(handle))
|
||||
snd_seq_poll_descriptors(handle, pfds, nseqs, POLLOUT|POLLIN);
|
||||
else
|
||||
snd_seq_poll_descriptors(handle, pfds, nseqs, POLLIN);
|
||||
max = nseqs;
|
||||
#ifdef USE_PCM
|
||||
if (phandle) {
|
||||
if (snd_pcm_poll_descriptor(phandle) > max)
|
||||
max = snd_pcm_poll_descriptor(phandle);
|
||||
FD_SET(snd_pcm_poll_descriptor(phandle), &out);
|
||||
int pmax = snd_pcm_poll_descriptors_count(phandle);
|
||||
snd_seq_poll_descriptors(phandle, pfds + max, pmax);
|
||||
max += pmax;
|
||||
}
|
||||
#endif
|
||||
if (select(max + 1, &in, &out, NULL, NULL) < 0)
|
||||
if (poll(pfds, max, -1) < 0)
|
||||
break;
|
||||
#ifdef USE_PCM
|
||||
if (phandle && FD_ISSET(snd_pcm_poll_descriptor(phandle), &out)) {
|
||||
if (snd_pcm_writei(phandle, pbuf, pfragment_size) != pfragment_size) {
|
||||
if (phandle && (pfds[nseqs].revents & POLLOUT)) {
|
||||
if (snd_pcm_writei(phandle, pbuf, period_size) != period_size) {
|
||||
fprintf(stderr, "Playback write error!!\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (FD_ISSET(snd_seq_poll_descriptor(handle), &out))
|
||||
if (pfds[0].revents & POLLOUT)
|
||||
snd_seq_drain_output(handle);
|
||||
if (FD_ISSET(snd_seq_poll_descriptor(handle), &in)) {
|
||||
if (pfds[0].revents & POLLIN) {
|
||||
do {
|
||||
if ((err = snd_seq_event_input(handle, &ev))<0)
|
||||
break;
|
||||
if (!ev)
|
||||
continue;
|
||||
if (ev->type == SND_SEQ_EVENT_ECHO)
|
||||
send_event(handle, queue, client, port.port, &sub, &time);
|
||||
send_event(handle, queue, client, port, &addr, &time);
|
||||
decode_event(ev);
|
||||
snd_seq_free_event(ev);
|
||||
} while (err > 0);
|
||||
|
|
|
|||
85
test/seq.c
85
test/seq.c
|
|
@ -16,20 +16,19 @@
|
|||
#define HELPID_VERBOSE 1002
|
||||
#define HELPID_VERSION 1003
|
||||
|
||||
snd_seq_system_info_t sysinfo;
|
||||
int max_clients;
|
||||
int max_ports;
|
||||
int max_queues;
|
||||
int debug = 0;
|
||||
int verbose = 0;
|
||||
|
||||
void set_name(snd_seq_t *handle)
|
||||
{
|
||||
int err;
|
||||
snd_seq_client_info_t info;
|
||||
char name[64];
|
||||
|
||||
bzero(&info, sizeof(info));
|
||||
info.client = snd_seq_client_id(handle);
|
||||
info.type = USER_CLIENT;
|
||||
snprintf(info.name, sizeof(info.name), "SeqUtil - %i", getpid());
|
||||
if ((err = snd_seq_set_client_info(handle, &info)) < 0) {
|
||||
sprintf(name, "SeqUtil - %i", getpid());
|
||||
if ((err = snd_seq_set_client_name(handle, name)) < 0) {
|
||||
fprintf(stderr, "Set client info error: %s\n", snd_strerror(err));
|
||||
exit(0);
|
||||
}
|
||||
|
|
@ -38,78 +37,88 @@ void set_name(snd_seq_t *handle)
|
|||
void system_info(snd_seq_t *handle)
|
||||
{
|
||||
int err;
|
||||
snd_seq_system_info_t *sysinfo;
|
||||
|
||||
if ((err = snd_seq_system_info(handle, &sysinfo))<0) {
|
||||
snd_seq_system_info_alloca(&sysinfo);
|
||||
if ((err = snd_seq_system_info(handle, sysinfo))<0) {
|
||||
fprintf(stderr, "System info error: %s\n", snd_strerror(err));
|
||||
exit(0);
|
||||
}
|
||||
max_clients = snd_seq_system_info_get_clients(sysinfo);
|
||||
max_ports = snd_seq_system_info_get_ports(sysinfo);
|
||||
max_queues = snd_seq_system_info_get_ports(sysinfo);
|
||||
}
|
||||
|
||||
void show_system_info(snd_seq_t *handle)
|
||||
{
|
||||
printf("System info\n");
|
||||
printf(" Max queues : %i\n", sysinfo.queues);
|
||||
printf(" Max clients : %i\n", sysinfo.clients);
|
||||
printf(" Max ports : %i\n", sysinfo.ports);
|
||||
printf(" Max queues : %i\n", max_queues);
|
||||
printf(" Max clients : %i\n", max_clients);
|
||||
printf(" Max ports : %i\n", max_ports);
|
||||
}
|
||||
|
||||
void show_queue_status(snd_seq_t *handle, int queue)
|
||||
{
|
||||
int err, idx, min, max;
|
||||
snd_seq_queue_status_t status;
|
||||
|
||||
snd_seq_queue_status_t *status;
|
||||
|
||||
snd_seq_queue_status_alloca(&status);
|
||||
min = queue < 0 ? 0 : queue;
|
||||
max = queue < 0 ? sysinfo.queues : queue + 1;
|
||||
max = queue < 0 ? max_queues : queue + 1;
|
||||
for (idx = min; idx < max; idx++) {
|
||||
if ((err = snd_seq_get_queue_status(handle, idx, &status))<0) {
|
||||
if ((err = snd_seq_get_queue_status(handle, idx, status))<0) {
|
||||
if (err == -ENOENT)
|
||||
continue;
|
||||
fprintf(stderr, "Client %i info error: %s\n", idx, snd_strerror(err));
|
||||
exit(0);
|
||||
}
|
||||
printf("Queue %i info\n", status.queue);
|
||||
printf(" Tick : %u\n", status.tick);
|
||||
printf(" Realtime : %li.%li\n", status.time.tv_sec, status.time.tv_nsec);
|
||||
printf(" Flags : 0x%x\n", status.flags);
|
||||
printf("Queue %i info\n", snd_seq_queue_status_get_queue(status));
|
||||
printf(" Tick : %u\n", snd_seq_queue_status_get_tick_time(status));
|
||||
printf(" Realtime : %i.%i\n",
|
||||
snd_seq_queue_status_get_real_time(status)->tv_sec,
|
||||
snd_seq_queue_status_get_real_time(status)->tv_nsec);
|
||||
printf(" Flags : 0x%x\n", snd_seq_queue_status_get_status(status));
|
||||
}
|
||||
}
|
||||
|
||||
void show_port_info(snd_seq_t *handle, int client, int port)
|
||||
{
|
||||
int err, idx, min, max;
|
||||
snd_seq_port_info_t info;
|
||||
snd_seq_port_info_t *info;
|
||||
|
||||
snd_seq_port_info_alloca(&info);
|
||||
min = port < 0 ? 0 : port;
|
||||
max = port < 0 ? sysinfo.ports : port + 1;
|
||||
max = port < 0 ? max_ports : port + 1;
|
||||
for (idx = min; idx < max; idx++) {
|
||||
if ((err = snd_seq_get_any_port_info(handle, client, idx, &info))<0) {
|
||||
if ((err = snd_seq_get_any_port_info(handle, client, idx, info))<0) {
|
||||
if (err == -ENOENT)
|
||||
continue;
|
||||
fprintf(stderr, "Port %i/%i info error: %s\n", client, idx, snd_strerror(err));
|
||||
exit(0);
|
||||
}
|
||||
printf(" Port %i info\n", idx);
|
||||
printf(" Client : %i\n", info.client);
|
||||
printf(" Port : %i\n", info.port);
|
||||
printf(" Name : %s\n", info.name);
|
||||
printf(" Capability : 0x%x\n", info.capability);
|
||||
printf(" Type : 0x%x\n", info.type);
|
||||
printf(" Midi channels : %i\n", info.midi_channels);
|
||||
printf(" Synth voices : %i\n", info.synth_voices);
|
||||
printf(" Output subs : %i\n", info.write_use);
|
||||
printf(" Input subs : %i\n", info.read_use);
|
||||
printf(" Client : %i\n", snd_seq_port_info_get_client(info));
|
||||
printf(" Port : %i\n", snd_seq_port_info_get_port(info));
|
||||
printf(" Name : %s\n", snd_seq_port_info_get_name(info));
|
||||
printf(" Capability : 0x%x\n", snd_seq_port_info_get_capability(info));
|
||||
printf(" Type : 0x%x\n", snd_seq_port_info_get_type(info));
|
||||
//printf(" Midi channels : %i\n", info.midi_channels);
|
||||
//printf(" Synth voices : %i\n", info.synth_voices);
|
||||
printf(" Output subs : %i\n", snd_seq_port_info_get_write_use(info));
|
||||
printf(" Input subs : %i\n", snd_seq_port_info_get_read_use(info));
|
||||
}
|
||||
}
|
||||
|
||||
void show_client_info(snd_seq_t *handle, int client)
|
||||
{
|
||||
int err, idx, min, max;
|
||||
snd_seq_client_info_t info;
|
||||
snd_seq_client_info_t *info;
|
||||
|
||||
snd_seq_client_info_alloca(&info);
|
||||
min = client < 0 ? 0 : client;
|
||||
max = client < 0 ? sysinfo.clients : client + 1;
|
||||
max = client < 0 ? max_clients : client + 1;
|
||||
for (idx = min; idx < max; idx++) {
|
||||
if ((err = snd_seq_get_any_client_info(handle, idx, &info))<0) {
|
||||
if ((err = snd_seq_get_any_client_info(handle, idx, info))<0) {
|
||||
if (err == -ENOENT)
|
||||
continue;
|
||||
fprintf(stderr, "Client %i info error: %s\n", idx, snd_strerror(err));
|
||||
|
|
@ -117,9 +126,9 @@ void show_client_info(snd_seq_t *handle, int client)
|
|||
}
|
||||
printf("Client %i info\n", idx);
|
||||
if (verbose)
|
||||
printf(" Client : %i\n", info.client);
|
||||
printf(" Type : %s\n", info.type == KERNEL_CLIENT ? "kernel" : "user");
|
||||
printf(" Name : %s\n", info.name);
|
||||
printf(" Client : %i\n", snd_seq_client_info_get_client(info));
|
||||
printf(" Type : %s\n", snd_seq_client_info_get_type(info) == SND_SEQ_KERNEL_CLIENT ? "kernel" : "user");
|
||||
printf(" Name : %s\n", snd_seq_client_info_get_name(info));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -190,7 +199,7 @@ int main(int argc, char *argv[])
|
|||
fprintf(stderr, "seq: Specify command...\n");
|
||||
return 0;
|
||||
}
|
||||
if ((err = snd_seq_open(&handle, SND_SEQ_OPEN))<0) {
|
||||
if ((err = snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0))<0) {
|
||||
fprintf(stderr, "Open error: %s\n", snd_strerror(err));
|
||||
exit(0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue