Annotation of embedaddon/bmon/src/out_audio.c, revision 1.1.1.1
1.1 misho 1: /*
2: * out_audio.c Save events
3: *
4: * Copyright (c) 2001-2005 Thomas Graf <tgraf@suug.ch>
5: * Claudio Mettler <claudio@fnord.ch>
6: *
7: * Permission is hereby granted, free of charge, to any person obtaining a
8: * copy of this software and associated documentation files (the "Software"),
9: * to deal in the Software without restriction, including without limitation
10: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11: * and/or sell copies of the Software, and to permit persons to whom the
12: * Software is furnished to do so, subject to the following conditions:
13: *
14: * The above copyright notice and this permission notice shall be included
15: * in all copies or substantial portions of the Software.
16: *
17: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23: * DEALINGS IN THE SOFTWARE.
24: */
25:
26: #include <bmon/bmon.h>
27: #include <bmon/node.h>
28: #include <bmon/output.h>
29: #include <bmon/graph.h>
30: #include <bmon/input.h>
31: #include <bmon/utils.h>
32: #include <inttypes.h>
33:
34: #include <alsa/asoundlib.h>
35:
36: static int c_max = 1000;
37: static int divisor;
38:
39: static snd_seq_t *seq_handle;
40: static snd_seq_event_t ev;
41:
42: #define CELL_MAX 127.0f
43:
44: void audio_draw(void)
45: {
46: rate_cnt_t rx, tx;
47: stat_attr_t *a;
48: item_t *it = get_current_item();
49:
50: if (it == NULL)
51: return;
52:
53: a = current_attr(it->i_graph_sel);
54: if (a == NULL)
55: return;
56:
57: rx = attr_get_rx_rate(a);
58: tx = attr_get_tx_rate(a);
59:
60: if (rx > c_max)
61: rx = c_max;
62:
63: if (tx > c_max)
64: tx = c_max;
65:
66: rx /= divisor;
67: tx /= divisor;
68:
69: snd_seq_ev_set_noteon(&ev, 0, rx, 127);
70: snd_seq_event_output_direct(seq_handle, &ev);
71: snd_seq_ev_set_noteoff(&ev, 0, rx, 127);
72: snd_seq_event_output_direct(seq_handle, &ev);
73:
74: snd_seq_ev_set_noteon(&ev, 1, tx, 127);
75: snd_seq_event_output_direct(seq_handle, &ev);
76: snd_seq_ev_set_noteoff(&ev, 1, tx, 127);
77: snd_seq_event_output_direct(seq_handle, &ev);
78: }
79:
80: static void print_module_help(void)
81: {
82: printf(
83: "Audio - Audio Output\n" \
84: "\n" \
85: " Outputs the currently selected attribute rate as MIDI\n" \
86: " sequence. OUT ::= (max(RATE,MAX)) / (MAX/127)\n" \
87: "\n" \
88: " Authors: Claudio Mettler <claudio@fnord.ch>\n" \
89: " Thomas Graf <tgraf@suug.ch>\n" \
90: "\n" \
91: " Options:\n" \
92: " max=NUM Upper limit\n");
93: }
94:
95: static void audio_set_opts(tv_t *attrs)
96: {
97: while (attrs) {
98: if (!strcasecmp(attrs->type, "max") && attrs->value)
99: c_max = strtol(attrs->value, NULL, 0);
100: else if (!strcasecmp(attrs->type, "help")) {
101: print_module_help();
102: exit(0);
103: }
104:
105: attrs = attrs->next;
106: }
107: }
108:
109: static void audio_shutdown(void)
110: {
111: }
112:
113: static int audio_probe(void)
114: {
115: snd_seq_addr_t src;
116:
117: if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_OUTPUT, 0) < 0) {
118: quit("Failed to access the ALSA sequencer.");
119: return 0;
120: }
121:
122: snd_seq_set_client_name(seq_handle, "bmonmidibridge");
123: src.client = snd_seq_client_id(seq_handle);
124: src.port = snd_seq_create_simple_port(seq_handle, "Output",
125: SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ,
126: SND_SEQ_PORT_TYPE_APPLICATION);
127:
128:
129: snd_seq_ev_clear(&ev);
130: snd_seq_ev_set_source(&ev, src.port);
131: snd_seq_ev_set_subs(&ev);
132: snd_seq_ev_set_direct(&ev);
133:
134: divisor = ceil(((double) c_max / CELL_MAX));
135:
136: return 1;
137: }
138:
139: static struct output_module audio_ops = {
140: .om_name = "audio",
141: .om_draw = audio_draw,
142: .om_set_opts = audio_set_opts,
143: .om_probe = audio_probe,
144: .om_shutdown audio_shutdown,
145: };
146:
147: static void __init audio_init(void)
148: {
149: register_secondary_output_module(&audio_ops);
150: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>