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 / click.c next >
C/C++ Source or Header  |  1991-08-21  |  3KB  |  109 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.  
  19. #include <sys/types.h>
  20. #include <sundev/midi.h>
  21. #include "readline.h"
  22. #include "event.h"
  23. #include "setting.h"
  24. #include "etime.h"
  25.  
  26. /*
  27.  * XXX Read these settings (and others) from environment or init file.
  28.  */
  29. #define ACCENT_CLICK_VELOC    120
  30. #define CLICKLEN 10
  31. #define CLICKNOTE (0x3a+11)
  32. #define CLICKVELOC 80
  33. #define CLICKCHAN 7
  34.  
  35. static u_long curclick;
  36.  
  37. void
  38. advance_click(p)
  39.     struct event *p;
  40. {
  41.     if (p->m.mm_data[2] != 0) {
  42.         /* was an on tick - get next off */
  43.         curclick += s.click.click_len;
  44.         p->m.mm_time = warp_time(s.tempo, curclick);
  45.         p->m.mm_data[2] = 0;
  46.     } else {
  47.         /* was an off tick - get next on tick */
  48.         curclick += s.ticks_per_beat - s.click.click_len;
  49.         p->m.mm_time = warp_time(s.tempo, curclick);
  50.  
  51.         if((curclick / s.ticks_per_beat) % s.beats_per_bar == 0)
  52.             p->m.mm_data[2] = ACCENT_CLICK_VELOC;
  53.         else
  54.             p->m.mm_data[2] = s.click.click_veloc;
  55.     }
  56. }
  57.  
  58. struct event *
  59. first_click(start)
  60.     u_long start;
  61. {
  62.  
  63.     static struct event e;
  64.  
  65.     if (s.click.click_len == 0)
  66.         return 0;
  67.  
  68.     /* Round down to next whole beat. */
  69.     start -= start % s.ticks_per_beat;
  70.     curclick = start;
  71.     e.m.mm_time = warp_time(s.tempo, start);
  72.     e.m.mm_data[0] = 0x90 | s.click.click_chan;
  73.     e.m.mm_data[1] = s.click.click_note;
  74.     if((start / s.ticks_per_beat) % s.beats_per_bar == 0)
  75.         e.m.mm_data[2] = ACCENT_CLICK_VELOC;
  76.     else
  77.         e.m.mm_data[2] = s.click.click_veloc;
  78.     
  79.     return &e;
  80. }
  81.  
  82. click_off()
  83. {
  84.     s.click.click_len = 0;
  85.     printf("click off\n");
  86. }
  87.  
  88. void
  89. click_on(chan, note)
  90.     int chan;
  91.     int note;
  92. {
  93.     if (note < 0)
  94.         note = CLICKNOTE;
  95.     else
  96.         note &= 0x7f;
  97.     if (chan < 0)
  98.         chan = CLICKCHAN;
  99.     else
  100.         chan = (chan - 1) & 0xf;
  101.  
  102.     s.click.click_len = CLICKLEN;
  103.     s.click.click_veloc = CLICKVELOC;
  104.     s.click.click_note = note;
  105.     s.click.click_chan = chan;
  106.     
  107.     printf("click on (channel %d, note %d)\n", chan + 1, note);
  108. }
  109.