Compare commits
33 Commits
87 changed files with 46782 additions and 1 deletions
@ -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"); |
|||
} |
|||
} |
|||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@ |
|||
g++ -o sonquencer -I/usr/include/SDL2 main.cpp -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer |
@ -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); |
|||
} |
|||
|
@ -0,0 +1,33 @@ |
|||
void inputActions(SDL_Event e) { |
|||
switch (e.key.keysym.sym) { |
|||
case SDLK_1: |
|||
setSample(1); |
|||
break; |
|||
case SDLK_2: |
|||
setSample(2); |
|||
break; |
|||
case SDLK_3: |
|||
setSample(3); |
|||
break; |
|||
case SDLK_4: |
|||
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; |
|||
} |
|||
} |
@ -0,0 +1,84 @@ |
|||
|
|||
int loadBank(int bank) { |
|||
|
|||
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 ) { |
|||
fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); |
|||
exit(-1); |
|||
} |
|||
|
|||
result = Mix_AllocateChannels(4); |
|||
if( result < 0 ) { |
|||
fprintf(stderr, "Unable to allocate mixing channels: %s\n", SDL_GetError()); |
|||
exit(-1); |
|||
} |
|||
|
|||
char waveFileName[17]; |
|||
|
|||
for( int i = 0; i < NUM_WAVEFORMS; i++ ) { |
|||
sprintf(waveFileName, "banks/BANK%d/%d.wav", bank, i+1); |
|||
|
|||
samples[i] = Mix_LoadWAV(waveFileName); |
|||
if( samples[i] == NULL ) { |
|||
fprintf(stderr, "Unable to load wave file: %s\n", waveFileName); |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
void loadPattern(int patternNum) { |
|||
printf("\nLoading pattern %d ...\n", patternNum); |
|||
|
|||
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; |
|||
|
|||
sprintf(patternFile, "patterns/pattern%d", patternNum); |
|||
fp = fopen(patternFile, "r"); |
|||
if(fp == NULL) {exit(EXIT_FAILURE);} |
|||
|
|||
while ((read = getline(&line, &len, fp)) != -1) { |
|||
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<cols; i++) { |
|||
pattern[lineCount-2][i] = line[i]-'0'; |
|||
} |
|||
} |
|||
lineCount++; |
|||
} |
|||
|
|||
printf("Pattern: %d\nBank: %d\nColumns: %d\nRows: %d\n", patternNum, bank, cols, rows); |
|||
|
|||
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]); |
|||
} |
|||
printf("\n"); |
|||
} |
|||
|
|||
drawRects(0); |
|||
|
|||
fclose(fp); |
|||
if(line) {free(line);} |
|||
loadBank(bank); |
|||
} |
@ -0,0 +1,94 @@ |
|||
#include <stdio.h> |
|||
#include <unistd.h> |
|||
#include <syslog.h> |
|||
#include <string.h> |
|||
#include <math.h> |
|||
|
|||
#include "SDL.h" |
|||
#include "SDL_mixer.h" |
|||
#include "SDL_image.h" |
|||
|
|||
#define NUM_WAVEFORMS 4 |
|||
#define PATTERN_ROWS 10 |
|||
#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; |
|||
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; |
|||
int timer = 0; |
|||
int stepDuration = 200; |
|||
|
|||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO ); |
|||
atexit(SDL_Quit); |
|||
|
|||
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); |
|||
SDL_Delay(1000); |
|||
|
|||
SDL_RenderClear(renderer); |
|||
SDL_RenderPresent(renderer); |
|||
SDL_Event event; |
|||
|
|||
if(loadBank(1) == false) {return -1;} |
|||
loadPattern(1); |
|||
|
|||
while (!done) { |
|||
bool gotEvent = SDL_PollEvent(&event); |
|||
|
|||
while (!done && gotEvent) { |
|||
switch (event.type) { |
|||
case SDL_KEYDOWN: |
|||
if(event.key.keysym.sym == SDLK_ESCAPE) { |
|||
Mix_CloseAudio(); |
|||
SDL_Quit(); |
|||
return 0; |
|||
} else { |
|||
inputActions(event); |
|||
} |
|||
break; |
|||
case SDL_QUIT: |
|||
done = true; |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
|
|||
if( !done ) { gotEvent = SDL_PollEvent(&event); } |
|||
|
|||
} |
|||
|
|||
if(play) { |
|||
playPattern(&timer, stepDuration); |
|||
} |
|||
} |
|||
|
|||
for( int i = 0; i < NUM_WAVEFORMS; i++ ) { |
|||
Mix_FreeChunk(samples[i]); |
|||
} |
|||
|
|||
Mix_CloseAudio(); |
|||
SDL_Quit(); |
|||
return 0; |
|||
} |
|||
|
@ -0,0 +1,6 @@ |
|||
bank 1 |
|||
rows 4 |
|||
00000000 |
|||
00000000 |
|||
00000000 |
|||
00000000 |
@ -0,0 +1,6 @@ |
|||
bank 2 |
|||
rows 4 |
|||
1000010010000001 |
|||
0100001101000011 |
|||
0010000100100001 |
|||
0001000100010001 |
@ -0,0 +1,23 @@ |
|||
|
|||
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) { |
|||
Mix_PlayChannel(-1, samples[i], 0); |
|||
} |
|||
} |
|||
|
|||
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; |
|||
} |
|||
} |
|||
} |
Binary file not shown.
@ -0,0 +1,81 @@ |
|||
import processing.sound.*; |
|||
|
|||
SoundFile[] file; |
|||
|
|||
// Initialize data |
|||
int numSounds = 0; |
|||
int numTracks = 0; |
|||
int bpm = 0; |
|||
int pattern = 0; |
|||
int bank = 0; |
|||
int swing = 0; |
|||
int divider = 0; |
|||
int duration = 0; |
|||
int beat = 0; |
|||
|
|||
String patternLabel = "NO PATTERN"; |
|||
String bpmLabel = "UNSET"; |
|||
String swingLabel = "100%"; |
|||
|
|||
boolean[][] samples; |
|||
|
|||
void setup() { |
|||
size(640, 460, P2D); |
|||
background(255); |
|||
loadData(); |
|||
setData(); |
|||
} |
|||
|
|||
void draw() { |
|||
background(50); |
|||
strokeWeight(3); |
|||
fill(200); |
|||
|
|||
printControllerStatus(); |
|||
|
|||
for(int i=0; i<numSounds; i++) { |
|||
for(int y=0; y<divider; y++) { |
|||
fill(samples[i][y] ? 120: 90); |
|||
stroke(50); |
|||
rect((width/divider)*y,((height-100)/numSounds)*i, width/divider, (height-100)/numSounds, 5); |
|||
} |
|||
} |
|||
|
|||
if(controller[0] == "PLAY") { |
|||
for(int i=0; i<numSounds; i++) { |
|||
fill(150); |
|||
if(samples[i][beat]) { |
|||
fill(0, 200, 0); |
|||
file[i].stop(); |
|||
file[i].play(); |
|||
} |
|||
|
|||
stroke(50); |
|||
rect((width/divider)*beat,((height-100)/numSounds)*i, width/divider, (height-100)/numSounds, 5); |
|||
} |
|||
|
|||
beat++; |
|||
if(beat>=divider){beat=0;} |
|||
|
|||
|
|||
// ################################## End of beat |
|||
if(beat==0) { |
|||
if(doRec == false) { |
|||
controller[1] = "UNSET"; |
|||
} |
|||
doRec = false; |
|||
} |
|||
|
|||
|
|||
if(ereaseRow>0 && doErease && beat==0) { |
|||
for(int x=0; x<divider; x++) { |
|||
samples[ereaseRow-1][x] = false; |
|||
} |
|||
ereaseRow = 0; |
|||
doErease = false; |
|||
} |
|||
} |
|||
|
|||
delay(duration); |
|||
|
|||
} |
@ -0,0 +1,85 @@ |
|||
int ereaseRow = 0; |
|||
boolean doErease = false; |
|||
boolean doRec = false; |
|||
boolean chooseBank = false; |
|||
boolean choosePattern = false; |
|||
boolean chooseBPM = false; |
|||
|
|||
void setBeat(int index, int sample) { |
|||
samples[sample][index] = true; |
|||
} |
|||
|
|||
|
|||
|
|||
void keyPressed() { |
|||
//println(keyCode); |
|||
if(keyCode >= 64 && keyCode <= 88) { // From A to Z |
|||
//println(key); |
|||
//ereaseRow = keyCode-48; |
|||
|
|||
if(key == 'b') { // BANK |
|||
chooseBank = true; |
|||
controller[0] = "STOP"; |
|||
controller[2] = "CHOOSE..."; |
|||
} |
|||
if(key == 'p') { // PLAY/STOP |
|||
controller[0] = controller[0] == "PLAY" ? "STOP" : "PLAY"; |
|||
beat=0; |
|||
} |
|||
if(key == 'r') { // REC/OVERDUB |
|||
controller[1] = controller[1] == "UNSET" ? "REC/OVERDUB" : "UNSET"; |
|||
doRec = true; |
|||
} |
|||
if(key == 's') { // BPM |
|||
bpmLabel = "CHOOSE..."; |
|||
chooseBPM = true; |
|||
} |
|||
if(key == 'o') { // PATTERN |
|||
choosePattern = true; |
|||
controller[0] = "STOP"; |
|||
patternLabel = "CHOOSE..."; |
|||
} |
|||
if(key == 'x') { // EREASE |
|||
controller[1] = "EREASE"; |
|||
} |
|||
|
|||
} else if(keyCode >= 48 && keyCode < 57) { // From 1 to 9 |
|||
int code = keyCode-49; |
|||
ereaseRow = controller[1] == "EREASE" ? keyCode-48 : 0; |
|||
doErease = ereaseRow>0; |
|||
|
|||
//&& code < numSounds |
|||
if(code >= 0 && !doErease) { |
|||
|
|||
if(chooseBank) { |
|||
controller[2] = banksLabels[code]; |
|||
bank = code+1; |
|||
chooseBank = false; |
|||
setData(); |
|||
|
|||
} else if(chooseBPM) { |
|||
bpmLabel = bpmsArray[code]+""; |
|||
bpm = bpmsArray[code]; |
|||
chooseBPM = false; |
|||
setData(); |
|||
|
|||
} else if(choosePattern) { |
|||
pattern = code; |
|||
patternLabel = "PATTERN" + (code+1); |
|||
choosePattern = false; |
|||
samples = patternsArray[code]; |
|||
numSounds = soundNumbersArray[code]; |
|||
divider = dividersArray[code]; |
|||
bank = banksArray[code]; |
|||
bpm = bpmPatArray[code]; |
|||
bpmLabel = bpmPatArray[code]+""; |
|||
numTracks = numSounds; |
|||
controller[2] = banksLabels[code]; |
|||
setData(); |
|||
|
|||
} else if(controller[1] != "EREASE" && controller[1] != "UNSET" && controller[0] != "STOP") { |
|||
setBeat(beat, code); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,29 @@ |
|||
String[] controller = {"STOP", "UNSET", "BANK1", "PATTERN"}; |
|||
|
|||
void printControllerStatus() { |
|||
fill(200); |
|||
text("PLAY/STOP:", 10, height-75); |
|||
text("REC/OVERDUB/ERASE:", 10, height-55); |
|||
text("BANK:", 10, height-35); |
|||
text("PATTERN/BPM/SWING:", 10, height-15); |
|||
|
|||
fill(240); |
|||
text(controller[0], 180, height-75); |
|||
text(controller[1], 180, height-55); |
|||
text(controller[2], 180, height-35); |
|||
text(controller[3], 180, height-15); |
|||
|
|||
fill(200); |
|||
text("PATTERN:", (width/2)+20, height-75); |
|||
text("BPM:", (width/2)+20, height-55); |
|||
text("SWING:",(width/2)+20, height-35); |
|||
|
|||
fill(240); |
|||
text(patternLabel, (width/2)+100, height-75); |
|||
text(bpmLabel, (width/2)+100, height-55); |
|||
text(swing, (width/2)+100, height-35); |
|||
|
|||
stroke(200); |
|||
line(width/2, height-85, width/2, height-15); |
|||
|
|||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,44 @@ |
|||
{ |
|||
"patterns": [ |
|||
{ |
|||
"name": "Pattern 1", |
|||
"numSounds": 5, |
|||
"divider": 8, |
|||
"bank": 1, |
|||
"bpm": 280, |
|||
"pattern": [ |
|||
[true, false, true, false, true, false, true, false], |
|||
[true, false, false, true, false, true, false, false], |
|||
[false, true, false, false, false, false, false, false], |
|||
[false, false, true, false, false, false, true, false], |
|||
[false, false, false, false, true, false, false, false] |
|||
] |
|||
}, |
|||
{ |
|||
"name": "Pattern 2", |
|||
"numSounds": 3, |
|||
"divider": 6, |
|||
"bank": 2, |
|||
"bpm": 180, |
|||
"pattern": [ |
|||
[false, true, false, true, false, true], |
|||
[false, false, true, false, false, true], |
|||
[false, false, false, true, false, false] |
|||
] |
|||
} |
|||
], |
|||
|
|||
"banks": [ |
|||
{"name": "Bank1"}, |
|||
{"name": "Drum"}, |
|||
{"name": "Electric"}, |
|||
{"name": "Bank 123"} |
|||
], |
|||
|
|||
"bpm": [ |
|||
{"value": 80}, |
|||
{"value": 120}, |
|||
{"value": 180}, |
|||
{"value": 280} |
|||
] |
|||
} |
@ -0,0 +1,65 @@ |
|||
String[] patternLabels = {}; |
|||
String[] banksLabels = {}; |
|||
int[] soundNumbersArray = {}; |
|||
int[] dividersArray = {}; |
|||
int[] banksArray = {}; |
|||
int[] bpmPatArray = {}; |
|||
int[] bpmsArray = {}; |
|||
boolean[][][] patternsArray = {}; |
|||
|
|||
void loadData() { |
|||
|
|||
JSONObject json; |
|||
json = loadJSONObject("data.json"); |
|||
|
|||
JSONArray pattsArray = json.getJSONArray("patterns"); |
|||
JSONArray bnksArray = json.getJSONArray("banks"); |
|||
JSONArray bpmArray = json.getJSONArray("bpm"); |
|||
|
|||
for(int bpm=0; bpm<bpmArray.size(); bpm++) { |
|||
JSONObject single = bpmArray.getJSONObject(bpm); |
|||
bpmsArray = append(bpmsArray, single.getInt("value")); |
|||
} |
|||
|
|||
bpm = bpmsArray[0]; |
|||
|
|||
for(int bnk=0; bnk<bnksArray.size(); bnk++) { |
|||
JSONObject single = bnksArray.getJSONObject(bnk); |
|||
banksLabels = append(banksLabels, single.getString("name")); |
|||
} |
|||
|
|||
for(int pat=0; pat<pattsArray.size(); pat++) { |
|||
JSONObject single = pattsArray.getJSONObject(pat); |
|||
JSONArray singlePattsArray = single.getJSONArray("pattern"); |
|||
boolean[][] tmpPat = {}; |
|||
|
|||
patternLabels = append(patternLabels, single.getString("name")); |
|||
soundNumbersArray = append(soundNumbersArray, single.getInt("numSounds")); |
|||
dividersArray = append(dividersArray, single.getInt("divider")); |
|||
banksArray = append(banksArray, single.getInt("bank")); |
|||
bpmPatArray = append(bpmPatArray, single.getInt("bpm")); |
|||
|
|||
for(int x=0; x<singlePattsArray.size(); x++) { |
|||
boolean[] tmpRow = {}; |
|||
JSONArray rowsArray = singlePattsArray.getJSONArray(x); |
|||
for(int y=0; y<rowsArray.size(); y++) { |
|||
boolean boolVal = rowsArray.getBoolean(y); |
|||
tmpRow = (boolean[]) append(tmpRow, boolVal); |
|||
} |
|||
tmpPat = (boolean[][]) append(tmpPat, tmpRow); |
|||
} |
|||
patternsArray = (boolean[][][]) append(patternsArray, tmpPat); |
|||
} |
|||
|
|||
/* |
|||
for(int i=0; i<patternsArray.length; i++) { |
|||
println("######"+i); |
|||
for(int x=0; x<patternsArray[i].length; x++) { |
|||
println("######"+x); |
|||
printArray(patternsArray[i][x]); |
|||
} |
|||
} |
|||
*/ |
|||
|
|||
|
|||
} |
@ -0,0 +1,27 @@ |
|||
void setData() { |
|||
|
|||
|
|||
swing = 50; |
|||
duration = int((60/float(bpm))*1000); |
|||
beat = 0; |
|||
|
|||
//println(bpm); |
|||
//println(patternLabel); |
|||
|
|||
/* |
|||
samples = new boolean[numTracks][divider]; |
|||
for(int i=0; i<numTracks; i++) { |
|||
boolean[] tmp = new boolean[divider]; |
|||
for(int x=0; x<divider; x++) { |
|||
tmp[x] = false; |
|||
} |
|||
samples[i] = tmp; |
|||
}*/ |
|||
|
|||
// Load sound files |
|||
file = new SoundFile[numSounds]; |
|||
for (int i = 0; i < numSounds; i++) { |
|||
file[i] = new SoundFile(this, "BANK" + bank + "/" + (i+1) + ".wav"); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,71 @@ |
|||
import processing.sound.*; |
|||
|
|||
SoundFile[] file; |
|||
|
|||
// Initialize data |
|||
int numSounds = 0; |
|||
int numTracks = 0; |
|||
int bpm = 0; |
|||
int divider = 0; |
|||
int duration = 0; |
|||
int beat = 0; |
|||
|
|||
boolean[][] samples; |
|||
|
|||
void setup() { |
|||
size(640, 460); |
|||
background(255); |
|||
|
|||
loadData(); |
|||
|
|||
} |
|||
|
|||
void draw() { |
|||
background(50); |
|||
stroke(255); |
|||
fill(200); |
|||
|
|||
printControllerStatus(); |
|||
|
|||
if(controller[0] == "PLAY") { |
|||
for(int i=0; i<numSounds; i++) { |
|||
for(int y=0; y<divider; y++) { |
|||
fill(samples[i][y] ? 120: 90); |
|||
rect((width/divider)*y,((height-100)/numSounds)*i, width/divider, (height-100)/numSounds); |
|||
} |
|||
} |
|||
|
|||
for(int i=0; i<numSounds; i++) { |
|||
fill(150); |
|||
if(samples[i][beat]) { |
|||
fill(0, 200, 0); |
|||
file[i].stop(); |
|||
file[i].play(); |
|||
} |
|||
rect((width/divider)*beat,((height-100)/numSounds)*i, width/divider, (height-100)/numSounds); |
|||
} |
|||
|
|||
beat++; |
|||
if(beat>=divider){beat=0;} |
|||
|
|||
// End of beat |
|||
if(beat==0) { |
|||
if(doRec == false) { |
|||
controller[1] = "UNSET"; |
|||
} |
|||
doRec = false; |
|||
} |
|||
|
|||
|
|||
if(ereaseRow>0 && doErease && beat==0) { |
|||
for(int x=0; x<divider; x++) { |
|||
samples[ereaseRow-1][x] = false; |
|||
} |
|||
ereaseRow = 0; |
|||
doErease = false; |
|||
} |
|||
} |
|||
|
|||
delay(duration); |
|||
|
|||
} |
@ -0,0 +1,31 @@ |
|||
int ereaseRow = 0; |
|||
boolean doErease = false; |
|||
boolean doRec = false; |
|||
|
|||
void setBeat(int index, int sample) { |
|||
samples[sample][index] = true; |
|||
} |
|||
|
|||
void keyPressed() { |
|||
println(keyCode); |
|||
if(keyCode >= 48 && keyCode < 53) { |
|||
ereaseRow = keyCode-48; |
|||
} else if(keyCode >= 74) { |
|||
if(key == 'p') { |
|||
controller[0] = controller[0] == "PLAY" ? "STOP" : "PLAY"; |
|||
beat=0; |
|||
} |
|||
if(key == 'r') { |
|||
controller[1] = controller[1] == "UNSET" ? "REC/OVERDUB" : "UNSET"; |
|||
doRec = true; |
|||
} |
|||
} else { |
|||
int sample = keyCode-65; |
|||
doErease = ereaseRow>0; |
|||
if(sample >= 0 && sample < numSounds && !doErease) { |
|||
if(controller[1] != "EREASE" && controller[1] != "UNSET") { |
|||
setBeat(beat, sample); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,16 @@ |
|||
String[] controller = {"STOP", "UNSET", "BANK", "PATTERN"}; |
|||
|
|||
|
|||
void printControllerStatus() { |
|||
fill(200); |
|||
text("PLAY/STOP:", 10, height-75); |
|||
text("REC/OVERDUB/ERASE:", 10, height-55); |
|||
text("BANK:", 10, height-35); |
|||
text("PATTERN/BPM/SWING:", 10, height-15); |
|||
|
|||
fill(240); |
|||
text(controller[0], 180, height-75); |
|||
text(controller[1], 180, height-55); |
|||
text(controller[2], 180, height-35); |
|||
text(controller[3], 180, height-15); |
|||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,28 @@ |
|||
void loadData() { |
|||
|
|||
numSounds = 10; |
|||
numTracks = numSounds;//4; |
|||
bpm = 280; |
|||
divider = 16; |
|||
duration = int((60/float(bpm))*1000); |
|||
beat = 0; |
|||
|
|||
String bank = "bank1"; |
|||
|
|||
samples = new boolean[numTracks][divider]; |
|||
for(int i=0; i<numTracks; i++) { |
|||
boolean[] tmp = new boolean[divider]; |
|||
for(int x=0; x<divider; x++) { |
|||
tmp[x] = false; |
|||
} |
|||
|
|||
samples[i] = tmp; |
|||
} |
|||
|
|||
// Load sound files |
|||
file = new SoundFile[numSounds]; |
|||
for (int i = 0; i < numSounds; i++) { |
|||
file[i] = new SoundFile(this, bank + "/" + (i+1) + ".wav"); |
|||
} |
|||
|
|||
} |
@ -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 | |
|||
| | | | | |
|||
| | | | | |
|||
| | | | | |
|||
| | | | | |
|||
|
|||
|
Binary file not shown.
After Width: | Height: | Size: 139 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
Binary file not shown.
After Width: | Height: | Size: 437 KiB |
Binary file not shown.
Loading…
Reference in new issue