Browse Source

Avoid hardcoded constants

Use defined constants in microx.h rather than hardcoding bank sizes
in microx.c and kmxtool.c.
develop
Damien Goutte-Gattat 8 years ago
parent
commit
44a4f469ff
  1. 2
      src/kmxtool.c
  2. 20
      src/microx.c
  3. 7
      src/microx.h

2
src/kmxtool.c

@ -171,7 +171,7 @@ do_list_programs(midi_io_t *midi)
errx(EXIT_FAILURE, "cannot dump data: %s", kmx_microx_error(midi, n));
for ( cursor = reply, bank = 'A'; bank < 'F'; bank++ ) {
for ( program = 1; program < 129; program++ ) {
for ( program = 1; program <= MICROX_BANK_SIZE; program++ ) {
printf("%c%03d %.16s\n", bank, program, cursor);
cursor += MICROX_PROGRAM_SIZE;
}

20
src/microx.c

@ -265,11 +265,11 @@ kmx_microx_parse_dump_request(const char *what, struct kmx_microx_dump *dump)
bank = *what++;
if ( bank == '*' )
dump->bank = KMX_MICROX_DUMP_ALL;
else if ( bank >= 'A' && bank <= 'E' ) {
else if ( bank >= 'A' && bank <= 'A' + MICROX_N_PROG_BANK ) {
dump->bank = bank - 'A';
if ( *what == '*' )
dump->program = KMX_MICROX_DUMP_ALL;
else if ( (val = parse_int(what)) >= 1 && val <= 128 )
else if ( (val = parse_int(what)) >= 1 && val <= MICROX_BANK_SIZE )
dump->program = val - 1;
else
ret = -1;
@ -283,11 +283,11 @@ kmx_microx_parse_dump_request(const char *what, struct kmx_microx_dump *dump)
bank = *what++;
if ( bank == '*' )
dump->bank = KMX_MICROX_DUMP_ALL;
else if ( bank >= 'A' && bank <= 'C' ) {
else if ( bank >= 'A' && bank <= 'A' + MICROX_N_COMB_BANK ) {
dump->bank = bank - 'A';
if ( *what == '*' )
dump->program = KMX_MICROX_DUMP_ALL;
else if ( (val = parse_int(what)) >= 1 && val <= 128 )
else if ( (val = parse_int(what)) >= 1 && val <= MICROX_BANK_SIZE )
dump->program = val - 1;
else
ret = -1;
@ -300,7 +300,7 @@ kmx_microx_parse_dump_request(const char *what, struct kmx_microx_dump *dump)
dump->type = MULTI_DATA;
if ( *what == '*' )
dump->program = KMX_MICROX_DUMP_ALL;
else if ( (val = parse_int(what)) >= 1 && val <= 128 )
else if ( (val = parse_int(what)) >= 1 && val <= MICROX_N_MULTI )
dump->program = val - 1;
else
ret = -1;
@ -310,7 +310,7 @@ kmx_microx_parse_dump_request(const char *what, struct kmx_microx_dump *dump)
dump->type = DRUMKIT_DATA;
if ( *what == '*' )
dump->program = KMX_MICROX_DUMP_ALL;
else if ( (val = parse_int(what)) >= 1 && val <= 40 )
else if ( (val = parse_int(what)) >= 1 && val <= MICROX_N_DRUMKIT )
dump->program = val - 1;
else
ret = -1;
@ -320,7 +320,7 @@ kmx_microx_parse_dump_request(const char *what, struct kmx_microx_dump *dump)
dump->type = ARPEGGIO_DATA;
if ( *what == '*' )
dump->program = KMX_MICROX_DUMP_ALL;
else if ( (val = parse_int(what)) >= 1 && val <= 251 )
else if ( (val = parse_int(what)) >= 1 && val <= MICROX_N_ARPEGGIO )
dump->program = val - 1;
else
ret = -1;
@ -330,7 +330,7 @@ kmx_microx_parse_dump_request(const char *what, struct kmx_microx_dump *dump)
dump->type = EXTSET_DATA;
if ( *what == '*' )
dump->program = KMX_MICROX_DUMP_ALL;
else if ( (val = parse_int(what)) >= 1 && val <= 64 )
else if ( (val = parse_int(what)) >= 1 && val <= MICROX_N_EXTSET )
dump->program = val - 1;
else
ret = -1;
@ -354,7 +354,7 @@ kmx_microx_get_dump_size(struct kmx_microx_dump *dump)
if ( dump->bank == KMX_MICROX_DUMP_ALL )
s *= MICROX_N_PROGRAM;
else if ( dump->program == KMX_MICROX_DUMP_ALL )
s *= 128;
s *= MICROX_BANK_SIZE;
break;
case COMBINATION_DATA:
@ -362,7 +362,7 @@ kmx_microx_get_dump_size(struct kmx_microx_dump *dump)
if ( dump->bank == KMX_MICROX_DUMP_ALL )
s *= MICROX_N_COMBINATION;
else if ( dump->program == KMX_MICROX_DUMP_ALL )
s *= 128;
s *= MICROX_BANK_SIZE;
break;
case MULTI_DATA:

7
src/microx.h

@ -42,8 +42,11 @@
#define KMX_OTHER_ERROR KMX_ERROR_CODE - 40
/* Numbers of memories. */
#define MICROX_N_PROGRAM 640
#define MICROX_N_COMBINATION 384
#define MICROX_N_PROG_BANK 5
#define MICROX_N_COMB_BANK 3
#define MICROX_BANK_SIZE 128
#define MICROX_N_PROGRAM MICROX_N_PROG_BANK * MICROX_BANK_SIZE
#define MICROX_N_COMBINATION MICROX_N_COMB_BANK * MICROX_BANK_SIZE
#define MICROX_N_MULTI 128
#define MICROX_N_DRUMKIT 40
#define MICROX_N_ARPEGGIO 251

Loading…
Cancel
Save