From 4c33b5e9573608ce5f7ae845e59a97f087d1aa9d Mon Sep 17 00:00:00 2001 From: JP Cimalando Date: Sun, 4 Nov 2018 01:39:36 +0100 Subject: update the WOPL library with fixes --- src/wopl/wopl_file.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src/wopl/wopl_file.c') diff --git a/src/wopl/wopl_file.c b/src/wopl/wopl_file.c index f018cbc..6e9103b 100644 --- a/src/wopl/wopl_file.c +++ b/src/wopl/wopl_file.c @@ -77,18 +77,30 @@ static void fromSint16BE(int16_t in, uint8_t *arr) WOPLFile *WOPL_Init(uint16_t melodic_banks, uint16_t percussive_banks) { - WOPLFile *file = NULL; - if(melodic_banks == 0) - return NULL; - if(percussive_banks == 0) - return NULL; - file = (WOPLFile*)calloc(1, sizeof(WOPLFile)); + WOPLFile *file = (WOPLFile*)calloc(1, sizeof(WOPLFile)); if(!file) return NULL; - file->banks_count_melodic = melodic_banks; - file->banks_count_percussion = percussive_banks; - file->banks_melodic = (WOPLBank*)calloc(1, sizeof(WOPLBank) * melodic_banks ); - file->banks_percussive = (WOPLBank*)calloc(1, sizeof(WOPLBank) * percussive_banks ); + + file->banks_count_melodic = (melodic_banks != 0) ? melodic_banks : 1; + file->banks_melodic = (WOPLBank*)calloc(file->banks_count_melodic, sizeof(WOPLBank)); + + if(melodic_banks == 0) + { + unsigned i; + for(i = 0; i < 128; ++i) + file->banks_melodic[0].ins[i].inst_flags = WOPL_Ins_IsBlank; + } + + file->banks_count_percussion = (percussive_banks != 0) ? percussive_banks : 1; + file->banks_percussive = (WOPLBank*)calloc(file->banks_count_percussion, sizeof(WOPLBank)); + + if(percussive_banks == 0) + { + unsigned i; + for(i = 0; i < 128; ++i) + file->banks_percussive[0].ins[i].inst_flags = WOPL_Ins_IsBlank; + } + return file; } -- cgit v1.2.3