added jackrack filter
[melted] / src / modules / jackrack / ui.c
1 /*
2 * JACK Rack
3 *
4 * Copyright (C) Robert Ham 2002, 2003 (node@users.sourceforge.net)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <strings.h>
24 #include <string.h>
25 #include <ctype.h>
26 #include <limits.h>
27 #include <stdarg.h>
28 #include <unistd.h>
29
30 #include <glib.h>
31 #include <ladspa.h>
32
33 #include "ui.h"
34 #include "control_message.h"
35
36
37 #define PROCESS_FIFO_SIZE 64
38 #define MIDI_FIFO_SIZE 256
39
40 ui_t *
41 ui_new (const char * client_name, unsigned long channels,
42 gboolean connect_inputs, gboolean connect_outputs)
43 {
44 ui_t * ui;
45
46 ui = g_malloc (sizeof (ui_t));
47 ui->filename = NULL;
48 ui->shutdown = FALSE;
49 ui->state = STATE_NORMAL;
50
51 ui->ui_to_process = lff_new (PROCESS_FIFO_SIZE, sizeof (ctrlmsg_t));
52 ui->process_to_ui = lff_new (PROCESS_FIFO_SIZE, sizeof (ctrlmsg_t));
53
54 ui->procinfo = process_info_new (ui, client_name, channels, connect_inputs, connect_outputs);
55 if (!ui->procinfo)
56 return NULL;
57
58 ui->plugin_mgr = plugin_mgr_new (ui);
59 plugin_mgr_set_plugins (ui->plugin_mgr, channels);
60 ui->jack_rack = jack_rack_new (ui, channels);
61
62 return ui;
63 }
64
65
66 void
67 ui_quit (ui_t * ui)
68 {
69 ctrlmsg_t ctrlmsg;
70
71 ui_set_state (ui, STATE_QUITTING);
72 ctrlmsg.type = CTRLMSG_QUIT;
73 lff_write (ui->ui_to_process, &ctrlmsg);
74 }
75
76 void
77 ui_destroy (ui_t * ui)
78 {
79 if (!ui->shutdown)
80 ui_quit (ui);
81 jack_rack_destroy (ui->jack_rack);
82
83 g_free (ui);
84 }
85
86 void
87 ui_set_state (ui_t * ui, ui_state_t state)
88 {
89 ui->state = state;
90 }
91
92 ui_state_t
93 ui_get_state (ui_t * ui)
94 {
95 return ui->state;
96 }
97
98 void
99 jack_shutdown_cb (void * data)
100 {
101 ui_t * ui = data;
102
103 ui->shutdown = TRUE;
104 }
105
106 /* do the process->gui message processing */
107 gboolean
108 ui_loop_iterate (ui_t * ui)
109 {
110 ctrlmsg_t ctrlmsg;
111 jack_rack_t * jack_rack = ui->jack_rack;
112
113 while (lff_read (ui->process_to_ui, &ctrlmsg) == 0)
114 {
115 switch (ctrlmsg.type)
116 {
117 case CTRLMSG_ADD:
118 jack_rack_add_plugin (jack_rack, ctrlmsg.data.add.plugin);
119 break;
120
121 case CTRLMSG_REMOVE:
122 plugin_destroy (ctrlmsg.data.remove.plugin, ui);
123 break;
124
125 case CTRLMSG_QUIT:
126 return TRUE;
127 break;
128
129 }
130 }
131
132 usleep (100000);
133
134 return FALSE;
135 }
136
137 /* EOF */