// ------------------------------------------------------ // Save a midi config file void Save_Midi_Cfg(void) { FILE *in; char Temph[96]; char extension[10]; sprintf(extension, "PROTMID1"); sprintf(Temph, "Saving '%s.pmi' data in midi configs directory...", Midi_Name); Status_Box(Temph); sprintf(Temph, "%s"SLASH"%s.pmi", Dir_MidiCfg, Midi_Name); in = fopen(Temph, "wb"); if(in != NULL) { Write_Data(extension, sizeof(char), 9, in); Write_Data(Midi_Name, sizeof(char), 20, in); Save_Midi_Cfg_Data(Write_Data, Write_Data_Swap, in); fclose(in); Read_SMPT(); last_index = -1; Actualize_Files_List(0); Status_Box("Midi config data saved succesfully."); } else { Status_Box("Midi config data save failed."); } Clear_Input(); }
// ------------------------------------------------------ // Save a 303 pattern void Save_303(void) { FILE *in; char Temph[MAX_PATH]; char extension[10]; sprintf(extension, "TWNN3031"); sprintf(Temph, "Saving '%s.303' pattern in patterns directory...", tb303[sl3].pattern_name[tb303[sl3].selectedpattern]); Status_Box(Temph); sprintf(Temph, "%s"SLASH"%s.303", Dir_Patterns, tb303[sl3].pattern_name[tb303[sl3].selectedpattern]); in = fopen(Temph, "wb"); if(in != NULL) { Write_Data(extension, sizeof(char), 9, in); Save_303_Data(Write_Data, Write_Data_Swap, in, sl3, tb303[sl3].selectedpattern); fclose(in); Read_SMPT(); last_index = -1; Actualize_Files_List(0); Status_Box("303 pattern saved succesfully."); } else { Status_Box("303 pattern save failed."); } Clear_Input(); }
void Load_303(char *FileName) { FILE *in; in = fopen(FileName, "rb"); if(in != NULL) { // Reading and checking extension... char extension[10]; fread(extension, sizeof(char), 9, in); if(strcmp(extension, "TWNN3031") == 0) { // Ok, extension matched! Status_Box("Loading 303 pattern..."); Load_303_Data(Read_Data, Read_Data_Swap, in, sl3, tb303[sl3].selectedpattern); Actualize_303_Ed(0); Status_Box("303 pattern loaded ok."); } else { Status_Box("That file is not a "TITLE" 303 pattern file..."); } fclose(in); } else { Status_Box("303 pattern loading failed. (Possible cause: file not found)"); } }
// ------------------------------------------------------ // Fade a sample out void Sample_FadeOut(int32 range_start, int32 range_end) { int32 i; Status_Box("Fade Out Selection..."); SDL_Delay(100); char nc = Sample_Channels[Current_Instrument][Current_Instrument_Split]; float c_vol = 1.0f; float const coef_vol = 1.0f / ((range_end + 1) - range_start); for(i = range_start; i < range_end + 1; i++) { float bleak = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i); bleak *= c_vol; if(bleak > 32767) bleak = 32767; if(bleak < -32767) bleak = -32767; *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i) = (short) bleak; if(nc == 2) { bleak = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i); bleak *= c_vol; if(bleak > 32767) bleak = 32767; if(bleak < -32767) bleak = -32767; *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i) = (short) bleak; } c_vol -= coef_vol; } draw_sampled_wave = TRUE; Status_Box("Fade out done."); }
// ------------------------------------------------------ // Load a reverb file void Load_Midi_Cfg(char *FileName) { FILE *in; in = fopen(FileName, "rb"); if(in != NULL) { // Reading and checking extension... char extension[10]; fread(extension, sizeof(char), 9, in); if(strcmp(extension, "PROTMID1") == 0) { // Ok, extension matched! Status_Box("Loading midi config data..."); Read_Data(Midi_Name, sizeof(char), 20, in); Load_Midi_Cfg_Data(Read_Data, Read_Data_Swap, in); Actualize_Midi_Ed(0); Status_Box("Midi config data loaded ok."); } else { Status_Box("That file is not a "TITLE" midi config file..."); } fclose(in); } else { Status_Box("Midi config data loading failed. (Possible cause: file not found)"); } }
// ------------------------------------------------------ // Half a sample void Sample_Half(int32 range_start, int32 range_end) { int32 i; char nc = Sample_Channels[Current_Instrument][Current_Instrument_Split]; float c_vol = 0.5f; for(i = range_start; i < range_end + 1; i++) { float bleak = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i); bleak *= c_vol; *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i) = (short) bleak; if(nc == 2) { bleak = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i); bleak *= c_vol; *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i) = (short) bleak; } } draw_sampled_wave = TRUE; Status_Box("Half done."); }
// ------------------------------------------------------ // Swap the data of a selection int Sample_Reverse(int32 range_start, int32 range_end) { int32 i; short sample; char nc; long p_s; long reversesize = (range_end - range_start) / 2; if(reversesize) { nc = Sample_Channels[Current_Instrument][Current_Instrument_Split]; p_s = range_end - 1; // Reverse it for(i = range_start; i < (range_start + reversesize); i++) { sample = RawSamples[Current_Instrument][0][Current_Instrument_Split][p_s]; RawSamples[Current_Instrument][0][Current_Instrument_Split][p_s] = RawSamples[Current_Instrument][0][Current_Instrument_Split][i]; RawSamples[Current_Instrument][0][Current_Instrument_Split][i] = sample; if(nc == 2) { sample = RawSamples[Current_Instrument][1][Current_Instrument_Split][p_s]; RawSamples[Current_Instrument][1][Current_Instrument_Split][p_s] = RawSamples[Current_Instrument][1][Current_Instrument_Split][i]; RawSamples[Current_Instrument][1][Current_Instrument_Split][i] = sample; } p_s--; } Status_Box("Reverse done."); return 1; } return 0; }
// ------------------------------------------------------ // Load a pattern file void Load_Pattern(char *FileName) { FILE *in; int version = 0; if(!is_editing) { Status_Box("Edit mode isn't turned on."); return; } in = fopen(FileName, "rb"); if(in != NULL) { // Reading and checking extension... char extension[10]; fread(extension, sizeof(char), 9, in); #ifndef __LITE__ if(strcmp(extension, "TWNNBLK1") == 0) version = 1; if(strcmp(extension, "PROTBLK2") == 0) version = 2; #else if(strcmp(extension, "PTKLBLK3") == 0) version = 2; #endif if(version) { // Ok, extension matched! Status_Box("Loading Pattern data..."); Read_Data(Selection_Name, sizeof(char), 20, in); Load_Pattern_Data(Read_Data, Read_Data_Swap, in, version); Actupated(0); Status_Box("Pattern data loaded ok."); } else { Status_Box("That file is not a "TITLE" Pattern file..."); } fclose(in); } else { Status_Box("Pattern data loading failed. (Possible cause: file not found)"); } }
// ------------------------------------------------------ // Convert a selection into a whole sample int Sample_Crop(int32 range_start, int32 range_end) { int32 i; short *NewBuffer[2]; char nc; long p_s; long cropsize = (range_end - range_start); if(cropsize) { Stop_Current_Instrument(); AUDIO_Stop(); nc = Sample_Channels[Current_Instrument][Current_Instrument_Split]; NewBuffer[0] = (short *) malloc(cropsize * 2 + 8); if(!NewBuffer[0]) return 0; memset(NewBuffer[0], 0, cropsize * 2 + 8); if(nc == 2) { NewBuffer[1] = (short *) malloc(cropsize * 2 + 8); if(!NewBuffer[1]) { free(NewBuffer[0]); return 0; } memset(NewBuffer[1], 0, cropsize * 2 + 8); } p_s = 0; // Copy the selection for(i = range_start; i < range_end; i++) { *(NewBuffer[0] + p_s) = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i); if(nc == 2) *(NewBuffer[1] + p_s) = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i); p_s++; } // Set the new buffer as current sample if(RawSamples[Current_Instrument][0][Current_Instrument_Split]) free(RawSamples[Current_Instrument][0][Current_Instrument_Split]); RawSamples[Current_Instrument][0][Current_Instrument_Split] = NewBuffer[0]; Player_WL[Current_Instrument][Current_Instrument_Split] = NewBuffer[0]; if(nc == 2) { if(RawSamples[Current_Instrument][1][Current_Instrument_Split]) free(RawSamples[Current_Instrument][1][Current_Instrument_Split]); RawSamples[Current_Instrument][1][Current_Instrument_Split] = NewBuffer[1]; Player_WR[Current_Instrument][Current_Instrument_Split] = NewBuffer[1]; } Sample_Length[Current_Instrument][Current_Instrument_Split] = cropsize; Status_Box("Crop done."); AUDIO_Play(); return 1; } return 0; }
// ------------------------------------------------------ // Save a pattern block file void Save_Pattern(void) { FILE *in; char Temph[96]; char extension[10]; #ifndef __LITE__ sprintf(extension, "PROTBLK2"); #else sprintf(extension, "PTKLBLK3"); #endif sprintf(Temph, "Saving '%s.ppb' data in patterns directory...", Selection_Name); Status_Box(Temph); sprintf(Temph, "%s"SLASH"%s.ppb", Dir_Patterns, Selection_Name); in = fopen(Temph, "wb"); if(in != NULL) { Write_Data(extension, sizeof(char), 9, in); Write_Data(Selection_Name, sizeof(char), 20, in); Save_Pattern_Data(Write_Data, Write_Data_Swap, in); fclose(in); Read_SMPT(); last_index = -1; Actualize_Files_List(0); Status_Box("Pattern data saved succesfully."); } else { Status_Box("Pattern data save failed."); } Clear_Input(); }
// ------------------------------------------------------ // Zeroize a sample void Sample_Zeroize(int32 range_start, int32 range_end) { int32 i; char nc = Sample_Channels[Current_Instrument][Current_Instrument_Split]; for(i = range_start; i < range_end + 1; i++) { *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i) = 0; if(nc == 2) { *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i) = 0; } } draw_sampled_wave = TRUE; Status_Box("Zero done."); }
// ------------------------------------------------------ // Maximize a sample void Sample_Maximize(int32 range_start, int32 range_end) { int32 i; char nc = Sample_Channels[Current_Instrument][Current_Instrument_Split]; float l_shift = 0; for(i = range_start; i < range_end + 1; i++) { if(abs(*(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i)) > l_shift) { l_shift = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i); } if(nc == 2) { if(abs(*(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i)) > l_shift) { l_shift = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i); } } } l_shift = 32768.0f / l_shift; for(i = range_start; i < range_end + 1; i++) { float bleak = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i); bleak *= l_shift; if(bleak > 32767) bleak = 32767; if(bleak < -32767) bleak = -32767; *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i) = (short) bleak; if(nc == 2) { bleak = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i); bleak *= l_shift; if(bleak > 32767) bleak = 32767; if(bleak < -32767) bleak = -32767; *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i) = (short) bleak; } } draw_sampled_wave = TRUE; Status_Box("Maximize done."); }
// ------------------------------------------------------ // Copy part of a sample int Sample_Copy(int32 range_start, int32 range_end) { int i; short *dest_mono; short *dest_stereo; long copysize = (range_end - range_start); char nc = Sample_Channels[Current_Instrument][Current_Instrument_Split]; if(copysize) { // Free both back buffers if(Sample_Back[cur_sample_buffer][0]) free(Sample_Back[cur_sample_buffer][0]); if(Sample_Back[cur_sample_buffer][1]) free(Sample_Back[cur_sample_buffer][1]); Sample_Back[cur_sample_buffer][0] = NULL; Sample_Back[cur_sample_buffer][1] = NULL; // Copy the data into the back buffer Sample_Back[cur_sample_buffer][0] = (short *) malloc(copysize * 2 + 8); if(!Sample_Back[cur_sample_buffer][0]) return 0; memset(Sample_Back[cur_sample_buffer][0], 0, copysize * 2 + 8); if(nc == 2) { Sample_Back[cur_sample_buffer][1] = (short *) malloc(copysize * 2 + 8); if(!Sample_Back[cur_sample_buffer][1]) { free(Sample_Back[cur_sample_buffer][0]); return 0; } memset(Sample_Back[cur_sample_buffer][1], 0, copysize * 2 + 8); } Sample_Back_Channels[cur_sample_buffer] = nc; Sample_Back_Size[cur_sample_buffer] = copysize; // Copy the selection into the back buffer dest_mono = Sample_Back[cur_sample_buffer][0]; dest_stereo = Sample_Back[cur_sample_buffer][1]; for(i = range_start; i < range_end; i++) { *dest_mono++ = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i); if(nc == 2) *dest_stereo++ = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i); } Status_Box("Copy done."); return 1; } return 0; }
// ------------------------------------------------------ // Adjust DC of a sample void Sample_DC_Adjust(int32 range_start, int32 range_end) { int32 i; char nc = Sample_Channels[Current_Instrument][Current_Instrument_Split]; float l_shift = 0; float r_shift = 0; for(i = range_start; i < range_end + 1; i++) { l_shift += *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i); if(nc == 2) r_shift += *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i); } l_shift /= (range_end + 1) - range_start; r_shift /= (range_end + 1) - range_start; for(i = range_start; i < range_end + 1; i++) { float bleak = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i); bleak -= l_shift; if(bleak > 32767) bleak = 32767; if(bleak < -32767) bleak = -32767; *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i) = (short) bleak; if(nc == 2) { bleak = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i); bleak -= r_shift; if(bleak > 32767) bleak = 32767; if(bleak < -32767) bleak = -32767; *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i) = (short) bleak; } } draw_sampled_wave = TRUE; Status_Box("DC adjust done."); }
// ------------------------------------------------------ // Rotate a selection to the right by a given amount int Sample_Rotate_Right(int32 range_start, int32 range_end, int amount) { int32 i; int j; short sample1; short sample2; char nc; long shiftsize = (range_end - range_start); if(shiftsize) { nc = Sample_Channels[Current_Instrument][Current_Instrument_Split]; for(j = 0; j < amount; j++) { sample1 = RawSamples[Current_Instrument][0][Current_Instrument_Split][range_end - 1]; if(nc == 2) sample2 = RawSamples[Current_Instrument][1][Current_Instrument_Split][range_end - 1]; // Shift it for(i = range_end - 2; i >= range_start; i--) { RawSamples[Current_Instrument][0][Current_Instrument_Split][i + 1] = RawSamples[Current_Instrument][0][Current_Instrument_Split][i]; if(nc == 2) { RawSamples[Current_Instrument][1][Current_Instrument_Split][i + 1] = RawSamples[Current_Instrument][1][Current_Instrument_Split][i]; } } RawSamples[Current_Instrument][0][Current_Instrument_Split][range_start] = sample1; if(nc == 2) RawSamples[Current_Instrument][1][Current_Instrument_Split][range_start] = sample2; } Status_Box("Shift right done."); return 1; } return 0; }
// ------------------------------------------------------ // Cut part of a sample int Sample_Cut(int32 range_start, int32 range_end, int do_copy) { int32 i; short *NewBuffer[2]; char nc; long p_s; long cutsize = (range_end - range_start); long newsize = Sample_Length[Current_Instrument][Current_Instrument_Split] - cutsize; if(newsize) { Stop_Current_Instrument(); AUDIO_Stop(); nc = Sample_Channels[Current_Instrument][Current_Instrument_Split]; // Allocate the wav with the minus the block to cut NewBuffer[0] = (short *) malloc(newsize * 2 + 8); if(!NewBuffer[0]) return 0; memset(NewBuffer[0], 0, newsize * 2 + 8); if(nc == 2) { NewBuffer[1] = (short *) malloc(newsize * 2 + 8); if(!NewBuffer[1]) { free(NewBuffer[0]); return 0; } memset(NewBuffer[1], 0, newsize * 2 + 8); } if(do_copy) { if(!Sample_Copy(range_start, range_end)) { free(NewBuffer[1]); free(NewBuffer[0]); return 0; } } p_s = 0; if(range_start > 0) { // Copy the data located before the range start for(i = 0; i < range_start; i++) { *(NewBuffer[0] + p_s) = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i); if(nc == 2) *(NewBuffer[1] + p_s) = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i); p_s++; } } if((Sample_Length[Current_Instrument][Current_Instrument_Split] - range_end) > 0) { // Add the data located after the range end for(i = range_end; i < (int32) Sample_Length[Current_Instrument][Current_Instrument_Split]; i++) { *(NewBuffer[0] + p_s) = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i); if(nc == 2) *(NewBuffer[1] + p_s) = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i); p_s++; } } // Set the new buffer as current sample if(RawSamples[Current_Instrument][0][Current_Instrument_Split]) free(RawSamples[Current_Instrument][0][Current_Instrument_Split]); RawSamples[Current_Instrument][0][Current_Instrument_Split] = NewBuffer[0]; Player_WL[Current_Instrument][Current_Instrument_Split] = NewBuffer[0]; if(nc == 2) { if(RawSamples[Current_Instrument][1][Current_Instrument_Split]) free(RawSamples[Current_Instrument][1][Current_Instrument_Split]); RawSamples[Current_Instrument][1][Current_Instrument_Split] = NewBuffer[1]; Player_WR[Current_Instrument][Current_Instrument_Split] = NewBuffer[1]; } Sample_Length[Current_Instrument][Current_Instrument_Split] = newsize; Status_Box("Cut done."); AUDIO_Play(); return 1; } else { if(do_copy) { Status_Box("You cannot cut entire sample, use 'delete' on instrument instead."); } else { Status_Box("You cannot zap entire sample, use 'delete' on instrument instead."); } return 0; } }
// ------------------------------------------------------ // Save the configuration file void SaveConfig(void) { FILE *out; char extension[10]; char FileName[MAX_PATH]; int i; int Real_Palette_Idx; char KeyboardName[MAX_PATH]; signed char phony = -1; sprintf(extension, "PROTCFGF"); Status_Box("Saving 'ptk.cfg'..."); #ifdef __linux__ sprintf(FileName, "%s/.ptk.cfg", getenv("HOME")); #else sprintf(FileName, "%s"SLASH"ptk.cfg", ExePath); #endif memset(KeyboardName, 0, sizeof(KeyboardName)); sprintf(KeyboardName, "%s", Keyboard_Name); out = fopen(FileName, "wb"); if(out != NULL) { Write_Data(extension, sizeof(char), 9, out); Write_Data_Swap(&Current_Edit_Steps, sizeof(Current_Edit_Steps), 1, out); Write_Data_Swap(&patt_highlight, sizeof(patt_highlight), 1, out); Write_Data_Swap(&AUDIO_Milliseconds, sizeof(AUDIO_Milliseconds), 1, out); #if defined(__NO_MIDI__) Write_Data(&phony, sizeof(phony), 1, out); #else Write_Data(&c_midiin, sizeof(c_midiin), 1, out); #endif #if defined(__NO_MIDI__) Write_Data(&phony, sizeof(phony), 1, out); #else Write_Data(&c_midiout, sizeof(c_midiout), 1, out); #endif Write_Data_Swap(&MouseWheel_Multiplier, sizeof(MouseWheel_Multiplier), 1, out); Write_Data(&Rows_Decimal, sizeof(Rows_Decimal), 1, out); Write_Data(&FullScreen, sizeof(FullScreen), 1, out); for(i = 0; i < NUMBER_COLORS; i++) { Real_Palette_Idx = Idx_Palette[i]; Write_Data(&Ptk_Palette[Real_Palette_Idx].r, sizeof(char), 1, out); Write_Data(&Ptk_Palette[Real_Palette_Idx].g, sizeof(char), 1, out); Write_Data(&Ptk_Palette[Real_Palette_Idx].b, sizeof(char), 1, out); } Write_Data(&See_Prev_Next_Pattern, sizeof(See_Prev_Next_Pattern), 1, out); Write_Data_Swap(&Beveled, sizeof(Beveled), 1, out); Write_Data_Swap(&Continuous_Scroll, sizeof(Continuous_Scroll), 1, out); Write_Data(&AutoSave, sizeof(AutoSave), 1, out); Write_Data(&AutoBackup, sizeof(AutoBackup), 1, out); Write_Data(&Dir_Mods, sizeof(Dir_Mods), 1, out); Write_Data(&Dir_Instrs, sizeof(Dir_Instrs), 1, out); Write_Data(&Dir_Presets, sizeof(Dir_Presets), 1, out); Write_Data(&Dir_Reverbs, sizeof(Dir_Reverbs), 1, out); Write_Data(&Dir_MidiCfg, sizeof(Dir_MidiCfg), 1, out); Write_Data(&Dir_Patterns, sizeof(Dir_Patterns), 1, out); Write_Data(&Dir_Samples, sizeof(Dir_Samples), 1, out); Write_Data(KeyboardName, MAX_PATH, 1, out); Write_Data(&rawrender_32float, sizeof(char), 1, out); Write_Data(&rawrender_multi, sizeof(char), 1, out); Write_Data(&rawrender_target, sizeof(char), 1, out); Write_Data(&Large_Patterns, sizeof(char), 1, out); Write_Data(&Scopish_LeftRight, sizeof(char), 1, out); Write_Data(&Paste_Across, sizeof(char), 1, out); Write_Data(&Jazz_Edit, sizeof(char), 1, out); Write_Data(&Accidental, sizeof(char), 1, out); Write_Data(&Use_Shadows, sizeof(char), 1, out); Write_Data(&Global_Patterns_Font, sizeof(char), 1, out); Write_Data(&metronome_magnify, sizeof(int), 1, out); // Save the compelte midi automation config Save_MidiCfg_Data(Write_Data, Write_Data_Swap, out); Write_Data_Swap(&Cur_Width, sizeof(int), 1, out); Write_Data_Swap(&Cur_Height, sizeof(int), 1, out); Cur_Left = -1; Cur_Top = -1; Write_Data_Swap(&Cur_Left, sizeof(int), 1, out); Write_Data_Swap(&Cur_Top, sizeof(int), 1, out); fclose(out); Read_SMPT(); last_index = -1; Actualize_Files_List(0); Status_Box("Configuration file saved succesfully."); } else { Status_Box("Configuration file save failed."); } }
// ------------------------------------------------------ // Insert zeroes into a sample the length of the selection buffer int Sample_InsertZero(int32 range_start, int32 range_end) { int32 i; short *NewBuffer[2]; char nc; long p_s; long cutsize = range_end - range_start; long newsize = Sample_Length[Current_Instrument][Current_Instrument_Split] + cutsize; if(cutsize) { Stop_Current_Instrument(); AUDIO_Stop(); nc = Sample_Channels[Current_Instrument][Current_Instrument_Split]; // Allocate the destination buffer(s) // (We need to clear the second one as the back buffer may not be stereo). NewBuffer[0] = (short *) malloc(newsize * 2 + 8); if(!NewBuffer[0]) return 0; memset(NewBuffer[0], 0, newsize * 2 + 8); if(nc == 2) { NewBuffer[1] = (short *) malloc(newsize * 2 + 8); if(!NewBuffer[1]) { free(NewBuffer[0]); return 0; } memset(NewBuffer[1], 0, newsize * 2 + 8); } p_s = 0; if(range_start > 0) { // Copy the original data into the new buffer for(i = 0; i < range_start; i++) { *(NewBuffer[0] + p_s) = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i); if(nc == 2) *(NewBuffer[1] + p_s) = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i); p_s++; } } // Skip a buffer of the selection's size p_s += cutsize; if((Sample_Length[Current_Instrument][Current_Instrument_Split] - range_start) > 0) { // Add the rest of the original data for(i = range_start; i < (int32) Sample_Length[Current_Instrument][Current_Instrument_Split]; i++) { *(NewBuffer[0] + p_s) = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i); if(nc == 2) *(NewBuffer[1] + p_s) = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i); p_s++; } } // Set the new buffer as current sample if(RawSamples[Current_Instrument][0][Current_Instrument_Split]) free(RawSamples[Current_Instrument][0][Current_Instrument_Split]); RawSamples[Current_Instrument][0][Current_Instrument_Split] = NewBuffer[0]; Player_WL[Current_Instrument][Current_Instrument_Split] = NewBuffer[0]; if(nc == 2) { if(RawSamples[Current_Instrument][1][Current_Instrument_Split]) free(RawSamples[Current_Instrument][1][Current_Instrument_Split]); RawSamples[Current_Instrument][1][Current_Instrument_Split] = NewBuffer[1]; Player_WR[Current_Instrument][Current_Instrument_Split] = NewBuffer[1]; } Sample_Length[Current_Instrument][Current_Instrument_Split] = newsize; Status_Box("Duplicate done."); AUDIO_Play(); return 1; } return 0; }