1
0

midi_driver.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include "main.h"
  2. MIDI_driver * MIDI_driver::driver_list=0;
  3. MIDI_driver::MIDI_driver()
  4. {
  5. next=driver_list;
  6. driver_list=this;
  7. inited=0;
  8. device_list=0;
  9. }
  10. void MIDI_driver::reset_devices()
  11. {
  12. while(device_list)
  13. {
  14. MIDI_device * ptr = device_list->next;
  15. delete device_list;
  16. device_list = ptr;
  17. }
  18. }
  19. MIDI_driver::~MIDI_driver()
  20. {
  21. reset_devices();
  22. }
  23. void MIDI_driver::add_device(MIDI_device * dev)
  24. {
  25. MIDI_device **ptr = &device_list;
  26. while(ptr && *ptr) ptr = &(*ptr)->next;
  27. *ptr=dev;
  28. dev->next=0;
  29. dev->driver=this;
  30. }
  31. MIDI_driver * MIDI_driver::driver_enumerate(int n)
  32. {
  33. MIDI_driver * ptr = driver_list;
  34. while(ptr && n>0) {ptr=ptr->next;n--;}
  35. return ptr;
  36. }
  37. int MIDI_driver::driver_count()
  38. {
  39. int n=0;
  40. MIDI_driver * ptr = driver_list;
  41. while(ptr) {ptr=ptr->next;n++;}
  42. return n;
  43. }
  44. MIDI_device * MIDI_driver::device_enumerate(int n)
  45. {
  46. init();
  47. MIDI_device * ptr = device_list;
  48. while(ptr && n>0) {ptr=ptr->next;n--;}
  49. return ptr;
  50. }
  51. int MIDI_driver::device_count()
  52. {
  53. init();
  54. int n=0;
  55. MIDI_device * ptr = device_list;
  56. while(ptr) {ptr=ptr->next;n++;}
  57. return n;
  58. }
  59. MIDI_device * MIDI_driver::find_device(GUID guid_driver,GUID guid_device)
  60. {
  61. MIDI_driver * driver_ptr = find_driver(guid_driver);
  62. if (!driver_ptr) return 0;
  63. MIDI_device * device_ptr;
  64. int idx=0;
  65. while(device_ptr = driver_ptr->device_enumerate(idx++))
  66. {
  67. if (device_ptr->get_guid()==guid_device) return device_ptr;
  68. }
  69. return 0;
  70. }
  71. MIDI_driver * MIDI_driver::find_driver(GUID guid_driver)
  72. {
  73. MIDI_driver * driver_ptr = driver_list;
  74. while(driver_ptr)
  75. {
  76. if (driver_ptr->get_guid()==guid_driver) break;
  77. driver_ptr = driver_ptr->next;
  78. }
  79. return driver_ptr;
  80. }
  81. MIDI_device * MIDI_driver::find_device_default()
  82. {
  83. MIDI_driver * driver_ptr = driver_list;
  84. while(driver_ptr)
  85. {
  86. if (driver_ptr->is_default())
  87. {
  88. MIDI_device * device_ptr;
  89. int idx=0;
  90. while(device_ptr = driver_ptr->device_enumerate(idx++))
  91. {
  92. if (device_ptr->is_default()) return device_ptr;
  93. }
  94. }
  95. driver_ptr = driver_ptr->next;
  96. }
  97. return 0;
  98. }
  99. void MIDI_driver::shutdown()
  100. {
  101. MIDI_driver * driver_ptr = driver_list;
  102. while(driver_ptr)
  103. {
  104. driver_ptr->deinit();
  105. driver_ptr = driver_ptr->next;
  106. }
  107. }