~ubuntu-branches/debian/squeeze/bristol/squeeze

« back to all changes in this revision

Viewing changes to libbristolmidi/midiSeqDevMan.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2009-11-10 12:21:04 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091110122104-432yau0haobyl122
Tags: 0.40.6-1
* Adopting this (Closes: #546954).
* Create new bristol-data runtime package, it will contain application's
  architecture-indipendent data files.
* Drop all patches, now useless.
* Switch to debhelper 7.
* debian/copyright: Update according to DEP-5 spec.
* debian/bristol.1: Fix little spelling mistake.
* Replace patch system, from dpatch to quilt.
* Add 01-spelling_errors.patch patch to fix spelling-error-in-binary.
* debian/rules: dh_makeshlibs doesn't touch shlibs/symbols file, libraries
  under /usr/lib/bristol/ are private.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/*
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
5
5
 *
6
6
 *
7
7
 *   This program is free software; you can redistribute it and/or modify
31
31
 
32
32
#include "bristolmidi.h"
33
33
 
34
 
/* #define DEBUG */
 
34
//#define DEBUG
35
35
 
36
36
extern bristolMidiMain bmidi;
37
37
extern int bristolFreeHandle();
54
54
        snd_seq_addr_t addr;
55
55
  
56
56
#ifdef DEBUG
57
 
        printf("bristolMidiSeqOpen(%s)\n", devname);
 
57
        if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
 
58
                printf("bristolMidiSeqOpen(%s)\n", devname);
58
59
#endif
 
60
 
59
61
#if (SND_LIB_MAJOR == 1)
60
62
        /*
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);
 
124
 
 
125
        //printf("Registering %i %i\n", addr.client, addr.port);
 
126
 
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);
 
130
 
 
131
        printf("Registered %i %i\n", addr.client, addr.port);
 
132
 
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);
326
332
*/
327
333
 
328
334
int
329
 
translate_event(snd_seq_event_t *ev, bristolMidiMsg *msg)
 
335
translate_event(snd_seq_event_t *ev, bristolMidiMsg *msg, int dev)
330
336
{
331
337
#ifdef DEBUG
332
 
        char *space = "  ";
333
 
 
334
 
        printf("EVENT>>> Type = %d, flags = 0x%x", ev->type, ev->flags);
335
 
 
336
 
        switch (ev->flags & SND_SEQ_TIME_STAMP_MASK) {
337
 
                case SND_SEQ_TIME_STAMP_TICK:
338
 
                        printf(", time = %d ticks", ev->time.tick);
339
 
                        break;
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);
344
 
                        break;
 
338
        if ((bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
 
339
                && (ev->type != SND_SEQ_EVENT_CLOCK)) /* Very chatty, naturally */
 
340
        {
 
341
                char *space = "  ";
 
342
 
 
343
                printf("\nEVENT>>> Type = %d, flags = 0x%x", ev->type, ev->flags);
 
344
 
 
345
                switch (ev->flags & SND_SEQ_TIME_STAMP_MASK) {
 
346
                        case SND_SEQ_TIME_STAMP_TICK:
 
347
                                printf(", time = %d ticks", ev->time.tick);
 
348
                                break;
 
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);
 
353
                                break;
 
354
                }
 
355
 
 
356
                printf("\n%sSource = %d.%d, dest = %d.%d, queue = %d\n",
 
357
                        space,
 
358
                        ev->source.client,
 
359
                        ev->source.port,
 
360
                        ev->dest.client,
 
361
                        ev->dest.port,
 
362
                        ev->queue);
345
363
        }
346
 
 
347
 
        printf("\n%sSource = %d.%d, dest = %d.%d, queue = %d\n",
348
 
                space,
349
 
                ev->source.client,
350
 
                ev->source.port,
351
 
                ev->dest.client,
352
 
                ev->dest.port,
353
 
                ev->queue);
354
 
 
355
 
/*
356
 
        if (event_names[ev->type])
357
 
                printf("%sEvent = %s", space, event_names[ev->type]);
358
 
        else
359
 
                printf("%sEvent = Reserved %d\n", space, ev->type);
360
 
*/
361
364
#endif
362
365
 
363
366
        msg->command = 0xff;
369
372
        switch (ev->type) {
370
373
                case SND_SEQ_EVENT_NOTE:
371
374
#ifdef DEBUG
372
 
                        printf(
 
375
                        if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
 
376
                                printf(
373
377
                                "; ch=%d, note=%d, velocity=%d, off_velocity=%d, duration=%d\n",
374
 
                                ev->data.note.channel,
375
 
                                ev->data.note.note,
376
 
                                ev->data.note.velocity,
377
 
                                ev->data.note.off_velocity,
378
 
                                ev->data.note.duration);
 
378
                                        ev->data.note.channel,
 
379
                                        ev->data.note.note,
 
380
                                        ev->data.note.velocity,
 
381
                                        ev->data.note.off_velocity,
 
382
                                        ev->data.note.duration);
379
383
#endif
380
384
                        break;
381
385
 
382
386
                case SND_SEQ_EVENT_NOTEON:
383
 
#ifdef DEBUG
384
 
                        printf("; ch=%d, note=%d, velocity=%d\n",
385
 
                                ev->data.note.channel,
386
 
                                ev->data.note.note,
387
 
                                ev->data.note.velocity);
388
 
#endif
 
387
                        if (dev)
 
388
                                printf("c%i-%02x/%02x/%02x ",
 
389
                                        dev,
 
390
                                        ev->data.note.channel,
 
391
                                        ev->data.note.note,
 
392
                                        ev->data.note.velocity);
 
393
 
389
394
                        if (ev->data.note.velocity == 0) {
390
395
                                msg->command = MIDI_NOTE_OFF;
391
396
                                msg->params.key.velocity = 64;
395
400
                        }
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;
398
405
                        break;
399
406
 
400
407
                case SND_SEQ_EVENT_NOTEOFF:
401
 
#ifdef DEBUG
402
 
                        printf("; ch=%d, note=%d, velocity=%d\n",
403
 
                                ev->data.note.channel,
404
 
                                ev->data.note.note,
405
 
                                ev->data.note.velocity);
406
 
#endif
 
408
                        if (dev)
 
409
                                printf("c%i-%02x/%02x/%02x ",
 
410
                                        dev,
 
411
                                        ev->data.note.channel,
 
412
                                        ev->data.note.note,
 
413
                                        ev->data.note.velocity);
 
414
 
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;
411
421
                        break;
412
422
 
413
423
                case SND_SEQ_EVENT_KEYPRESS:
414
424
#ifdef DEBUG
415
 
                        printf("; ch=%d, note=%d, velocity=%d\n",
416
 
                                ev->data.note.channel,
417
 
                                ev->data.note.note,
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,
 
428
                                        ev->data.note.note,
 
429
                                        ev->data.note.velocity);
419
430
#endif
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;
424
436
                        break;
425
437
 
426
438
                case SND_SEQ_EVENT_CONTROLLER:
427
 
#ifdef DEBUG
428
 
                        printf("; ch=%d, param=%i, value=%i\n",
429
 
                                ev->data.control.channel,
430
 
                                ev->data.control.param,
431
 
                                ev->data.control.value);
432
 
#endif
 
439
                        if (dev)
 
440
                                printf("c%i-%02x/%02x/%02x ",
 
441
                                        dev,
 
442
                                        ev->data.control.channel,
 
443
                                        ev->data.control.param,
 
444
                                        ev->data.control.value);
 
445
 
433
446
                        /*
434
447
                         * Hm, we may need to recode these to 7 bit midi values?
435
448
                         */
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;
440
455
 
441
456
                        /*
442
457
                         * We should also stuff the GM-2 table for defined controller 
449
464
                        /*
450
465
                         * May need to have a registered callback here from GUI.
451
466
                         */
452
 
#ifdef DEBUG
453
 
                        printf("; ch=%d, program=%i\n",
454
 
                                ev->data.control.channel,
455
 
                                ev->data.control.value);
456
 
#endif
 
467
                        if (dev)
 
468
                                printf("c%i-%02x/%02x ",
 
469
                                        dev,
 
470
                                        ev->data.control.channel,
 
471
                                        ev->data.control.value);
 
472
 
457
473
 
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;
461
479
 
462
480
                        break;
463
481
 
464
482
                case SND_SEQ_EVENT_CHANPRESS:
465
 
#ifdef DEBUG
466
 
                        printf("; ch=%d, value=%i\n",
467
 
                                ev->data.control.channel,
468
 
                                ev->data.control.value);
469
 
#endif
 
483
                        if (dev)
 
484
                                printf("c%i-%02x/%02x ",
 
485
                                        dev,
 
486
                                        ev->data.control.channel,
 
487
                                        ev->data.control.value);
 
488
 
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;
473
494
                        break;
474
495
 
475
496
                case SND_SEQ_EVENT_PITCHBEND:
476
 
#ifdef DEBUG
477
 
                        printf("; ch=%d, value=%i\n",
478
 
                                ev->data.control.channel,
479
 
                                ev->data.control.value);
480
 
#endif
 
497
                        if (dev)
 
498
                                printf("c%i-%02x/%02x ",
 
499
                                        dev,
 
500
                                        ev->data.control.channel,
 
501
                                        ev->data.control.value);
481
502
 
482
503
                        /*
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;
490
513
                        break;
491
514
 
492
515
                case SND_SEQ_EVENT_SYSEX:
 
516
#ifdef DEBUG
 
517
                        if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
493
518
                        {
494
 
#ifdef DEBUG
495
519
                                unsigned char *sysex =
496
520
                                        (unsigned char *) ev + sizeof(snd_seq_event_t);
497
521
                                unsigned int c;
503
527
                                                sysex[c], c < ev->data.ext.len - 1 ? ":" : "");
504
528
                                }
505
529
                                printf("]\n");
 
530
                        }
506
531
#endif
507
 
                                /*
508
 
                                 * Hm, we should at least see if this is a SLab message?
509
 
                                 */
510
 
                        }
 
532
                        /*
 
533
                         * Hm, we should at least see if this is a SLab message?
 
534
                         */
511
535
                        break;
512
536
 
513
537
                case SND_SEQ_EVENT_QFRAME:
514
538
#ifdef DEBUG
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);
516
541
#endif
517
542
                        break;
518
543
 
520
545
                case SND_SEQ_EVENT_START:
521
546
                case SND_SEQ_EVENT_CONTINUE:
522
547
                case SND_SEQ_EVENT_STOP:
523
 
#ifdef DEBUG
524
 
                        printf("; queue = %i\n", ev->data.queue.queue);
 
548
#ifdef DONT_DEBUG
 
549
                        if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
 
550
                                printf("; queue = %i\n", ev->data.queue.queue);
525
551
#endif
526
552
                        break;
527
553
 
532
558
                        break;
533
559
 
534
560
                case SND_SEQ_EVENT_ECHO:
 
561
#ifdef DEBUG
 
562
                        if (bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG)
535
563
                        {
536
 
#ifdef DEBUG
537
564
                                int i;
538
565
                                printf("; ");
539
566
                                for (i = 0; i < 8; i++) {
540
567
                                        printf("%02i%s", ev->data.raw8.d[i], i < 7 ? ":" : "\n");
541
568
                                }
 
569
                        }
542
570
#endif
543
 
                        }
