timidity: remove noluck variable and directly check whether rw is NULL.
authorOzkan Sezer
Mon, 16 Dec 2019 10:55:10 +0300
changeset 1085c91c7bce78c6
parent 1084 c7cedfb5f65f
child 1086 89f446aae9b5
timidity: remove noluck variable and directly check whether rw is NULL.
src/codecs/timidity/instrum.c
     1.1 --- a/src/codecs/timidity/instrum.c	Mon Dec 16 10:55:02 2019 +0300
     1.2 +++ b/src/codecs/timidity/instrum.c	Mon Dec 16 10:55:10 2019 +0300
     1.3 @@ -6,8 +6,8 @@
     1.4      This program is free software; you can redistribute it and/or modify
     1.5      it under the terms of the Perl Artistic License, available in COPYING.
     1.6  
     1.7 -   instrum.c 
     1.8 -   
     1.9 +   instrum.c
    1.10 +
    1.11     Code to load and unload GUS-compatible instrument patches.
    1.12  
    1.13  */
    1.14 @@ -60,7 +60,7 @@
    1.15  static Sint32 convert_envelope_rate(MidiSong *song, Uint8 rate)
    1.16  {
    1.17    Sint32 r;
    1.18 -  
    1.19 +
    1.20    r = 3 - ((rate >> 6) & 0x3);
    1.21    r *= 3;
    1.22    r = (Sint32) (rate & 0x3f) << r; /* 6.9 fixed point */
    1.23 @@ -139,12 +139,12 @@
    1.24      }
    1.25  }
    1.26  
    1.27 -/* 
    1.28 +/*
    1.29     If panning or note_to_use != -1, it will be used for all samples,
    1.30     instead of the sample-specific values in the instrument file. 
    1.31  
    1.32     For note_to_use, any value <0 or >127 will be forced to 0.
    1.33 - 
    1.34 +
    1.35     For other parameters, 1 means yes, 0 means no, other values are
    1.36     undefined.
    1.37  
    1.38 @@ -158,16 +158,15 @@
    1.39    Sample *sp;
    1.40    SDL_RWops *rw;
    1.41    char tmp[1024];
    1.42 -  int i,j,noluck=0;
    1.43 +  int i,j;
    1.44    static char *patch_ext[] = PATCH_EXT_LIST;
    1.45 +
    1.46    (void)percussion; /* unused */
    1.47 +  if (!name) return 0;
    1.48  
    1.49 -  if (!name) return 0;
    1.50 -  
    1.51    /* Open patch file */
    1.52    if ((rw=open_file(name)) == NULL)
    1.53      {
    1.54 -      noluck=1;
    1.55        /* Try with various extensions */
    1.56        for (i=0; patch_ext[i]; i++)
    1.57  	{
    1.58 @@ -176,22 +175,19 @@
    1.59  	      strcpy(tmp, name);
    1.60  	      strcat(tmp, patch_ext[i]);
    1.61  	      if ((rw=open_file(tmp)) != NULL)
    1.62 -		{
    1.63 -		  noluck=0;
    1.64  		  break;
    1.65 -		}
    1.66  	    }
    1.67  	}
    1.68      }
    1.69 -  
    1.70 -  if (noluck)
    1.71 +
    1.72 +  if (rw == NULL)
    1.73      {
    1.74        SNDDBG(("Instrument `%s' can't be found.\n", name));
    1.75        return 0;
    1.76      }
    1.77 -      
    1.78 +
    1.79    SNDDBG(("Loading instrument %s\n", tmp));
    1.80 -  
    1.81 +
    1.82    /* Read some headers and do cursory sanity checks. There are loads
    1.83       of magic offsets. This could be rewritten... */
    1.84  
    1.85 @@ -204,8 +200,8 @@
    1.86        SDL_RWclose(rw);
    1.87        return 0;
    1.88      }
    1.89 -  
    1.90 -  if (tmp[82] != 1 && tmp[82] != 0) /* instruments. To some patch makers, 
    1.91 +
    1.92 +  if (tmp[82] != 1 && tmp[82] != 0) /* instruments. To some patch makers,
    1.93  				       0 means 1 */
    1.94      {
    1.95        SNDDBG(("Can't handle patches with %d instruments\n", tmp[82]));
    1.96 @@ -219,13 +215,12 @@
    1.97        SDL_RWclose(rw);
    1.98        return 0;
    1.99      }
   1.100 -  
   1.101 +
   1.102    ip=safe_malloc(sizeof(Instrument));
   1.103    ip->samples = tmp[198];
   1.104    ip->sample = safe_malloc(sizeof(Sample) * ip->samples);
   1.105    for (i=0; i<ip->samples; i++)
   1.106      {
   1.107 -
   1.108        Uint8 fractions;
   1.109        Sint32 tmplong;
   1.110        Uint16 tmpshort;
   1.111 @@ -256,7 +251,7 @@
   1.112  	}
   1.113  
   1.114        sp=&(ip->sample[i]);
   1.115 -      
   1.116 +
   1.117        READ_LONG(sp->data_length);
   1.118        READ_LONG(sp->loop_start);
   1.119        READ_LONG(sp->loop_end);
   1.120 @@ -266,7 +261,7 @@
   1.121        READ_LONG(sp->root_freq);
   1.122        SDL_RWseek(rw, 2, RW_SEEK_CUR); /* Why have a "root frequency" and then
   1.123  				    * "tuning"?? */
   1.124 -      
   1.125 +
   1.126        READ_CHAR(tmp[0]);
   1.127  
   1.128        if (panning==-1)
   1.129 @@ -314,20 +309,19 @@
   1.130        READ_CHAR(sp->modes);
   1.131  
   1.132        SDL_RWseek(rw, 40, RW_SEEK_CUR); /* skip the useless scale frequency, scale
   1.133 -				       factor (what's it mean?), and reserved
   1.134 -				       space */
   1.135 +				  factor (what's it mean?), and reserved
   1.136 +				  space */
   1.137  
   1.138        /* Mark this as a fixed-pitch instrument if such a deed is desired. */
   1.139        if (note_to_use!=-1)
   1.140  	sp->note_to_use=(Uint8)(note_to_use);
   1.141        else
   1.142  	sp->note_to_use=0;
   1.143 -      
   1.144 +
   1.145        /* seashore.pat in the Midia patch set has no Sustain. I don't
   1.146           understand why, and fixing it by adding the Sustain flag to
   1.147           all looped patches probably breaks something else. We do it
   1.148           anyway. */
   1.149 -	 
   1.150        if (sp->modes & MODES_LOOPING) 
   1.151  	sp->modes |= MODES_SUSTAIN;
   1.152  
   1.153 @@ -388,7 +382,7 @@
   1.154        sp->data = (sample_t *) safe_malloc(sp->data_length+4);
   1.155        if (1 != SDL_RWread(rw, sp->data, sp->data_length, 1))
   1.156  	goto fail;
   1.157 -      
   1.158 +
   1.159        if (!(sp->modes & MODES_16BIT)) /* convert to 16-bit data */
   1.160  	{
   1.161  	  Sint32 k=sp->data_length;
   1.162 @@ -416,7 +410,7 @@
   1.163  	    }
   1.164  	}
   1.165  #endif
   1.166 -      
   1.167 +
   1.168        if (sp->modes & MODES_UNSIGNED) /* convert to signed data */
   1.169  	{
   1.170  	  Sint32 k=sp->data_length/2;