diff --git a/C/banks/BANK1/1.wav b/C/banks/BANK1/1.wav index dcb8553..3de85f6 100644 Binary files a/C/banks/BANK1/1.wav and b/C/banks/BANK1/1.wav differ diff --git a/C/compile.sh b/C/compile.sh index 561922d..65c4f0e 100644 --- a/C/compile.sh +++ b/C/compile.sh @@ -1 +1 @@ -g++ -o sonquencer -I/usr/include/SDL2 main.cpp -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer +g++ -o sonquencer -I/usr/include/SDL2 main.cpp -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer diff --git a/C/loaders.cpp b/C/loaders.cpp index 7350a19..7ebade4 100644 --- a/C/loaders.cpp +++ b/C/loaders.cpp @@ -1,7 +1,8 @@ int loadBank(int bank) { - memset(_sample, 0, sizeof(Mix_Chunk*) * NUM_WAVEFORMS); + printf("\nLoading bank %d ...\n", bank); + memset(samples, 0, sizeof(Mix_Chunk*) * NUM_WAVEFORMS); int result = Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 512); if( result < 0 ) { @@ -20,11 +21,70 @@ int loadBank(int bank) { for( int i = 0; i < NUM_WAVEFORMS; i++ ) { sprintf(waveFileName, "banks/BANK%d/%d.wav", bank, i+1); - _sample[i] = Mix_LoadWAV(waveFileName); - if( _sample[i] == NULL ) { + samples[i] = Mix_LoadWAV(waveFileName); + if( samples[i] == NULL ) { fprintf(stderr, "Unable to load wave file: %s\n", waveFileName); } } return true; } + + +void loadPattern(int pattern) { + printf("\nLoading pattern %d ...\n", pattern); + + FILE *fp; + char *line = NULL; + size_t len = 0; + ssize_t read; + int lineCount = 0; + char patternFile[16]; + + int bank = 0; + int cols = 0; + int rows = 0; + + int patternArray[10][32]; + + sprintf(patternFile, "patterns/pattern%d", pattern); + fp = fopen(patternFile, "r"); + if(fp == NULL) {exit(EXIT_FAILURE);} + + while ((read = getline(&line, &len, fp)) != -1) { + //printf("Retrieved line of length %zu:\n", read); + + if(lineCount == 0) { bank = line[10]-'0'; } + if(lineCount == 1) { rows = line[10]-'0'; } + + if(lineCount > 1) { + if(lineCount == 2) { + cols = read-1; + } + + for(int i=0; i -#include "SDL.h" -#include "SDL_mixer.h" -#include "SDL_image.h" #include #include #include #include -#define NUM_WAVEFORMS 6 +#include "SDL.h" +#include "SDL_mixer.h" +#include "SDL_image.h" + +#define NUM_WAVEFORMS 4 -Mix_Chunk* _sample[NUM_WAVEFORMS]; +Mix_Chunk* samples[NUM_WAVEFORMS]; #include "players.cpp" #include "loaders.cpp" @@ -33,16 +34,17 @@ int main(int argc, char** argv) { SDL_SetRenderDrawColor(renderer, 100, 100, 100, 255); SDL_Delay(1000); - if(loadBank(1) == false) {return -1;} - + SDL_RenderClear(renderer); + SDL_RenderPresent(renderer); SDL_Event event; + if(loadBank(1) == false) {return -1;} + loadPattern(2); + + /* while (!done) { bool gotEvent = SDL_PollEvent(&event); - SDL_RenderClear(renderer); - SDL_RenderPresent(renderer); - while (!done && gotEvent) { switch (event.type) { case SDL_KEYDOWN: @@ -91,10 +93,10 @@ int main(int argc, char** argv) { playStep(play, &timer, &step); } - + */ for( int i = 0; i < NUM_WAVEFORMS; i++ ) { - Mix_FreeChunk(_sample[i]); + Mix_FreeChunk(samples[i]); } Mix_CloseAudio(); diff --git a/C/patterns/pattern1 b/C/patterns/pattern1 new file mode 100644 index 0000000..fb04e98 --- /dev/null +++ b/C/patterns/pattern1 @@ -0,0 +1,6 @@ +bank 1 +rows 4 +00011010 +01100010 +00011000 +10000000 diff --git a/C/patterns/pattern2 b/C/patterns/pattern2 new file mode 100644 index 0000000..090df4f --- /dev/null +++ b/C/patterns/pattern2 @@ -0,0 +1,6 @@ +bank 2 +rows 4 +10000010 +01100010 +00011000 +10001001 diff --git a/C/players.cpp b/C/players.cpp index 633a6f1..8a042a1 100644 --- a/C/players.cpp +++ b/C/players.cpp @@ -6,10 +6,10 @@ void playStep(bool play, int *timer, int *step) { if(*timer == 0) { printf("%d\n", *timer); - Mix_PlayChannel(-1, _sample[1], 0); + Mix_PlayChannel(-1, samples[1], 0); } } void playSample(int sample) { - Mix_PlayChannel(-1, _sample[sample-1], 0); + Mix_PlayChannel(-1, samples[sample-1], 0); } diff --git a/C/sonquencer b/C/sonquencer index baf7a3d..ac76495 100755 Binary files a/C/sonquencer and b/C/sonquencer differ