544
571
                        break;
545
572
 
546
573
                case SND_SEQ_EVENT_CLIENT_START:
547
574
                case SND_SEQ_EVENT_CLIENT_EXIT:
548
575
                case SND_SEQ_EVENT_CLIENT_CHANGE:
549
576
#ifdef DEBUG
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);
551
579
#endif
552
580
                        break;
553
581
 
555
583
                case SND_SEQ_EVENT_PORT_EXIT:
556
584
                case SND_SEQ_EVENT_PORT_CHANGE:
557
585
#ifdef DEBUG
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);
560
589
#endif
561
590
                        break;
562
591
 
563
592
                case SND_SEQ_EVENT_PORT_SUBSCRIBED:
564
593
                case SND_SEQ_EVENT_PORT_UNSUBSCRIBED:
565
594
#ifdef DEBUG
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);
569
601
#endif
570
602
                        break;
571
603
 
609
641
        while ((res = snd_seq_event_input(bmidi.dev[dev].driver.seq.handle, &ev))
610
642
                > 0)
611
643
        {
612
 
                translate_event(ev, msg);
 
644
                translate_event(ev, msg,
 
645
                        bmidi.dev[dev].flags & _BRISTOL_MIDI_DEBUG? dev: 0);
613
646
 
614
647
                if (msg->command != 0xff)
615
648
                {