Example #1
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;
	}
}
Example #2
0
void finishup(void) {
	eventBuffer.off();
	printAllMarkers(cout, markers, data);
	std::fill(markers.begin(), markers.end(), 0);
	colormessage(cout, COLOR_RESET, colormode, colorQ);
}