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
/
etime.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-17
|
3KB
|
141 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 "readline.h"
#include "setting.h"
struct token *
parse_time(tp, p)
struct token *tp;
u_long *p;
{
u_long bar, beat = 0, tick = 0;
if (tp == 0)
goto bad;
if (tp->t_id != TK_INT)
goto bad;
bar = tp->t_int;
tp = tp->next;
if (tp && tp->t_id == ':') {
tp = tp->next;
if (tp->t_id != TK_INT)
goto bad;
beat = tp->t_int;
tp = tp->next;
if (tp && tp->t_id == ':') {
tp = tp->next;
if (tp->t_id != TK_INT)
goto bad;
tick = tp->t_int;
}
}
*p = tick + s.ticks_per_beat * (beat + bar * s.beats_per_bar);
return tp->next;
bad:
printf("malformed time specifier\n");
return 0;
}
struct token *
parse_window(tp, sptr, eptr)
struct token *tp;
u_long *sptr, *eptr;
{
if (tp != 0)
{
if (tp->t_id != ',')
tp = parse_time(tp, sptr);
if (tp !=0 && tp->t_id == ',')
tp = parse_time(tp->next, eptr);
return tp;
}
error("Bad window syntax");
return 0;
}
static float
bpm_to_scale(bpm)
u_long bpm;
{
return bpm == 0 ? (float)BASETEMPO : (float)BASETEMPO / bpm;
}
/* XXX Need to guarantee we have an origin (0). */
void
tempo_command(x)
int x;
{
struct pt_list *old;
u_long t;
old = s.tempo;
s.tempo = 0;
pt_insert(&s.tempo, 0, bpm_to_scale(x));
pt_free(old);
#ifdef notdef
while (tp) {
tp = parse_time(tp, &t);
if (tp == 0 || tp->t_id != TK_INT) {
printf("error: tempo bpm_0 t0 bpm_1 t1 etc\n");
goto bad;
}
pt_insert(&s.tempo, t, bpm_to_scale(tp->t_int));
tp = tp->next;
}
pt_free(old);
return;
bad:
pt_free(s.tempo);
s.tempo = old;
#endif
}
ptime(t)
u_long t;
{
int beat, bar, tick;
if (t == ~0) {
printf("infinity");
return;
}
bar = t / (s.beats_per_bar * s.ticks_per_beat);
beat = (t / s.ticks_per_beat) % s.beats_per_bar;
tick = t % s.ticks_per_beat;
printf("%03d:%01d:%03d", bar, beat, tick);
}
write_tempo(fd)
{
write_ptlist(fd, s.tempo);
}
read_tempo(fd)
{
read_ptlist(fd, &s.tempo);
}