seq_queue.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /*
  2. * ALSA sequencer Timing queue handling
  3. * Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. * MAJOR CHANGES
  20. * Nov. 13, 1999 Takashi Iwai <iwai@ww.uni-erlangen.de>
  21. * - Queues are allocated dynamically via ioctl.
  22. * - When owner client is deleted, all owned queues are deleted, too.
  23. * - Owner of unlocked queue is kept unmodified even if it is
  24. * manipulated by other clients.
  25. * - Owner field in SET_QUEUE_OWNER ioctl must be identical with the
  26. * caller client. i.e. Changing owner to a third client is not
  27. * allowed.
  28. *
  29. * Aug. 30, 2000 Takashi Iwai
  30. * - Queues are managed in static array again, but with better way.
  31. * The API itself is identical.
  32. * - The queue is locked when queue_t pinter is returned via
  33. * queueptr(). This pointer *MUST* be released afterward by
  34. * queuefree(ptr).
  35. * - Addition of experimental sync support.
  36. */
  37. #include <sound/driver.h>
  38. #include <linux/init.h>
  39. #include <linux/slab.h>
  40. #include <sound/core.h>
  41. #include "seq_memory.h"
  42. #include "seq_queue.h"
  43. #include "seq_clientmgr.h"
  44. #include "seq_fifo.h"
  45. #include "seq_timer.h"
  46. #include "seq_info.h"
  47. /* list of allocated queues */
  48. static queue_t *queue_list[SNDRV_SEQ_MAX_QUEUES];
  49. static DEFINE_SPINLOCK(queue_list_lock);
  50. /* number of queues allocated */
  51. static int num_queues;
  52. int snd_seq_queue_get_cur_queues(void)
  53. {
  54. return num_queues;
  55. }
  56. /*----------------------------------------------------------------*/
  57. /* assign queue id and insert to list */
  58. static int queue_list_add(queue_t *q)
  59. {
  60. int i;
  61. unsigned long flags;
  62. spin_lock_irqsave(&queue_list_lock, flags);
  63. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  64. if (! queue_list[i]) {
  65. queue_list[i] = q;
  66. q->queue = i;
  67. num_queues++;
  68. spin_unlock_irqrestore(&queue_list_lock, flags);
  69. return i;
  70. }
  71. }
  72. spin_unlock_irqrestore(&queue_list_lock, flags);
  73. return -1;
  74. }
  75. static queue_t *queue_list_remove(int id, int client)
  76. {
  77. queue_t *q;
  78. unsigned long flags;
  79. spin_lock_irqsave(&queue_list_lock, flags);
  80. q = queue_list[id];
  81. if (q) {
  82. spin_lock(&q->owner_lock);
  83. if (q->owner == client) {
  84. /* found */
  85. q->klocked = 1;
  86. spin_unlock(&q->owner_lock);
  87. queue_list[id] = NULL;
  88. num_queues--;
  89. spin_unlock_irqrestore(&queue_list_lock, flags);
  90. return q;
  91. }
  92. spin_unlock(&q->owner_lock);
  93. }
  94. spin_unlock_irqrestore(&queue_list_lock, flags);
  95. return NULL;
  96. }
  97. /*----------------------------------------------------------------*/
  98. /* create new queue (constructor) */
  99. static queue_t *queue_new(int owner, int locked)
  100. {
  101. queue_t *q;
  102. q = kcalloc(1, sizeof(*q), GFP_KERNEL);
  103. if (q == NULL) {
  104. snd_printd("malloc failed for snd_seq_queue_new()\n");
  105. return NULL;
  106. }
  107. spin_lock_init(&q->owner_lock);
  108. spin_lock_init(&q->check_lock);
  109. init_MUTEX(&q->timer_mutex);
  110. snd_use_lock_init(&q->use_lock);
  111. q->queue = -1;
  112. q->tickq = snd_seq_prioq_new();
  113. q->timeq = snd_seq_prioq_new();
  114. q->timer = snd_seq_timer_new();
  115. if (q->tickq == NULL || q->timeq == NULL || q->timer == NULL) {
  116. snd_seq_prioq_delete(&q->tickq);
  117. snd_seq_prioq_delete(&q->timeq);
  118. snd_seq_timer_delete(&q->timer);
  119. kfree(q);
  120. return NULL;
  121. }
  122. q->owner = owner;
  123. q->locked = locked;
  124. q->klocked = 0;
  125. return q;
  126. }
  127. /* delete queue (destructor) */
  128. static void queue_delete(queue_t *q)
  129. {
  130. /* stop and release the timer */
  131. snd_seq_timer_stop(q->timer);
  132. snd_seq_timer_close(q);
  133. /* wait until access free */
  134. snd_use_lock_sync(&q->use_lock);
  135. /* release resources... */
  136. snd_seq_prioq_delete(&q->tickq);
  137. snd_seq_prioq_delete(&q->timeq);
  138. snd_seq_timer_delete(&q->timer);
  139. kfree(q);
  140. }
  141. /*----------------------------------------------------------------*/
  142. /* setup queues */
  143. int __init snd_seq_queues_init(void)
  144. {
  145. /*
  146. memset(queue_list, 0, sizeof(queue_list));
  147. num_queues = 0;
  148. */
  149. return 0;
  150. }
  151. /* delete all existing queues */
  152. void __exit snd_seq_queues_delete(void)
  153. {
  154. int i;
  155. /* clear list */
  156. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  157. if (queue_list[i])
  158. queue_delete(queue_list[i]);
  159. }
  160. }
  161. /* allocate a new queue -
  162. * return queue index value or negative value for error
  163. */
  164. int snd_seq_queue_alloc(int client, int locked, unsigned int info_flags)
  165. {
  166. queue_t *q;
  167. q = queue_new(client, locked);
  168. if (q == NULL)
  169. return -ENOMEM;
  170. q->info_flags = info_flags;
  171. if (queue_list_add(q) < 0) {
  172. queue_delete(q);
  173. return -ENOMEM;
  174. }
  175. snd_seq_queue_use(q->queue, client, 1); /* use this queue */
  176. return q->queue;
  177. }
  178. /* delete a queue - queue must be owned by the client */
  179. int snd_seq_queue_delete(int client, int queueid)
  180. {
  181. queue_t *q;
  182. if (queueid < 0 || queueid >= SNDRV_SEQ_MAX_QUEUES)
  183. return -EINVAL;
  184. q = queue_list_remove(queueid, client);
  185. if (q == NULL)
  186. return -EINVAL;
  187. queue_delete(q);
  188. return 0;
  189. }
  190. /* return pointer to queue structure for specified id */
  191. queue_t *queueptr(int queueid)
  192. {
  193. queue_t *q;
  194. unsigned long flags;
  195. if (queueid < 0 || queueid >= SNDRV_SEQ_MAX_QUEUES)
  196. return NULL;
  197. spin_lock_irqsave(&queue_list_lock, flags);
  198. q = queue_list[queueid];
  199. if (q)
  200. snd_use_lock_use(&q->use_lock);
  201. spin_unlock_irqrestore(&queue_list_lock, flags);
  202. return q;
  203. }
  204. /* return the (first) queue matching with the specified name */
  205. queue_t *snd_seq_queue_find_name(char *name)
  206. {
  207. int i;
  208. queue_t *q;
  209. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  210. if ((q = queueptr(i)) != NULL) {
  211. if (strncmp(q->name, name, sizeof(q->name)) == 0)
  212. return q;
  213. queuefree(q);
  214. }
  215. }
  216. return NULL;
  217. }
  218. /* -------------------------------------------------------- */
  219. void snd_seq_check_queue(queue_t *q, int atomic, int hop)
  220. {
  221. unsigned long flags;
  222. snd_seq_event_cell_t *cell;
  223. if (q == NULL)
  224. return;
  225. /* make this function non-reentrant */
  226. spin_lock_irqsave(&q->check_lock, flags);
  227. if (q->check_blocked) {
  228. q->check_again = 1;
  229. spin_unlock_irqrestore(&q->check_lock, flags);
  230. return; /* other thread is already checking queues */
  231. }
  232. q->check_blocked = 1;
  233. spin_unlock_irqrestore(&q->check_lock, flags);
  234. __again:
  235. /* Process tick queue... */
  236. while ((cell = snd_seq_prioq_cell_peek(q->tickq)) != NULL) {
  237. if (snd_seq_compare_tick_time(&q->timer->tick.cur_tick, &cell->event.time.tick)) {
  238. cell = snd_seq_prioq_cell_out(q->tickq);
  239. if (cell)
  240. snd_seq_dispatch_event(cell, atomic, hop);
  241. } else {
  242. /* event remains in the queue */
  243. break;
  244. }
  245. }
  246. /* Process time queue... */
  247. while ((cell = snd_seq_prioq_cell_peek(q->timeq)) != NULL) {
  248. if (snd_seq_compare_real_time(&q->timer->cur_time, &cell->event.time.time)) {
  249. cell = snd_seq_prioq_cell_out(q->timeq);
  250. if (cell)
  251. snd_seq_dispatch_event(cell, atomic, hop);
  252. } else {
  253. /* event remains in the queue */
  254. break;
  255. }
  256. }
  257. /* free lock */
  258. spin_lock_irqsave(&q->check_lock, flags);
  259. if (q->check_again) {
  260. q->check_again = 0;
  261. spin_unlock_irqrestore(&q->check_lock, flags);
  262. goto __again;
  263. }
  264. q->check_blocked = 0;
  265. spin_unlock_irqrestore(&q->check_lock, flags);
  266. }
  267. /* enqueue a event to singe queue */
  268. int snd_seq_enqueue_event(snd_seq_event_cell_t *cell, int atomic, int hop)
  269. {
  270. int dest, err;
  271. queue_t *q;
  272. snd_assert(cell != NULL, return -EINVAL);
  273. dest = cell->event.queue; /* destination queue */
  274. q = queueptr(dest);
  275. if (q == NULL)
  276. return -EINVAL;
  277. /* handle relative time stamps, convert them into absolute */
  278. if ((cell->event.flags & SNDRV_SEQ_TIME_MODE_MASK) == SNDRV_SEQ_TIME_MODE_REL) {
  279. switch (cell->event.flags & SNDRV_SEQ_TIME_STAMP_MASK) {
  280. case SNDRV_SEQ_TIME_STAMP_TICK:
  281. cell->event.time.tick += q->timer->tick.cur_tick;
  282. break;
  283. case SNDRV_SEQ_TIME_STAMP_REAL:
  284. snd_seq_inc_real_time(&cell->event.time.time, &q->timer->cur_time);
  285. break;
  286. }
  287. cell->event.flags &= ~SNDRV_SEQ_TIME_MODE_MASK;
  288. cell->event.flags |= SNDRV_SEQ_TIME_MODE_ABS;
  289. }
  290. /* enqueue event in the real-time or midi queue */
  291. switch (cell->event.flags & SNDRV_SEQ_TIME_STAMP_MASK) {
  292. case SNDRV_SEQ_TIME_STAMP_TICK:
  293. err = snd_seq_prioq_cell_in(q->tickq, cell);
  294. break;
  295. case SNDRV_SEQ_TIME_STAMP_REAL:
  296. default:
  297. err = snd_seq_prioq_cell_in(q->timeq, cell);
  298. break;
  299. }
  300. if (err < 0) {
  301. queuefree(q); /* unlock */
  302. return err;
  303. }
  304. /* trigger dispatching */
  305. snd_seq_check_queue(q, atomic, hop);
  306. queuefree(q); /* unlock */
  307. return 0;
  308. }
  309. /*----------------------------------------------------------------*/
  310. static inline int check_access(queue_t *q, int client)
  311. {
  312. return (q->owner == client) || (!q->locked && !q->klocked);
  313. }
  314. /* check if the client has permission to modify queue parameters.
  315. * if it does, lock the queue
  316. */
  317. static int queue_access_lock(queue_t *q, int client)
  318. {
  319. unsigned long flags;
  320. int access_ok;
  321. spin_lock_irqsave(&q->owner_lock, flags);
  322. access_ok = check_access(q, client);
  323. if (access_ok)
  324. q->klocked = 1;
  325. spin_unlock_irqrestore(&q->owner_lock, flags);
  326. return access_ok;
  327. }
  328. /* unlock the queue */
  329. static inline void queue_access_unlock(queue_t *q)
  330. {
  331. unsigned long flags;
  332. spin_lock_irqsave(&q->owner_lock, flags);
  333. q->klocked = 0;
  334. spin_unlock_irqrestore(&q->owner_lock, flags);
  335. }
  336. /* exported - only checking permission */
  337. int snd_seq_queue_check_access(int queueid, int client)
  338. {
  339. queue_t *q = queueptr(queueid);
  340. int access_ok;
  341. unsigned long flags;
  342. if (! q)
  343. return 0;
  344. spin_lock_irqsave(&q->owner_lock, flags);
  345. access_ok = check_access(q, client);
  346. spin_unlock_irqrestore(&q->owner_lock, flags);
  347. queuefree(q);
  348. return access_ok;
  349. }
  350. /*----------------------------------------------------------------*/
  351. /*
  352. * change queue's owner and permission
  353. */
  354. int snd_seq_queue_set_owner(int queueid, int client, int locked)
  355. {
  356. queue_t *q = queueptr(queueid);
  357. if (q == NULL)
  358. return -EINVAL;
  359. if (! queue_access_lock(q, client)) {
  360. queuefree(q);
  361. return -EPERM;
  362. }
  363. q->locked = locked ? 1 : 0;
  364. q->owner = client;
  365. queue_access_unlock(q);
  366. queuefree(q);
  367. return 0;
  368. }
  369. /*----------------------------------------------------------------*/
  370. /* open timer -
  371. * q->use mutex should be down before calling this function to avoid
  372. * confliction with snd_seq_queue_use()
  373. */
  374. int snd_seq_queue_timer_open(int queueid)
  375. {
  376. int result = 0;
  377. queue_t *queue;
  378. seq_timer_t *tmr;
  379. queue = queueptr(queueid);
  380. if (queue == NULL)
  381. return -EINVAL;
  382. tmr = queue->timer;
  383. if ((result = snd_seq_timer_open(queue)) < 0) {
  384. snd_seq_timer_defaults(tmr);
  385. result = snd_seq_timer_open(queue);
  386. }
  387. queuefree(queue);
  388. return result;
  389. }
  390. /* close timer -
  391. * q->use mutex should be down before calling this function
  392. */
  393. int snd_seq_queue_timer_close(int queueid)
  394. {
  395. queue_t *queue;
  396. seq_timer_t *tmr;
  397. int result = 0;
  398. queue = queueptr(queueid);
  399. if (queue == NULL)
  400. return -EINVAL;
  401. tmr = queue->timer;
  402. snd_seq_timer_close(queue);
  403. queuefree(queue);
  404. return result;
  405. }
  406. /* change queue tempo and ppq */
  407. int snd_seq_queue_timer_set_tempo(int queueid, int client, snd_seq_queue_tempo_t *info)
  408. {
  409. queue_t *q = queueptr(queueid);
  410. int result;
  411. if (q == NULL)
  412. return -EINVAL;
  413. if (! queue_access_lock(q, client)) {
  414. queuefree(q);
  415. return -EPERM;
  416. }
  417. result = snd_seq_timer_set_tempo(q->timer, info->tempo);
  418. if (result >= 0)
  419. result = snd_seq_timer_set_ppq(q->timer, info->ppq);
  420. if (result >= 0 && info->skew_base > 0)
  421. result = snd_seq_timer_set_skew(q->timer, info->skew_value, info->skew_base);
  422. queue_access_unlock(q);
  423. queuefree(q);
  424. return result;
  425. }
  426. /* use or unuse this queue -
  427. * if it is the first client, starts the timer.
  428. * if it is not longer used by any clients, stop the timer.
  429. */
  430. int snd_seq_queue_use(int queueid, int client, int use)
  431. {
  432. queue_t *queue;
  433. queue = queueptr(queueid);
  434. if (queue == NULL)
  435. return -EINVAL;
  436. down(&queue->timer_mutex);
  437. if (use) {
  438. if (!test_and_set_bit(client, queue->clients_bitmap))
  439. queue->clients++;
  440. } else {
  441. if (test_and_clear_bit(client, queue->clients_bitmap))
  442. queue->clients--;
  443. }
  444. if (queue->clients) {
  445. if (use && queue->clients == 1)
  446. snd_seq_timer_defaults(queue->timer);
  447. snd_seq_timer_open(queue);
  448. } else {
  449. snd_seq_timer_close(queue);
  450. }
  451. up(&queue->timer_mutex);
  452. queuefree(queue);
  453. return 0;
  454. }
  455. /*
  456. * check if queue is used by the client
  457. * return negative value if the queue is invalid.
  458. * return 0 if not used, 1 if used.
  459. */
  460. int snd_seq_queue_is_used(int queueid, int client)
  461. {
  462. queue_t *q;
  463. int result;
  464. q = queueptr(queueid);
  465. if (q == NULL)
  466. return -EINVAL; /* invalid queue */
  467. result = test_bit(client, q->clients_bitmap) ? 1 : 0;
  468. queuefree(q);
  469. return result;
  470. }
  471. /*----------------------------------------------------------------*/
  472. /* notification that client has left the system -
  473. * stop the timer on all queues owned by this client
  474. */
  475. void snd_seq_queue_client_termination(int client)
  476. {
  477. unsigned long flags;
  478. int i;
  479. queue_t *q;
  480. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  481. if ((q = queueptr(i)) == NULL)
  482. continue;
  483. spin_lock_irqsave(&q->owner_lock, flags);
  484. if (q->owner == client)
  485. q->klocked = 1;
  486. spin_unlock_irqrestore(&q->owner_lock, flags);
  487. if (q->owner == client) {
  488. if (q->timer->running)
  489. snd_seq_timer_stop(q->timer);
  490. snd_seq_timer_reset(q->timer);
  491. }
  492. queuefree(q);
  493. }
  494. }
  495. /* final stage notification -
  496. * remove cells for no longer exist client (for non-owned queue)
  497. * or delete this queue (for owned queue)
  498. */
  499. void snd_seq_queue_client_leave(int client)
  500. {
  501. int i;
  502. queue_t *q;
  503. /* delete own queues from queue list */
  504. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  505. if ((q = queue_list_remove(i, client)) != NULL)
  506. queue_delete(q);
  507. }
  508. /* remove cells from existing queues -
  509. * they are not owned by this client
  510. */
  511. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  512. if ((q = queueptr(i)) == NULL)
  513. continue;
  514. if (test_bit(client, q->clients_bitmap)) {
  515. snd_seq_prioq_leave(q->tickq, client, 0);
  516. snd_seq_prioq_leave(q->timeq, client, 0);
  517. snd_seq_queue_use(q->queue, client, 0);
  518. }
  519. queuefree(q);
  520. }
  521. }
  522. /*----------------------------------------------------------------*/
  523. /* remove cells from all queues */
  524. void snd_seq_queue_client_leave_cells(int client)
  525. {
  526. int i;
  527. queue_t *q;
  528. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  529. if ((q = queueptr(i)) == NULL)
  530. continue;
  531. snd_seq_prioq_leave(q->tickq, client, 0);
  532. snd_seq_prioq_leave(q->timeq, client, 0);
  533. queuefree(q);
  534. }
  535. }
  536. /* remove cells based on flush criteria */
  537. void snd_seq_queue_remove_cells(int client, snd_seq_remove_events_t *info)
  538. {
  539. int i;
  540. queue_t *q;
  541. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  542. if ((q = queueptr(i)) == NULL)
  543. continue;
  544. if (test_bit(client, q->clients_bitmap) &&
  545. (! (info->remove_mode & SNDRV_SEQ_REMOVE_DEST) ||
  546. q->queue == info->queue)) {
  547. snd_seq_prioq_remove_events(q->tickq, client, info);
  548. snd_seq_prioq_remove_events(q->timeq, client, info);
  549. }
  550. queuefree(q);
  551. }
  552. }
  553. /*----------------------------------------------------------------*/
  554. /*
  555. * send events to all subscribed ports
  556. */
  557. static void queue_broadcast_event(queue_t *q, snd_seq_event_t *ev, int atomic, int hop)
  558. {
  559. snd_seq_event_t sev;
  560. sev = *ev;
  561. sev.flags = SNDRV_SEQ_TIME_STAMP_TICK|SNDRV_SEQ_TIME_MODE_ABS;
  562. sev.time.tick = q->timer->tick.cur_tick;
  563. sev.queue = q->queue;
  564. sev.data.queue.queue = q->queue;
  565. /* broadcast events from Timer port */
  566. sev.source.client = SNDRV_SEQ_CLIENT_SYSTEM;
  567. sev.source.port = SNDRV_SEQ_PORT_SYSTEM_TIMER;
  568. sev.dest.client = SNDRV_SEQ_ADDRESS_SUBSCRIBERS;
  569. snd_seq_kernel_client_dispatch(SNDRV_SEQ_CLIENT_SYSTEM, &sev, atomic, hop);
  570. }
  571. /*
  572. * process a received queue-control event.
  573. * this function is exported for seq_sync.c.
  574. */
  575. static void snd_seq_queue_process_event(queue_t *q, snd_seq_event_t *ev,
  576. int atomic, int hop)
  577. {
  578. switch (ev->type) {
  579. case SNDRV_SEQ_EVENT_START:
  580. snd_seq_prioq_leave(q->tickq, ev->source.client, 1);
  581. snd_seq_prioq_leave(q->timeq, ev->source.client, 1);
  582. if (! snd_seq_timer_start(q->timer))
  583. queue_broadcast_event(q, ev, atomic, hop);
  584. break;
  585. case SNDRV_SEQ_EVENT_CONTINUE:
  586. if (! snd_seq_timer_continue(q->timer))
  587. queue_broadcast_event(q, ev, atomic, hop);
  588. break;
  589. case SNDRV_SEQ_EVENT_STOP:
  590. snd_seq_timer_stop(q->timer);
  591. queue_broadcast_event(q, ev, atomic, hop);
  592. break;
  593. case SNDRV_SEQ_EVENT_TEMPO:
  594. snd_seq_timer_set_tempo(q->timer, ev->data.queue.param.value);
  595. queue_broadcast_event(q, ev, atomic, hop);
  596. break;
  597. case SNDRV_SEQ_EVENT_SETPOS_TICK:
  598. if (snd_seq_timer_set_position_tick(q->timer, ev->data.queue.param.time.tick) == 0) {
  599. queue_broadcast_event(q, ev, atomic, hop);
  600. }
  601. break;
  602. case SNDRV_SEQ_EVENT_SETPOS_TIME:
  603. if (snd_seq_timer_set_position_time(q->timer, ev->data.queue.param.time.time) == 0) {
  604. queue_broadcast_event(q, ev, atomic, hop);
  605. }
  606. break;
  607. case SNDRV_SEQ_EVENT_QUEUE_SKEW:
  608. if (snd_seq_timer_set_skew(q->timer,
  609. ev->data.queue.param.skew.value,
  610. ev->data.queue.param.skew.base) == 0) {
  611. queue_broadcast_event(q, ev, atomic, hop);
  612. }
  613. break;
  614. }
  615. }
  616. /*
  617. * Queue control via timer control port:
  618. * this function is exported as a callback of timer port.
  619. */
  620. int snd_seq_control_queue(snd_seq_event_t *ev, int atomic, int hop)
  621. {
  622. queue_t *q;
  623. snd_assert(ev != NULL, return -EINVAL);
  624. q = queueptr(ev->data.queue.queue);
  625. if (q == NULL)
  626. return -EINVAL;
  627. if (! queue_access_lock(q, ev->source.client)) {
  628. queuefree(q);
  629. return -EPERM;
  630. }
  631. snd_seq_queue_process_event(q, ev, atomic, hop);
  632. queue_access_unlock(q);
  633. queuefree(q);
  634. return 0;
  635. }
  636. /*----------------------------------------------------------------*/
  637. /* exported to seq_info.c */
  638. void snd_seq_info_queues_read(snd_info_entry_t *entry,
  639. snd_info_buffer_t * buffer)
  640. {
  641. int i, bpm;
  642. queue_t *q;
  643. seq_timer_t *tmr;
  644. for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) {
  645. if ((q = queueptr(i)) == NULL)
  646. continue;
  647. tmr = q->timer;
  648. if (tmr->tempo)
  649. bpm = 60000000 / tmr->tempo;
  650. else
  651. bpm = 0;
  652. snd_iprintf(buffer, "queue %d: [%s]\n", q->queue, q->name);
  653. snd_iprintf(buffer, "owned by client : %d\n", q->owner);
  654. snd_iprintf(buffer, "lock status : %s\n", q->locked ? "Locked" : "Free");
  655. snd_iprintf(buffer, "queued time events : %d\n", snd_seq_prioq_avail(q->timeq));
  656. snd_iprintf(buffer, "queued tick events : %d\n", snd_seq_prioq_avail(q->tickq));
  657. snd_iprintf(buffer, "timer state : %s\n", tmr->running ? "Running" : "Stopped");
  658. snd_iprintf(buffer, "timer PPQ : %d\n", tmr->ppq);
  659. snd_iprintf(buffer, "current tempo : %d\n", tmr->tempo);
  660. snd_iprintf(buffer, "current BPM : %d\n", bpm);
  661. snd_iprintf(buffer, "current time : %d.%09d s\n", tmr->cur_time.tv_sec, tmr->cur_time.tv_nsec);
  662. snd_iprintf(buffer, "current tick : %d\n", tmr->tick.cur_tick);
  663. snd_iprintf(buffer, "\n");
  664. queuefree(q);
  665. }
  666. }