Browse Source

add data loading

develop
Carmine De Rosa 5 years ago
parent
commit
b91493048a
  1. 27
      Processing/TESTS/Sampler/Sampler.pde
  2. 2
      Processing/TESTS/Sampler/SetBeat.pde
  3. 0
      Processing/TESTS/Sampler/data/bank1/2.wav
  4. 28
      Processing/TESTS/Sampler/loadData.pde

27
Processing/TESTS/Sampler/Sampler.pde

@ -2,29 +2,21 @@ import processing.sound.*;
SoundFile[] file; SoundFile[] file;
// Define the number of samples
int numsounds = 5;
int bpm = 280;
int divider = 16;
int duration = int((60/float(bpm))*1000);
// Initialize data
int numSounds = 0;
int numTracks = 0;
int bpm = 0;
int divider = 0;
int duration = 0;
int beat = 0; int beat = 0;
int[][] samples = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
int[][] samples;
void setup() { void setup() {
size(640, 360); size(640, 360);
background(255); background(255);
// Load sound files
file = new SoundFile[numsounds];
for (int i = 0; i < numsounds; i++) {
file[i] = new SoundFile(this, "bank1/" + (i+3) + ".wav");
}
loadData();
} }
@ -46,7 +38,8 @@ void draw() {
fill(150); fill(150);
if(samples[i][beat] != 0) { if(samples[i][beat] != 0) {
fill(0, 200, 0); fill(0, 200, 0);
file[samples[i][beat]+1].play();
file[samples[i][beat]].stop();
file[samples[i][beat]].play();
} }
rect((width/divider)*beat,(height/4)*i, width/divider, height/4); rect((width/divider)*beat,(height/4)*i, width/divider, height/4);

2
Processing/TESTS/Sampler/SetBeat.pde

@ -11,7 +11,7 @@ void keyPressed() {
} else { } else {
int sample = keyCode-65; int sample = keyCode-65;
println(sample); println(sample);
if(sample >= 0 && sample < numsounds) {
if(sample >= 0 && sample < numSounds) {
setBeat(activeRow, beat, sample); setBeat(activeRow, beat, sample);
} }
} }

0
Processing/TESTS/Sampler/data/bank1/12.wav → Processing/TESTS/Sampler/data/bank1/2.wav

28
Processing/TESTS/Sampler/loadData.pde

@ -0,0 +1,28 @@
void loadData() {
numSounds = 5;
numTracks = 4;
bpm = 280;
divider = 16;
duration = int((60/float(bpm))*1000);
beat = 0;
String bank = "bank1";
samples = new int[numTracks][divider];
for(int i=0; i<numTracks; i++) {
int[] tmp = new int[divider];
for(int x=0; x<divider; x++) {
tmp[x] = 0;
}
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");
}
}
Loading…
Cancel
Save