~ubuntu-branches/ubuntu/vivid/oss4/vivid

« back to all changes in this revision

Viewing changes to lib/libOSSlib/play_event.c

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis, Samuel Thibault, Romain Beauxis, Sebastien NOEL
  • Date: 2011-06-14 10:06:56 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110614100656-cx4oc7u426zn812z
Tags: 4.2-build2004-1
[ Samuel Thibault ]
* debian/control: Add liboss4-salsa2, liboss4-salsa-dev and
  liboss4-salsa-asound2 packages, equivalent to (and will replace) those from
  the oss-libsalsa package (Closes: #589127).
* debian/patches/liboss4-salsa.patch: New patch to rename libsalsa into
  liboss4-salsa to avoid conflicts in the archive for no good reason.
* debian/rules: Make in libOSSlib and libsalsa.
* debian/liboss4-salsa-dev.install, debian/liboss4-salsa2.install,
  debian/liboss4-salsa-asound2.links, debian/liboss4-salsa-dev.links:
  Install liboss4-salsa libraries like was done in the oss-libsalsa package.
* include-alsa: Add a copy of ALSA 1.0.5 headers: Cf ALSA_1.0.* symbols in
  libsalsa, this is the roughly supported version.
* debian/copyright: Update for new include-alsa files.
* alsa.pc: New file for compatibility with libasound-dev.
* debian/control:
  - Add Vcs-Browser and Vcs-Svn fields.
  - Use linux-any instead of the list of Linux archs (Closes: #604679).
  - Make dkms dependency linux-any only.
* debian/patches/hurd_iot.patch: New patch to fix soundcard.h usage in
  libsalsa on hurd-i386.
* debian/patches/libsalsa_fixes.patch: New patch to fix some printf usages
  and ioctl declaration in libsalsa.
* debian/patches/no_EBADE.patch: New patch to cope with hurd-i386 not having
  EBADE.
* debian/patches/CFLAGS.patch: New patch to make oss4 take debian/rules
  CFLAGS into account.
* debian/patches/snd_asoundlib_version.patch: New patch to add
  snd_asoundlib_version().
* debian/patches/generic_srccconf.patch: New patch to fix source
  configuration on unknown archs.

[ Romain Beauxis ]
* Fixed README.Debian to only mention dkms' modules.
* Switch to dpkg-source 3.0 (quilt) format
* Added DM-Upload-Allowed: yes

[ Sebastien NOEL ]
* New upstream release (Closes: #595298, #619272).
* Fix typo in initscript (Closes: #627149).
* debian/control: adjust linux-headers dependencies (Closes: #628879).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <unistd.h>
 
2
#include <stdio.h>
 
3
#include <stdlib.h>
 
4
#include <string.h>
 
5
#include <fcntl.h>
 
6
#include "../../include/soundcard.h"
 
7
#include <sys/time.h>
 
8
 
 
9
#undef  DEBUG
 
10
 
 
11
extern int __seqfd;
 
12
 
 
13
static midi_packet_t midi_packet;
 
14
 
 
15
static unsigned char *midibuf = &midi_packet.payload[0];
 
16
static int mp = 0;
 
17
 
 
18
oss_midi_time_t current_tick = 0;
 
19
 
 
20
static int timer_started = 0;
 
21
 
 
22
void
 
23
OSS_set_timebase (int tb)
 
24
{
 
25
/* TODO? */
 
26
}
 
27
 
 
28
#if 1
 
29
#define _write write
 
30
#else
 
31
static size_t
 
32
_write (int fildes, void *b, size_t nbyte)
 
33
{
 
34
  midi_packet_header_t *hdr = b;
 
35
  unsigned char *buf;
 
36
  int l = nbyte;
 
37
 
 
38
 
 
39
  buf = (unsigned char *) b + sizeof (*hdr);
 
40
 
 
41
  if (hdr->magic == MIDI_HDR_MAGIC)     /* Timed mode write */
 
42
    {
 
43
      l -= sizeof (*hdr);
 
44
 
 
45
      switch (hdr->event_type)
 
46
        {
 
47
        case MIDI_EV_WRITE:
 
48
          printf ("%9lu: MIDI_EV_WRITE: ", hdr->time);
 
49
          break;
 
50
        case MIDI_EV_TEMPO:
 
51
          printf ("%9lu: MIDI_EV_TEMPO: ", hdr->time);
 
52
          break;
 
53
        case MIDI_EV_ECHO:
 
54
          printf ("%9lu: MIDI_EV_ECHO: ", hdr->time);
 
55
          break;
 
56
        case MIDI_EV_START:
 
57
          printf ("%9lu: MIDI_EV_START: ", hdr->time);
 
58
          break;
 
59
        case MIDI_EV_STOP:
 
60
          printf ("%9lu: MIDI_EV_STOP: ", hdr->time);
 
61
          break;
 
62
        default:
 
63
          printf ("%9lu: MIDI_EV_%d: ", hdr->time, hdr->event_type);
 
64
          break;
 
65
        }
 
66
 
 
67
      if (hdr->options & MIDI_OPT_TIMED)
 
68
        printf ("TIMED ");
 
69
 
 
70
      if (l > 0)
 
71
        {
 
72
          int i;
 
73
 
 
74
          printf ("%d bytes (", l);
 
75
 
 
76
          for (i = 0; i < l; i++)
 
77
            printf ("%02x ", buf[i]);
 
78
          printf (")");
 
79
        }
 
80
 
 
81
      printf ("\n");
 
82
    }
 
83
 
 
84
  return write (fildes, b, nbyte);
 
85
}
 
86
#endif
 
87
 
 
88
static void
 
89
start_timer (void)
 
90
{
 
91
#ifndef DEBUG
 
92
  midi_packet_header_t hdr;
 
93
 
 
94
  hdr.magic = MIDI_HDR_MAGIC;
 
95
  hdr.event_type = MIDI_EV_START;
 
96
  hdr.options = MIDI_OPT_NONE;
 
97
  hdr.time = 0;
 
98
  hdr.parm = 0;
 
99
  if (_write (__seqfd, &hdr, sizeof (hdr)) != sizeof (hdr))
 
100
    {
 
101
      perror ("Write start timer");
 
102
      exit (-1);
 
103
    }
 
104
 
 
105
  timer_started = 1;
 
106
  printf ("Timer started\n");
 
107
#endif
 
108
}
 
109
 
 
110
void
 
111
_dump_midi (void)
 
112
{
 
113
  if (mp > 0)
 
114
    {
 
115
      if (!timer_started)
 
116
        start_timer ();
 
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;
 
122
 
 
123
#ifdef DEBUG
 
124
      if (write (1, &midi_packet.payload[0], mp) == -1)
 
125
#else
 
126
      if (_write (__seqfd, &midi_packet, sizeof (midi_packet_header_t) + mp)
 
127
          == -1)
 
128
#endif
 
129
        {
 
130
          perror ("MIDI write");
 
131
          exit (-1);
 
132
        }
 
133
      mp = 0;
 
134
    }
 
135
}
 
136
 
 
137
static void
 
138
oss_do_timing (unsigned char *ev)
 
139
{
 
140
  unsigned int parm = *(unsigned int *) &ev[4];
 
141
  midi_packet_header_t hdr;
 
142
 
 
143
  oss_midi_time_t tick;
 
144
 
 
145
  _dump_midi ();
 
146
 
 
147
  switch (ev[1])
 
148
    {
 
149
    case TMR_TEMPO:
 
150
#ifndef DEBUG
 
151
      if (!timer_started)
 
152
        start_timer ();
 
153
      hdr.magic = MIDI_HDR_MAGIC;
 
154
      hdr.event_type = MIDI_EV_TEMPO;
 
155
      hdr.options = MIDI_OPT_TIMED;
 
156
      hdr.time = current_tick;
 
157
      hdr.parm = parm;
 
158
      if (_write (__seqfd, &hdr, sizeof (hdr)) != sizeof (hdr))
 
159
        {
 
160
          perror ("Write tempo");
 
161
          exit (-1);
 
162
        }
 
163
#endif
 
164
      break;
 
165
 
 
166
    case TMR_WAIT_REL:
 
167
      tick = current_tick + parm;
 
168
 
 
169
      current_tick = tick;
 
170
      break;
 
171
 
 
172
    case TMR_WAIT_ABS:
 
173
      tick = parm;
 
174
      current_tick = tick;
 
175
      break;
 
176
    }
 
177
 
 
178
}
 
179
 
 
180
static void
 
181
out_midi3 (unsigned char a, unsigned char b, unsigned char c)
 
182
{
 
183
  if (mp > 950)
 
184
    _dump_midi ();
 
185
  midibuf[mp++] = a;
 
186
  midibuf[mp++] = b;
 
187
  midibuf[mp++] = c;
 
188
/* printf("Out %02x %02x %02x\n", a, b, c); */
 
189
}
 
190
 
 
191
static void
 
192
out_midi2 (unsigned char a, unsigned char b)
 
193
{
 
194
  if (mp > 950)
 
195
    _dump_midi ();
 
196
  midibuf[mp++] = a;
 
197
  midibuf[mp++] = b;
 
198
/* printf("Out %02x %02x\n", a, b); */
 
199
}
 
200
 
 
201
void
 
202
play_event (unsigned char *ev)
 
203
{
 
204
  int i;
 
205
 
 
206
  switch (ev[0])
 
207
    {
 
208
    case EV_TIMING:
 
209
      oss_do_timing (ev);
 
210
      return;
 
211
      break;
 
212
 
 
213
    case EV_SEQ_LOCAL:
 
214
      break;
 
215
 
 
216
    case EV_CHN_COMMON:
 
217
      switch (ev[2])
 
218
        {
 
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]);
 
222
          break;
 
223
 
 
224
        case MIDI_CHN_PRESSURE:
 
225
          out_midi2 (ev[2] | ev[3], ev[4]);
 
226
          break;
 
227
 
 
228
        case MIDI_CTL_CHANGE:
 
229
          out_midi3 (ev[2] | ev[3], ev[4], *(short *) &ev[6]);
 
230
          break;
 
231
 
 
232
        default:
 
233
          out_midi3 (ev[2] | ev[3], ev[4], *(short *) &ev[6]);
 
234
        }
 
235
      return;
 
236
      break;
 
237
 
 
238
    case EV_CHN_VOICE:
 
239
      out_midi3 (ev[2] | ev[3], ev[4], ev[5]);
 
240
      return;
 
241
      break;
 
242
 
 
243
    case EV_SYSEX:
 
244
      {
 
245
        int i, l;
 
246
        l = 8;
 
247
        for (i = 2; i < 8; i++)
 
248
          if (ev[i] == 0xff)
 
249
            {
 
250
              l = i;
 
251
              break;
 
252
            }
 
253
        if (mp > 950)
 
254
          _dump_midi ();
 
255
        for (i = 2; i < l; i++)
 
256
          midibuf[mp++] = ev[i];
 
257
      }
 
258
      return;
 
259
      break;
 
260
 
 
261
    case EV_SYSTEM:
 
262
      printf ("EV_SYSTEM: ");
 
263
      break;
 
264
 
 
265
    default:
 
266
      printf ("Unknown event %d: ", ev[0]);
 
267
 
 
268
    }
 
269
 
 
270
  for (i = 0; i < 8; i++)
 
271
    printf ("%02x ", ev[i]);
 
272
  printf ("\n");
 
273
}