Advertisement
Guest User

Untitled

a guest
Dec 7th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include <MidiShare.h>
  2. #include <stdio.h>
  3.  
  4. void initMidiShare();
  5. void sendNote(long pitch);
  6. void closeMidiShare();
  7. void wait(long d);
  8.  
  9. int refNum;
  10. int duration = 1000;
  11.  
  12. int main(int argc, char* argv[]) {
  13.  
  14. printf("sendNote.c\n");
  15. initMidiShare();
  16. printf("Note On Sent\n");
  17. sendNote(60);
  18. wait(duration*2);
  19. closeMidiShare();
  20.  
  21. return 0;
  22. }
  23.  
  24. void initMidiShare() {
  25.  
  26. // Check if MidiShare loaded.
  27. if (!MidiShare()) {
  28. printf("MidiShare not available\n");
  29. return;
  30. } else {
  31. printf("MidiShare available\n");
  32. }
  33.  
  34. // Ask for a reference number.
  35. printf("Opening sendNote\n");
  36.  
  37. refNum = MidiOpen((char*)"sendNote");
  38. if (refNum < 1) {
  39. printf("Could not open MidiShare\n");
  40. return;
  41. } else {
  42. printf("MidiShare open\n");
  43. }
  44.  
  45. MidiConnect(refNum, 0, 1);
  46. }
  47.  
  48. void sendNote(long pitch) {
  49.  
  50. MidiEvPtr e = MidiNewEv(typeNote);
  51.  
  52. if (e) {
  53. Chan(e) = 0; // channels have numbers from 0 to 15
  54. Port(e) = 0; // port 0 is Modem port, port 1 is Printer port
  55. MidiSetField(e, 0, pitch); // the pitch
  56. MidiSetField(e, 1, 127); // the velocity
  57. MidiSetField(e, 2, duration); // the duration in milliseconds
  58.  
  59. MidiSendIm(refNum, e);
  60. }
  61. }
  62.  
  63. void closeMidiShare() {
  64.  
  65. // Close MidiShare
  66. printf("Closing MidiShare\n");
  67. MidiClose(refNum);
  68.  
  69. printf("Closing sendNote\n");
  70. }
  71.  
  72. void wait(long d){
  73.  
  74. d += MidiGetTime();
  75. while (MidiGetTime() < d);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement