* Pack a program into a 32 packed sysex */
| 53 | * Pack a program into a 32 packed sysex |
| 54 | */ |
| 55 | void Cartridge::packProgram(uint8_t *src, int idx, String name, char *opSwitch) { |
| 56 | uint8_t *bulk = voiceData + 6 + (idx * 128); |
| 57 | |
| 58 | for(int op = 0; op < 6; op++) { |
| 59 | // eg rate and level, brk pt, depth, scaling |
| 60 | memcpy(bulk + op * 17, src + op * 21, 11); |
| 61 | int pp = op*17; |
| 62 | int up = op*21; |
| 63 | |
| 64 | // left curves |
| 65 | bulk[pp+11] = (src[up+11]&0x03) | ((src[up+12]&0x03) << 2); |
| 66 | bulk[pp+12] = (src[up+13]&0x07) | ((src[up+20]&0x0f) << 3); |
| 67 | // kvs_ams |
| 68 | bulk[pp+13] = (src[up+14]&0x03) | ((src[up+15]&0x07) << 2); |
| 69 | // output lvl |
| 70 | if ( opSwitch[op] == '0' ) |
| 71 | bulk[pp+14] = 0; |
| 72 | else |
| 73 | bulk[pp+14] = src[up+16]; |
| 74 | // fcoarse_mode |
| 75 | bulk[pp+15] = (src[up+17]&0x01) | ((src[up+18]&0x1f) << 1); |
| 76 | // fine freq |
| 77 | bulk[pp+16] = src[up+19]; |
| 78 | } |
| 79 | memcpy(bulk + 102, src + 126, 9); // pitch env, algo |
| 80 | bulk[111] = (src[135]&0x07) | ((src[136]&0x01) << 3); |
| 81 | memcpy(bulk + 112, src + 137, 4); // lfo |
| 82 | bulk[116] = (src[141]&0x01) | (((src[142]&0x07) << 1) | ((src[143]&0x07) << 4)); |
| 83 | bulk[117] = src[144]; |
| 84 | |
| 85 | int eos = 0; |
| 86 | |
| 87 | for(int i=0; i < 10; i++) { |
| 88 | char c = (char) name[i]; |
| 89 | if ( c == 0 ) |
| 90 | eos = 1; |
| 91 | if ( eos ) { |
| 92 | bulk[118+i] = ' '; |
| 93 | continue; |
| 94 | } |
| 95 | c = c < 32 ? ' ' : c; |
| 96 | c = c > 127 ? ' ' : c; |
| 97 | bulk[118+i] = c; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * This function normalize data that comes from corrupted sysex. |