Example #1
0
/**
 * @brief Detect the format of message stored in a buffer.
 * Determine the message format used in a stream of bytes but check for running status as well.
 * @public @memberof MIDIMessageFormat
 * @param buffer The message as it would appear on a MIDI cable.
 * @param status The running status to use if the buffer does not contain a status byte.
 * @return a pointer to the correct message format if the format could be detected.
 * @return a NULL pointer if the format could not be detected.
 */
struct MIDIMessageFormat * MIDIMessageFormatDetectRunningStatus( void * buffer, MIDIRunningStatus * status ) {
  if( VOID_BYTE(buffer, 0) & 0x80 ) {
    return MIDIMessageFormatDetect( buffer );
  } else if( status != NULL && *status != 0 ) {
    return MIDIMessageFormatDetect( status );
  } else {
    return NULL;
  }
}
Example #2
0
/*
 * event input callback - just redirect events to subscribers
 */
static int _alsa_input(struct snd_seq_event *ev, int direct, void *private_data,
		       int atomic, int hop)
{
	struct privateData *data = (struct privateData *)private_data;
	pr_debug("callback from alsa received of type %d\n", ev->type);

	spin_lock(&(data->drv->lock));

	if (ev->type == SND_SEQ_EVENT_NOTEON) {
		data->msg.data.bytes[0] = 0x90;
	} else if (ev->type == SND_SEQ_EVENT_NOTEOFF) {
		data->msg.data.bytes[0] = 0x80;
	} else {
		return 1;
	}
	
	//might be changed to ev->data.raw?? for event independant passing

	data->msg.data.bytes[0] |= ev->data.note.channel & 0xf;
	data->msg.data.bytes[1] = ev->data.note.note;
	data->msg.data.bytes[2] = ev->data.note.velocity;
	data->msg.data.bytes[3] = 0;
	data->msg.data.size = 3;
	data->msg.data.data = NULL;
	data->msg.format = MIDIMessageFormatDetect(&(data->msg.data.bytes[0]));
	pr_debug("found format\n");
	data->msg.timestamp = 0;

	RTPMIDISessionSend(data->drv->rtpmidi_session, &(data->list));

	spin_unlock(&(data->drv->lock));

	return 0;
}
Example #3
0
/**
 * @brief Get a format used for a given status.
 * Determine the format that shall be used when accessing messages of
 * a known status.
 * If the status byte looks like a channel status it is correctly
 * shifted so that the correct byte can be checked by MIDIMessageFormatDetect.
 * @see MIDIMessageFormatDetect
 * @public @memberof MIDIMessageFormat
 * @param status A message status.
 * @return a pointer to the correct message format if the format could be detected.
 * @return a NULL pointer if the format could not be detected or if the given
 *         status is not an allowed MIDIStatus.
 */
struct MIDIMessageFormat * MIDIMessageFormatForStatus( MIDIStatus status ) {
  unsigned char byte;
  if( status >= 0x80 ) {
    byte = status;
    if( byte < 0xf0 ) return NULL; /* messed up channel status? */
  } else {
    byte = status << 4;
    if( byte < 0x80 ) return NULL; /* no status bit? */
  }
  return MIDIMessageFormatDetect( &byte );
}