~ubuntu-branches/debian/stretch/bristol/stretch

« back to all changes in this revision

Viewing changes to brighton/brighton.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-04-23 09:49:32 UTC
  • mfrom: (1.2.1 upstream) (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100423094932-btfvxmt11hv8dj4p
Tags: 0.60.0-4
* Switch back to deb format 1.0, bug#578693 has been fixed.
* Refresh and improvements, another attempt to fix FTBFS on
  hppa,sparc,s390.
* Drop debian/patches/02-implicit_pointer_conversion.patch patch,
  applied upstream.
* Patch to fix FTBFS on hurd-i386.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/*
3
3
 *  Diverse Bristol audio routines.
4
 
 *  Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2009
 
4
 *  Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2010
5
5
 *
6
6
 *
7
7
 *   This program is free software; you can redistribute it and/or modify
8
 
 *   it under the terms of the GNU General Public License as published by
9
 
 *   the Free Software Foundation; either version 2 of the License, or
 
8
 *       it under the terms of the GNU General Public License as published by
 
9
 *   the Free Software Foundation; either version 3 of the License, or
10
10
 *   (at your option) any later version.
11
11
 *
12
12
 *   This program is distributed in the hope that it will be useful,
15
15
 *   GNU General Public License for more details.
16
16
 *
17
17
 *   You should have received a copy of the GNU General Public License
18
 
 *   along with this program; if not, write to the Free Software
19
 
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 *   along with this program; if not, see <http://www.gnu.org/licenses/>.
20
19
 *
21
20
 */
22
21
 
25
24
#include <stdlib.h>
26
25
#include <sys/time.h>
27
26
 
 
27
#include <sys/types.h>
 
28
#include <sys/stat.h>
 
29
#include <unistd.h>
 
30
 
28
31
#include <pthread.h>
29
32
 
30
33
#include "brighton.h"
79
82
extern brightonApp sidApp;
80
83
extern brightonApp sid2App;
81
84
 
 
85
extern int brightonCLIcheck(guimain *);
 
86
extern int brightonCLIinit(guimain *, int *);
 
87
 
82
88
#define BRIGHTON_BIT99APP (BRISTOL_SYNTHCOUNT + 1)
83
89
 
84
90
char *bristolhome = NULL;
86
92
guimain global;
87
93
 
88
94
brightonApp *synthesisers[BRISTOL_SYNTHCOUNT];
 
95
#include "brightonreadme.h"
 
96
 
 
97
static char *defname = "bristol";
89
98
 
90
99
void *eventMgr();
91
100
 
 
101
int readMe = 0;
 
102
int gmc = 0;
92
103
int opacity = 60;
93
104
int gs = 1;
94
105
int nar = 0;
 
106
int azoom = 0;
95
107
int quality = 6;
 
108
int deswidth = -1;
96
109
float scale = 1.0;
97
110
float antialias = 0.0;
98
111
int aliastype = 0;
103
116
int mwt = 50000;
104
117
int activeSense = 2000;
105
118
int activeSensePeriod = 15000;
 
119
int bwflags = BRIGHTON_POST_WINDOW;
 
120
int rlflags = BRIGHTON_SET_RAISE|BRIGHTON_SET_LOWER;
 
121
int nrpcc = BRIGHTON_NRP_COUNT;
 
122
int cli = 0;
 
123
int cli_fd[2];
106
124
 
107
125
static char *BRISTOL_DEF_HOST = "localhost";
108
126
 
 
127
extern int vuInterval;
 
128
void printBrightonHelp(int);
 
129
void printBrightonReadme();
 
130
 
109
131
extern int brightonMidiInput(bristolMidiMsg *);
 
132
extern void brightonControlKeyInput(brightonWindow *, int, int);
110
133
 
111
134
/*
112
135
 * Some of the emulations really benefit from a bit of detune, this is the
114
137
 */
115
138
#define NON_DEF_DETUNE 100
116
139
 
 
140
static int asc, emStart = 0, midiHandle = -1;
 
141
 
 
142
volatile sig_atomic_t ladiRequest = 0;
 
143
 
 
144
static void
 
145
savehandler()
 
146
{
 
147
        if (global.synths->flags & LADI_ENABLE && global.synths->ladimode)
 
148
                ladiRequest = 1;
 
149
        else
 
150
                ladiRequest = 0;
 
151
}
 
152
 
 
153
static void
 
154
loadhandler()
 
155
{
 
156
        if (global.synths->flags & LADI_ENABLE && global.synths->ladimode)
 
157
                ladiRequest = 2;
 
158
        else
 
159
                ladiRequest = 0;
 
160
}
 
161
 
 
162
static void
 
163
brightonFindEmulation(int argc, char **argv)
 
164
{
 
165
        int argCount, i, found = -1;
 
166
 
 
167
        for (argCount = 1; argCount < argc; argCount++)
 
168
        {
 
169
                if (argv[argCount][0] != '-')
 
170
                        continue;
 
171
 
 
172
                for (i = 0 ; i < BRISTOL_SYNTHCOUNT; i++)
 
173
                {
 
174
                        if (synthesisers[i] == NULL)
 
175
                                continue;
 
176
 
 
177
                        if (strcmp(synthesisers[i]->name, &argv[argCount][1]) == 0)
 
178
                                found = global.synths->synthtype = i;
 
179
                }
 
180
        }
 
181
 
 
182
        /*
 
183
         * Global.synths->synthtype will now either be the last emulator found or
 
184
         * will be the usual default (b3). Stuff this back into i, that is nicely
 
185
         * confusing but makes the lines shorter. Hm.
 
186
         */
 
187
        i = global.synths->synthtype;
 
188
 
 
189
        if (found > 0)
 
190
                printf("%s emulation defaults:\n", synthesisers[i]->name);
 
191
        else
 
192
                printf("emulation defaults:\n");
 
193
 
 
194
        if ((global.synths->voices = synthesisers[i]->emulate.voices)
 
195
                < 0)
 
196
        {
 
197
                printf("    -voices  %i\n", BRISTOL_VOICECOUNT);
 
198
                global.synths->voices = BRISTOL_VOICECOUNT;
 
199
        } else
 
200
                printf("    -voices  %i\n",synthesisers[i]->emulate.voices);
 
201
        if (global.synths->voices == 1)
 
202
        {
 
203
                printf("    -retrig\n");
 
204
                printf("    -lvel\n");
 
205
                printf("    -hnp\n");
 
206
                printf("    -wwf\n");
 
207
                global.synths->lwf = 2;
 
208
                global.synths->legatovelocity = 1;
 
209
                global.synths->notepref = BRIGHTON_HNP;
 
210
                global.synths->notetrig = 1;
 
211
        }
 
212
        if (i == BRISTOL_2600)
 
213
                printf("    -multi   4\n");
 
214
        printf("    -detune  %i\n", synthesisers[i]->emulate.detune);
 
215
        printf("    -gain    %i\n",     synthesisers[i]->emulate.gain);
 
216
        printf("    -pwd     %i\n",     synthesisers[i]->emulate.pwd);
 
217
        printf("    -glide   %i\n",     synthesisers[i]->emulate.glide);
 
218
        printf("    -curve   %i\n",     synthesisers[i]->emulate.velocity);
 
219
 
 
220
        global.synths->detune = synthesisers[i]->emulate.detune;
 
221
        global.synths->gain = synthesisers[i]->emulate.gain * 16;
 
222
        global.synths->pwd = synthesisers[i]->emulate.pwd;
 
223
        global.synths->glide = synthesisers[i]->emulate.glide;
 
224
        global.synths->velocity = synthesisers[i]->emulate.velocity;
 
225
        if (synthesisers[i]->emulate.opacity != 0)
 
226
                printf("    -opacity %i\n",
 
227
                        opacity = synthesisers[i]->emulate.opacity);
 
228
}
 
229
 
117
230
/*
118
231
 * Need to make this multithreaded?
119
232
 */
120
233
int
121
234
main(int argc, char **argv)
122
235
{
123
 
        int argCount = 1, midiHandle = -1, cFD = -1, midiFD = -1, i, j, asc = 0;
124
 
        pthread_t thread;
125
 
        bristolMidiMsg msg;
 
236
        int argCount = 1, i, j, logtype = BRISTOL_LOG_BRIGHTON;
 
237
        pthread_t emgrThread, logthread;
 
238
        char appname[65], *devname = defname;
126
239
 
127
240
        signal(SIGINT, cleanupBristol);
128
241
        signal(SIGPIPE, cleanupBristolQuietly);
129
242
        signal(SIGHUP, cleanupBristol);
 
243
        signal(SIGUSR1, savehandler);
 
244
        signal(SIGUSR2, loadhandler);
130
245
 
131
246
        global.home = getenv("BRISTOL");
132
247
 
136
251
        global.synths->voices = BRISTOL_VOICECOUNT;
137
252
        global.synths->pwd = 2;
138
253
        global.synths->gain = 32;
 
254
        global.synths->ladimem = 1024;
139
255
        global.synths->synthtype = BRISTOL_HAMMONDB3;
140
256
        global.synths->velocity = 510;  /* linear tracking */
141
257
        global.synths->glide = 5;  /* maximum glide delay - up to 30s */
142
258
        global.synths->detune = 40;
143
 
        global.synths->lwf = 0;
 
259
        global.synths->lowkey = 0;
 
260
        global.synths->highkey = 127;
 
261
        global.synths->lwf = 0; //3;
144
262
        global.synths->mbi = 0;
145
 
        global.synths->notepref = 0;
 
263
        global.synths->notepref = BRIGHTON_POLYPHONIC;
146
264
        global.synths->notetrig = 0;
147
 
        global.port = -1;
 
265
        global.synths->win = NULL;
 
266
        global.synths->flags = REQ_FORWARD|REQ_LOCAL_FORWARD|REQ_REMOTE_FORWARD;
 
267
        global.port = 5028;
148
268
        global.host = BRISTOL_DEF_HOST;
149
269
 
 
270
        memset(synthesisers, 0, sizeof(synthesisers));
 
271
 
150
272
        synthesisers[BRISTOL_MINI] = &miniApp;
151
273
        synthesisers[BRISTOL_PROPHET] = &prophetApp;
152
274
        synthesisers[BRISTOL_PRO52] = &prophet52App;
190
312
        synthesisers[BRISTOL_SID_M1] = &sidApp;
191
313
        synthesisers[BRISTOL_SID_M2] = &sid2App;
192
314
 
193
 
        global.synths->location = 0;
 
315
        readme[BRISTOL_PRO52] = readme[BRISTOL_PROPHET];
 
316
        readme[BRISTOL_VOYAGER] = readme[BRISTOL_EXPLORER];
 
317
 
 
318
        if (argc == 1)
 
319
        {
 
320
                printf("You probably prefer to use the startBristol script.\n");
 
321
                exit(0);
 
322
        }
 
323
 
 
324
        if (strcmp(argv[1], "-console") == 0)
 
325
                logtype = BRISTOL_LOG_CONSOLE;
 
326
 
 
327
        if (strcmp(argv[1], "-readme") == 0)
 
328
        {
 
329
                readMe = 1;
 
330
                logtype = BRISTOL_LOG_CONSOLE;
 
331
                if (argc == 2)
 
332
                {
 
333
                        printBrightonReadme();
 
334
                        exit(0);
 
335
                }
 
336
        }
 
337
 
 
338
        if ((strcmp(argv[argCount], "-V") == 0) && (strlen(argv[argCount]) == 2))
 
339
        {
 
340
                printf("Version %s\n", VERSION);
 
341
                exit(0);
 
342
        }
194
343
 
195
344
        if ((argc > 1) && (strcmp(argv[1], "-summary") == 0))
196
345
        {
198
347
                exit(0);
199
348
        }
200
349
 
201
 
 
202
350
        if (argc < 2) {
203
351
                printf("You probably prefer to use the startBristol script.\n");
204
352
                exit(1);
205
353
        }
206
354
 
207
 
        printf("bristol version %s\n", VERSION);
 
355
        if ((argc == 2) 
 
356
                && ((strcmp(argv[argCount], "--help") == 0)
 
357
                || (strcmp(argv[argCount], "-help") == 0)
 
358
                || (strcmp(argv[argCount], "-h") == 0)
 
359
                || (strcmp(argv[argCount], "--h") == 0)))
 
360
        {
 
361
#ifdef BRISTOL_BUILD
 
362
                if (BRISTOL_BUILD == 0)
 
363
                        printf("bristol %i.%i.%i: ",
 
364
                                BRISTOL_MAJOR, BRISTOL_MINOR, BRISTOL_PATCH);
 
365
                else
 
366
                        printf("bristol %i.%i.%i-%i: ",
 
367
                                BRISTOL_MAJOR, BRISTOL_MINOR, BRISTOL_PATCH, BRISTOL_BUILD);
 
368
#else
 
369
                        printf("bristol %s\n", VERSION);
 
370
#endif
 
371
                printf("%s", helptext);
 
372
                exit(0);
 
373
        }
 
374
 
 
375
        if (readMe == 0)
 
376
                printf("%s", gplnotice);
 
377
 
 
378
        global.synths->location = 0;
 
379
 
 
380
        if ((getenv("BRISTOL_LOG_CONSOLE") != NULL)
 
381
                && (strcmp(getenv("BRISTOL_LOG_CONSOLE"), "true") == 0))
 
382
                logtype = BRISTOL_LOG_CONSOLE;
 
383
 
 
384
        cli_fd[0] = 0;//dup(0);
 
385
        cli_fd[1] = 1;//dup(1);
 
386
 
 
387
        logthread = bristolOpenStdio(logtype);
 
388
 
 
389
        /* Set up a default SYSEX ID, may get changed later */
 
390
        bristolMidiOption(0, BRISTOL_NRP_SYSID_H, 0x534C);
 
391
        bristolMidiOption(0, BRISTOL_NRP_SYSID_L, 0x6162);
 
392
 
 
393
        brightonFindEmulation(argc, argv);
208
394
 
209
395
        /*
210
396
         * close our standard input, create a pipe which will never be used.
211
397
         */
212
398
        while (argc > argCount)
213
399
        {
214
 
                if ((strcmp(argv[argCount], "--help") == 0)
215
 
                        || (strcmp(argv[argCount], "-help") == 0)
216
 
                        || (strcmp(argv[argCount], "-h") == 0)
217
 
                        || (strcmp(argv[argCount], "--h") == 0))
218
 
                {
219
 
#ifdef BRISTOL_BUILD
220
 
                        if (BRISTOL_BUILD == 0)
221
 
                                printf("bristol %i.%i.%i: ",
222
 
                                        BRISTOL_MAJOR, BRISTOL_MINOR, BRISTOL_PATCH);
223
 
                        else
224
 
                                printf("bristol %i.%i.%i-%i: ",
225
 
                                        BRISTOL_MAJOR, BRISTOL_MINOR, BRISTOL_PATCH, BRISTOL_BUILD);
226
 
#else
227
 
                                printf("bristol %s\n", VERSION);
228
 
#endif
229
 
                        printf("%s", helptext);
230
 
                        exit(0);
231
 
                }
 
400
                if (strcmp(argv[argCount], "-log") == 0)
 
401
                        bristolOpenStdio(BRISTOL_LOG_DAEMON);
 
402
 
 
403
                if (strcmp(argv[argCount], "-syslog") == 0)
 
404
                        bristolOpenStdio(BRISTOL_LOG_SYSLOG);
232
405
 
233
406
                if ((strcmp(argv[argCount], "-V") == 0)
234
407
                        && (strlen(argv[argCount]) == 2))
235
408
                {
236
409
#ifdef BRISTOL_BUILD
237
410
                        if (BRISTOL_BUILD == 0)
238
 
                                printf("bristol version %i.%i.%i\n",
 
411
                                printf("brighton version %i.%i.%i\n",
239
412
                                        BRISTOL_MAJOR, BRISTOL_MINOR, BRISTOL_PATCH);
240
413
                        else
241
 
                                printf("bristol version %i.%i.%i-%i\n",
 
414
                                printf("brighton version %i.%i.%i-%i\n",
242
415
                                        BRISTOL_MAJOR, BRISTOL_MINOR, BRISTOL_PATCH, BRISTOL_BUILD);
243
416
#endif
244
417
                        exit(0);
286
459
                                printf("        -glide:  %i\n", synthesisers[i]->emulate.glide);
287
460
                                printf("        -curve:  %i\n", synthesisers[i]->emulate.velocity);
288
461
 
289
 
                                global.synths->voices = synthesisers[i]->emulate.voices;
 
462
                                if ((global.synths->voices = synthesisers[i]->emulate.voices)
 
463
                                        < 0)
 
464
                                        global.synths->voices = BRISTOL_VOICECOUNT;
290
465
                                global.synths->detune = synthesisers[i]->emulate.detune;
291
466
                                global.synths->gain = synthesisers[i]->emulate.gain * 128;
292
467
                                global.synths->pwd = synthesisers[i]->emulate.pwd;
295
470
                                if (synthesisers[i]->emulate.opacity != 0)
296
471
                                        printf("    -opacity:%i\n",
297
472
                                                opacity = synthesisers[i]->emulate.opacity);
 
473
                                if (global.synths->voices == 1)
 
474
                                        global.synths->notepref = BRIGHTON_HNP;
298
475
                        }
299
476
                        argCount++;
300
477
                        continue;
301
478
                }
302
479
 
 
480
                if (strcmp(argv[argCount], "-iconify") == 0)
 
481
                        bwflags &= ~BRIGHTON_POST_WINDOW;
 
482
 
303
483
                if ((strcmp(argv[argCount], "-quality") == 0) && (argCount < argc))
304
484
                {
305
485
                        if ((quality = atoi(argv[argCount + 1])) < 2)
361
541
                        continue;
362
542
                }
363
543
 
 
544
                if ((strcmp(argv[argCount], "-jsmuuid") == 0) && (argCount < argc))
 
545
                {
 
546
                        global.synths->ladimem += atoi(argv[argCount + 1]);
 
547
                        argCount++;
 
548
                        continue;
 
549
                }
 
550
 
 
551
                /*
 
552
                 * LADI level 1 options:
 
553
                 */
 
554
                if ((strcmp(argv[argCount], "-ladi") == 0) && (argCount < argc))
 
555
                {
 
556
                        global.synths->flags |= LADI_ENABLE;
 
557
 
 
558
                        if (strcmp(argv[argCount + 1], "both") == 0)
 
559
                                global.synths->ladimode = 1;
 
560
                        else if (strcmp(argv[argCount + 1], "bristol") == 0)
 
561
                                global.synths->ladimode = 0;
 
562
                        else if (strcmp(argv[argCount + 1], "brighton") == 0)
 
563
                                global.synths->ladimode = 1;
 
564
                        else {
 
565
                                if ((global.synths->ladimem = atoi(argv[argCount + 1])) <= 0)
 
566
                                {
 
567
                                        global.synths->ladimem = 1024;
 
568
                                        global.synths->ladiStateFile = argv[argCount + 1];
 
569
                                }
 
570
                        }
 
571
 
 
572
                        /*
 
573
                         * We also need to force the startup to open this memory location
 
574
                         * as well, that can get overridden if there is a -load option 
 
575
                         * anywhere later on the command line.
 
576
                         */
 
577
                        global.synths->location = global.synths->ladimem;
 
578
 
 
579
                        global.synths->mbi = (global.synths->location / 1000) * 1000;
 
580
                        global.synths->location = global.synths->location % 1000;
 
581
 
 
582
                        argCount++;
 
583
                        continue;
 
584
                }
 
585
 
 
586
                if ((strcmp(argv[argCount], "-audiodev") == 0) && (argCount < argc))
 
587
                {
 
588
                        argCount++;
 
589
                        devname = argv[argCount];
 
590
                }
 
591
 
 
592
                if ((strcmp(argv[argCount], "-lowkey") == 0) && (argCount < argc))
 
593
                {
 
594
                        argCount++;
 
595
                        global.synths->lowkey = atoi(argv[argCount]);
 
596
                }
 
597
 
 
598
                if ((strcmp(argv[argCount], "-highkey") == 0) && (argCount < argc))
 
599
                {
 
600
                        argCount++;
 
601
                        global.synths->highkey = atoi(argv[argCount]);
 
602
                }
 
603
 
364
604
                if (strcmp(argv[argCount], "-rate") == 0)
365
605
                {
366
606
                        if ((sampleRate = atoi(argv[argCount + 1])) <= 0)
401
641
                        if ((activeSensePeriod = activeSense * 3) > 16000)
402
642
                                activeSensePeriod = 16000;
403
643
 
404
 
printf("as %i, asp %i\n", activeSense, activeSensePeriod);
405
644
                        argCount++;
406
645
                }
407
646
 
423
662
                        activeSensePeriod = activeSensePeriod * sampleRate / 1000;
424
663
                         */
425
664
 
426
 
printf("as %i, asp %i\n", activeSense, activeSensePeriod);
427
665
                        argCount++;
428
666
                }
429
667
 
 
668
                if (strcmp(argv[argCount], "-gmc") == 0)
 
669
                        gmc = 1;
 
670
 
430
671
                if ((strcmp(argv[argCount], "-mct") == 0)
431
672
                        && (argCount < argc))
432
673
                {
454
695
                        continue;
455
696
                }
456
697
 
 
698
                if ((strcmp(argv[argCount], "-width") == 0) && (argCount < argc))
 
699
                {
 
700
                        deswidth = atoi(argv[argCount + 1]);
 
701
                        argCount++;
 
702
                }
 
703
 
457
704
                if ((strcmp(argv[argCount], "-scale") == 0) && (argCount < argc))
458
705
                {
459
706
                        if ((strcmp(argv[argCount + 1], "fs") == 0)
476
723
                        scale = 1.0;
477
724
                }
478
725
 
 
726
                if (strcmp(argv[argCount], "-raise") == 0)
 
727
                        rlflags &= ~BRIGHTON_SET_RAISE;
 
728
                if (strcmp(argv[argCount], "-lower") == 0)
 
729
                        rlflags &= ~BRIGHTON_SET_LOWER;
 
730
 
 
731
                if (strcmp(argv[argCount], "-autozoom") == 0)
 
732
                {
 
733
                        azoom = 1;
 
734
                        if (deswidth < 1)
 
735
                                deswidth = 100;
 
736
                }
 
737
 
479
738
                if ((strcmp(argv[argCount], "-ar") == 0) ||
480
739
                        (strcmp(argv[argCount], "-nar") == 0) ||
481
740
                        (strcmp(argv[argCount], "-aspect") == 0))
515
774
                {
516
775
                        if (argCount < argc)
517
776
                                global.synths->location = atoi(argv[argCount + 1]);
518
 
                        if (global.synths->location > 999)
 
777
 
 
778
                        global.synths->mbi = (global.synths->location / 1000) * 1000;
 
779
                        global.synths->location = global.synths->location % 1000;
 
780
 
 
781
                        argCount++;
 
782
                }
 
783
 
 
784
                /* SYSEX System ID */
 
785
                if ((strcmp(argv[argCount], "-sysid") == 0) && (argCount < argc))
 
786
                {
 
787
                        unsigned int sysid = 0x534C6162, o = argCount + 1;
 
788
 
 
789
                        /*
 
790
                         * We will get 0x534C6162 for example
 
791
                         */
 
792
                        if ((argv[o][0] == '0') || (argv[o][1] == 'x')
 
793
                                || (strlen(argv[o]) == 10))
519
794
                        {
520
 
                                global.synths->mbi = (global.synths->location / 1000) * 1000;
521
 
                                global.synths->location = global.synths->location % 1000;
 
795
                                sscanf(argv[o], "0x%x", &sysid);
 
796
                                sysid &= 0x7f7f7f7f;
 
797
                                bristolMidiOption(0, BRISTOL_NRP_SYSID_H, sysid >> 16);
 
798
                                bristolMidiOption(0, BRISTOL_NRP_SYSID_L, sysid & 0x0000ffff);
 
799
                                printf("fixing sysex system id at 0x%x\n", sysid);
522
800
                        }
 
801
                }
523
802
 
 
803
                if ((strcmp(argv[argCount], "-nrpcc") == 0) && (argCount < argc))
 
804
                {
 
805
                        nrpcc = atoi(argv[argCount + 1]);
 
806
                        printf("Reserving %i NRP controllers\n", nrpcc);
524
807
                        argCount++;
525
808
                }
526
809
 
554
837
 
555
838
                if ((strcmp(argv[argCount], "-voices") == 0) && (argCount < argc))
556
839
                {
557
 
                        if (argCount < argc)
558
 
                                global.synths->voices = atoi(argv[argCount + 1]);
 
840
                        if (((global.synths->voices = atoi(argv[argCount + 1])) == 1)
 
841
                                && (global.synths->notepref == BRIGHTON_POLYPHONIC))
 
842
                                global.synths->notepref = BRIGHTON_HNP;
559
843
                        argCount++;
560
844
                }
561
845
 
562
846
                if (strcmp(argv[argCount], "-mono") == 0)
 
847
                {
563
848
                        global.synths->voices = 1;
 
849
                        global.synths->notepref = BRIGHTON_HNP;
 
850
                }
 
851
 
 
852
                if (strcmp(argv[argCount], "-localforward") == 0)
 
853
                        global.synths->flags &= ~REQ_LOCAL_FORWARD;
 
854
                if (strcmp(argv[argCount], "-remoteforward") == 0)
 
855
                        global.synths->flags &= ~REQ_REMOTE_FORWARD;
 
856
                if (strcmp(argv[argCount], "-forward") == 0)
 
857
                        global.synths->flags
 
858
                                &= ~(REQ_FORWARD|REQ_LOCAL_FORWARD|REQ_REMOTE_FORWARD);
564
859
 
565
860
                if (strcmp(argv[argCount], "-mididbg2") == 0)
566
861
                        global.synths->flags |= REQ_MIDI_DEBUG2;
568
863
                        || (strcmp(argv[argCount], "-mididbg1") == 0))
569
864
                        global.synths->flags |= REQ_MIDI_DEBUG;
570
865
 
571
 
                if ((strcmp(argv[argCount], "-midinrp") == 0)
572
 
                        || (strcmp(argv[argCount], "-nrp") == 0))
 
866
                if (strcmp(argv[argCount], "-debug") == 0)
 
867
                {
 
868
                        if ((argCount < argc) && (argv[argCount + 1][0] != '-'))
 
869
                        {
 
870
                                int i;
 
871
 
 
872
                                if ((i = atoi(argv[argCount + 1])) > 15)
 
873
                                        global.synths->flags |= REQ_DEBUG_MASK;
 
874
                                else {
 
875
                                        global.synths->flags &= ~REQ_DEBUG_MASK;
 
876
                                        global.synths->flags |= (i << 12);
 
877
                                }
 
878
                        } else {
 
879
                                /*
 
880
                                 * If we only have -debug and no value then increment the debug 
 
881
                                 * level.
 
882
                                 */
 
883
                                global.synths->flags = (global.synths->flags & ~REQ_DEBUG_MASK)
 
884
                                        | (((global.synths->flags & REQ_DEBUG_MASK) + REQ_DEBUG_1)
 
885
                                                & REQ_DEBUG_MASK);
 
886
                        }
 
887
 
 
888
                        if (global.synths->flags & REQ_DEBUG_MASK)
 
889
                                printf("debuging level set to %i\n",
 
890
                                        (global.synths->flags&REQ_DEBUG_MASK)>>12);
 
891
                }
 
892
 
 
893
                if (strcmp(argv[argCount], "-gnrp") == 0)
 
894
                        global.synths->flags |= GUI_NRP;
 
895
                if (strcmp(argv[argCount], "-enrp") == 0)
573
896
                        global.synths->flags |= MIDI_NRP;
 
897
                if (strcmp(argv[argCount], "-nrp") == 0)
 
898
                        global.synths->flags |= MIDI_NRP|GUI_NRP;
574
899
 
575
900
                if ((strcmp(argv[argCount], "-channel") == 0) && (argCount < argc))
576
901
                {
595
920
                        argCount++;
596
921
                }
597
922
 
598
 
                if (strcmp(argv[argCount], "-engine") == 0)
599
 
                        global.flags |= BRIGHTON_NOENGINE;
600
 
 
601
923
                if (strcmp(argv[argCount], "-port") == 0)
602
924
                {
603
925
                        if (argCount < argc)
607
929
                if (strcmp(argv[argCount], "-host") == 0)
608
930
                        global.host = argv[++argCount];
609
931
 
 
932
                if (strcmp(argv[argCount], "-window") == 0)
 
933
                        synthesisers[global.synths->synthtype]->flags ^= BRIGHTON_WINDOW;
 
934
 
 
935
                if (strcmp(argv[argCount], "-cli") == 0)
 
936
                {
 
937
                        cli = 1;
 
938
                        brightonCLIinit(&global, cli_fd);
 
939
                        //synthesisers[global.synths->synthtype]->flags ^= BRIGHTON_WINDOW;
 
940
                }
 
941
 
 
942
                if (strcmp(argv[argCount], "-nwf") == 0)
 
943
                        global.synths->lwf = 0;
610
944
                if (strcmp(argv[argCount], "-lwf") == 0)
611
945
                        global.synths->lwf = 1;
 
946
                if (strcmp(argv[argCount], "-lwf2") == 0)
 
947
                        global.synths->lwf = 2;
 
948
                if (strcmp(argv[argCount], "-wwf") == 0)
 
949
                        global.synths->lwf = 2;
 
950
                if (strcmp(argv[argCount], "-hwf") == 0)
 
951
                        global.synths->lwf = 3;
612
952
 
613
953
                if (strcmp(argv[argCount], "-lnp") == 0)
614
 
                        global.synths->notepref = 1;
 
954
                        global.synths->notepref = BRIGHTON_LNP;
615
955
                if (strcmp(argv[argCount], "-hnp") == 0)
616
 
                        global.synths->notepref = 2;
 
956
                        global.synths->notepref = BRIGHTON_HNP;
617
957
                if (strcmp(argv[argCount], "-nnp") == 0)
618
 
                        global.synths->notepref = 0;
 
958
                        global.synths->notepref = BRIGHTON_POLYPHONIC;
619
959
                if (strcmp(argv[argCount], "-retrig") == 0)
620
 
                        global.synths->notetrig = 1;
 
960
                        global.synths->notetrig = 1 - global.synths->notetrig;
621
961
                if (strcmp(argv[argCount], "-lvel") == 0)
622
 
                        global.synths->legatovelocity = 1;
 
962
                        global.synths->legatovelocity = 1 - global.synths->legatovelocity;
623
963
 
624
964
                /*
625
965
                 * And finally all the different synths
724
1064
                        global.synths->synthtype = BRISTOL_VOX;
725
1065
 
726
1066
                if ((strcmp(argv[argCount], "-voxm2") == 0)
 
1067
                        || (strcmp(argv[argCount], "-voxM2") == 0)
727
1068
                        || (strcmp(argv[argCount], "-vox300") == 0))
728
1069
                        global.synths->synthtype = BRISTOL_VOXM2;
729
1070
 
782
1123
                if (strcmp(argv[argCount], "-bme700") == 0)
783
1124
                {
784
1125
                        global.synths->synthtype = BRISTOL_BME700;
785
 
                        global.synths->voices = 8;
 
1126
                        global.synths->voices = 1;
 
1127
                        global.synths->notepref = BRIGHTON_HNP;
786
1128
                }
787
1129
 
788
1130
                if ((strcmp(argv[argCount], "-bassmaker") == 0)
797
1139
                {
798
1140
                        global.synths->synthtype = BRISTOL_SID_M1;
799
1141
                        global.synths->voices = 1;
800
 
                        global.synths->notepref = 2;
 
1142
                        global.synths->notepref = BRIGHTON_LNP;
801
1143
                        global.synths->notetrig = 1;
802
1144
                        antialias = 0.5;
803
1145
                        aliastype = 1;
814
1156
                {
815
1157
                        global.synths->synthtype = BRISTOL_SID_M2;
816
1158
                        global.synths->voices = 1;
817
 
                        global.synths->notepref = 2;
 
1159
                        global.synths->notepref = BRIGHTON_HNP;
818
1160
                        global.synths->notetrig = 1;
819
1161
                        antialias = 0.5;
820
1162
                        aliastype = 1;
979
1321
                argCount++;
980
1322
        }
981
1323
 
 
1324
        {
 
1325
                char statfile[1024];
 
1326
                struct stat statres;
 
1327
 
 
1328
                sprintf(statfile, "%s/%s.gz", getenv("BRISTOL"),
 
1329
                        synthesisers[global.synths->synthtype]->resources[0].image);
 
1330
 
 
1331
                if ((synthesisers[global.synths->synthtype]->resources[0].image != 0) &&
 
1332
                        (stat(statfile, &statres) != 0))
 
1333
                {
 
1334
                        sprintf(statfile, "%s/%s", getenv("BRISTOL"),
 
1335
                                synthesisers[global.synths->synthtype]->resources[0].image);
 
1336
 
 
1337
                        if (stat(statfile, &statres) != 0)
 
1338
                        {
 
1339
                                printf("unknown emulator\n");
 
1340
                                sleep(1);
 
1341
                                exit(-1);
 
1342
                        }
 
1343
                }
 
1344
        }
 
1345
 
 
1346
        if (readMe) {
 
1347
                printBrightonHelp(global.synths->synthtype);
 
1348
                exit(0);
 
1349
        }
 
1350
 
 
1351
        printf("brighton version %s\n", VERSION);
 
1352
 
 
1353
        sleep(1);
 
1354
 
 
1355
        printf("  %s", argv[0]);
 
1356
        for (i = 1; i < argc; i++) {
 
1357
                if (argv[i][0] == '-')
 
1358
                        printf("\n    %s", argv[i]);
 
1359
                else
 
1360
                        printf(" %s", argv[i]);
 
1361
        }
 
1362
        printf("\n");
 
1363
 
982
1364
        /*
983
 
         * Hm, this is a joke really. The Tandy, Realistic, whatever is an old
984
 
         * synth, and this mimics random slider changes. Should not really do it
985
 
         * but its fun. The original used to lose its white caps.
986
 
         * Once the gui is created its more work to change the image.
 
1365
         * Hm, this is a joke really. The Tandy, Realistic, whatever, is an old
 
1366
         * synth and this mimics random slider changes. Should not really do it
 
1367
         * but its fun: the original used to lose its white caps. Once the gui is
 
1368
         * created its more work to change the image.
987
1369
         */
988
1370
        if (global.synths->synthtype == BRISTOL_REALISTIC)
989
1371
        {
1010
1392
                exit(0);
1011
1393
 
1012
1394
        global.synths->resources = synthesisers[global.synths->synthtype];
 
1395
 
1013
1396
        synthesisers[global.synths->synthtype]->width *= scale;
1014
1397
        synthesisers[global.synths->synthtype]->height *= scale;
1015
1398
 
1016
1399
        /*
 
1400
         * Finally go and let the event manager handle our interface. Going to 
 
1401
         * create a separate GUI thread, which will allow us to handle things like
 
1402
         * MIDI events from the engine, timed operations, etc, from there.
 
1403
         */
 
1404
        if (pthread_create(&emgrThread, NULL, eventMgr, &global) != 0)
 
1405
                printf("Could not create GUI thread\n");
 
1406
 
 
1407
        /*
 
1408
         * We should not detach the thread, we should wait for it later before exit
 
1409
        if (pthread_detach(thread) != 0)
 
1410
                printf("Could not detach GUI thread\n");
 
1411
         */
 
1412
 
 
1413
        /*
1017
1414
         * win is actually set by the configuration routines, but we use it 
1018
1415
         * here anyway. The configuration options are a structure, they were a
1019
1416
         * list of parameters however that became unwieldy.
1020
1417
         */
 
1418
        if ((global.synths->flags & REQ_DEBUG_MASK) >= (REQ_DEBUG_4|REQ_DEBUG_1))
 
1419
                aliastype |= BRIGHTON_LIB_DEBUG;
 
1420
        synthesisers[global.synths->synthtype]->flags |= bwflags;
 
1421
 
 
1422
        /*
 
1423
         * We play around with the names here so that the window title gets filled
 
1424
         * with more information than just the emulator name. This enhancement was
 
1425
         * added for JSM but could be any Jack installation. If multiple instances
 
1426
         * of the same emulator are started then it is not clear which is which:
 
1427
         * both have the same title bar but different names in Jack. What we do here
 
1428
         * is add the Jack registration name to the title bar.
 
1429
         */
 
1430
        snprintf(appname, 64, "%s (%s)",
 
1431
                synthesisers[global.synths->synthtype]->name, devname);
 
1432
        devname = synthesisers[global.synths->synthtype]->name;
 
1433
        synthesisers[global.synths->synthtype]->name = appname;
1021
1434
        global.synths->win =
1022
1435
                brightonInterface(synthesisers[global.synths->synthtype],
1023
1436
                        quality, library, aliastype, antialias, gs);
 
1437
        synthesisers[global.synths->synthtype]->name = devname;
 
1438
        global.synths->resources->name = devname;
 
1439
 
 
1440
        /*
 
1441
         * We now need to decide which memory to load. There are a few choices.
 
1442
         * If we had a LADI declaration it will have been copied to both ladimem
 
1443
         * and to the emulator memory. If they are still the same then use it.
 
1444
         *
 
1445
         * If the emulator location has change then we should look and see if the
 
1446
         * LADI memory actually exists, if so, use it (overwrite the emulator
 
1447
         * memory location again). If it does not exist we will then continue to 
 
1448
         * access the emulator memory and it becomes the template for the eventual
 
1449
         * LADI state information.
 
1450
         */
 
1451
        if ((global.synths->flags & LADI_ENABLE) &&
 
1452
                (global.synths->ladimem
 
1453
                        != (global.synths->location + global.synths->mbi)))
 
1454
        {
 
1455
                int memHold = global.synths->location + global.synths->mbi;
 
1456
 
 
1457
                global.synths->mbi = 0;
 
1458
                global.synths->location = global.synths->ladimem;
 
1459
 
 
1460
                /* Location has changed. Stat the ladimem */
 
1461
                if (loadMemory(global.synths, global.synths->resources->name, 0,
 
1462
                        global.synths->ladimem,
 
1463
                        global.synths->mem.active, 0, BRISTOL_STAT) < 0)
 
1464
                {
 
1465
                        /* No LADI mem */
 
1466
                        global.synths->location = memHold;
 
1467
 
 
1468
                        global.synths->mbi = (global.synths->location / 1000) * 1000;
 
1469
                        global.synths->location = global.synths->location % 1000;
 
1470
 
 
1471
                        printf("did not find LADI memory %i, using %i\n",
 
1472
                                global.synths->ladimem, memHold);
 
1473
                } else
 
1474
                        printf("using LADI state memory %i\n", global.synths->ladimem);
 
1475
        }
 
1476
 
 
1477
        if (global.flags & REQ_EXIT)
 
1478
        {
 
1479
                printf("early termination logging thread (%i)\n", global.controlfd);
 
1480
 
 
1481
                bristolOpenStdio(BRISTOL_LOG_TERMINATE);
 
1482
 
 
1483
                if ((logthread != 0) && (pthread_join(logthread, NULL) != 0))
 
1484
                        return(1);
 
1485
 
 
1486
                exit(global.controlfd < 0? 1: 0);
 
1487
        }
1024
1488
 
1025
1489
        global.synths->win->dcTimeout = dcTimeout;
1026
1490
 
 
1491
        global.synths->win->flags |= rlflags;
 
1492
 
 
1493
        if (azoom) {
 
1494
                global.synths->win->flags |= BRIGHTON_AUTOZOOM;
 
1495
 
 
1496
                if (deswidth >= 100)
 
1497
                {
 
1498
                        global.synths->win->minw = deswidth;
 
1499
                        global.synths->win->minh =
 
1500
                                deswidth * global.synths->win->template->height
 
1501
                                / global.synths->win->template->width;
 
1502
                        global.synths->win->maxw =
 
1503
                                synthesisers[global.synths->synthtype]->width * scale;
 
1504
                        global.synths->win->maxh =
 
1505
                                synthesisers[global.synths->synthtype]->height * scale;
 
1506
                } else {
 
1507
                        global.synths->win->minw 
 
1508
                                = global.synths->win->maxw 
 
1509
                                = global.synths->win->minh 
 
1510
                                = global.synths->win->maxh = 0;
 
1511
                }
 
1512
        }
1027
1513
        if (nar)
1028
1514
                global.synths->win->flags |= BRIGHTON_NO_ASPECT;
1029
1515
 
1030
 
        /*
1031
 
         * Finally go and let the event manager handle our interface. Going to 
1032
 
         * create a separate GUI thread, which will allow us to handle things like
1033
 
         * MIDI events from the engine, timed operations, etc, from there.
1034
 
         */
1035
 
        if (pthread_create(&thread, NULL, eventMgr, NULL) != 0)
1036
 
                printf("Could not create GUI thread\n");
1037
 
        if (pthread_detach(thread) != 0)
1038
 
                printf("Could not detach GUI thread\n");
1039
 
 
1040
1516
        brightonOpacity(global.synths->win, ((float) opacity) / 100.0f);
1041
1517
 
1042
1518
        /*
1052
1528
 
1053
1529
        printf("user r %i/%i, e %i/%i\n", getuid(), getgid(), geteuid(), getegid());
1054
1530
 
 
1531
        global.synths->win->nrpcount = nrpcc;
 
1532
        global.synths->win->nrpcontrol =
 
1533
                malloc(sizeof(brightonNRPcontrol) * nrpcc);
 
1534
        memset(global.synths->win->nrpcontrol, 0,
 
1535
                sizeof(brightonNRPcontrol) * nrpcc);
 
1536
 
 
1537
        brightonReadConfiguration(global.synths->win,
 
1538
                synthesisers[global.synths->synthtype],
 
1539
                global.synths->midichannel,
 
1540
                synthesisers[global.synths->synthtype]->name);
 
1541
 
 
1542
        if (bristolMidiSendMsg(global.controlfd, global.synths->sid,
 
1543
                BRISTOL_ACTIVE_SENSE, 0, activeSense == 0? 0:16383) != 0)
 
1544
        {
 
1545
                printf("Active sense transmit failure\n");
 
1546
                sleep(1);
 
1547
                exit(1);
 
1548
        } if (global.synths->flags & REQ_MIDI_DEBUG)
 
1549
                printf("Sent Active sense\n");
 
1550
 
 
1551
        if ((global.synths->sid2 > 0) &&
 
1552
                (bristolMidiSendMsg(global.manualfd, global.synths->sid2,
 
1553
                        BRISTOL_ACTIVE_SENSE, 0, activeSense == 0? 0:16383) != 0))
 
1554
        {
 
1555
                printf("Active sense transmit failure\n");
 
1556
                sleep(1);
 
1557
                exit(1);
 
1558
        } if (global.synths->flags & REQ_MIDI_DEBUG)
 
1559
                printf("Sent Active sense on second channel\n");
 
1560
 
 
1561
        emStart = 1;
 
1562
 
 
1563
        if (global.libtest != 1)
 
1564
        {
 
1565
                if (global.synths->flags & REQ_FORWARD)
 
1566
                        bristolMidiOption(0, BRISTOL_NRP_FORWARD, 1);
 
1567
 
 
1568
                if (global.synths->flags & NO_KEYTRACK)
 
1569
                        bristolMidiOption(0, BRISTOL_NRP_MIDI_GO, 0);
 
1570
                else
 
1571
                        bristolMidiOption(0, BRISTOL_NRP_MIDI_GO, 1);
 
1572
 
 
1573
                /*
 
1574
                 * The Hammond needs a note event on the upper manual to kick the
 
1575
                 * gearbox into action.
 
1576
                 */
 
1577
                if (global.synths->synthtype == BRISTOL_HAMMONDB3)
 
1578
                {
 
1579
                        sleep(1);
 
1580
                        bristolMidiSendMsg(global.controlfd, global.synths->midichannel,
 
1581
                                BRISTOL_EVENT_KEYON, 0, 10 + global.synths->transpose);
 
1582
                        usleep(50000);
 
1583
                        bristolMidiSendMsg(global.controlfd, global.synths->midichannel,
 
1584
                                BRISTOL_EVENT_KEYOFF, 0, 10 + global.synths->transpose);
 
1585
                }
 
1586
        }
 
1587
 
 
1588
        /* if we are CLI, somebody needs to force this to happen */
 
1589
        if (synthesisers[global.synths->synthtype]->flags & BRIGHTON_WINDOW)
 
1590
                brightonWorldChanged(global.synths->win, 500, 500);
 
1591
 
 
1592
        /*
 
1593
        if (cli == 0)
 
1594
        {
 
1595
                close(cli_fd[0]);
 
1596
                close(cli_fd[1]);
 
1597
        }
 
1598
        */
 
1599
 
 
1600
        while (~global.flags & REQ_EXIT)
 
1601
        {
 
1602
                /*
 
1603
                 * Do whatever we want. Will turn into a wait routine on the MIDI
 
1604
                 * channel. This could be merged with the UI heartbeat code.
 
1605
                 */
 
1606
                if (cli) {
 
1607
                        if (brightonCLIcheck(&global) < 0)
 
1608
                                cleanupBristol();
 
1609
                }
 
1610
                /*
 
1611
                 * This was never operational anyway:
 
1612
                if (vuInterval != 0) {
 
1613
                        usleep(vuInterval);
 
1614
                        if (global.synths->flags & OPERATIONAL)
 
1615
                                doAlarm();
 
1616
                } else if (cli == 0)
 
1617
                 */
 
1618
                else
 
1619
                        sleep(1);
 
1620
        }
 
1621
 
 
1622
        if (pthread_join(emgrThread, NULL) != 0)
 
1623
                printf("brighton event thread exit error\n");
 
1624
        else
 
1625
                printf("brighton event thread exited\n");
 
1626
 
 
1627
        /* Now that the event manager thread has exit, put key repeat back on */
 
1628
        BAutoRepeat(global.synths->win->display, 1);
 
1629
 
 
1630
        printf("terminating logging thread (%i)\n", global.controlfd);
 
1631
 
 
1632
        if (global.libtest == 0)
 
1633
                sleep(1);
 
1634
 
 
1635
        bristolOpenStdio(BRISTOL_LOG_TERMINATE);
 
1636
 
 
1637
        if ((logthread != 0) && (pthread_join(logthread, NULL) != 0))
 
1638
                return(1);
 
1639
 
 
1640
        exit(global.controlfd < 0? 1: 0);
 
1641
}
 
1642
 
 
1643
void *
 
1644
eventMgr()
 
1645
{
 
1646
        bristolMidiMsg msg;
 
1647
        int i, r;
 
1648
        int midiFD, cFD;
 
1649
 
 
1650
        /* This will send activesense as soon as the interface initialises */
 
1651
        asc = activeSense * 4;
 
1652
 
 
1653
        printf("starting event management thread\n");
 
1654
 
1055
1655
        /*
1056
1656
         * Here we should open an ALSA SEQ interface. We want to get an index back
1057
1657
         * and pass that to the event handler for selection. This should not really
1058
1658
         * be a SEQ interface, it should depend on the flags given to the GUI.
1059
1659
         */
1060
 
        if (global.libtest != 1)
 
1660
        if (gmc && (global.libtest != 1))
1061
1661
        {
1062
1662
                if ((midiHandle = bristolMidiOpen("brighton",
1063
 
                        BRISTOL_CONN_SEQ|BRISTOL_DUPLEX,
1064
 
                        -1, BRISTOL_REQ_NSX, brightonMidiInput, &global)) < 0)
 
1663
                        BRISTOL_CONN_SEQ|BRISTOL_RDONLY,
 
1664
                        -1, -1, brightonMidiInput, &global)) < 0)
1065
1665
                        printf("Error opening midi device %s\n", "0.0");
1066
 
 
1067
 
                midiFD = bristolGetMidiFD(midiHandle);
1068
 
//              cFD = bristolMidiDupFD(global.controlfd, BRISTOL_REQ_NSX,
1069
 
//                       brightonMidiInput, &global);
1070
 
//              cFD = bristolGetMidiFD(cFD);
1071
 
 
1072
 
                printf("opened GUI midi handles: %i, %i\n", midiFD, cFD);
1073
 
        }
1074
 
 
1075
 
        brightonReadConfiguration(global.synths->win,
1076
 
                synthesisers[global.synths->synthtype],
1077
 
                global.synths->midichannel,
1078
 
                synthesisers[global.synths->synthtype]->name);
1079
 
 
1080
 
        while (1) {
1081
 
                i = brightonEventMgr();
 
1666
        }
 
1667
 
 
1668
        while (global.synths->win == NULL)
 
1669
        {
 
1670
                usleep(100000);
 
1671
                printf("waiting for window creation\n");
 
1672
        }
 
1673
 
 
1674
        midiFD = bristolGetMidiFD(midiHandle);
 
1675
        cFD = bristolGetMidiFD(global.controlfd);
 
1676
 
 
1677
        printf("opened GUI midi handles: %i, %i\n", midiFD, cFD);
 
1678
 
 
1679
/*
 
1680
        if (global.libtest != 1)
 
1681
        {
 
1682
                if (global.synths->flags & REQ_FORWARD)
 
1683
                        bristolMidiOption(0, BRISTOL_NRP_FORWARD, 1);
 
1684
 
 
1685
                if (global.synths->flags & NO_KEYTRACK)
 
1686
                        bristolMidiOption(0, BRISTOL_NRP_MIDI_GO, 0);
 
1687
                else
 
1688
                        bristolMidiOption(0, BRISTOL_NRP_MIDI_GO, 1);
 
1689
 
 
1690
                bristolMidiSendMsg(global.controlfd, global.synths->midichannel,
 
1691
                        BRISTOL_EVENT_KEYON, 0, 10 + global.synths->transpose);
 
1692
                bristolMidiSendMsg(global.controlfd, global.synths->midichannel,
 
1693
                        BRISTOL_EVENT_KEYOFF, 0, 10 + global.synths->transpose);
 
1694
        }
 
1695
*/
 
1696
 
 
1697
        while ((global.flags & REQ_EXIT) == 0) {
 
1698
                if (emStart)
 
1699
                        i = brightonEventMgr();
 
1700
                else
 
1701
                        i = 0;
1082
1702
 
1083
1703
                /*
1084
1704
                 * This will now become a select on the ALSA SEQ socket looking for
1110
1730
                 * for a select operation. We should look at some point in putting
1111
1731
                 * this into a separate thread and using a semaphore since the 'busy'
1112
1732
                 * waiting is ugly.
 
1733
                 *
 
1734
                 * We should also look into separating the MIDI and GUI threads more,
 
1735
                 * it would require a bit of internal signalling to prevent both wanting
 
1736
                 * X Server access at the same time.
1113
1737
                 */
1114
 
//              bristolMidiDevRead(cFD, &msg);
1115
 
                bristolMidiDevRead(midiFD, &msg);
 
1738
                 /*
 
1739
                  * CHANGE TO READ ON EVERY OPENED HANDLE
 
1740
                bristolMidiDevRead(cFD, &msg);
 
1741
                bristolMidiDevRead(2, &msg);
 
1742
                  */
 
1743
                while ((r = bristolMidiDevRead(midiFD, &msg)) > 0)
 
1744
                        ;
 
1745
                if (r == BRISTOL_MIDI_CHANNEL)
 
1746
                {
 
1747
                        printf("Read failed on Midi FD\n");
 
1748
                        global.flags |= REQ_EXIT;
 
1749
 
 
1750
                        pthread_exit(0);
 
1751
                }
 
1752
 
 
1753
                while ((r = bristolMidiTCPRead(&msg)) > 0)
 
1754
                        ;
 
1755
                if (r < 0)
 
1756
                {
 
1757
                        printf("Read failed on TCP fd\n");
 
1758
                        global.flags |= REQ_EXIT;
 
1759
 
 
1760
                        pthread_exit(0);
 
1761
                }
1116
1762
 
1117
1763
                if (i == 0)
1118
1764
                        usleep(mwt);
1129
1775
                 */
1130
1776
                brightonFastTimer(0, 0, 0, BRIGHTON_FT_CLOCK, mwt / 1000);
1131
1777
 
1132
 
                if ((activeSense > 0) && ((asc -= mwt / 1000) < 0))
 
1778
                if ((activeSense > 0) && ((asc -= mwt / 1000) < 0) && (emStart))
1133
1779
                {
1134
1780
                        asc = activeSense;
1135
1781
 
1145
1791
                                BRISTOL_ACTIVE_SENSE, 0, activeSensePeriod) != 0)
1146
1792
                        {
1147
1793
                                printf("Active sense transmit failure\n");
 
1794
                                sleep(1);
1148
1795
                                exit(1);
1149
1796
                        }
1150
1797
                        if ((global.synths->sid2 > 0) &&
1151
 
                                (bristolMidiSendMsg(global.controlfd, global.synths->sid2,
 
1798
                                (bristolMidiSendMsg(global.manualfd, global.synths->sid2,
1152
1799
                                        BRISTOL_ACTIVE_SENSE, 0, activeSensePeriod) != 0))
1153
1800
                        {
1154
1801
                                printf("Active sense transmit failure\n");
 
1802
                                sleep(1);
1155
1803
                                exit(1);
1156
1804
                        }
1157
1805
 
 
1806
                        if ((ladiRequest == 1) && global.synths->flags & LADI_ENABLE) {
 
1807
                                int memHold = global.synths->cmem;
 
1808
 
 
1809
                                ladiRequest = 0;
 
1810
 
 
1811
                                printf("LADI save state signalled\n");
 
1812
 
 
1813
                                global.synths->cmem = global.synths->ladimem;
 
1814
                                brightonControlKeyInput(global.synths->win, 's', 0);
 
1815
 
 
1816
                                global.synths->cmem = memHold;
 
1817
                        }
 
1818
 
 
1819
                        if ((ladiRequest == 2) && global.synths->flags & LADI_ENABLE) {
 
1820
                                int memHold = global.synths->cmem;
 
1821
 
 
1822
                                ladiRequest = 0;
 
1823
 
 
1824
                                printf("LADI load state signalled\n");
 
1825
 
 
1826
                                global.synths->cmem = global.synths->ladimem;
 
1827
                                brightonControlKeyInput(global.synths->win, 'l', 0);
 
1828
 
 
1829
                                global.synths->cmem = memHold;
 
1830
                        }
 
1831
 
1158
1832
                        /*
1159
1833
                         * We are going to piggyback the slow event timer onto this code.
1160
1834
                         * It means the slow events will be related to the activeSensing
1164
1838
                        brightonSlowTimer(0, 0, BRIGHTON_ST_CLOCK);
1165
1839
                }
1166
1840
        }
1167
 
}
1168
 
 
1169
 
extern int vuInterval;
1170
 
 
1171
 
void *
1172
 
eventMgr()
1173
 
{
1174
 
        while (1)
1175
 
        {
1176
 
                /*
1177
 
                 * Do whatever we want. Will turn into a wait routine on the MIDI
1178
 
                 * channel. This could be merged with the UI heartbeat code.
1179
 
                 */
1180
 
                if (vuInterval != 0)
1181
 
                {
1182
 
                        usleep(vuInterval);
1183
 
                        if (global.synths->flags & OPERATIONAL)
1184
 
                                doAlarm();
1185
 
                }
1186
 
                else
1187
 
                        sleep(1);
1188
 
        }
 
1841
 
 
1842
        printf("brighton event manager thread exiting\n");
 
1843
 
 
1844
        global.flags |= REQ_EXIT;
 
1845
 
 
1846
        pthread_exit(0);
1189
1847
}
1190
1848
 
1191
1849
void
1200
1858
void
1201
1859
clearout(int result)
1202
1860
{
 
1861
        /*
 
1862
         * This is not the right way to do things. We should request an exit and
 
1863
         * let all the processes do their work. The issue here is that this can
 
1864
         * get called very early in the window creation process which causes other
 
1865
         * issues if we try to close down nicely. A better option here would be
 
1866
         * to assert the result is '0'. That way we get a nice core memory dump
 
1867
         * to debug under other circumstances.
 
1868
         */
 
1869
        printf("clearing out via early exit\n");
1203
1870
        exit(result);
1204
1871
}
1205
1872
 
 
1873
void
 
1874
printBrightonHelp(int synth)
 
1875
{
 
1876
        if ((synth >= BRISTOL_SYNTHCOUNT) || (readme[synth] == NULL))
 
1877
                return;
 
1878
 
 
1879
        printf("\n%s\n", readme[synth]);
 
1880
}
 
1881
 
 
1882
void
 
1883
printBrightonReadme()
 
1884
{
 
1885
        int i;
 
1886
 
 
1887
        printf("\n%s\n\n\n", readmeheader);
 
1888
        for (i = 0; i < BRISTOL_SYNTHCOUNT; i++)
 
1889
        {
 
1890
                if ((synthesisers[i] != NULL) && (readme[i] != NULL))
 
1891
                        printf("%s\n\n\n", readme[i]);
 
1892
        }
 
1893
        printf("\n%s\n", readmetrailer);
 
1894
        printf("%s", helptext);
 
1895
}
 
1896