Example #1
0
void playdata(HumdrumFile& data, int& linenum, SigTimer& timer) {
	double duration = 0;     // duration of the current line;

	if (data.getNumLines() == 0) {
		// ignore empty files.
		return;
	}

	int type = data[linenum].getType();

	while (linenum < data.getNumLines() && duration == 0.0) {
		duration = data[linenum].getDuration();

		if (type == E_humrec_data) {
			processNotes(data[linenum]);
		} else if (type == E_humrec_interpretation) {
			if (strncmp(data[linenum][0], "*MM", 3) == 0) {
				tempo = atoi(&data[linenum][0][3]);
			}
		}
		if (echoTextQ) {
			printInputLine(data, linenum);
		}
		if (duration > 0.0) {
			timer.setPeriod(60000 / tempo / tempoScale * duration);
			timer.reset();
		}
		linenum++;
		if (linenum < data.getNumLines()) {
			type = data[linenum].getType();
		}
	}
}
Example #2
0
void mainloopalgorithms(void) { 
   // 1. check to see if we are in a new measure and update the
   // metronome accordingly.  If in 4/4, then the metronome will
   // be guarenteed to be between 0 and 3.99999 after the following
   // code is run.  The update will make sure that the metronome remains
   // synced exactly in time with the absolute beat. (Useful for 
   // polyphony, not really necessary in monophonic cases).
   if (metronome.expired() >= meter) {
      metronome.update(meter);
   }

   // 2. Determine the current beat of the meter.
   // We will want to play automated chords on beats one and three.
   beatfraction = metronome.getPeriodCount();
   beat = (int)beatfraction + 1;
   beatfraction -= beat - 1;

   // 3. Process the incoming MIDI note messages (if any), keeping track 
   // of the last note, and whether it is currently on or off.
   while (synth.getNoteCount() > 0) {
      notemessage = synth.extractNote();
      if (notemessage.getP2() != 0) {
         note = notemessage.getP1();
         notestates[note] = 1;
      } else {
         notestates[notemessage.getP1()] = 0;
      }
   }

   // 4. Determine the position in time in the current beat.
   // There are two beat-parts which are called states:
   //    state == 0: we are at the start of the beat and may need to
   //                choose a new chord.
   //    state == 1: we are past the maximum wait time for a chord decision
   // Also, check to see if the state has changed from 0 to 1 or 1 to 0.
   oldstate = state;
   state = beatfraction < maxwait ? 0 : 1;
   stateChange = (state != oldstate);

   // 5. Check to see if a chord needs to be played.
   if (stateChange && state == 0) {
      playMetronome(beat);
      if (chordBeat(beat, meter)) {
         notescan = 1;
      } else {
         playChord(currentnote, OFF);
      }
   }

   if (notescan && notestates[note]) {   // if note played in beat window
      currentnote = note;
      playChord(currentnote, ON);
      notescan = 0;
   } else if (notescan && state == 1) {  // if too late for a new note
      playChord(currentnote, ON);
      notescan = 0;
   }
}
Example #3
0
void mainloopalgorithms(void) { 
   if (synth.getNoteCount() > 0) {
      processKeyboard();
   }

   if (offTimer.expired()) {
      checkBuffers();
      checkOffNotes();
      offTimer.reset();
   }

   if (batonTimer.expired()) {
      processBaton();
      batonTimer.reset();
   }

   voicePeriod = (int)(avgDur - avgDurRange);
   if (voicePeriod <= 50) {
      voicePeriod = 50;
   }

   voiceTimer.setPeriod(voicePeriod);
   if (voiceTimer.expired()) {
      generateVoices();
      voiceTimer.reset();
   }

   if (controlDisplayQ && controlDisplayTimer.expired()) {
      displayVariables();
      controlDisplayTimer.reset();
   }

}
Example #4
0
void initialization(void) { 
   notetimer.setPeriod(period); // set the period in ms between MIDI events.
   notetimer.reset();

   sentout.setSize(1024);       // store up to 1024 MIDI output bytes 
   receivedin.setSize(1024);    // store up to 1024 MIDI input bytes
   description();

   synth.makeOrphanBuffer();
   start();
}
Example #5
0
void mainloopalgorithms(void) { 
   sensor.checkPoll();   // see if it is time to check for new data frame
   makeNote();           // check if it is time to play a MIDI note

   if (display && displayTimer.expired()) {
      displayTimer.reset();
      cout << "\r\t\t\t\t\t\t\t\t\t";
      cout << "\rkey0= " << (int)(100 * keymin)/100.0 
           << "  keyx= " << (int)(100 * keymax)/100.0
           << "  keyc= " << (int)(100 * sensor[keychan][0])/100.0 
           << "   \tvel0= " << (int)(100 * velmin)/100.0 
           << "  velx= " << (int)(100 * velmax)/100.0 
           << "  velc= " << (int)(100 * sensor[velchan][0])/100.0  
           << "   " << flush;
   }
}
Example #6
0
void keyboardchar(int key) { 
   switch (key) {
      case ',':      // slow the tempo down
      case '<':
         tempo *= 0.95;
         metronome.setTempo(tempo);
         cout << "Tempo = " << tempo << endl;
         maxwait = calculateMaxWait(tempo);
         break;

      case '.':      // speed the tempo up
      case '>':
         tempo *= 1.05;
         metronome.setTempo(tempo);
         cout << "Tempo = " << tempo << endl;
         maxwait = calculateMaxWait(tempo);
         break;

      case '[':    // decrease the beat lag time in determing a chord
         lagmaxinsec -= 0.05;
         if (lagmaxinsec < 0.05) {
            lagmaxinsec = 0.05;
         }
         cout << "Chord decision time set to " << lagmaxinsec << endl;
         maxwait = calculateMaxWait(tempo);
         break;

      case ']':    // increase the beat lag time in determing a chord
         lagmaxinsec += 0.05;
         if (lagmaxinsec > 60.0/tempo - 0.05) {
            lagmaxinsec = 60.0/tempo - 0.05;
         }
         cout << "Chord decision time set to " << lagmaxinsec << endl;
         maxwait = calculateMaxWait(tempo);
         break;

      default:
         cout << "Undefined keyboard command" << endl;
   }

}
Example #7
0
void initialization(void) { 
   checkOptions(options);

   triggerTimer.setPeriod(75);

   performance.read(options.getArg(1));
   performance.setPort(outport);
   performance.setMaxAmp(maxamp);
   performance.open();
   performance.setTempoMethod(tempoMethod);

}
Example #8
0
void initialization(void) { 
   cout << "Enter a tempo for melody performance: ";
   echoKeysOn();
   cin  >> tempo;
   echoKeysOff();

   metronome.setTempo(tempo);
   maxwait = calculateMaxWait(tempo);

   playChord = playChordByRules;
   cout << "Using rules for playing accompaniment" << endl;
}
Example #9
0
int main(int argc, char** argv) {
   Options options(argc, argv);
   checkOptions(options);

   keyboardTimer.setPeriod(10);
   int command = 0;

   MidiInput midiin;
   midiin.setPort(inport);
   midiin.open();
   MidiEvent midimessage;

   performance.read(options.getArg(1).data());
   performance.setPort(outport);
   performance.setMaxAmp(maxamp);
   performance.open();
   performance.setTempoMethod(tempoMethod);
   performance.play();
   while (command != 'Q') {
      while (midiin.getCount() > 0) {
         midiin.extract(midimessage);
         processMidiCommand(midimessage);
      }
      performance.xcheck();
      eventIdler.sleep();

      if (keyboardTimer.expired()) {
         keyboardTimer.reset();
         command = checkKeyboard();
         if (command == 'Q') {
            break;
         } else {
            keyboardCommand(command);
         }
      }

   }

   return 0;
}
Example #10
0
void mainloopalgorithms(void) {
	eventBuffer.checkPoll();
	if (pauseQ) {
		return;
	}
	if (timer.expired()) {
		playdata(data, linenum, timer);
		if (linenum >= data.getNumLines()) {
			printAllMarkers(cout, markers, data);
			std::fill(markers.begin(), markers.end(), 0);
			inputNewFile();
		}
	}
}
Example #11
0
void initialization(void) {
	checkOptions();
	timer.setPeriod(500);
	timer.reset();
	eventIdler.setPeriod(0);
	eventBuffer.setPollPeriod(10);
	eventBuffer.setPort(synth.getOutputPort());
	if (colorQ) {
		colormessage(cout, COLOR_INIT, colormode, colorQ);
		colormessage(cout, COLOR_CLEAR_SCREEN, colormode, colorQ);
		//if (!options.getBoolean("Q")) {
		//   print_commands();
		//}
		//sleep(1);
	}
	trackmute.resize(1000); // maximum track in humdrum file assumed to be 1000
							       // space 1000-10 is used for a special purpose.
	std::fill(trackmute.begin(), trackmute.end(), 0);

	markers.resize(1001);
	std::fill(markers.begin(), markers.end(), 0);
	markerindex = 0;
}
Example #12
0
void initialization(void) { 
   batonTimer.setPeriod(50);           // time to get new state of baton
   offTimer.setPeriod(200);            // time to check buffer for forgetting
   controlDisplayTimer.setPeriod(200); // time to check buffer for forgetting

   // set the voice channels all to be 0 for the disklavier and so
   // the channels do not have to be specified when playing the note.
   for (int i=0; i<MAXVOICES; i++) {
      voice[i].setChannel(0);
   }
   computer.setChannel(0);
   computerMessage.time = t_time;
   computerMessage.p0() = 0x90;
   computerMessage.p1() = 0;
   computerMessage.p2() = 0;

   keys.setSize(1000);        // store keys for memory of previous notes
   keytimes.setSize(1000);    // note times for keys buffer
   volumes.setSize(1000);     // duration of notes being held by performer
   voltimes.setSize(1000);    // duration of notes being held by performer
   durations.setSize(1000);   // duration of notes being held by performer
   durtimes.setSize(1000);    // duration of notes being held by performer
}
Example #13
0
void initialization(void) { 
   sensor.initialize(options.argv()); // start CVIRTE stuff for NIDAQ card
   sensor.setPollPeriod(1);      // check for new data every 1 millisecond   
   sensor.setFrameSize(1);       // data transfer size from NIDAQ card
   sensor.setModeLatest();       // just look at most recent data in buffer
   sensor.setSrate(500);         // set NIDAQ sampling rate to X Hz
   sensor.activateAllChannels(); // turn on all channels for sampling 
   cout << "starting data aquisition ... " << flush;
   sensor.start();              // start aquiring data from NIDAQ card
   cout << "ready." << endl;

   voice.setPort(synth.getOutputPort());   // specify output port of voice
   voice.setChannel(0);         // specify output chan of voice
   voice.pc(inst);

   displayTimer.setPeriod(200); // display position every X milliseconds
}
Example #14
0
void stick2trig(void) {
   if (triggerTimer.expired()) {
      performance.beat();
      triggerTimer.reset();
   }
}
Example #15
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) {
      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;
      }

   }
 
}
Example #16
0
void keyboardchar(int key) { 
   switch (key) {
      case 'h':        // more help
         help();
         break;
      case '[':        // slow tempo
         period--;
         if (period < 1) {
            period = 1;
         }
         cout << "Period: " << period << endl;
         notetimer.setPeriod(period);
         break;
      case '{':        // slow tempo by 5
         period -= 5;
         if (period < 1) {
            period = 1;
         }
         cout << "Period: " << period << endl;
         notetimer.setPeriod(period);
         break;
      case ']':        // speed tempo
         period++;
         cout << "Period: " << period << endl;
         notetimer.setPeriod(period);
         break;
      case '}':        // speed tempo by 5
         period += 5;
         cout << "Period: " << period << endl;
         notetimer.setPeriod(period);
         break;
      case 'u':        // make glissando go up
         direction = 1;
         cout << "Glissandoing up" << endl;
         break;
      case 'd':        // make glissando go down
         direction = -1;
         cout << "Glissandoing down" << endl;
         break;
      case '1':        // lower bottom of glissando range
         if (lowestnote > 0) {
            lowestnote--;
            cout << "lowest note set to: " << lowestnote << endl;
         }
         break;
      case '2':        // raise bottom of glissando range
         if (lowestnote < highestnote - 1) {
            lowestnote++;
            cout << "lowest note set to " << lowestnote << endl;
         } 
         break;
      case '3':        // lower both the top and the bottom of range
         if (lowestnote > 0) {
            lowestnote--;
            highestnote--;
            cout << "Range lowered" << endl;
         }
         break;
      case '4':        // lower both the top and the bottom of range
         if (highestnote < 127) {
            lowestnote++;
            highestnote++;
            cout << "Range raised" << endl;
         }
         break;
      case '5':        // lower step amount
         step--;
         if (step < 1) {
            step = 1;
         }
         cout << "Step size = " << step << endl;
         break;
      case '6':        // raise step amount
         step++;
         cout << "Step size = " << step << endl;
         break;
      case '-':        // lower top of glissando range
         if (highestnote > lowestnote + 1) {
            highestnote--;
            cout << "highest note set to: " << highestnote << endl;
         }
         break;
      case '=':        // raise top or glissando range
         if (highestnote < 127) {
            highestnote++;
            cout << "highestnote note set to: " << highestnote << endl;
         }
         break;
      case ' ':       // toggle sending/comparing of data
         if (comparestate) {
            stop();
            cout << "Stopped data transmission/comparison" << endl;
         } else {
            cout << "Starting data transmission/comparison" << endl;
            start();
         }
   }
}
Example #17
0
void keyboardchar(int key) {
	static int lastkeytime = 0;
	static int number      = 0;

	if (t_time - lastkeytime > 5000) {
		// reset the number value if more than 5 seconds has elapsed
		// since the last key press.
		number = 0;
	}
	lastkeytime = t_time;

	if (isdigit(key)) {
		number = number * 10 + (key - '0');
		return;
	}
	switch (key) {
	// case 'a': break;
		case 'b':               // set color mode to black
			colorQ = 1;          // turn on colorization automatically
			colormode = 'b';
			colormessage(cout, COLOR_INIT, colormode, colorQ);
			cout << "!! CHANGING TO BLACK BACKGROUND" << endl;
			break;
		case 'c':               // toggle colorization
			colorQ = !colorQ;
			if (colorQ) {
				colormessage(cout, COLOR_INIT, colormode, colorQ);
				cout << "!! COLORIZATION TURNED ON" << endl;
			} else {
				colormessage(cout, COLOR_RESET, colormode, !colorQ);
				cout << "!! COLORIZATION TURNED OFF" << endl;
			}
			break;
	// case 'd': break;
		case 'e':               // print exclusive interpretation info for spines
			printExclusiveInterpLine(linenum, data);
			break;
	// case 'f': break;
	// case 'g': break;

		case 'h':               // hide/unhide non-kern spine (remove later)
		case 'k':               // hide/unhide non-kern spine
			hideQ = !hideQ;
			if (hideQ) {
				cout << "!! Hiding non-kern spines" << endl;
			} else {
				cout << "!! Showing all spines" << endl;
			}
			break;
	// case 'i': break;
	// case 'j': break;
	// case 'k': break;
		case 'l':               // transpose up specified number of semitones
			if (number < 100) {
				transpose = number;
				cout << "!! Transposing " << transpose << " steps up" << endl;
			}
			break;
		case 'L':               // transpose down specified number of semitones
			if (number < 100) {
				transpose = -number;
				cout << "!! Transposing " << -transpose << " steps down" << endl;
			}
			break;
		case 'm':               // mute or unmute all tracks
			if (number == 0) {
				std::fill(trackmute.begin(), trackmute.end(), 
						!trackmute[(int)trackmute.size()-1]);
				if (trackmute[0]) {
					cout << "!! All spines are muted" << endl;
				} else {
					cout << "!! All spines are unmuted" << endl;
				}
			} else {
				int tracknum = getKernTrack(number, data);
				trackmute[tracknum] = !trackmute[tracknum];
				if (trackmute[tracknum]) {
					cout << "!! **kern spine " << number << " is muted" << endl;
				} else {
					cout << "!! **kern spine " << number << " is unmuted" << endl;
				}
			}
			break;
			break;
		case 'n':     // toggle display of note only (supression
						  // of beam and stem display
						  // Also, don't display ![!]LO: lines.
			noteonlyQ = !noteonlyQ;
			if (noteonlyQ) {
				cout << "!! Notes only: supressing beams and stems in **kern data"
					  << endl;
			} else {
				cout << "!! Displaying **kern data unmodified" << endl;
			}
			break;
		case 'o':               // set the tempo to a particular value
			if (number > 20 && number < 601) {
				cout << "!! TEMPO SET TO " << number << endl;
				tempo = number;
				tempoScale = 1.0;
			} else if (number == 0) {
				cout << "!! Current tempo: " << tempo * tempoScale << endl;
			}
			break;
		case 'p':               // toggle music pausing
			eventBuffer.off();
			timer.reset();
			pauseQ = !pauseQ;
			if (pauseQ) {
				cout << "!! Paused" << endl;
			}
			break;
		case 'q':               // toggle display of file while playing
			echoTextQ = !echoTextQ;
			if (echoTextQ) {
				cout << "!! FILE DISPLAY TURNED ON" << endl;
			} else {
				cout << "!! FILE DISPLAY TURNED OFF" << endl;
			}
			break;
		case 'r':               // return to a marker
			if (number == 0) {
				linenum = markers[0];
				cout << "!! Going to line " << linenum << endl;
				eventBuffer.off();
				timer.reset();
			} else if (number < (int)markers.size()) {
				linenum = markers[number];
				cout << "!! Going to line " << linenum << endl;
				eventBuffer.off();
				timer.reset();
			}
			break;
		case 'R':               // Print a list of all markers
			printAllMarkers(cout, markers, data);
			break;
		case 's':    // silence notes
			eventBuffer.off();
			break;
		case 't':    // increase tab size
			tabsize++;
			// cout << "!! tabsize = " << tabsize << endl;
			break;
		case 'T':    // decrease tab size
			tabsize--;
			if (tabsize < 3) {
				tabsize = 3;
			}
			// cout << "!! tabsize = " << tabsize << endl;
			break;
	// case 'u': break;
	// case 'v': break;
		case 'w':               // set color mode to white
			colorQ = 1;          // turn on colorization automatically
			colormode = 'w';
			colormessage(cout, COLOR_INIT, colormode, colorQ);
			cout << "!! CHANGING TO WHITE BACKGROUND" << endl;
			break;
		case 'x':               // clear the screen
			colormessage(cout, COLOR_CLEAR_SCREEN, colormode, 1);
			printInputLine(data, linenum-1);
			break;
	// case 'y': break;
	// case 'z': break;

		case ' ':               // mark the measure/beat/line of the music
			if ((number != 0) && (number < (int)markers.size())) {
				markerindex = number;
			} else {
				markerindex++;
				if (markerindex > (int)markers.size()-1) {
					markerindex = 1;
				}
			}
			printMarkLocation(data, linenum == 0 ? 0 : linenum-1, markerindex);
			break;
		case ',':    // slow down tempo
			tempoScale *= 0.97;
			cout << "!! TEMPO SET TO " << (int)(tempo * tempoScale) << endl;
			break;
		case '<':
			tempoScale *= 0.93;
			cout << "!! TEMPO SET TO " << (int)(tempo * tempoScale) << endl;
			break;
		case '.':    // speed up tempo
			tempoScale *= 1.03;
			cout << "!! TEMPO SET TO " << (int)(tempo * tempoScale) << endl;
			break;
		case '>':
			tempoScale *= 1.07;
			cout << "!! TEMPO SET TO " << (int)(tempo * tempoScale) << endl;
			break;
		case '=':
			{
				int newline = 0;
				if (number == 0) {
					newline = 0;
				} else {
					newline = getMeasureLine(data, number);
				}
				if (newline >= 0) {
					cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
						  << " =" << number
						  << endl;
					linenum = newline;
					eventBuffer.off();
					timer.reset();
				}
			}
			break;
		case '(':
			{
				int newline = goBackMeasures(data, linenum, number);
				cout << "!! back " << number << " measure"
		 << (number==1? "":"s") << endl;
				linenum = newline;
				eventBuffer.off();
				timer.reset();
			}
			break;
		case ')':
			{
				int newline = goForwardMeasures(data, linenum, number);
				cout << "!! forward " << number << " measure"
					  << (number==1? "":"s") << endl;
				linenum = newline;
				eventBuffer.off();
				timer.reset();
			}
			break;
		case '+':    // louder
			velocity++;
			if (velocity > 127) {
				velocity = 127;
			}
			cout << "!! velocity = " << velocity << endl;
			break;

		case '_':    // sofer
			velocity--;
			if (velocity < 1) {
				velocity = 1;
			}
			cout << "!! velocity = " << velocity << endl;
			break;

		case '^':    // go to the start of the file
			linenum = 0;
			cout << "!! Going to start of file" << endl;
			break;

		case '$':    // go to the end of the file
			linenum = data.getNumLines() - 1;
			cout << "!! Going to end of file" << endl;
			break;
	}

	if (!isdigit(key)) {
		number = 0;
	}
}