Skip to content

Commit

Permalink
added hotkey-midi coupling and assigned F4 hotkey to it
Browse files Browse the repository at this point in the history
  • Loading branch information
hvfrancesco committed Jul 7, 2012
1 parent f46f9e7 commit c780da1
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/parseMIDI.cpp
Expand Up @@ -20,6 +20,40 @@ void testApp::newMidiMessage(ofxMidiMessage& msg) {
cout << "value: " << midiMessage.value << endl;
*/

if(bMidiHotkeyCoupling && midiHotkeyPressed >= 0)
{
if(midiHotkeyMessages.size()>0 && midiHotkeyMessages.size() == midiHotkeyKeys.size())
{
for(int i=0; i < midiHotkeyMessages.size(); i++)
{
if(midiHotkeyKeys[i] == midiHotkeyPressed)
{
midiHotkeyKeys.erase(midiHotkeyKeys.begin()+i);
midiHotkeyMessages.erase(midiHotkeyMessages.begin()+i);
}
}
}
midiHotkeyMessages.push_back(midiMessage);
midiHotkeyKeys.push_back(midiHotkeyPressed);
midiHotkeyPressed = -1;
bMidiHotkeyCoupling = false;
bMidiHotkeyLearning = false;
return;
}

if(midiHotkeyMessages.size()>0 && midiHotkeyMessages.size() == midiHotkeyKeys.size())
{
for(int i=0; i < midiHotkeyMessages.size(); i++)
{
ofxMidiMessage midiControl = midiHotkeyMessages[i];
if(midiMessage.velocity >0 && midiMessage.status == midiControl.status && midiMessage.pitch == midiControl.pitch && midiMessage.channel == midiControl.channel)
{
keyPressed(midiHotkeyKeys[i]);
}
}
}


for(int i=0; i < gui.getPages().size(); i++)
{
for(int j=0; j < gui.getPages()[i]->getControls().size(); j++)
Expand Down
34 changes: 34 additions & 0 deletions src/testApp.cpp
Expand Up @@ -169,8 +169,14 @@ void testApp::setup()
midiIn.addListener(this);
// print received messages to the console
midiIn.setVerbose(true);
//clear vectors used for midi-hotkeys coupling
midiHotkeyMessages.clear();
midiHotkeyKeys.clear();
#endif

bMidiHotkeyCoupling = false;
bMidiHotkeyLearning = false;
midiHotkeyPressed = -1;

// we scan the video dir for videos
//string videoDir = string("./data/video");
Expand Down Expand Up @@ -878,6 +884,18 @@ void testApp::draw()
ofSetHexColor(0xFF0000);
ttf.drawString("Mask-editing mode ", 170, ofGetHeight()-25);
}
if(bMidiHotkeyCoupling) {
if(bMidiHotkeyLearning)
{
ofSetColor(255,255,0);
ttf.drawString("waiting for MIDI message ", 170, ofGetHeight()-25);
}
else{
ofSetColor(255,0,0);
ttf.drawString("MIDI-hotkey coupling ", 170, ofGetHeight()-25);
}
ofRect(2,2,ofGetWidth()-4,ofGetHeight()-4);
}
// draws gui
gui.draw();
}
Expand Down Expand Up @@ -932,6 +950,7 @@ void testApp::mpeResetEvent(ofxMPEEventArgs& event)
void testApp::keyPressed(int key)
{

if(!bMidiHotkeyCoupling){
// moves active layer one position up
if ( key == '+' && !bTimeline && !bGui)
{
Expand Down Expand Up @@ -1107,6 +1126,7 @@ void testApp::keyPressed(int key)
gui.setPage((activeQuad*3)+2);
}


if ( (key == 'd' || key == 'D') && !bTimeline)
{
if(maskSetup && quads[activeQuad].maskPoints.size()>0)
Expand Down Expand Up @@ -1457,6 +1477,20 @@ void testApp::keyPressed(int key)
quads[activeQuad].corners[i] = quads[activeQuad].corners[i] * resultingMatrix;
}
}
}

else
{
bMidiHotkeyLearning = true;
midiHotkeyPressed = key;
}

if ( key == OF_KEY_F4)
{
bMidiHotkeyCoupling = !bMidiHotkeyCoupling;
bMidiHotkeyLearning = false;
midiHotkeyPressed = -1;
}

}

Expand Down
5 changes: 5 additions & 0 deletions src/testApp.h
Expand Up @@ -120,6 +120,8 @@ class testApp : public ofBaseApp
void newMidiMessage(ofxMidiMessage& eventArgs);
ofxMidiIn midiIn;
ofxMidiMessage midiMessage;
vector<ofxMidiMessage> midiHotkeyMessages;
vector<int> midiHotkeyKeys;
#endif

// Shaders
Expand All @@ -144,6 +146,9 @@ class testApp : public ofBaseApp
bool bQuadBezierSpherize;
bool bQuadBezierSpherizeStrong;
bool bQuadBezierReset;
bool bMidiHotkeyCoupling;
bool bMidiHotkeyLearning;
int midiHotkeyPressed;

void openImageFile();
void openVideoFile();
Expand Down

0 comments on commit c780da1

Please sign in to comment.