Ejemplo n.º 1
0
void processMidiCommand(MidiMessage& message) {
   if (message.p0() != 0x90 || message.p2() == 0) {
      return;
   }

   switch (message.p1()) {
      case 60:                     // Middle C = beat
         keyboardchar(' ');
         break;
      case 61:                     // C# = amplitude control
         {
         double amp = performance.getAmp();
         amp = amp * message.p2() / 64;
         if (amp < 0) {
            amp = 0;
         } else if (amp > 127) {
            amp = 127;
         }
         performance.setAmp((int)amp);
         }
         break;
      case 71:                      // B  = 1 beat tempo follow
         keyboardchar('1');
         break;
      case 72:                      // C  = 2 beat tempo follow
         keyboardchar('2');
         break;
      case 73:                      // C# = 3 beat tempo follow
         keyboardchar('3');
         break;
      case 74:                      // D  = 4 beat tempo follow
         keyboardchar('4');
         break;
      case 79:                      // G  = constant tempo follow
         keyboardchar('9');
         break;
      case 80:                      // G# = automatic
         keyboardchar('0');
         break;
      case 62:                      // amplitude decrease
         keyboardchar('[');
         break;
      case 63:                      // amplitude increase
         keyboardchar(']');
         break;
      case 64:                      // tempo decrease
         keyboardchar('-');
         break;
      case 65:                      // tempo increase
         keyboardchar('=');
         break;
   }

}
Ejemplo n.º 2
0
void keyboardchar(int command) {
   switch (command) {
      case ' ':
         performance.beat();
         break;
      case 'b':                   // print beat location in performance
         cout << "Current beat is: " << performance.getBeatLocation() << endl;
         break;
      case 'z':                   // toggle MIDI collapsing
         {
         int setting = performance.channelCollapse();
         setting = !setting;
         performance.channelCollapse(setting);
         if (setting) {
            cout << "All notes going to channel 1" << endl;
         } else {
            cout << "All channel settings are unmodified" << endl;
         }
         }
         break;
      case 'p':                   // start playing the performance
         performance.play();
         cout << "Starting performance" << endl;
         break;
      case '[':                   // set performance volume lower
         {
         double amp = performance.getAmp();
         amp /= 1.15;
         performance.setAmp(amp);
         cout << "Amplitude scaling = " << performance.getAmp() << endl;
         }
         break;
      case ']':                   // set performance volume higher
         {
         double amp = performance.getAmp();
         amp *= 1.15;
         performance.setAmp(amp);
         cout << "Amplitude scaling = " << performance.getAmp() << endl;
         }
         break;
      case 't':                   // current tempo display
         cout << "The Current tempo is: " << performance.getTempo() << endl;
         break;
      case '-':                   // slow down the tempo
         {
         double tempo = performance.getTempo();
         tempo /= 1.03;
         performance.setTempo(tempo);
         cout << "The Tempo was set on the keyboard to : " << tempo << endl;
         }
         break;
      case '=':                   // speed up the tempo
         {
         double tempo = performance.getTempo();
         tempo *= 1.03;
         performance.setTempo(tempo);
         cout << "The Tempo was set on the keyboard to : " << tempo << endl;
         }
         break;
      case '0':                   // automatic tempo control
         performance.setTempoMethod(TEMPO_METHOD_AUTOMATIC);
         cout << "Automatic Tempo Setting at tempo = " 
              << performance.getTempo() << endl;
         break;
      case '9':                   // constant tempo control
         performance.setTempoMethod(TEMPO_METHOD_CONSTANT);
         cout << "Constant Tempo Contro at tempo = " 
              << performance.getTempo() << endl;
         break;
      case '1':                   // 1 beat history average tempo
         performance.setTempoMethod(TEMPO_METHOD_ONEBACK);
         cout << "One beat tempo history" << endl;
         break;
      case '2':                   // 2 beat history average tempo
         performance.setTempoMethod(TEMPO_METHOD_TWOBACK);
         cout << "Two beat tempo history" << endl;
         break;
      case '3':                   // 3 beat history average tempo
         performance.setTempoMethod(TEMPO_METHOD_THREEBACK);
         cout << "Three beat tempo history" << endl;
         break;
      case '4':                   // 4 beat history average tempo
         performance.setTempoMethod(TEMPO_METHOD_FOURBACK);
         cout << "Four beat tempo history" << endl;
         break;
   }
}