6
#include "../../include/soundcard.h"
13
static midi_packet_t midi_packet;
15
static unsigned char *midibuf = &midi_packet.payload[0];
18
oss_midi_time_t current_tick = 0;
20
static int timer_started = 0;
23
OSS_set_timebase (int tb)
32
_write (int fildes, void *b, size_t nbyte)
34
midi_packet_header_t *hdr = b;
39
buf = (unsigned char *) b + sizeof (*hdr);
41
if (hdr->magic == MIDI_HDR_MAGIC) /* Timed mode write */
45
switch (hdr->event_type)
48
printf ("%9lu: MIDI_EV_WRITE: ", hdr->time);
51
printf ("%9lu: MIDI_EV_TEMPO: ", hdr->time);
54
printf ("%9lu: MIDI_EV_ECHO: ", hdr->time);
57
printf ("%9lu: MIDI_EV_START: ", hdr->time);
60
printf ("%9lu: MIDI_EV_STOP: ", hdr->time);
63
printf ("%9lu: MIDI_EV_%d: ", hdr->time, hdr->event_type);
67
if (hdr->options & MIDI_OPT_TIMED)
74
printf ("%d bytes (", l);
76
for (i = 0; i < l; i++)
77
printf ("%02x ", buf[i]);
84
return write (fildes, b, nbyte);
92
midi_packet_header_t hdr;
94
hdr.magic = MIDI_HDR_MAGIC;
95
hdr.event_type = MIDI_EV_START;
96
hdr.options = MIDI_OPT_NONE;
99
if (_write (__seqfd, &hdr, sizeof (hdr)) != sizeof (hdr))
101
perror ("Write start timer");
106
printf ("Timer started\n");
117
midi_packet.hdr.magic = MIDI_HDR_MAGIC;
118
midi_packet.hdr.options = MIDI_OPT_TIMED;
119
midi_packet.hdr.event_type = MIDI_EV_WRITE;
120
midi_packet.hdr.parm = 0;
121
midi_packet.hdr.time = current_tick;
124
if (write (1, &midi_packet.payload[0], mp) == -1)
126
if (_write (__seqfd, &midi_packet, sizeof (midi_packet_header_t) + mp)
130
perror ("MIDI write");
138
oss_do_timing (unsigned char *ev)
140
unsigned int parm = *(unsigned int *) &ev[4];
141
midi_packet_header_t hdr;
143
oss_midi_time_t tick;
153
hdr.magic = MIDI_HDR_MAGIC;
154
hdr.event_type = MIDI_EV_TEMPO;
155
hdr.options = MIDI_OPT_TIMED;
156
hdr.time = current_tick;
158
if (_write (__seqfd, &hdr, sizeof (hdr)) != sizeof (hdr))
160
perror ("Write tempo");
167
tick = current_tick + parm;
181
out_midi3 (unsigned char a, unsigned char b, unsigned char c)
188
/* printf("Out %02x %02x %02x\n", a, b, c); */
192
out_midi2 (unsigned char a, unsigned char b)
198
/* printf("Out %02x %02x\n", a, b); */
202
play_event (unsigned char *ev)
219
case MIDI_PGM_CHANGE:
220
/* printf("PGM change %02x %d\n", ev[2]|ev[3], ev[4]); */
221
out_midi2 (ev[2] | ev[3], ev[4]);
224
case MIDI_CHN_PRESSURE:
225
out_midi2 (ev[2] | ev[3], ev[4]);
228
case MIDI_CTL_CHANGE:
229
out_midi3 (ev[2] | ev[3], ev[4], *(short *) &ev[6]);
233
out_midi3 (ev[2] | ev[3], ev[4], *(short *) &ev[6]);
239
out_midi3 (ev[2] | ev[3], ev[4], ev[5]);
247
for (i = 2; i < 8; i++)
255
for (i = 2; i < l; i++)
256
midibuf[mp++] = ev[i];
262
printf ("EV_SYSTEM: ");
266
printf ("Unknown event %d: ", ev[0]);
270
for (i = 0; i < 8; i++)
271
printf ("%02x ", ev[i]);