fluid_mdriver.c
上传用户:tjmskj2
上传日期:2020-08-17
资源大小:577k
文件大小:8k
源码类别:

midi

开发平台:

C/C++

  1. /* FluidSynth - A Software Synthesizer
  2.  *
  3.  * Copyright (C) 2003  Peter Hanappe and others.
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Library General Public License
  7.  * as published by the Free Software Foundation; either version 2 of
  8.  * the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * Library General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Library General Public
  16.  * License along with this library; if not, write to the Free
  17.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18.  * 02111-1307, USA
  19.  */
  20. #include "fluid_mdriver.h"
  21. #include "fluid_settings.h"
  22. /* ALSA */
  23. #if ALSA_SUPPORT
  24. fluid_midi_driver_t* new_fluid_alsa_rawmidi_driver(fluid_settings_t* settings,
  25.  handle_midi_event_func_t handler,
  26.  void* event_handler_data);
  27. int delete_fluid_alsa_rawmidi_driver(fluid_midi_driver_t* p);
  28. void fluid_alsa_rawmidi_driver_settings(fluid_settings_t* settings);
  29. fluid_midi_driver_t* new_fluid_alsa_seq_driver(fluid_settings_t* settings,
  30.      handle_midi_event_func_t handler,
  31.      void* event_handler_data);
  32. int delete_fluid_alsa_seq_driver(fluid_midi_driver_t* p);
  33. void fluid_alsa_seq_driver_settings(fluid_settings_t* settings);
  34. #endif
  35. /* JACK */
  36. #if JACK_SUPPORT
  37. void fluid_jack_midi_driver_settings (fluid_settings_t *settings);
  38. fluid_midi_driver_t *new_fluid_jack_midi_driver (fluid_settings_t *settings,
  39.  handle_midi_event_func_t handler,
  40.  void *data);
  41. int delete_fluid_jack_midi_driver(fluid_midi_driver_t *p);
  42. #endif
  43. /* OSS */
  44. #if OSS_SUPPORT
  45. fluid_midi_driver_t* new_fluid_oss_midi_driver(fluid_settings_t* settings,
  46.      handle_midi_event_func_t handler,
  47.      void* event_handler_data);
  48. int delete_fluid_oss_midi_driver(fluid_midi_driver_t* p);
  49. void fluid_oss_midi_driver_settings(fluid_settings_t* settings);
  50. #endif
  51. /* Windows MIDI service */
  52. #if WINMIDI_SUPPORT
  53. fluid_midi_driver_t* new_fluid_winmidi_driver(fluid_settings_t* settings,
  54.     handle_midi_event_func_t handler,
  55.     void* event_handler_data);
  56. int delete_fluid_winmidi_driver(fluid_midi_driver_t* p);
  57. void fluid_winmidi_midi_driver_settings(fluid_settings_t* settings);
  58. #endif
  59. /* definitions for the MidiShare driver */
  60. #if MIDISHARE_SUPPORT
  61. fluid_midi_driver_t* new_fluid_midishare_midi_driver(fluid_settings_t* settings,
  62.                                                      handle_midi_event_func_t handler,
  63.                                                      void* event_handler_data);
  64. int delete_fluid_midishare_midi_driver(fluid_midi_driver_t* p);
  65. #endif
  66. /* definitions for the CoreMidi driver */
  67. #if COREMIDI_SUPPORT
  68. fluid_midi_driver_t* new_fluid_coremidi_driver(fluid_settings_t* settings,
  69.    void* event_handler_data,
  70.    handle_midi_event_func_t handler);
  71. int delete_fluid_coremidi_driver(fluid_midi_driver_t* p);
  72. void fluid_coremidi_driver_settings(fluid_settings_t* settings);
  73. #endif
  74. /*
  75.  * fluid_mdriver_definition
  76.  */
  77. struct fluid_mdriver_definition_t {
  78.   char* name;
  79.   fluid_midi_driver_t* (*new)(fluid_settings_t* settings,
  80.      handle_midi_event_func_t event_handler,
  81.      void* event_handler_data);
  82.   int (*free)(fluid_midi_driver_t* p);
  83.   void (*settings)(fluid_settings_t* settings);
  84. };
  85. struct fluid_mdriver_definition_t fluid_midi_drivers[] = {
  86. #if JACK_SUPPORT
  87.   { "jack",
  88.     new_fluid_jack_midi_driver,
  89.     delete_fluid_jack_midi_driver,
  90.     fluid_jack_midi_driver_settings },
  91. #endif
  92. #if OSS_SUPPORT
  93.   { "oss",
  94.     new_fluid_oss_midi_driver,
  95.     delete_fluid_oss_midi_driver,
  96.     fluid_oss_midi_driver_settings },
  97. #endif
  98. #if ALSA_SUPPORT
  99.   { "alsa_raw",
  100.     new_fluid_alsa_rawmidi_driver,
  101.     delete_fluid_alsa_rawmidi_driver,
  102.     fluid_alsa_rawmidi_driver_settings },
  103.   { "alsa_seq",
  104.     new_fluid_alsa_seq_driver,
  105.     delete_fluid_alsa_seq_driver,
  106.     fluid_alsa_seq_driver_settings },
  107. #endif
  108. #if WINMIDI_SUPPORT
  109.   { "winmidi",
  110.     new_fluid_winmidi_driver,
  111.     delete_fluid_winmidi_driver,
  112.     fluid_winmidi_midi_driver_settings },
  113. #endif
  114. #if MIDISHARE_SUPPORT
  115.   { "midishare",
  116.     new_fluid_midishare_midi_driver,
  117.     delete_fluid_midishare_midi_driver,
  118.     NULL },
  119. #endif
  120. #if COREMIDI_SUPPORT
  121.   { "coremidi",
  122.     new_fluid_coremidi_driver,
  123.     delete_fluid_coremidi_driver,
  124.     fluid_coremidi_driver_settings },
  125. #endif
  126.   { NULL, NULL, NULL, NULL }
  127. };
  128. void fluid_midi_driver_settings(fluid_settings_t* settings)
  129. {
  130.   int i;
  131.   fluid_settings_register_int (settings, "midi.realtime-prio",
  132.                                FLUID_DEFAULT_MIDI_RT_PRIO, 0, 99, 0, NULL, NULL);
  133.   /* Set the default driver */
  134. #if ALSA_SUPPORT
  135.   fluid_settings_register_str(settings, "midi.driver", "alsa_seq", 0, NULL, NULL);
  136. #elif JACK_SUPPORT
  137.   fluid_settings_register_str(settings, "midi.driver", "jack", 0, NULL, NULL);
  138. #elif OSS_SUPPORT
  139.   fluid_settings_register_str(settings, "midi.driver", "oss", 0, NULL, NULL);
  140. #elif WINMIDI_SUPPORT
  141.   fluid_settings_register_str(settings, "midi.driver", "winmidi", 0, NULL, NULL);
  142. #elif MIDISHARE_SUPPORT
  143.   fluid_settings_register_str(settings, "midi.driver", "midishare", 0, NULL, NULL);
  144. #elif COREMIDI_SUPPORT
  145.   fluid_settings_register_str(settings, "midi.driver", "coremidi", 0, NULL, NULL);
  146. #else
  147.   fluid_settings_register_str(settings, "midi.driver", "", 0, NULL, NULL);
  148. #endif
  149.   /* Add all drivers to the list of options */
  150. #if ALSA_SUPPORT
  151.   fluid_settings_add_option(settings, "midi.driver", "alsa_seq");
  152.   fluid_settings_add_option(settings, "midi.driver", "alsa_raw");
  153. #endif
  154. #if JACK_SUPPORT
  155.   fluid_settings_add_option(settings, "midi.driver", "jack");
  156. #endif
  157. #if OSS_SUPPORT
  158.   fluid_settings_add_option(settings, "midi.driver", "oss");
  159. #endif
  160. #if WINMIDI_SUPPORT
  161.   fluid_settings_add_option(settings, "midi.driver", "winmidi");
  162. #endif
  163. #if MIDISHARE_SUPPORT
  164.   fluid_settings_add_option(settings, "midi.driver", "midishare");
  165. #endif
  166. #if COREMIDI_SUPPORT
  167.   fluid_settings_add_option(settings, "midi.driver", "coremidi");
  168. #endif
  169.   for (i = 0; fluid_midi_drivers[i].name != NULL; i++) {
  170.     if (fluid_midi_drivers[i].settings != NULL) {
  171.       fluid_midi_drivers[i].settings(settings);
  172.     }
  173.   }
  174. }
  175. /**
  176.  * Create a new MIDI driver instance.
  177.  * @param settings Settings used to configure new MIDI driver.
  178.  * @param handler MIDI handler callback (for example: fluid_midi_router_handle_midi_event()
  179.  *   for MIDI router)
  180.  * @param event_handler_data Caller defined data to pass to 'handler'
  181.  * @return New MIDI driver instance or NULL on error
  182.  */
  183. fluid_midi_driver_t* new_fluid_midi_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* event_handler_data)
  184. {
  185.   fluid_midi_driver_t* driver = NULL;
  186.   char *allnames;
  187.   int i;
  188.   for (i = 0; fluid_midi_drivers[i].name != NULL; i++) {
  189.     if (fluid_settings_str_equal(settings, "midi.driver", fluid_midi_drivers[i].name)) {
  190.       FLUID_LOG(FLUID_DBG, "Using '%s' midi driver", fluid_midi_drivers[i].name);
  191.       driver = fluid_midi_drivers[i].new(settings, handler, event_handler_data);
  192.       if (driver) {
  193.         driver->name = fluid_midi_drivers[i].name;
  194.       }
  195.       return driver;
  196.     }
  197.   }
  198.   allnames = fluid_settings_option_concat (settings, "midi.driver", NULL);
  199.   FLUID_LOG(FLUID_ERR, "Couldn't find the requested midi driver. Valid drivers are: %s.",
  200.             allnames ? allnames : "ERROR");
  201.   if (allnames) FLUID_FREE (allnames);
  202.   return NULL;
  203. }
  204. /**
  205.  * Delete a MIDI driver instance.
  206.  * @param driver MIDI driver to delete
  207.  */
  208. void delete_fluid_midi_driver(fluid_midi_driver_t* driver)
  209. {
  210.   int i;
  211.   for (i = 0; fluid_midi_drivers[i].name != NULL; i++) {
  212.     if (fluid_midi_drivers[i].name == driver->name) {
  213.       fluid_midi_drivers[i].free(driver);
  214.       return;
  215.     }
  216.   }
  217. }