reuse midi-control code to implement midi thru boxes and remove

the old midithru implementation; less code, less bugs. As a side
effect, midi output doesn't implement running status "compression"
any more
This commit is contained in:
Alexandre Ratchov 2011-12-02 11:38:53 +01:00
parent a3955999b1
commit 37f7cba0f8
6 changed files with 284 additions and 493 deletions

View File

@ -169,11 +169,9 @@ struct aproc {
int bnext; /* to reach the next byte */
int snext; /* to reach the next sample */
} conv;
struct {
struct timo timo; /* timout for throtteling */
} thru;
struct {
struct dev *dev; /* controlled device */
struct timo timo; /* timout for throtteling */
unsigned fps; /* MTC frames per second */
#define MTC_FPS_24 0
#define MTC_FPS_25 1
@ -185,7 +183,7 @@ struct aproc {
unsigned fr; /* MTC frames */
unsigned qfr; /* MTC quarter frames */
int delta; /* rel. to the last MTC tick */
} ctl;
} midi;
} u;
};

View File

@ -532,7 +532,7 @@ main(int argc, char **argv)
mkdev("loopback", MODE_LOOP, bufsz, round, 1, autovol);
break;
case 'M':
mkdev("midithru", MODE_THRU, 0, 0, 1, 0);
mkdev("midithru", MODE_THRU, 0, 0, hold, 0);
break;
case 'l':
background = 1;
@ -609,7 +609,7 @@ main(int argc, char **argv)
dnext = d->next;
if (!dev_run(d))
goto fatal;
if (!dev_idle(d))
if (d->refcnt > 0)
active = 1;
}
if (dev_list == NULL)

View File

@ -141,6 +141,7 @@ dev_new(char *path, unsigned mode,
d->hold = hold;
d->autovol = autovol;
d->autostart = 0;
d->refcnt = 0;
d->pstate = DEV_CLOSED;
d->serial = 0;
for (i = 0; i < CTL_NSLOT; i++) {
@ -395,8 +396,7 @@ dev_open(struct dev *d)
* if there's no device
*/
if (d->mode & MODE_MIDIMASK) {
d->midi = (d->mode & MODE_THRU) ?
thru_new("thru") : ctl_new("ctl", d);
d->midi = midi_new("midi", (d->mode & MODE_THRU) ? NULL : d);
d->midi->refs++;
}
@ -1450,8 +1450,9 @@ dev_slotnew(struct dev *d, char *who, struct ctl_ops *ops, void *arg, int mmc)
s->ops->vol(s->arg, s->vol);
if (APROC_OK(d->midi)) {
ctl_slot(d->midi, slot);
ctl_vol(d->midi, slot, s->vol);
midi_send_slot(d->midi, slot);
midi_send_vol(d->midi, slot, s->vol);
midi_flush(d->midi);
} else {
#ifdef DEBUG
if (debug_level >= 2) {
@ -1495,38 +1496,10 @@ dev_slotvol(struct dev *d, int slot, unsigned vol)
}
#endif
d->slot[slot].vol = vol;
if (APROC_OK(d->midi))
ctl_vol(d->midi, slot, vol);
}
/*
* check if there are controlled streams
*/
int
dev_idle(struct dev *d)
{
unsigned i;
struct ctl_slot *s;
/*
* XXX: this conditions breaks -aoff for thru boxes
*/
if (d->mode & MODE_THRU)
return 0;
if (d->pstate != DEV_CLOSED)
return 0;
/*
* XXX: if the device is closed, we're sure there are no
* slots in use, so the following test is useless
*/
for (i = 0, s = d->slot; i < CTL_NSLOT; i++, s++) {
if (s->ops)
return 0;
if (APROC_OK(d->midi)) {
midi_send_vol(d->midi, slot, vol);
midi_flush(d->midi);
}
return 1;
}
/*
@ -1578,8 +1551,11 @@ dev_try(struct dev *d, int slot)
if (slot >= 0)
d->slot[slot].tstate = CTL_RUN;
d->tstate = CTL_RUN;
if (APROC_OK(d->midi))
ctl_full(d->midi, d->origin, d->rate, d->round, dev_getpos(d));
if (APROC_OK(d->midi)) {
midi_send_full(d->midi,
d->origin, d->rate, d->round, dev_getpos(d));
midi_flush(d->midi);
}
dev_wakeup(d);
return 1;
}
@ -1726,6 +1702,8 @@ dev_onmove(void *arg, int delta)
*/
if (d->tstate != CTL_RUN)
return;
if (APROC_OK(d->midi))
ctl_qfr(d->midi, d->rate, delta);
if (APROC_OK(d->midi)) {
midi_send_qfr(d->midi, d->rate, delta);
midi_flush(d->midi);
}
}

View File

@ -32,7 +32,6 @@ struct dev {
struct aparams reqipar, reqopar; /* parameters */
unsigned reqbufsz; /* buffer size */
unsigned reqround; /* block size */
unsigned reqrate; /* sample rate */
unsigned hold; /* hold the device open ? */
unsigned autovol; /* auto adjust playvol ? */
unsigned autostart; /* don't wait for MMC start */
@ -120,6 +119,5 @@ void dev_slotstop(struct dev *, int);
void dev_mmcstart(struct dev *);
void dev_mmcstop(struct dev *);
void dev_loc(struct dev *, unsigned);
int dev_idle(struct dev *);
#endif /* !define(DEV_H) */

File diff suppressed because it is too large Load Diff

View File

@ -19,13 +19,13 @@
struct dev;
struct aproc *thru_new(char *);
struct aproc *ctl_new(char *, struct dev *);
struct aproc *midi_new(char *, struct dev *);
void ctl_ontick(struct aproc *, int);
void ctl_slot(struct aproc *, int);
void ctl_vol(struct aproc *, int, unsigned);
void ctl_full(struct aproc *, unsigned, unsigned, unsigned, unsigned);
void ctl_qfr(struct aproc *, unsigned, int);
void midi_ontick(struct aproc *, int);
void midi_send_slot(struct aproc *, int);
void midi_send_vol(struct aproc *, int, unsigned);
void midi_send_full(struct aproc *, unsigned, unsigned, unsigned, unsigned);
void midi_send_qfr(struct aproc *, unsigned, int);
void midi_flush(struct aproc *);
#endif /* !defined(MIDI_H) */