// Accept MIDI bytes then setup/remove synths as requested. void midirdy () { byte buf[40]; int bytes = read(0, buf, 40); if (-1 == bytes) err(1, "read"); if (!bytes) exit(0); for (int i=0; i<bytes; i++) { struct mm_msg m; switch (mm_inject(buf[i], &m)) { case 2: exit(1); case 1: continue; case 0: { double freq = mm_notefreq(m.arg1); int id = makeid(m.arg1, m.chan); // x/3 isn't special, it just gives decent results. if (m.type == MM_NOTEON) noteon(freq, m.arg2/3, id); if (m.type == MM_NOTEOFF) noteoff(id); }}}}
int cremid (char *buf, char *partition) { int i, n, rec; char cmd; char *ptr; ptr = buf; for (i=0; i<strlen(partition); i++) { cmd = partition[i]; if (cmd >= 'A' && cmd <= 'P') canal = cmd - 'A'; else if (cmd >= '0' && cmd <= '9') octave = cmd - '0'; else if (cmd == '(') garde = 1; else if (cmd == '*') niveau++; else if (cmd == '$') { n = sp; canal = pile[n-1-niveau].canal; freq = pile[n-1-niveau].freq; ptr += delay (ptr, 0); ptr += noteoff (ptr, canal, freq); niveau = 0; } else if (cmd == ';') { ptr += delay (ptr, tempo1); ptr += noteoff (ptr, canal1, numnote1); numnote1 = -1; } else if (cmd == ')') { ptr += delay (ptr, tempo1); ptr += noteoff (ptr, canal1, numnote1); numnote1 = 0; i++; note = partition[i] - 'a'; numnote = num_note (note, octave); ptr += delay (ptr, 0); ptr += noteoff (ptr, canal, numnote); } else if (cmd == ':') { instrument = 100 * (partition[i+1]-'0') + 10 * (partition[i+2]-'0') + partition[i+3]-'0'; ptr += delay (ptr, 0); ptr += setinstr (ptr, canal, instrument); i += 3; } else if (cmd == '!') { volume = 100 * (partition[i+1]-'0') + 10 * (partition[i+2]-'0') + partition[i+3]-'0'; i += 3; } else if (cmd == ',') { tempo *= vt; volume *= va; if (garde == 0) { int j; for (j=0; j<naccord; j++) { numnote2 = accord[j]; if (numnote2 > 0) { char d[10]; int ld; if (j == 0) ld = delay (d, tempo1); else { ld = 1; d[0] = 0; } memcpy (ptr, d, ld); ptr += ld; ptr += noteoff (ptr, canal, numnote2); } } } naccord = 0; } else if (cmd >= 'a' && cmd <= 'z') { note = cmd - 'a' + shift; if (!accords) { tempo *= vt; volume *= va; } numnote = num_note (note, octave); if (!garde && numnote1 > 0 && !accords) { ptr += delay (ptr, tempo1); ptr += noteoff (ptr, canal1, numnote1); } if (numnote1 == -1) silence = tempo1; ptr += delay (ptr, silence); ptr += noteon (ptr, canal, numnote, volume); /***/ if (accords == 1) { accord[naccord++] = numnote; } if (garde) { pile[sp].canal = canal; pile[sp].freq = numnote; sp++; } tempo1 = tempo; garde = 0; silence = 0; canal1 = canal; numnote1 = numnote; } else if (cmd == 'W') { silence = tempo1; tempo1 = tempo; } else if (cmd == 'T') { tempo = 100 * (partition[i+1]-'0') + 10 * (partition[i+2]-'0') + partition[i+3]-'0'; i += 3; } else if (cmd == 'S') { shift = 100 * (partition[i+1]-'0') + 10 * (partition[i+2]-'0') + partition[i+3]-'0'; i += 3; } else if (cmd == 'V') { char b[6]; float x; v = partition[i+1]; memcpy (b, partition+i+2, 5); b[5] = 0; sscanf (b, "%f", &x); if (v == 'T') vt = x; else if (v == '!') va = x; i += 6; } else if (cmd == '^') { mode = partition[i+1]; i++; if (mode == 'A') accords = 1; else if (mode == '1') accords = 0; } else if (cmd == 'U') { i++; if (partition[i] == '_') tempo *= 2; else if (partition[i] == '\'') tempo /= 2; else if (partition[i] == '+') { i++; tempo += 100 * (partition[i] - '0'); } else if (partition[i] == '-') { i++; tempo -= 100 * (partition[i] - '0'); } } else if (cmd == '_') tempo1 *= 2; else if (cmd == '\'') tempo1 /= 2; else if (cmd == '+') { i++; tempo1 += 100 * (partition[i] - '0'); } else if (cmd == '-') { i++; tempo1 -= 100 * (partition[i] - '0'); } } ptr += delay (ptr, tempo1); ptr += noteoff (ptr, canal1, numnote1); ptr += delay (ptr, 0); memcpy (ptr, "\xFF\x2F\x00", 3); ptr += 3; return ptr-buf; }
/* * Note On Messages (velocity=0 for NoteOff) */ void Master::NoteOn(unsigned char chan,unsigned char note,unsigned char velocity){ dump.dumpnote(chan,note,velocity); noteon(chan,note,velocity); };
void TSampler::process_signal(char* pSignal) { if ( (pSignal[0] == 'F') && (pSignal[1] == 'I') && (pSignal[2] == 'L') && (pSignal[3] == 'I') ) { char filename[cStringLength]; strcpy(filename, pSignal + 4); open_file(filename); } if ( (pSignal[0] == 'F') && (pSignal[1] == 'I') && (pSignal[2] == 'L') && (pSignal[3] == 'O') ) { char filename[cStringLength]; int length; length = (unsigned int)(pSignal[ 4]-48)*1000000000 + (unsigned int)(pSignal[ 5]-48)*100000000 + (unsigned int)(pSignal[ 6]-48)*10000000 + (unsigned int)(pSignal[ 7]-48)*1000000 + (unsigned int)(pSignal[ 8]-48)*100000 + (unsigned int)(pSignal[ 9]-48)*10000 + (unsigned int)(pSignal[10]-48)*1000 + (unsigned int)(pSignal[11]-48)*100 + (unsigned int)(pSignal[12]-48)*10 + (unsigned int)(pSignal[13]-48); strcpy(filename, pSignal + 14); write_history_to_file(length, filename); } if ( (pSignal[0] == 'N') && (pSignal[1] == 'O') && (pSignal[2] == 'T') && (pSignal[3] == 'E') ) { int polych = (unsigned int)(pSignal[4] - 48); // polych is the Poly-Channel, i.e. the index // of the channel which shall play/stop the note. if ((polych >= 0) && (polych < cPolyNum)) { if (pSignal[5] == '1') { StkFloat speedfactor = (pSignal[6] - 48) * 10 + (pSignal[7] - 48) + (pSignal[8] - 48) * 0.1 + (pSignal[9] - 48) * 0.01 + (pSignal[10] - 48) * 0.001 + (pSignal[11] - 48) * 0.0001 + (pSignal[12] - 48) * 0.00001 + (pSignal[13] - 48) * 0.000001; StkFloat velocity = StkFloat(hex2byte( pSignal[14], pSignal[15] )) / 127.0; noteon(polych, speedfactor, velocity); } else if (pSignal[5] == '0') { noteoff(polych); } } else { std::cout << "Error: The master says the slave " << "to play the poly-channel with index " << polych << ". This index is not valid " << "Please check, whether master and slave " << "use the same number of poly-channels. " << "You can find this in the" << "constant-declarations" << std::endl; } } if ( (pSignal[0] == 'V') && (pSignal[1] == 'O') && (pSignal[2] == 'L') && (pSignal[3] == 'I') ) { VolumeInc(); } if ( (pSignal[0] == 'V') && (pSignal[1] == 'O') && (pSignal[2] == 'L') && (pSignal[3] == 'D') ) { VolumeDec(); } if ( (pSignal[0] == 'A') && (pSignal[1] == 'D') && (pSignal[2] == 'S') && (pSignal[3] == 'R') ) { if (pSignal[4] == 'a') { if (pSignal[5] == '+') { zADSR_A += cADSRaStep; } else if (pSignal[5] == '-') { zADSR_A -= cADSRaStep; if (zADSR_A <= 0) { zADSR_A = cADSRaStep; } } } else if (pSignal[4] == 'd') { if (pSignal[5] == '+') { zADSR_D += cADSRdStep; } else if (pSignal[5] == '-') { zADSR_D -= cADSRdStep; if (zADSR_D <= 0) { zADSR_D = cADSRdStep; } } } else if (pSignal[4] == 's') { if (pSignal[5] == '+') { zADSR_S += cADSRsStep; if (zADSR_S > 1) { zADSR_S = 1; } if (zADSR_S < 0) { zADSR_S = 0; } } else if (pSignal[5] == '-') { zADSR_S -= cADSRsStep; } } else if (pSignal[4] == 'r') { if (pSignal[5] == '+') { zADSR_R += cADSRrStep; } else if (pSignal[5] == '-') { zADSR_R -= cADSRrStep; if (zADSR_R <= 0) { zADSR_R = cADSRrStep; } } } else if (pSignal[4] == '0') { zADSRon = 0; } else if (pSignal[4] == '1') { zADSRon = 1; } refreshADSR(); } if ( (pSignal[0] == 'S') && (pSignal[1] == 'H') && (pSignal[2] == 'O') && (pSignal[3] == 'W') && (pSignal[4] == 'A')) { printADSR(); } if ( (pSignal[0] == 'T') && (pSignal[1] == 'I') && (pSignal[2] == 'M') && (pSignal[3] == 'E') ) { int numOfFrames = (unsigned int)(pSignal[5] - 48) * 100000 + (unsigned int)(pSignal[6] - 48) * 10000 + (unsigned int)(pSignal[7] - 48) * 1000 + (unsigned int)(pSignal[8] - 48) * 100 + (unsigned int)(pSignal[9] - 48) * 10 + (unsigned int)(pSignal[10] - 48); if (pSignal[4] == '-') { numOfFrames *= -1; } TimeShift(numOfFrames); } }