Hi there,
I’m a University student who took Music Technology as an extra subject for my first year. For one task due in on Monday I have to create a c programming project that performs some sort of task. I decided to create a program that harmonizes a scale with chords (or a triad, ie three notes). But I actually have no idea how to play MIDI notes simultaneously. Here is my code so far, if anyone knows how to help, I’d be extremely grateful. It has been created on a mac, using Xcode and simple synth for midi audio output.
Code:
#include <stdio.h>
#include "simplemidi.h"
void playNote(int n, int l);
int main() {
char input[100];
int i;
chooseMidiOutput();
printf("Type letter names of pitches to play (with no spaces).\n");
scanf("%s", input); // scanf("%99s", input); would be safer
for (i = 0; input[i] != '\0'; i++) {
if (input[i] == 'C' || input[i] == 'c') {
playNote(60, 250);
} else if (input[i] == 'D' || input[i] == 'd') {
playNote(62, 250);
} else if (input[i] == 'E' || input[i] == 'e') {
playNote(64, 250);
} else if (input[i] == 'F' || input[i] == 'f') {
playNote(65, 250);
} else if (input[i] == 'G' || input[i] == 'g') {
playNote(67, 250);
} else if (input[i] == 'A' || input[i] == 'a') {
playNote(69, 250);
} else if (input[i] == 'B' || input[i] == 'b') {
playNote(71, 250);
} else {
printf("%c is not a pitch.\n", input[i]);
}
}
waitMidi(500);
closeMidiOutput();
return 0;
}
void playNote(int n, int l) {
sendMessageNow(144, n, 64);
waitMidi(l);
sendMessageNow(128, n, 0);
}
Many Thanks,
Tom