Subversion Repositories svn.mios32

Rev

Rev 1376 | Rev 1486 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1376 Rev 1409
Line 113... Line 113...
113
113
114
114
115
// Call this routine with the sample array number to reference, and the filename to open
115
// Call this routine with the sample array number to reference, and the filename to open
116
s32 SAMP_FILE_open(u8 sample_n, char fname[])
116
s32 SAMP_FILE_open(u8 sample_n, char fname[])
117
{
117
{
-
 
118
  DEBUG_MSG("Filename is %s.",fname);
118
  s32 status = FILE_ReadOpen(&samplefile_fileinfo[sample_n], fname);
119
  s32 status = FILE_ReadOpen(&samplefile_fileinfo[sample_n], fname);
119
  FILE_ReadClose(&samplefile_fileinfo[sample_n]); // close again - file will be reopened by read handler
120
  FILE_ReadClose(&samplefile_fileinfo[sample_n]); // close again - file will be reopened by read handler
120
121
121
  if( status < 0 ) {
122
  if( status < 0 ) {
122
    DEBUG_MSG("[APP] failed to open file, status: %d\n", status);
123
    DEBUG_MSG("[APP] failed to open file, status: %d\n", status);
Line 154... Line 155...
154
}
155
}
155
156
156
void Open_Bank(u8 b_num)    // Open the bank number passed and parse the bank information, load samples, set midi notes, number of samples and cache cluster positions
157
void Open_Bank(u8 b_num)    // Open the bank number passed and parse the bank information, load samples, set midi notes, number of samples and cache cluster positions
157
{
158
{
158
  u8 samp_no;
159
  u8 samp_no;
159
  u8 f_line[25];                // 0..3=0xXX (hex midi note) 4=space 5=sample hold (0 or 1) 6=space 7..10=decay (4 digit decimal) 11=space 12..23=8.3 filename 24=null
160
  u8 f_line[63];                // 0..3=0xXX (hex midi note) 4=space 5=sample hold (0 or 1) 6=space 7..10=decay (4 digit decimal) 11=space 12..23=8.3 filename 24=null
160
  char b_file[13];              // Overall bank name to generate
161
  char b_file[13];              // Overall bank name to generate
161
  char b_num_char[4];           // Up to 3 digit bank string plus terminator
162
  char b_num_char[4];           // Up to 3 digit bank string plus terminator
162
  static char sample_filenames[NUM_SAMPLES_TO_OPEN][13];        // Stores sample mappings from bank file, needs to be static to avoid crash
163
  static char sample_filenames[NUM_SAMPLES_TO_OPEN][30];        // Stores sample mappings from bank file, needs to be static to avoid crash
163
164
164
  strcpy(b_file,bankprefix);        // Get prefix in
165
  strcpy(b_file,bankprefix);        // Get prefix in
165
  sprintf(b_num_char,"%d",b_num);   // get bank number as string
166
  sprintf(b_num_char,"%d",b_num);   // get bank number as string
166
  strcat(b_file,b_num_char);        // Create the final filename
167
  strcat(b_file,b_num_char);        // Create the final filename
167
 
168
 
Line 170... Line 171...
170
  no_samples_loaded=0;
171
  no_samples_loaded=0;
171
  no_decay=1;                       // Default to no decay for bank
172
  no_decay=1;                       // Default to no decay for bank
172
 
173
 
173
  DEBUG_MSG("Opening bank file %s",b_file);
174
  DEBUG_MSG("Opening bank file %s",b_file);
174
  if(FILE_ReadOpen(&bank_fileinfo, b_file)<0) { DEBUG_MSG("Failed to open bank file."); }
175
  if(FILE_ReadOpen(&bank_fileinfo, b_file)<0) { DEBUG_MSG("Failed to open bank file."); }
-
 
176
   else
175
 
177
  {
176
  for(samp_no=0;samp_no<NUM_SAMPLES_TO_OPEN;samp_no++)  // Check for up to the defined maximum of sample mappings (one per line)
178
          for(samp_no=0;samp_no<NUM_SAMPLES_TO_OPEN;samp_no++)  // Check for up to the defined maximum of sample mappings (one per line)
177
  {
179
          {
178
    if(FILE_ReadLine(f_line, 25)) // Read line up to 23 chars long
180
            if(FILE_ReadLine(f_line, 63)) // Read line up to 63 chars long
179
    {
181
            {
180
       //DEBUG_MSG("Sample no %d, Line is: %s",samp_no,f_line);
182
               //DEBUG_MSG("Sample no %d, Line is: %s",samp_no,f_line);
181
       sample_to_midinote[samp_no]=(int)strtol((char *)(f_line+2),NULL,16); // Convert hex string values to a real number (pos 2 on line, base 16)
183
               sample_to_midinote[samp_no]=(int)strtol((char *)(f_line+2),NULL,16); // Convert hex string values to a real number (pos 2 on line, base 16)
182
       hold_sample[samp_no]=(int)strtol((char *)(f_line+5),NULL,10); // Convert sample hold digit
184
               hold_sample[samp_no]=(int)strtol((char *)(f_line+5),NULL,10); // Convert sample hold digit
183
       sample_decval[samp_no]=(int)strtol((char *)(f_line+7),NULL,10); // Convert decay number (pos 5 on line, base 10)
185
               sample_decval[samp_no]=(int)strtol((char *)(f_line+7),NULL,10); // Convert decay number (pos 5 on line, base 10)
184
       if(sample_decval[samp_no]>0) { no_decay=0; } // At least one of the samples requires decay processing
186
               if(sample_decval[samp_no]>0) { no_decay=0; } // At least one of the samples requires decay processing
185
       (void) strncpy(sample_filenames[samp_no],(char *)(f_line+12),12);    // Put name into array of sample names (pos 10 on line), up to 12 chars (8.3)   
187
               (void) strncpy(sample_filenames[samp_no],(char *)(f_line+12),30);    // Put name into array of sample names (pos 10 on line), up to 12 chars (8.3)   
186
       DEBUG_MSG("Sample no %d, filename is: %s, midi note value=0x%x, decay value %d, hold=%d",samp_no,sample_filenames[samp_no],sample_to_midinote[samp_no],sample_decval[samp_no],hold_sample[samp_no]);
188
               DEBUG_MSG("Sample no %d, filename is: %s, midi note value=0x%x, decay value %d, hold=%d",samp_no,sample_filenames[samp_no],sample_to_midinote[samp_no],sample_decval[samp_no],hold_sample[samp_no]);
187
       no_samples_loaded++; // increment global number of samples we will read in and scan for in play
189
               no_samples_loaded++; // increment global number of samples we will read in and scan for in play
188
    }
190
            }
189
   }
191
           }
190
  FILE_ReadClose(&bank_fileinfo);
192
          FILE_ReadClose(&bank_fileinfo);
Line 220... Line 222...
220
       DEBUG_MSG("Cluster %d: %d ", cluster_ix, sample_cluster_cache[samp_no][cluster_ix]);
222
               DEBUG_MSG("Cluster %d: %d ", cluster_ix, sample_cluster_cache[samp_no][cluster_ix]);
221
     }
223
             }
222
   }
224
           }
223
225
224
   sample_on[samp_no]=0;    // Set sample to off
226
           sample_on[samp_no]=0;    // Set sample to off
-
 
227
         }
