Skip to content

Instantly share code, notes, and snippets.

@tobetchi
Created September 28, 2016 10:53
Show Gist options
  • Save tobetchi/b78370270b245d90e1e88d2d7497e9e4 to your computer and use it in GitHub Desktop.
Save tobetchi/b78370270b245d90e1e88d2d7497e9e4 to your computer and use it in GitHub Desktop.
openFrameworks MIDI send to Launchpad sample
#include "ofMain.h"
#include "ofApp.h"
int main( ){
ofSetupOpenGL(320, 320 , OF_WINDOW);
ofRunApp(new ofApp());
}
#include "ofApp.h"
const int midiMap[] = {
0, 1, 2, 3, 4, 5, 6, 7,
16, 17, 18, 19, 20, 21, 22, 23,
32, 33, 34, 35, 36, 37, 38, 39,
48, 49, 50, 51, 52, 53, 54, 55,
64, 65, 66, 67, 68, 69, 70, 71,
80, 81, 82, 83, 84, 85, 86, 87,
96, 97, 98, 99, 100, 101, 102, 103,
112, 113, 114, 115, 116, 117, 118, 119
};
void ofApp::setup() {
// MIDI Setup
midiOut.listPorts();
midiOut.openPort("Launchpad");
}
void ofApp::draw() {
// Draw grid line
int w = ofGetWidth() / 8;
int h = ofGetHeight() / 8;
for (int i=0; i<8; i++) {
ofDrawLine(w*i, 0, w*i, ofGetHeight());
ofDrawLine(0, h*i, ofGetWidth(), h*i);
}
}
void ofApp::keyReleased(int key) {
switch(key) {
case ' ':
// Reset
midiOut.sendControlChange(1, 0, 0);
break;
}
}
void ofApp::mouseDragged(int x, int y, int button) {
int w = x / (ofGetWidth() / 8);
int h = y / (ofGetHeight() / 8);
int key = ofClamp(8*h+w, 0, 63);
int channel = 1;
int velocity = 127;
midiOut.sendNoteOn(channel, midiMap[key], velocity);
}
#pragma once
#include "ofMain.h"
#include "ofxMidi.h"
class ofApp : public ofBaseApp {
public:
void setup();
void draw();
void keyReleased(int key);
void mouseDragged(int x, int y, int button);
private:
ofxMidiOut midiOut;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment