// read void Potentiometer::read(){ tempRead=map(analogRead(pin), 0, 1023, 0, 127); if (tempRead!=lastValue) { //value changed midiCC(tempRead, lastValue); } lastValue=tempRead; }
// read void Potentiometer::read(){ if(mapped){ tempRead=constrain(analogRead(pin),inMin,inMax); tempRead=map(tempRead,inMin,inMax,0,127); } else tempRead=map(analogRead(pin), 0, 1023, 0, 127); if (tempRead!=lastValue) { //value changed midiCC(tempRead, lastValue); } lastValue=tempRead; }
// read with relative noise canceling void Potentiometer::read_n(int deviation = 8){ if(mapped){ tempRead=constrain(analogRead(pin),inMin,inMax); tempRead=map(tempRead,inMin,inMax,0,127); } else tempRead=map(analogRead(pin), 0, 1023, 0, 127); tempRead_n=analogRead(pin); if (tempRead_n<=(lastValue_n-deviation) || tempRead_n>=(lastValue_n+deviation)) { //value changed midiCC(map(tempRead_n, 0, 1023, 0, 127), map(lastValue_n, 0, 1023, 0, 127)); lastValue_n=tempRead_n; } }
// read void Potentiometer::readAvr(){ tempRead=0; for(int i=0; i<10; i++){ tempRead+=analogRead(pin); } tempRead=tempRead/10; if(mapped) { tempRead=map(constrain(tempRead,inMin,inMax),inMin,inMax,0,127); } else tempRead=map(tempRead, 0, 1023, 0, 127); if (tempRead!=lastValue) { //value changed midiCC(tempRead, lastValue); } lastValue=tempRead; }
//============================================================================== // MAIN //============================================================================== int main(int argc,char **argv) { pthread_t test; printf("SFemtoZ!\n"); int c; while ((c = getopt (argc, argv, "t:v")) != -1) switch (c) { case 't': if(pthread_create(&test,NULL,thread_test,optarg)) { printf("error thread test\n"); } break; case 'v': verbose=TRUE; break; } char sfzfile[50]; strcpy(sfzfile,USBPATH); strcat(sfzfile,argv[optind]); printf("Load SFZ: %s\n",sfzfile); loadsfz(sfzfile); //printsfz(); loadsounds(); int fd; if(( fd = serialOpen("/dev/ttyAMA0",57600))<0) { printf("serialOpen ERROR:\n",strerror(errno)); return 1; } if(configuresoundio()!=0) return 1; signal(SIGINT,exit_cli); signal(SIGTERM,exit_cli); run = TRUE; while(run) { if(serialDataAvail(fd)>2) { int type=serialGetchar(fd); while(type!=0x99 && type!= 0xB9) type=serialGetchar(fd); int note=serialGetchar(fd); int vel=serialGetchar(fd); //printf("MIDI%i(%i,%i)\n",type,note,vel); if(type==0x99) noteOn(note,vel); else midiCC(note,vel); } // soundio_wait_events(soundio); } //FINISH pthread_cancel(test); soundio_outstream_destroy(outstream); soundio_device_unref(device); soundio_destroy(soundio); serialClose(fd); freesounds(); freesfz(); return 0; }