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

Contents of /src/pidim_common.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (show annotations)
Fri Aug 27 00:11:30 2010 UTC (10 years, 9 months ago) by ben
File MIME type: text/plain
File size: 2932 byte(s)
factorised cli code
1 /* 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 #include <alsa/asoundlib.h>
22 #include <stdlib.h>
23
24 /* common midi values */
25 #define CHAN_MAX 15
26 #define INST_MAX 127
27 #define VAL_MAX 127
28 #define CTRL_MAX 127
29
30 /* cli routines */
31 char* cli_parse(int argc, char** argv, const char* brief, const char* text);
32
33 /* ALSA routines */
34
35 /* create a client handle */
36 snd_seq_t* alsa_open_client (const char* name);
37
38 /* create an input port */
39 int alsa_open_input_port(snd_seq_t *handle, const char* name);
40
41 /* create an output port */
42 int alsa_open_output_port(snd_seq_t *handle, const char* name);
43
44 /* initialize an event queue */
45 int alsa_init_queue(snd_seq_t * handle, int seq_len);
46
47 /* clear an event queue */
48 void alsa_clear_queue(snd_seq_t *handle, int queue_id);
49
50 /* get the file descriptor of the first MIDI input port */
51 #if SND_LIB_MAJOR > 0 || SND_LIB_MINOR >= 6
52 /* FIXME: this is a dirty hack form XMBC code */
53 int alsa_get_fd(snd_seq_t *handle);
54 #endif
55
56 /* math routines */
57
58 /* return a random integer between 0 and 127 */
59 #define random127() (unsigned char)(random()%128)
60
61 /* return a random integer between 0 and 15 */
62 #define random15() (unsigned char)(random()%16)
63
64 #define scale(n, max, base) (((double)((n)*(base)))/(double)(max))
65 #define scale127(n, max) (scale((n),(max),127))
66 #define scale15(n, max) (scale((n),(max),15))
67 #define PI 3.1415926535897932384626434
68 #define scalePI(n, max) (scale((n),(max),PI))
69 #define scale2PI(n, max) (scale((n),(max),(2*PI)))
70
71 /* return an arbitrary lenghted array containing values 0 to max (and < 255) */
72 unsigned char* midi_ramp (int size, unsigned char max);
73
74 #define midi_ramp127(size) (midi_ramp ((size), 127))
75 #define midi_ramp15(size) (midi_ramp ((size), 15))
76
77 /* return a sinewave of arbitrary length containing values < max (and < 255) */
78 unsigned char* midi_sine (int period, unsigned char max);
79
80 #define midi_sine127(period) (midi_sine((period), 127))
81 #define midi_sine15(period) (midi_sine((period, 15))
82
83 /* return a random line of arbitrary length containing values < max (and < 255) */
84 unsigned char* midi_rand (int length, unsigned char max);
85
86 #endif

  ViewVC Help
Powered by ViewVC 1.1.26