source: ext/midi/midi_driver.c @ 876c5e7

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 876c5e7 was b60dd4ae, checked in by Paul Brossier <piem@altern.org>, 20 years ago

moved midi functions to ext/

  • Property mode set to 100644
File size: 5.8 KB
Line 
1/*
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Library General Public License
5 * as published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 * Library General Public License for more details.
12 * 
13 * You should have received a copy of the GNU Library General Public
14 * License along with this library; if not, write to the Free
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
16 * 02111-1307, USA
17 */
18/* This file originally tajke from
19 * FluidSynth - A Software Synthesizer
20 *
21 * Copyright (C) 2003  Peter Hanappe and others.
22 */
23
24#include "aubio_priv.h"
25#include "midi_event.h"
26#include "midi_driver.h"
27//#include "settings.h"
28
29/*
30 * aubio_mdriver_definition
31 */
32struct aubio_mdriver_definition_t {
33  char* name;
34  aubio_midi_driver_t* (*new)(
35      //aubio_settings_t* settings,
36      handle_midi_event_func_t event_handler, 
37      void* event_handler_data);
38  int (*free)(aubio_midi_driver_t* p);
39  void (*settings)(aubio_settings_t* settings);
40};
41
42
43/* ALSA */
44#if ALSA_SUPPORT
45aubio_midi_driver_t* new_aubio_midi_alsa_raw_driver(
46    //aubio_settings_t* settings,
47    handle_midi_event_func_t handler, 
48    void* event_handler_data);
49int del_aubio_midi_alsa_raw_driver(aubio_midi_driver_t* p);
50void aubio_midi_alsa_raw_driver_settings(aubio_settings_t* settings);
51
52aubio_midi_driver_t* new_aubio_alsa_seq_driver(
53    //aubio_settings_t* settings,
54    handle_midi_event_func_t handler, 
55    void* event_handler_data);
56int del_aubio_alsa_seq_driver(aubio_midi_driver_t* p);
57void aubio_alsa_seq_driver_settings(aubio_settings_t* settings);
58#endif
59
60/* OSS */
61#if OSS_SUPPORT
62aubio_midi_driver_t* new_aubio_oss_midi_driver(aubio_settings_t* settings,
63    handle_midi_event_func_t handler, 
64    void* event_handler_data);
65int del_aubio_oss_midi_driver(aubio_midi_driver_t* p);
66//void aubio_oss_midi_driver_settings(aubio_settings_t* settings);
67#endif
68
69/* Windows MIDI service */
70#if WINMIDI_SUPPORT
71aubio_midi_driver_t* new_aubio_winmidi_driver(aubio_settings_t* settings,
72    handle_midi_event_func_t handler, 
73    void* event_handler_data);
74int del_aubio_winmidi_driver(aubio_midi_driver_t* p);
75#endif
76
77/* definitions for the MidiShare driver */
78#if MIDISHARE_SUPPORT
79aubio_midi_driver_t* new_aubio_midishare_midi_driver(aubio_settings_t* settings,
80    handle_midi_event_func_t handler, 
81    void* event_handler_data);
82int del_aubio_midishare_midi_driver(aubio_midi_driver_t* p);
83#endif
84
85
86struct aubio_mdriver_definition_t aubio_midi_drivers[] = {
87#if OSS_SUPPORT
88  { "oss", 
89    new_aubio_oss_midi_driver, 
90    del_aubio_oss_midi_driver, 
91    aubio_oss_midi_driver_settings },
92#endif
93#if ALSA_SUPPORT
94  { "alsa_raw", 
95    new_aubio_midi_alsa_raw_driver, 
96    del_aubio_midi_alsa_raw_driver, 
97    NULL /*aubio_midi_alsa_raw_driver_settings*/ },
98  { "alsa_seq", 
99    new_aubio_alsa_seq_driver, 
100    del_aubio_alsa_seq_driver, 
101    NULL /*aubio_alsa_seq_driver_settings*/ },
102#endif
103#if WINMIDI_SUPPORT
104  { "winmidi", 
105    new_aubio_winmidi_driver, 
106    del_aubio_winmidi_driver, 
107    NULL },
108#endif
109#if MIDISHARE_SUPPORT
110  { "midishare", 
111    new_aubio_midishare_midi_driver, 
112    del_aubio_midishare_midi_driver, 
113    NULL },
114#endif
115  { NULL, NULL, NULL, NULL }
116};
117
118
119void aubio_midi_driver_settings(aubio_settings_t* settings)
120{ 
121  int i;
122
123#if 0
124  /* Set the default driver */
125#if ALSA_SUPPORT
126  aubio_settings_register_str(settings, "midi.driver", "alsa_seq", 0, NULL, NULL);
127#elif OSS_SUPPORT
128  aubio_settings_register_str(settings, "midi.driver", "oss", 0, NULL, NULL);
129#elif WINMIDI_SUPPORT
130  aubio_settings_register_str(settings, "midi.driver", "winmidi", 0, NULL, NULL);
131#elif MIDISHARE_SUPPORT
132  aubio_settings_register_str(settings, "midi.driver", "midishare", 0, NULL, NULL);
133#else
134  aubio_settings_register_str(settings, "midi.driver", "", 0, NULL, NULL);
135#endif
136
137  /* Add all drivers to the list of options */
138#if ALSA_SUPPORT
139  aubio_settings_add_option(settings, "midi.driver", "alsa_seq");
140  aubio_settings_add_option(settings, "midi.driver", "alsa_raw");
141#endif
142#if OSS_SUPPORT
143  aubio_settings_add_option(settings, "midi.driver", "oss");
144#endif
145#if WINMIDI_SUPPORT
146  aubio_settings_add_option(settings, "midi.driver", "winmidi");
147#endif
148#if MIDISHARE_SUPPORT
149  aubio_settings_add_option(settings, "midi.driver", "midishare");
150#endif
151
152#endif
153
154  for (i = 0; aubio_midi_drivers[i].name != NULL; i++) {
155    if (aubio_midi_drivers[i].settings != NULL) {
156      aubio_midi_drivers[i].settings(settings);
157    }
158  } 
159}
160
161//aubio_midi_driver_t* new_aubio_midi_driver(aubio_settings_t* settings,
162aubio_midi_driver_t* new_aubio_midi_driver(char * name, 
163    handle_midi_event_func_t handler, 
164    void* event_handler_data)
165{
166  int i;
167  aubio_midi_driver_t* driver = NULL;
168  for (i = 0; aubio_midi_drivers[i].name != NULL; i++) {
169    if (AUBIO_STRCMP(name,aubio_midi_drivers[i].name) == 0){
170      //if (aubio_settings_str_equal(settings, "midi.driver", aubio_midi_drivers[i].name)) {
171      AUBIO_DBG( "Using '%s' midi driver\n", aubio_midi_drivers[i].name);
172      //driver = aubio_midi_drivers[i].new(settings, handler, event_handler_data);
173      driver = aubio_midi_drivers[i].new(/*name,*/ handler, event_handler_data);
174      if (driver) {
175        driver->name = aubio_midi_drivers[i].name;
176      }
177      return driver;
178    }
179  }
180  AUBIO_ERR("Couldn't find the requested midi driver");
181  return NULL;
182}
183
184void del_aubio_midi_driver(aubio_midi_driver_t* driver)
185{
186  int i;
187
188  for (i = 0; aubio_midi_drivers[i].name != NULL; i++) {
189    if (aubio_midi_drivers[i].name == driver->name) {
190      aubio_midi_drivers[i].free(driver);
191      return;
192    }
193  } 
194}
195
Note: See TracBrowser for help on using the repository browser.