Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <MidiShare.h>
- #include <stdio.h>
- void initMidiShare();
- void sendNote(long pitch);
- void closeMidiShare();
- void wait(long d);
- int refNum;
- int duration = 1000;
- int main(int argc, char* argv[]) {
- printf("sendNote.c\n");
- initMidiShare();
- printf("Note On Sent\n");
- sendNote(60);
- wait(duration*2);
- closeMidiShare();
- return 0;
- }
- void initMidiShare() {
- // Check if MidiShare loaded.
- if (!MidiShare()) {
- printf("MidiShare not available\n");
- return;
- } else {
- printf("MidiShare available\n");
- }
- // Ask for a reference number.
- printf("Opening sendNote\n");
- refNum = MidiOpen((char*)"sendNote");
- if (refNum < 1) {
- printf("Could not open MidiShare\n");
- return;
- } else {
- printf("MidiShare open\n");
- }
- MidiConnect(refNum, 0, 1);
- }
- void sendNote(long pitch) {
- MidiEvPtr e = MidiNewEv(typeNote);
- if (e) {
- Chan(e) = 0; // channels have numbers from 0 to 15
- Port(e) = 0; // port 0 is Modem port, port 1 is Printer port
- MidiSetField(e, 0, pitch); // the pitch
- MidiSetField(e, 1, 127); // the velocity
- MidiSetField(e, 2, duration); // the duration in milliseconds
- MidiSendIm(refNum, e);
- }
- }
- void closeMidiShare() {
- // Close MidiShare
- printf("Closing MidiShare\n");
- MidiClose(refNum);
- printf("Closing sendNote\n");
- }
- void wait(long d){
- d += MidiGetTime();
- while (MidiGetTime() < d);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement