~ubuntu-branches/debian/sid/terminatorx/sid

« back to all changes in this revision

Viewing changes to src/tX_midiin.cc

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2012-04-02 02:12:47 UTC
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: package-import@ubuntu.com-20120402021247-jkp28ktrhvjve323
Tags: upstream-3.84
Import upstream version 3.84

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
  Description: Implements MIDI input to control turntable parameters.
22
22
  
23
 
        Changes (Alexander K�nig <alex@lisas.de>:
 
23
        Changes (Alexander König <alex@lisas.de>:
24
24
        - Using a glib GIOCallback instead of polling events
25
25
        - Updating the treeview immedialtey after bind/unbind_clicked
26
26
        - Adding "remove binding" option
189
189
                                
190
190
                                list <tX_seqpar *> :: iterator sp;                      
191
191
                                
192
 
                                for (sp=tX_seqpar::all.begin(); sp!=tX_seqpar::all.end(); sp++) {
 
192
                                for (sp=tX_seqpar::all->begin(); sp!=tX_seqpar::all->end(); sp++) {
193
193
                                        if ( (*sp)->bound_midi_event.type_matches (event) ) {
194
194
                                                (*sp)->handle_midi_input (event);
195
195
                                        }
212
212
        GtkTreeIter iter;
213
213
        char tempstr[128];
214
214
        
215
 
        for (sp=tX_seqpar::all.begin(); sp!=tX_seqpar::all.end(); sp++) {
 
215
        for (sp=tX_seqpar::all->begin(); sp!=tX_seqpar::all->end(); sp++) {
216
216
                if (((*sp)->is_mappable) && ((*sp)->vtt) == (void*) vtt) {
217
217
                        
218
218
                        snprintf( tempstr, sizeof(tempstr), "Type: %d, Number: %d, Channel: %d",
450
450
        gzFile *rz=NULL;
451
451
        
452
452
        tX_store("%s<midi_connections>\n", indent);
453
 
        strcat(indent, "\t");
454
 
 
455
 
        snd_seq_addr_t my_addr;
456
 
        my_addr.client=snd_seq_client_id(ALSASeqHandle);
457
 
        my_addr.port=portid;
458
 
 
459
 
        snd_seq_query_subscribe_t *subs;
460
 
        snd_seq_query_subscribe_alloca(&subs);
461
 
        snd_seq_query_subscribe_set_root(subs, &my_addr);
462
 
        snd_seq_query_subscribe_set_type(subs, SND_SEQ_QUERY_SUBS_WRITE);
463
 
        snd_seq_query_subscribe_set_index(subs, 0);
 
453
 
 
454
        if (ALSASeqHandle != NULL) {
 
455
                strcat(indent, "\t");
 
456
                snd_seq_addr_t my_addr;
 
457
                my_addr.client=snd_seq_client_id(ALSASeqHandle);
 
458
                my_addr.port=portid;
 
459
 
 
460
                snd_seq_query_subscribe_t *subs;
 
461
                snd_seq_query_subscribe_alloca(&subs);
 
462
                snd_seq_query_subscribe_set_root(subs, &my_addr);
 
463
                snd_seq_query_subscribe_set_type(subs, SND_SEQ_QUERY_SUBS_WRITE);
 
464
                snd_seq_query_subscribe_set_index(subs, 0);
464
465
        
465
 
        while (snd_seq_query_port_subscribers(ALSASeqHandle, subs) >= 0) {
466
 
                const snd_seq_addr_t *addr;
467
 
                addr = snd_seq_query_subscribe_get_addr(subs);
468
 
                
469
 
                tX_store("%s<link client=\"%i\" port=\"%i\"/>\n", indent, addr->client, addr->port);
470
 
                snd_seq_query_subscribe_set_index(subs, snd_seq_query_subscribe_get_index(subs) + 1);
471
 
        }       
472
 
                
473
 
        indent[strlen(indent)-1]=0;
 
466
                while (snd_seq_query_port_subscribers(ALSASeqHandle, subs) >= 0) {
 
467
                        const snd_seq_addr_t *addr;
 
468
                        addr = snd_seq_query_subscribe_get_addr(subs);
 
469
                
 
470
                        tX_store("%s<link client=\"%i\" port=\"%i\"/>\n", indent, addr->client, addr->port);
 
471
                        snd_seq_query_subscribe_set_index(subs, snd_seq_query_subscribe_get_index(subs) + 1);
 
472
                }       
 
473
                
 
474
                indent[strlen(indent)-1]=0;
 
475
        }
 
476
 
474
477
        tX_store("%s</midi_connections>\n", indent);    
475
478
}
476
479
 
477
480
void tX_midiin::restore_connections(xmlNodePtr node)
478
481
{
479
482
        snd_seq_addr_t my_addr;
480
 
        my_addr.client=snd_seq_client_id(ALSASeqHandle);
481
 
        my_addr.port=portid;
482
 
        
483
 
        if (xmlStrcmp(node->name, (xmlChar *) "midi_connections")==0) {
484
 
                for (xmlNodePtr cur=node->xmlChildrenNode; cur != NULL; cur = cur->next) {
485
 
                        if (cur->type == XML_ELEMENT_NODE) {
486
 
                                if (xmlStrcmp(cur->name, (xmlChar *) "link")==0) {
487
 
                                        char *buffer;
488
 
                                        int client=-1;
489
 
                                        int port=-1;
490
 
                                        
491
 
                                        buffer=(char *) xmlGetProp(cur, (xmlChar *) "client");
492
 
                                        if (buffer) {
493
 
                                                sscanf(buffer, "%i", &client);
494
 
                                        }
495
 
                                        
496
 
                                        buffer=(char *) xmlGetProp(cur, (xmlChar *) "port");
497
 
                                        if (buffer) {
498
 
                                                sscanf(buffer, "%i", &port);
499
 
                                        }
500
 
                                        
501
 
                                        if ((port>=0) && (client>=0)) {
502
 
                                                snd_seq_addr_t sender_addr;
503
 
                                                sender_addr.client=client;
504
 
                                                sender_addr.port=port;
505
 
                                                
506
 
                                                snd_seq_port_subscribe_t *subs;
507
 
                                                snd_seq_port_subscribe_alloca(&subs);
508
 
                                                snd_seq_port_subscribe_set_sender(subs, &sender_addr);
509
 
                                                snd_seq_port_subscribe_set_dest(subs, &my_addr);
510
 
 
511
 
                                                if (snd_seq_subscribe_port(ALSASeqHandle, subs) < 0) {
512
 
                                                        tX_error("tX_midiin::restore_connections() -> failed to connect to: %d:%d.", port, client);
513
 
                                                }
 
483
        
 
484
        if (ALSASeqHandle != NULL) {
 
485
                my_addr.client=snd_seq_client_id(ALSASeqHandle);
 
486
                my_addr.port=portid;
 
487
                
 
488
                if (xmlStrcmp(node->name, (xmlChar *) "midi_connections")==0) {
 
489
                        for (xmlNodePtr cur=node->xmlChildrenNode; cur != NULL; cur = cur->next) {
 
490
                                if (cur->type == XML_ELEMENT_NODE) {
 
491
                                        if (xmlStrcmp(cur->name, (xmlChar *) "link")==0) {
 
492
                                                char *buffer;
 
493
                                                int client=-1;
 
494
                                                int port=-1;
 
495
                                                
 
496
                                                buffer=(char *) xmlGetProp(cur, (xmlChar *) "client");
 
497
                                                if (buffer) {
 
498
                                                        sscanf(buffer, "%i", &client);
 
499
                                                }
 
500
                                                
 
501
                                                buffer=(char *) xmlGetProp(cur, (xmlChar *) "port");
 
502
                                                if (buffer) {
 
503
                                                        sscanf(buffer, "%i", &port);
 
504
                                                }
 
505
                                                
 
506
                                                if ((port>=0) && (client>=0)) {
 
507
                                                        snd_seq_addr_t sender_addr;
 
508
                                                        sender_addr.client=client;
 
509
                                                        sender_addr.port=port;
 
510
                                                        
 
511
                                                        snd_seq_port_subscribe_t *subs;
 
512
                                                        snd_seq_port_subscribe_alloca(&subs);
 
513
                                                        snd_seq_port_subscribe_set_sender(subs, &sender_addr);
 
514
                                                        snd_seq_port_subscribe_set_dest(subs, &my_addr);
 
515
        
 
516
                                                        if (snd_seq_subscribe_port(ALSASeqHandle, subs) < 0) {
 
517
                                                                tX_error("tX_midiin::restore_connections() -> failed to connect to: %d:%d.", port, client);
 
518
                                                        }
 
519
                                                } else {
 
520
                                                        tX_error("tX_midiin::restore_connections() -> invalid port: %d:%d.", port, client);
 
521
                                                }
 
522
                                                
514
523
                                        } else {
515
 
                                                tX_error("tX_midiin::restore_connections() -> invalid port: %d:%d.", port, client);
 
524
                                                tX_error("tX_midiin::restore_connections() -> invalid element: %s.", cur->name);
516
525
                                        }
517
 
                                        
518
 
                                } else {
519
 
                                        tX_error("tX_midiin::restore_connections() -> invalid element: %s.", cur->name);
520
526
                                }
521
527
                        }
 
528
                } else {
 
529
                        tX_error("tX_midiin::restore_connections() -> invalid XML element.");
522
530
                }
523
531
        } else {
524
 
                tX_error("tX_midiin::restore_connections() -> invalid XML element.");
 
532
                tX_error("tX_midiin::restore_connections() -> Couldn't get ALSA sequencer handle - snd-seq module not loaded?.");
525
533
        }
526
534
}
527
535
 
629
637
                }               
630
638
        }
631
639
        
632
 
        for (sp=tX_seqpar::all.begin(); sp!=tX_seqpar::all.end(); sp++) {
 
640
        for (sp=tX_seqpar::all->begin(); sp!=tX_seqpar::all->end(); sp++) {
633
641
                (*sp)->bound_midi_event.type=tX_midievent::NONE;
634
642
                (*sp)->bound_midi_event.channel=0;
635
643
                (*sp)->bound_midi_event.number=0;