seqmid.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. /**
  2. * \file include/seqmid.h
  3. * \brief Application interface library for the ALSA driver
  4. * \author Jaroslav Kysela <perex@perex.cz>
  5. * \author Abramo Bagnara <abramo@alsa-project.org>
  6. * \author Takashi Iwai <tiwai@suse.de>
  7. * \date 1998-2001
  8. *
  9. * Application interface library for the ALSA driver
  10. */
  11. /*
  12. * This library is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU Lesser General Public License as
  14. * published by the Free Software Foundation; either version 2.1 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public
  23. * License along with this library; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. *
  26. */
  27. #ifndef __ALSA_SEQMID_H
  28. #define __ALSA_SEQMID_H
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /**
  33. * \defgroup SeqMiddle Sequencer Middle Level Interface
  34. * Sequencer Middle Level Interface
  35. * \ingroup Sequencer
  36. * \{
  37. */
  38. /**
  39. * \brief initialize event record
  40. * \param ev event record pointer
  41. *
  42. * This macro clears the given event record pointer to the default status.
  43. */
  44. #define snd_seq_ev_clear(ev) \
  45. memset(ev, 0, sizeof(snd_seq_event_t))
  46. /**
  47. * \brief set the tag for given event
  48. * \param ev event record
  49. * \param t event tag
  50. *
  51. * This macro sets the tag to the given event record.
  52. */
  53. #define snd_seq_ev_set_tag(ev,t) \
  54. ((ev)->tag = (t))
  55. /**
  56. * \brief set the explicit destination
  57. * \param ev event record
  58. * \param c destination client id
  59. * \param p destination port id
  60. *
  61. * This macro sets the client and port id numbers to the given event record.
  62. *
  63. * \sa snd_seq_ev_set_subs()
  64. */
  65. #define snd_seq_ev_set_dest(ev,c,p) \
  66. ((ev)->dest.client = (c), (ev)->dest.port = (p))
  67. /**
  68. * \brief set broadcasting to subscribers
  69. * \param ev event record
  70. *
  71. * This macro sets the destination as the subscribers.
  72. *
  73. * \sa snd_seq_ev_set_dest()
  74. */
  75. #define snd_seq_ev_set_subs(ev) \
  76. ((ev)->dest.client = SND_SEQ_ADDRESS_SUBSCRIBERS,\
  77. (ev)->dest.port = SND_SEQ_ADDRESS_UNKNOWN)
  78. /**
  79. * \brief set broadcasting to all clients/ports
  80. * \param ev event record
  81. *
  82. * This macro sets the destination as the broadcasting.
  83. *
  84. * \sa snd_seq_ev_set_dest()
  85. */
  86. #define snd_seq_ev_set_broadcast(ev) \
  87. ((ev)->dest.client = SND_SEQ_ADDRESS_BROADCAST,\
  88. (ev)->dest.port = SND_SEQ_ADDRESS_BROADCAST)
  89. /**
  90. * \brief set the source port
  91. * \param ev event record
  92. * \param p source port id
  93. *
  94. * This macro sets the source port id number.
  95. */
  96. #define snd_seq_ev_set_source(ev,p) \
  97. ((ev)->source.port = (p))
  98. /**
  99. * \brief set direct passing mode (without queued)
  100. * \param ev event instance
  101. *
  102. * This macro sets the event to the direct passing mode
  103. * to be delivered immediately without queueing.
  104. *
  105. * \sa snd_seq_ev_schedule_tick(), snd_seq_ev_schedule_real()
  106. */
  107. #define snd_seq_ev_set_direct(ev) \
  108. ((ev)->queue = SND_SEQ_QUEUE_DIRECT)
  109. /**
  110. * \brief set tick-scheduling mode on queue
  111. * \param ev event instance
  112. * \param q queue id to schedule
  113. * \param relative relative time-stamp if non-zero
  114. * \param ttick tick time-stamp to be delivered
  115. *
  116. * This macro sets the scheduling of the event in the
  117. * MIDI tick mode.
  118. *
  119. * \sa snd_seq_ev_schedule_real(), snd_seq_ev_set_direct()
  120. */
  121. #define snd_seq_ev_schedule_tick(ev, q, relative, ttick) \
  122. ((ev)->flags &= ~(SND_SEQ_TIME_STAMP_MASK | SND_SEQ_TIME_MODE_MASK),\
  123. (ev)->flags |= SND_SEQ_TIME_STAMP_TICK,\
  124. (ev)->flags |= (relative) ? SND_SEQ_TIME_MODE_REL : SND_SEQ_TIME_MODE_ABS,\
  125. (ev)->time.tick = (ttick),\
  126. (ev)->queue = (q))
  127. /**
  128. * \brief set real-time-scheduling mode on queue
  129. * \param ev event instance
  130. * \param q queue id to schedule
  131. * \param relative relative time-stamp if non-zero
  132. * \param rtime time-stamp to be delivered
  133. *
  134. * This macro sets the scheduling of the event in the
  135. * realtime mode.
  136. *
  137. * \sa snd_seq_ev_schedule_tick(), snd_seq_ev_set_direct()
  138. */
  139. #define snd_seq_ev_schedule_real(ev, q, relative, rtime) \
  140. ((ev)->flags &= ~(SND_SEQ_TIME_STAMP_MASK | SND_SEQ_TIME_MODE_MASK),\
  141. (ev)->flags |= SND_SEQ_TIME_STAMP_REAL,\
  142. (ev)->flags |= (relative) ? SND_SEQ_TIME_MODE_REL : SND_SEQ_TIME_MODE_ABS,\
  143. (ev)->time.time = *(rtime),\
  144. (ev)->queue = (q))
  145. /**
  146. * \brief set event priority
  147. * \param ev event instance
  148. * \param high_prior 1 for high priority mode
  149. */
  150. #define snd_seq_ev_set_priority(ev, high_prior) \
  151. ((ev)->flags &= ~SND_SEQ_PRIORITY_MASK,\
  152. (ev)->flags |= (high_prior) ? SND_SEQ_PRIORITY_HIGH : SND_SEQ_PRIORITY_NORMAL)
  153. /**
  154. * \brief set fixed data
  155. * \param ev event instance
  156. *
  157. * Sets the event length mode as fixed size.
  158. *
  159. * \sa snd_seq_ev_set_variable(), snd_seq_ev_set_varusr()
  160. */
  161. #define snd_seq_ev_set_fixed(ev) \
  162. ((ev)->flags &= ~SND_SEQ_EVENT_LENGTH_MASK,\
  163. (ev)->flags |= SND_SEQ_EVENT_LENGTH_FIXED)
  164. /**
  165. * \brief set variable data
  166. * \param ev event instance
  167. * \param datalen length of the external data
  168. * \param dataptr pointer of the external data
  169. *
  170. * Sets the event length mode as variable length and stores the data.
  171. *
  172. * \sa snd_seq_ev_set_fixed(), snd_seq_ev_set_varusr()
  173. */
  174. #define snd_seq_ev_set_variable(ev, datalen, dataptr) \
  175. ((ev)->flags &= ~SND_SEQ_EVENT_LENGTH_MASK,\
  176. (ev)->flags |= SND_SEQ_EVENT_LENGTH_VARIABLE,\
  177. (ev)->data.ext.len = (datalen),\
  178. (ev)->data.ext.ptr = (dataptr))
  179. /**
  180. * \brief set varusr data
  181. * \param ev event instance
  182. * \param datalen length of the external data
  183. * \param dataptr pointer of the external data
  184. *
  185. * Sets the event length mode as variable user-space data and stores the data.
  186. *
  187. * \sa snd_seq_ev_set_fixed(), snd_seq_ev_set_variable()
  188. */
  189. #define snd_seq_ev_set_varusr(ev, datalen, dataptr) \
  190. ((ev)->flags &= ~SND_SEQ_EVENT_LENGTH_MASK,\
  191. (ev)->flags |= SND_SEQ_EVENT_LENGTH_VARUSR,\
  192. (ev)->data.ext.len = (datalen),\
  193. (ev)->data.ext.ptr = (dataptr))
  194. /**
  195. * \brief set queue controls
  196. * \param ev event record
  197. * \param typ event type
  198. * \param q queue id
  199. * \param val control value
  200. */
  201. #define snd_seq_ev_set_queue_control(ev, typ, q, val) \
  202. ((ev)->type = (typ),\
  203. snd_seq_ev_set_dest(ev, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_TIMER),\
  204. (ev)->data.queue.queue = (q),\
  205. (ev)->data.queue.param.value = (val))
  206. /**
  207. * \brief set the start queue event
  208. * \param ev event record
  209. * \param q queue id to start
  210. *
  211. * \sa snd_seq_ev_set_queue_stop(), snd_seq_ev_set_queue_continue()
  212. */
  213. #define snd_seq_ev_set_queue_start(ev, q) \
  214. snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_START, q, 0)
  215. /**
  216. * \brief set the stop queue event
  217. * \param ev event record
  218. * \param q queue id to stop
  219. *
  220. * \sa snd_seq_ev_set_queue_start(), snd_seq_ev_set_queue_continue()
  221. */
  222. #define snd_seq_ev_set_queue_stop(ev, q) \
  223. snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_STOP, q, 0)
  224. /**
  225. * \brief set the stop queue event
  226. * \param ev event record
  227. * \param q queue id to continue
  228. *
  229. * \sa snd_seq_ev_set_queue_start(), snd_seq_ev_set_queue_stop()
  230. */
  231. #define snd_seq_ev_set_queue_continue(ev, q) \
  232. snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_CONTINUE, q, 0)
  233. /**
  234. * \brief set the stop queue event
  235. * \param ev event record
  236. * \param q queue id to change tempo
  237. * \param val the new tempo value
  238. */
  239. #define snd_seq_ev_set_queue_tempo(ev, q, val) \
  240. snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_TEMPO, q, val)
  241. /**
  242. * \brief set the real-time position of a queue
  243. * \param ev event record
  244. * \param q queue id to change tempo
  245. * \param rtime the new real-time pointer
  246. */
  247. #define snd_seq_ev_set_queue_pos_real(ev, q, rtime) \
  248. ((ev)->type = SND_SEQ_EVENT_SETPOS_TIME,\
  249. snd_seq_ev_set_dest(ev, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_TIMER),\
  250. (ev)->data.queue.queue = (q),\
  251. (ev)->data.queue.param.time.time = *(rtime))
  252. /**
  253. * \brief set the tick-time position of a queue
  254. * \param ev event record
  255. * \param q queue id to change tempo
  256. * \param ttime the new tick-time
  257. */
  258. #define snd_seq_ev_set_queue_pos_tick(ev, q, ttime) \
  259. ((ev)->type = SND_SEQ_EVENT_SETPOS_TICK,\
  260. snd_seq_ev_set_dest(ev, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_TIMER),\
  261. (ev)->data.queue.queue = (q),\
  262. (ev)->data.queue.param.time.tick = (ttime))
  263. /* set and send a queue control event */
  264. int snd_seq_control_queue(snd_seq_t *seq, int q, int type, int value, snd_seq_event_t *ev);
  265. /**
  266. * \brief start the specified queue
  267. * \param seq sequencer handle
  268. * \param q queue id to start
  269. * \param ev optional event record (see #snd_seq_control_queue)
  270. */
  271. #define snd_seq_start_queue(seq, q, ev) \
  272. snd_seq_control_queue(seq, q, SND_SEQ_EVENT_START, 0, ev)
  273. /**
  274. * \brief stop the specified queue
  275. * \param seq sequencer handle
  276. * \param q queue id to stop
  277. * \param ev optional event record (see #snd_seq_control_queue)
  278. */
  279. #define snd_seq_stop_queue(seq, q, ev) \
  280. snd_seq_control_queue(seq, q, SND_SEQ_EVENT_STOP, 0, ev)
  281. /**
  282. * \brief continue the specified queue
  283. * \param seq sequencer handle
  284. * \param q queue id to continue
  285. * \param ev optional event record (see #snd_seq_control_queue)
  286. */
  287. #define snd_seq_continue_queue(seq, q, ev) \
  288. snd_seq_control_queue(seq, q, SND_SEQ_EVENT_CONTINUE, 0, ev)
  289. /**
  290. * \brief change the tempo of the specified queue
  291. * \param seq sequencer handle
  292. * \param q queue id
  293. * \param tempo the new tempo value
  294. * \param ev optional event record (see #snd_seq_control_queue)
  295. */
  296. #define snd_seq_change_queue_tempo(seq, q, tempo, ev) \
  297. snd_seq_control_queue(seq, q, SND_SEQ_EVENT_TEMPO, tempo, ev)
  298. /* create a port - simple version - return the port number */
  299. int snd_seq_create_simple_port(snd_seq_t *seq, const char *name,
  300. unsigned int caps, unsigned int type);
  301. /* delete the port */
  302. int snd_seq_delete_simple_port(snd_seq_t *seq, int port);
  303. /* simple subscription between this port and another port
  304. (w/o exclusive & time conversion)
  305. */
  306. int snd_seq_connect_from(snd_seq_t *seq, int my_port, int src_client, int src_port);
  307. int snd_seq_connect_to(snd_seq_t *seq, int my_port, int dest_client, int dest_port);
  308. int snd_seq_disconnect_from(snd_seq_t *seq, int my_port, int src_client, int src_port);
  309. int snd_seq_disconnect_to(snd_seq_t *seq, int my_port, int dest_client, int dest_port);
  310. /*
  311. * set client information
  312. */
  313. int snd_seq_set_client_name(snd_seq_t *seq, const char *name);
  314. int snd_seq_set_client_event_filter(snd_seq_t *seq, int event_type);
  315. int snd_seq_set_client_pool_output(snd_seq_t *seq, size_t size);
  316. int snd_seq_set_client_pool_output_room(snd_seq_t *seq, size_t size);
  317. int snd_seq_set_client_pool_input(snd_seq_t *seq, size_t size);
  318. /* sync output queue */
  319. int snd_seq_sync_output_queue(snd_seq_t *seq);
  320. /*
  321. * parse the given string and get the sequencer address
  322. */
  323. int snd_seq_parse_address(snd_seq_t *seq, snd_seq_addr_t *addr, const char *str);
  324. /*
  325. * reset client input/output pool
  326. */
  327. int snd_seq_reset_pool_output(snd_seq_t *seq);
  328. int snd_seq_reset_pool_input(snd_seq_t *seq);
  329. /**
  330. * \brief set note event
  331. * \param ev event record
  332. * \param ch channel number
  333. * \param key note key
  334. * \param vel velocity
  335. * \param dur duration (in tick or msec)
  336. */
  337. #define snd_seq_ev_set_note(ev, ch, key, vel, dur) \
  338. ((ev)->type = SND_SEQ_EVENT_NOTE,\
  339. snd_seq_ev_set_fixed(ev),\
  340. (ev)->data.note.channel = (ch),\
  341. (ev)->data.note.note = (key),\
  342. (ev)->data.note.velocity = (vel),\
  343. (ev)->data.note.duration = (dur))
  344. /**
  345. * \brief set note-on event
  346. * \param ev event record
  347. * \param ch channel number
  348. * \param key note key
  349. * \param vel velocity
  350. */
  351. #define snd_seq_ev_set_noteon(ev, ch, key, vel) \
  352. ((ev)->type = SND_SEQ_EVENT_NOTEON,\
  353. snd_seq_ev_set_fixed(ev),\
  354. (ev)->data.note.channel = (ch),\
  355. (ev)->data.note.note = (key),\
  356. (ev)->data.note.velocity = (vel))
  357. /**
  358. * \brief set note-off event
  359. * \param ev event record
  360. * \param ch channel number
  361. * \param key note key
  362. * \param vel velocity
  363. */
  364. #define snd_seq_ev_set_noteoff(ev, ch, key, vel) \
  365. ((ev)->type = SND_SEQ_EVENT_NOTEOFF,\
  366. snd_seq_ev_set_fixed(ev),\
  367. (ev)->data.note.channel = (ch),\
  368. (ev)->data.note.note = (key),\
  369. (ev)->data.note.velocity = (vel))
  370. /**
  371. * \brief set key-pressure event
  372. * \param ev event record
  373. * \param ch channel number
  374. * \param key note key
  375. * \param vel velocity
  376. */
  377. #define snd_seq_ev_set_keypress(ev,ch,key,vel) \
  378. ((ev)->type = SND_SEQ_EVENT_KEYPRESS,\
  379. snd_seq_ev_set_fixed(ev),\
  380. (ev)->data.note.channel = (ch),\
  381. (ev)->data.note.note = (key),\
  382. (ev)->data.note.velocity = (vel))
  383. /**
  384. * \brief set MIDI controller event
  385. * \param ev event record
  386. * \param ch channel number
  387. * \param cc controller number
  388. * \param val control value
  389. */
  390. #define snd_seq_ev_set_controller(ev,ch,cc,val) \
  391. ((ev)->type = SND_SEQ_EVENT_CONTROLLER,\
  392. snd_seq_ev_set_fixed(ev),\
  393. (ev)->data.control.channel = (ch),\
  394. (ev)->data.control.param = (cc),\
  395. (ev)->data.control.value = (val))
  396. /**
  397. * \brief set program change event
  398. * \param ev event record
  399. * \param ch channel number
  400. * \param val program number
  401. */
  402. #define snd_seq_ev_set_pgmchange(ev,ch,val) \
  403. ((ev)->type = SND_SEQ_EVENT_PGMCHANGE,\
  404. snd_seq_ev_set_fixed(ev),\
  405. (ev)->data.control.channel = (ch),\
  406. (ev)->data.control.value = (val))
  407. /**
  408. * \brief set pitch-bend event
  409. * \param ev event record
  410. * \param ch channel number
  411. * \param val pitch bend; zero centered from -8192 to 8191
  412. */
  413. #define snd_seq_ev_set_pitchbend(ev,ch,val) \
  414. ((ev)->type = SND_SEQ_EVENT_PITCHBEND,\
  415. snd_seq_ev_set_fixed(ev),\
  416. (ev)->data.control.channel = (ch),\
  417. (ev)->data.control.value = (val))
  418. /**
  419. * \brief set channel pressure event
  420. * \param ev event record
  421. * \param ch channel number
  422. * \param val channel pressure value
  423. */
  424. #define snd_seq_ev_set_chanpress(ev,ch,val) \
  425. ((ev)->type = SND_SEQ_EVENT_CHANPRESS,\
  426. snd_seq_ev_set_fixed(ev),\
  427. (ev)->data.control.channel = (ch),\
  428. (ev)->data.control.value = (val))
  429. /**
  430. * \brief set sysex event
  431. * \param ev event record
  432. * \param datalen length of sysex data
  433. * \param dataptr sysex data pointer
  434. *
  435. * the sysex data must contain the start byte 0xf0 and the end byte 0xf7.
  436. */
  437. #define snd_seq_ev_set_sysex(ev,datalen,dataptr) \
  438. ((ev)->type = SND_SEQ_EVENT_SYSEX,\
  439. snd_seq_ev_set_variable(ev, datalen, dataptr))
  440. /** \} */
  441. #ifdef __cplusplus
  442. }
  443. #endif
  444. #endif /* __ALSA_SEQMID_H */