I'm trying to create a kind of custom midi player, for this I use an array that has already correctly memorized the data of midi messages, for example:
int array[3000][4]={{time,status,data1,data2},{...},...}
when I want my program to send a midi message (so that it can be played) I call this array and make the necessary differences between note / shutdown, tone skew, etc. The value of the pitch (in the range from 0 to 16383, but usually around 8192, which means there is no pitch shift), is stored in data1 (array [i] [2]). To convert from int to two 7 bit values to go to midiOutShortMsg (), I used the code I found here . Here is the code I'm actually using:
union { unsigned long word; unsigned char data[4]; } message;
int main(int argc, char** argv) {
int midiport;
uint16_t bend;
int flag,u;
uint16_t mask = 0x007F;
HMIDIOUT device;
message.data[0] = 0x90;
message.data[1] = 60;
message.data[2] = 100;
message.data[3] = 0;
if (!midiOutGetNumDevs()){
printf("non ci sono devices");
}
if (argc < 2) {
midiport = 0;
}
else {
midiport = 0;
}
printf("MIDI output port set to %d.\n", midiport);
flag = midiOutOpen(&device, midiport, 0, 0, CALLBACK_NULL);
if (flag != MMSYSERR_NOERROR) {
printf("Error opening MIDI Output.\n");
return 1;
}i = 0;
message.data[0] = 0xC0;
message.data[1] = 25;
message.data[2] = 0;
flag = midiOutShortMsg(device, message.word);
if (flag != MMSYSERR_NOERROR) {
printf("Warning: MIDI Output is not open.\n");
}
while (1){
if (array[i][1] == 1) {
this_works();i++;
}
else if (array[i][1] == 0){
this_also_works();i++;
}
else if (array[i][1] == 2){
while (array[i][1] == 2){
Sleep(10);
message.data[0] = 0xE0;
bend = (uint16_t) array[i][2];
message.data[1] = bend & mask;
message.data[2] = (bend & (mask << 7)) >> 7;
printf("bending %d, %d\n", message.data[1],message.data[2]);
flag = midiOutShortMsg(device, message.word);
if (flag != MMSYSERR_NOERROR) {
printf("Warning: MIDI Output is not open.\n");
}i++;
}
}
}}
printf ( "bending% d,% d" ) % d 0, , . , midi, 7- , , .