Exemplo n.º 1
0
/* exported to seq_info.c */
void snd_seq_info_queues_read(struct snd_info_entry *entry, 
                  struct snd_info_buffer *buffer)
{
    int i, bpm;
    struct snd_seq_queue *q;
    struct snd_seq_timer *tmr;

    for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
        if ((q = queueptr(i)) == NULL)
            continue;

        tmr = q->timer;
        if (tmr->tempo)
            bpm = 60000000 / tmr->tempo;
        else
            bpm = 0;

        snd_iprintf(buffer, "queue %d: [%s]\n", q->queue, q->name);
        snd_iprintf(buffer, "owned by client    : %d\n", q->owner);
        snd_iprintf(buffer, "lock status        : %s\n", q->locked ? "Locked" : "Free");
        snd_iprintf(buffer, "queued time events : %d\n", snd_seq_prioq_avail(q->timeq));
        snd_iprintf(buffer, "queued tick events : %d\n", snd_seq_prioq_avail(q->tickq));
        snd_iprintf(buffer, "timer state        : %s\n", tmr->running ? "Running" : "Stopped");
        snd_iprintf(buffer, "timer PPQ          : %d\n", tmr->ppq);
        snd_iprintf(buffer, "current tempo      : %d\n", tmr->tempo);
        snd_iprintf(buffer, "current BPM        : %d\n", bpm);
        snd_iprintf(buffer, "current time       : %d.%09d s\n", tmr->cur_time.tv_sec, tmr->cur_time.tv_nsec);
        snd_iprintf(buffer, "current tick       : %d\n", tmr->tick.cur_tick);
        snd_iprintf(buffer, "\n");
        queuefree(q);
    }
}
Exemplo n.º 2
0
/* final stage notification -
 * remove cells for no longer exist client (for non-owned queue)
 * or delete this queue (for owned queue)
 */
void snd_seq_queue_client_leave(int client)
{
    int i;
    struct snd_seq_queue *q;

    /* delete own queues from queue list */
    for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
        if ((q = queue_list_remove(i, client)) != NULL)
            queue_delete(q);
    }

    /* remove cells from existing queues -
     * they are not owned by this client
     */
    for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
        if ((q = queueptr(i)) == NULL)
            continue;
        if (test_bit(client, q->clients_bitmap)) {
            snd_seq_prioq_leave(q->tickq, client, 0);
            snd_seq_prioq_leave(q->timeq, client, 0);
            snd_seq_queue_use(q->queue, client, 0);
        }
        queuefree(q);
    }
}
Exemplo n.º 3
0
/* use or unuse this queue -
 * if it is the first client, starts the timer.
 * if it is not longer used by any clients, stop the timer.
 */
int snd_seq_queue_use(int queueid, int client, int use)
{
    struct snd_seq_queue *queue;

    queue = queueptr(queueid);
    if (queue == NULL)
        return -EINVAL;
    mutex_lock(&queue->timer_mutex);
    if (use) {
        if (!test_and_set_bit(client, queue->clients_bitmap))
            queue->clients++;
    } else {
        if (test_and_clear_bit(client, queue->clients_bitmap))
            queue->clients--;
    }
    if (queue->clients) {
        if (use && queue->clients == 1)
            snd_seq_timer_defaults(queue->timer);
        snd_seq_timer_open(queue);
    } else {
        snd_seq_timer_close(queue);
    }
    mutex_unlock(&queue->timer_mutex);
    queuefree(queue);
    return 0;
}
Exemplo n.º 4
0
/*
 * check if queue is used by the client
 * return negative value if the queue is invalid.
 * return 0 if not used, 1 if used.
 */
int snd_seq_queue_is_used(int queueid, int client)
{
    struct snd_seq_queue *q;
    int result;

    q = queueptr(queueid);
    if (q == NULL)
        return -EINVAL; /* invalid queue */
    result = test_bit(client, q->clients_bitmap) ? 1 : 0;
    queuefree(q);
    return result;
}
Exemplo n.º 5
0
/* close timer -
 * q->use mutex should be down before calling this function
 */
