From d3f4d3285d1be8a6445bae43827961c44880033b Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 15 Feb 2018 18:33:39 +0100 Subject: note switching --- sv.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 12 deletions(-) (limited to 'sv.c') diff --git a/sv.c b/sv.c index de792f0..338509d 100644 --- a/sv.c +++ b/sv.c @@ -48,7 +48,7 @@ typedef struct Param { int new; } Parameter; -Parameter parameters[32]; +Parameter parameters[4]; static snd_seq_t *seq_handle; static int in_port; @@ -180,10 +180,10 @@ void readImage(int i) { glBindTexture(GL_TEXTURE_2D,images[i].id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); stbi_image_free(pixels); } @@ -200,7 +200,7 @@ void updateImages(int force) { void updateParams(int force) { glUniform1i(glGetUniformLocation(shader.id, "bars"), bars); - for (int i = 0; i<32; i++) { + for (int i = 0; i<4; i++) { if (parameters[i].new || force) { glUniform1f(glGetUniformLocation(shader.id, "params")+i, parameters[i].value); parameters[i].new = 0; @@ -210,8 +210,8 @@ void updateParams(int force) { int ticks =0; int running = 0; -int note = 0; -int vel = 0; +int idx[2] = {0,1}; +float vel[2] = {0,0}; void *readMidi() { midi_open(); @@ -219,11 +219,56 @@ void *readMidi() { snd_seq_event_t *ev = NULL; snd_seq_event_input(seq_handle, &ev); if (ev->type == SND_SEQ_EVENT_NOTEON) { - note = ev->data.note.note; - vel = ev->data.note.velocity; + int note = ev->data.note.note; + int v = ev->data.note.velocity; + int i,j; + if (note < 48) { + i = 0; + j = note-36; + } + else { + i = 1; + j = note-48; + } + // only white keys + if (j == 0) { + idx[i] = 0; vel[i] = (float)v/127.0; + } + else if (j == 2) { + idx[i] = 1; vel[i] = (float)v/127.0; + } + else if (j == 4) { + idx[i] = 2; vel[i] = (float)v/127.0; + } + else if (j == 5) { + idx[i] = 3; vel[i] = (float)v/127.0; + } + } else if (ev->type == SND_SEQ_EVENT_NOTEOFF) { - vel = 0; + int note = ev->data.note.note; + int i,j; + if (note < 48) { + i = 0; + j = note-36; + } + else { + i = 1; + j = note-48; + } + // only white keys + if (j == 0) { + idx[i] = 0; vel[i] = 0; + } + else if (j == 2) { + idx[i] = 1; vel[i] = 0; + } + else if (j == 4) { + idx[i] = 2; vel[i] = 0; + } + else if (j == 5) { + idx[i] = 3; vel[i] = 0; + } } else if(ev->type == SND_SEQ_EVENT_CONTROLLER) printf("[%d] Control: %2x val(%2x)\n", ev->time.tick, @@ -318,7 +363,11 @@ int main(int argc, char **argv) { //glUniform1f(glGetUniformLocation(shader.id, "time"),glfwGetTime()); glUniform1f(glGetUniformLocation(shader.id, "ticks"),(float)ticks); //printf("%i\n",note); - glUniform1i(glGetUniformLocation(shader.id, "program"),note-36); + //glUniform1i(glGetUniformLocation(shader.id, "program"),note-36); + for (int i = 0; i<2; i++) { + glUniform1i(glGetUniformLocation(shader.id, "idx")+i,idx[i]); + glUniform1f(glGetUniformLocation(shader.id, "vel")+i,vel[i]); + } if (shader.new) { createShader(); glUniform2f(glGetUniformLocation(shader.id, "resolution"),width,height); // important!! -- cgit v1.2.3