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 >
C/C++ Source or Header  |  1991-02-17  |  3KB  |  141 lines

  1. /*
  2.  * Copyright (c) 1990 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Lawrence Berkeley Laboratory,
  11.  * Berkeley, CA.  The name of the University may not be used to
  12.  * endorse or promote products derived from this software without
  13.  * specific prior written permission.
  14.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  15.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  16.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17.  */
  18. #include <sys/types.h>
  19. #include "readline.h"
  20. #include "setting.h"
  21.  
  22. struct token *
  23. parse_time(tp, p)
  24.     struct token *tp;
  25.     u_long *p;
  26. {
  27.     u_long bar, beat = 0, tick = 0;
  28.  
  29.     if (tp == 0)
  30.         goto bad;
  31.     if (tp->t_id != TK_INT)
  32.         goto bad;
  33.     bar = tp->t_int;
  34.     tp = tp->next;
  35.     if (tp && tp->t_id == ':') {
  36.         tp = tp->next;
  37.         if (tp->t_id != TK_INT)
  38.             goto bad;
  39.         beat = tp->t_int;
  40.         tp = tp->next;
  41.         if (tp && tp->t_id == ':') {
  42.             tp = tp->next;
  43.             if (tp->t_id != TK_INT)
  44.                 goto bad;
  45.             tick = tp->t_int;
  46.         }
  47.     }
  48.     *p = tick + s.ticks_per_beat * (beat + bar * s.beats_per_bar);
  49.     return tp->next;
  50.  bad:
  51.     printf("malformed time specifier\n");
  52.     return 0;
  53. }
  54.  
  55.  
  56. struct token *
  57. parse_window(tp, sptr, eptr)
  58.     struct token *tp;
  59.     u_long    *sptr, *eptr;
  60. {    
  61.     if (tp != 0)
  62.         {
  63.                 if (tp->t_id != ',')
  64.                         tp = parse_time(tp, sptr);
  65.  
  66.                 if (tp !=0 && tp->t_id == ',')
  67.                         tp = parse_time(tp->next, eptr);
  68.  
  69.         return tp;
  70.     }
  71.  
  72.     error("Bad window syntax");
  73.     return 0;
  74.     
  75. }
  76.         
  77. static float
  78. bpm_to_scale(bpm)
  79.     u_long bpm;
  80. {
  81.     return bpm == 0 ? (float)BASETEMPO : (float)BASETEMPO / bpm;
  82. }
  83.  
  84. /* XXX Need to guarantee we have an origin (0). */
  85. void
  86. tempo_command(x)
  87.     int x;
  88. {
  89.     struct pt_list *old;
  90.     u_long t;
  91.  
  92.     old = s.tempo;
  93.     s.tempo = 0;
  94.     pt_insert(&s.tempo, 0, bpm_to_scale(x));
  95.     pt_free(old);
  96.  
  97. #ifdef notdef
  98.     while (tp) {
  99.         tp = parse_time(tp, &t);
  100.         if (tp == 0 || tp->t_id != TK_INT) {
  101.             printf("error: tempo bpm_0 t0 bpm_1 t1 etc\n");
  102.             goto bad;
  103.         }
  104.         pt_insert(&s.tempo, t, bpm_to_scale(tp->t_int));
  105.         tp = tp->next;
  106.     }
  107.     pt_free(old);
  108.     return;
  109.  bad:
  110.     pt_free(s.tempo);
  111.     s.tempo = old;
  112. #endif
  113. }
  114.  
  115. ptime(t)
  116.     u_long t;
  117. {
  118.     int beat, bar, tick;
  119.  
  120.        if (t == ~0) {
  121.                printf("infinity");
  122.                return;
  123.        }
  124.        
  125.     bar = t / (s.beats_per_bar * s.ticks_per_beat);
  126.     beat = (t / s.ticks_per_beat) % s.beats_per_bar;
  127.     tick = t % s.ticks_per_beat;
  128.  
  129.     printf("%03d:%01d:%03d", bar, beat, tick);
  130. }
  131.  
  132. write_tempo(fd)
  133. {
  134.     write_ptlist(fd, s.tempo);
  135. }
  136.  
  137. read_tempo(fd)
  138. {
  139.     read_ptlist(fd, &s.tempo);
  140. }
  141.