Browse Source

draw pattern

develop^2
Carmine De Rosa 5 years ago
parent
commit
36ea8604df
  1. 36
      C/draw.cpp
  2. 7
      C/inputs.cpp
  3. 3
      C/loaders.cpp
  4. 17
      C/main.cpp
  5. 1
      C/players.cpp
  6. BIN
      C/sonquencer

36
C/draw.cpp

@ -0,0 +1,36 @@
void drawRects(int step){
SDL_RenderClear(renderer);
int cols = matrix[1];
int rows = matrix[0];
int colWidth = ((600-5)/cols)-5;
int rowHeight = ((300-5)/rows)-5;
for(int i=0; i<rows; i++) {
for(int y=0; y<cols; y++) {
SDL_Rect rect;
rect.x = (colWidth+5)*y+5;
rect.y = (rowHeight+5)*i+5;
rect.w = colWidth;
rect.h = rowHeight;
if(pattern[i][y] == 1) {
SDL_SetRenderDrawColor(renderer, 50, 255, 50, 255);
} else {
SDL_SetRenderDrawColor(renderer, 50, 50, 50, 255);
}
SDL_RenderFillRect(renderer, &rect);
if(step == y) {
SDL_SetRenderDrawColor(renderer, 200, 200, 200, 255);
SDL_RenderDrawRect(renderer, &rect);
}
SDL_SetRenderDrawColor(renderer, 100, 100, 100, 255);
}
}
SDL_RenderPresent(renderer);
}

7
C/inputs.cpp

@ -1,4 +1,4 @@
void inputActions(SDL_Event e, int step) {
void inputActions(SDL_Event e) {
switch (e.key.keysym.sym) {
case SDLK_1:
setSample(1, step);
@ -12,6 +12,11 @@ void inputActions(SDL_Event e, int step) {
case SDLK_4:
setSample(4, step);
break;
case SDLK_p:
play = !play;
step = 0;
break;
default:
break;
}

3
C/loaders.cpp

@ -68,6 +68,7 @@ void loadPattern(int patternNum) {
matrix[0] = rows;
matrix[1] = cols;
for(int i=0; i<rows; i++) {
for(int y=0; y<cols; y++) {
printf("%d ", pattern[i][y]);
@ -75,6 +76,8 @@ void loadPattern(int patternNum) {
printf("\n");
}
drawRects(0);
fclose(fp);
if(line) {free(line);}
loadBank(bank);

17
C/main.cpp

@ -13,9 +13,15 @@
#define PATTERN_COLS 32
Mix_Chunk* samples[NUM_WAVEFORMS];
SDL_Window* window;
SDL_Renderer* renderer;
int pattern[PATTERN_ROWS][PATTERN_COLS];
int matrix[] = {PATTERN_ROWS, PATTERN_COLS};
bool play = false;
int step = 0;
#include "draw.cpp"
#include "players.cpp"
#include "loaders.cpp"
#include "inputs.cpp"
@ -23,18 +29,13 @@ int matrix[] = {PATTERN_ROWS, PATTERN_COLS};
int main(int argc, char** argv) {
bool done = false;
bool play = true;
int timer = 0;
int step = 0;
int stepDuration = 500;
SDL_Window* window;
SDL_Renderer* renderer;
int stepDuration = 200;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO );
atexit(SDL_Quit);
window = SDL_CreateWindow("Sonquencer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 400, 300, 0);
window = SDL_CreateWindow("Sonquencer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 600, 300, 0);
renderer = SDL_CreateRenderer(window, -1, 0);
SDL_SetRenderDrawColor(renderer, 100, 100, 100, 255);
@ -58,7 +59,7 @@ int main(int argc, char** argv) {
SDL_Quit();
return 0;
} else {
inputActions(event, step);
inputActions(event);
}
break;
case SDL_QUIT:

1
C/players.cpp

@ -4,6 +4,7 @@ void playPattern(int *timer, int duration, int *step) {
usleep(1000);
if(*timer == 0) {
drawRects(*step-1);
for(int i=0; i<matrix[0]; i++) {
if(pattern[i][*step-1] == 1) {
Mix_PlayChannel(-1, samples[i], 0);

BIN
C/sonquencer

Binary file not shown.
Loading…
Cancel
Save