/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#define USE_ERROR
#define USE_TRACE
#include "PLATFORM_API_LinuxOS_ALSA_MidiUtils.h"
#include "PLATFORM_API_LinuxOS_ALSA_CommonUtils.h"
#include <string.h>
}
return snd_strerror((int) err);
}
// callback for iteration through devices
// returns TRUE if iteration should continue
void *userData);
// for each ALSA device, call iterator. userData is passed to the iterator
// returns total number of iterations
void* userData) {
int count = 0;
int subdeviceCount;
int err;
// 1st try "default" device
if (direction == SND_RAWMIDI_STREAM_INPUT) {
} else if (direction == SND_RAWMIDI_STREAM_OUTPUT) {
} else {
ERROR0("ERROR: iterateRawmidiDevices(): direction is neither"
" SND_RAWMIDI_STREAM_INPUT nor SND_RAWMIDI_STREAM_OUTPUT\n");
}
if (err < 0) {
ERROR1("ERROR: snd_rawmidi_open (\"default\"): %s\n",
snd_strerror(err));
} else {
if (err < 0) {
ERROR1("ERROR: snd_rawmidi_info (\"default\"): %s\n",
snd_strerror(err));
} else {
// try to get card info
if (card >= 0) {
}
}
}
// call calback function for the device
}
count++;
}
}
// iterate cards
card = -1;
TRACE0("testing for cards...\n");
if (snd_card_next(&card) >= 0) {
while (doContinue && (card >= 0)) {
if (err < 0) {
} else {
TRACE0("snd_ctl_open() SUCCESS\n");
if (err < 0) {
} else {
TRACE0("snd_ctl_card_info() SUCCESS\n");
dev = -1;
while (doContinue) {
ERROR0("snd_ctl_rawmidi_next_device\n");
}
TRACE0("snd_ctl_rawmidi_next_device() SUCCESS\n");
if (dev < 0) {
break;
}
TRACE0("after snd_ctl_rawmidi_info()\n");
if (err < 0) {
}
} else {
TRACE0("snd_ctl_rawmidi_info() SUCCESS\n");
: 1;
count++;
TRACE0("returned from iterator\n");
if (!doContinue) {
break;
}
}
} else {
count += subdeviceCount;
}
}
} // of while(doContinue)
}
}
if (snd_card_next(&card) < 0) {
break;
}
}
} else {
ERROR0("No cards found!\n");
}
return count;
}
int deviceCount;
TRACE0("> getMidiDeviceCount()\n");
TRACE0("< getMidiDeviceCount()\n");
return deviceCount;
}
/*
userData is assumed to be a pointer to ALSA_MIDIDeviceDescription.
ALSA_MIDIDeviceDescription->index has to be set to the index of the device
we want to get information of before this method is called the first time via
iterateRawmidiDevices(). On each call of this method,
ALSA_MIDIDeviceDescription->index is decremented. If it is equal to zero,
we have reached the desired device, so action is taken.
So after successful completion of iterateRawmidiDevices(),
ALSA_MIDIDeviceDescription->index is zero. If it isn't, this is an
indication of an error.
*/
#ifdef ALSA_MIDI_USE_PLUGHW
#else
int usePlugHw = 0;
#endif
TRACE0("deviceInfoIterator\n");
// we found the device with correct index
desc->description[0] = 0;
}
return FALSE; // do not continue iteration
}
return TRUE;
}
}
! desc->description) {
}
return ret;
}
}
if (desc->description) {
}
}
UINT32 nameLength) {
int ret;
if (ret == MIDI_SUCCESS) {
TRACE0("getMidiDeviceName: initMIDIDeviceDescription() SUCCESS\n");
if (ret == MIDI_SUCCESS) {
}
}
return ret;
}
return MIDI_SUCCESS;
}
int ret;
if (ret == MIDI_SUCCESS) {
if (ret == MIDI_SUCCESS) {
}
}
return ret;
}
return MIDI_SUCCESS;
}
int ret;
if (ret == MIDI_SUCCESS) {
if (ret == MIDI_SUCCESS) {
// TRACE1("getMidiDeviceName: desc.name: %s\n", desc.name);
}
}
return ret;
}
/*
direction has to be either SND_RAWMIDI_STREAM_INPUT or
SND_RAWMIDI_STREAM_OUTPUT.
Returns 0 on success. Otherwise, MIDI_OUT_OF_MEMORY, MIDI_INVALID_ARGUMENT
or a negative ALSA error code is returned.
*/
MidiDeviceHandle** handle) {
int err;
#ifdef ALSA_MIDI_USE_PLUGHW
#else
int usePlugHw = 0;
#endif
TRACE0("> openMidiDevice()\n");
if (!(*handle)) {
ERROR0("ERROR: openDevice: out of memory\n");
return MIDI_OUT_OF_MEMORY;
}
// TODO: iterate to get dev ID from index
// finally open the device
if (direction == SND_RAWMIDI_STREAM_INPUT) {
} else if (direction == SND_RAWMIDI_STREAM_OUTPUT) {
} else {
ERROR0(" ERROR: openMidiDevice(): direction is neither SND_RAWMIDI_STREAM_INPUT nor SND_RAWMIDI_STREAM_OUTPUT\n");
}
if (err < 0) {
return err;
}
/* We opened with non-blocking behaviour to not get hung if the device
is used by a different process. Writing, however, should
be blocking. So we change it here. */
if (direction == SND_RAWMIDI_STREAM_OUTPUT) {
if (err < 0) {
return err;
}
}
if (direction == SND_RAWMIDI_STREAM_INPUT) {
if (err < 0) {
return err;
}
}
TRACE0("< openMidiDevice(): succeeded\n");
return err;
}
int err;
TRACE0("> closeMidiDevice()\n");
if (!handle) {
ERROR0("< ERROR: closeMidiDevice(): handle is NULL\n");
return MIDI_INVALID_HANDLE;
}
if (!handle->deviceHandle) {
ERROR0("< ERROR: closeMidiDevice(): native handle is NULL\n");
return MIDI_INVALID_HANDLE;
}
if (handle->platformData) {
}
TRACE0("< closeMidiDevice: succeeded\n");
return err;
}
if (!handle) {
ERROR0("< ERROR: closeMidiDevice(): handle is NULL\n");
return MIDI_INVALID_HANDLE;
}
}
/* end */