Пример #1
0
void usb_get_midi(MidiDevice * device) {
   /* Select the MIDI OUT stream */
   Endpoint_SelectEndpoint(MIDI_STREAM_OUT_EPNUM);

   MIDI_EventPacket_t event;
   while (MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, &event)) {

      midi_packet_length_t length = midi_packet_length(event.Data1);

      //pass the data to the device input function
      //not dealing with sysex yet
      if (length != UNDEFINED)
         midi_device_input(device, length, event.Data1, event.Data2, event.Data3);

   }
   MIDI_Device_USBTask(&USB_MIDI_Interface);
   USB_USBTask();
}
Пример #2
0
void usb_get_midi(MidiDevice * device) {
   MIDI_EventPacket_t event;
   while (MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, &event)) {

      midi_packet_length_t length = midi_packet_length(event.Data1);

      //pass the data to the device input function
      //not dealing with sysex yet
      if (length != UNDEFINED) {
         uint8_t input[3];
         input[0] = event.Data1;
         input[1] = event.Data2;
         input[2] = event.Data3;
         midi_device_input(device, length, input);
      }

   }
   MIDI_Device_USBTask(&USB_MIDI_Interface);
   USB_USBTask();
}
Пример #3
0
int main(void) {
   midi_init_device(&test_device);
   midi_device_set_send_func(&test_device, send_func);

   midi_send_cc(&test_device, 0, 0, 1);
   midi_send_cc(&test_device, 15, 1, 1);

   midi_register_fallthrough_callback(&test_device, fallthrough_callback);
   midi_register_realtime_callback(&test_device, realtime_callback);

   assert(!fallthrough_called);
   assert(!realtime_called);
   midi_device_input(&test_device, 3, 0xB0, 0, 1);
   midi_device_input(&test_device, 1, MIDI_CLOCK, 0, 0);
   midi_process(&test_device);
   assert(fallthrough_called);
   assert(realtime_called);

   reset();
   assert(!fallthrough_called);
   assert(!realtime_called);
   //interspersed
   midi_device_input(&test_device, 1, 0xB0, 0, 0);
   midi_device_input(&test_device, 1, MIDI_CLOCK, 0, 0);
   midi_device_input(&test_device, 1, 0, 0, 0);
   midi_device_input(&test_device, 1, MIDI_START, 0, 0);
   midi_device_input(&test_device, 1, 1, 0, 0);
   midi_process(&test_device);
   assert(fallthrough_called);
   assert(realtime_called);

   midi_register_cc_callback(&test_device, cc_callback);
   assert(!cc_called);
   midi_device_input(&test_device, 3, 0xB0, 0, 1);
   midi_process(&test_device);
   assert(cc_called);

   reset();
   assert(!cc_called);
   assert(!realtime_called);
   midi_device_input(&test_device, 1, 0xB0, 0, 0);
   midi_device_input(&test_device, 1, MIDI_CLOCK, 0, 0);
   midi_device_input(&test_device, 1, 0, 0, 0);
   midi_device_input(&test_device, 1, MIDI_START, 0, 0);
   midi_device_input(&test_device, 1, 1, 0, 0);
   midi_process(&test_device);
   assert(cc_called);
   assert(realtime_called);

   reset();
   assert(!anything_called());
   midi_device_input(&test_device, 1, 0xB0, 0, 0);
   midi_device_input(&test_device, 1, 0, 0, 0);
   midi_process(&test_device);
   assert(!anything_called());

   printf("\n\nTEST PASSED!\n\n");
   return 0;
}