=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/aucat/Attic/midi.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- src/usr.bin/aucat/Attic/midi.c 2010/04/03 17:40:33 1.17 +++ src/usr.bin/aucat/Attic/midi.c 2010/04/03 17:59:17 1.18 @@ -1,4 +1,4 @@ -/* $OpenBSD: midi.c,v 1.17 2010/04/03 17:40:33 ratchov Exp $ */ +/* $OpenBSD: midi.c,v 1.18 2010/04/03 17:59:17 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov * @@ -132,7 +132,7 @@ if (debug_level >= 4) { aproc_dbg(p); dbg_puts(": "); - dbg_putx(c); + dbg_putu(c); dbg_puts(": flushing realtime message\n"); } #endif @@ -350,15 +350,16 @@ { struct ctl_slot *s; + aproc_dbg(p); if (slot < 0) { - dbg_puts("none"); + dbg_puts("/none"); } else { s = p->u.ctl.slot + slot; dbg_puts(s->name); dbg_putu(s->unit); - dbg_puts("("); + dbg_puts("="); dbg_putu(s->vol); - dbg_puts(")/"); + dbg_puts("/"); switch (s->tstate) { case CTL_OFF: dbg_puts("off"); @@ -393,7 +394,7 @@ for (i = LIST_FIRST(&p->obuflist); i != NULL; i = inext) { inext = LIST_NEXT(i, oent); - if (i->duplex && i->duplex == ibuf) + if (i->duplex == ibuf) continue; itodo = len; idata = msg; @@ -638,10 +639,8 @@ if (p->u.ctl.tstate != CTL_START) { #ifdef DEBUG - if (debug_level >= 3) { - ctl_slotdbg(p, caller); - dbg_puts(": server not started, delayd\n"); - } + aproc_dbg(p); + dbg_puts(": not in starting state\n"); #endif return 0; } @@ -650,10 +649,8 @@ continue; if (s->tstate != CTL_OFF && s->tstate != CTL_START) { #ifdef DEBUG - if (debug_level >= 3) { - ctl_slotdbg(p, i); - dbg_puts(": not ready, server delayed\n"); - } + ctl_slotdbg(p, i); + dbg_puts(": not ready to start, start delayed\n"); #endif return 0; } @@ -663,10 +660,8 @@ continue; if (s->tstate == CTL_START) { #ifdef DEBUG - if (debug_level >= 3) { - ctl_slotdbg(p, i); - dbg_puts(": started\n"); - } + ctl_slotdbg(p, i); + dbg_puts(": started\n"); #endif s->tstate = CTL_RUN; s->ops->start(s->arg); @@ -676,10 +671,10 @@ p->u.ctl.slot[caller].tstate = CTL_RUN; p->u.ctl.tstate = CTL_RUN; p->u.ctl.delta = MTC_SEC * dev_getpos(); - if (dev_rate % (30 * 4 * dev_round) == 0) { + if (dev_rate % (30 * 4 * dev_round)) { p->u.ctl.fps_id = MTC_FPS_30; p->u.ctl.fps = 30; - } else if (dev_rate % (25 * 4 * dev_round) == 0) { + } else if (dev_rate % (25 * 4 * dev_round)) { p->u.ctl.fps_id = MTC_FPS_25; p->u.ctl.fps = 25; } else { @@ -687,17 +682,13 @@ p->u.ctl.fps = 24; } #ifdef DEBUG - if (debug_level >= 3) { - ctl_slotdbg(p, caller); - dbg_puts(": started server at "); - dbg_puti(p->u.ctl.delta); - dbg_puts(", "); - dbg_puti(p->u.ctl.fps); - dbg_puts(" mtc fps\n"); - } + ctl_slotdbg(p, caller); + dbg_puts(": started server at "); + dbg_puti(p->u.ctl.delta); + dbg_puts(", "); + dbg_puti(p->u.ctl.fps); + dbg_puts(" mtc fps\n"); #endif - if (dev_pstate == DEV_INIT) - dev_pstate = DEV_START; ctl_full(p); return 1; } @@ -711,15 +702,8 @@ int idx; struct ctl_slot *s; - if (!APROC_OK(p)) { -#ifdef DEBUG - if (debug_level >= 1) { - dbg_puts(who); - dbg_puts(": MIDI control not available\n"); - } -#endif + if (p == NULL) return -1; - } idx = ctl_getidx(p, who); if (idx < 0) return -1; @@ -742,7 +726,7 @@ unsigned i; struct ctl_slot *s; - if (!APROC_OK(p)) + if (p == NULL) return; p->u.ctl.slot[index].ops = NULL; if (!(p->flags & APROC_QUIT)) @@ -795,7 +779,7 @@ { unsigned char msg[3]; - if (!APROC_OK(p)) + if (p == NULL) return; #ifdef DEBUG if (debug_level >= 3) { @@ -823,7 +807,7 @@ { struct ctl_slot *s = p->u.ctl.slot + slot; - if (!APROC_OK(p)) + if (p == NULL) return 1; if (s->tstate == CTL_OFF || p->u.ctl.tstate == CTL_OFF) return 1; @@ -847,7 +831,7 @@ { struct ctl_slot *s = p->u.ctl.slot + slot; - if (!APROC_OK(p)) + if (p == NULL) return; /* * tag the stream as not trying to start, @@ -858,118 +842,6 @@ } /* - * start all slots simultaneously - */ -void -ctl_start(struct aproc *p) -{ - if (!APROC_OK(p)) - return; - if (p->u.ctl.tstate == CTL_STOP) { - p->u.ctl.tstate = CTL_START; - (void)ctl_trystart(p, -1); -#ifdef DEBUG - } else { - if (debug_level >= 3) { - aproc_dbg(p); - dbg_puts(": ignoring mmc start\n"); - } -#endif - } -} - -/* - * stop all slots simultaneously - */ -void -ctl_stop(struct aproc *p) -{ - unsigned i; - struct ctl_slot *s; - - if (!APROC_OK(p)) - return; - switch (p->u.ctl.tstate) { - case CTL_START: - p->u.ctl.tstate = CTL_STOP; - return; - case CTL_RUN: - p->u.ctl.tstate = CTL_STOP; - break; - default: -#ifdef DEBUG - if (debug_level >= 3) { - aproc_dbg(p); - dbg_puts(": ignored mmc stop\n"); - } -#endif - return; - } - for (i = 0, s = p->u.ctl.slot; i < CTL_NSLOT; i++, s++) { - if (!s->ops) - continue; - if (s->tstate == CTL_RUN) { -#ifdef DEBUG - if (debug_level >= 3) { - ctl_slotdbg(p, i); - dbg_puts(": requested to stop\n"); - } -#endif - s->ops->stop(s->arg); - } - } -} - -/* - * relocate all slots simultaneously - */ -void -ctl_loc(struct aproc *p, unsigned origin) -{ - unsigned i, tstate; - struct ctl_slot *s; - - if (!APROC_OK(p)) - return; -#ifdef DEBUG - if (debug_level >= 2) { - dbg_puts("server relocated to "); - dbg_putu(origin); - dbg_puts("\n"); - } -#endif - tstate = p->u.ctl.tstate; - if (tstate == CTL_RUN) - ctl_stop(p); - p->u.ctl.origin = origin; - for (i = 0, s = p->u.ctl.slot; i < CTL_NSLOT; i++, s++) { - if (!s->ops) - continue; - s->ops->loc(s->arg, p->u.ctl.origin); - } - if (tstate == CTL_RUN) - ctl_start(p); -} - -/* - * check if there are controlled streams - */ -int -ctl_idle(struct aproc *p) -{ - unsigned i; - struct ctl_slot *s; - - if (!APROC_OK(p)) - return 1; - for (i = 0, s = p->u.ctl.slot; i < CTL_NSLOT; i++, s++) { - if (s->ops) - return 0; - } - return 1; -} - -/* * handle a MIDI event received from ibuf */ void @@ -1011,21 +883,41 @@ switch (ibuf->r.midi.msg[4]) { case 0x01: /* mmc stop */ #ifdef DEBUG - if (debug_level >= 3) { + if (debug_level >= 1) { abuf_dbg(ibuf); dbg_puts(": mmc stop\n"); } #endif - ctl_stop(p); + if (p->u.ctl.tstate == CTL_RUN || + p->u.ctl.tstate == CTL_START) + p->u.ctl.tstate = CTL_STOP; +#ifdef DEBUG + else { + if (debug_level >= 1) { + aproc_dbg(p); + dbg_puts(": ignored mmc stop\n"); + } + } +#endif break; case 0x02: /* mmc start */ #ifdef DEBUG - if (debug_level >= 3) { + if (debug_level >= 1) { abuf_dbg(ibuf); dbg_puts(": mmc start\n"); } #endif - ctl_start(p); + if (p->u.ctl.tstate == CTL_STOP) { + p->u.ctl.tstate = CTL_START; + (void)ctl_trystart(p, -1); +#ifdef DEBUG + } else { + if (debug_level >= 1) { + abuf_dbg(ibuf); + dbg_puts(": ignoring mmc start\n"); + } +#endif + } break; } } @@ -1051,12 +943,20 @@ p->u.ctl.origin = 0; return; } - ctl_loc(p, + p->u.ctl.origin = (ibuf->r.midi.msg[7] & 0x1f) * 3600 * MTC_SEC + ibuf->r.midi.msg[8] * 60 * MTC_SEC + ibuf->r.midi.msg[9] * MTC_SEC + ibuf->r.midi.msg[10] * (MTC_SEC / fps) + - ibuf->r.midi.msg[11] * (MTC_SEC / 100 / fps)); + ibuf->r.midi.msg[11] * (MTC_SEC / 100 / fps); +#ifdef DEBUG + if (debug_level >= 1) { + aproc_dbg(p); + dbg_puts(": relocated to "); + dbg_putu(p->u.ctl.origin); + dbg_puts("\n"); + } +#endif } }