Ejemplo n.º 1
0
	virtual void handleNote(uint8_t note, uint8_t duration) {
		int octave = noteOctave(note);
		if(channel < 8) {
			if(curOctave != octave) {
				if(curOctave == -1 || curOctave - octave > 1 || octave - curOctave > 1) {
					mmlf("o%d", octave);
				} else if(curOctave == octave + 1) {
					mmlf("<");
				} else if(curOctave == octave - 1) {
					mmlf(">");
				}
			}
			curOctave = octave;
		}
		if(duration > 0) {
			int mmlDuration;
			bool dot = false, percent = false;
			if(192 % duration == 0) {
				mmlDuration = 192 / duration;
			} else if(192 % (duration * 2 / 3) == 0 && (duration * 2) % 3 == 0) {
				dot = true;
				mmlDuration = 192 * 3 / duration / 2;
			} else {
				percent = true;
			}
			char buf[100];
			if(channel < 8) {
				sprintf(buf, "%s", noteName(note));
			} else {
				sprintf(buf, "n%d,", note);
			}
			if(percent) sprintf(buf + strlen(buf), "%%%d", duration);
			else sprintf(buf + strlen(buf), "%d", mmlDuration);
			if(dot) strcat(buf, ".");
			if(nextKeyOff) strcat(buf, "&");
			if(nextPortamento) {
				int nextNote = note + (nextPortamento * duration + (nextPortamento < 0 ? -16383 : 16383)) / 16384;
				int nextOctave = noteOctave(nextNote);
				strcat(buf, "_");
				if(nextOctave != octave) sprintf(buf + strlen(buf), "o%d", nextOctave);
				curOctave = nextOctave;
				sprintf(buf + strlen(buf), "%s", noteName(nextNote));
			}
			mmlf("%s", buf);
		}
		nextKeyOff = false;
		nextPortamento = 0;
	}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
int noteOctave(const double & pitch)
{
  return noteOctave(toInt(pitch));
}