Esempio n. 1
0
int main(void) {
   MidiInput midiin;
   MidiOutput midiout;
   midiout.setPort(0);
   midiout.open();
   midiin.setPort(0);
   midiin.open();

   MidiEvent message;
   int sysexloc;
   unsigned char *sysexdata = NULL;
   int sysexsize = 0;
   int i;
   int running = 1;
   cout << "sysexio -- display and echo SYSEX messages from MIDI input" << endl;
   cout << "Press Middle C to quit." << endl;
   while (running) {
      if (midiin.getCount() > 0) {
         midiin.extract(message);
         if (message.getP0() == 0xf0) {
            sysexloc = message.getP1();
            sysexdata = midiin.getSysex(sysexloc);
            sysexsize = midiin.getSysexSize(sysexloc);

            // print out the sysex data to the screen:
            for (i=0; i<sysexsize; i++) {
               cout << hex << (int)sysexdata[i] << " ";
               if ((i + 1) % 30 == 0) {
                  cout << endl;
               }
            }
            cout << endl;

            // Now echo the messages to MIDI output (as a demo
            // for how to send Sysex outputs)
            midiout.rawsend(sysexdata, sysexsize);

            // As a courtesy, mark the midiin sysex buffer free
            // but this is not necessay (it will be erased when
            // more space is needed for storing a sysex.
            midiin.clearSysex(sysexloc);
            
         } else if ((message.getP0() & 0xf0) == 0x90) {
            // Exit the program when a middle C note is pressed.
            if (message.getP1() == 60 && message.getP2() > 0) {
               running = 0;
            }
         }
      }
   }

   return 0;
}
Esempio n. 2
0
void processMidiCommand(MidiEvent& message) {
   if (message.getP0() != 0x90 || message.getP2() == 0) {
      return;
   }

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

}
Esempio n. 3
0
void mainloopalgorithms(void) { 
   eventBuffer.checkPoll();        // see if any notes to play

   while (synth.getNoteCount() > 0) {
      message = synth.extractNote();
      if (message.getP2() != 0) {
         lastnotes.insert(message.getP1());
         lasttimes.insert(message.tick);
         distancee = lastnotes[0] - lastnotes[1];
         duration = lasttimes[0] - lasttimes[1];
         channel = 0x0f & message.getP0();
         if (distancee != 0) {
            playgliss(message.getP1(), message.getP2(), channel,  duration, distancee);
         }
      }
   }
}
Esempio n. 4
0
void mainloopalgorithms(void) { 
   if (synth.getNoteCount() > 0) {
      while (synth.getNoteCount() > 0) {
         message = synth.extractNote();
         if ((message.getP2() == 0) || ((message.getP0() & 0xf0) == 0x80)) {
            keystates[message.getP1()] = 0;
         } else if (message.getP2() != 0) {
            keystates[message.getP1()] = 1;
         }
      }
      getNewChordInfo(tempchord, keystates);

      lastnotetime = t_time;
   }

   if (t_time > lastnotetime + timedelta) {
      if (!equalChord(tempchord, currentchord)) {
         printNewChord(tempchord, chordset, names);
         currentchord = tempchord;
      }
   }
}
Esempio n. 5
0
void mainloopalgorithms(void) { 
   if (comparestate && notetimer.expired()) {
      if (notetimer.expired() > 2) {
         notetimer.reset();
      } else {
         notetimer.update();
      }

      notestate = !notestate;
      if (notestate == 1 || notestate == -1) {
         synth.play(0, note, 64);
         data = 0x90; sentout.insert(data);
         data = note; sentout.insert(data);
         data = 64;   sentout.insert(data);
      } else {
         synth.play(0, note, 0);
         data = 0x90; sentout.insert(data);
         data = note; sentout.insert(data);
         data = 0;    sentout.insert(data);
         note += step * direction;
         if (note > highestnote) {
            note = lowestnote;
         }
         if (note < lowestnote) {
            note = highestnote;
         }
      }
   }

   if (midiinput.getCount() > 0) {
      midiinput.extract(message);
      receivedin.insert(message.getP0());
      receivedin.insert(message.getP1());
      receivedin.insert(message.getP2());

      // check that the messages are identical
      if (receivedin.getCount() < 3) {
         cout << "Error: not enough received data" << endl;
      } else {
         receivedin.extract(checkin[0]);
         receivedin.extract(checkin[1]);
         receivedin.extract(checkin[2]);
      }

      if (sentout.getCount() < 3) {
         cout << "Error: not enough sent data" << endl;
      } else {
         sentout.extract(checkout[0]);
         sentout.extract(checkout[0]);
         sentout.extract(checkout[0]);
      }

      if ((checkout[0] != checkin[0]) || (checkout[1] != checkin[1]) ||
          (checkout[2] != checkin[2])) {
         synth.rawsend(0xaa, 0x7f, 0x00);
         cout << "Error " 
              << "output was = (" << hex << (int)checkout[0] << ") "
              << dec << (int)checkout[1] << " "
              << dec << (int)checkout[2] << "\tbut input is = ("
              << hex << (int)checkin[0] << ") "
              << dec << (int)checkin[1] << " "
              << dec << (int)checkin[2] << " "
              << endl;

         // assume that a note message was missed.
         if (sentout.getCount() < 3) {
            cout << "Error: not enough sent data during error" << endl;
         } else {
            sentout.extract(checkout[0]);
            sentout.extract(checkout[1]);
            sentout.extract(checkout[2]);
         }

         stop();  
         cout << "Press space to restart testing, "
                 "or press 'S' to silence synth" << endl;
      }

   }
 
}
Esempio n. 6
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
   MidiEvent message;
   int lastTime = -1;

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

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

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

         // adjust message time to delta time if necessary
         if (!absoluteQ) {
            if (lastTime == -1) {
               lastTime = message.tick;
               message.tick = 0;
            } else {
               int temp = message.tick;
               message.tick = message.tick - 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

   }
Esempio n. 7
0
void processNote(MidiEvent message) {
   int key = message.getP1();
   int velocity = message.getP2();
   int channel = message.getP0() & 0x0f;

   int status = 1;
   if (message.getP0() - channel == 0x80 || velocity == 0) {
      status = 0;
   }

   if (status == 0) {
      if (key == C8 || key == B7) {
         trillcorrection = 0;
      }
      if (key == As7 || key == A7) {
         velcorrection = 0;
      }
      return;
   }

   if (key == C8) {
      trillcorrection = velocity / 10;
      return;
   }

   if (key == B7) {
      trillcorrection = -(velocity / 10);
      return;
   }

   if (key == As7) {
      velcorrection = +(velocity / 10);
      return;
   }

   if (key == A7) {
      velcorrection = -(velocity / 10);
      return;
   }

   if (key == A0) {
      for (int j=0; j<128; j++) {
         noteontimes[j] = t_time;
      }
      return;
   }
  
   if (key == A0) {
      for (int j=0; j<128; j++) {
         noteontimes[j] = t_time;
      }
      return;
   }

   noteontimes[key] = t_time;

   notetimes.insert(message.tick);
   notes.insert(key);

   if (notes[1] == 0) {
      trills.insert(0);
      return;
   }
  
   if (notes[2] != 0) {
      if (trills[0] == 1 && notetimes[1] - notetimes[2] < TRIGTIME) {
         trills.insert(0);
         return;
      }
   }

   trills.insert(1);

   int duration = notetimes[0] - notetimes[1];
   if (duration < TRIGTIME && duration > MINTRIGTIME &&
       notes[0] - notes[1] != 0) {
      createTrill(key, notes[1], velocity, channel, duration);
   }
}