int snd_seq_queue_timer_close(int queueid)
{
	struct snd_seq_queue *queue;
	int result = 0;

	queue = queueptr(queueid);
	if (queue == NULL)
		return -EINVAL;
	snd_seq_timer_close(queue);
	queuefree(queue);
	return result;
}
Exemplo n.º 6
0
/* remove cells from all queues */
void snd_seq_queue_client_leave_cells(int client)
{
    int i;
    struct snd_seq_queue *q;

    for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
        if ((q = queueptr(i)) == NULL)
            continue;
        snd_seq_prioq_leave(q->tickq, client, 0);
        snd_seq_prioq_leave(q->timeq, client, 0);
        queuefree(q);
    }
}
Exemplo n.º 7
0
/* exported - only checking permission */
int snd_seq_queue_check_access(int queueid, int client)
{
    struct snd_seq_queue *q = queueptr(queueid);
    int access_ok;
    unsigned long flags;

    if (! q)
        return 0;
    spin_lock_irqsave(&q->owner_lock, flags);
    access_ok = check_access(q, client);
    spin_unlock_irqrestore(&q->owner_lock, flags);
    queuefree(q);
    return access_ok;
}
Exemplo n.º 8
0
/* return the (first) queue matching with the specified name */
struct snd_seq_queue *snd_seq_queue_find_name(char *name)
{
    int i;
    struct snd_seq_queue *q;

    for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
        if ((q = queueptr(i)) != NULL) {
            if (strncmp(q->name, name, sizeof(q->name)) == 0)
                return q;
            queuefree(q);
        }
    }
    return NULL;
}
Exemplo n.º 9
0
/* enqueue a event to singe queue */
int snd_seq_enqueue_event(struct snd_seq_event_cell *cell, int atomic, int hop)
{
	int dest, err;
	struct snd_seq_queue *q;

	if (snd_BUG_ON(!cell))
		return -EINVAL;
	dest = cell->event.queue;	/* destination queue */
	q = queueptr(dest);
	if (q == NULL)
		return -EINVAL;
	/* handle relative time stamps, convert them into absolute */
	if ((cell->event.flags & SNDRV_SEQ_TIME_MODE_MASK) == SNDRV_SEQ_TIME_MODE_REL) {
		switch (cell->event.flags & SNDRV_SEQ_TIME_STAMP_MASK) {
		case SNDRV_SEQ_TIME_STAMP_TICK:
			cell->event.time.tick += q->timer->tick.cur_tick;
			break;

		case SNDRV_SEQ_TIME_STAMP_REAL:
			snd_seq_inc_real_time(&cell->event.time.time,
					      &q->timer->cur_time);
			break;
		}
		cell->event.flags &= ~SNDRV_SEQ_TIME_MODE_MASK;
		cell->event.flags |= SNDRV_SEQ_TIME_MODE_ABS;
	}
	/* enqueue event in the real-time or midi queue */
	switch (cell->event.flags & SNDRV_SEQ_TIME_STAMP_MASK) {
	case SNDRV_SEQ_TIME_STAMP_TICK:
		err = snd_seq_prioq_cell_in(q->tickq, cell);
		break;

	case SNDRV_SEQ_TIME_STAMP_REAL:
	default:
		err = snd_seq_prioq_cell_in(q->timeq, cell);
		break;
	}

	if (err < 0) {
		queuefree(q); /* unlock */
		return err;
	}

	/* trigger dispatching */
	snd_seq_check_queue(q, atomic, hop);

	queuefree(q); /* unlock */

	return 0;
}
Exemplo n.º 10
0
/* close timer -
 * q->use mutex should be down before calling this function
 */
