~ubuntu-branches/ubuntu/trusty/pmidi/trusty

« back to all changes in this revision

Viewing changes to src/seqlib.c

  • Committer: Bazaar Package Importer
  • Author(s): Matej Vela
  • Date: 2006-04-24 22:12:53 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20060424221253-dox8r0gy0ixmw6ds
Tags: 1.6.0-1
* QA upload.
* New upstream release.  Closes: #272609.
* Package is orphaned (#361299); set maintainer to Debian QA Group.
* Automatically update config.sub and config.guess from autotools-dev.
  Closes: #355139.
* Switch to debhelper 5.
* debian/copyright, debian/watch: Update upstream URL.
  Closes: #272610.
* debian/copyright: Update FSF address.
* Conforms to Standards version 3.6.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * File: seqlib.m - Interface to the alsa sequencer library.
3
3
 * 
4
 
 * Copyright (C) 1999 Steve Ratcliffe
 
4
 * Copyright (C) 1999-2003 Steve Ratcliffe
5
5
 * 
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License version 2 as
25
25
#include "seqlib.h"
26
26
#include "seqpriv.h"
27
27
 
 
28
static void set_channel(snd_seq_event_t *ep, int chan);
 
29
 
28
30
/*
29
31
 * Create a main client for an application. A queue is
30
32
 * allocated and a client is created.
77
79
 * link all together so can all be closed at once.
78
80
 */
79
81
void 
80
 
seq_free_context(seq_context_t *cxtp)
 
82
seq_free_context(seq_context_t *ctxp)
81
83
{
82
84
 
83
 
        if (cxtp->main == cxtp) {
 
85
        if (ctxp->main == ctxp) {
84
86
                /* This is the main context */
85
 
                snd_seq_free_queue(cxtp->handle, cxtp->queue);
86
 
                snd_seq_close(cxtp->handle);
 
87
                snd_seq_event_t ev;
 
88
                unsigned long t;
 
89
 
 
90
                snd_seq_drop_output(ctxp->handle);
 
91
 
 
92
                t = 0;
 
93
                seq_midi_event_init(ctxp, &ev, t, 0);
 
94
                seq_midi_control(ctxp, &ev, 0, MIDI_CTL_ALL_SOUNDS_OFF, 0);
 
95
                seq_send_to_all(ctxp, &ev);
 
96
                snd_seq_drain_output(ctxp->handle);
 
97
 
 
98
                snd_seq_free_queue(ctxp->handle, ctxp->queue);
 
99
                snd_seq_close(ctxp->handle);
87
100
        }
88
101
 
89
 
        g_free(cxtp);
 
102
        g_free(ctxp);
90
103
}
91
104
 
92
105
/*
116
129
}
117
130
 
118
131
void 
119
 
seq_destroy_port(seq_context_t *cxtp, int port)
 
132
seq_destroy_port(seq_context_t *ctxp, int port)
120
133
{
121
134
}
122
135
 
211
224
}
212
225
 
213
226
/*
 
227
 * seq_send_to_all:
 
228
 * Send the event to all the connected devices across all
 
229
 * possible channels. The messages are sent to the blocking
 
230
 * control port and so should not have timestamps in the
 
231
 * future. This function is intended for all-sounds-off type
 
232
 * controls etc.
 
233
 *  
 
234
 *  Arguments:
 
235
 *      ctxp: Client context
 
236
 *      ep: Event prototype to be sent
 
237
 */
 
238
int 
 
239
seq_send_to_all(seq_context_t *ctxp, snd_seq_event_t *ep)
 
240
{
 
241
        int  dev;
 
242
        int  chan;
 
243
        snd_seq_addr_t *addr;
 
244
 
 
245
        for (dev = 0; ; dev++) {
 
246
                addr = seq_dev_addr(ctxp, dev);
 
247
                if (addr == NULL)
 
248
                        break; /* No more */
 
249
 
 
250
                ep->queue = ctxp->queue;
 
251
                ep->dest = *addr;
 
252
                for (chan = 0; chan < 16; chan++) {
 
253
                        set_channel(ep, chan);
 
254
                        (void) seq_write(ctxp, ep);
 
255
                }
 
256
        }
 
257
 
 
258
        return 0;
 
259
}
 
260
 
 
261
/*
 
262
 * seq_dev_addr:
 
263
 * Return the address corresponding to the specified logical
 
264
 * device.
 
265
 *  
 
266
 *      Arguments:
 
267
 *      dev: Device to get the address of.
 
268
 *      inout: Input or output device
 
269
 */
 
270
snd_seq_addr_t *
 
271
seq_dev_addr(seq_context_t *ctxp, int dev)
 
272
{
 
273
        GArray *list;
 
274
        snd_seq_addr_t *addr;
 
275
 
 
276
        list = ctxp->destlist;
 
277
 
 
278
        if (dev >= (int)list->len)
 
279
                return NULL;
 
280
 
 
281
        addr = &g_array_index(list, snd_seq_addr_t, dev);
 
282
 
 
283
        return addr;
 
284
}
 
285
 
 
286
/*
214
287
 * Start the timer. (What about timers other than the system
215
288
 * one?)
216
289
 */
277
350
        return ctxp->handle;
278
351
}
279
352
 
 
353
static void 
 
354
set_channel(snd_seq_event_t *ep, int chan)
 
355
{
 
356
 
 
357
        switch (ep->type) {
 
358
        case SND_SEQ_EVENT_NOTE:
 
359
        case SND_SEQ_EVENT_NOTEON:
 
360
        case SND_SEQ_EVENT_NOTEOFF:
 
361
                ep->data.note.channel = chan;
 
362
                break;
 
363
        case SND_SEQ_EVENT_KEYPRESS:
 
364
        case SND_SEQ_EVENT_PGMCHANGE:
 
365
        case SND_SEQ_EVENT_CHANPRESS:
 
366
        case SND_SEQ_EVENT_PITCHBEND:
 
367
        case SND_SEQ_EVENT_CONTROL14:
 
368
        case SND_SEQ_EVENT_NONREGPARAM:
 
369
        case SND_SEQ_EVENT_REGPARAM:
 
370
        case SND_SEQ_EVENT_CONTROLLER:
 
371
                ep->data.control.channel = chan;
 
372
                break;
 
373
        default:
 
374
                if (snd_seq_ev_is_channel_type(ep))
 
375
                        g_warning("Missed a case in set_channel");
 
376
                break;
 
377
        }
 
378
}