Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. MIDIEndpointRef localVirtualEndpoint;
  2. result = MIDIDestinationCreate(virtualMidi,
  3. (CFSTR("Virtual Destination")),
  4. MyMIDIReadProc,
  5. _samplerUnit1,
  6. &localVirtualEndpoint);
  7.  
  8. static void MyMIDIReadProc(const MIDIPacketList *pktlist,
  9. void *refCon,
  10. void *connRefCon) {
  11.  
  12.  
  13. AUGraph *player = (AUGraph*) refCon;
  14.  
  15. MIDIPacket *packet = (MIDIPacket *)pktlist->packet;
  16. for (int i=0; i < pktlist->numPackets; i++) {
  17. Byte midiStatus = packet->data[0];
  18. Byte midiCommand = midiStatus >> 4;
  19.  
  20.  
  21. if (midiCommand == 0x09) {
  22. Byte note = packet->data[1] & 0x7F;
  23. Byte velocity = packet->data[2] & 0x7F;
  24.  
  25. int noteNumber = ((int) note) % 12;
  26. NSString *noteType;
  27. switch (noteNumber) {
  28. case 0:
  29. noteType = @"C";
  30. break;
  31. case 1:
  32. noteType = @"C#";
  33. break;
  34. case 2:
  35. noteType = @"D";
  36. break;
  37. case 3:
  38. noteType = @"D#";
  39. break;
  40. case 4:
  41. noteType = @"E";
  42. break;
  43. case 5:
  44. noteType = @"F";
  45. break;
  46. case 6:
  47. noteType = @"F#";
  48. break;
  49. case 7:
  50. noteType = @"G";
  51. break;
  52. case 8:
  53. noteType = @"G#";
  54. break;
  55. case 9:
  56. noteType = @"A";
  57. break;
  58. case 10:
  59. noteType = @"Bb";
  60. break;
  61. case 11:
  62. noteType = @"B";
  63. break;
  64. default:
  65. break;
  66. }
  67.  
  68. NSLog(@" noteType= %@ note number %d",noteType,noteNumber);
  69.  
  70.  
  71. OSStatus result = noErr;
  72. //MARK: Render
  73. result = MusicDeviceMIDIEvent (player,
  74. midiStatus,
  75. note+7,
  76. velocity,
  77. 0);
  78. }
  79. packet = MIDIPacketNext(packet);
  80. }
  81.  
  82. MIDIEndpointRef localVirtualEndpoint;
  83. result = MIDIDestinationCreate(virtualMidi,
  84. (CFSTR("Virtual Destination")),
  85. MyMIDIReadProc,
  86. _processingGraph,
  87. &localVirtualEndpoint);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement