int pat_gm_drumnote(int n) { char *p; p = strchr(midipat[pat_gm_drumnr(n)-1], ':'); if( p ) return pat_getopt(p+1, "note", n); return n; }
static void mid_notes_to_percussion(MIDTRACK *tp, ULONG adjust, ULONG tmin) { MIDEVENT *e, *lno = 0; int n = 0,v; ULONG ton, toff = 0, tnext; v = 0x7f; // as loud as it gets ton = 0; for( e=tp->head; e; e=e->next ) { if( e->tracktick < adjust ) e->tracktick = 0; else e->tracktick -= adjust; if( e->flg == 1 ) { if( e->volume > 0 ) { n = e->note; e->smpno = pat_gmtosmp(pat_gm_drumnr(n)); e->note = pat_gm_drumnote(n); e->volume = (v * e->volume) / 128; if( v && !e->volume ) e->volume = 1; ton = e->tracktick; } else { toff = ton + tmin; if( toff > e->tracktick ) { tnext = mid_next_tracktick(e); if( toff + tmin < tnext ) e->tracktick = toff; else { if( toff < tnext ) e->tracktick = toff - 1; else e->tracktick = tnext - 1; } } toff = e->tracktick; lno = e; } } else { if( e->fx == mainvol ) { v = e->fxparam; if( !v && ton > toff ) { e->flg = 1; e->volume = 0; e->note = pat_gm_drumnote(n); toff = e->tracktick; lno = e; } } } } if( ton > toff ) { char info[32]; sprintf(info,"%ld > %ld note %d", (long)ton, (long)toff, n); mid_message("drum track ends with note on (%s)", info); } if( lno && lno->next ) mid_stripoff(tp, lno); }
void pat_init_patnames(void) { int z, i, nsources, isdrumset, nskip, pfnlen; char *p, *q; char line[PATH_MAX]; char cfgsources[5][PATH_MAX] = {{0}, {0}, {0}, {0}, {0}}; MMSTREAM *mmcfg; strncpy(pathforpat, PATHFORPAT, PATH_MAX); strncpy(timiditycfg, TIMIDITYCFG, PATH_MAX); p = getenv(PAT_ENV_PATH2CFG); if( p ) { strncpy(timiditycfg, p, PATH_MAX - 14); strncpy(pathforpat, p, PATH_MAX - 13); strcat(timiditycfg, "/timidity.cfg"); strcat(pathforpat, "/instruments"); } strncpy(cfgsources[0], timiditycfg, PATH_MAX - 1); nsources = 1; for( i=0; i<MAXSMP; i++ ) midipat[i][0] = '\0'; for ( z=0; z<5; z++ ) { if (cfgsources[z][0] == 0) continue; mmcfg = _mm_fopen(cfgsources[z],"r"); if( !mmcfg ) { pat_message("can not open %s, use environment variable " PAT_ENV_PATH2CFG " for the directory", cfgsources[z]); } else { // read in bank 0 and drum patches isdrumset = 0; _mm_fgets(mmcfg, line, PATH_MAX); while( !_mm_feof(mmcfg) ) { if( isdigit(line[0]) || (isblank(line[0]) && isdigit(line[1])) ) { p = line; // get pat number while ( isspace(*p) ) p ++; i = atoi(p); while ( isdigit(*p) ) p ++; while ( isspace(*p) ) p ++; // get pat file name if( *p && i < MAXSMP && i >= 0 && *p != '#' ) { q = isdrumset ? midipat[pat_gm_drumnr(i)-1] : midipat[i]; pfnlen = 0; while( *p && !isspace(*p) && *p != '#' && pfnlen < 128 ) { pfnlen ++; *q++ = *p++; } if( isblank(*p) && *(p+1) != '#' && pfnlen < 128 ) { *q++ = ':'; pfnlen ++; while( isspace(*p) ) { while( isspace(*p) ) p++; if ( *p == '#' ) { // comment } else while( *p && !isspace(*p) && pfnlen < 128 ) { pfnlen ++; *q++ = *p++; } if( isspace(*p) ) { *q++ = ' '; pfnlen++; } } } *q++ = '\0'; } } if( !strncmp(line,"drumset",7) ) isdrumset = 1; if( !strncmp(line,"source",6) && nsources < 5 ) { q = cfgsources[nsources]; p = &line[7]; while ( isspace(*p) ) p ++; pfnlen = 0; while ( *p && *p != '#' && !isspace(*p) && pfnlen < 128 ) { pfnlen ++; *q++ = *p++; } *q = 0; // null termination nsources++; } _mm_fgets(mmcfg, line, PATH_MAX); } /* end file parsing */ _mm_fclose(mmcfg); } } q = midipat[0]; nskip = 0; // make all empty patches duplicates the previous valid one. for( i=0; i<MAXSMP; i++ ) { if( midipat[i][0] ) q = midipat[i]; else { if( midipat[i] != q) strcpy(midipat[i], q); if( midipat[i][0] == '\0' ) nskip++; } } if( nskip ) { for( i=MAXSMP; i-- > 0; ) { if( midipat[i][0] ) q = midipat[i]; else if( midipat[i] != q ) strcpy(midipat[i], q); } } }
void pat_init_patnames(void) { int i,j; char *p, *q; char line[80]; MMSTREAM *mmcfg; strcpy(pathforpat, PATHFORPAT); strcpy(timiditycfg, TIMIDITYCFG); p = getenv(PAT_ENV_PATH2CFG); if( p ) { strcpy(timiditycfg,p); strcpy(pathforpat,p); strcat(timiditycfg,"/timidity.cfg"); strcat(pathforpat,"/instruments"); } mmcfg = _mm_fopen(timiditycfg,"r"); for( i=0; i<MAXSMP; i++ ) midipat[i][0] = '\0'; if( !mmcfg ) { pat_message("can not open %s, use environment variable " PAT_ENV_PATH2CFG " for the directory", timiditycfg); } else { // read in bank 0 and drum patches j = 0; _mm_fgets(mmcfg, line, 80); while( !_mm_feof(mmcfg) ) { if( isdigit(line[0]) ) { i = atoi(line); if( i < MAXSMP && i >= 0 ) { p = strchr(line,'/')+1; if(j) q = midipat[pat_gm_drumnr(i)-1]; else q = midipat[i]; while( *p && !isspace(*p) ) *q++ = *p++; if( isspace(*p) ) { *q++ = ':'; while( isspace(*p) ) { while( isspace(*p) ) p++; while( *p && !isspace(*p) ) *q++ = *p++; if( isspace(*p) ) *q++ = ' '; } } *q++ = '\0'; } } if( !strncmp(line,"drumset",7) ) j = 1; _mm_fgets(mmcfg, line, 80); } _mm_fclose(mmcfg); } q = midipat[0]; j = 0; for( i=0; i<MAXSMP; i++ ) { if( midipat[i][0] ) q = midipat[i]; else { strcpy(midipat[i],q); if( midipat[i][0] == '\0' ) j++; } } if( j ) { for( i=MAXSMP; i-- > 0; ) { if( midipat[i][0] ) q = midipat[i]; else strcpy(midipat[i],q); } } }