コード例 #1
0
ファイル: squelch.cpp プロジェクト: Isssmael/improv
void mainloopalgorithms(void) { 
   if (synth.getNoteCount() > 0) {
      message = synth.extractNote();
      oldnote = checkForSquelch(message, memory, mintime, maxtime, t_time);
      if (!oldnote || sstate == 0) {
         cout << "New note from performer: " << message << endl;
         if (message.is_note_on()) {
            message.p1() += 7;
            outvel = message.p2() + veladd;
            if (outvel > 127) { outvel = 127; }
            synth.send(message.p0(), message.p1(), outvel);
            message.time = t_time;
            message.p2() = outvel;
            memory.insert(message);
         } else if (message.is_note_off()) {
            message.p1() += 7;
            synth.send(message.p0(), message.p1(), message.p2());
            message.time = t_time;
            memory.insert(message);
         }
      } else {
         cout << "Feedback note from piano: " << message << endl;
      }
   }

}
コード例 #2
0
ファイル: sample.cpp プロジェクト: mdsmus/humdrum
void checkOptions(Options& opts, int argc, char* argv[]) {
   opts.define("r|rhythm|rhythm-cycle|=s:4");  // rhythm to sample notes at
   opts.define("m|metric=s");                 // metric cycle to sample

   opts.define("d|divide=b");             // determine if to split input notes
   opts.define("debug=b");                // determine bad input line num
   opts.define("author=b");               // author of program
   opts.define("version=b");              // compilation info
   opts.define("example=b");              // example usages
   opts.define("h|help=b");               // short description
   opts.process(argc, argv);

   // handle basic options:
   if (opts.getBoolean("author")) {
      cout << "Written by Craig Stuart Sapp, "
           << "[email protected], July 1998" << endl;
      exit(0);
   } else if (opts.getBoolean("version")) {
      cout << argv[0] << ", version: 5 December 2000" << endl;
      cout << "compiled: " << __DATE__ << endl;
      cout << MUSEINFO_VERSION << endl;
      exit(0);
   } else if (opts.getBoolean("help")) {
      usage(opts.getCommand());
      exit(0);
   } else if (opts.getBoolean("example")) {
      example();
      exit(0);
   }

   double duration = 0.0;
   int style = 0;

   int length;
   length = strlen(opts.getString("rhythm"));
   char buffer[length + 1];
   strcpy(buffer, opts.getString("rhythm"));

   durations.reset();
   styles.reset();

   char *durstr;
   durstr = strtok(buffer, " ,:\t\n;");
   while (durstr != NULL) {
      duration = Convert::kernToDuration(durstr);
      if (strchr(durstr, 'r') != 0) {
         style = 'r';
      } else if (strchr(durstr, 'x') != 0) {
         style = 'x';
      } else {
         style = 0;
      }
      durations.insert(duration);
      styles.insert(style);
      durstr = strtok(NULL, " ,:\t\n;");
   }

}
コード例 #3
0
ファイル: trill.cpp プロジェクト: craigsapp/improv
void initialization(void) { 
   eventBuffer.setPollPeriod(10);
   notetimes.reset();
   notetimes.insert(0);
   notetimes.insert(0);
   notes.reset();
   notes.insert(0);
   notes.insert(0);
   noteontimes.zero();
}
コード例 #4
0
ファイル: ripple.cpp プロジェクト: craigsapp/improv
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);
         }
      }
   }
}
コード例 #5
0
ファイル: circ.cpp プロジェクト: jeb2239/tcpoudp
int main(int argc, char** argv) {
  CircularBuffer cb;
  int ret, start=0, end=0;
  char buf[100] = "";
  

  cb.setSize(8);
  cb.insert("123", 3);

  cb.remove(4);
  cb.insert("k",1);
  
  cb.print();
  printf("\n");
  cb.insert("abcdefghijklmnopqrstuv", 22);
  cb.remove(7);
  cb.print();
  printf("\n");
  cb.insert("12345678", 8);
  cb.print();

  cb.getAt(buf, 9, 7, end);
  printf("\nread from buf\n%s\nindex end:%d\n", buf, end);
  
  //char testcase1[1000] = "f a\ta\na\0a f";
  //char testcase2[1000] = "abcdefghij";
  //cb.insert(testcase1, 11);
  //cb.remove(5);



  //cb.print();
  /*
  ret=cb.getTotalElements();
  printf("tot elements: %d\n", ret);

  start=cb.getHead();
  for(int i=0; i<cb.getSize(); i++) {
    ret=cb.getAt(buf, start, 1, end);
    start=end;
    printf("%d %d\n", buf[0], ret);
  }
  */

}//main
コード例 #6
0
ファイル: ques1.cpp プロジェクト: yida/CodingInterview
void append(CircularBuffer& buffer) {
  size_t input_num = 0;
  cin >> input_num;
  string input_str;
  for (size_t counter = 0; counter < input_num; counter ++) {
    cin >> input_str;
    buffer.insert(input_str);
  }
}
コード例 #7
0
ファイル: keykey.cpp プロジェクト: Isssmael/improv
void mainloopalgorithms(void) { 
   if (synth.getNoteCount() > 0) {
      nextActionTime = t_time;
      message = synth.extractNote();
      if (message.p2() == 0) {   // note off
         keyCount--;
         if (keyCount < 0) {
            keyCount = 0;
         }
         switch (message.p1()) {
            case C3:   lastOffTime[1]  = t_time;   break;
            case D3:   lastOffTime[2]  = t_time;   break;
            case E3:   lastOffTime[3]  = t_time;   break;
            case F3:   lastOffTime[4]  = t_time;   break;
            case G3:   lastOffTime[5]  = t_time;   break;
            case C4:   lastOffTime[6]  = t_time;   break;
            case D4:   lastOffTime[7]  = t_time;   break;
            case E4:   lastOffTime[8]  = t_time;   break;
            case F4:   lastOffTime[9]  = t_time;   break;
            case G4:   lastOffTime[10] = t_time;   break;
         }
      } else {                   // note on
         keyCount++;
         keysOn.insert(message.p1());
         onKey2 = onKey1;
         switch (message.p1()) {
            case C3:   lastOnTime[1]  = t_time;  onKey1 = 1;   break;
            case D3:   lastOnTime[2]  = t_time;  onKey1 = 2;   break;
            case E3:   lastOnTime[3]  = t_time;  onKey1 = 3;   break;
            case F3:   lastOnTime[4]  = t_time;  onKey1 = 4;   break;
            case G3:   lastOnTime[5]  = t_time;  onKey1 = 5;   break;
            case C4:   lastOnTime[6]  = t_time;  onKey1 = 6;   break;
            case D4:   lastOnTime[7]  = t_time;  onKey1 = 7;   break;
            case E4:   lastOnTime[8]  = t_time;  onKey1 = 8;   break;
            case F4:   lastOnTime[9]  = t_time;  onKey1 = 9;   break;
            case G4:   lastOnTime[10] = t_time;  onKey1 = 10;  break;
         }
      }
   }

   if (nextActionTime + repeatRate <= t_time) {
      nextActionTime = t_time;
   }    

   event = makeEventDecision();
   if (event > 0) {
      if (shift) {
         event = toupper(event);
      }
      cout << (char)event << flush;
   }

}
コード例 #8
0
TEST(CircularBuffer, Insert)
{
    CircularBuffer<int, 5> cb;

    cb.pushBack(0);
    cb.pushBack(1);
    cb.pushBack(3);

    auto it(cb.begin());

    ++it;
    ++it;

    cb.insert(it, 2);

    std::vector<int> values({ 0, 1, 2, 3 });

    ASSERT_TRUE(std::equal(cb.begin(), cb.end(),
                           values.begin()));
}
コード例 #9
0
ファイル: seny.cpp プロジェクト: Isssmael/improv
void processKeyboard(void) {
   MidiMessage message;
   int key;
   int vel;
   int command;
   
   while (synth.getNoteCount() > 0) {
      message = synth.extractNote();
      command = message.p0();
      key = message.p1();
      vel = message.p2();
 
      if (vel == 0 || (command & 0xf0 == 0x80)) {
         // note-off command section
         long duration = t_time - performerNotes[key];
         durations.insert(duration);
         durtimes.insert(t_time);

         performerNotes[key] = 0;
         performerPC[key%12]--;
         if (performerPC[key%12] < 0) {
            performerPC[key%12] = 0;
         }
      
      } else {   // note-on command
         performerNotes[key] = t_time;
         performerPC[key%12]++;
         performerPCHistory[key%12]++;
         keys.insert(key);
         keytimes.insert(t_time);
         volumes.insert(vel);
         voltimes.insert(t_time);

      } // end of the note-on command section

   }  // end of the while loop for processing notes from the performer

   // update the time that the performer last play a note on/off:
   lastPerformerTime = t_time;

   updatePerformRegions();
   updateDuration();
   updateVolume();
}
コード例 #10
0
int main()
{
    {
        // Test default constructor
        CircularBuffer buf;
        std::cout << buf.size() << "\n";
    }

    {
        // Test constructor taking 1 arg: size of buffer
        CircularBuffer buf(32);
        std::cout << buf.size() << "\n";
    }

    {
        // Test constructor taking std::vector
        std::vector<int> v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
        CircularBuffer buf(v);
        std::cout << buf.size() << "\n";
    }

    {
        // Test copy constructor
        std::vector<int> v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
        CircularBuffer buf(v);
        CircularBuffer buf2(buf);
        std::cout << buf.size() << ", " << buf2.size() << "\n";
    }

    {
        // Test move constructor
        std::vector<int> v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
        CircularBuffer buf(v);
        CircularBuffer buf2(std::move(buf));
        std::cout << buf.size() << ", " << buf2.size() << "\n";
    }

    {
        // Test copy assignment
        std::vector<int> v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
        CircularBuffer buf(v);
        CircularBuffer buf2(3);
        std::cout << buf.size() << ", " << buf2.size() << " -> ";
        buf2 = buf;
        std::cout << buf.size() << ", " << buf2.size() << "\n";
    }

    {
        // Test move assignment
        std::vector<int> v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
        CircularBuffer buf(v);
        CircularBuffer buf2(3);
        std::cout << buf.size() << ", " << buf2.size() << " -> ";
        buf2 = std::move(buf);
        std::cout << buf.size() << ", " << buf2.size() << "\n";
    }

    {
        // Test indexing
        CircularBuffer buf(10);
        buf[0] = buf[2] = buf[4] = buf[6] = buf[8] = 1;
        buf[1] = buf[3] = buf[5] = buf[7] = buf[9] = 2;
        std::cout << buf.at(1) << " " << buf[6] << "\n";
        std::cout << buf.at(32) << " " << buf[127] << "\n";
    }

    {
        // Test indexing const object
        const CircularBuffer buf({1, 2, 3, 4, 5});
        std::cout << buf.at(1) << " " << buf[8] << "\n";
    }

    {
        // Test size (already used above)
        CircularBuffer buf(3);
        if (buf.size() != 3)
            std::cout << "Incorrect size!\n";
        else
            std::cout << "Correct size!\n";
    }

    {
        // Test clear
        CircularBuffer buf(5);
        std::cout << buf.size() << " -> ";
        buf.clear();
        std::cout << buf.size() << "\n";
    }

    {
        // Test swap
        CircularBuffer buf({1, 2, 3, 4, 5});
        CircularBuffer buf2({6, 7, 8, 9, 0});
        std::cout << buf[0] << " " << buf[4] << " : " << buf2[0] << " "
                  << buf2[4] << " -> ";
        buf.swap(buf2);
        std::cout << buf[0] << " " << buf[4] << " : " << buf2[0] << " "
                  << buf2[4] << "\n";
    }

    {
        // Test insert
        CircularBuffer buf;
        buf.insert(0, 1);
        buf.insert(0, 2);
        buf.insert(0, 3);
        std::cout << buf.size() << " " << buf[2] << "\n";
        buf.insert(200, 4);
        std::cout << buf.size() << " " << buf[2] << "\n";
    }

    {
        // Test move-insert
        CircularBuffer buf;
        int x = 3;
        buf.insert(0, std::move(x));
        int y = 2;
        buf.insert(0, std::move(y));
        std::cout << buf[0] << " " << buf[1] << " " << buf[2] << "\n";
    }

    {
        // Test erase
        CircularBuffer buf({1, 2, 3, 4});
        std::cout << buf[0] << " " << buf.size() << " -> ";
        buf.erase(0);
        std::cout << buf[0] << " " << buf.size() << "\n";
    }

    return 0;
}
コード例 #11
0
ファイル: tumble.cpp プロジェクト: craigsapp/improv
void processNote(MidiEvent message, int seqLength, int direction) {
   static Array<char>         notes;
   static Array<char>         velocities;
   static Array<int>          durations;
   static Array<int>          iois;
   static Array<int>          ontimes;
   static CircularBuffer<int> attacktimes;
   static int                 init = 0;
   static TumbleParameters    temparam;
   char vel;

   if (!init) {
      attacktimes.setSize(256);
      attacktimes.reset();
      notes.setSize(0);
      velocities.setSize(0);
      durations.setSize(0);
      iois.setSize(0);
      ontimes.setSize(128);
      ontimes.zero();
      init = 1;
   }

   char note;
   int deltatime;
   int ioi0;
   int ioix;
   if (message.isNoteOn()) {
      attacktimes.insert(message.tick);

      // check to see if the ioi is in the correct range
      if (notes.getSize() == 0) {
         // no notes yet, so don't know the first ioi
      } else {
         deltatime = attacktimes[0] - attacktimes[1];
         iois.append(deltatime);
      }
      if (iois.getSize() > 1) {
         ioi0 = iois[0];
         ioix = iois[iois.getSize()-1];
         if ((ioix < ioi0 * tolerance) || (ioix > ioi0 / tolerance)) {
            goto resettrigger;
         }
      }

      // at this point the note can be added to the sequence
      if (notes.getSize() + 1 >= seqLength) {
         // time to trigger an algorithm
         if (durations.getSize() < notes.getSize()) {
            // if the last note has not yet been turned off, approximate dur.
            deltatime = iois[iois.getSize()-1];
            durations.append(deltatime);
         }

         int i;
         for (i=0; i<seqLength; i++) {
            temparam.v[i] = velocities[i];
            temparam.i[i] = iois[i];
            temparam.d[i] = durations[i];
            temparam.n[i] = notes[i] - notes[0];
         }
         temparam.n[0]    = message.getP1() - notes[0];
         temparam.current = message.getP1();
         temparam.pos     = 1;
         temparam.max     = seqLength;
         temparam.active  = 1;
         
         startAlgorithm(temparam);
         goto resettrigger;
      } else {
         // add the note info to the algorithm pile
         note = message.getP1();
         notes.append(note);
         vel = message.getP2();
         velocities.append(vel);
         attacktimes[message.getP1()] = message.tick;
      }
   } else if (message.isNoteOff()) {
      if (notes.getSize() > 0) {
         if (notes[notes.getSize()-1] == message.getP1()) {
         deltatime = message.tick - ontimes[message.getP1()];
         durations.append(deltatime);
      } else {
         cout << "A funny error ocurred" << endl;
      }
   }

   return;

resettrigger:
   attacktimes.setSize(0);
   notes.setSize(0);
   velocities.setSize(0);
   durations.setSize(0);
   iois.setSize(0);

   if (message.isNoteOn()) {
      note = message.getP1();
      notes.append(note);
      ontimes[message.getP1()] = message.tick;
      vel = message.getP2();
      velocities.append(vel);
   }
}



//////////////////////////////
//
// startAlgorithm -- start playing the tumble algorithm.  Inserts a
//     FunctionEvent into the eventBuffer which plays the tumble
//     algorithm sequence.  The algorithm will die after the notes
//     fall off of the 88-note keyboard.
//

}
コード例 #12
0
ファイル: testgliss.cpp プロジェクト: Isssmael/improv
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) {
      message = midiinput.extract();
      receivedin.insert(message.p0());
      receivedin.insert(message.p1());
      receivedin.insert(message.p2());

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

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

      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 {
            checkout[0] = sentout.extract();
            checkout[1] = sentout.extract();
            checkout[2] = sentout.extract();
         }

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

   }
 
}
コード例 #13
0
ファイル: sample.cpp プロジェクト: mdsmus/humdrum
void processRecords(HumdrumFile& infile, HumdrumFile& outfile) {
   infile.analyzeRhythm();
   char buffer[10000] = {0};

   int style;
   double duration;
   style = styles.extract();
   duration = durations.extract();

   double currbeat = 0;

   double targetbeat = 0;
   int lastline = 0;
   double currdur;
   int state = 0;

   for (int i=0; i<infile.getNumLines(); i++) {
      if (options.getBoolean("debug")) {
         cout << "processing line " << (i+1) << " of input ..." << endl;
      }

      if (infile[i].getType() != E_humrec_data) {
         outfile.appendLine(infile[i]);
         continue;
      }
 
      state = 0;
      currbeat = infile[i].getAbsBeat();
      currdur = infile[i].getDuration();
      while ((currbeat+currdur > targetbeat) || 
            (fabs(currbeat-targetbeat) < 0.001)) {

         if (fabs(currbeat - targetbeat) < 0.0001) {
            createDataLine(buffer, infile, i, duration, style);
            outfile.appendLine(buffer);
            styles.insert(style);
            durations.insert(duration);
            style = styles.extract();
            duration = durations.extract();
            targetbeat += duration;
         } else if (currbeat+currdur > targetbeat) {
            if (state == 1) {
               createDataLine(buffer, infile, lastline, duration, style);
            } else {
               createDataLine(buffer, infile, i, duration, style);
            }
            outfile.appendLine(buffer);
            styles.insert(style);
            durations.insert(duration);
            style = styles.extract();
            duration = durations.extract();
            targetbeat += duration;
         } else {
            break;
         }
      }

      lastline = i;

   }
}
コード例 #14
0
ファイル: trill.cpp プロジェクト: craigsapp/improv
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);
   }
}