Browse Source

Merge branch 'feature/actions' into develop

develop
Dslak 5 years ago
parent
commit
25fe251f36
  1. 27
      C/actions.cpp
  2. 36
      C/draw.cpp
  3. 25
      C/inputs.cpp
  4. 3
      C/loaders.cpp
  5. 31
      C/main.cpp
  6. 8
      C/patterns/pattern2
  7. 21
      C/players.cpp
  8. BIN
      C/sonquencer
  9. 17
      README.md

27
C/actions.cpp

@ -0,0 +1,27 @@
void setSample(int sample) {
if(setErease) {
ereaseSample = sample;
} else if(selectPattern) {
loadPattern(sample);
selectPattern = false;
} else if(selectBank) {
loadBank(sample);
selectBank = false;
} else {
pattern[sample-1][step-1] = 1;
for(int i=0; i<matrix[0]; i++) {
for(int y=0; y<matrix[1]; y++) {
printf("%d ", pattern[i][y]);
}
printf("\n");
}
}
}

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);
}

25
C/inputs.cpp

@ -1,17 +1,32 @@
void inputActions(SDL_Event e, int step) {
void inputActions(SDL_Event e) {
switch (e.key.keysym.sym) {
case SDLK_1:
setSample(1, step);
setSample(1);
break;
case SDLK_2:
setSample(2, step);
setSample(2);
break;
case SDLK_3:
setSample(3, step);
setSample(3);
break;
case SDLK_4:
setSample(4, step);
setSample(4);
break;
case SDLK_p:
play = !play;
step = 0;
break;
case SDLK_e:
setErease = true;
break;
case SDLK_o:
selectPattern = true;
break;
case SDLK_b:
selectBank = true;
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);

31
C/main.cpp

@ -13,28 +13,34 @@
#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};
#include "players.cpp"
bool play = false;
bool setErease = false;
bool selectPattern = false;
bool selectBank = false;
int ereaseSample = 0;
int step = 0;
#include "draw.cpp"
#include "loaders.cpp"
#include "actions.cpp"
#include "players.cpp"
#include "inputs.cpp"
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 +64,7 @@ int main(int argc, char** argv) {
SDL_Quit();
return 0;
} else {
inputActions(event, step);
inputActions(event);
}
break;
case SDL_QUIT:
@ -66,8 +72,6 @@ int main(int argc, char** argv) {
break;
default:
break;
}
if( !done ) { gotEvent = SDL_PollEvent(&event); }
@ -75,11 +79,10 @@ int main(int argc, char** argv) {
}
if(play) {
playPattern(&timer, stepDuration, &step);
playPattern(&timer, stepDuration);
}
}
for( int i = 0; i < NUM_WAVEFORMS; i++ ) {
Mix_FreeChunk(samples[i]);
}

8
C/patterns/pattern2

@ -1,6 +1,6 @@
bank 2
rows 4
10000101
01000011
00100001
00010001
1000010010000001
0100001101000011
0010000100100001
0001000100010001

21
C/players.cpp

@ -1,24 +1,23 @@
void playPattern(int *timer, int duration, int *step) {
void playPattern(int *timer, int duration) {
*timer = *timer >= duration ? 0 : *timer+1;
usleep(1000);
if(*timer == 0) {
drawRects(step-1);
for(int i=0; i<matrix[0]; i++) {
if(pattern[i][*step-1] == 1) {
if(pattern[i][step-1] == 1) {
Mix_PlayChannel(-1, samples[i], 0);
}
}
*step = *step < matrix[1] ? *step+1 : 1;
}
}
void setSample(int sample, int step) {
pattern[sample-1][step-1] = 1;
for(int i=0; i<matrix[0]; i++) {
for(int y=0; y<matrix[1]; y++) {
printf("%d ", pattern[i][y]);
step = step < matrix[1] ? step+1 : 1;
if(setErease && step == 1) {
for(int i=0; i<matrix[1]; i++) {
pattern[ereaseSample-1][i] = 0;
}
setErease = false;
}
printf("\n");
}
}

BIN
C/sonquencer

Binary file not shown.

17
README.md

@ -1 +1,16 @@
sonquencer
# Sonquencer
#### Keys (C version)
| Key | Options | Action | Description |
| ------- | ------- | ------------- | ------------------------------------------------------- |
| 1,2,3,4 | | Play sample n | Set the sample when sequencer is playing or set options |
| P | | Play/Stop | Play/Stop Sequencer |
| E | 1,2,3,4 | Erease | Erease the sample line |
| O | 1,2,3,4 | Open pattern | Open the pattern by number |
| B | 1,2,3,4 | Open bank | Open the bank by number |
| | | | |
| | | | |
| | | | |
| | | | |

Loading…
Cancel
Save