# src/fluid_mdriver.c

    00001 /* FluidSynth - A Software Synthesizer
    00002  *
    00003  * Copyright (C) 2003  Peter Hanappe and others.
    00004  *
    00005  * This library is free software; you can redistribute it and/or
    00006  * modify it under the terms of the GNU Library General Public License
    00007  * as published by the Free Software Foundation; either version 2 of
    00008  * the License, or (at your option) any later version.
    00009  *
    00010  * This library is distributed in the hope that it will be useful, but
    00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  * Library General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Library General Public
    00016  * License along with this library; if not, write to the Free
    00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    00018  * 02111-1307, USA
    00019  */
    00020
    00021 #include "fluid_mdriver.h"
    00022 #include "fluid_settings.h"
    00023
    00024
    00025 /* ALSA */
    00026 #if ALSA_SUPPORT
    00027 fluid_midi_driver_t* new_fluid_alsa_rawmidi_driver(fluid_settings_t* settings,
    00028                                                  handle_midi_event_func_t handler,
    00029                                                  void* event_handler_data);
    00030 int delete_fluid_alsa_rawmidi_driver(fluid_midi_driver_t* p);
    00031 void fluid_alsa_rawmidi_driver_settings(fluid_settings_t* settings);
    00032
    00033 fluid_midi_driver_t* new_fluid_alsa_seq_driver(fluid_settings_t* settings,
    00034                                              handle_midi_event_func_t handler,
    00035                                              void* event_handler_data);
    00036 int delete_fluid_alsa_seq_driver(fluid_midi_driver_t* p);
    00037 void fluid_alsa_seq_driver_settings(fluid_settings_t* settings);
    00038 #endif
    00039
    00040 /* OSS */
    00041 #if OSS_SUPPORT
    00042 fluid_midi_driver_t* new_fluid_oss_midi_driver(fluid_settings_t* settings,
    00043                                              handle_midi_event_func_t handler,
    00044                                              void* event_handler_data);
    00045 int delete_fluid_oss_midi_driver(fluid_midi_driver_t* p);
    00046 void fluid_oss_midi_driver_settings(fluid_settings_t* settings);
    00047 #endif
    00048
    00049 /* Windows MIDI service */
    00050 #if WINMIDI_SUPPORT
    00051 fluid_midi_driver_t* new_fluid_winmidi_driver(fluid_settings_t* settings,
    00052                                             handle_midi_event_func_t handler,
    00053                                             void* event_handler_data);
    00054 int delete_fluid_winmidi_driver(fluid_midi_driver_t* p);
    00055 #endif
    00056
    00057 /* definitions for the MidiShare driver */
    00058 #if MIDISHARE_SUPPORT
    00059 fluid_midi_driver_t* new_fluid_midishare_midi_driver(fluid_settings_t* settings,
    00060                                                    void* event_handler_data,
    00061                                                    handle_midi_event_func_t handler);
    00062 int delete_fluid_midishare_midi_driver(fluid_midi_driver_t* p);
    00063 #endif
    00064
    00065
    00066
    00067 /*
    00068  * fluid_mdriver_definition
    00069  */
    00070 struct fluid_mdriver_definition_t {
    00071   char* name;
    00072   fluid_midi_driver_t* (*new)(fluid_settings_t* settings,
    00073                              handle_midi_event_func_t event_handler,
    00074                              void* event_handler_data);
    00075   int (*free)(fluid_midi_driver_t* p);
    00076   void (*settings)(fluid_settings_t* settings);
    00077 };
    00078
    00079
    00080 struct fluid_mdriver_definition_t fluid_midi_drivers[] = {
    00081 #if OSS_SUPPORT
    00082   { "oss",
    00083     new_fluid_oss_midi_driver,
    00084     delete_fluid_oss_midi_driver,
    00085     fluid_oss_midi_driver_settings },
    00086 #endif
    00087 #if ALSA_SUPPORT
    00088   { "alsa_raw",
    00089     new_fluid_alsa_rawmidi_driver,
    00090     delete_fluid_alsa_rawmidi_driver,
    00091     fluid_alsa_rawmidi_driver_settings },
    00092   { "alsa_seq",
    00093     new_fluid_alsa_seq_driver,
    00094     delete_fluid_alsa_seq_driver,
    00095     fluid_alsa_seq_driver_settings },
    00096 #endif
    00097 #if WINMIDI_SUPPORT
    00098   { "winmidi",
    00099     new_fluid_winmidi_driver,
    00100     delete_fluid_winmidi_driver,
    00101     NULL },
    00102 #endif
    00103 #if MIDISHARE_SUPPORT
    00104   { "midishare",
    00105     new_fluid_midishare_midi_driver,
    00106     delete_fluid_midishare_midi_driver,
    00107     NULL },
    00108 #endif
    00109   { NULL, NULL, NULL, NULL }
    00110 };
    00111
    00112
    00113
    00114 void fluid_midi_driver_settings(fluid_settings_t* settings)
    00115 {
    00116   int i;
    00117
    00118   /* Set the default driver */
    00119 #if ALSA_SUPPORT
    00120   fluid_settings_register_str(settings, "midi.driver", "alsa_seq", 0, NULL, NULL);
    00121 #elif OSS_SUPPORT
    00122   fluid_settings_register_str(settings, "midi.driver", "oss", 0, NULL, NULL);
    00123 #elif WINMIDI_SUPPORT
    00124   fluid_settings_register_str(settings, "midi.driver", "winmidi", 0, NULL, NULL);
    00125 #elif MIDISHARE_SUPPORT
    00126   fluid_settings_register_str(settings, "midi.driver", "midishare", 0, NULL, NULL);
    00127 #else
    00128   fluid_settings_register_str(settings, "midi.driver", "", 0, NULL, NULL);
    00129 #endif
    00130
    00131   /* Add all drivers to the list of options */
    00132 #if ALSA_SUPPORT
    00133   fluid_settings_add_option(settings, "midi.driver", "alsa_seq");
    00134   fluid_settings_add_option(settings, "midi.driver", "alsa_raw");
    00135 #endif
    00136 #if OSS_SUPPORT
    00137   fluid_settings_add_option(settings, "midi.driver", "oss");
    00138 #endif
    00139 #if WINMIDI_SUPPORT
    00140   fluid_settings_add_option(settings, "midi.driver", "winmidi");
    00141 #endif
    00142 #if MIDISHARE_SUPPORT
    00143   fluid_settings_add_option(settings, "midi.driver", "midishare");
    00144 #endif
    00145
    00146   for (i = 0; fluid_midi_drivers[i].name != NULL; i++) {
    00147     if (fluid_midi_drivers[i].settings != NULL) {
    00148       fluid_midi_drivers[i].settings(settings);
    00149     }
    00150   }
    00151 }
    00152
    00153
    00162 fluid_midi_driver_t* new_fluid_midi_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* event_handler_data)
    00163 {
    00164   int i;
    00165   fluid_midi_driver_t* driver = NULL;
    00166   for (i = 0; fluid_midi_drivers[i].name != NULL; i++) {
    00167     if (fluid_settings_str_equal(settings, "midi.driver", fluid_midi_drivers[i].name)) {
    00168       FLUID_LOG(FLUID_DBG, "Using '%s' midi driver", fluid_midi_drivers[i].name);
    00169       driver = fluid_midi_drivers[i].new(settings, handler, event_handler_data);
    00170       if (driver) {
    00171         driver->name = fluid_midi_drivers[i].name;
    00172       }
    00173       return driver;
    00174     }
    00175   }
    00176
    00177   FLUID_LOG(FLUID_ERR, "Couldn't find the requested midi driver");
    00178   return NULL;
    00179 }
    00180
    00185 void delete_fluid_midi_driver(fluid_midi_driver_t* driver)
    00186 {
    00187   int i;
    00188
    00189   for (i = 0; fluid_midi_drivers[i].name != NULL; i++) {
    00190     if (fluid_midi_drivers[i].name == driver->name) {
    00191       fluid_midi_drivers[i].free(driver);
    00192       return;
    00193     }
    00194   }
    00195 }