Re: [AD] Patch for alsa midi support. |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
And again :)
This time the patch really is attaced :)
thanks.
--
Tom Fjellstrom
tfjellstrom@xxxxxxxxxx
http://strangesoft.net/
diff -udr /home/moose/allegro/src/unix/ualsamidi.c /usr/src/allegro/src/unix/ualsamidi.c
--- /home/moose/allegro/src/unix/ualsamidi.c Sat Nov 4 15:49:07 2000
+++ /usr/src/allegro/src/unix/ualsamidi.c Sat Nov 4 15:52:35 2000
@@ -14,12 +14,18 @@
*
* See readme.txt for copyright information.
*/
-
+
+#include "allegro.h"
+
+#ifdef MIDI_ALSA
+
+#include "allegro/aintern.h"
+#include "allegro/aintunix.h"
+
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
-#include <allegro.h>
-#include <allegro/aintern.h>
+
#include <sys/asoundlib.h>
/* external interface to the ALSA rawmidi driver */
@@ -28,8 +34,6 @@
static void alsa_rawmidi_exit(int input);
static void alsa_rawmidi_output(int data);
-#define MIDI_ALSA AL_ID('A','M','I','D')
-
static char alsa_rawmidi_desc[80];
static snd_rawmidi_t *rawmidi_handle = NULL;
@@ -56,13 +60,6 @@
_dummy_noop2 /* set_vibrato */
};
-/*_DRIVER_INFO my_midi_driver_list[] = {
- { MIDI_ALSA, &midi_alsa, FALSE },
- MIDI_DRIVER_DIGMID
- { 0 },
-};
-*/
-
/* alsa_rawmidi_detect:
* ALSA RawMIDI detection.
*/
@@ -71,46 +68,49 @@
int card = -1;
int device = -1;
int ret = FALSE, err;
- char tmp1[80], tmp2[80];
+ char tmp1[80], tmp2[80], temp[255];
snd_rawmidi_t *handle = NULL;
if(input) {
-
card = get_config_int(uconvert_ascii("sound", tmp1),
- uconvert_ascii("alsa_input_card", tmp2),
- snd_defaults_rawmidi_card());
+ uconvert_ascii("alsa_input_card", tmp2),
+ snd_defaults_rawmidi_card());
- device = get_config_int(uconvert_ascii("sound", tmp1),
- uconvert_ascii("alsa_rawmidi_input_device", tmp2),
- snd_defaults_rawmidi_device());
+ device = get_config_int(uconvert_ascii("sound", tmp1),
+ uconvert_ascii("alsa_rawmidi_input_device", tmp2),
+ snd_defaults_rawmidi_device());
- if ((err = snd_rawmidi_open(&handle, card, device, SND_RAWMIDI_OPEN_INPUT|SND_RAWMIDI_OPEN_NONBLOCK)) < 0) {
- ustrcpy(allegro_error, get_config_text("Could not open card/rawmidi device"));
+ if ((err = snd_rawmidi_open(&handle, card, device, SND_RAWMIDI_OPEN_INPUT)) < 0) {
+ sprintf(temp, "Could not open card/rawmidi device: %s", snd_strerror(err));
+ ustrcpy(allegro_error, get_config_text(temp));
ret = FALSE;
}
+ snd_rawmidi_close(handle);
+
ret = TRUE;
}
else {
card = get_config_int(uconvert_ascii("sound", tmp1),
- uconvert_ascii("alsa_rawmidi_card", tmp2),
- snd_defaults_rawmidi_card());
+ uconvert_ascii("alsa_rawmidi_card", tmp2),
+ snd_defaults_rawmidi_card());
- device = get_config_int(uconvert_ascii("sound", tmp1),
- uconvert_ascii("alsa_rawmidi_device", tmp2),
- snd_defaults_rawmidi_device());
+ device = get_config_int(uconvert_ascii("sound", tmp1),
+ uconvert_ascii("alsa_rawmidi_device", tmp2),
+ snd_defaults_rawmidi_device());
- if ((err = snd_rawmidi_open(&handle, card, device, SND_RAWMIDI_OPEN_OUTPUT|SND_RAWMIDI_OPEN_NONBLOCK)) < 0) {
- ustrcpy(allegro_error, get_config_text("Could not open card/rawmidi device"));
+ if ((err = snd_rawmidi_open(&handle, card, device, SND_RAWMIDI_OPEN_OUTPUT_APPEND)) < 0) {
+ sprintf(temp, "Could not open card/rawmidi device: %s", snd_strerror(err));
+ ustrcpy(allegro_error, get_config_text(temp));
ret = FALSE;
}
- snd_rawmidi_close(handle);
+ snd_rawmidi_close(handle);
- ret = TRUE;
- }
+ ret = TRUE;
+ }
return ret;
}
@@ -123,21 +123,22 @@
int card = -1;
int device = -1;
int ret = -1, err;
- char tmp1[80], tmp2[80];
+ char tmp1[80], tmp2[80], temp[255];
snd_rawmidi_info_t info;
if(input) {
card = get_config_int(uconvert_ascii("sound", tmp1),
- uconvert_ascii("alsa_input_card", tmp2),
- snd_defaults_rawmidi_card());
+ uconvert_ascii("alsa_input_card", tmp2),
+ snd_defaults_rawmidi_card());
device = get_config_int(uconvert_ascii("sound", tmp1),
- uconvert_ascii("alsa_rawmidi_input_device", tmp2),
- snd_defaults_rawmidi_device());
+ uconvert_ascii("alsa_rawmidi_input_device", tmp2),
+ snd_defaults_rawmidi_device());
- if ((err = snd_rawmidi_open(&rawmidi_handle, card, device, SND_RAWMIDI_OPEN_INPUT|SND_RAWMIDI_OPEN_NONBLOCK)) < 0) {
- ustrcpy(allegro_error, get_config_text("Could not open card/rawmidi device"));
+ if ((err = snd_rawmidi_open(&rawmidi_handle, card, device, SND_RAWMIDI_OPEN_INPUT)) < 0) {
+ sprintf(temp, "Could not open card/rawmidi device: %s", snd_strerror(err));
+ ustrcpy(allegro_error, get_config_text(temp));
ret = -1;
}
@@ -147,20 +148,21 @@
else {
card = get_config_int(uconvert_ascii("sound", tmp1),
- uconvert_ascii("alsa_card", tmp2),
- snd_defaults_rawmidi_card());
+ uconvert_ascii("alsa_rawmidi_card", tmp2),
+ snd_defaults_rawmidi_card());
- device = get_config_int(uconvert_ascii("sound", tmp1),
- uconvert_ascii("alsa_rawmidi_device", tmp2),
- snd_defaults_rawmidi_device());
+ device = get_config_int(uconvert_ascii("sound", tmp1),
+ uconvert_ascii("alsa_rawmidi_device", tmp2),
+ snd_defaults_rawmidi_device());
- if ((err = snd_rawmidi_open(&rawmidi_handle, card, device, SND_RAWMIDI_OPEN_OUTPUT_APPEND/*|SND_RAWMIDI_OPEN_NONBLOCK*/)) < 0) {
- ustrcpy(allegro_error, get_config_text("Could not open card/rawmidi device"));
+ if ((err = snd_rawmidi_open(&rawmidi_handle, card, device, SND_RAWMIDI_OPEN_OUTPUT_APPEND)) < 0) {
+ sprintf(temp, "Could not open card/rawmidi device: %s", snd_strerror(err));
+ ustrcpy(allegro_error, get_config_text(temp));
ret = -1;
}
- ret = 0;
- }
+ ret = 0;
+ }
if(rawmidi_handle) {
snd_rawmidi_block_mode(rawmidi_handle, 1);
@@ -199,13 +201,6 @@
int err;
err = snd_rawmidi_write(rawmidi_handle, &data, sizeof(char));
- if(err < 0)
- printf("error: %s\n", snd_strerror(err));
- else if(err == 0)
- printf("didn't write to midi port...\n");
-
- //snd_rawmidi_output_drain(rawmidi_handle);
- //printf("drained output que\n");
}
END_OF_STATIC_FUNCTION(alsa_rawmidi_output);
@@ -223,16 +218,4 @@
return 0;
}
-/*
-_DRIVER_INFO *detect_midi_drivers(void)
-{
- return my_midi_driver_list;
-}
-
-
-void init_alsa_rawmidi_driver(void)
-{
- if(system_driver)
- system_driver->midi_drivers = detect_midi_drivers;
-}
-*/
+#endif /* MIDI_ALSA */