Controller.C (2319B)
1 #include "Controller.h" 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <math.h> 5 6 pthread_mutex_t mutex; 7 int Pexitprogram; 8 9 Controller::Controller() { 10 //init 11 for(int i = 0; i < 6; ++i) { 12 pars[i].mode = 1; 13 pars[i].val1 = 0; 14 pars[i].val2 = 127; 15 pars[i].nrpn.cpar = 8; 16 pars[i].nrpn.fpar = 0; 17 pars[i].nrpn.cval = 0; 18 } 19 pars[0].ctl.par = 71; 20 pars[1].ctl.par = 74; 21 pars[2].ctl.par = 10; 22 pars[3].ctl.par = 11; 23 pars[4].ctl.par = 1; 24 pars[5].ctl.par = 75; 25 26 //ALSA init 27 snd_seq_open(&midi_out, "default", SND_SEQ_OPEN_OUTPUT, 0); 28 29 char portname[50]; sprintf(portname, "Controller"); 30 snd_seq_create_simple_port( 31 midi_out, 32 portname, 33 SND_SEQ_PORT_CAP_READ 34 | SND_SEQ_PORT_CAP_SUBS_READ, 35 SND_SEQ_PORT_TYPE_SYNTH); 36 } 37 38 Controller::~Controller() { 39 snd_seq_close(midi_out); 40 } 41 42 void Controller::sendcontroller(int par, unsigned char val) { 43 snd_seq_event_t midievent; 44 snd_seq_ev_clear(&midievent); 45 46 snd_seq_ev_set_controller(&midievent, Pchout, par, val); 47 48 snd_seq_ev_set_subs(&midievent); 49 snd_seq_ev_set_direct(&midievent); 50 snd_seq_event_output_direct(midi_out, &midievent); 51 52 // fprintf(stderr,"Controller: %d %d\n",par,val); 53 } 54 55 void Controller::sendnrpn(int npar, unsigned char val) { 56 // fprintf(stderr,"NRPN: %d %d %d %d\n",pars[npar].nrpn.cpar,pars[npar].nrpn.fpar,pars[npar].nrpn.cval,val); 57 58 sendcontroller(0x63, pars[npar].nrpn.cpar); 59 sendcontroller(0x62, pars[npar].nrpn.fpar); 60 sendcontroller(0x06, pars[npar].nrpn.cval); 61 sendcontroller(0x26, val); 62 // fprintf(stderr,"------------\n\n"); 63 } 64 65 void Controller::send(int npar, float xval) { 66 if(pars[npar].mode == 0) 67 return; 68 int val; 69 if(pars[npar].val1 <= pars[npar].val2) 70 val = 71 (int) (xval 72 * (pars[npar].val2 - pars[npar].val1 73 + 1.0) * 0.9999 + pars[npar].val1); 74 else 75 val = 76 (int) (xval 77 * (pars[npar].val2 - pars[npar].val1 78 - 1.0) * 0.9999 + pars[npar].val1 + 1.0); 79 switch(pars[npar].mode) { 80 case 1: sendcontroller(pars[npar].ctl.par, val); break; 81 //case 2:break; 82 case 3: sendnrpn(npar, val); break; 83 } 84 }