Dont assign restore tasks to stateless clients; improve logs
[ladish.git] / clients / synth / main.c
blob1c1b882f90a4d0e330c9c6e4411982d78a955fa9
1 /*
2 * LASH
4 * Copyright (C) 2002 Robert Ham <rah@bash.sh>
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 #define _GNU_SOURCE
23 #include "config.h"
25 #include <sys/types.h>
26 #include <unistd.h>
27 #include <getopt.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <pthread.h>
33 #include "lash/lash.h"
35 #ifdef HAVE_GTK2
36 # include <gtk/gtk.h>
37 # include "interface.h"
38 #endif
40 #include "synth.h"
41 #include "lash.h"
43 #define MODULATION_DEFAULT 0.8
44 #define HARMONIC_DEFAULT 1
45 #define SUBHARMONIC_DEFAULT 3
46 #define TRANSPOSE_DEFAULT 12
47 #define ATTACK_DEFAULT 0.05
48 #define DECAY_DEFAULT 0.3
49 #define SUSTAIN_DEFAULT 0.8
50 #define RELEASE_DEFAULT 0.2
51 #define GAIN_DEFAULT 1.0
53 #define CLIENT_NAME_BASE "lash_synth"
55 static void
56 print_help()
58 printf("LASH Synth version %s\n", PACKAGE_VERSION);
59 printf("Copyright (C) 2002 Robert Ham <rah@bash.sh>\n");
60 printf("\n");
61 printf
62 ("This program comes with ABSOLUTELY NO WARRANTY. You are licensed to use it\n");
63 printf
64 ("under the terms of the GNU General Public License, version 2 or later. See\n");
65 printf("the COPYING file that came with this software for details.\n");
66 printf("\n");
67 printf(" -h, --help Display this help info\n");
68 printf(" --lash-port=<port> Connect to server on port <port>\n");
69 printf
70 (" -p, --pid Use the pid in the client string (default)\n");
71 printf
72 (" -e, --name <string> Use the specified string in the client string\n");
73 printf
74 (" -b, --basic-name Use just the program name in the client string\n");
75 printf("\n");
76 printf
77 (" -m, --modulation <float> Set the synth modulation parameter [%g]\n",
78 MODULATION_DEFAULT);
79 printf
80 (" -n, --harmonic <int> Set the synth harmonic parameter [%d]\n",
81 HARMONIC_DEFAULT);
82 printf
83 (" -u, --subharmonic <int> Set the synth subharmonic parameter [%d]\n",
84 SUBHARMONIC_DEFAULT);
85 printf
86 (" -t, --transpose <int> Set the synth transpose parameter [%d]\n",
87 TRANSPOSE_DEFAULT);
88 printf
89 (" -a, --attack <float> Set the synth attack parameter [%g]\n",
90 ATTACK_DEFAULT);
91 printf
92 (" -d, --decay <float> Set the synth decay parameter [%g]\n",
93 DECAY_DEFAULT);
94 printf
95 (" -s, --sustain <float> Set the synth sustain parameter [%g]\n",
96 SUSTAIN_DEFAULT);
97 printf
98 (" -r, --release <float> Set the synth release parameter [%g]\n",
99 RELEASE_DEFAULT);
100 printf
101 (" -g, --gain <float> Set the synth gain [%g]\n",
102 GAIN_DEFAULT);
103 printf("\n");
107 main(int argc, char **argv)
109 int opt;
110 const char *options = "hm:n:u:t:a:d:s:r:g:pe:";
111 struct option long_options[] = {
112 {"help", 0, NULL, 'h'},
113 {"pid", 0, NULL, 'p'},
114 {"name", 1, NULL, 'e'},
115 {"basic-name", 0, NULL, 'b'},
116 {"modulation", 1, NULL, 'm'},
117 {"harmonic", 1, NULL, 'n'},
118 {"subharmonic", 1, NULL, 'u'},
119 {"transpose", 1, NULL, 'y'},
120 {"attack", 1, NULL, 'a'},
121 {"decay", 1, NULL, 'd'},
122 {"sustain", 1, NULL, 's'},
123 {"release", 1, NULL, 'r'},
124 {"gain", 1, NULL, 'g'},
125 {0, 0, 0, 0}
127 lash_event_t *event;
128 lash_args_t *lash_args;
130 #ifdef HAVE_GTK2
131 pthread_t interface_thread;
132 #else
133 pthread_t lash_thread;
134 #endif
135 int flags = 0;
137 modulation = MODULATION_DEFAULT;
138 harmonic = HARMONIC_DEFAULT;
139 subharmonic = SUBHARMONIC_DEFAULT;
140 transpose = TRANSPOSE_DEFAULT;
141 attack = ATTACK_DEFAULT;
142 decay = DECAY_DEFAULT;
143 sustain = SUSTAIN_DEFAULT;
144 release = RELEASE_DEFAULT;
145 gain = GAIN_DEFAULT;
147 lash_args = lash_extract_args(&argc, &argv);
149 #ifdef HAVE_GTK2
150 gtk_init(&argc, &argv);
151 #endif
153 sprintf(alsa_client_name, "%s_%d", CLIENT_NAME_BASE, getpid());
154 sprintf(jack_client_name, "%s_%d", CLIENT_NAME_BASE, getpid());
156 while ((opt = getopt_long(argc, argv, options, long_options, NULL)) != -1) {
157 switch (opt) {
158 case 'm':
159 modulation = atof(optarg);
160 break;
161 case 'n':
162 harmonic = atoi(optarg);
163 break;
164 case 'u':
165 subharmonic = atoi(optarg);
166 break;
167 case 't':
168 transpose = atoi(optarg);
169 break;
170 case 'a':
171 attack = atof(optarg);
172 break;
173 case 'd':
174 decay = atof(optarg);
175 break;
176 case 's':
177 sustain = atof(optarg);
178 break;
179 case 'r':
180 release = atof(optarg);
181 break;
182 case 'g':
183 gain = atof(optarg);
184 break;
185 case 'p':
187 pid_t pid;
189 pid = getpid();
190 sprintf(alsa_client_name, "%s_%d", CLIENT_NAME_BASE, pid);
191 sprintf(jack_client_name, "%s_%d", CLIENT_NAME_BASE, pid);
192 break;
194 case 'e':
195 sprintf(alsa_client_name, "%s_%s", CLIENT_NAME_BASE, optarg);
196 sprintf(jack_client_name, "%s_%s", CLIENT_NAME_BASE, optarg);
197 break;
198 case 'b':
199 sprintf(alsa_client_name, "%s", CLIENT_NAME_BASE);
200 sprintf(jack_client_name, "%s", CLIENT_NAME_BASE);
201 break;
202 case 'h':
203 print_help();
204 exit(0);
205 break;
206 case ':':
207 case '?':
208 print_help();
209 exit(1);
210 break;
214 flags = LASH_Config_Data_Set;
215 #ifndef HAVE_GTK2
216 flags |= LASH_Terminal;
217 #endif
219 lash_client =
220 lash_init(lash_args, "LASH Synth", flags, LASH_PROTOCOL(2, 0));
222 if (!lash_client) {
223 fprintf(stderr, "%s: could not initialise lash\n", __FUNCTION__);
224 exit(1);
227 if (lash_enabled(lash_client)) {
228 event = lash_event_new_with_type(LASH_Client_Name);
229 lash_event_set_string(event, alsa_client_name);
230 lash_send_event(lash_client, event);
232 #ifdef HAVE_GTK2
233 pthread_create(&interface_thread, NULL, interface_main, NULL);
234 #else
235 pthread_create(&lash_thread, NULL, lash_thread_main, NULL);
236 #endif
238 synth_main(NULL);
240 return 0;