1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <conio.h> /* include for kbhit() and getch() functions */
#include <stdio.h> /* for printf() function */
#include <windows.h> /* required before including mmsystem.h */
#include <mmsystem.h> /* multimedia functions (such as MIDI) for Windows */
int main(int argc, char *argv[])
{
POINT pt;
GetCursorPos(&pt);
BOOL bContinue = TRUE;
const SHORT Mask = 32768;
int initX = pt.x;
int x = pt.x;
int diff = 0;
int initY = pt.y;
int velocity = 100; // MIDI note velocity parameter value
int midiport; // select which MIDI output port to open
int flag; // monitor the status of returning functions
HMIDIOUT device; // MIDI device interface for sending MIDI output
// variable which is both an integer and an array of characters:
union { unsigned long word; unsigned char data[4]; } message;
message.data[0] = 0x90; // MIDI note-on message (requires to data bytes)
message.data[1] = 60; // MIDI note-on message: Key number (60 = middle C)
message.data[2] = 100; // MIDI note-on message: Key velocity (100 = loud)
message.data[3] = 0; // Unused parameter
// Assign the MIDI output port number (from input or default to 0)
if (argc < 2) {
midiport = 0;
}
else {
midiport = atoi(argv[1]);
}
// Open the MIDI output port
flag = midiOutOpen(&device, midiport, NULL, 0, CALLBACK_NULL);
if (flag != MMSYSERR_NOERROR) {
printf("Error opening MIDI Output.\n");
return 1;
}
// Main event loop
while (bContinue) { // event loop
if (GetKeyState(VK_ESCAPE) & Mask)
bContinue = FALSE;
GetCursorPos(&pt);
diff = initX - pt.x;
message.data[1] = abs(pt.y - diff)%128;
flag = midiOutShortMsg(device, message.word);
if (flag != MMSYSERR_NOERROR) {
printf("Warning: MIDI Output is not open.\n");
}
Sleep(10);
}
// turn any MIDI notes currently playing:
midiOutReset(device);
// Remove any data in MIDI device and close the MIDI Output port
midiOutClose(device);
return 0;
} |
Partager