sequencer.c (166322) | sequencer.c (166971) |
---|---|
1/*- 2 * Copyright (c) 2003 Mathew Kanner 3 * Copyright (c) 1993 Hannu Savolainen 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 16 unchanged lines hidden (view full) --- 25 * SUCH DAMAGE. 26 */ 27 28/* 29 * The sequencer personality manager. 30 */ 31 32#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003 Mathew Kanner 3 * Copyright (c) 1993 Hannu Savolainen 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 16 unchanged lines hidden (view full) --- 25 * SUCH DAMAGE. 26 */ 27 28/* 29 * The sequencer personality manager. 30 */ 31 32#include <sys/cdefs.h> |
33__FBSDID("$FreeBSD: head/sys/dev/sound/midi/sequencer.c 166322 2007-01-28 20:38:07Z joel $"); | 33__FBSDID("$FreeBSD: head/sys/dev/sound/midi/sequencer.c 166971 2007-02-25 13:51:52Z netchild $"); |
34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/ioccom.h> 38 39#include <sys/filio.h> 40#include <sys/lock.h> 41#include <sys/sockio.h> 42#include <sys/fcntl.h> 43#include <sys/tty.h> 44#include <sys/proc.h> 45#include <sys/sysctl.h> 46 | 34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/ioccom.h> 38 39#include <sys/filio.h> 40#include <sys/lock.h> 41#include <sys/sockio.h> 42#include <sys/fcntl.h> 43#include <sys/tty.h> 44#include <sys/proc.h> 45#include <sys/sysctl.h> 46 |
47#include <sys/kernel.h> /* for DATA_SET */ | 47#include <sys/kernel.h> /* for DATA_SET */ |
48 49#include <sys/module.h> 50#include <sys/conf.h> 51#include <sys/file.h> 52#include <sys/uio.h> 53#include <sys/syslog.h> 54#include <sys/errno.h> 55#include <sys/malloc.h> 56#include <sys/bus.h> 57#include <machine/resource.h> 58#include <machine/bus.h> | 48 49#include <sys/module.h> 50#include <sys/conf.h> 51#include <sys/file.h> 52#include <sys/uio.h> 53#include <sys/syslog.h> 54#include <sys/errno.h> 55#include <sys/malloc.h> 56#include <sys/bus.h> 57#include <machine/resource.h> 58#include <machine/bus.h> |
59#include <machine/clock.h> /* for DELAY */ | 59#include <machine/clock.h> /* for DELAY */ |
60#include <sys/soundcard.h> 61#include <sys/rman.h> 62#include <sys/mman.h> 63#include <sys/poll.h> 64#include <sys/mutex.h> 65#include <sys/condvar.h> 66#include <sys/kthread.h> 67#include <sys/unistd.h> 68#include <sys/selinfo.h> 69 70 71#include <dev/sound/midi/midi.h> 72#include <dev/sound/midi/midiq.h> 73#include "synth_if.h" 74 75#include <dev/sound/midi/sequencer.h> 76 77#define TMR_TIMERBASE 13 78 | 60#include <sys/soundcard.h> 61#include <sys/rman.h> 62#include <sys/mman.h> 63#include <sys/poll.h> 64#include <sys/mutex.h> 65#include <sys/condvar.h> 66#include <sys/kthread.h> 67#include <sys/unistd.h> 68#include <sys/selinfo.h> 69 70 71#include <dev/sound/midi/midi.h> 72#include <dev/sound/midi/midiq.h> 73#include "synth_if.h" 74 75#include <dev/sound/midi/sequencer.h> 76 77#define TMR_TIMERBASE 13 78 |
79#define SND_DEV_SEQ 1 /* Sequencer output /dev/sequencer (FM 80 synthesizer and MIDI output) */ 81#define SND_DEV_MUSIC 8 /* /dev/music, level 2 interface */ | 79#define SND_DEV_SEQ 1 /* Sequencer output /dev/sequencer (FM 80 * synthesizer and MIDI output) */ 81#define SND_DEV_MUSIC 8 /* /dev/music, level 2 interface */ |
82 83/* Length of a sequencer event. */ 84#define EV_SZ 8 85#define IEV_SZ 8 86 87/* Lookup modes */ 88#define LOOKUP_EXIST (0) 89#define LOOKUP_OPEN (1) --- 10 unchanged lines hidden (view full) --- 100static d_close_t seq_close; 101static d_ioctl_t seq_ioctl; 102static d_read_t seq_read; 103static d_write_t seq_write; 104static d_poll_t seq_poll; 105 106static struct cdevsw seq_cdevsw = { 107 .d_version = D_VERSION, | 82 83/* Length of a sequencer event. */ 84#define EV_SZ 8 85#define IEV_SZ 8 86 87/* Lookup modes */ 88#define LOOKUP_EXIST (0) 89#define LOOKUP_OPEN (1) --- 10 unchanged lines hidden (view full) --- 100static d_close_t seq_close; 101static d_ioctl_t seq_ioctl; 102static d_read_t seq_read; 103static d_write_t seq_write; 104static d_poll_t seq_poll; 105 106static struct cdevsw seq_cdevsw = { 107 .d_version = D_VERSION, |
108 .d_open = seq_open, 109 .d_close = seq_close, 110 .d_read = seq_read, 111 .d_write = seq_write, 112 .d_ioctl = seq_ioctl, 113 .d_poll = seq_poll, 114 .d_name = "sequencer", | 108 .d_open = seq_open, 109 .d_close = seq_close, 110 .d_read = seq_read, 111 .d_write = seq_write, 112 .d_ioctl = seq_ioctl, 113 .d_poll = seq_poll, 114 .d_name = "sequencer", |
115}; 116 117struct seq_softc { 118 KOBJ_FIELDS; 119 120 struct mtx seq_lock, q_lock; 121 struct cv empty_cv, reset_cv, in_cv, out_cv, state_cv, th_cv; 122 123 MIDIQ_HEAD(, u_char) in_q, out_q; 124 | 115}; 116 117struct seq_softc { 118 KOBJ_FIELDS; 119 120 struct mtx seq_lock, q_lock; 121 struct cv empty_cv, reset_cv, in_cv, out_cv, state_cv, th_cv; 122 123 MIDIQ_HEAD(, u_char) in_q, out_q; 124 |
125 u_long flags; | 125 u_long flags; |
126 /* Flags (protected by flag_mtx of mididev_info) */ | 126 /* Flags (protected by flag_mtx of mididev_info) */ |
127 int fflags; /* Access mode */ 128 int music; | 127 int fflags; /* Access mode */ 128 int music; |
129 | 129 |
130 int out_water; /* Sequence output threshould */ 131 snd_sync_parm sync_parm; /* AIOSYNC parameter set */ 132 struct thread *sync_thread; /* AIOSYNCing thread */ | 130 int out_water; /* Sequence output threshould */ 131 snd_sync_parm sync_parm; /* AIOSYNC parameter set */ 132 struct thread *sync_thread; /* AIOSYNCing thread */ |
133 struct selinfo in_sel, out_sel; | 133 struct selinfo in_sel, out_sel; |
134 int midi_number; | 134 int midi_number; |
135 struct cdev *seqdev, *musicdev; | 135 struct cdev *seqdev, *musicdev; |
136 int unit; 137 int maxunits; | 136 int unit; 137 int maxunits; |
138 kobj_t *midis; | 138 kobj_t *midis; |
139 int *midi_flags; 140 kobj_t mapper; 141 void *mapper_cookie; | 139 int *midi_flags; 140 kobj_t mapper; 141 void *mapper_cookie; |
142 struct timeval timerstop, timersub; | 142 struct timeval timerstop, timersub; |
143 int timerbase, tempo; 144 int timerrun; 145 int done; 146 int playing; 147 int recording; 148 int busy; 149 int pre_event_timeout; 150 int waiting; | 143 int timerbase, tempo; 144 int timerrun; 145 int done; 146 int playing; 147 int recording; 148 int busy; 149 int pre_event_timeout; 150 int waiting; |
151}; 152 153/* 154 * Module specific stuff, including how many sequecers 155 * we currently own. 156 */ 157 158SYSCTL_NODE(_hw_midi, OID_AUTO, seq, CTLFLAG_RD, 0, "Midi sequencer"); --- 101 unchanged lines hidden (view full) --- 260}; 261 262/* 263 * static const char *mpu401_mprovider(kobj_t obj, struct mpu401 *m); 264 */ 265 266static kobj_method_t seq_methods[] = { 267 /* KOBJMETHOD(mpu_provider,mpu401_mprovider), */ | 151}; 152 153/* 154 * Module specific stuff, including how many sequecers 155 * we currently own. 156 */ 157 158SYSCTL_NODE(_hw_midi, OID_AUTO, seq, CTLFLAG_RD, 0, "Midi sequencer"); --- 101 unchanged lines hidden (view full) --- 260}; 261 262/* 263 * static const char *mpu401_mprovider(kobj_t obj, struct mpu401 *m); 264 */ 265 266static kobj_method_t seq_methods[] = { 267 /* KOBJMETHOD(mpu_provider,mpu401_mprovider), */ |
268 { 0, 0 } | 268 {0, 0} |
269}; | 269}; |
270 |
|
270DEFINE_CLASS(sequencer, seq_methods, 0); 271 272/* The followings are the local function. */ 273static int seq_convertold(u_char *event, u_char *out); | 271DEFINE_CLASS(sequencer, seq_methods, 0); 272 273/* The followings are the local function. */ 274static int seq_convertold(u_char *event, u_char *out); |
275 |
|
274/* 275 * static void seq_midiinput(struct seq_softc * scp, void *md); 276 */ | 276/* 277 * static void seq_midiinput(struct seq_softc * scp, void *md); 278 */ |
277static void seq_reset(struct seq_softc * scp); 278static int seq_sync(struct seq_softc * scp); | 279static void seq_reset(struct seq_softc *scp); 280static int seq_sync(struct seq_softc *scp); |
279 | 281 |
280static int seq_processevent(struct seq_softc * scp, u_char *event); | 282static int seq_processevent(struct seq_softc *scp, u_char *event); |
281 | 283 |
282static int seq_timing(struct seq_softc * scp, u_char *event); 283static int seq_local(struct seq_softc * scp, u_char *event); | 284static int seq_timing(struct seq_softc *scp, u_char *event); 285static int seq_local(struct seq_softc *scp, u_char *event); |
284 | 286 |
285static int seq_chnvoice(struct seq_softc * scp, kobj_t md, u_char *event); 286static int seq_chncommon(struct seq_softc * scp, kobj_t md, u_char *event); 287static int seq_sysex(struct seq_softc * scp, kobj_t md, u_char *event); | 287static int seq_chnvoice(struct seq_softc *scp, kobj_t md, u_char *event); 288static int seq_chncommon(struct seq_softc *scp, kobj_t md, u_char *event); 289static int seq_sysex(struct seq_softc *scp, kobj_t md, u_char *event); |
288 289static int seq_fetch_mid(struct seq_softc *scp, int unit, kobj_t *md); | 290 291static int seq_fetch_mid(struct seq_softc *scp, int unit, kobj_t *md); |
290void seq_copytoinput(struct seq_softc *scp, u_char *event, int len); 291int seq_modevent(module_t mod, int type, void *data); | 292void seq_copytoinput(struct seq_softc *scp, u_char *event, int len); 293int seq_modevent(module_t mod, int type, void *data); |
292struct seq_softc *seqs[10]; | 294struct seq_softc *seqs[10]; |
293static struct mtx seqinfo_mtx; 294static u_long nseq = 0; | 295static struct mtx seqinfo_mtx; 296static u_long nseq = 0; |
295 296static void timer_start(struct seq_softc *t); 297static void timer_stop(struct seq_softc *t); 298static void timer_setvals(struct seq_softc *t, int tempo, int timerbase); 299static void timer_wait(struct seq_softc *t, int ticks, int wait_abs); 300static int timer_now(struct seq_softc *t); 301 302 --- 5 unchanged lines hidden (view full) --- 308} 309 310static void 311timer_continue(struct seq_softc *t) 312{ 313 struct timeval now; 314 315 if (t->timerrun == 1) | 297 298static void timer_start(struct seq_softc *t); 299static void timer_stop(struct seq_softc *t); 300static void timer_setvals(struct seq_softc *t, int tempo, int timerbase); 301static void timer_wait(struct seq_softc *t, int ticks, int wait_abs); 302static int timer_now(struct seq_softc *t); 303 304 --- 5 unchanged lines hidden (view full) --- 310} 311 312static void 313timer_continue(struct seq_softc *t) 314{ 315 struct timeval now; 316 317 if (t->timerrun == 1) |
316 return; | 318 return; |
317 t->timerrun = 1; 318 getmicrotime(&now); 319 timevalsub(&now, &t->timerstop); 320 timevaladd(&t->timersub, &now); 321} 322 323static void 324timer_stop(struct seq_softc *t) --- 12 unchanged lines hidden (view full) --- 337static void 338timer_wait(struct seq_softc *t, int ticks, int wait_abs) 339{ 340 struct timeval now, when; 341 int ret; 342 unsigned long long i; 343 344 while (t->timerrun == 0) { | 319 t->timerrun = 1; 320 getmicrotime(&now); 321 timevalsub(&now, &t->timerstop); 322 timevaladd(&t->timersub, &now); 323} 324 325static void 326timer_stop(struct seq_softc *t) --- 12 unchanged lines hidden (view full) --- 339static void 340timer_wait(struct seq_softc *t, int ticks, int wait_abs) 341{ 342 struct timeval now, when; 343 int ret; 344 unsigned long long i; 345 346 while (t->timerrun == 0) { |
345 SEQ_DEBUG(2,printf("Timer wait when timer isn't running\n")); 346 /* 347 * The old sequencer used timeouts that only increased 348 * the timer when the timer was running. 349 * Hence the sequencer would stick (?) if the 350 * timer was disabled. 351 */ 352 cv_wait(&t->reset_cv, &t->seq_lock); 353 if (t->playing == 0) 354 return; | 347 SEQ_DEBUG(2, printf("Timer wait when timer isn't running\n")); 348 /* 349 * The old sequencer used timeouts that only increased 350 * the timer when the timer was running. 351 * Hence the sequencer would stick (?) if the 352 * timer was disabled. 353 */ 354 cv_wait(&t->reset_cv, &t->seq_lock); 355 if (t->playing == 0) 356 return; |
355 } 356 357 i = ticks * 60ull * 1000000ull / (t->tempo * t->timerbase); 358 359 when.tv_sec = i / 1000000; 360 when.tv_usec = i % 1000000; 361 362#if 0 | 357 } 358 359 i = ticks * 60ull * 1000000ull / (t->tempo * t->timerbase); 360 361 when.tv_sec = i / 1000000; 362 when.tv_usec = i % 1000000; 363 364#if 0 |
363 printf("timer_wait tempo %d timerbase %d ticks %d abs %d u_sec %llu\n", t->tempo, t->timerbase, ticks, wait_abs, i); | 365 printf("timer_wait tempo %d timerbase %d ticks %d abs %d u_sec %llu\n", 366 t->tempo, t->timerbase, ticks, wait_abs, i); |
364#endif 365 366 if (wait_abs != 0) { | 367#endif 368 369 if (wait_abs != 0) { |
367 getmicrotime(&now); 368 timevalsub(&now, &t->timersub); 369 timevalsub(&when, &now); | 370 getmicrotime(&now); 371 timevalsub(&now, &t->timersub); 372 timevalsub(&when, &now); |
370 } | 373 } |
371 | |
372 if (when.tv_sec < 0 || when.tv_usec < 0) { | 374 if (when.tv_sec < 0 || when.tv_usec < 0) { |
373 SEQ_DEBUG(3,printf("seq_timer error negative time %lds.%06lds\n", 374 (long)when.tv_sec,(long)when.tv_usec)); 375 return; | 375 SEQ_DEBUG(3, 376 printf("seq_timer error negative time %lds.%06lds\n", 377 (long)when.tv_sec, (long)when.tv_usec)); 378 return; |
376 } | 379 } |
377 | |
378 i = when.tv_sec * 1000000ull; 379 i += when.tv_usec; 380 i *= hz; 381 i /= 1000000ull; 382#if 0 | 380 i = when.tv_sec * 1000000ull; 381 i += when.tv_usec; 382 i *= hz; 383 i /= 1000000ull; 384#if 0 |
383 printf("seq_timer usec %llu ticks %llu\n", when.tv_sec * 1000000ull + when.tv_usec, i); | 385 printf("seq_timer usec %llu ticks %llu\n", 386 when.tv_sec * 1000000ull + when.tv_usec, i); |
384#endif 385 t->waiting = 1; 386 ret = cv_timedwait(&t->reset_cv, &t->seq_lock, i + 1); 387 t->waiting = 0; 388 389 if (ret != EWOULDBLOCK) | 387#endif 388 t->waiting = 1; 389 ret = cv_timedwait(&t->reset_cv, &t->seq_lock, i + 1); 390 t->waiting = 0; 391 392 if (ret != EWOULDBLOCK) |
390 SEQ_DEBUG(3,printf("seq_timer didn't timeout\n")); | 393 SEQ_DEBUG(3, printf("seq_timer didn't timeout\n")); |
391 392} 393 394static int 395timer_now(struct seq_softc *t) 396{ 397 struct timeval now; 398 unsigned long long i; 399 int ret; 400 401 if (t->timerrun == 0) | 394 395} 396 397static int 398timer_now(struct seq_softc *t) 399{ 400 struct timeval now; 401 unsigned long long i; 402 int ret; 403 404 if (t->timerrun == 0) |
402 now = t->timerstop; | 405 now = t->timerstop; |
403 else | 406 else |
404 getmicrotime(&now); | 407 getmicrotime(&now); |
405 406 timevalsub(&now, &t->timersub); 407 408 i = now.tv_sec * 1000000ull; 409 i += now.tv_usec; 410 i *= t->timerbase; 411/* i /= t->tempo; */ 412 i /= 1000000ull; --- 8 unchanged lines hidden (view full) --- 421 422static void 423seq_eventthread(void *arg) 424{ 425 struct seq_softc *scp = arg; 426 char event[EV_SZ]; 427 428 mtx_lock(&scp->seq_lock); | 408 409 timevalsub(&now, &t->timersub); 410 411 i = now.tv_sec * 1000000ull; 412 i += now.tv_usec; 413 i *= t->timerbase; 414/* i /= t->tempo; */ 415 i /= 1000000ull; --- 8 unchanged lines hidden (view full) --- 424 425static void 426seq_eventthread(void *arg) 427{ 428 struct seq_softc *scp = arg; 429 char event[EV_SZ]; 430 431 mtx_lock(&scp->seq_lock); |
429 SEQ_DEBUG(2,printf("seq_eventthread started\n")); 430 while(scp->done == 0) { | 432 SEQ_DEBUG(2, printf("seq_eventthread started\n")); 433 while (scp->done == 0) { |
431restart: | 434restart: |
432 while (scp->playing == 0) { 433 cv_wait(&scp->state_cv, &scp->seq_lock); 434 if (scp->done) 435 goto done; 436 } | 435 while (scp->playing == 0) { 436 cv_wait(&scp->state_cv, &scp->seq_lock); 437 if (scp->done) 438 goto done; 439 } |
437 | 440 |
438 while (MIDIQ_EMPTY(scp->out_q)) { 439 cv_broadcast(&scp->empty_cv); 440 cv_wait(&scp->out_cv, &scp->seq_lock); 441 if (scp->playing == 0) 442 goto restart; 443 if (scp->done) 444 goto done; 445 } | 441 while (MIDIQ_EMPTY(scp->out_q)) { 442 cv_broadcast(&scp->empty_cv); 443 cv_wait(&scp->out_cv, &scp->seq_lock); 444 if (scp->playing == 0) 445 goto restart; 446 if (scp->done) 447 goto done; 448 } |
446 | 449 |
447 MIDIQ_DEQ(scp->out_q, event, EV_SZ); | 450 MIDIQ_DEQ(scp->out_q, event, EV_SZ); |
448 | 451 |
449 if (MIDIQ_AVAIL(scp->out_q) < scp->out_water) { 450 cv_broadcast(&scp->out_cv); 451 selwakeup(&scp->out_sel); 452 } 453 454 seq_processevent(scp, event); | 452 if (MIDIQ_AVAIL(scp->out_q) < scp->out_water) { 453 cv_broadcast(&scp->out_cv); 454 selwakeup(&scp->out_sel); 455 } 456 seq_processevent(scp, event); |
455 } 456 457done: 458 cv_broadcast(&scp->th_cv); 459 mtx_unlock(&scp->seq_lock); 460 mtx_lock(&Giant); | 457 } 458 459done: 460 cv_broadcast(&scp->th_cv); 461 mtx_unlock(&scp->seq_lock); 462 mtx_lock(&Giant); |
461 SEQ_DEBUG(2,printf("seq_eventthread finished\n")); | 463 SEQ_DEBUG(2, printf("seq_eventthread finished\n")); |
462 kthread_exit(0); 463} 464 465/* 466 * seq_processevent: This maybe called by the event thread or the IOCTL 467 * handler for queued and out of band events respectively. 468 */ 469static int --- 4 unchanged lines hidden (view full) --- 474 475 ret = 0; 476 477 if (event[0] == EV_SEQ_LOCAL) 478 ret = seq_local(scp, event); 479 else if (event[0] == EV_TIMING) 480 ret = seq_timing(scp, event); 481 else if (event[0] != EV_CHN_VOICE && | 464 kthread_exit(0); 465} 466 467/* 468 * seq_processevent: This maybe called by the event thread or the IOCTL 469 * handler for queued and out of band events respectively. 470 */ 471static int --- 4 unchanged lines hidden (view full) --- 476 477 ret = 0; 478 479 if (event[0] == EV_SEQ_LOCAL) 480 ret = seq_local(scp, event); 481 else if (event[0] == EV_TIMING) 482 ret = seq_timing(scp, event); 483 else if (event[0] != EV_CHN_VOICE && |
482 event[0] != EV_CHN_COMMON && 483 event[0] != EV_SYSEX && 484 event[0] != SEQ_MIDIPUTC) { | 484 event[0] != EV_CHN_COMMON && 485 event[0] != EV_SYSEX && 486 event[0] != SEQ_MIDIPUTC) { |
485 ret = 1; | 487 ret = 1; |
486 SEQ_DEBUG(2,printf("seq_processevent not known %d\n", event[0])); | 488 SEQ_DEBUG(2, printf("seq_processevent not known %d\n", 489 event[0])); |
487 } else if (seq_fetch_mid(scp, event[1], &m) != 0) { 488 ret = 1; | 490 } else if (seq_fetch_mid(scp, event[1], &m) != 0) { 491 ret = 1; |
489 SEQ_DEBUG(2,printf("seq_processevent midi unit not found %d\n", event[1])); 490 } else switch(event[0]) { 491 case EV_CHN_VOICE: | 492 SEQ_DEBUG(2, printf("seq_processevent midi unit not found %d\n", 493 event[1])); 494 } else 495 switch (event[0]) { 496 case EV_CHN_VOICE: |
492 ret = seq_chnvoice(scp, m, event); 493 break; 494 case EV_CHN_COMMON: 495 ret = seq_chncommon(scp, m, event); 496 break; 497 case EV_SYSEX: 498 ret = seq_sysex(scp, m, event); 499 break; 500 case SEQ_MIDIPUTC: 501 mtx_unlock(&scp->seq_lock); 502 ret = SYNTH_WRITERAW(m, &event[2], 1); 503 mtx_lock(&scp->seq_lock); 504 break; | 497 ret = seq_chnvoice(scp, m, event); 498 break; 499 case EV_CHN_COMMON: 500 ret = seq_chncommon(scp, m, event); 501 break; 502 case EV_SYSEX: 503 ret = seq_sysex(scp, m, event); 504 break; 505 case SEQ_MIDIPUTC: 506 mtx_unlock(&scp->seq_lock); 507 ret = SYNTH_WRITERAW(m, &event[2], 1); 508 mtx_lock(&scp->seq_lock); 509 break; |
505 } | 510 } |
506 return ret; 507} 508 509static int 510seq_addunit(void) 511{ 512 struct seq_softc *scp; 513 int ret; 514 u_char *buf; 515 516 /* Allocate the softc. */ 517 ret = ENOMEM; 518 scp = malloc(sizeof(*scp), M_DEVBUF, M_NOWAIT | M_ZERO); 519 if (scp == NULL) { | 511 return ret; 512} 513 514static int 515seq_addunit(void) 516{ 517 struct seq_softc *scp; 518 int ret; 519 u_char *buf; 520 521 /* Allocate the softc. */ 522 ret = ENOMEM; 523 scp = malloc(sizeof(*scp), M_DEVBUF, M_NOWAIT | M_ZERO); 524 if (scp == NULL) { |
520 SEQ_DEBUG(1,printf("seq_addunit: softc allocation failed.\n")); | 525 SEQ_DEBUG(1, printf("seq_addunit: softc allocation failed.\n")); |
521 goto err; 522 } | 526 goto err; 527 } |
523 kobj_init((kobj_t) scp, &sequencer_class); | 528 kobj_init((kobj_t)scp, &sequencer_class); |
524 525 buf = malloc(sizeof(*buf) * EV_SZ * 1024, M_TEMP, M_NOWAIT | M_ZERO); 526 if (buf == NULL) | 529 530 buf = malloc(sizeof(*buf) * EV_SZ * 1024, M_TEMP, M_NOWAIT | M_ZERO); 531 if (buf == NULL) |
527 goto err; | 532 goto err; |
528 MIDIQ_INIT(scp->in_q, buf, EV_SZ * 1024); 529 buf = malloc(sizeof(*buf) * EV_SZ * 1024, M_TEMP, M_NOWAIT | M_ZERO); 530 if (buf == NULL) | 533 MIDIQ_INIT(scp->in_q, buf, EV_SZ * 1024); 534 buf = malloc(sizeof(*buf) * EV_SZ * 1024, M_TEMP, M_NOWAIT | M_ZERO); 535 if (buf == NULL) |
531 goto err; | 536 goto err; |
532 MIDIQ_INIT(scp->out_q, buf, EV_SZ * 1024); 533 ret = EINVAL; 534 535 scp->midis = malloc(sizeof(kobj_t) * 32, M_TEMP, M_NOWAIT | M_ZERO); 536 scp->midi_flags = malloc(sizeof(*scp->midi_flags) * 32, M_TEMP, | 537 MIDIQ_INIT(scp->out_q, buf, EV_SZ * 1024); 538 ret = EINVAL; 539 540 scp->midis = malloc(sizeof(kobj_t) * 32, M_TEMP, M_NOWAIT | M_ZERO); 541 scp->midi_flags = malloc(sizeof(*scp->midi_flags) * 32, M_TEMP, |
537 M_NOWAIT | M_ZERO); | 542 M_NOWAIT | M_ZERO); |
538 | 543 |
539 if ( scp->midis == NULL || scp->midi_flags == NULL) 540 goto err; | 544 if (scp->midis == NULL || scp->midi_flags == NULL) 545 goto err; |
541 542 scp->flags = 0; 543 544 mtx_init(&scp->seq_lock, "seqflq", 0, 0); 545 cv_init(&scp->state_cv, "seqstate"); 546 cv_init(&scp->empty_cv, "seqempty"); 547 cv_init(&scp->reset_cv, "seqtimer"); 548 cv_init(&scp->out_cv, "seqqout"); 549 cv_init(&scp->in_cv, "seqqin"); 550 cv_init(&scp->th_cv, "seqstart"); 551 552 /* 553 * Init the damn timer 554 */ 555 556 scp->mapper = midimapper_addseq(scp, &scp->unit, &scp->mapper_cookie); 557 if (scp->mapper == NULL) | 546 547 scp->flags = 0; 548 549 mtx_init(&scp->seq_lock, "seqflq", 0, 0); 550 cv_init(&scp->state_cv, "seqstate"); 551 cv_init(&scp->empty_cv, "seqempty"); 552 cv_init(&scp->reset_cv, "seqtimer"); 553 cv_init(&scp->out_cv, "seqqout"); 554 cv_init(&scp->in_cv, "seqqin"); 555 cv_init(&scp->th_cv, "seqstart"); 556 557 /* 558 * Init the damn timer 559 */ 560 561 scp->mapper = midimapper_addseq(scp, &scp->unit, &scp->mapper_cookie); 562 if (scp->mapper == NULL) |
558 goto err; | 563 goto err; |
559 560 scp->seqdev = make_dev(&seq_cdevsw, | 564 565 scp->seqdev = make_dev(&seq_cdevsw, |
561 MIDIMKMINOR(scp->unit, SND_DEV_SEQ,0), UID_ROOT, 562 GID_WHEEL, 0666, "sequencer%d", scp->unit); | 566 MIDIMKMINOR(scp->unit, SND_DEV_SEQ, 0), UID_ROOT, 567 GID_WHEEL, 0666, "sequencer%d", scp->unit); |
563 564 scp->musicdev = make_dev(&seq_cdevsw, | 568 569 scp->musicdev = make_dev(&seq_cdevsw, |
565 MIDIMKMINOR(scp->unit, SND_DEV_MUSIC,0), UID_ROOT, 566 GID_WHEEL, 0666, "music%d", scp->unit); | 570 MIDIMKMINOR(scp->unit, SND_DEV_MUSIC, 0), UID_ROOT, 571 GID_WHEEL, 0666, "music%d", scp->unit); |
567 568 if (scp->seqdev == NULL || scp->musicdev == NULL) | 572 573 if (scp->seqdev == NULL || scp->musicdev == NULL) |
569 goto err; | 574 goto err; |
570 /* 571 * TODO: Add to list of sequencers this module provides 572 */ 573 | 575 /* 576 * TODO: Add to list of sequencers this module provides 577 */ 578 |
574 ret = kthread_create(seq_eventthread, scp, NULL, RFHIGHPID, 0, "sequencer %02d", scp->unit); | 579 ret = kthread_create(seq_eventthread, scp, NULL, RFHIGHPID, 0, 580 "sequencer %02d", scp->unit); |
575 576 if (ret) | 581 582 if (ret) |
577 goto err; | 583 goto err; |
578 579 scp->seqdev->si_drv1 = scp->musicdev->si_drv1 = scp; 580 | 584 585 scp->seqdev->si_drv1 = scp->musicdev->si_drv1 = scp; 586 |
581 SEQ_DEBUG(2,printf("sequencer %d created scp %p\n", scp->unit, scp)); | 587 SEQ_DEBUG(2, printf("sequencer %d created scp %p\n", scp->unit, scp)); |
582 583 ret = 0; 584 585 mtx_lock(&seqinfo_mtx); | 588 589 ret = 0; 590 591 mtx_lock(&seqinfo_mtx); |
586 seqs[nseq++]=scp; | 592 seqs[nseq++] = scp; |
587 mtx_unlock(&seqinfo_mtx); 588 589 goto ok; 590 591err: 592 if (scp != NULL) { | 593 mtx_unlock(&seqinfo_mtx); 594 595 goto ok; 596 597err: 598 if (scp != NULL) { |
593 if (scp->seqdev != NULL) 594 destroy_dev(scp->seqdev); 595 if (scp->musicdev != NULL) 596 destroy_dev(scp->musicdev); 597 /* 598 * TODO: Destroy mutex and cv 599 */ 600 if (scp->midis != NULL) 601 free(scp->midis, M_TEMP); 602 if (scp->midi_flags != NULL) 603 free(scp->midi_flags, M_TEMP); 604 if (scp->out_q.b) 605 free(scp->out_q.b, M_TEMP); 606 if (scp->in_q.b) 607 free(scp->in_q.b, M_TEMP); 608 free(scp, M_DEVBUF); | 599 if (scp->seqdev != NULL) 600 destroy_dev(scp->seqdev); 601 if (scp->musicdev != NULL) 602 destroy_dev(scp->musicdev); 603 /* 604 * TODO: Destroy mutex and cv 605 */ 606 if (scp->midis != NULL) 607 free(scp->midis, M_TEMP); 608 if (scp->midi_flags != NULL) 609 free(scp->midi_flags, M_TEMP); 610 if (scp->out_q.b) 611 free(scp->out_q.b, M_TEMP); 612 if (scp->in_q.b) 613 free(scp->in_q.b, M_TEMP); 614 free(scp, M_DEVBUF); |
609 } 610ok: 611 return ret; 612} 613 614static int 615seq_delunit(int unit) 616{ 617 struct seq_softc *scp = seqs[unit]; 618 int i; 619 | 615 } 616ok: 617 return ret; 618} 619 620static int 621seq_delunit(int unit) 622{ 623 struct seq_softc *scp = seqs[unit]; 624 int i; 625 |
620 //SEQ_DEBUG(4,printf("seq_delunit: %d\n", unit)); | 626 //SEQ_DEBUG(4, printf("seq_delunit: %d\n", unit)); |
621 SEQ_DEBUG(1, printf("seq_delunit: 1 \n")); 622 mtx_lock(&scp->seq_lock); 623 624 scp->playing = 0; 625 scp->done = 1; 626 cv_broadcast(&scp->out_cv); 627 cv_broadcast(&scp->state_cv); 628 cv_broadcast(&scp->reset_cv); --- 12 unchanged lines hidden (view full) --- 641 cv_destroy(&scp->out_cv); 642 SEQ_DEBUG(1, printf("seq_delunit: 7 \n")); 643 cv_destroy(&scp->in_cv); 644 SEQ_DEBUG(1, printf("seq_delunit: 8 \n")); 645 cv_destroy(&scp->th_cv); 646 647 SEQ_DEBUG(1, printf("seq_delunit: 10 \n")); 648 if (scp->seqdev) | 627 SEQ_DEBUG(1, printf("seq_delunit: 1 \n")); 628 mtx_lock(&scp->seq_lock); 629 630 scp->playing = 0; 631 scp->done = 1; 632 cv_broadcast(&scp->out_cv); 633 cv_broadcast(&scp->state_cv); 634 cv_broadcast(&scp->reset_cv); --- 12 unchanged lines hidden (view full) --- 647 cv_destroy(&scp->out_cv); 648 SEQ_DEBUG(1, printf("seq_delunit: 7 \n")); 649 cv_destroy(&scp->in_cv); 650 SEQ_DEBUG(1, printf("seq_delunit: 8 \n")); 651 cv_destroy(&scp->th_cv); 652 653 SEQ_DEBUG(1, printf("seq_delunit: 10 \n")); 654 if (scp->seqdev) |
649 destroy_dev(scp->seqdev); | 655 destroy_dev(scp->seqdev); |
650 SEQ_DEBUG(1, printf("seq_delunit: 11 \n")); 651 if (scp->musicdev) | 656 SEQ_DEBUG(1, printf("seq_delunit: 11 \n")); 657 if (scp->musicdev) |
652 destroy_dev(scp->musicdev); | 658 destroy_dev(scp->musicdev); |
653 SEQ_DEBUG(1, printf("seq_delunit: 12 \n")); 654 scp->seqdev = scp->musicdev = NULL; 655 if (scp->midis != NULL) | 659 SEQ_DEBUG(1, printf("seq_delunit: 12 \n")); 660 scp->seqdev = scp->musicdev = NULL; 661 if (scp->midis != NULL) |
656 free(scp->midis, M_TEMP); | 662 free(scp->midis, M_TEMP); |
657 SEQ_DEBUG(1, printf("seq_delunit: 13 \n")); 658 if (scp->midi_flags != NULL) | 663 SEQ_DEBUG(1, printf("seq_delunit: 13 \n")); 664 if (scp->midi_flags != NULL) |
659 free(scp->midi_flags, M_TEMP); | 665 free(scp->midi_flags, M_TEMP); |
660 SEQ_DEBUG(1, printf("seq_delunit: 14 \n")); 661 free(scp->out_q.b, M_TEMP); 662 SEQ_DEBUG(1, printf("seq_delunit: 15 \n")); 663 free(scp->in_q.b, M_TEMP); 664 665 SEQ_DEBUG(1, printf("seq_delunit: 16 \n")); 666 667 mtx_destroy(&scp->seq_lock); 668 SEQ_DEBUG(1, printf("seq_delunit: 17 \n")); 669 free(scp, M_DEVBUF); 670 671 mtx_lock(&seqinfo_mtx); | 666 SEQ_DEBUG(1, printf("seq_delunit: 14 \n")); 667 free(scp->out_q.b, M_TEMP); 668 SEQ_DEBUG(1, printf("seq_delunit: 15 \n")); 669 free(scp->in_q.b, M_TEMP); 670 671 SEQ_DEBUG(1, printf("seq_delunit: 16 \n")); 672 673 mtx_destroy(&scp->seq_lock); 674 SEQ_DEBUG(1, printf("seq_delunit: 17 \n")); 675 free(scp, M_DEVBUF); 676 677 mtx_lock(&seqinfo_mtx); |
672 for ( i = unit ; i < (nseq - 1) ; i++ ) 673 seqs[i] = seqs[i+1]; | 678 for (i = unit; i < (nseq - 1); i++) 679 seqs[i] = seqs[i + 1]; |
674 nseq--; 675 mtx_unlock(&seqinfo_mtx); 676 677 return 0; 678} 679 680int 681seq_modevent(module_t mod, int type, void *data) 682{ 683 int retval, r; 684 685 retval = 0; 686 687 switch (type) { | 680 nseq--; 681 mtx_unlock(&seqinfo_mtx); 682 683 return 0; 684} 685 686int 687seq_modevent(module_t mod, int type, void *data) 688{ 689 int retval, r; 690 691 retval = 0; 692 693 switch (type) { |
688 case MOD_LOAD: | 694 case MOD_LOAD: |
689 mtx_init(&seqinfo_mtx, "seqmod", 0, 0); 690 retval = seq_addunit(); 691 break; 692 | 695 mtx_init(&seqinfo_mtx, "seqmod", 0, 0); 696 retval = seq_addunit(); 697 break; 698 |
693 case MOD_UNLOAD: | 699 case MOD_UNLOAD: |
694 while (nseq) { | 700 while (nseq) { |
695 r=seq_delunit(nseq-1); | 701 r = seq_delunit(nseq - 1); |
696 if (r) { 697 retval = r; 698 break; 699 } 700 } | 702 if (r) { 703 retval = r; 704 break; 705 } 706 } |
701 if(nseq == 0) { | 707 if (nseq == 0) { |
702 retval = 0; 703 mtx_destroy(&seqinfo_mtx); 704 } 705 break; 706 | 708 retval = 0; 709 mtx_destroy(&seqinfo_mtx); 710 } 711 break; 712 |
707 default: | 713 default: |
708 break; 709 } 710 711 return retval; 712} 713 714static int 715seq_fetch_mid(struct seq_softc *scp, int unit, kobj_t *md) 716{ 717 718 if (unit > scp->midi_number || unit < 0) | 714 break; 715 } 716 717 return retval; 718} 719 720static int 721seq_fetch_mid(struct seq_softc *scp, int unit, kobj_t *md) 722{ 723 724 if (unit > scp->midi_number || unit < 0) |
719 return EINVAL; | 725 return EINVAL; |
720 721 *md = scp->midis[unit]; 722 723 return 0; 724} 725 726int 727seq_open(struct cdev *i_dev, int flags, int mode, struct thread *td) 728{ 729 struct seq_softc *scp = i_dev->si_drv1; 730 int i; 731 732 if (scp == NULL) | 726 727 *md = scp->midis[unit]; 728 729 return 0; 730} 731 732int 733seq_open(struct cdev *i_dev, int flags, int mode, struct thread *td) 734{ 735 struct seq_softc *scp = i_dev->si_drv1; 736 int i; 737 738 if (scp == NULL) |
733 return ENXIO; | 739 return ENXIO; |
734 | 740 |
735 SEQ_DEBUG(3,printf("seq_open: scp %p unit %d, flags 0x%x.\n", 736 scp, scp->unit, flags)); | 741 SEQ_DEBUG(3, printf("seq_open: scp %p unit %d, flags 0x%x.\n", 742 scp, scp->unit, flags)); |
737 738 /* | 743 744 /* |
739 * Mark this device busy. | 745 * Mark this device busy. |
740 */ 741 742 mtx_lock(&scp->seq_lock); 743 if (scp->busy) { 744 mtx_unlock(&scp->seq_lock); | 746 */ 747 748 mtx_lock(&scp->seq_lock); 749 if (scp->busy) { 750 mtx_unlock(&scp->seq_lock); |
745 SEQ_DEBUG(2,printf("seq_open: unit %d is busy.\n", scp->unit)); | 751 SEQ_DEBUG(2, printf("seq_open: unit %d is busy.\n", scp->unit)); |
746 return EBUSY; 747 } 748 scp->fflags = flags; 749 /* 750 if ((scp->fflags & O_NONBLOCK) != 0) 751 scp->flags |= SEQ_F_NBIO; 752 */ 753 scp->music = MIDIDEV(i_dev) == SND_DEV_MUSIC; 754 755 /* 756 * Enumerate the available midi devices 757 */ 758 scp->midi_number = 0; 759 scp->maxunits = midimapper_open(scp->mapper, &scp->mapper_cookie); 760 761 if (scp->maxunits == 0) | 752 return EBUSY; 753 } 754 scp->fflags = flags; 755 /* 756 if ((scp->fflags & O_NONBLOCK) != 0) 757 scp->flags |= SEQ_F_NBIO; 758 */ 759 scp->music = MIDIDEV(i_dev) == SND_DEV_MUSIC; 760 761 /* 762 * Enumerate the available midi devices 763 */ 764 scp->midi_number = 0; 765 scp->maxunits = midimapper_open(scp->mapper, &scp->mapper_cookie); 766 767 if (scp->maxunits == 0) |
762 SEQ_DEBUG(2,printf("seq_open: no midi devices\n")); | 768 SEQ_DEBUG(2, printf("seq_open: no midi devices\n")); |
763 | 769 |
764 for (i = 0 ; i < scp->maxunits; i++) { 765 scp->midis[scp->midi_number] = 766 midimapper_fetch_synth(scp->mapper, scp->mapper_cookie, i); 767 if (scp->midis[scp->midi_number]) { 768 if ( SYNTH_OPEN(scp->midis[scp->midi_number], scp, scp->fflags) 769 != 0 ) 770 scp->midis[scp->midi_number] = NULL; 771 else { 772 scp->midi_flags[scp->midi_number] = 773 SYNTH_QUERY(scp->midis[scp->midi_number]); 774 scp->midi_number++; | 770 for (i = 0; i < scp->maxunits; i++) { 771 scp->midis[scp->midi_number] = 772 midimapper_fetch_synth(scp->mapper, scp->mapper_cookie, i); 773 if (scp->midis[scp->midi_number]) { 774 if (SYNTH_OPEN(scp->midis[scp->midi_number], scp, 775 scp->fflags) != 0) 776 scp->midis[scp->midi_number] = NULL; 777 else { 778 scp->midi_flags[scp->midi_number] = 779 SYNTH_QUERY(scp->midis[scp->midi_number]); 780 scp->midi_number++; 781 } |
775 } | 782 } |
776 } | |
777 } 778 779 timer_setvals(scp, 60, 100); 780 781 timer_start(scp); 782 timer_stop(scp); 783 /* 784 * actually, if we're in rdonly mode, we should start the timer 785 */ 786 /* 787 * TODO: Handle recording now 788 */ 789 790 scp->out_water = MIDIQ_SIZE(scp->out_q) / 2; 791 792 scp->busy = 1; 793 mtx_unlock(&scp->seq_lock); 794 | 783 } 784 785 timer_setvals(scp, 60, 100); 786 787 timer_start(scp); 788 timer_stop(scp); 789 /* 790 * actually, if we're in rdonly mode, we should start the timer 791 */ 792 /* 793 * TODO: Handle recording now 794 */ 795 796 scp->out_water = MIDIQ_SIZE(scp->out_q) / 2; 797 798 scp->busy = 1; 799 mtx_unlock(&scp->seq_lock); 800 |
795 SEQ_DEBUG(2,printf("seq_open: opened, mode %s.\n", 796 scp->music ? "music" : "sequencer")); 797 SEQ_DEBUG(2,printf("Sequencer %d %p opened maxunits %d midi_number %d:\n", scp->unit, scp, scp->maxunits, scp->midi_number)); 798 for (i=0;i<scp->midi_number;i++) 799 SEQ_DEBUG(3,printf(" midi %d %p\n", i, scp->midis[i])); | 801 SEQ_DEBUG(2, printf("seq_open: opened, mode %s.\n", 802 scp->music ? "music" : "sequencer")); 803 SEQ_DEBUG(2, 804 printf("Sequencer %d %p opened maxunits %d midi_number %d:\n", 805 scp->unit, scp, scp->maxunits, scp->midi_number)); 806 for (i = 0; i < scp->midi_number; i++) 807 SEQ_DEBUG(3, printf(" midi %d %p\n", i, scp->midis[i])); |
800 801 return 0; 802} 803 804/* 805 * seq_close 806 */ 807int 808seq_close(struct cdev *i_dev, int flags, int mode, struct thread *td) 809{ 810 int i; 811 struct seq_softc *scp = i_dev->si_drv1; 812 int ret; 813 814 if (scp == NULL) | 808 809 return 0; 810} 811 812/* 813 * seq_close 814 */ 815int 816seq_close(struct cdev *i_dev, int flags, int mode, struct thread *td) 817{ 818 int i; 819 struct seq_softc *scp = i_dev->si_drv1; 820 int ret; 821 822 if (scp == NULL) |
815 return ENXIO; | 823 return ENXIO; |
816 | 824 |
817 SEQ_DEBUG(2,printf("seq_close: unit %d.\n", scp->unit)); | 825 SEQ_DEBUG(2, printf("seq_close: unit %d.\n", scp->unit)); |
818 819 mtx_lock(&scp->seq_lock); 820 821 ret = ENXIO; 822 if (scp->busy == 0) | 826 827 mtx_lock(&scp->seq_lock); 828 829 ret = ENXIO; 830 if (scp->busy == 0) |
823 goto err; | 831 goto err; |
824 825 seq_reset(scp); 826 seq_sync(scp); 827 | 832 833 seq_reset(scp); 834 seq_sync(scp); 835 |
828 for (i = 0 ; i < scp->midi_number; i++) 829 if (scp->midis[i]) 830 SYNTH_CLOSE(scp->midis[i]); | 836 for (i = 0; i < scp->midi_number; i++) 837 if (scp->midis[i]) 838 SYNTH_CLOSE(scp->midis[i]); |
831 832 midimapper_close(scp->mapper, scp->mapper_cookie); 833 834 timer_stop(scp); 835 836 scp->busy = 0; 837 ret = 0; 838 839err: | 839 840 midimapper_close(scp->mapper, scp->mapper_cookie); 841 842 timer_stop(scp); 843 844 scp->busy = 0; 845 ret = 0; 846 847err: |
840 SEQ_DEBUG(3,printf("seq_close: closed ret = %d.\n", ret)); | 848 SEQ_DEBUG(3, printf("seq_close: closed ret = %d.\n", ret)); |
841 mtx_unlock(&scp->seq_lock); 842 return ret; 843} 844 845int 846seq_read(struct cdev *i_dev, struct uio *uio, int ioflag) 847{ 848 int retval, used; 849 struct seq_softc *scp = i_dev->si_drv1; | 849 mtx_unlock(&scp->seq_lock); 850 return ret; 851} 852 853int 854seq_read(struct cdev *i_dev, struct uio *uio, int ioflag) 855{ 856 int retval, used; 857 struct seq_softc *scp = i_dev->si_drv1; |
858 |
|
850#define SEQ_RSIZE 32 851 u_char buf[SEQ_RSIZE]; 852 853 if (scp == NULL) | 859#define SEQ_RSIZE 32 860 u_char buf[SEQ_RSIZE]; 861 862 if (scp == NULL) |
854 return ENXIO; | 863 return ENXIO; |
855 | 864 |
856 SEQ_DEBUG(7,printf("seq_read: unit %d, resid %d.\n", 857 scp->unit, uio->uio_resid)); | 865 SEQ_DEBUG(7, printf("seq_read: unit %d, resid %d.\n", 866 scp->unit, uio->uio_resid)); |
858 859 mtx_lock(&scp->seq_lock); 860 if ((scp->fflags & FREAD) == 0) { | 867 868 mtx_lock(&scp->seq_lock); 869 if ((scp->fflags & FREAD) == 0) { |
861 SEQ_DEBUG(2,printf("seq_read: unit %d is not for reading.\n", 862 scp->unit)); 863 retval = EIO; 864 goto err1; | 870 SEQ_DEBUG(2, printf("seq_read: unit %d is not for reading.\n", 871 scp->unit)); 872 retval = EIO; 873 goto err1; |
865 } | 874 } |
866 | |
867 /* 868 * Begin recording. 869 */ 870 /* 871 * if ((scp->flags & SEQ_F_READING) == 0) 872 */ 873 /* 874 * TODO, start recording if not alread 875 */ 876 877 /* 878 * I think the semantics are to return as soon 879 * as possible. 880 * Second thought, it doens't seem like midimoutain 881 * expects that at all. 882 * TODO: Look up in some sort of spec 883 */ 884 885 while (uio->uio_resid > 0) { | 875 /* 876 * Begin recording. 877 */ 878 /* 879 * if ((scp->flags & SEQ_F_READING) == 0) 880 */ 881 /* 882 * TODO, start recording if not alread 883 */ 884 885 /* 886 * I think the semantics are to return as soon 887 * as possible. 888 * Second thought, it doens't seem like midimoutain 889 * expects that at all. 890 * TODO: Look up in some sort of spec 891 */ 892 893 while (uio->uio_resid > 0) { |
886 while (MIDIQ_EMPTY(scp->in_q)) { 887 retval = EWOULDBLOCK; 888 /* 889 * I wish I knew which one to care about 890 */ | 894 while (MIDIQ_EMPTY(scp->in_q)) { 895 retval = EWOULDBLOCK; 896 /* 897 * I wish I knew which one to care about 898 */ |
891 | 899 |
892 if (scp->fflags & O_NONBLOCK) 893 goto err1; 894 if (ioflag & O_NONBLOCK) 895 goto err1; | 900 if (scp->fflags & O_NONBLOCK) 901 goto err1; 902 if (ioflag & O_NONBLOCK) 903 goto err1; |
896 | 904 |
897 retval = cv_wait_sig(&scp->in_cv, &scp->seq_lock); 898 if (retval == EINTR) 899 goto err1; 900 } | 905 retval = cv_wait_sig(&scp->in_cv, &scp->seq_lock); 906 if (retval == EINTR) 907 goto err1; 908 } |
901 | 909 |
902 used = MIN(MIDIQ_LEN(scp->in_q), uio->uio_resid); 903 used = MIN(used, SEQ_RSIZE); | 910 used = MIN(MIDIQ_LEN(scp->in_q), uio->uio_resid); 911 used = MIN(used, SEQ_RSIZE); |
904 | 912 |
905 SEQ_DEBUG(8,printf("midiread: uiomove cc=%d\n", used)); 906 MIDIQ_DEQ(scp->in_q, buf, used); 907 retval = uiomove(buf, used, uio); 908 if (retval) 909 goto err1; | 913 SEQ_DEBUG(8, printf("midiread: uiomove cc=%d\n", used)); 914 MIDIQ_DEQ(scp->in_q, buf, used); 915 retval = uiomove(buf, used, uio); 916 if (retval) 917 goto err1; |
910 } 911 912 retval = 0; 913err1: 914 mtx_unlock(&scp->seq_lock); | 918 } 919 920 retval = 0; 921err1: 922 mtx_unlock(&scp->seq_lock); |
915 SEQ_DEBUG(6,printf("seq_read: ret %d, resid %d.\n", 916 retval, uio->uio_resid)); | 923 SEQ_DEBUG(6, printf("seq_read: ret %d, resid %d.\n", 924 retval, uio->uio_resid)); |
917 918 return retval; 919} 920 921int 922seq_write(struct cdev *i_dev, struct uio *uio, int ioflag) 923{ 924 u_char event[EV_SZ], newevent[EV_SZ], ev_code; 925 struct seq_softc *scp = i_dev->si_drv1; 926 int retval; 927 int used; 928 | 925 926 return retval; 927} 928 929int 930seq_write(struct cdev *i_dev, struct uio *uio, int ioflag) 931{ 932 u_char event[EV_SZ], newevent[EV_SZ], ev_code; 933 struct seq_softc *scp = i_dev->si_drv1; 934 int retval; 935 int used; 936 |
929 SEQ_DEBUG(7,printf("seq_write: unit %d, resid %d.\n", 930 scp->unit, uio->uio_resid)); | 937 SEQ_DEBUG(7, printf("seq_write: unit %d, resid %d.\n", 938 scp->unit, uio->uio_resid)); |
931 932 if (scp == NULL) | 939 940 if (scp == NULL) |
933 return ENXIO; | 941 return ENXIO; |
934 935 mtx_lock(&scp->seq_lock); 936 937 if ((scp->fflags & FWRITE) == 0) { | 942 943 mtx_lock(&scp->seq_lock); 944 945 if ((scp->fflags & FWRITE) == 0) { |
938 SEQ_DEBUG(2,printf("seq_write: unit %d is not for writing.\n", 939 scp->unit)); 940 retval = EIO; 941 goto err0; | 946 SEQ_DEBUG(2, printf("seq_write: unit %d is not for writing.\n", 947 scp->unit)); 948 retval = EIO; 949 goto err0; |
942 } | 950 } |
943 | |
944 while (uio->uio_resid > 0) { | 951 while (uio->uio_resid > 0) { |
945 while (MIDIQ_AVAIL(scp->out_q) == 0) { 946 retval = EWOULDBLOCK; 947 if (scp->fflags & O_NONBLOCK) 948 goto err0; 949 if (ioflag & O_NONBLOCK) 950 goto err0; 951 SEQ_DEBUG(8,printf("seq_write cvwait\n")); | 952 while (MIDIQ_AVAIL(scp->out_q) == 0) { 953 retval = EWOULDBLOCK; 954 if (scp->fflags & O_NONBLOCK) 955 goto err0; 956 if (ioflag & O_NONBLOCK) 957 goto err0; 958 SEQ_DEBUG(8, printf("seq_write cvwait\n")); |
952 | 959 |
953 scp->playing = 1; 954 cv_broadcast(&scp->out_cv); 955 cv_broadcast(&scp->state_cv); | 960 scp->playing = 1; 961 cv_broadcast(&scp->out_cv); 962 cv_broadcast(&scp->state_cv); |
956 | 963 |
957 retval = cv_wait_sig(&scp->out_cv, &scp->seq_lock); 958 /* 959 * We slept, maybe things have changed since last 960 * dying check 961 */ 962 if (retval == EINTR) 963 goto err0; | 964 retval = cv_wait_sig(&scp->out_cv, &scp->seq_lock); 965 /* 966 * We slept, maybe things have changed since last 967 * dying check 968 */ 969 if (retval == EINTR) 970 goto err0; |
964#if 0 | 971#if 0 |
965 /* 966 * Useless test 967 */ 968 if (scp != i_dev->si_drv1) 969 retval = ENXIO; | 972 /* 973 * Useless test 974 */ 975 if (scp != i_dev->si_drv1) 976 retval = ENXIO; |
970#endif | 977#endif |
971 } | 978 } |
972 | 979 |
973 used = MIN(uio->uio_resid, 4); | 980 used = MIN(uio->uio_resid, 4); |
974 | 981 |
975 SEQ_DEBUG(8,printf("seqout: resid %d len %jd avail %jd\n", 976 uio->uio_resid, (intmax_t)MIDIQ_LEN(scp->out_q), 977 (intmax_t)MIDIQ_AVAIL(scp->out_q))); | 982 SEQ_DEBUG(8, printf("seqout: resid %d len %jd avail %jd\n", 983 uio->uio_resid, (intmax_t)MIDIQ_LEN(scp->out_q), 984 (intmax_t)MIDIQ_AVAIL(scp->out_q))); |
978 | 985 |
979 if (used != 4) { 980 retval = ENXIO; 981 goto err0; 982 } | 986 if (used != 4) { 987 retval = ENXIO; 988 goto err0; 989 } 990 retval = uiomove(event, used, uio); 991 if (retval) 992 goto err0; |
983 | 993 |
984 retval = uiomove(event, used, uio); 985 if (retval) 986 goto err0; | 994 ev_code = event[0]; 995 SEQ_DEBUG(8, printf("seq_write: unit %d, event %s.\n", 996 scp->unit, midi_cmdname(ev_code, cmdtab_seqevent))); |
987 | 997 |
988 ev_code = event[0]; 989 SEQ_DEBUG(8,printf("seq_write: unit %d, event %s.\n", 990 scp->unit, midi_cmdname(ev_code, cmdtab_seqevent))); | 998 /* Have a look at the event code. */ 999 if (ev_code == SEQ_FULLSIZE) { |
991 | 1000 |
992 /* Have a look at the event code. */ 993 if (ev_code == SEQ_FULLSIZE) { 994 995 /* 996 * TODO: restore code for SEQ_FULLSIZE 997 */ | 1001 /* 1002 * TODO: restore code for SEQ_FULLSIZE 1003 */ |
998#if 0 | 1004#if 0 |
999 /* A long event, these are the patches/samples for a synthesizer. */ 1000 midiunit = *(u_short *)&event[2]; 1001 mtx_lock(&sd->seq_lock); 1002 ret = lookup_mididev(scp, midiunit, LOOKUP_OPEN, &md); 1003 mtx_unlock(&sd->seq_lock); 1004 if (ret != 0) 1005 return (ret); | 1005 /* 1006 * A long event, these are the patches/samples for a 1007 * synthesizer. 1008 */ 1009 midiunit = *(u_short *)&event[2]; 1010 mtx_lock(&sd->seq_lock); 1011 ret = lookup_mididev(scp, midiunit, LOOKUP_OPEN, &md); 1012 mtx_unlock(&sd->seq_lock); 1013 if (ret != 0) 1014 return (ret); |
1006 | 1015 |
1007 SEQ_DEBUG(printf("seq_write: loading a patch to the unit %d.\n", midiunit)); | 1016 SEQ_DEBUG(printf("seq_write: loading a patch to the unit %d.\n", midiunit)); |
1008 | 1017 |
1009 ret = md->synth.loadpatch(md, *(short *)&event[0], buf, p + 4, count, 0); 1010 return (ret); | 1018 ret = md->synth.loadpatch(md, *(short *)&event[0], buf, 1019 p + 4, count, 0); 1020 return (ret); |
1011#else | 1021#else |
1012 /* 1013 * For now, just flush the darn buffer 1014 */ 1015 SEQ_DEBUG(2,printf("seq_write: SEQ_FULLSIZE flusing buffer.\n")); 1016 while (uio->uio_resid > 0) { 1017 retval = uiomove(event, EV_SZ, uio); 1018 if (retval) 1019 goto err0; | 1022 /* 1023 * For now, just flush the darn buffer 1024 */ 1025 SEQ_DEBUG(2, 1026 printf("seq_write: SEQ_FULLSIZE flusing buffer.\n")); 1027 while (uio->uio_resid > 0) { 1028 retval = uiomove(event, EV_SZ, uio); 1029 if (retval) 1030 goto err0; |
1020 | 1031 |
1021 } 1022 retval = 0; 1023 goto err0; | 1032 } 1033 retval = 0; 1034 goto err0; |
1024#endif | 1035#endif |
1025 } | 1036 } 1037 retval = EINVAL; 1038 if (ev_code >= 128) { |
1026 | 1039 |
1027 retval = EINVAL; 1028 if (ev_code >= 128) { 1029 1030 /* 1031 * Some sort of an extended event. The size is eight bytes. 1032 * scoop extra info. 1033 */ 1034 if (scp->music && ev_code == SEQ_EXTENDED) { 1035 SEQ_DEBUG(2,printf("seq_write: invalid level two event %x.\n", ev_code)); 1036 goto err0; | 1040 /* 1041 * Some sort of an extended event. The size is eight 1042 * bytes. scoop extra info. 1043 */ 1044 if (scp->music && ev_code == SEQ_EXTENDED) { 1045 SEQ_DEBUG(2, printf("seq_write: invalid level two event %x.\n", ev_code)); 1046 goto err0; 1047 } 1048 if (uiomove((caddr_t)&event[4], 4, uio)) { 1049 SEQ_DEBUG(2, 1050 printf("seq_write: user memory mangled?\n")); 1051 goto err0; 1052 } 1053 } else { 1054 /* 1055 * Size four event. 1056 */ 1057 if (scp->music) { 1058 SEQ_DEBUG(2, printf("seq_write: four byte event in music mode.\n")); 1059 goto err0; 1060 } |
1037 } | 1061 } |
1038 if (uiomove((caddr_t)&event[4], 4, uio)) { 1039 SEQ_DEBUG(2,printf("seq_write: user memory mangled?\n")); 1040 goto err0; | 1062 if (ev_code == SEQ_MIDIPUTC) { 1063 /* 1064 * TODO: event[2] is unit number to receive char. 1065 * Range check it. 1066 */ |
1041 } | 1067 } |
1042 } else { 1043 /* 1044 * Size four event. 1045 */ | |
1046 if (scp->music) { | 1068 if (scp->music) { |
1047 SEQ_DEBUG(2,printf("seq_write: four byte event in music mode.\n")); 1048 goto err0; 1049 } 1050 } 1051 if (ev_code == SEQ_MIDIPUTC) { 1052 /* 1053 * TODO: event[2] is unit number to receive char. Range check 1054 * it 1055 */ 1056 } 1057 1058 if (scp->music) { | |
1059#ifdef not_ever_ever | 1069#ifdef not_ever_ever |
1060 if (event[0] == EV_TIMING && 1061 (event[1] == TMR_START || event[1] == TMR_STOP) ) { 1062 /* 1063 * For now, try to make midimoutain work by 1064 * forcing these events to be processed immediatly 1065 */ 1066 seq_processevent(scp, event); 1067 } 1068 else 1069 MIDIQ_ENQ(scp->out_q, event, EV_SZ); | 1070 if (event[0] == EV_TIMING && 1071 (event[1] == TMR_START || event[1] == TMR_STOP)) { 1072 /* 1073 * For now, try to make midimoutain work by 1074 * forcing these events to be processed 1075 * immediatly. 1076 */ 1077 seq_processevent(scp, event); 1078 } else 1079 MIDIQ_ENQ(scp->out_q, event, EV_SZ); |
1070#else | 1080#else |
1071 MIDIQ_ENQ(scp->out_q, event, EV_SZ); | 1081 MIDIQ_ENQ(scp->out_q, event, EV_SZ); |
1072#endif | 1082#endif |
1073 } else { 1074 if (seq_convertold(event, newevent) > 0) 1075 MIDIQ_ENQ(scp->out_q, newevent, EV_SZ); | 1083 } else { 1084 if (seq_convertold(event, newevent) > 0) 1085 MIDIQ_ENQ(scp->out_q, newevent, EV_SZ); |
1076#if 0 | 1086#if 0 |
1077 else 1078 goto err0; | 1087 else 1088 goto err0; |
1079#endif | 1089#endif |
1080 } | 1090 } |
1081 1082 } 1083 1084 scp->playing = 1; 1085 cv_broadcast(&scp->state_cv); 1086 cv_broadcast(&scp->out_cv); 1087 1088 retval = 0; 1089 1090err0: | 1091 1092 } 1093 1094 scp->playing = 1; 1095 cv_broadcast(&scp->state_cv); 1096 cv_broadcast(&scp->out_cv); 1097 1098 retval = 0; 1099 1100err0: |
1091 SEQ_DEBUG(6,printf("seq_write done: leftover buffer length %d retval %d\n", 1092 uio->uio_resid, retval)); | 1101 SEQ_DEBUG(6, 1102 printf("seq_write done: leftover buffer length %d retval %d\n", 1103 uio->uio_resid, retval)); |
1093 mtx_unlock(&scp->seq_lock); 1094 return retval; 1095} 1096 1097int | 1104 mtx_unlock(&scp->seq_lock); 1105 return retval; 1106} 1107 1108int |
1098seq_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *td) | 1109seq_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, 1110 struct thread *td) |
1099{ 1100 int midiunit, ret, tmp; 1101 struct seq_softc *scp = i_dev->si_drv1; 1102 struct synth_info *synthinfo; 1103 struct midi_info *midiinfo; 1104 u_char event[EV_SZ]; 1105 u_char newevent[EV_SZ]; 1106 1107 kobj_t md; | 1111{ 1112 int midiunit, ret, tmp; 1113 struct seq_softc *scp = i_dev->si_drv1; 1114 struct synth_info *synthinfo; 1115 struct midi_info *midiinfo; 1116 u_char event[EV_SZ]; 1117 u_char newevent[EV_SZ]; 1118 1119 kobj_t md; |
1120 |
|
1108 /* 1109 * struct snd_size *sndsize; 1110 */ 1111 1112 if (scp == NULL) | 1121 /* 1122 * struct snd_size *sndsize; 1123 */ 1124 1125 if (scp == NULL) |
1113 return ENXIO; | 1126 return ENXIO; |
1114 | 1127 |
1115 SEQ_DEBUG(6,printf("seq_ioctl: unit %d, cmd %s.\n", 1116 scp->unit, midi_cmdname(cmd, cmdtab_seqioctl))); | 1128 SEQ_DEBUG(6, printf("seq_ioctl: unit %d, cmd %s.\n", 1129 scp->unit, midi_cmdname(cmd, cmdtab_seqioctl))); |
1117 1118 ret = 0; 1119 1120 switch (cmd) { | 1130 1131 ret = 0; 1132 1133 switch (cmd) { |
1121 case SNDCTL_SEQ_GETTIME: | 1134 case SNDCTL_SEQ_GETTIME: |
1122 /* 1123 * ioctl needed by libtse 1124 */ 1125 mtx_lock(&scp->seq_lock); 1126 *(int *)arg = timer_now(scp); 1127 mtx_unlock(&scp->seq_lock); | 1135 /* 1136 * ioctl needed by libtse 1137 */ 1138 mtx_lock(&scp->seq_lock); 1139 *(int *)arg = timer_now(scp); 1140 mtx_unlock(&scp->seq_lock); |
1128 SEQ_DEBUG(6,printf("seq_ioctl: gettime %d.\n", *(int *)arg)); | 1141 SEQ_DEBUG(6, printf("seq_ioctl: gettime %d.\n", *(int *)arg)); |
1129 ret = 0; 1130 break; | 1142 ret = 0; 1143 break; |
1131 case SNDCTL_TMR_METRONOME: | 1144 case SNDCTL_TMR_METRONOME: |
1132 /* fallthrough */ | 1145 /* fallthrough */ |
1133 case SNDCTL_TMR_SOURCE: | 1146 case SNDCTL_TMR_SOURCE: |
1134 /* 1135 * Not implemented 1136 */ 1137 ret = 0; 1138 break; | 1147 /* 1148 * Not implemented 1149 */ 1150 ret = 0; 1151 break; |
1139 case SNDCTL_TMR_TEMPO: | 1152 case SNDCTL_TMR_TEMPO: |
1140 event[1] = TMR_TEMPO; 1141 event[4] = *(int *)arg & 0xFF; 1142 event[5] = (*(int *)arg >> 8) & 0xFF; 1143 event[6] = (*(int *)arg >> 16) & 0xFF; 1144 event[7] = (*(int *)arg >> 24) & 0xFF; 1145 goto timerevent; | 1153 event[1] = TMR_TEMPO; 1154 event[4] = *(int *)arg & 0xFF; 1155 event[5] = (*(int *)arg >> 8) & 0xFF; 1156 event[6] = (*(int *)arg >> 16) & 0xFF; 1157 event[7] = (*(int *)arg >> 24) & 0xFF; 1158 goto timerevent; |
1146 case SNDCTL_TMR_TIMEBASE: | 1159 case SNDCTL_TMR_TIMEBASE: |
1147 event[1] = TMR_TIMERBASE; 1148 event[4] = *(int *)arg & 0xFF; 1149 event[5] = (*(int *)arg >> 8) & 0xFF; 1150 event[6] = (*(int *)arg >> 16) & 0xFF; 1151 event[7] = (*(int *)arg >> 24) & 0xFF; 1152 goto timerevent; | 1160 event[1] = TMR_TIMERBASE; 1161 event[4] = *(int *)arg & 0xFF; 1162 event[5] = (*(int *)arg >> 8) & 0xFF; 1163 event[6] = (*(int *)arg >> 16) & 0xFF; 1164 event[7] = (*(int *)arg >> 24) & 0xFF; 1165 goto timerevent; |
1153 case SNDCTL_TMR_START: | 1166 case SNDCTL_TMR_START: |
1154 event[1] = TMR_START; 1155 goto timerevent; | 1167 event[1] = TMR_START; 1168 goto timerevent; |
1156 case SNDCTL_TMR_STOP: | 1169 case SNDCTL_TMR_STOP: |
1157 event[1] = TMR_STOP; 1158 goto timerevent; | 1170 event[1] = TMR_STOP; 1171 goto timerevent; |
1159 case SNDCTL_TMR_CONTINUE: | 1172 case SNDCTL_TMR_CONTINUE: |
1160 event[1] = TMR_CONTINUE; | 1173 event[1] = TMR_CONTINUE; |
1161 timerevent: | 1174timerevent: |
1162 event[0] = EV_TIMING; 1163 mtx_lock(&scp->seq_lock); 1164 if (!scp->music) { | 1175 event[0] = EV_TIMING; 1176 mtx_lock(&scp->seq_lock); 1177 if (!scp->music) { |
1165 ret = EINVAL; 1166 mtx_unlock(&scp->seq_lock); 1167 break; | 1178 ret = EINVAL; 1179 mtx_unlock(&scp->seq_lock); 1180 break; |
1168 } 1169 seq_processevent(scp, event); 1170 mtx_unlock(&scp->seq_lock); 1171 break; | 1181 } 1182 seq_processevent(scp, event); 1183 mtx_unlock(&scp->seq_lock); 1184 break; |
1172 case SNDCTL_TMR_SELECT: 1173 SEQ_DEBUG(2,printf("seq_ioctl: SNDCTL_TMR_SELECT not supported\n")); | 1185 case SNDCTL_TMR_SELECT: 1186 SEQ_DEBUG(2, 1187 printf("seq_ioctl: SNDCTL_TMR_SELECT not supported\n")); |
1174 ret = EINVAL; 1175 break; | 1188 ret = EINVAL; 1189 break; |
1176 case SNDCTL_SEQ_SYNC: | 1190 case SNDCTL_SEQ_SYNC: |
1177 if (mode == O_RDONLY) { | 1191 if (mode == O_RDONLY) { |
1178 ret = 0; 1179 break; | 1192 ret = 0; 1193 break; |
1180 } 1181 mtx_lock(&scp->seq_lock); 1182 ret = seq_sync(scp); 1183 mtx_unlock(&scp->seq_lock); 1184 break; | 1194 } 1195 mtx_lock(&scp->seq_lock); 1196 ret = seq_sync(scp); 1197 mtx_unlock(&scp->seq_lock); 1198 break; |
1185 case SNDCTL_SEQ_PANIC: | 1199 case SNDCTL_SEQ_PANIC: |
1186 /* fallthrough */ | 1200 /* fallthrough */ |
1187 case SNDCTL_SEQ_RESET: | 1201 case SNDCTL_SEQ_RESET: |
1188 /* 1189 * SNDCTL_SEQ_PANIC == SNDCTL_SEQ_RESET 1190 */ 1191 mtx_lock(&scp->seq_lock); 1192 seq_reset(scp); 1193 mtx_unlock(&scp->seq_lock); 1194 ret = 0; 1195 break; | 1202 /* 1203 * SNDCTL_SEQ_PANIC == SNDCTL_SEQ_RESET 1204 */ 1205 mtx_lock(&scp->seq_lock); 1206 seq_reset(scp); 1207 mtx_unlock(&scp->seq_lock); 1208 ret = 0; 1209 break; |
1196 case SNDCTL_SEQ_TESTMIDI: | 1210 case SNDCTL_SEQ_TESTMIDI: |
1197 mtx_lock(&scp->seq_lock); 1198 /* 1199 * TODO: SNDCTL_SEQ_TESTMIDI now means "can I write to the 1200 * device?". 1201 */ 1202 mtx_unlock(&scp->seq_lock); 1203 break; 1204#if 0 | 1211 mtx_lock(&scp->seq_lock); 1212 /* 1213 * TODO: SNDCTL_SEQ_TESTMIDI now means "can I write to the 1214 * device?". 1215 */ 1216 mtx_unlock(&scp->seq_lock); 1217 break; 1218#if 0 |
1205 case SNDCTL_SEQ_GETINCOUNT: | 1219 case SNDCTL_SEQ_GETINCOUNT: |
1206 if (mode == O_WRONLY) | 1220 if (mode == O_WRONLY) |
1207 *(int *)arg = 0; | 1221 *(int *)arg = 0; |
1208 else { | 1222 else { |
1209 mtx_lock(&scp->seq_lock); 1210 *(int *)arg = scp->in_q.rl; 1211 mtx_unlock(&scp->seq_lock); 1212 SEQ_DEBUG(printf("seq_ioctl: incount %d.\n", *(int *)arg)); | 1223 mtx_lock(&scp->seq_lock); 1224 *(int *)arg = scp->in_q.rl; 1225 mtx_unlock(&scp->seq_lock); 1226 SEQ_DEBUG(printf("seq_ioctl: incount %d.\n", 1227 *(int *)arg)); |
1213 } 1214 ret = 0; 1215 break; | 1228 } 1229 ret = 0; 1230 break; |
1216 case SNDCTL_SEQ_GETOUTCOUNT: | 1231 case SNDCTL_SEQ_GETOUTCOUNT: |
1217 if (mode == O_RDONLY) | 1232 if (mode == O_RDONLY) |
1218 *(int *)arg = 0; | 1233 *(int *)arg = 0; |
1219 else { | 1234 else { |
1220 mtx_lock(&scp->seq_lock); 1221 *(int *)arg = scp->out_q.fl; 1222 mtx_unlock(&scp->seq_lock); 1223 SEQ_DEBUG(printf("seq_ioctl: outcount %d.\n", *(int *)arg)); | 1235 mtx_lock(&scp->seq_lock); 1236 *(int *)arg = scp->out_q.fl; 1237 mtx_unlock(&scp->seq_lock); 1238 SEQ_DEBUG(printf("seq_ioctl: outcount %d.\n", 1239 *(int *)arg)); |
1224 } 1225 ret = 0; 1226 break; 1227#endif | 1240 } 1241 ret = 0; 1242 break; 1243#endif |
1228 case SNDCTL_SEQ_CTRLRATE: | 1244 case SNDCTL_SEQ_CTRLRATE: |
1229 if (*(int *)arg != 0) { | 1245 if (*(int *)arg != 0) { |
1230 ret = EINVAL; 1231 break; | 1246 ret = EINVAL; 1247 break; |
1232 } 1233 mtx_lock(&scp->seq_lock); 1234 *(int *)arg = scp->timerbase; 1235 mtx_unlock(&scp->seq_lock); | 1248 } 1249 mtx_lock(&scp->seq_lock); 1250 *(int *)arg = scp->timerbase; 1251 mtx_unlock(&scp->seq_lock); |
1236 SEQ_DEBUG(3,printf("seq_ioctl: ctrlrate %d.\n", *(int *)arg)); | 1252 SEQ_DEBUG(3, printf("seq_ioctl: ctrlrate %d.\n", *(int *)arg)); |
1237 ret = 0; 1238 break; 1239 /* 1240 * TODO: ioctl SNDCTL_SEQ_RESETSAMPLES 1241 */ 1242#if 0 | 1253 ret = 0; 1254 break; 1255 /* 1256 * TODO: ioctl SNDCTL_SEQ_RESETSAMPLES 1257 */ 1258#if 0 |
1243 case SNDCTL_SEQ_RESETSAMPLES: | 1259 case SNDCTL_SEQ_RESETSAMPLES: |
1244 mtx_lock(&scp->seq_lock); 1245 ret = lookup_mididev(scp, *(int *)arg, LOOKUP_OPEN, &md); 1246 mtx_unlock(&scp->seq_lock); 1247 if (ret != 0) | 1260 mtx_lock(&scp->seq_lock); 1261 ret = lookup_mididev(scp, *(int *)arg, LOOKUP_OPEN, &md); 1262 mtx_unlock(&scp->seq_lock); 1263 if (ret != 0) |
1248 break; 1249 ret = midi_ioctl(MIDIMKDEV(major(i_dev), *(int *)arg, SND_DEV_MIDIN), cmd, arg, mode, td); | 1264 break; 1265 ret = midi_ioctl(MIDIMKDEV(major(i_dev), *(int *)arg, 1266 SND_DEV_MIDIN), cmd, arg, mode, td); |
1250 break; 1251#endif | 1267 break; 1268#endif |
1252 case SNDCTL_SEQ_NRSYNTHS: | 1269 case SNDCTL_SEQ_NRSYNTHS: |
1253 mtx_lock(&scp->seq_lock); | 1270 mtx_lock(&scp->seq_lock); |
1254 *(int *)arg = scp->midi_number; | 1271 *(int *)arg = scp->midi_number; |
1255 mtx_unlock(&scp->seq_lock); | 1272 mtx_unlock(&scp->seq_lock); |
1256 SEQ_DEBUG(3,printf("seq_ioctl: synths %d.\n", *(int *)arg)); | 1273 SEQ_DEBUG(3, printf("seq_ioctl: synths %d.\n", *(int *)arg)); |
1257 ret = 0; 1258 break; | 1274 ret = 0; 1275 break; |
1259 case SNDCTL_SEQ_NRMIDIS: | 1276 case SNDCTL_SEQ_NRMIDIS: |
1260 mtx_lock(&scp->seq_lock); 1261 if (scp->music) | 1277 mtx_lock(&scp->seq_lock); 1278 if (scp->music) |
1262 *(int *)arg = 0; | 1279 *(int *)arg = 0; |
1263 else { | 1280 else { |
1264 /* 1265 * TODO: count the numbder of devices that can WRITERAW 1266 */ 1267 *(int *)arg = scp->midi_number; | 1281 /* 1282 * TODO: count the numbder of devices that can WRITERAW 1283 */ 1284 *(int *)arg = scp->midi_number; |
1268 } 1269 mtx_unlock(&scp->seq_lock); | 1285 } 1286 mtx_unlock(&scp->seq_lock); |
1270 SEQ_DEBUG(3,printf("seq_ioctl: midis %d.\n", *(int *)arg)); | 1287 SEQ_DEBUG(3, printf("seq_ioctl: midis %d.\n", *(int *)arg)); |
1271 ret = 0; 1272 break; 1273 /* 1274 * TODO: ioctl SNDCTL_SYNTH_MEMAVL 1275 */ 1276#if 0 | 1288 ret = 0; 1289 break; 1290 /* 1291 * TODO: ioctl SNDCTL_SYNTH_MEMAVL 1292 */ 1293#if 0 |
1277 case SNDCTL_SYNTH_MEMAVL: | 1294 case SNDCTL_SYNTH_MEMAVL: |
1278 mtx_lock(&scp->seq_lock); 1279 ret = lookup_mididev(scp, *(int *)arg, LOOKUP_OPEN, &md); 1280 mtx_unlock(&scp->seq_lock); 1281 if (ret != 0) | 1295 mtx_lock(&scp->seq_lock); 1296 ret = lookup_mididev(scp, *(int *)arg, LOOKUP_OPEN, &md); 1297 mtx_unlock(&scp->seq_lock); 1298 if (ret != 0) |
1282 break; 1283 ret = midi_ioctl(MIDIMKDEV(major(i_dev), *(int *)arg, SND_DEV_MIDIN), cmd, arg, mode, td); | 1299 break; 1300 ret = midi_ioctl(MIDIMKDEV(major(i_dev), *(int *)arg, 1301 SND_DEV_MIDIN), cmd, arg, mode, td); |
1284 break; 1285#endif | 1302 break; 1303#endif |
1286 case SNDCTL_SEQ_OUTOFBAND: | 1304 case SNDCTL_SEQ_OUTOFBAND: |
1287 for (ret = 0; ret < EV_SZ; ret++) | 1305 for (ret = 0; ret < EV_SZ; ret++) |
1288 event[ret] = (u_char)arg[0]; | 1306 event[ret] = (u_char)arg[0]; |
1289 1290 mtx_lock(&scp->seq_lock); 1291 if (scp->music) | 1307 1308 mtx_lock(&scp->seq_lock); 1309 if (scp->music) |
1292 ret = seq_processevent(scp, event); | 1310 ret = seq_processevent(scp, event); |
1293 else { | 1311 else { |
1294 if (seq_convertold(event, newevent) > 0) 1295 ret = seq_processevent(scp, newevent); 1296 else ret = EINVAL; | 1312 if (seq_convertold(event, newevent) > 0) 1313 ret = seq_processevent(scp, newevent); 1314 else 1315 ret = EINVAL; |
1297 } 1298 mtx_unlock(&scp->seq_lock); 1299 break; | 1316 } 1317 mtx_unlock(&scp->seq_lock); 1318 break; |
1300 case SNDCTL_SYNTH_INFO: | 1319 case SNDCTL_SYNTH_INFO: |
1301 synthinfo = (struct synth_info *)arg; 1302 midiunit = synthinfo->device; 1303 mtx_lock(&scp->seq_lock); 1304 if (seq_fetch_mid(scp, midiunit, &md) == 0) { | 1320 synthinfo = (struct synth_info *)arg; 1321 midiunit = synthinfo->device; 1322 mtx_lock(&scp->seq_lock); 1323 if (seq_fetch_mid(scp, midiunit, &md) == 0) { |
1305 bzero(synthinfo, sizeof(*synthinfo)); 1306 synthinfo->name[0] = 'f'; 1307 synthinfo->name[1] = 'a'; 1308 synthinfo->name[2] = 'k'; 1309 synthinfo->name[3] = 'e'; 1310 synthinfo->name[4] = 's'; 1311 synthinfo->name[5] = 'y'; 1312 synthinfo->name[6] = 'n'; 1313 synthinfo->name[7] = 't'; 1314 synthinfo->name[8] = 'h'; 1315 synthinfo->device = midiunit; 1316 synthinfo->synth_type = SYNTH_TYPE_MIDI; 1317 synthinfo->capabilities = scp->midi_flags[midiunit]; 1318 ret = 0; | 1324 bzero(synthinfo, sizeof(*synthinfo)); 1325 synthinfo->name[0] = 'f'; 1326 synthinfo->name[1] = 'a'; 1327 synthinfo->name[2] = 'k'; 1328 synthinfo->name[3] = 'e'; 1329 synthinfo->name[4] = 's'; 1330 synthinfo->name[5] = 'y'; 1331 synthinfo->name[6] = 'n'; 1332 synthinfo->name[7] = 't'; 1333 synthinfo->name[8] = 'h'; 1334 synthinfo->device = midiunit; 1335 synthinfo->synth_type = SYNTH_TYPE_MIDI; 1336 synthinfo->capabilities = scp->midi_flags[midiunit]; 1337 ret = 0; |
1319 } else | 1338 } else |
1320 ret = EINVAL; | 1339 ret = EINVAL; |
1321 mtx_unlock(&scp->seq_lock); 1322 break; | 1340 mtx_unlock(&scp->seq_lock); 1341 break; |
1323 case SNDCTL_MIDI_INFO: | 1342 case SNDCTL_MIDI_INFO: |
1324 midiinfo = (struct midi_info *)arg; 1325 midiunit = midiinfo->device; 1326 mtx_lock(&scp->seq_lock); 1327 if (seq_fetch_mid(scp, midiunit, &md) == 0) { | 1343 midiinfo = (struct midi_info *)arg; 1344 midiunit = midiinfo->device; 1345 mtx_lock(&scp->seq_lock); 1346 if (seq_fetch_mid(scp, midiunit, &md) == 0) { |
1328 bzero(midiinfo, sizeof(*midiinfo)); 1329 midiinfo->name[0] = 'f'; 1330 midiinfo->name[1] = 'a'; 1331 midiinfo->name[2] = 'k'; 1332 midiinfo->name[3] = 'e'; 1333 midiinfo->name[4] = 'm'; 1334 midiinfo->name[5] = 'i'; 1335 midiinfo->name[6] = 'd'; 1336 midiinfo->name[7] = 'i'; 1337 midiinfo->device = midiunit; 1338 midiinfo->capabilities = scp->midi_flags[midiunit]; 1339 /* 1340 * TODO: What devtype? 1341 */ 1342 midiinfo->dev_type = 0x01; 1343 ret = 0; | 1347 bzero(midiinfo, sizeof(*midiinfo)); 1348 midiinfo->name[0] = 'f'; 1349 midiinfo->name[1] = 'a'; 1350 midiinfo->name[2] = 'k'; 1351 midiinfo->name[3] = 'e'; 1352 midiinfo->name[4] = 'm'; 1353 midiinfo->name[5] = 'i'; 1354 midiinfo->name[6] = 'd'; 1355 midiinfo->name[7] = 'i'; 1356 midiinfo->device = midiunit; 1357 midiinfo->capabilities = scp->midi_flags[midiunit]; 1358 /* 1359 * TODO: What devtype? 1360 */ 1361 midiinfo->dev_type = 0x01; 1362 ret = 0; |
1344 } else | 1363 } else |
1345 ret = EINVAL; | 1364 ret = EINVAL; |
1346 mtx_unlock(&scp->seq_lock); 1347 break; | 1365 mtx_unlock(&scp->seq_lock); 1366 break; |
1348 case SNDCTL_SEQ_THRESHOLD: | 1367 case SNDCTL_SEQ_THRESHOLD: |
1349 mtx_lock(&scp->seq_lock); 1350 RANGE(*(int *)arg, 1, MIDIQ_SIZE(scp->out_q) - 1); 1351 scp->out_water = *(int *)arg; 1352 mtx_unlock(&scp->seq_lock); | 1368 mtx_lock(&scp->seq_lock); 1369 RANGE(*(int *)arg, 1, MIDIQ_SIZE(scp->out_q) - 1); 1370 scp->out_water = *(int *)arg; 1371 mtx_unlock(&scp->seq_lock); |
1353 SEQ_DEBUG(3,printf("seq_ioctl: water %d.\n", *(int *)arg)); | 1372 SEQ_DEBUG(3, printf("seq_ioctl: water %d.\n", *(int *)arg)); |
1354 ret = 0; 1355 break; | 1373 ret = 0; 1374 break; |
1356 case SNDCTL_MIDI_PRETIME: | 1375 case SNDCTL_MIDI_PRETIME: |
1357 tmp = *(int *)arg; 1358 if (tmp < 0) | 1376 tmp = *(int *)arg; 1377 if (tmp < 0) |
1359 tmp = 0; | 1378 tmp = 0; |
1360 mtx_lock(&scp->seq_lock); 1361 scp->pre_event_timeout = (hz * tmp) / 10; 1362 *(int *)arg = scp->pre_event_timeout; 1363 mtx_unlock(&scp->seq_lock); | 1379 mtx_lock(&scp->seq_lock); 1380 scp->pre_event_timeout = (hz * tmp) / 10; 1381 *(int *)arg = scp->pre_event_timeout; 1382 mtx_unlock(&scp->seq_lock); |
1364 SEQ_DEBUG(3,printf("seq_ioctl: pretime %d.\n", *(int *)arg)); | 1383 SEQ_DEBUG(3, printf("seq_ioctl: pretime %d.\n", *(int *)arg)); |
1365 ret = 0; 1366 break; | 1384 ret = 0; 1385 break; |
1367 case SNDCTL_FM_4OP_ENABLE: 1368 case SNDCTL_PMGR_IFACE: 1369 case SNDCTL_PMGR_ACCESS: | 1386 case SNDCTL_FM_4OP_ENABLE: 1387 case SNDCTL_PMGR_IFACE: 1388 case SNDCTL_PMGR_ACCESS: |
1370 /* 1371 * Patch manager and fm are ded, ded, ded. 1372 */ 1373 /* fallthrough */ | 1389 /* 1390 * Patch manager and fm are ded, ded, ded. 1391 */ 1392 /* fallthrough */ |
1374 default: | 1393 default: |
1375 /* 1376 * TODO: Consider ioctl default case. 1377 * Old code used to 1378 * if ((scp->fflags & O_ACCMODE) == FREAD) { 1379 * ret = EIO; 1380 * break; 1381 * } 1382 * Then pass on the ioctl to device 0 1383 */ | 1394 /* 1395 * TODO: Consider ioctl default case. 1396 * Old code used to 1397 * if ((scp->fflags & O_ACCMODE) == FREAD) { 1398 * ret = EIO; 1399 * break; 1400 * } 1401 * Then pass on the ioctl to device 0 1402 */ |
1384 SEQ_DEBUG(2,printf("seq_ioctl: unsupported IOCTL %ld.\n", cmd)); | 1403 SEQ_DEBUG(2, 1404 printf("seq_ioctl: unsupported IOCTL %ld.\n", cmd)); |
1385 ret = EINVAL; 1386 break; 1387 } 1388 1389 return ret; 1390} 1391 1392int --- 6 unchanged lines hidden (view full) --- 1399 SEQ_DEBUG(1, printf("seq_poll: unit %d.\n", scp->unit)); 1400 1401 mtx_lock(&scp->seq_lock); 1402 1403 ret = 0; 1404 1405 /* Look up the apropriate queue and select it. */ 1406 if ((events & (POLLOUT | POLLWRNORM)) != 0) { | 1405 ret = EINVAL; 1406 break; 1407 } 1408 1409 return ret; 1410} 1411 1412int --- 6 unchanged lines hidden (view full) --- 1419 SEQ_DEBUG(1, printf("seq_poll: unit %d.\n", scp->unit)); 1420 1421 mtx_lock(&scp->seq_lock); 1422 1423 ret = 0; 1424 1425 /* Look up the apropriate queue and select it. */ 1426 if ((events & (POLLOUT | POLLWRNORM)) != 0) { |
1407 /* Start playing. */ 1408 scp->playing = 1; 1409 cv_broadcast(&scp->state_cv); 1410 cv_broadcast(&scp->out_cv); | 1427 /* Start playing. */ 1428 scp->playing = 1; 1429 cv_broadcast(&scp->state_cv); 1430 cv_broadcast(&scp->out_cv); |
1411 | 1431 |
1412 lim = scp->out_water; | 1432 lim = scp->out_water; |
1413 | 1433 |
1414 if (MIDIQ_AVAIL(scp->out_q) < lim) 1415 /* No enough space, record select. */ 1416 selrecord(td, &scp->out_sel); 1417 else 1418 /* We can write now. */ 1419 ret |= events & (POLLOUT | POLLWRNORM); | 1434 if (MIDIQ_AVAIL(scp->out_q) < lim) 1435 /* No enough space, record select. */ 1436 selrecord(td, &scp->out_sel); 1437 else 1438 /* We can write now. */ 1439 ret |= events & (POLLOUT | POLLWRNORM); |
1420 } | 1440 } |
1421 | |
1422 if ((events & (POLLIN | POLLRDNORM)) != 0) { | 1441 if ((events & (POLLIN | POLLRDNORM)) != 0) { |
1423 /* TODO: Start recording. */ | 1442 /* TODO: Start recording. */ |
1424 | 1443 |
1425 /* Find out the boundary. */ 1426 lim = 1; 1427 if (MIDIQ_LEN(scp->in_q) < lim) 1428 /* No data ready, record select. */ 1429 selrecord(td, &scp->in_sel); 1430 else 1431 /* We can read now. */ 1432 ret |= events & (POLLIN | POLLRDNORM); | 1444 /* Find out the boundary. */ 1445 lim = 1; 1446 if (MIDIQ_LEN(scp->in_q) < lim) 1447 /* No data ready, record select. */ 1448 selrecord(td, &scp->in_sel); 1449 else 1450 /* We can read now. */ 1451 ret |= events & (POLLIN | POLLRDNORM); |
1433 } | 1452 } |
1434 | |
1435 mtx_unlock(&scp->seq_lock); 1436 1437 return (ret); 1438} | 1453 mtx_unlock(&scp->seq_lock); 1454 1455 return (ret); 1456} |
1457 |
|
1439#if 0 1440static void 1441sein_qtr(void *p, void /* mididev_info */ *md) 1442{ 1443 struct seq_softc *scp; 1444 1445 scp = (struct seq_softc *)p; 1446 1447 mtx_lock(&scp->seq_lock); 1448 1449 /* Restart playing if we have the data to output. */ 1450 if (scp->queueout_pending) 1451 seq_callback(scp, SEQ_CB_START | SEQ_CB_WR); 1452 /* Check the midi device if we are reading. */ 1453 if ((scp->flags & SEQ_F_READING) != 0) 1454 seq_midiinput(scp, md); 1455 1456 mtx_unlock(&scp->seq_lock); 1457} | 1458#if 0 1459static void 1460sein_qtr(void *p, void /* mididev_info */ *md) 1461{ 1462 struct seq_softc *scp; 1463 1464 scp = (struct seq_softc *)p; 1465 1466 mtx_lock(&scp->seq_lock); 1467 1468 /* Restart playing if we have the data to output. */ 1469 if (scp->queueout_pending) 1470 seq_callback(scp, SEQ_CB_START | SEQ_CB_WR); 1471 /* Check the midi device if we are reading. */ 1472 if ((scp->flags & SEQ_F_READING) != 0) 1473 seq_midiinput(scp, md); 1474 1475 mtx_unlock(&scp->seq_lock); 1476} |
1477 |
|
1458#endif 1459/* 1460 * seq_convertold 1461 * Was the old playevent. Use this to convert and old | 1478#endif 1479/* 1480 * seq_convertold 1481 * Was the old playevent. Use this to convert and old |
1462 * style /dev/sequencer event to a /dev/music event | 1482 * style /dev/sequencer event to a /dev/music event |
1463 */ 1464static int 1465seq_convertold(u_char *event, u_char *out) 1466{ 1467 int used; 1468 u_char dev, chn, note, vel; 1469 | 1483 */ 1484static int 1485seq_convertold(u_char *event, u_char *out) 1486{ 1487 int used; 1488 u_char dev, chn, note, vel; 1489 |
1470 out[0] = out[1] = out[2] = out[3] = out[4] = out[5] = out[6] = out[7] = 0; | 1490 out[0] = out[1] = out[2] = out[3] = out[4] = out[5] = out[6] = 1491 out[7] = 0; |
1471 1472 dev = 0; 1473 chn = event[1]; 1474 note = event[2]; 1475 vel = event[3]; 1476 1477 used = 0; 1478 1479restart: 1480 /* 1481 * TODO: Debug statement 1482 */ | 1492 1493 dev = 0; 1494 chn = event[1]; 1495 note = event[2]; 1496 vel = event[3]; 1497 1498 used = 0; 1499 1500restart: 1501 /* 1502 * TODO: Debug statement 1503 */ |
1483 switch(event[0]) { 1484 case EV_TIMING: 1485 case EV_CHN_VOICE: 1486 case EV_CHN_COMMON: 1487case EV_SYSEX: 1488case EV_SEQ_LOCAL: | 1504 switch (event[0]) { 1505 case EV_TIMING: 1506 case EV_CHN_VOICE: 1507 case EV_CHN_COMMON: 1508 case EV_SYSEX: 1509 case EV_SEQ_LOCAL: |
1489 out[0] = event[0]; 1490 out[1] = event[1]; 1491 out[2] = event[2]; 1492 out[3] = event[3]; 1493 out[4] = event[4]; 1494 out[5] = event[5]; 1495 out[6] = event[6]; 1496 out[7] = event[7]; 1497 used += 8; 1498 break; | 1510 out[0] = event[0]; 1511 out[1] = event[1]; 1512 out[2] = event[2]; 1513 out[3] = event[3]; 1514 out[4] = event[4]; 1515 out[5] = event[5]; 1516 out[6] = event[6]; 1517 out[7] = event[7]; 1518 used += 8; 1519 break; |
1499 case SEQ_NOTEOFF: | 1520 case SEQ_NOTEOFF: |
1500 out[0] = EV_CHN_VOICE; 1501 out[1] = dev; 1502 out[2] = MIDI_NOTEOFF; 1503 out[3] = chn; 1504 out[4] = note; 1505 out[5] = 255; | 1521 out[0] = EV_CHN_VOICE; 1522 out[1] = dev; 1523 out[2] = MIDI_NOTEOFF; 1524 out[3] = chn; 1525 out[4] = note; 1526 out[5] = 255; |
1506 used += 4; | 1527 used += 4; |
1507 break; 1508 | 1528 break; 1529 |
1509 case SEQ_NOTEON: | 1530 case SEQ_NOTEON: |
1510 out[0] = EV_CHN_VOICE; 1511 out[1] = dev; 1512 out[2] = MIDI_NOTEON; 1513 out[3] = chn; 1514 out[4] = note; 1515 out[5] = vel; | 1531 out[0] = EV_CHN_VOICE; 1532 out[1] = dev; 1533 out[2] = MIDI_NOTEON; 1534 out[3] = chn; 1535 out[4] = note; 1536 out[5] = vel; |
1516 used += 4; | 1537 used += 4; |
1517 break; 1518 1519 /* 1520 * wait delay = (event[2] << 16) + (event[3] << 8) + event[4] 1521 */ 1522 | 1538 break; 1539 1540 /* 1541 * wait delay = (event[2] << 16) + (event[3] << 8) + event[4] 1542 */ 1543 |
1523 case SEQ_PGMCHANGE: | 1544 case SEQ_PGMCHANGE: |
1524 out[0] = EV_CHN_COMMON; 1525 out[1] = dev; 1526 out[2] = MIDI_PGM_CHANGE; 1527 out[3] = chn; 1528 out[4] = note; 1529 out[5] = vel; | 1545 out[0] = EV_CHN_COMMON; 1546 out[1] = dev; 1547 out[2] = MIDI_PGM_CHANGE; 1548 out[3] = chn; 1549 out[4] = note; 1550 out[5] = vel; |
1530 used += 4; | 1551 used += 4; |
1531 break; 1532/* 1533 out[0] = EV_TIMING; 1534 out[1] = dev; 1535 out[2] = MIDI_PGM_CHANGE; 1536 out[3] = chn; 1537 out[4] = note; 1538 out[5] = vel; 1539 SEQ_DEBUG(4,printf("seq_playevent: synctimer\n")); 1540 break; 1541*/ 1542 | 1552 break; 1553/* 1554 out[0] = EV_TIMING; 1555 out[1] = dev; 1556 out[2] = MIDI_PGM_CHANGE; 1557 out[3] = chn; 1558 out[4] = note; 1559 out[5] = vel; 1560 SEQ_DEBUG(4,printf("seq_playevent: synctimer\n")); 1561 break; 1562*/ 1563 |
1543 case SEQ_MIDIPUTC: 1544 SEQ_DEBUG(4,printf("seq_playevent: put data 0x%02x, unit %d.\n", 1545 event[1], event[2])); | 1564 case SEQ_MIDIPUTC: 1565 SEQ_DEBUG(4, 1566 printf("seq_playevent: put data 0x%02x, unit %d.\n", 1567 event[1], event[2])); |
1546 /* 1547 * Pass through to the midi device. 1548 * device = event[2] 1549 * data = event[1] 1550 */ 1551 out[0] = SEQ_MIDIPUTC; 1552 out[1] = dev; 1553 out[2] = chn; | 1568 /* 1569 * Pass through to the midi device. 1570 * device = event[2] 1571 * data = event[1] 1572 */ 1573 out[0] = SEQ_MIDIPUTC; 1574 out[1] = dev; 1575 out[2] = chn; |
1554 used += 4; | 1576 used += 4; |
1555 break; 1556#ifdef notyet | 1577 break; 1578#ifdef notyet |
1557 case SEQ_ECHO: | 1579 case SEQ_ECHO: |
1558 /* 1559 * This isn't handled here yet because I don't know if I can | 1580 /* 1581 * This isn't handled here yet because I don't know if I can |
1560 * just use four bytes events. There might be consequences | 1582 * just use four bytes events. There might be consequences |
1561 * in the _read routing 1562 */ 1563 if (seq_copytoinput(scp, event, 4) == EAGAIN) { | 1583 * in the _read routing 1584 */ 1585 if (seq_copytoinput(scp, event, 4) == EAGAIN) { |
1564 ret = QUEUEFULL; 1565 break; | 1586 ret = QUEUEFULL; 1587 break; |
1566 } 1567 ret = MORE; 1568 break; 1569#endif | 1588 } 1589 ret = MORE; 1590 break; 1591#endif |
1570 case SEQ_EXTENDED: | 1592 case SEQ_EXTENDED: |
1571 switch (event[1]) { | 1593 switch (event[1]) { |
1572 case SEQ_NOTEOFF: 1573 case SEQ_NOTEON: 1574 case SEQ_PGMCHANGE: | 1594 case SEQ_NOTEOFF: 1595 case SEQ_NOTEON: 1596 case SEQ_PGMCHANGE: |
1575 event++; 1576 used = 4; 1577 goto restart; 1578 break; | 1597 event++; 1598 used = 4; 1599 goto restart; 1600 break; |
1579 case SEQ_AFTERTOUCH: | 1601 case SEQ_AFTERTOUCH: |
1580 /* 1581 * SYNTH_AFTERTOUCH(md, event[3], event[4]) 1582 */ | 1602 /* 1603 * SYNTH_AFTERTOUCH(md, event[3], event[4]) 1604 */ |
1583 case SEQ_BALANCE: | 1605 case SEQ_BALANCE: |
1584 /* 1585 * SYNTH_PANNING(md, event[3], (char)event[4]) 1586 */ | 1606 /* 1607 * SYNTH_PANNING(md, event[3], (char)event[4]) 1608 */ |
1587 case SEQ_CONTROLLER: | 1609 case SEQ_CONTROLLER: |
1588 /* 1589 * SYNTH_CONTROLLER(md, event[3], event[4], *(short *)&event[5]) 1590 */ | 1610 /* 1611 * SYNTH_CONTROLLER(md, event[3], event[4], *(short *)&event[5]) 1612 */ |
1591 case SEQ_VOLMODE: | 1613 case SEQ_VOLMODE: |
1592 /* | 1614 /* |
1593 * SYNTH_VOLUMEMETHOD(md, event[3]) | 1615 * SYNTH_VOLUMEMETHOD(md, event[3]) |
1594 */ | 1616 */ |
1595 default: 1596 SEQ_DEBUG(2,printf("seq_convertold: SEQ_EXTENDED type %d" 1597 "not handled\n", event[1])); | 1617 default: 1618 SEQ_DEBUG(2, 1619 printf("seq_convertold: SEQ_EXTENDED type %d" 1620 "not handled\n", event[1])); |
1598 break; 1599 } 1600 break; | 1621 break; 1622 } 1623 break; |
1601 case SEQ_WAIT: | 1624 case SEQ_WAIT: |
1602 out[0] = EV_TIMING; 1603 out[1] = TMR_WAIT_REL; 1604 out[4] = event[2]; 1605 out[5] = event[3]; 1606 out[6] = event[4]; 1607 | 1625 out[0] = EV_TIMING; 1626 out[1] = TMR_WAIT_REL; 1627 out[4] = event[2]; 1628 out[5] = event[3]; 1629 out[6] = event[4]; 1630 |
1608 SEQ_DEBUG(5,printf("SEQ_WAIT %d", event[2] + (event[3] << 8) + (event[4] << 24))); | 1631 SEQ_DEBUG(5, printf("SEQ_WAIT %d", 1632 event[2] + (event[3] << 8) + (event[4] << 24))); |
1609 | 1633 |
1610 used+= 4; | 1634 used += 4; |
1611 break; 1612 | 1635 break; 1636 |
1613 case SEQ_ECHO: 1614 case SEQ_SYNCTIMER: 1615 case SEQ_PRIVATE: 1616 default: 1617 SEQ_DEBUG(2,printf("seq_convertold: event type %d not handled %d %d %d\n", event[0], event[1], event[2], event[3])); | 1637 case SEQ_ECHO: 1638 case SEQ_SYNCTIMER: 1639 case SEQ_PRIVATE: 1640 default: 1641 SEQ_DEBUG(2, 1642 printf("seq_convertold: event type %d not handled %d %d %d\n", 1643 event[0], event[1], event[2], event[3])); |
1618 break; 1619 } 1620 return used; 1621} 1622 1623/* 1624 * Writting to the sequencer buffer never blocks and drops 1625 * input which cannot be queued 1626 */ 1627void 1628seq_copytoinput(struct seq_softc *scp, u_char *event, int len) 1629{ 1630 1631 mtx_assert(&scp->seq_lock, MA_OWNED); 1632 1633 if (MIDIQ_AVAIL(scp->in_q) < len) { | 1644 break; 1645 } 1646 return used; 1647} 1648 1649/* 1650 * Writting to the sequencer buffer never blocks and drops 1651 * input which cannot be queued 1652 */ 1653void 1654seq_copytoinput(struct seq_softc *scp, u_char *event, int len) 1655{ 1656 1657 mtx_assert(&scp->seq_lock, MA_OWNED); 1658 1659 if (MIDIQ_AVAIL(scp->in_q) < len) { |
1634 /* 1635 * ENOROOM? EINPUTDROPPED? ETOUGHLUCK? 1636 */ 1637 SEQ_DEBUG(2,printf("seq_copytoinput: queue full\n")); | 1660 /* 1661 * ENOROOM? EINPUTDROPPED? ETOUGHLUCK? 1662 */ 1663 SEQ_DEBUG(2, printf("seq_copytoinput: queue full\n")); |
1638 } else { | 1664 } else { |
1639 MIDIQ_ENQ(scp->in_q, event, len); 1640 selwakeup(&scp->in_sel); 1641 cv_broadcast(&scp->in_cv); | 1665 MIDIQ_ENQ(scp->in_q, event, len); 1666 selwakeup(&scp->in_sel); 1667 cv_broadcast(&scp->in_cv); |
1642 } 1643 1644} 1645 1646static int 1647seq_chnvoice(struct seq_softc *scp, kobj_t md, u_char *event) 1648{ 1649 int ret, voice; 1650 u_char cmd, chn, note, parm; 1651 1652 ret = 0; 1653 cmd = event[2]; 1654 chn = event[3]; 1655 note = event[4]; 1656 parm = event[5]; 1657 1658 mtx_assert(&scp->seq_lock, MA_OWNED); 1659 | 1668 } 1669 1670} 1671 1672static int 1673seq_chnvoice(struct seq_softc *scp, kobj_t md, u_char *event) 1674{ 1675 int ret, voice; 1676 u_char cmd, chn, note, parm; 1677 1678 ret = 0; 1679 cmd = event[2]; 1680 chn = event[3]; 1681 note = event[4]; 1682 parm = event[5]; 1683 1684 mtx_assert(&scp->seq_lock, MA_OWNED); 1685 |
1660 SEQ_DEBUG(5,printf("seq_chnvoice: unit %d, dev %d, cmd %s," 1661 " chn %d, note %d, parm %d.\n", scp->unit, event[1], 1662 midi_cmdname(cmd, cmdtab_seqcv), chn, note, parm)); | 1686 SEQ_DEBUG(5, printf("seq_chnvoice: unit %d, dev %d, cmd %s," 1687 " chn %d, note %d, parm %d.\n", scp->unit, event[1], 1688 midi_cmdname(cmd, cmdtab_seqcv), chn, note, parm)); |
1663 1664 voice = SYNTH_ALLOC(md, chn, note); 1665 1666 mtx_unlock(&scp->seq_lock); 1667 1668 switch (cmd) { | 1689 1690 voice = SYNTH_ALLOC(md, chn, note); 1691 1692 mtx_unlock(&scp->seq_lock); 1693 1694 switch (cmd) { |
1669 case MIDI_NOTEON: | 1695 case MIDI_NOTEON: |
1670 if (note < 128 || note == 255) { 1671#if 0 | 1696 if (note < 128 || note == 255) { 1697#if 0 |
1672 if (scp->music && chn == 9) { 1673 /* 1674 * This channel is a percussion. The note number is the 1675 * patch number. 1676 */ 1677 /* 1678 mtx_unlock(&scp->seq_lock); 1679 if (SYNTH_SETINSTR(md, voice, 128 + note) == EAGAIN) { 1680 mtx_lock(&scp->seq_lock); 1681 return (QUEUEFULL); | 1698 if (scp->music && chn == 9) { 1699 /* 1700 * This channel is a percussion. The note 1701 * number is the patch number. 1702 */ 1703 /* 1704 mtx_unlock(&scp->seq_lock); 1705 if (SYNTH_SETINSTR(md, voice, 128 + note) 1706 == EAGAIN) { 1707 mtx_lock(&scp->seq_lock); 1708 return (QUEUEFULL); 1709 } 1710 mtx_lock(&scp->seq_lock); 1711 */ 1712 note = 60; /* Middle C. */ |
1682 } | 1713 } |
1683 mtx_lock(&scp->seq_lock); 1684 */ 1685 note = 60; /* Middle C. */ 1686 } | |
1687#endif | 1714#endif |
1688 if (scp->music) { 1689 /* 1690 mtx_unlock(&scp->seq_lock); 1691 if (SYNTH_SETUPVOICE(md, voice, chn) == EAGAIN) { 1692 mtx_lock(&scp->seq_lock); 1693 return (QUEUEFULL); | 1715 if (scp->music) { 1716 /* 1717 mtx_unlock(&scp->seq_lock); 1718 if (SYNTH_SETUPVOICE(md, voice, chn) 1719 == EAGAIN) { 1720 mtx_lock(&scp->seq_lock); 1721 return (QUEUEFULL); 1722 } 1723 mtx_lock(&scp->seq_lock); 1724 */ |
1694 } | 1725 } |
1695 mtx_lock(&scp->seq_lock); 1696 */ 1697 } 1698 SYNTH_STARTNOTE(md, voice, note, parm); | 1726 SYNTH_STARTNOTE(md, voice, note, parm); |
1699 } 1700 break; 1701 case MIDI_NOTEOFF: 1702 SYNTH_KILLNOTE(md, voice, note, parm); 1703 break; 1704 case MIDI_KEY_PRESSURE: 1705 SYNTH_AFTERTOUCH(md, voice, parm); 1706 break; 1707 default: 1708 ret = 1; | 1727 } 1728 break; 1729 case MIDI_NOTEOFF: 1730 SYNTH_KILLNOTE(md, voice, note, parm); 1731 break; 1732 case MIDI_KEY_PRESSURE: 1733 SYNTH_AFTERTOUCH(md, voice, parm); 1734 break; 1735 default: 1736 ret = 1; |
1709 SEQ_DEBUG(2,printf("seq_chnvoice event type %d not handled\n", event[1])); | 1737 SEQ_DEBUG(2, printf("seq_chnvoice event type %d not handled\n", 1738 event[1])); |
1710 break; 1711 } 1712 1713 mtx_lock(&scp->seq_lock); 1714 return ret; 1715} 1716 1717static int --- 4 unchanged lines hidden (view full) --- 1722 u_char cmd, chn, p1; 1723 1724 ret = 0; 1725 cmd = event[2]; 1726 chn = event[3]; 1727 p1 = event[4]; 1728 w14 = *(u_short *)&event[6]; 1729 | 1739 break; 1740 } 1741 1742 mtx_lock(&scp->seq_lock); 1743 return ret; 1744} 1745 1746static int --- 4 unchanged lines hidden (view full) --- 1751 u_char cmd, chn, p1; 1752 1753 ret = 0; 1754 cmd = event[2]; 1755 chn = event[3]; 1756 p1 = event[4]; 1757 w14 = *(u_short *)&event[6]; 1758 |
1730 SEQ_DEBUG(5,printf("seq_chncommon: unit %d, dev %d, cmd %s, chn %d," 1731 " p1 %d, w14 %d.\n", scp->unit, event[1], 1732 midi_cmdname(cmd, cmdtab_seqccmn), chn, p1, w14)); | 1759 SEQ_DEBUG(5, printf("seq_chncommon: unit %d, dev %d, cmd %s, chn %d," 1760 " p1 %d, w14 %d.\n", scp->unit, event[1], 1761 midi_cmdname(cmd, cmdtab_seqccmn), chn, p1, w14)); |
1733 mtx_unlock(&scp->seq_lock); 1734 switch (cmd) { | 1762 mtx_unlock(&scp->seq_lock); 1763 switch (cmd) { |
1735 case MIDI_PGM_CHANGE: 1736 SEQ_DEBUG(4,printf("seq_chncommon pgmchn chn %d pg %d\n", 1737 chn, p1)); 1738 SYNTH_SETINSTR(md, chn, p1); | 1764 case MIDI_PGM_CHANGE: 1765 SEQ_DEBUG(4, printf("seq_chncommon pgmchn chn %d pg %d\n", 1766 chn, p1)); 1767 SYNTH_SETINSTR(md, chn, p1); |
1739 break; | 1768 break; |
1740 case MIDI_CTL_CHANGE: 1741 SEQ_DEBUG(4,printf("seq_chncommon ctlch chn %d pg %d %d\n", 1742 chn, p1, w14)); | 1769 case MIDI_CTL_CHANGE: 1770 SEQ_DEBUG(4, printf("seq_chncommon ctlch chn %d pg %d %d\n", 1771 chn, p1, w14)); |
1743 SYNTH_CONTROLLER(md, chn, p1, w14); 1744 break; | 1772 SYNTH_CONTROLLER(md, chn, p1, w14); 1773 break; |
1745 case MIDI_PITCH_BEND: | 1774 case MIDI_PITCH_BEND: |
1746 if (scp->music) { | 1775 if (scp->music) { |
1747 /* 1748 * TODO: MIDI_PITCH_BEND 1749 */ | 1776 /* 1777 * TODO: MIDI_PITCH_BEND 1778 */ |
1750#if 0 | 1779#if 0 |
1751 mtx_lock(&md->synth.vc_mtx); 1752 md->synth.chn_info[chn].bender_value = w14; 1753 if (md->midiunit >= 0) { 1754 /* Handle all of the notes playing on this channel. */ 1755 key = ((int)chn << 8); 1756 for (i = 0 ; i < md->synth.alloc.max_voice ; i++) 1757 if ((md->synth.alloc.map[i] & 0xff00) == key) { | 1780 mtx_lock(&md->synth.vc_mtx); 1781 md->synth.chn_info[chn].bender_value = w14; 1782 if (md->midiunit >= 0) { 1783 /* 1784 * Handle all of the notes playing on this 1785 * channel. 1786 */ 1787 key = ((int)chn << 8); 1788 for (i = 0; i < md->synth.alloc.max_voice; i++) 1789 if ((md->synth.alloc.map[i] & 0xff00) == key) { 1790 mtx_unlock(&md->synth.vc_mtx); 1791 mtx_unlock(&scp->seq_lock); 1792 if (md->synth.bender(md, i, w14) == EAGAIN) { 1793 mtx_lock(&scp->seq_lock); 1794 return (QUEUEFULL); 1795 } 1796 mtx_lock(&scp->seq_lock); 1797 } 1798 } else { |
1758 mtx_unlock(&md->synth.vc_mtx); 1759 mtx_unlock(&scp->seq_lock); | 1799 mtx_unlock(&md->synth.vc_mtx); 1800 mtx_unlock(&scp->seq_lock); |
1760 if (md->synth.bender(md, i, w14) == EAGAIN) { 1761 mtx_lock(&scp->seq_lock); 1762 return (QUEUEFULL); | 1801 if (md->synth.bender(md, chn, w14) == EAGAIN) { 1802 mtx_lock(&scp->seq_lock); 1803 return (QUEUEFULL); |
1763 } 1764 mtx_lock(&scp->seq_lock); | 1804 } 1805 mtx_lock(&scp->seq_lock); |
1765 } 1766 } else { 1767 mtx_unlock(&md->synth.vc_mtx); 1768 mtx_unlock(&scp->seq_lock); 1769 if (md->synth.bender(md, chn, w14) == EAGAIN) { 1770 mtx_lock(&scp->seq_lock); 1771 return (QUEUEFULL); | |
1772 } | 1806 } |
1773 mtx_lock(&scp->seq_lock); 1774 } | |
1775#endif 1776 } else | 1807#endif 1808 } else |
1777 SYNTH_BENDER(md, chn, w14); | 1809 SYNTH_BENDER(md, chn, w14); |
1778 break; | 1810 break; |
1779 default: | 1811 default: |
1780 ret = 1; | 1812 ret = 1; |
1781 SEQ_DEBUG(2,printf("seq_chncommon event type %d not handled.\n", event[1])); | 1813 SEQ_DEBUG(2, 1814 printf("seq_chncommon event type %d not handled.\n", 1815 event[1])); |
1782 break; 1783 1784 } 1785 mtx_lock(&scp->seq_lock); 1786 return ret; 1787} 1788 1789static int 1790seq_timing(struct seq_softc *scp, u_char *event) 1791{ 1792 int param; 1793 int ret; 1794 1795 ret = 0; 1796 param = event[4] + (event[5] << 8) + 1797 (event[6] << 16) + (event[7] << 24); 1798 | 1816 break; 1817 1818 } 1819 mtx_lock(&scp->seq_lock); 1820 return ret; 1821} 1822 1823static int 1824seq_timing(struct seq_softc *scp, u_char *event) 1825{ 1826 int param; 1827 int ret; 1828 1829 ret = 0; 1830 param = event[4] + (event[5] << 8) + 1831 (event[6] << 16) + (event[7] << 24); 1832 |
1799 SEQ_DEBUG(5,printf("seq_timing: unit %d, cmd %d, param %d.\n", 1800 scp->unit, event[1], param)); | 1833 SEQ_DEBUG(5, printf("seq_timing: unit %d, cmd %d, param %d.\n", 1834 scp->unit, event[1], param)); |
1801 switch (event[1]) { 1802 case TMR_WAIT_REL: | 1835 switch (event[1]) { 1836 case TMR_WAIT_REL: |
1803 timer_wait(scp, param, 0); | 1837 timer_wait(scp, param, 0); |
1804 break; 1805 case TMR_WAIT_ABS: | 1838 break; 1839 case TMR_WAIT_ABS: |
1806 timer_wait(scp, param, 1); | 1840 timer_wait(scp, param, 1); |
1807 break; 1808 case TMR_START: 1809 timer_start(scp); 1810 cv_broadcast(&scp->reset_cv); 1811 break; 1812 case TMR_STOP: 1813 timer_stop(scp); 1814 /* 1815 * The following cv_broadcast isn't needed since we only 1816 * wait for 0->1 transitions. It probably won't hurt 1817 */ 1818 cv_broadcast(&scp->reset_cv); 1819 break; 1820 case TMR_CONTINUE: 1821 timer_continue(scp); 1822 cv_broadcast(&scp->reset_cv); 1823 break; 1824 case TMR_TEMPO: 1825 if (param < 8) | 1841 break; 1842 case TMR_START: 1843 timer_start(scp); 1844 cv_broadcast(&scp->reset_cv); 1845 break; 1846 case TMR_STOP: 1847 timer_stop(scp); 1848 /* 1849 * The following cv_broadcast isn't needed since we only 1850 * wait for 0->1 transitions. It probably won't hurt 1851 */ 1852 cv_broadcast(&scp->reset_cv); 1853 break; 1854 case TMR_CONTINUE: 1855 timer_continue(scp); 1856 cv_broadcast(&scp->reset_cv); 1857 break; 1858 case TMR_TEMPO: 1859 if (param < 8) |
1826 param = 8; | 1860 param = 8; |
1827 if (param > 360) | 1861 if (param > 360) |
1828 param = 360; 1829 SEQ_DEBUG(4,printf("Timer set tempo %d\n", param)); | 1862 param = 360; 1863 SEQ_DEBUG(4, printf("Timer set tempo %d\n", param)); |
1830 timer_setvals(scp, param, scp->timerbase); 1831 break; 1832 case TMR_TIMERBASE: 1833 if (param < 1) | 1864 timer_setvals(scp, param, scp->timerbase); 1865 break; 1866 case TMR_TIMERBASE: 1867 if (param < 1) |
1834 param = 1; | 1868 param = 1; |
1835 if (param > 1000) | 1869 if (param > 1000) |
1836 param = 1000; 1837 SEQ_DEBUG(4,printf("Timer set timerbase %d\n", param)); | 1870 param = 1000; 1871 SEQ_DEBUG(4, printf("Timer set timerbase %d\n", param)); |
1838 timer_setvals(scp, scp->tempo, param); 1839 break; 1840 case TMR_ECHO: 1841 /* 1842 * TODO: Consider making 4-byte events for /dev/sequencer 1843 * PRO: Maybe needed by legacy apps 1844 * CON: soundcard.h has been warning for a while many years 1845 * to expect 8 byte events. --- 4 unchanged lines hidden (view full) --- 1850 else { 1851 param = (param << 8 | SEQ_ECHO); 1852 seq_copytoinput(scp, (u_char *)¶m, 4); 1853 } 1854#else 1855 seq_copytoinput(scp, event, 8); 1856#endif 1857 break; | 1872 timer_setvals(scp, scp->tempo, param); 1873 break; 1874 case TMR_ECHO: 1875 /* 1876 * TODO: Consider making 4-byte events for /dev/sequencer 1877 * PRO: Maybe needed by legacy apps 1878 * CON: soundcard.h has been warning for a while many years 1879 * to expect 8 byte events. --- 4 unchanged lines hidden (view full) --- 1884 else { 1885 param = (param << 8 | SEQ_ECHO); 1886 seq_copytoinput(scp, (u_char *)¶m, 4); 1887 } 1888#else 1889 seq_copytoinput(scp, event, 8); 1890#endif 1891 break; |
1858 default: 1859 SEQ_DEBUG(2,printf("seq_timing event type %d not handled.\n", event[1])); | 1892 default: 1893 SEQ_DEBUG(2, printf("seq_timing event type %d not handled.\n", 1894 event[1])); |
1860 ret = 1; 1861 break; 1862 } 1863 return ret; 1864} 1865 1866static int 1867seq_local(struct seq_softc *scp, u_char *event) 1868{ 1869 int ret; 1870 1871 ret = 0; 1872 mtx_assert(&scp->seq_lock, MA_OWNED); 1873 | 1895 ret = 1; 1896 break; 1897 } 1898 return ret; 1899} 1900 1901static int 1902seq_local(struct seq_softc *scp, u_char *event) 1903{ 1904 int ret; 1905 1906 ret = 0; 1907 mtx_assert(&scp->seq_lock, MA_OWNED); 1908 |
1874 SEQ_DEBUG(5,printf("seq_local: unit %d, cmd %d\n", scp->unit, event[1])); | 1909 SEQ_DEBUG(5, printf("seq_local: unit %d, cmd %d\n", scp->unit, 1910 event[1])); |
1875 switch (event[1]) { | 1911 switch (event[1]) { |
1876 default: 1877 SEQ_DEBUG(1, printf("seq_local event type %d not handled\n", event[1])); | 1912 default: 1913 SEQ_DEBUG(1, printf("seq_local event type %d not handled\n", 1914 event[1])); |
1878 ret = 1; 1879 break; 1880 } 1881 return ret; 1882} 1883 1884static int 1885seq_sysex(struct seq_softc *scp, kobj_t md, u_char *event) 1886{ 1887 int i, l; 1888 1889 mtx_assert(&scp->seq_lock, MA_OWNED); | 1915 ret = 1; 1916 break; 1917 } 1918 return ret; 1919} 1920 1921static int 1922seq_sysex(struct seq_softc *scp, kobj_t md, u_char *event) 1923{ 1924 int i, l; 1925 1926 mtx_assert(&scp->seq_lock, MA_OWNED); |
1890 SEQ_DEBUG(5,printf("seq_sysex: unit %d device %d\n", scp->unit, event[1])); | 1927 SEQ_DEBUG(5, printf("seq_sysex: unit %d device %d\n", scp->unit, 1928 event[1])); |
1891 l = 0; | 1929 l = 0; |
1892 for (i = 0 ; i < 6 && event[i + 2] != 0xff ; i++) | 1930 for (i = 0; i < 6 && event[i + 2] != 0xff; i++) |
1893 l = i + 1; 1894 if (l > 0) { 1895 mtx_unlock(&scp->seq_lock); 1896 if (SYNTH_SENDSYSEX(md, &event[2], l) == EAGAIN) { 1897 mtx_lock(&scp->seq_lock); 1898 return 1; 1899 } 1900 mtx_lock(&scp->seq_lock); 1901 } 1902 return 0; 1903} 1904 1905/* 1906 * Reset no longer closes the raw devices nor seq_sync's 1907 * Callers are IOCTL and seq_close 1908 */ 1909static void 1910seq_reset(struct seq_softc *scp) 1911{ | 1931 l = i + 1; 1932 if (l > 0) { 1933 mtx_unlock(&scp->seq_lock); 1934 if (SYNTH_SENDSYSEX(md, &event[2], l) == EAGAIN) { 1935 mtx_lock(&scp->seq_lock); 1936 return 1; 1937 } 1938 mtx_lock(&scp->seq_lock); 1939 } 1940 return 0; 1941} 1942 1943/* 1944 * Reset no longer closes the raw devices nor seq_sync's 1945 * Callers are IOCTL and seq_close 1946 */ 1947static void 1948seq_reset(struct seq_softc *scp) 1949{ |
1912 int chn, i; | 1950 int chn, i; |
1913 kobj_t m; 1914 1915 mtx_assert(&scp->seq_lock, MA_OWNED); 1916 | 1951 kobj_t m; 1952 1953 mtx_assert(&scp->seq_lock, MA_OWNED); 1954 |
1917 SEQ_DEBUG(5,printf("seq_reset: unit %d.\n", scp->unit)); | 1955 SEQ_DEBUG(5, printf("seq_reset: unit %d.\n", scp->unit)); |
1918 1919 /* 1920 * Stop reading and writing. 1921 */ 1922 1923 /* scp->recording = 0; */ 1924 scp->playing = 0; 1925 cv_broadcast(&scp->state_cv); 1926 cv_broadcast(&scp->out_cv); 1927 cv_broadcast(&scp->reset_cv); 1928 1929 /* 1930 * For now, don't reset the timers. 1931 */ 1932 MIDIQ_CLEAR(scp->in_q); 1933 MIDIQ_CLEAR(scp->out_q); 1934 1935 for (i = 0; i < scp->midi_number; i++) { | 1956 1957 /* 1958 * Stop reading and writing. 1959 */ 1960 1961 /* scp->recording = 0; */ 1962 scp->playing = 0; 1963 cv_broadcast(&scp->state_cv); 1964 cv_broadcast(&scp->out_cv); 1965 cv_broadcast(&scp->reset_cv); 1966 1967 /* 1968 * For now, don't reset the timers. 1969 */ 1970 MIDIQ_CLEAR(scp->in_q); 1971 MIDIQ_CLEAR(scp->out_q); 1972 1973 for (i = 0; i < scp->midi_number; i++) { |
1936 m = scp->midis[i]; 1937 mtx_unlock(&scp->seq_lock); 1938 SYNTH_RESET(m); 1939 for (chn = 0 ; chn < 16 ; chn++) { 1940 SYNTH_CONTROLLER(m, chn, 123, 0) ; 1941 SYNTH_CONTROLLER(m, chn, 121, 0); 1942 SYNTH_BENDER(m, chn, 1 << 13); 1943 } 1944 mtx_lock(&scp->seq_lock); | 1974 m = scp->midis[i]; 1975 mtx_unlock(&scp->seq_lock); 1976 SYNTH_RESET(m); 1977 for (chn = 0; chn < 16; chn++) { 1978 SYNTH_CONTROLLER(m, chn, 123, 0); 1979 SYNTH_CONTROLLER(m, chn, 121, 0); 1980 SYNTH_BENDER(m, chn, 1 << 13); 1981 } 1982 mtx_lock(&scp->seq_lock); |
1945 } 1946} 1947 1948/* 1949 * seq_sync 1950 * *really* flush the output queue 1951 * flush the event queue, then flush the synthsisers. 1952 * Callers are IOCTL and close 1953 */ 1954 1955#define SEQ_SYNC_TIMEOUT 8 1956static int 1957seq_sync(struct seq_softc *scp) 1958{ 1959 int i, rl, sync[16], done; 1960 1961 mtx_assert(&scp->seq_lock, MA_OWNED); 1962 | 1983 } 1984} 1985 1986/* 1987 * seq_sync 1988 * *really* flush the output queue 1989 * flush the event queue, then flush the synthsisers. 1990 * Callers are IOCTL and close 1991 */ 1992 1993#define SEQ_SYNC_TIMEOUT 8 1994static int 1995seq_sync(struct seq_softc *scp) 1996{ 1997 int i, rl, sync[16], done; 1998 1999 mtx_assert(&scp->seq_lock, MA_OWNED); 2000 |
1963 SEQ_DEBUG(4,printf("seq_sync: unit %d.\n", scp->unit)); | 2001 SEQ_DEBUG(4, printf("seq_sync: unit %d.\n", scp->unit)); |
1964 1965 /* 1966 * Wait until output queue is empty. Check every so often to see if 1967 * the queue is moving along. If it isn't just abort. 1968 */ 1969 while (!MIDIQ_EMPTY(scp->out_q)) { 1970 | 2002 2003 /* 2004 * Wait until output queue is empty. Check every so often to see if 2005 * the queue is moving along. If it isn't just abort. 2006 */ 2007 while (!MIDIQ_EMPTY(scp->out_q)) { 2008 |
1971 if (!scp->playing) { 1972 scp->playing = 1; 1973 cv_broadcast(&scp->state_cv); 1974 cv_broadcast(&scp->out_cv); 1975 } | 2009 if (!scp->playing) { 2010 scp->playing = 1; 2011 cv_broadcast(&scp->state_cv); 2012 cv_broadcast(&scp->out_cv); 2013 } 2014 rl = MIDIQ_LEN(scp->out_q); |
1976 | 2015 |
1977 rl = MIDIQ_LEN(scp->out_q); 1978 1979 i = cv_timedwait_sig(&scp->out_cv, | 2016 i = cv_timedwait_sig(&scp->out_cv, |
1980 &scp->seq_lock, SEQ_SYNC_TIMEOUT * hz); 1981 | 2017 &scp->seq_lock, SEQ_SYNC_TIMEOUT * hz); 2018 |
1982 if (i == EINTR || i == ERESTART) { 1983 if (i == EINTR) { 1984 /* 1985 * XXX: I don't know why we stop playing 1986 */ 1987 scp->playing = 0; 1988 cv_broadcast(&scp->out_cv); | 2019 if (i == EINTR || i == ERESTART) { 2020 if (i == EINTR) { 2021 /* 2022 * XXX: I don't know why we stop playing 2023 */ 2024 scp->playing = 0; 2025 cv_broadcast(&scp->out_cv); 2026 } 2027 return i; |
1989 } | 2028 } |
1990 return i; 1991 } 1992 1993 if (i == EWOULDBLOCK && rl == MIDIQ_LEN(scp->out_q) && | 2029 if (i == EWOULDBLOCK && rl == MIDIQ_LEN(scp->out_q) && |
1994 scp->waiting == 0) { | 2030 scp->waiting == 0) { |
1995 /* 1996 * A queue seems to be stuck up. Give up and clear queues. 1997 */ 1998 MIDIQ_CLEAR(scp->out_q); 1999 scp->playing = 0; 2000 cv_broadcast(&scp->state_cv); 2001 cv_broadcast(&scp->out_cv); 2002 cv_broadcast(&scp->reset_cv); | 2031 /* 2032 * A queue seems to be stuck up. Give up and clear 2033 * queues. 2034 */ 2035 MIDIQ_CLEAR(scp->out_q); 2036 scp->playing = 0; 2037 cv_broadcast(&scp->state_cv); 2038 cv_broadcast(&scp->out_cv); 2039 cv_broadcast(&scp->reset_cv); |
2003 | 2040 |
2004 /* 2005 * TODO: Consider if the raw devices need to be flushed 2006 */ | 2041 /* 2042 * TODO: Consider if the raw devices need to be flushed 2043 */ |
2007 | 2044 |
2008 SEQ_DEBUG(1,printf("seq_sync queue stuck, aborting\n")); | 2045 SEQ_DEBUG(1, printf("seq_sync queue stuck, aborting\n")); |
2009 | 2046 |
2010 return i; 2011 } | 2047 return i; 2048 } |
2012 } 2013 2014 scp->playing = 0; 2015 /* 2016 * Since syncing a midi device might block, unlock scp->seq_lock. 2017 */ 2018 2019 mtx_unlock(&scp->seq_lock); | 2049 } 2050 2051 scp->playing = 0; 2052 /* 2053 * Since syncing a midi device might block, unlock scp->seq_lock. 2054 */ 2055 2056 mtx_unlock(&scp->seq_lock); |
2020 for(i = 0 ; i < scp->midi_number; i++) 2021 sync[i] = 1; | 2057 for (i = 0; i < scp->midi_number; i++) 2058 sync[i] = 1; |
2022 2023 do { | 2059 2060 do { |
2024 done = 1; 2025 for (i = 0 ; i < scp->midi_number; i++) 2026 if (sync[i]) { 2027 if (SYNTH_INSYNC(scp->midis[i]) == 0) 2028 sync[i] = 0; 2029 else 2030 done = 0; 2031 } | 2061 done = 1; 2062 for (i = 0; i < scp->midi_number; i++) 2063 if (sync[i]) { 2064 if (SYNTH_INSYNC(scp->midis[i]) == 0) 2065 sync[i] = 0; 2066 else 2067 done = 0; 2068 } 2069 if (!done) 2070 DELAY(5000); |
2032 | 2071 |
2033 if (!done) 2034 DELAY(5000); 2035 | |
2036 } while (!done); 2037 2038 mtx_lock(&scp->seq_lock); 2039 return 0; 2040} 2041 | 2072 } while (!done); 2073 2074 mtx_lock(&scp->seq_lock); 2075 return 0; 2076} 2077 |
2042char * | 2078char * |
2043midi_cmdname(int cmd, midi_cmdtab *tab) 2044{ 2045 while (tab->name != NULL) { 2046 if (cmd == tab->cmd) 2047 return (tab->name); 2048 tab++; 2049 } 2050 2051 return ("unknown"); 2052} | 2079midi_cmdname(int cmd, midi_cmdtab *tab) 2080{ 2081 while (tab->name != NULL) { 2082 if (cmd == tab->cmd) 2083 return (tab->name); 2084 tab++; 2085 } 2086 2087 return ("unknown"); 2088} |