int snd_seq_queue_timer_close(int queueid)
{
	queue_t *queue;
	seq_timer_t *tmr;
	int result = 0;

	queue = queueptr(queueid);
	if (queue == NULL)
		return -EINVAL;
	tmr = queue->timer;
	snd_seq_timer_close(queue);
	queuefree(queue);
	return result;
}
Exemplo n.º 11
0
/* remove cells based on flush criteria */
void snd_seq_queue_remove_cells(int client, struct snd_seq_remove_events *info)
{
    int i;
    struct snd_seq_queue *q;

    for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
        if ((q = queueptr(i)) == NULL)
            continue;
        if (test_bit(client, q->clients_bitmap) &&
            (! (info->remove_mode & SNDRV_SEQ_REMOVE_DEST) ||
             q->queue == info->queue)) {
            snd_seq_prioq_remove_events(q->tickq, client, info);
            snd_seq_prioq_remove_events(q->timeq, client, info);
        }
        queuefree(q);
    }
}
Exemplo n.º 12
0
/* open timer -
 * q->use mutex should be down before calling this function to avoid
 * confliction with snd_seq_queue_use()
 */
int snd_seq_queue_timer_open(int queueid)
{
    int result = 0;
    struct snd_seq_queue *queue;
    struct snd_seq_timer *tmr;

    queue = queueptr(queueid);
    if (queue == NULL)
        return -EINVAL;
    tmr = queue->timer;
    if ((result = snd_seq_timer_open(queue)) < 0) {
        snd_seq_timer_defaults(tmr);
        result = snd_seq_timer_open(queue);
    }
    queuefree(queue);
    return result;
}
Exemplo n.º 13
0
/*
 * change queue's owner and permission
 */
int snd_seq_queue_set_owner(int queueid, int client, int locked)
{
    struct snd_seq_queue *q = queueptr(queueid);

    if (q == NULL)
        return -EINVAL;

    if (! queue_access_lock(q, client)) {
        queuefree(q);
        return -EPERM;
    }

    q->locked = locked ? 1 : 0;
    q->owner = client;
    queue_access_unlock(q);
    queuefree(q);

    return 0;
}
Exemplo n.º 14
0
/*
 * Queue control via timer control port:
 * this function is exported as a callback of timer port.
 */
int snd_seq_control_queue(struct snd_seq_event *ev, int atomic, int hop)
{
    struct snd_seq_queue *q;

    snd_assert(ev != NULL, return -EINVAL);
    q = queueptr(ev->data.queue.queue);

    if (q == NULL)
        return -EINVAL;

    if (! queue_access_lock(q, ev->source.client)) {
        queuefree(q);
        return -EPERM;
    }

    snd_seq_queue_process_event(q, ev, atomic, hop);

    queue_access_unlock(q);
    queuefree(q);
    return 0;
}
Exemplo n.º 15
0
/* notification that client has left the system -
 * stop the timer on all queues owned by this client
 */
void snd_seq_queue_client_termination(int client)
{
    unsigned long flags;
    int i;
    struct snd_seq_queue *q;

    for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
        if ((q = queueptr(i)) == NULL)
            continue;
        spin_lock_irqsave(&q->owner_lock, flags);
        if (q->owner == client)
            q->klocked = 1;
        spin_unlock_irqrestore(&q->owner_lock, flags);
        if (q->owner == client) {
            if (q->timer->running)
                snd_seq_timer_stop(q->timer);
            snd_seq_timer_reset(q->timer);
        }
        queuefree(q);
    }
}
Exemplo n.º 16
0
/* change queue tempo and ppq */
int snd_seq_queue_timer_set_tempo(int queueid, int client, snd_seq_queue_tempo_t *info)
{
	queue_t *q = queueptr(queueid);
	int result;

	if (q == NULL)
		return -EINVAL;
	if (! queue_access_lock(q, client)) {
		queuefree(q);
		return -EPERM;
	}

	result = snd_seq_timer_set_tempo(q->timer, info->tempo);
	if (result >= 0)
		result = snd_seq_timer_set_ppq(q->timer, info->ppq);
	if (result >= 0 && info->skew_base > 0)
		result = snd_seq_timer_set_skew(q->timer, info->skew_value, info->skew_base);
	queue_access_unlock(q);
	queuefree(q);
	return result;
}