Git Product home page Git Product logo

kodelife_midi's Introduction

kodelife_midi

In the quest to integrate midi into my generative art, I started using KodeLife by Hexler. The midi example in their documentation didn't work for me, but I was able to figure it out with some tinkering and with the help of some other generative artists. Hopefully this works for you! Read the code below, or download the .klproj file in this repo.

#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;

//In codelife, you need to click the + button by parameters, navigate to 'built-in>input', and add 'midi channel'
//At the time of writing this, the default name is midi1. I changed it to u_midi
uniform sampler2D u_midi;


//this function takes a midi offset and turns it into coordinates for the texture/sampler
//the KodeLife examples use ints, but float seemed to be required in my case
//values are divided by 32. because the midi channel resolution is 32, but texture2D requires 0.-1.
vec2 midiCoord(float offset)
{
    float x = mod(offset,32.);
    float y = offset / 32.;
    return vec2(x,y)/32.;
}

void main() {
    //st represents the position from 0. to 1. on the x and y axes where the pixel lives
    //this convention is adopted from thebookofshaders.com
    vec2 st = gl_FragCoord.xy/u_resolution;
    
    //the 3 at the beginning takes you to the midi continuous controllers
    //21, 22, and 23 are the addresses for the continuous controllers I am using for r, g, and b
    //I found these using components, the configuration software for my novation controller
    
    float ccr = 3. * 127. + 21.;
    float ccg = 3. * 127. + 22.;
    float ccb = 3. * 127. + 23.;
    
    //now we can use texture2D and midiCoord to pull r, g, and b values fro the 4th dimension of the sample
    float r = texture2D(u_midi,midiCoord(ccr)).w;
    float g = texture2D(u_midi,midiCoord(ccg)).w;
    float b = texture2D(u_midi,midiCoord(ccb)).w;
    

    gl_FragColor = vec4(r,g,b,1.);
}

kodelife_midi's People

Contributors

dataneel avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.