# HG changeset patch # User samer # Date 1330373350 0 # Node ID 330f2746fedd0282e279a8ab5836f9cd02dc85de # Parent 260cc4f4d70add55a0878a07f6f96685d10a7895 Added keys help in a smaller font; changed loadness keyboard controls. diff -r 260cc4f4d70a -r 330f2746fedd src/melodyTriangle.cpp --- a/src/melodyTriangle.cpp Wed Feb 22 00:30:20 2012 +0000 +++ b/src/melodyTriangle.cpp Mon Feb 27 20:09:10 2012 +0000 @@ -3,6 +3,7 @@ #define BUFFER_ZONE 64 // have to drag this far to snap out of triange. #define NUM_TEMPI 9 +#define NUMEL(a) sizeof(a)/sizeof(a[0]) static int tempi[]={20,30,45,60,90,120,150,180,240}; @@ -25,13 +26,15 @@ bool enableKeys,int voiceIdOffset,int receivePort): numVoices(numVoices), receivePort(receivePort), snapTruePos(enableKeys), enableKeys(enableKeys), randInit(false),allowExit(true), ratio(2), tempoIndex(4), - display_msg(""), display_frames(0) + display_msg(""), display_frames(0), display_font(NULL) { for (int i=0;igetStringBoundingBox(display_msg,0,0); ofSetColor(220,220,220); - display_font.drawString(display_msg, + display_font->drawString(display_msg, (ofGetWidth()-bbox.width)/2, (ofGetHeight()-bbox.height)/2); if (display_frames>0) display_frames--; } if (ratio!=2) { ofSetColor(160,160,160); - display_font.drawString(ofToString(ratio),16,ofGetHeight()-16); + display_font->drawString(ofToString(ratio),16,ofGetHeight()-16); } } @@ -205,6 +208,44 @@ ratio=2; } } + +struct command { + const char *key; + const char *desc; +}; + +struct command voice_commands[] = { +// { "←", "fractional delay" }, +// { "→", "fractional advance" }, +// { "↑", "multiply note rate" }, +// { "↓", "divide note rate" }, + { "[right]", "fractional delay" }, + { "[left]", "fractional advance" }, + { "[up]", "multiply note rate" }, + { "[down]", "divide note rate" }, + { "[", "transpose octave down" }, + { "]", "transpose octave up" }, + { "{", "quieter" }, + { "}", "louder" }, + { "c", "change to nearby pattern" }, + { "s", "shuffle notes" }, + { "h", "this help screen" }, + { "H", "global keys help screen" }, +}; + +struct command global_commands[] = { + { "<", "reduce tempo" }, + { ">", "increase tempo" }, + { "I", "toggle randomise on birth" }, + { "S", "save current pattern" }, + { "C", "calibrate triangle" }, + { "F", "toggle full screen" }, + { "R", "reset token positions" }, + { "Q", "quit" }, + { "H", "this help screen" }, + { "h", "token keys help screen" } +}; + void melodyTriangle::keyPressed(int key){ if (enableKeys){ if (key>='2' && key<='9') { @@ -213,11 +254,11 @@ printf("got key: %d.\n",key); switch (key) { - case '{': + case '<': if (tempoIndex>0) tempoIndex--; sender << msg("/tempo",tempi[tempoIndex]); break; - case '}': + case '>': if (tempoIndexid,ratio,1); break; case ']': sender << msgOctave(v->id, ++v->octave); break; case '[': sender << msgOctave(v->id, --v->octave); break; - case '*': sender << msgAmplitude(v->id, v->louder()); break; - case '/': sender << msgAmplitude(v->id, v->quieter()); break; + case '}': sender << msgAmplitude(v->id, v->louder()); break; + case '{': sender << msgAmplitude(v->id, v->quieter()); break; case 'c': sender << msg("/change",v->id); v->status=Voice::pending; break; + case 's': sender << msg("/shuffle",v->id); break; default: printf("unrecognised key: %d.\n",key); } } +inline int max(int x, int y) { return y>x ? y : x; } + +string melodyTriangle::help_string(bool global) { + stringstream buf; + struct command *cmds; + int n, maxw=0; + + buf << " ( " << (global ? "GLOBAL" : "TOKEN") << " KEYBOARD CONTROLS ) \n\n"; + if (global) { cmds=global_commands; n=NUMEL(global_commands); } + else { cmds=voice_commands; n=NUMEL(voice_commands); } + + for (int i=0; i