3
3
* Diverse Bristol midi routines.
4
* Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2008
4
* Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2009
7
7
* This program is free software; you can redistribute it and/or modify
54
54
snd_seq_addr_t addr;
57
printf("bristolMidiSeqOpen(%s)\n", devname);
57
if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
58
printf("bristolMidiSeqOpen(%s)\n", devname);
59
61
#if (SND_LIB_MAJOR == 1)
61
63
* Well, we got here, so I could perhaps consider assuming that we have
119
121
snd_seq_port_subscribe_alloca(&sub);
120
122
addr.client = SND_SEQ_CLIENT_SYSTEM;
121
123
addr.port = SND_SEQ_PORT_SYSTEM_ANNOUNCE;
122
printf("Registering %i %i\n", addr.client, addr.port);
125
//printf("Registering %i %i\n", addr.client, addr.port);
123
127
snd_seq_port_subscribe_set_sender(sub, &addr);
124
128
addr.client = client;
125
129
addr.port = port;
126
printf("Registered %i %i\n", addr.client, addr.port);
131
printf("Registered %i %i\n", addr.client, addr.port);
127
133
snd_seq_port_subscribe_set_dest(sub, &addr);
128
134
snd_seq_port_subscribe_set_queue(sub, queue);
129
135
snd_seq_port_subscribe_set_time_update(sub, 1);
329
translate_event(snd_seq_event_t *ev, bristolMidiMsg *msg)
335
translate_event(snd_seq_event_t *ev, bristolMidiMsg *msg, int dev)
334
printf("EVENT>>> Type = %d, flags = 0x%x", ev->type, ev->flags);
336
switch (ev->flags & SND_SEQ_TIME_STAMP_MASK) {
337
case SND_SEQ_TIME_STAMP_TICK:
338
printf(", time = %d ticks", ev->time.tick);
340
case SND_SEQ_TIME_STAMP_REAL:
341
printf(", time = %d.%09d",
342
(int)ev->time.time.tv_sec,
343
(int)ev->time.time.tv_nsec);
338
if ((bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
339
&& (ev->type != SND_SEQ_EVENT_CLOCK)) /* Very chatty, naturally */
343
printf("\nEVENT>>> Type = %d, flags = 0x%x", ev->type, ev->flags);
345
switch (ev->flags & SND_SEQ_TIME_STAMP_MASK) {
346
case SND_SEQ_TIME_STAMP_TICK:
347
printf(", time = %d ticks", ev->time.tick);
349
case SND_SEQ_TIME_STAMP_REAL:
350
printf(", time = %d.%09d",
351
(int)ev->time.time.tv_sec,
352
(int)ev->time.time.tv_nsec);
356
printf("\n%sSource = %d.%d, dest = %d.%d, queue = %d\n",
347
printf("\n%sSource = %d.%d, dest = %d.%d, queue = %d\n",
356
if (event_names[ev->type])
357
printf("%sEvent = %s", space, event_names[ev->type]);
359
printf("%sEvent = Reserved %d\n", space, ev->type);
363
366
msg->command = 0xff;
369
372
switch (ev->type) {
370
373
case SND_SEQ_EVENT_NOTE:
375
if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
373
377
"; ch=%d, note=%d, velocity=%d, off_velocity=%d, duration=%d\n",
374
ev->data.note.channel,
376
ev->data.note.velocity,
377
ev->data.note.off_velocity,
378
ev->data.note.duration);
378
ev->data.note.channel,
380
ev->data.note.velocity,
381
ev->data.note.off_velocity,
382
ev->data.note.duration);
382
386
case SND_SEQ_EVENT_NOTEON:
384
printf("; ch=%d, note=%d, velocity=%d\n",
385
ev->data.note.channel,
387
ev->data.note.velocity);
388
printf("c%i-%02x/%02x/%02x ",
390
ev->data.note.channel,
392
ev->data.note.velocity);
389
394
if (ev->data.note.velocity == 0) {
390
395
msg->command = MIDI_NOTE_OFF;
391
396
msg->params.key.velocity = 64;
396
401
msg->channel = ev->data.note.channel;
397
402
msg->params.key.key = ev->data.note.note;
403
msg->sequence = bmidi.dev[dev].sequence++;
404
msg->params.bristol.msgLen = 3;
400
407
case SND_SEQ_EVENT_NOTEOFF:
402
printf("; ch=%d, note=%d, velocity=%d\n",
403
ev->data.note.channel,
405
ev->data.note.velocity);
409
printf("c%i-%02x/%02x/%02x ",
411
ev->data.note.channel,
413
ev->data.note.velocity);
407
415
msg->command = MIDI_NOTE_OFF;
408
416
msg->channel = ev->data.note.channel;
409
417
msg->params.key.key = ev->data.note.note,
410
418
msg->params.key.velocity = ev->data.note.velocity;
419
msg->sequence = bmidi.dev[dev].sequence++;
420
msg->params.bristol.msgLen = 3;
413
423
case SND_SEQ_EVENT_KEYPRESS:
415
printf("; ch=%d, note=%d, velocity=%d\n",
416
ev->data.note.channel,
418
ev->data.note.velocity);
425
if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
426
printf("; ch=%d, note=%d, velocity=%d\n",
427
ev->data.note.channel,
429
ev->data.note.velocity);
420
431
msg->command = MIDI_POLY_PRESS;
421
432
msg->channel = ev->data.note.channel;
422
433
msg->params.pressure.key = ev->data.note.note,
423
434
msg->params.pressure.pressure = ev->data.note.velocity;
435
msg->params.bristol.msgLen = 3;
426
438
case SND_SEQ_EVENT_CONTROLLER:
428
printf("; ch=%d, param=%i, value=%i\n",
429
ev->data.control.channel,
430
ev->data.control.param,
431
ev->data.control.value);
440
printf("c%i-%02x/%02x/%02x ",
442
ev->data.control.channel,
443
ev->data.control.param,
444
ev->data.control.value);
434
447
* Hm, we may need to recode these to 7 bit midi values?
437
450
msg->channel = ev->data.control.channel;
438
451
msg->params.controller.c_id = ev->data.control.param,
439
452
msg->params.controller.c_val = ev->data.control.value;
453
msg->sequence = bmidi.dev[dev].sequence++;
454
msg->params.bristol.msgLen = 3;
442
457
* We should also stuff the GM-2 table for defined controller
450
465
* May need to have a registered callback here from GUI.
453
printf("; ch=%d, program=%i\n",
454
ev->data.control.channel,
455
ev->data.control.value);
468
printf("c%i-%02x/%02x ",
470
ev->data.control.channel,
471
ev->data.control.value);
458
474
msg->command = MIDI_PROGRAM;
459
475
msg->channel = ev->data.control.channel;
460
476
msg->params.program.p_id = ev->data.control.value;
477
msg->sequence = bmidi.dev[dev].sequence++;
478
msg->params.bristol.msgLen = 2;
464
482
case SND_SEQ_EVENT_CHANPRESS:
466
printf("; ch=%d, value=%i\n",
467
ev->data.control.channel,
468
ev->data.control.value);
484
printf("c%i-%02x/%02x ",
486
ev->data.control.channel,
487
ev->data.control.value);
470
489
msg->command = MIDI_CONTROL;
471
490
msg->channel = ev->data.control.channel;
472
491
msg->params.channelpress.pressure = ev->data.control.value;
492
msg->sequence = bmidi.dev[dev].sequence++;
493
msg->params.bristol.msgLen = 2;
475
496
case SND_SEQ_EVENT_PITCHBEND:
477
printf("; ch=%d, value=%i\n",
478
ev->data.control.channel,
479
ev->data.control.value);
498
printf("c%i-%02x/%02x ",
500
ev->data.control.channel,
501
ev->data.control.value);
483
504
* Hm, we may need to recode these to 7 bit midi values?
487
508
ev->data.control.value += 8192;
488
509
msg->params.pitch.lsb = ev->data.control.value & 0x7f;
489
510
msg->params.pitch.msb = ev->data.control.value >> 7;
511
msg->sequence = bmidi.dev[dev].sequence++;
512
msg->params.bristol.msgLen = 3;
492
515
case SND_SEQ_EVENT_SYSEX:
517
if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
495
519
unsigned char *sysex =
496
520
(unsigned char *) ev + sizeof(snd_seq_event_t);
503
527
sysex[c], c < ev->data.ext.len - 1 ? ":" : "");
508
* Hm, we should at least see if this is a SLab message?
533
* Hm, we should at least see if this is a SLab message?
513
537
case SND_SEQ_EVENT_QFRAME:
515
printf("; frame=0x%02x\n", ev->data.control.value);
539
if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
540
printf("; frame=0x%02x\n", ev->data.control.value);
520
545
case SND_SEQ_EVENT_START:
521
546
case SND_SEQ_EVENT_CONTINUE:
522
547
case SND_SEQ_EVENT_STOP:
524
printf("; queue = %i\n", ev->data.queue.queue);
549
if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
550
printf("; queue = %i\n", ev->data.queue.queue);
534
560
case SND_SEQ_EVENT_ECHO:
562
if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
539
566
for (i = 0; i < 8; i++) {
540
567
printf("%02i%s", ev->data.raw8.d[i], i < 7 ? ":" : "\n");
546
573
case SND_SEQ_EVENT_CLIENT_START:
547
574
case SND_SEQ_EVENT_CLIENT_EXIT:
548
575
case SND_SEQ_EVENT_CLIENT_CHANGE:
550
printf("; client=%i\n", ev->data.addr.client);
577
if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
578
printf("; client=%i\n", ev->data.addr.client);
555
583
case SND_SEQ_EVENT_PORT_EXIT:
556
584
case SND_SEQ_EVENT_PORT_CHANGE:
558
printf("; client=%i, port = %i\n",
559
ev->data.addr.client, ev->data.addr.port);
586
if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
587
printf("; client=%i, port = %i\n",
588
ev->data.addr.client, ev->data.addr.port);
563
592
case SND_SEQ_EVENT_PORT_SUBSCRIBED:
564
593
case SND_SEQ_EVENT_PORT_UNSUBSCRIBED:
566
printf("; %i:%i -> %i:%i\n",
567
ev->data.connect.sender.client, ev->data.connect.sender.port,
568
ev->data.connect.dest.client, ev->data.connect.dest.port);
595
if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
596
printf("; %i:%i -> %i:%i\n",
597
ev->data.connect.sender.client,
598
ev->data.connect.sender.port,
599
ev->data.connect.dest.client,
600
ev->data.connect.dest.port);
609
641
while ((res = snd_seq_event_input(bmidi.dev[dev].driver.seq.handle, &ev))
612
translate_event(ev, msg);
644
translate_event(ev, msg,
645
bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG? dev: 0);
614
647
if (msg->command != 0xff)