home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.lbl.gov
/
2014.05.ftp.ee.lbl.gov.tar
/
ftp.ee.lbl.gov
/
bmd-1.0beta.tar.Z
/
bmd-1.0beta.tar
/
bmd-1.0beta
/
app
/
omtd
/
event.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-21
|
3KB
|
166 lines
/*
* Copyright (c) 1990 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Lawrence Berkeley Laboratory,
* Berkeley, CA. The name of the University may not be used to
* endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <sys/types.h>
#include <sundev/midi.h>
#include "readline.h"
#include "event.h"
#include "track.h"
struct event *master_list;
struct event *raw_list;
static struct event *efreelist;
struct event *
ealloc()
{
struct event *p;
if (efreelist) {
p = efreelist;
efreelist = p->next;
} else {
p = (struct event *)malloc(sizeof(*p));
if (p == 0) {
error("out of memory");
exit(1);
}
}
return p;
}
void
efree(p)
struct event *p;
{
p->next = efreelist;
efreelist = p;
}
void
efreel(p)
struct event *p;
{
struct event *next;
for (; p != 0; p = next) {
next = p->next;
efree(p);
}
}
void
pq_insert(pp, p)
struct event **pp, *p;
{
while (*pp && p->m.mm_time >= (*pp)->m.mm_time)
pp = &(*pp)->pqnext;
p->pqnext = *pp;
*pp = p;
}
struct event *
pq_remove_bynote(pp, note)
struct event **pp;
int note;
{
struct event *p;
while (*pp && (*pp)->m.mm_data[1] != note)
pp = &(*pp)->pqnext;
if (*pp == 0)
return 0;
p = *pp;
*pp = (*pp)->pqnext;
return p;
}
static void
ptrk(p, trk)
struct event *p;
struct track *trk;
{
for (; p != 0; p = p->next) {
if (trk != 0 && p->trk != trk)
continue;
ptime(p->m.mm_time);
putchar(' ');
ptime(p->duration);
printf(" [%d:%d] \"%s\" %x %x %x\n",
p->m.mm_time, p->duration,
p->trk->name,
p->m.mm_data[0],
p->m.mm_data[1],
p->m.mm_data[2]);
}
}
void
dump_command(trk)
struct track *trk;
{
ptrk(master_list, trk);
}
write_master(fd)
int fd;
{
struct event *p;
for (p = master_list; p != 0; p = p->next) {
write(fd, &p->trk->id, sizeof p->trk->id);
write(fd, &p->duration, sizeof p->duration);
write(fd, &p->m, sizeof p->m);
}
}
read_master(fd)
int fd;
{
struct event **pp = &master_list, *p;
int id;
while (1) {
if (read(fd, &id, sizeof(id)) != sizeof(id))
break;
p = ealloc();
p->trk = id_to_track(id);
read(fd, &p->duration, sizeof p->duration);
read(fd, &p->m, sizeof p->m);
*pp = p;
pp = &p->next;
}
*pp = 0;
}
new()
{
efreel(master_list);
master_list = 0;
efreel(raw_list);
raw_list = 0;
free_tracks();
}
void
new_command()
{
new();
}