225
 }
228
    }
226
   MIOS32_BOARD_LED_Set(0x1, 0x0);  // Turn off LED after bank load
229
    MIOS32_BOARD_LED_Set(0x1, 0x0); // Turn off LED after bank load
227
}
230
}
228
231
229
u8 Read_Switch(void) // Lee's temp hardware: Set up inputs for bank switch as input with pullups, then read bank number (1,2,3,4) based on which of D0, D1 or D2 low
232
u8 Read_Switch(void) // Lee's temp hardware: Set up inputs for bank switch as input with pullups, and find if any lines pulled low to select bank 
230
{
233
{
231
     u8 pin_no;
234
     u8 pin_no;
232
     u8 bank_val;
235
     u8 bank_val;
233
236
234
     for(pin_no=0;pin_no<8;pin_no++)
237
     for(pin_no=0;pin_no<8;pin_no++)
235
     {
238
     {
236
      MIOS32_BOARD_J10_PinInit(pin_no, MIOS32_BOARD_PIN_MODE_INPUT_PU);
239
      MIOS32_BOARD_J10_PinInit(pin_no, MIOS32_BOARD_PIN_MODE_INPUT_PU);
237
     }
240
     }
238
241
239
     bank_val=(u8)(MIOS32_BOARD_J10_Get() & 0x07); // Read all pins, but only care about first 3, 7=1st pos (all high), 6=2nd pos (D0 low), 5=3rd pos (D1 low), 3=4th pos (D2 low)
242
     bank_val=(u8)MIOS32_BOARD_J10_Get(); // Read all pins, if all pins high, val=0 meaning bank 1, otherwise one pin should be pulled low eg bank_index 0 = bank_val=1 so bank 2
-
 
243
     if(bank_val==127) { return 9; }    // D7 = 128 low
-
 
244
     if(bank_val==191) { return 8; }    // D6 = 64 low
-
 
245
     if(bank_val==223) { return 7; }    // D5 = 32 low
-
 
246
     if(bank_val==239) { return 6; }    // D4 = 16 low
-
 
247
     if(bank_val==247) { return 5; }    // D3 = 8 low
240
     if(bank_val==3) { return 4; }
248
     if(bank_val==251) { return 4; }    // D2 = 4 low
241
     if(bank_val==5) { return 3; }
249
     if(bank_val==253) { return 3; }    // D1 = 2 low
242
     if(bank_val==6) { return 2; }   
250
     if(bank_val==254) { return 2; }    // D0 = 1 low
243
     return 1;      // default to bank 1
251
     return 1;      // default to bank 1 (bank val 255)
244
 }
252
 }
245
253
246
void Read_Config()  // Open the config file on the SD card and (re)set various settings for the player
254
void Read_Config()  // Open the config file on the SD card and (re)set various settings for the player
247
{
255
{
248
  u8 f_line[25];                    // parameter and value space separated
256
  u8 f_line[25];                    // parameter and value space separated