Debian Codegraph @

main.cpp

raw symbols SCIP
1 /* Copyright 2013 Kjetil S. Matheussen
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; either version 2
6 of the License, or (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
16
17
18 #include <math.h>
19 #include <signal.h>
20
21 #include <string>
22
23 //#include "audio/faudiostream/architecture/faust/gui/UI.h"
24
25 #include "nonlib/nsm.h"
26
27 #include <vector>
28
29 #define OPTARGS_CHECK_GET(wrong,right) lokke==argc-1?(fprintf(stderr,"Must supply argument for '%s'\n",argv[lokke]),exit(-4),wrong):right
30
31 #define OPTARGS_BEGIN(das_usage) {int lokke;const char *usage=das_usage;for(lokke=1;lokke<argc;lokke++){char *a=argv[lokke];if(!strcmp("--help",a)||!strcmp("-h",a)){fprintf(stderr,"%s",usage);exit(0);
32 #define OPTARG(name,name2) }}else if(!strcmp(name,a)||!strcmp(name2,a)){{
33 #define OPTARG_GETINT() OPTARGS_CHECK_GET(0,atoll(argv[++lokke]))
34 //int optargs_inttemp;
35 //#define OPTARG_GETINT() OPTARGS_CHECK_GET(0,(optargs_inttemp=strtol(argv[++lokke],(char**)NULL,10),errno!=0?(perror("strtol"),0):optargs_inttemp))
36 #define OPTARG_GETFLOAT() OPTARGS_CHECK_GET(0.0f,atof(argv[++lokke]))
37 #define OPTARG_GETSTRING() OPTARGS_CHECK_GET("",argv[++lokke])
38 #define OPTARG_LAST() }}else if(lokke==argc-1 && argv[lokke][0]!='-'){lokke--;{
39 #define OPTARGS_ELSE() }else if(1){
40 #define OPTARGS_END }else{fprintf(stderr,"%s",usage);exit(-1);}}}
41
42 #include "common/nsmtracker.h"
43 #include "Qt/Qt_MyQCheckBox.h"
44 #include "Qt/Qt_MyQSlider.h"
45 #include "Qt/Qt_MyQButton.h"
46
47 static QColor das_colors[16];
48 QColor *g_colors=&das_colors[0];
49
50 #include "mQt_compressor_widget_callbacks.h"
51
52 static void set_colors(void){
53 das_colors[0] = QColor("#828070");
54 das_colors[1] = QColor("#00001d");
55 das_colors[2] = QColor("#f1ece6");
56 das_colors[3] = QColor("#98006d");
57 das_colors[4] = QColor("#6437a7");
58 das_colors[5] = QColor("#354353");
59 das_colors[6] = QColor("#8b6735");
60 das_colors[7] = QColor("#23405d");
61 das_colors[8] = QColor("#310062");
62 das_colors[9] = QColor("#8a8877");
63 das_colors[10] = QColor("#7a7a7a");
64 das_colors[11] = QColor("#696c5f");
65 das_colors[12] = QColor("#a1b09b");
66 das_colors[13] = QColor("#13511f");
67 das_colors[14] = QColor("#8a0000");
68 das_colors[15] = QColor("#7a7967");
69 }
70
71 bool g_autoconnect = false;
72 const char *g_jack_client_name = "radium_compressor";
73 const char *g_settings_filename = NULL;
74 const char *g_shared_mem_key = NULL;
75
76 static Compressor_widget *g_compressor_editor = NULL;
77 static void *g_compressor = NULL;
78
79 Compressor_widget *create_compressor_editor(QWidget *parent, void *compressor){
80 // A minimal radium patch environment.
81 struct Patch *patch = new Patch;
82 SoundPlugin *plugin = new SoundPlugin;
83 patch->patchdata = plugin;
84 plugin->compressor = compressor;
85
86 Compressor_widget *compressor_widget = new Compressor_widget(patch,parent);
87
88 if(g_settings_filename!=NULL)
89 compressor_widget->load(g_settings_filename);
90
91 set_colors();
92
93 QPalette pal = compressor_widget->palette();
94 //pal.setColor(compressor.backgroundRole(), das_colors[11].light(200));
95 pal.setColor(compressor_widget->backgroundRole(), das_colors[11].light(100));
96 compressor_widget->setPalette(pal);
97
98 return compressor_widget;
99 }
100
101 void delete_compressor_editor(Compressor_widget *compressor_editor){
102 struct Patch *patch=compressor_editor->_patch;
103 struct SoundPlugin *plugin=(SoundPlugin*)patch->patchdata;
104 COMPRESSOR_delete(plugin->compressor);
105 //delete compressor;
106 }
107
108 static nsm_client_t *g_nsm = 0;
109 static bool g_nsm_quit_now = false;
110
111
112 struct NSMTimer : public QTimer{
113 void timerEvent(QTimerEvent * e){
114 if(g_nsm_quit_now==true)
115 QApplication::quit();
116 else
117 nsm_check_nowait(g_nsm);
118 }
119 };
120
121 NSMTimer g_nsm_timer;
122
123 static const char *g_nsm_save_filename;
124
125 int rc_nsm_open ( const char *name,
126 const char *display_name,
127 const char *client_id,
128 char **out_msg,
129 void *userdata )
130 {
131
132 if(g_compressor_editor != NULL) {
133 fprintf(stderr,"calling nsm open twice is not supported.\n");
134 abort();
135 }
136
137 //do_open_stuff();
138 g_jack_client_name = client_id;
139 g_compressor = COMPRESSOR_create(0);
140
141 if(g_nsm_save_filename != NULL)
142 free((void*)g_nsm_save_filename);
143 g_nsm_save_filename = strdup(name);
144
145 g_compressor_editor = create_compressor_editor(NULL, g_compressor);
146 g_compressor_editor->load_button->hide();
147 g_compressor_editor->save_button->hide();
148 g_compressor_editor->setWindowFlags ( Qt::CustomizeWindowHint | Qt::WindowTitleHint);
149
150 g_compressor_editor->load(name, false);
151 g_compressor_editor->show();
152
153
154 char temp[1000];
155 sprintf(temp, "Open. name: %s, display_name: %s, client_id: %s\n",name, display_name, client_id);
156 *out_msg = strdup(temp);
157 puts(temp);
158
159 return ERR_OK;
160 }
161
162 int rc_nsm_save ( char **out_msg,
163 void *userdata )
164 {
165 //do_save_stuff();
166 g_compressor_editor->save(g_nsm_save_filename);
167
168 char temp[1000];
169 sprintf(temp, "Save. userdata: %p\n", userdata);
170 *out_msg = strdup(temp);
171 puts(temp);
172 return ERR_OK;
173 }
174
175 void rc_nsm_signalHanlder(int sigNum)
176 {
177 g_nsm_quit_now = true;
178 }
179
180
181 void start_program(int argc, char **argv){
182
183 QApplication app(argc, argv);
184
185 {
186
187
188 // nsm
189 {
190 const char *nsm_url = getenv( "NSM_URL" );
191 if ( nsm_url )
192 {
193 g_nsm = nsm_new();
194
195 printf("NSM: %p\n",g_nsm);
196
197 nsm_set_open_callback( g_nsm, rc_nsm_open, 0 );
198 nsm_set_save_callback( g_nsm, rc_nsm_save, 0 );
199
200 if ( 0 == nsm_init( g_nsm, nsm_url ) )
201 {
202 signal(SIGTERM, rc_nsm_signalHanlder);
203 nsm_send_announce( g_nsm, "Radium Compressor", "", argv[0] );
204 g_nsm_timer.setInterval(50);
205 g_nsm_timer.start();
206
207 }
208 else
209 {
210 nsm_free( g_nsm );
211 g_nsm = 0;
212 }
213 }
214 }
215
216 if(g_nsm == NULL){
217 if (g_compressor == NULL)
218 g_compressor = COMPRESSOR_create(0);
219 g_compressor_editor = create_compressor_editor(NULL, g_compressor);
220 g_compressor_editor->show();
221 }
222
223 app.exec();
224
225 if(g_compressor_editor != NULL)
226 delete_compressor_editor(g_compressor_editor);
227 }
228 }
229
230 #ifndef COMPILING_VST
231
232 void *COMPRESSOR_create_ladspa(const char *key);
233
234
235
236
237 int main(int argc, char **argv){
238
239 {
240 // Qt insists on doing strange things with locale settings, causing commans to appear instead of punctation. In an ideal world, LC_NUMERIC/LANG should never be set to anything else than "C", but unfortunately, many computers runs with uncommon language settings such as french or swedish. By default, programs seems to respect the sane behaviour (in the programming world), namely to never use commas when converting between strings and floats, but Qt does something strange with the world inside the QApplication contructor, and causes commas to be used everywhere if there is an uncommon LC_NUMERIC settings (or uncommon LANG setting).
241
242 setenv("LC_NUMERIC", "C", 1);
243
244 putenv(strdup("LC_NUMERIC=C")); // for mingw
245
246 QLocale::setDefault(QLocale::c());
247
248 QApplication::setDesktopSettingsAware(false);
249
250 QLocale::setDefault(QLocale::C);
251 }
252
253 OPTARGS_BEGIN("radium_compressor [--autoconnect] [--client-name s] [--settings-filename s] [settings-filename]\n"
254 " [ -ac ] [ -cn s] [ -sn s] [settings filename]\n"
255 "\n"
256 "\"autoconnect\" connects radium_compressor to physical in and out ports.\n"
257 "\"client-name\" sets the name of the jack client.\n"
258 "\"settings-filename\" is the name of a settings file to load at startup.\n"
259 )
260 {
261
262 OPTARG("--settings-filename","-sn") g_settings_filename=OPTARG_GETSTRING();
263 OPTARG("--autoconnect","-ac") g_autoconnect=true;
264 OPTARG("--client-name","-cn") g_jack_client_name=OPTARG_GETSTRING();
265 //OPTARG("--ladspa-slave","-ls") g_shared_mem_key = OPTARG_GETSTRING();
266 OPTARG_LAST() g_settings_filename=OPTARG_GETSTRING();
267 }OPTARGS_END;
268
269 if(g_shared_mem_key!=NULL){
270
271 g_compressor = COMPRESSOR_create_ladspa(g_shared_mem_key);
272 start_program(argc,argv);
273
274 }else{
275
276 start_program(argc,argv);
277
278 }
279 return 0;
280 }
281
282 #endif