Beispiel #1
0
int checkKeyboard(void) {
   int output = -1;
   if (keyboard.hit()) {
      output = keyboard.getch();
   }
   return output;
}
Beispiel #2
0
int main(int argc, char** argv) {
   options.setOptions(argc, argv);
   checkOptions(options);

   displayHeader(cout);
   if (fileQ) {
      displayHeader(outputfile);
   }

   KeyboardInput keyboard;     // for typing comments into output file
   char keych;                 // character from keyboard
   MidiMessage message;
   int lastTime = -1;

   midi.open();
   while (1) {
      while (midi.getCount() > 0) {
         message = midi.extract();
         if (echoQ) {
            midi.send(message);
         }

         if ((!activeSensingQ) && (message.p0() == 0xfe)) {
            // don't display incoming active-sensing messages
            continue;
         }

         // filter any specified message types
         if (suppressOffQ && ((message.p0() & 0xf0) == 0x90) &&
               (message.p2() == 0)) {      
            continue;
         } else if (filter[(message.p0() >> 4) - 8]) {
            continue;
         } else if (cfilter[message.p0() & 0x0f]) {
            continue;
         }

         // adjust message time to delta time if necessary
         if (!absoluteQ) {
            if (lastTime == -1) {
               lastTime = message.time;
               message.time = 0;
            } else {
               int temp = message.time;
               message.time = message.time - lastTime;
               lastTime = temp;
            }
         }

         displayMessage(cout, message, style);
         if (fileQ) {
            displayMessage(outputfile, message, style);
         }
      }

      if (keyboardQ && keyboard.hit()) {
         keych = keyboard.getch();
         switch (keych) {
            case 27:                   // escape key 
               if (fileQ && bufferIndex != 0 && bufferIndex < MAX_KEY_BUFF) {
                  inputBuffer[bufferIndex] = '\0';
                  outputfile << inputBuffer;
               }
               keyboard.deinitialize();
               exit(0);      
               break;
            case 0x08:                 // backspace key
            case 0x7f:                 // delete key
               if (bufferIndex > 0) {
                  cout << "\b \b" << flush;
                  bufferIndex--;
               }
               break;
            case 0x0a:                 // enter key only
               #ifdef VISUAL
                  break;
               #endif
            case 13:                   // line feed
               cout << endl;
               if (bufferIndex < MAX_KEY_BUFF) {
                  inputBuffer[bufferIndex] = '\0';
                  if (fileQ) {
                     outputfile << inputBuffer << '\n';
                  }
                  examineInputForCommand(inputBuffer);
               }
               bufferIndex = 0;
               break;
            case 0x0c:                 // ^L key (redraw input)
               cout << endl;
               if (bufferIndex < MAX_KEY_BUFF) {
                  inputBuffer[bufferIndex] = '\0';
                  cout << inputBuffer << flush;
               }
               break;
            default:                   // normal key
               cout << keych << flush;
               if (bufferIndex < MAX_KEY_BUFF) {
                  inputBuffer[bufferIndex++] = keych;
               } else { 
                  // buffer is WAY to long: kill it
                  bufferIndex = 0;
               }
         }
      }

      millisleep(1);   // sleep for 1 millisec for multi-tasking courtesy

   }