/[pidim]/src/pidim_common.h
ViewVC logotype

Annotation of /src/pidim_common.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (hide annotations)
Thu Aug 26 19:26:02 2010 UTC (9 years, 5 months ago) by ben
File MIME type: text/plain
File size: 2685 byte(s)
added some common routines for automation
1 ben 7 /* pidim_common, part of the Pidim project.
2     * Copyright (C) 2010 Benoit Rouits
3     *
4     * This program is free software; you can redistribute it and/or modify
5     * it under the terms of the GNU General Public License as published by
6     * the Free Software Foundation; either version 2 of the License, or
7     * (at your option) any later version.
8     *
9     * This program is distributed in the hope that it will be useful,
10     * but WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     * GNU General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License along
15     * with this program; if not, write to the Free Software Foundation, Inc.,
16     * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17     */
18    
19     #ifndef PIDIM_COMMON
20     #define PIDIM_COMMON
21 ben 1 #include <alsa/asoundlib.h>
22 ben 8 #include <stdlib.h>
23 ben 1
24     /* create a client handle */
25     snd_seq_t* alsa_open_client (const char* name);
26    
27     /* create an input port */
28     int alsa_open_input_port(snd_seq_t *handle, const char* name);
29    
30     /* create an output port */
31     int alsa_open_output_port(snd_seq_t *handle, const char* name);
32    
33     /* initialize an event queue */
34 ben 3 int alsa_init_queue(snd_seq_t * handle, int seq_len);
35 ben 1
36     /* clear an event queue */
37     void alsa_clear_queue(snd_seq_t *handle, int queue_id);
38    
39     /* get the file descriptor of the first MIDI input port */
40     #if SND_LIB_MAJOR > 0 || SND_LIB_MINOR >= 6
41     /* FIXME: this is a dirty hack form XMBC code */
42     int alsa_get_fd(snd_seq_t *handle);
43     #endif
44 ben 7
45 ben 8 /* return a random integer between 0 and 127 */
46     #define random127() (unsigned char)(random()%128)
47    
48     /* return a random integer between 0 and 15 */
49     #define random15() (unsigned char)(random()%16)
50    
51     #define scale(n, max, base) (((double)((n)*(base)))/(double)(max))
52     #define scale127(n, max) (scale((n),(max),127))
53     #define scale15(n, max) (scale((n),(max),15))
54     #define PI 3.1415926535897932384626434
55     #define scalePI(n, max) (scale((n),(max),PI))
56     #define scale2PI(n, max) (scale((n),(max),(2*PI)))
57    
58     /* return an arbitrary lenghted array containing values 0 to max (and < 255) */
59     unsigned char* midi_ramp (int size, unsigned char max);
60    
61     #define midi_ramp127(size) (midi_ramp ((size), 127))
62     #define midi_ramp15(size) (midi_ramp ((size), 15))
63    
64     /* return a sinewave of arbitrary length containing values < max (and < 255) */
65     unsigned char* midi_sine (int period, unsigned char max);
66    
67     #define midi_sine127(period) (midi_sine((period), 127))
68     #define midi_sine15(period) (midi_sine((period, 15))
69    
70     /* return a random line of arbitrary length containing values < max (and < 255) */
71     unsigned char* midi_rand (int length, unsigned char max);
72    
73 ben 7 #endif

  ViewVC Help
Powered by ViewVC 1.1.26