Skip to content

Instantly share code, notes, and snippets.

@tobetchi

tobetchi/main.cpp

Created Sep 29, 2016
Embed
What would you like to do?
Simple VJ Controller: Resolume + Launchpad + openFrameworks
#include "ofMain.h"
#include "ofApp.h"
int main( ){
ofSetupOpenGL(320, 320, OF_WINDOW);
ofRunApp(new ofApp());
}
#include "ofApp.h"
#include <regex>
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
};
int ledWidth = 8, ledHeight = 8;
void ofApp::setup() {
// Setup OSC
receiver.setup(PORT);
sender.setup(HOST, SEND_PORT);
// Setup MIDI
midiIn.listPorts();
midiIn.openPort("Launchpad");
midiOut.openPort("Launchpad");
midiIn.addListener(this);
// Reset LED
midiOut.sendControlChange(1, 0, 0);
}
void ofApp::update() {
// Recieve OSC message
while (receiver.hasWaitingMessages()) {
ofxOscMessage m;
receiver.getNextMessage(m);
string address = m.getAddress();
// レイヤー不透明度を指定するOSCメッセージを受信
std::regex re("/layer([0-9]+)/video/opacity/values");
std::smatch match;
if (std::regex_match(address, match, re)) {
int x = ofMap(m.getArgAsFloat(0), 0, 1, 0, 7);
int y = ofToInt(match[1]) - 1;
bool set;
// 不透明度の値に合わせてLEDを横一列に点灯
for (int i=0; i<ledWidth; i++) {
set = i <= x ? true : false;
ledSet(i, y, set);
}
}
}
}
void ofApp::newMidiMessage(ofxMidiMessage& msg) {
int x = msg.pitch%16;
int y = msg.pitch/16;
bool pressed = msg.velocity ? true : false;
bool set;
if (!pressed) return;
// Send MIDI to Launchpad
for (int i=0; i<ledWidth; i++) {
set = i <= x ? true : false;
ledSet(i, y, set);
}
// Send OSC to Resolume
int layer = y+1;
float opacity = ofMap(x, 0, 7, 0, 1.0);
// レイヤー不透明度を指定するOSCメッセージを送信
m.setAddress("/layer"+ofToString(layer)+"/video/opacity/values");
m.addFloatArg(opacity);
sender.sendMessage(m);
m.clear();
}
// LaunchpadのLEDを点灯
void ofApp::ledSet(int x, int y, bool set) {
midiOut.sendNoteOn(1, midiMap[y*ledHeight+x], set ? 127 : 0);
}
#pragma once
#include "ofMain.h"
#include "ofxOsc.h"
#include "ofxMidi.h"
#define PORT 7001
#define SEND_PORT 7000
#define HOST "localhost"
class ofApp : public ofBaseApp, public ofxMidiListener {
public:
void setup();
void update();
private:
ofxOscReceiver receiver;
ofxOscSender sender;
ofxOscMessage m;
ofxMidiIn midiIn;
ofxMidiOut midiOut;
void newMidiMessage(ofxMidiMessage& msg);
void ledSet(int x, int y, bool set);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.