1999-09-17 16:17:21 +00:00
|
|
|
/*
|
|
|
|
|
* Sequencer Interface - middle-level routines
|
|
|
|
|
*
|
2001-06-06 17:50:16 +00:00
|
|
|
* Copyright (c) 1999 by Takashi Iwai <tiwai@suse.de>
|
1999-09-17 16:17:21 +00:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
2001-12-30 09:22:54 +00:00
|
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
1999-09-17 16:17:21 +00:00
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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
|
2001-12-30 09:22:54 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
1999-09-17 16:17:21 +00:00
|
|
|
*
|
2001-12-30 09:22:54 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1999-09-17 16:17:21 +00:00
|
|
|
* License along with this library; if not, write to the Free Software
|
2017-11-14 14:29:26 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1999-09-17 16:17:21 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2023-09-13 12:27:21 +02:00
|
|
|
#include "seq_local.h"
|
1999-09-17 16:17:21 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <fcntl.h>
|
2001-07-04 13:54:13 +00:00
|
|
|
#include <ctype.h>
|
1999-09-17 16:17:21 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
|
|
|
|
* \brief queue controls - start/stop/continue
|
|
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \param q queue id to control
|
|
|
|
|
* \param type event type
|
|
|
|
|
* \param value event value
|
|
|
|
|
* \param ev event instance
|
|
|
|
|
*
|
2001-07-04 13:54:13 +00:00
|
|
|
* This function sets up general queue control event and sends it.
|
|
|
|
|
* To send at scheduled time, set the schedule in \a ev.
|
|
|
|
|
* If \a ev is NULL, the event is composed locally and sent immediately
|
2003-10-22 14:25:55 +00:00
|
|
|
* to the specified queue. In any cases, you need to call #snd_seq_drain_output()
|
2002-03-12 20:14:33 +00:00
|
|
|
* appropriately to feed the event.
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
|
|
|
|
* \sa snd_seq_alloc_queue()
|
2001-06-06 17:50:16 +00:00
|
|
|
*/
|
1999-09-17 16:17:21 +00:00
|
|
|
int snd_seq_control_queue(snd_seq_t *seq, int q, int type, int value, snd_seq_event_t *ev)
|
|
|
|
|
{
|
|
|
|
|
snd_seq_event_t tmpev;
|
|
|
|
|
if (ev == NULL) {
|
|
|
|
|
snd_seq_ev_clear(&tmpev);
|
|
|
|
|
ev = &tmpev;
|
|
|
|
|
snd_seq_ev_set_direct(ev);
|
|
|
|
|
}
|
1999-12-15 18:34:12 +00:00
|
|
|
snd_seq_ev_set_queue_control(ev, type, q, value);
|
1999-09-17 16:17:21 +00:00
|
|
|
return snd_seq_event_output(seq, ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
|
|
|
|
* \brief create a port - simple version
|
2001-07-04 13:54:13 +00:00
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \param name the name of the port
|
|
|
|
|
* \param caps capability bits
|
|
|
|
|
* \param type type bits
|
|
|
|
|
* \return the created port number or negative error code
|
2001-06-06 17:50:16 +00:00
|
|
|
*
|
2001-07-04 13:54:13 +00:00
|
|
|
* Creates a port with the given capability and type bits.
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
|
|
|
|
* \sa snd_seq_create_port(), snd_seq_delete_simple_port()
|
1999-09-17 16:17:21 +00:00
|
|
|
*/
|
2001-02-11 15:45:35 +00:00
|
|
|
int snd_seq_create_simple_port(snd_seq_t *seq, const char *name,
|
1999-09-17 16:17:21 +00:00
|
|
|
unsigned int caps, unsigned int type)
|
|
|
|
|
{
|
|
|
|
|
snd_seq_port_info_t pinfo;
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
memset(&pinfo, 0, sizeof(pinfo));
|
|
|
|
|
if (name)
|
|
|
|
|
strncpy(pinfo.name, name, sizeof(pinfo.name) - 1);
|
|
|
|
|
pinfo.capability = caps;
|
|
|
|
|
pinfo.type = type;
|
|
|
|
|
pinfo.midi_channels = 16;
|
|
|
|
|
pinfo.midi_voices = 64; /* XXX */
|
|
|
|
|
pinfo.synth_voices = 0; /* XXX */
|
|
|
|
|
|
|
|
|
|
result = snd_seq_create_port(seq, &pinfo);
|
|
|
|
|
if (result < 0)
|
|
|
|
|
return result;
|
|
|
|
|
else
|
2001-07-04 13:54:13 +00:00
|
|
|
return pinfo.addr.port;
|
1999-09-17 16:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
|
|
|
|
* \brief delete the port
|
2001-07-04 13:54:13 +00:00
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \param port port id
|
2002-03-12 20:14:33 +00:00
|
|
|
* \return 0 on success or negative error code
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
|
|
|
|
* \sa snd_seq_delete_port(), snd_seq_create_simple_port()
|
2001-06-06 17:50:16 +00:00
|
|
|
*/
|
1999-09-17 16:17:21 +00:00
|
|
|
int snd_seq_delete_simple_port(snd_seq_t *seq, int port)
|
|
|
|
|
{
|
2001-07-04 13:54:13 +00:00
|
|
|
return snd_seq_delete_port(seq, port);
|
1999-09-17 16:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
2001-07-04 13:54:13 +00:00
|
|
|
* \brief simple subscription (w/o exclusive & time conversion)
|
2005-05-24 14:14:28 +00:00
|
|
|
* \param seq sequencer handle
|
2001-07-04 13:54:13 +00:00
|
|
|
* \param myport the port id as receiver
|
|
|
|
|
* \param src_client sender client id
|
|
|
|
|
* \param src_port sender port id
|
|
|
|
|
* \return 0 on success or negative error code
|
|
|
|
|
*
|
|
|
|
|
* Connect from the given sender client:port to the given destination port in the
|
|
|
|
|
* current client.
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
|
|
|
|
* \sa snd_seq_subscribe_port(), snd_seq_disconnect_from()
|
1999-09-17 16:17:21 +00:00
|
|
|
*/
|
|
|
|
|
int snd_seq_connect_from(snd_seq_t *seq, int myport, int src_client, int src_port)
|
|
|
|
|
{
|
|
|
|
|
snd_seq_port_subscribe_t subs;
|
|
|
|
|
|
|
|
|
|
memset(&subs, 0, sizeof(subs));
|
|
|
|
|
subs.sender.client = src_client;
|
|
|
|
|
subs.sender.port = src_port;
|
|
|
|
|
/*subs.dest.client = seq->client;*/
|
|
|
|
|
subs.dest.client = snd_seq_client_id(seq);
|
|
|
|
|
subs.dest.port = myport;
|
|
|
|
|
|
|
|
|
|
return snd_seq_subscribe_port(seq, &subs);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
2002-03-12 20:14:33 +00:00
|
|
|
* \brief simple subscription (w/o exclusive & time conversion)
|
2005-05-24 14:14:28 +00:00
|
|
|
* \param seq sequencer handle
|
2001-07-04 13:54:13 +00:00
|
|
|
* \param myport the port id as sender
|
|
|
|
|
* \param dest_client destination client id
|
|
|
|
|
* \param dest_port destination port id
|
|
|
|
|
* \return 0 on success or negative error code
|
|
|
|
|
*
|
|
|
|
|
* Connect from the given receiver port in the current client
|
|
|
|
|
* to the given destination client:port.
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
|
|
|
|
* \sa snd_seq_subscribe_port(), snd_seq_disconnect_to()
|
2001-06-06 17:50:16 +00:00
|
|
|
*/
|
1999-09-17 16:17:21 +00:00
|
|
|
int snd_seq_connect_to(snd_seq_t *seq, int myport, int dest_client, int dest_port)
|
|
|
|
|
{
|
|
|
|
|
snd_seq_port_subscribe_t subs;
|
|
|
|
|
|
|
|
|
|
memset(&subs, 0, sizeof(subs));
|
|
|
|
|
/*subs.sender.client = seq->client;*/
|
|
|
|
|
subs.sender.client = snd_seq_client_id(seq);
|
|
|
|
|
subs.sender.port = myport;
|
|
|
|
|
subs.dest.client = dest_client;
|
|
|
|
|
subs.dest.port = dest_port;
|
|
|
|
|
|
|
|
|
|
return snd_seq_subscribe_port(seq, &subs);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
2001-07-04 13:54:13 +00:00
|
|
|
* \brief simple disconnection
|
2005-05-24 14:14:28 +00:00
|
|
|
* \param seq sequencer handle
|
2001-07-04 13:54:13 +00:00
|
|
|
* \param myport the port id as receiver
|
|
|
|
|
* \param src_client sender client id
|
|
|
|
|
* \param src_port sender port id
|
|
|
|
|
* \return 0 on success or negative error code
|
|
|
|
|
*
|
|
|
|
|
* Remove connection from the given sender client:port
|
|
|
|
|
* to the given destination port in the current client.
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
|
|
|
|
* \sa snd_seq_unsubscribe_port(), snd_seq_connect_from()
|
2001-06-06 17:50:16 +00:00
|
|
|
*/
|
1999-09-17 16:17:21 +00:00
|
|
|
int snd_seq_disconnect_from(snd_seq_t *seq, int myport, int src_client, int src_port)
|
|
|
|
|
{
|
|
|
|
|
snd_seq_port_subscribe_t subs;
|
|
|
|
|
|
|
|
|
|
memset(&subs, 0, sizeof(subs));
|
|
|
|
|
subs.sender.client = src_client;
|
|
|
|
|
subs.sender.port = src_port;
|
|
|
|
|
/*subs.dest.client = seq->client;*/
|
|
|
|
|
subs.dest.client = snd_seq_client_id(seq);
|
|
|
|
|
subs.dest.port = myport;
|
|
|
|
|
|
|
|
|
|
return snd_seq_unsubscribe_port(seq, &subs);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
2001-07-04 13:54:13 +00:00
|
|
|
* \brief simple disconnection
|
2005-05-24 14:14:28 +00:00
|
|
|
* \param seq sequencer handle
|
2001-07-04 13:54:13 +00:00
|
|
|
* \param myport the port id as sender
|
|
|
|
|
* \param dest_client destination client id
|
|
|
|
|
* \param dest_port destination port id
|
|
|
|
|
* \return 0 on success or negative error code
|
|
|
|
|
*
|
|
|
|
|
* Remove connection from the given sender client:port
|
|
|
|
|
* to the given destination port in the current client.
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
|
|
|
|
* \sa snd_seq_unsubscribe_port(), snd_seq_connect_to()
|
2001-06-06 17:50:16 +00:00
|
|
|
*/
|
1999-09-17 16:17:21 +00:00
|
|
|
int snd_seq_disconnect_to(snd_seq_t *seq, int myport, int dest_client, int dest_port)
|
|
|
|
|
{
|
|
|
|
|
snd_seq_port_subscribe_t subs;
|
|
|
|
|
|
|
|
|
|
memset(&subs, 0, sizeof(subs));
|
|
|
|
|
/*subs.sender.client = seq->client;*/
|
|
|
|
|
subs.sender.client = snd_seq_client_id(seq);
|
|
|
|
|
subs.sender.port = myport;
|
|
|
|
|
subs.dest.client = dest_client;
|
|
|
|
|
subs.dest.port = dest_port;
|
|
|
|
|
|
|
|
|
|
return snd_seq_unsubscribe_port(seq, &subs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* set client information
|
|
|
|
|
*/
|
2001-07-04 13:54:13 +00:00
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
|
|
|
|
* \brief set client name
|
2001-07-04 13:54:13 +00:00
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \param name name string
|
|
|
|
|
* \return 0 on success or negative error code
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
|
|
|
|
* \sa snd_seq_set_client_info()
|
2001-06-06 17:50:16 +00:00
|
|
|
*/
|
2001-02-11 15:45:35 +00:00
|
|
|
int snd_seq_set_client_name(snd_seq_t *seq, const char *name)
|
1999-09-17 16:17:21 +00:00
|
|
|
{
|
|
|
|
|
snd_seq_client_info_t info;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if ((err = snd_seq_get_client_info(seq, &info)) < 0)
|
|
|
|
|
return err;
|
|
|
|
|
strncpy(info.name, name, sizeof(info.name) - 1);
|
|
|
|
|
return snd_seq_set_client_info(seq, &info);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
2001-07-04 13:54:13 +00:00
|
|
|
* \brief add client event filter
|
|
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \param event_type event type to be added
|
|
|
|
|
* \return 0 on success or negative error code
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
|
|
|
|
* \sa snd_seq_set_client_info()
|
2001-06-06 17:50:16 +00:00
|
|
|
*/
|
1999-09-17 16:17:21 +00:00
|
|
|
int snd_seq_set_client_event_filter(snd_seq_t *seq, int event_type)
|
|
|
|
|
{
|
|
|
|
|
snd_seq_client_info_t info;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if ((err = snd_seq_get_client_info(seq, &info)) < 0)
|
|
|
|
|
return err;
|
2008-02-22 17:50:01 +01:00
|
|
|
snd_seq_client_info_event_filter_add(&info, event_type);
|
1999-09-17 16:17:21 +00:00
|
|
|
return snd_seq_set_client_info(seq, &info);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 15:49:44 +01:00
|
|
|
/**
|
|
|
|
|
* \brief set client MIDI protocol version
|
|
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \param midi_version MIDI protocol version to set
|
|
|
|
|
* \return 0 on success or negative error code
|
|
|
|
|
*
|
|
|
|
|
* \sa snd_seq_set_client_info()
|
|
|
|
|
*/
|
|
|
|
|
int snd_seq_set_client_midi_version(snd_seq_t *seq, int midi_version)
|
|
|
|
|
{
|
|
|
|
|
snd_seq_client_info_t info;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if ((err = snd_seq_get_client_info(seq, &info)) < 0)
|
|
|
|
|
return err;
|
|
|
|
|
snd_seq_client_info_set_midi_version(&info, midi_version);
|
|
|
|
|
return snd_seq_set_client_info(seq, &info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief enable/disable client's automatic conversion of UMP/legacy events
|
|
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \param enable 0 or 1 to disable/enable the conversion
|
|
|
|
|
* \return 0 on success or negative error code
|
|
|
|
|
*
|
|
|
|
|
* \sa snd_seq_set_client_info()
|
|
|
|
|
*/
|
|
|
|
|
int snd_seq_set_client_ump_conversion(snd_seq_t *seq, int enable)
|
|
|
|
|
{
|
|
|
|
|
snd_seq_client_info_t info;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if ((err = snd_seq_get_client_info(seq, &info)) < 0)
|
|
|
|
|
return err;
|
|
|
|
|
snd_seq_client_info_set_ump_conversion(&info, enable);
|
|
|
|
|
return snd_seq_set_client_info(seq, &info);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
|
|
|
|
* \brief change the output pool size of the given client
|
2001-07-04 13:54:13 +00:00
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \param size output pool size
|
|
|
|
|
* \return 0 on success or negative error code
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
|
|
|
|
* \sa snd_seq_set_client_pool()
|
2001-06-06 17:50:16 +00:00
|
|
|
*/
|
2001-07-04 13:54:13 +00:00
|
|
|
int snd_seq_set_client_pool_output(snd_seq_t *seq, size_t size)
|
1999-09-17 16:17:21 +00:00
|
|
|
{
|
|
|
|
|
snd_seq_client_pool_t info;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if ((err = snd_seq_get_client_pool(seq, &info)) < 0)
|
|
|
|
|
return err;
|
|
|
|
|
info.output_pool = size;
|
|
|
|
|
return snd_seq_set_client_pool(seq, &info);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
|
|
|
|
* \brief change the output room size of the given client
|
2001-07-04 13:54:13 +00:00
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \param size output room size
|
|
|
|
|
* \return 0 on success or negative error code
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
|
|
|
|
* \sa snd_seq_set_client_pool()
|
2001-06-06 17:50:16 +00:00
|
|
|
*/
|
2001-07-04 13:54:13 +00:00
|
|
|
int snd_seq_set_client_pool_output_room(snd_seq_t *seq, size_t size)
|
1999-09-17 16:17:21 +00:00
|
|
|
{
|
|
|
|
|
snd_seq_client_pool_t info;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if ((err = snd_seq_get_client_pool(seq, &info)) < 0)
|
|
|
|
|
return err;
|
|
|
|
|
info.output_room = size;
|
|
|
|
|
return snd_seq_set_client_pool(seq, &info);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
|
|
|
|
* \brief change the input pool size of the given client
|
2001-07-04 13:54:13 +00:00
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \param size input pool size
|
|
|
|
|
* \return 0 on success or negative error code
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
|
|
|
|
* \sa snd_seq_set_client_pool()
|
2001-06-06 17:50:16 +00:00
|
|
|
*/
|
2001-07-04 13:54:13 +00:00
|
|
|
int snd_seq_set_client_pool_input(snd_seq_t *seq, size_t size)
|
1999-09-17 16:17:21 +00:00
|
|
|
{
|
|
|
|
|
snd_seq_client_pool_t info;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if ((err = snd_seq_get_client_pool(seq, &info)) < 0)
|
|
|
|
|
return err;
|
|
|
|
|
info.input_pool = size;
|
|
|
|
|
return snd_seq_set_client_pool(seq, &info);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
|
|
|
|
* \brief reset client output pool
|
2001-07-04 13:54:13 +00:00
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \return 0 on success or negative error code
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
2009-02-22 07:54:10 -06:00
|
|
|
* So far, this works identically like #snd_seq_drop_output().
|
1999-09-17 16:17:21 +00:00
|
|
|
*/
|
|
|
|
|
int snd_seq_reset_pool_output(snd_seq_t *seq)
|
|
|
|
|
{
|
2003-10-22 14:25:55 +00:00
|
|
|
return snd_seq_drop_output(seq);
|
1999-09-17 16:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
2001-06-06 17:50:16 +00:00
|
|
|
/**
|
|
|
|
|
* \brief reset client input pool
|
2001-07-04 13:54:13 +00:00
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \return 0 on success or negative error code
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
2009-02-22 07:54:10 -06:00
|
|
|
* So far, this works identically like #snd_seq_drop_input().
|
2001-06-06 17:50:16 +00:00
|
|
|
*/
|
1999-09-17 16:17:21 +00:00
|
|
|
int snd_seq_reset_pool_input(snd_seq_t *seq)
|
|
|
|
|
{
|
2003-10-22 14:25:55 +00:00
|
|
|
return snd_seq_drop_input(seq);
|
1999-09-17 16:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
2001-09-03 10:41:18 +00:00
|
|
|
/**
|
2003-10-22 14:25:55 +00:00
|
|
|
* \brief wait until all events are processed
|
2001-09-03 10:41:18 +00:00
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \return 0 on success or negative error code
|
2003-10-22 14:25:55 +00:00
|
|
|
*
|
|
|
|
|
* This function waits until all events of this client are processed.
|
|
|
|
|
*
|
|
|
|
|
* \sa snd_seq_drain_output()
|
2001-09-03 10:41:18 +00:00
|
|
|
*/
|
|
|
|
|
int snd_seq_sync_output_queue(snd_seq_t *seq)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
snd_seq_client_pool_t info;
|
|
|
|
|
int saved_room;
|
|
|
|
|
struct pollfd pfd;
|
|
|
|
|
|
|
|
|
|
assert(seq);
|
|
|
|
|
/* reprogram the room size to full */
|
|
|
|
|
if ((err = snd_seq_get_client_pool(seq, &info)) < 0)
|
|
|
|
|
return err;
|
|
|
|
|
saved_room = info.output_room;
|
|
|
|
|
info.output_room = info.output_pool; /* wait until all gone */
|
|
|
|
|
if ((err = snd_seq_set_client_pool(seq, &info)) < 0)
|
|
|
|
|
return err;
|
|
|
|
|
/* wait until all events are purged */
|
|
|
|
|
pfd.fd = seq->poll_fd;
|
|
|
|
|
pfd.events = POLLOUT;
|
|
|
|
|
err = poll(&pfd, 1, -1);
|
|
|
|
|
/* restore the room size */
|
|
|
|
|
info.output_room = saved_room;
|
|
|
|
|
snd_seq_set_client_pool(seq, &info);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-04 13:54:13 +00:00
|
|
|
/**
|
|
|
|
|
* \brief parse the given string and get the sequencer address
|
|
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \param addr the address pointer to be returned
|
|
|
|
|
* \param arg the string to be parsed
|
|
|
|
|
* \return 0 on success or negative error code
|
2001-09-03 10:41:18 +00:00
|
|
|
*
|
|
|
|
|
* This function parses the sequencer client and port numbers from the given string.
|
2012-03-14 18:45:02 +01:00
|
|
|
* The client and port tokens are separated by either colon or period, e.g. 128:1.
|
2001-09-03 10:41:18 +00:00
|
|
|
* When \a seq is not NULL, the function accepts also a client name not only
|
|
|
|
|
* digit numbers.
|
2012-03-14 18:45:02 +01:00
|
|
|
* Actually \a arg need to be only a prefix of the wanted client.
|
|
|
|
|
* That is, if a client named "Foobar XXL Master 2012" with number 128 is available,
|
2013-05-13 21:16:36 +02:00
|
|
|
* then parsing "Foobar" will return the address 128:0 if no other client is
|
|
|
|
|
* an exact match.
|
2001-07-04 13:54:13 +00:00
|
|
|
*/
|
|
|
|
|
int snd_seq_parse_address(snd_seq_t *seq, snd_seq_addr_t *addr, const char *arg)
|
|
|
|
|
{
|
2021-05-26 17:28:53 +02:00
|
|
|
char *p, *buf;
|
|
|
|
|
const char *s;
|
|
|
|
|
char c;
|
|
|
|
|
long client, port = 0;
|
2001-07-11 14:18:38 +00:00
|
|
|
int len;
|
2001-07-04 13:54:13 +00:00
|
|
|
|
2001-09-03 10:41:18 +00:00
|
|
|
assert(addr && arg);
|
2001-07-04 13:54:13 +00:00
|
|
|
|
2021-05-26 17:28:53 +02:00
|
|
|
c = *arg;
|
|
|
|
|
if (c == '"' || c == '\'') {
|
|
|
|
|
s = ++arg;
|
|
|
|
|
while (*s && *s != c) s++;
|
|
|
|
|
len = s - arg;
|
|
|
|
|
if (*s)
|
|
|
|
|
s++;
|
|
|
|
|
if (*s) {
|
|
|
|
|
if (*s != '.' && *s != ':')
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if ((port = atoi(s + 1)) < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2001-07-11 14:18:38 +00:00
|
|
|
} else {
|
2021-05-26 17:28:53 +02:00
|
|
|
if ((p = strpbrk(arg, ":.")) != NULL) {
|
|
|
|
|
if ((port = atoi(p + 1)) < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
len = (int)(p - arg); /* length of client name */
|
|
|
|
|
} else {
|
|
|
|
|
len = strlen(arg);
|
|
|
|
|
}
|
2001-07-11 14:18:38 +00:00
|
|
|
}
|
2021-05-26 17:28:53 +02:00
|
|
|
if (len == 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
buf = alloca(len + 1);
|
|
|
|
|
strncpy(buf, arg, len);
|
|
|
|
|
buf[len] = '\0';
|
2001-07-04 13:54:13 +00:00
|
|
|
addr->port = port;
|
2021-05-26 17:28:53 +02:00
|
|
|
if (safe_strtol(buf, &client) == 0) {
|
2001-07-04 13:54:13 +00:00
|
|
|
addr->client = client;
|
|
|
|
|
} else {
|
|
|
|
|
/* convert from the name */
|
|
|
|
|
snd_seq_client_info_t cinfo;
|
|
|
|
|
|
2001-09-03 10:41:18 +00:00
|
|
|
if (! seq)
|
|
|
|
|
return -EINVAL;
|
2001-07-04 13:54:13 +00:00
|
|
|
if (len <= 0)
|
|
|
|
|
return -EINVAL;
|
2013-05-13 21:16:36 +02:00
|
|
|
client = -1;
|
2001-07-04 13:54:13 +00:00
|
|
|
cinfo.client = -1;
|
|
|
|
|
while (snd_seq_query_next_client(seq, &cinfo) >= 0) {
|
2013-05-13 21:16:36 +02:00
|
|
|
if (!strncmp(arg, cinfo.name, len)) {
|
|
|
|
|
if (strlen(cinfo.name) == (size_t)len) {
|
|
|
|
|
/* exact match */
|
|
|
|
|
addr->client = cinfo.client;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (client < 0)
|
|
|
|
|
client = cinfo.client;
|
2001-07-04 13:54:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-05-13 21:16:36 +02:00
|
|
|
if (client >= 0) {
|
|
|
|
|
/* prefix match */
|
|
|
|
|
addr->client = client;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-07-04 13:54:13 +00:00
|
|
|
return -ENOENT; /* not found */
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-19 14:35:36 +02:00
|
|
|
/**
|
|
|
|
|
* \brief create a UMP Endpoint for the given sequencer client
|
|
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \param info UMP Endpoint information to initialize
|
|
|
|
|
* \param num_groups max number of groups in the endpoint
|
|
|
|
|
* \return 0 on success or negative error code
|
|
|
|
|
*
|
|
|
|
|
* This function initializes the sequencer client to the corresponding
|
|
|
|
|
* MIDI 2.0 mode (either MIDI 1.0 or MIDI 2.0 protocol) depending on the
|
|
|
|
|
* given snd_ump_endpoint_info_t info.
|
|
|
|
|
*
|
|
|
|
|
* This function should be called right after opening a sequencer client.
|
|
|
|
|
* The client name is updated from the UMP Endpoint name, and a primary
|
|
|
|
|
* MIDI 2.0 UMP port and each UMP Group port are created.
|
|
|
|
|
* The application should pass each UMP block info via succeeding
|
|
|
|
|
* snd_seq_create_ump_block() call.
|
|
|
|
|
*/
|
|
|
|
|
int snd_seq_create_ump_endpoint(snd_seq_t *seq,
|
|
|
|
|
const snd_ump_endpoint_info_t *info,
|
|
|
|
|
unsigned int num_groups)
|
|
|
|
|
{
|
|
|
|
|
int err, version;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
snd_seq_port_info_t *pinfo;
|
|
|
|
|
|
|
|
|
|
if (seq->ump_ep)
|
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
|
|
if (num_groups < 1 || num_groups > SND_UMP_MAX_GROUPS)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
if (!(info->protocol_caps & info->protocol)) {
|
|
|
|
|
SNDERR("Inconsistent UMP protocol_caps and protocol\n");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info->protocol & SND_UMP_EP_INFO_PROTO_MIDI2) {
|
|
|
|
|
version = SND_SEQ_CLIENT_UMP_MIDI_2_0;
|
|
|
|
|
} else if (info->protocol & SND_UMP_EP_INFO_PROTO_MIDI1) {
|
|
|
|
|
version = SND_SEQ_CLIENT_UMP_MIDI_1_0;
|
|
|
|
|
} else {
|
|
|
|
|
SNDERR("Invalid UMP protocol set 0x%x\n", info->protocol);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = snd_seq_set_client_midi_version(seq, version);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
SNDERR("Failed to set to MIDI protocol 0x%x\n", version);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
seq->ump_ep = malloc(sizeof(*info));
|
|
|
|
|
if (!seq->ump_ep)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
*seq->ump_ep = *info;
|
|
|
|
|
if (!seq->ump_ep->version)
|
|
|
|
|
seq->ump_ep->version = SND_UMP_EP_INFO_DEFAULT_VERSION;
|
|
|
|
|
|
2025-02-02 22:26:39 +01:00
|
|
|
if (info->name[0]) {
|
2024-06-19 14:35:36 +02:00
|
|
|
err = snd_seq_set_client_name(seq, (const char *)info->name);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
goto error_free;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = snd_seq_set_ump_endpoint_info(seq, seq->ump_ep);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
SNDERR("Failed to set UMP EP info\n");
|
|
|
|
|
goto error_free;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
snd_seq_port_info_alloca(&pinfo);
|
|
|
|
|
|
|
|
|
|
snd_seq_port_info_set_port(pinfo, 0);
|
|
|
|
|
snd_seq_port_info_set_port_specified(pinfo, 1);
|
|
|
|
|
snd_seq_port_info_set_name(pinfo, "MIDI 2.0");
|
|
|
|
|
snd_seq_port_info_set_capability(pinfo,
|
2025-04-01 07:59:40 +02:00
|
|
|
SND_SEQ_PORT_CAP_UMP_ENDPOINT |
|
2025-04-01 08:02:51 +02:00
|
|
|
SND_SEQ_PORT_CAP_READ |
|
|
|
|
|
SND_SEQ_PORT_CAP_SYNC_READ |
|
|
|
|
|
SND_SEQ_PORT_CAP_SUBS_READ |
|
|
|
|
|
SND_SEQ_PORT_CAP_WRITE |
|
|
|
|
|
SND_SEQ_PORT_CAP_SYNC_WRITE |
|
|
|
|
|
SND_SEQ_PORT_CAP_SUBS_WRITE |
|
|
|
|
|
SND_SEQ_PORT_CAP_DUPLEX);
|
2024-06-19 14:35:36 +02:00
|
|
|
snd_seq_port_info_set_type(pinfo,
|
|
|
|
|
SND_SEQ_PORT_TYPE_MIDI_GENERIC |
|
2025-04-01 08:02:51 +02:00
|
|
|
SND_SEQ_PORT_TYPE_MIDI_UMP |
|
2024-06-19 14:35:36 +02:00
|
|
|
SND_SEQ_PORT_TYPE_APPLICATION |
|
2025-04-01 08:02:51 +02:00
|
|
|
SND_SEQ_PORT_TYPE_PORT);
|
2025-03-01 11:00:15 +01:00
|
|
|
snd_seq_port_info_set_ump_group(pinfo, 0);
|
2024-06-19 14:35:36 +02:00
|
|
|
err = snd_seq_create_port(seq, pinfo);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
SNDERR("Failed to create MIDI 2.0 port\n");
|
|
|
|
|
goto error_free;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < num_groups; i++) {
|
|
|
|
|
char name[32];
|
|
|
|
|
|
|
|
|
|
snd_seq_port_info_set_port(pinfo, i + 1);
|
|
|
|
|
snd_seq_port_info_set_port_specified(pinfo, 1);
|
|
|
|
|
sprintf(name, "Group %d", i + 1);
|
|
|
|
|
snd_seq_port_info_set_capability(pinfo, 0); /* set later */
|
|
|
|
|
snd_seq_port_info_set_name(pinfo, name);
|
|
|
|
|
snd_seq_port_info_set_ump_group(pinfo, i + 1);
|
|
|
|
|
err = snd_seq_create_port(seq, pinfo);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
SNDERR("Failed to create Group port %d\n", i + 1);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
seq->num_ump_groups = num_groups;
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
/* delete all ports including port 0 */
|
|
|
|
|
for (i = 0; i <= num_groups; i++)
|
|
|
|
|
snd_seq_delete_port(seq, i);
|
|
|
|
|
error_free:
|
|
|
|
|
free(seq->ump_ep);
|
|
|
|
|
seq->ump_ep = NULL;
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* update each port name and capability from the block list */
|
|
|
|
|
static void update_group_ports(snd_seq_t *seq, snd_ump_endpoint_info_t *ep)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i, b;
|
|
|
|
|
snd_seq_port_info_t *pinfo;
|
|
|
|
|
snd_ump_block_info_t *bp;
|
|
|
|
|
|
|
|
|
|
snd_seq_port_info_alloca(&pinfo);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < seq->num_ump_groups; i++) {
|
|
|
|
|
char blknames[64];
|
|
|
|
|
char name[64];
|
|
|
|
|
unsigned int caps = 0;
|
2024-07-31 11:14:08 +02:00
|
|
|
int len;
|
2024-06-19 14:35:36 +02:00
|
|
|
|
|
|
|
|
blknames[0] = 0;
|
|
|
|
|
for (b = 0; b < ep->num_blocks; b++) {
|
|
|
|
|
bp = seq->ump_blks[b];
|
|
|
|
|
if (!bp)
|
|
|
|
|
continue;
|
|
|
|
|
if (i < bp->first_group ||
|
|
|
|
|
i >= bp->first_group + bp->num_groups)
|
|
|
|
|
continue;
|
|
|
|
|
switch (bp->direction) {
|
2025-04-01 08:02:51 +02:00
|
|
|
case SND_UMP_DIR_INPUT: /* sink, receiver */
|
|
|
|
|
caps |= SND_SEQ_PORT_CAP_WRITE |
|
|
|
|
|
SND_SEQ_PORT_CAP_SYNC_WRITE |
|
|
|
|
|
SND_SEQ_PORT_CAP_SUBS_WRITE;
|
2024-06-19 14:35:36 +02:00
|
|
|
break;
|
2025-04-01 08:02:51 +02:00
|
|
|
case SND_UMP_DIR_OUTPUT: /* source, transmitter */
|
|
|
|
|
caps |= SND_SEQ_PORT_CAP_READ |
|
|
|
|
|
SND_SEQ_PORT_CAP_SYNC_READ |
|
|
|
|
|
SND_SEQ_PORT_CAP_SUBS_READ;
|
2024-07-09 07:23:23 +02:00
|
|
|
break;
|
2025-04-01 08:02:51 +02:00
|
|
|
case SND_UMP_DIR_BIDIRECTION:
|
|
|
|
|
caps |= SND_SEQ_PORT_CAP_READ |
|
|
|
|
|
SND_SEQ_PORT_CAP_SYNC_READ |
|
|
|
|
|
SND_SEQ_PORT_CAP_SUBS_READ |
|
|
|
|
|
SND_SEQ_PORT_CAP_WRITE |
|
|
|
|
|
SND_SEQ_PORT_CAP_SYNC_WRITE |
|
|
|
|
|
SND_SEQ_PORT_CAP_SUBS_WRITE |
|
|
|
|
|
SND_SEQ_PORT_CAP_DUPLEX;
|
2024-06-19 14:35:36 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!*bp->name)
|
|
|
|
|
continue;
|
2024-07-31 11:14:08 +02:00
|
|
|
len = strlen(blknames);
|
|
|
|
|
if (len)
|
|
|
|
|
snprintf(blknames + len, sizeof(blknames) - len,
|
|
|
|
|
", %s", bp->name);
|
|
|
|
|
else
|
2024-06-19 14:35:36 +02:00
|
|
|
snd_strlcpy(blknames, (const char *)bp->name,
|
|
|
|
|
sizeof(blknames));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!*blknames)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "Group %d (%s)", i + 1, blknames);
|
|
|
|
|
if (snd_seq_get_port_info(seq, i + 1, pinfo) < 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (strcmp(name, snd_seq_port_info_get_name(pinfo)) ||
|
|
|
|
|
snd_seq_port_info_get_capability(pinfo) != caps) {
|
|
|
|
|
snd_seq_port_info_set_name(pinfo, name);
|
|
|
|
|
snd_seq_port_info_set_capability(pinfo, caps);
|
|
|
|
|
snd_seq_set_port_info(seq, i + 1, pinfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief create a UMP block for the given sequencer client
|
|
|
|
|
* \param seq sequencer handle
|
|
|
|
|
* \param blkid 0-based block id
|
|
|
|
|
* \param info UMP block info to initialize
|
|
|
|
|
* \return 0 on success or negative error code
|
|
|
|
|
*
|
|
|
|
|
* This function sets up the UMP block info of the given block id.
|
|
|
|
|
* The sequencer port name is updated accordingly with the associated
|
|
|
|
|
* block name automatically.
|
|
|
|
|
*/
|
|
|
|
|
int snd_seq_create_ump_block(snd_seq_t *seq, int blkid,
|
|
|
|
|
const snd_ump_block_info_t *info)
|
|
|
|
|
{
|
|
|
|
|
snd_ump_block_info_t *bp;
|
|
|
|
|
snd_ump_endpoint_info_t *ep = seq->ump_ep;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if (!ep)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (info->first_group >= seq->num_ump_groups ||
|
|
|
|
|
info->first_group + info->num_groups > seq->num_ump_groups)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (blkid < 0 || blkid >= (int)ep->num_blocks)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
if (seq->ump_blks[blkid])
|
|
|
|
|
return -EBUSY;
|
|
|
|
|
seq->ump_blks[blkid] = bp = malloc(sizeof(*info));
|
|
|
|
|
if (!bp)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
*bp = *info;
|
|
|
|
|
|
|
|
|
|
if (!bp->midi_ci_version)
|
|
|
|
|
bp->midi_ci_version = SND_UMP_BLOCK_INFO_DEFAULT_MIDI_CI_VERSION;
|
|
|
|
|
bp->active = 1;
|
|
|
|
|
|
|
|
|
|
err = snd_seq_set_ump_block_info(seq, blkid, bp);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
SNDERR("Failed to set UMP EP info\n");
|
|
|
|
|
free(bp);
|
|
|
|
|
seq->ump_blks[blkid] = NULL;
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update_group_ports(seq, ep);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|