Created
May 29, 2018 01:19
-
-
Save stephanschulz/c72930fcd69096b8d1f9e573100a615f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright (c) 2013 Dan Wilcox <[email protected]> | |
| * | |
| * BSD Simplified License. | |
| * For information on usage and redistribution, and for a DISCLAIMER OF ALL | |
| * WARRANTIES, see the file, "LICENSE.txt," in this distribution. | |
| * | |
| * See https://github.com/danomatika/ofxMidi for documentation | |
| * | |
| */ | |
| #include "ofApp.h" | |
| string status, old_status; | |
| int pitch, velocity,channel,control,value,deltatime; | |
| //-------------------------------------------------------------- | |
| void ofApp::setup() { | |
| ofSetVerticalSync(true); | |
| ofBackground(255, 255, 255); | |
| ofSetLogLevel(OF_LOG_VERBOSE); | |
| // print input ports to console | |
| midiIn.listPorts(); // via instance | |
| //ofxMidiIn::listPorts(); // via static as well | |
| // open port by number (you may need to change this) | |
| midiIn.openPort(0); | |
| //midiIn.openPort("IAC Pure Data In"); // by name | |
| //midiIn.openVirtualPort("ofxMidiIn Input"); // open a virtual port | |
| // don't ignore sysex, timing, & active sense messages, | |
| // these are ignored by default | |
| midiIn.ignoreTypes(false, false, false); | |
| // add ofApp as a listener | |
| midiIn.addListener(this); | |
| // print received messages to the console | |
| // midiIn.setVerbose(true); | |
| } | |
| //-------------------------------------------------------------- | |
| void ofApp::update() { | |
| // draw the last recieved message contents to the screen | |
| string status = ofxMidiMessage::getStatusString(midiMessage.status); | |
| if(old_status != status){ | |
| old_status = status; | |
| // cout<<"status "<<status<<endl; | |
| } | |
| if(status != "Time Clock"){ | |
| msg = status; | |
| msg += "pitch "+ofToString(pitch)+" velocity "+ofToString(velocity); | |
| channel = midiMessage.channel; | |
| pitch = midiMessage.pitch; | |
| velocity = midiMessage.velocity; | |
| control = midiMessage.control; | |
| value = midiMessage.value; | |
| deltatime = midiMessage.deltatime; | |
| if(lastMsg != msg){ | |
| lastMsg = msg; | |
| ofLog()<<msg; | |
| } | |
| } | |
| } | |
| //-------------------------------------------------------------- | |
| void ofApp::draw() { | |
| ofSetColor(0); | |
| text << "Received: " << status; //ofxMidiMessage::getStatusString(midiMessage.status); | |
| ofDrawBitmapString(text.str(), 20, 20); | |
| text.str(""); // clear | |
| text << "channel: " << channel; | |
| ofDrawBitmapString(text.str(), 20, 34); | |
| text.str(""); // clear | |
| text << "pitch: " <<pitch; | |
| ofDrawBitmapString(text.str(), 20, 48); | |
| text.str(""); // clear | |
| ofDrawRectangle(20, 58, ofMap(pitch, 0, 127, 0, ofGetWidth()-40), 20); | |
| text << "velocity: " <<velocity; | |
| ofDrawBitmapString(text.str(), 20, 96); | |
| text.str(""); // clear | |
| ofDrawRectangle(20, 105, ofMap(velocity, 0, 127, 0, ofGetWidth()-40), 20); | |
| text << "control: " << control; | |
| ofDrawBitmapString(text.str(), 20, 144); | |
| text.str(""); // clear | |
| ofDrawRectangle(20, 154, ofMap(control, 0, 127, 0, ofGetWidth()-40), 20); | |
| text << "value: " << value; | |
| ofDrawBitmapString(text.str(), 20, 192); | |
| text.str(""); // clear | |
| if(midiMessage.status == MIDI_PITCH_BEND) { | |
| ofDrawRectangle(20, 202, ofMap(value, 0, MIDI_MAX_BEND, 0, ofGetWidth()-40), 20); | |
| } | |
| else { | |
| ofDrawRectangle(20, 202, ofMap(value, 0, 127, 0, ofGetWidth()-40), 20); | |
| } | |
| text << "delta: " << deltatime; | |
| ofDrawBitmapString(text.str(), 20, 240); | |
| text.str(""); // clear | |
| } | |
| //-------------------------------------------------------------- | |
| void ofApp::exit() { | |
| // clean up | |
| midiIn.closePort(); | |
| midiIn.removeListener(this); | |
| } | |
| //-------------------------------------------------------------- | |
| void ofApp::newMidiMessage(ofxMidiMessage& msg) { | |
| // make a copy of the latest message | |
| midiMessage = msg; | |
| } | |
| //-------------------------------------------------------------- | |
| void ofApp::keyPressed(int key) { | |
| switch(key) { | |
| case 'l': | |
| midiIn.listPorts(); | |
| break; | |
| } | |
| } | |
| //-------------------------------------------------------------- | |
| void ofApp::keyReleased(int key) { | |
| } | |
| //-------------------------------------------------------------- | |
| void ofApp::mouseMoved(int x, int y) { | |
| } | |
| //-------------------------------------------------------------- | |
| void ofApp::mouseDragged(int x, int y, int button) { | |
| } | |
| //-------------------------------------------------------------- | |
| void ofApp::mousePressed(int x, int y, int button) { | |
| } | |
| //-------------------------------------------------------------- | |
| void ofApp::mouseReleased() { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright (c) 2013 Dan Wilcox <[email protected]> | |
| * | |
| * BSD Simplified License. | |
| * For information on usage and redistribution, and for a DISCLAIMER OF ALL | |
| * WARRANTIES, see the file, "LICENSE.txt," in this distribution. | |
| * | |
| * See https://github.com/danomatika/ofxMidi for documentation | |
| * | |
| */ | |
| #pragma once | |
| #include "ofMain.h" | |
| #include "ofxMidi.h" | |
| class ofApp : public ofBaseApp, public ofxMidiListener { | |
| public: | |
| void setup(); | |
| void update(); | |
| void draw(); | |
| void exit(); | |
| void keyPressed(int key); | |
| void keyReleased(int key); | |
| void mouseMoved(int x, int y ); | |
| void mouseDragged(int x, int y, int button); | |
| void mousePressed(int x, int y, int button); | |
| void mouseReleased(); | |
| void newMidiMessage(ofxMidiMessage& eventArgs); | |
| stringstream text; | |
| ofxMidiIn midiIn; | |
| ofxMidiMessage midiMessage; | |
| string msg, lastMsg; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment