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
/
track.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-21
|
4KB
|
229 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 "track.h"
#include "readline.h"
#include "event.h"
#include "setting.h"
struct track *trklist;
free_tracks()
{
struct track *p, *next;
for (p = trklist; p != 0; p = next) {
next = p->next;
free((char *)p);
}
trklist = 0;
}
delete_command(trk)
struct track *trk;
{
struct track **pp;
if (trk == 0)
return;
for (pp = &trklist; *pp != 0; pp = &(*pp)->next) {
if (*pp == trk) {
*pp = (*pp)->next;
free((void *)trk);
return;
}
}
}
struct track *
get_track(name)
char *name;
{
struct track *p;
for (p = trklist; p != 0; p = p->next)
if (p->name == name)
return p;
return 0;
}
struct track *
lookup_track(name, chan)
char *name;
int chan;
{
struct track *p = get_track(name);
if (p == 0) {
p = (struct track *)malloc(sizeof(*p));
bzero((char *)p, sizeof(*p));
p->name = name;
p->channel = chan;
p->next = trklist;
p->id = trklist ? trklist->id + 1 : 0;
trklist = p;
}
return p;
}
struct track *
find_track(name)
char *name;
{
struct track *trk = get_track(name);
if (trk == 0)
printf("no track named '%s'\n", name);
return trk;
}
static int
trkcnt(trk)
struct track *trk;
{
struct event *p;
int n = 0;
for (p = master_list; p != 0; p = p->next)
if (trk == p->trk)
++n;
return n;
}
void
tracks_command()
{
struct track *p;
for (p = trklist; p != 0; p = p->next)
printf("\"%s\"\t%s\tchan %d\t#%d\n", p->name,
p->mute ? "off" : "on", p->channel + 1,
trkcnt(p));
}
count_tracks(p)
struct track *p;
{
if (p == 0)
return 0;
else {
p->id = count_tracks(p->next);
return p->id + 1;
}
}
write_tracks(fd)
int fd;
{
int cnt = 0, strings = 0;
struct track *p;
if (trklist == 0) {
(void)write(fd, &cnt, sizeof cnt);
return;
}
cnt = count_tracks(trklist);
(void)write(fd, &cnt, sizeof cnt);
for (p = trklist; p != 0; p = p->next) {
char c = strlen(p->name);
(void)write(fd, &c, 1);
(void)write(fd, p->name, strlen(p->name));
(void)write(fd, &p->mute, sizeof p->mute);
(void)write(fd, &p->channel, sizeof p->channel);
}
}
read_tracks(fd)
int fd;
{
int cnt = 0;
struct track *p, **pp;
char len;
char buf[80];
pp = &trklist;
if (read(fd, &cnt, sizeof cnt) != sizeof(cnt)) {
}
while (--cnt >= 0) {
if (read(fd, &len, 1) != 1) {
}
if (read(fd, buf, len) != len) {
}
buf[len] = 0;
p = (struct track *)malloc(sizeof(*p));
p->id = cnt;
p->name = intern(buf);
read(fd, &p->mute, sizeof p->mute);
read(fd, &p->channel, sizeof p->channel);
*pp = p;
pp = &p->next;
}
*pp = 0;
}
struct track *
id_to_track(id)
int id;
{
struct track *p;
char name[30];
for (p = trklist; p != 0; p = p->next)
if (p->id == id)
return p;
abort();
sprintf(name, "trk%d", id);
p = lookup_track(intern(name), 0);
p->id = id;
return p;
}
void
save_mutes()
{
struct track *p;
for (p = trklist; p != 0; p = p->next)
p->smute = p->mute;
}
void
mute_all()
{
struct track *p;
for (p = trklist; p != 0; p = p->next)
p->mute = 1;
}
void
restore_mutes()
{
struct track *p;
for (p = trklist; p != 0; p = p->next)
p->mute = p->smute;
}