-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctl.cpp
More file actions
1232 lines (1023 loc) · 27.1 KB
/
ctl.cpp
File metadata and controls
1232 lines (1023 loc) · 27.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
kmidi
$Id$
Copyright 1997 Bernd Johannes Wuebben math.cornell.edu
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if defined(KMIDI) || defined(IA_GTK)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <string.h>
#include <sys/ioctl.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/wait.h>
#ifdef KMIDI
#include "../config.h"
#endif
#ifdef NOW_USING_SEMAPHORES
#ifdef HAVE_SYS_SEM_H
#include <sys/sem.h>
#endif
#endif
#ifdef _SCO_DS
#include <sys/socket.h>
#endif
#include <errno.h>
#ifdef HAVE_SYS_FILIO_H
#include <sys/filio.h>
#endif
#include "config.h"
#include "common.h"
#include "instrum.h"
#include "playmidi.h"
#include "output.h"
#include "controls.h"
#include "ctl.h"
#ifdef NOW_USING_SEMAPHORES
#ifdef _SEM_SEMUN_UNDEFINED
union semun
{
int val;
struct semid_ds *buf;
unsigned short int *array;
struct seminfo *__buf;
};
#endif
#endif
static void ctl_refresh(void);
static void ctl_total_time(uint32 tt);
static void ctl_master_volume(int mv);
static void ctl_file_name(char *name);
static void ctl_current_time(uint32 ct);
static void ctl_note(int v);
static void ctl_program( int ch, int val, const char *name);
static void ctl_volume( int ch, int val );
static void ctl_expression( int ch, int val );
static void ctl_panning( int ch, int val );
static void ctl_sustain( int ch, int val );
static void ctl_pitch_bend( int ch, int val );
static void ctl_reset(void);
static int ctl_open(int using_stdin, int using_stdout);
static void ctl_close(void);
static int ctl_read(int32 *valp);
static int cmsg(int type, int verbosity_level, const char *fmt, ...);
static void ctl_pass_playing_list(int number_of_files, const char *list_of_files[]);
static int ctl_blocking_read(int32 *valp);
void pipe_int_write(int c);
void pipe_int_read(int *c);
void pipe_string_write(const char *str);
void pipe_string_read(char *str);
void pipe_open(void);
void pipe_error(const char *st);
int pipe_read_ready(void);
static void get_child(int sig);
static void shm_alloc(void);
static void shm_free(int sig);
/**********************************************/
#undef ctl
#ifdef KMIDI
#define ctl kmidi_control_mode
#else
#define ctl gtk_control_mode
#endif
ControlMode ctl=
{
#ifdef KMIDI
"kmidi qt interface", 'q',
#else
"gtk interface", 'g',
#endif
1,1,0,
ctl_open, ctl_pass_playing_list, ctl_close, ctl_read, cmsg,
ctl_refresh, ctl_reset, ctl_file_name, ctl_total_time, ctl_current_time,
ctl_note,
ctl_master_volume, ctl_program, ctl_volume,
ctl_expression, ctl_panning, ctl_sustain, ctl_pitch_bend
};
PanelInfo *Panel;
static int songoffset = 0;
static int shmid; /* shared memory id */
#ifdef NOW_USING_SEMAPHORES
static int semid; /* semaphore id */
#endif
static int child_killed = 0;
static int pipeAppli[2],pipeMotif[2];
static int fpip_in, fpip_out;
static int child_pid;
#ifdef KMIDI
extern int Launch_KMidi_Process(int );
#else
extern int Launch_Gtk_Process(int pipe_number);
#endif
/***********************************************************************/
/* Put controls on the pipe */
/***********************************************************************/
static int cmsg(int type, int verbosity_level, const char *fmt, ...)
{
char local[2048];
#define TOO_LONG 2000
#define TOO_LONG2 2047
va_list ap;
if ((type==CMSG_TEXT || type==CMSG_INFO || type==CMSG_WARNING) &&
ctl.verbosity<verbosity_level)
return 0;
va_start(ap, fmt);
/*
if (strlen(fmt) > TOO_LONG)
fmt[TOO_LONG] = 0;
*/
if (!ctl.opened) {
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
else if (type == CMSG_ERROR) {
/* int rc;
int32 val;*/
vsprintf(local, fmt, ap);
pipe_int_write(type);
/* printf("writing CMSG_ERROR of length %d\n",strlen(local));*/
if (strlen(local) > TOO_LONG2){
fprintf(stderr,"CSMG_ERROR STRING TOO LONG!\n");
printf("%s\n",local);
local[TOO_LONG2] = 0;
}
pipe_string_write(local);
/* while ((rc = ctl_blocking_read(&val)) != RC_NEXT)
;*/
} else {
vsprintf(local, fmt, ap);
pipe_int_write(CMSG_MESSAGE);
pipe_int_write(type);
if (type == CMSG_LYRIC) {
pipe_int_write( (int)(current_event->time / (play_mode->rate/100)) );
}
/*printf("writing CMSG of length %d and type %d \n",strlen(local),type);*/
if (strlen(local) > TOO_LONG2){
fprintf(stderr,"CSMG STRING TOO LONG!\n");
printf("%s\n",local);
local[TOO_LONG2] = 0;
}
/* printf("WRITING=%s %d\n",local, strlen(local));*/
pipe_string_write(local);
}
va_end(ap);
return 0;
}
static void ctl_refresh(void)
{
}
static void ctl_total_time(uint32 tt)
{
int centisecs=(int)tt/(play_mode->rate/100);
pipe_int_write(TOTALTIME_MESSAGE);
pipe_int_write(centisecs);
}
static int change_in_volume = 0;
static int change_in_voices;
static void ctl_master_volume(int mv)
{
change_in_volume = 0;
pipe_int_write(MASTERVOL_MESSAGE);
pipe_int_write(mv);
}
static void ctl_file_name(char *name)
{
pipe_int_write(FILENAME_MESSAGE);
pipe_string_write(name);
}
static void ctl_current_time(uint32 ct)
{
int i,v, flags=0;
int centisecs, realct;
realct = play_mode->output_count(ct);
if (realct < 0) realct = 0;
else realct += songoffset;
centisecs = realct / (play_mode->rate/100);
if (!ctl.trace_playing)
return;
Panel->buffer_state = output_buffer_full;
if (dont_cspline) flags |= 1;
if (dont_reverb) flags |= 2;
if (dont_chorus) flags |= 4;
Panel->various_flags = flags;
v=0;
i=voices;
while (i--)
if (voice[i].status!=VOICE_FREE) v++;
pipe_int_write(CURTIME_MESSAGE);
pipe_int_write(centisecs);
pipe_int_write(v);
}
static int vcurve[128] = {
0,0,18,29,36,42,47,51,55,58,
60,63,65,67,69,71,73,74,76,77,
79,80,81,82,83,84,85,86,87,88,
89,90,91,92,92,93,94,95,95,96,
97,97,98,99,99,100,100,101,101,102,
103,103,104,104,105,105,106,106,106,107,
107,108,108,109,109,109,110,110,111,111,
111,112,112,112,113,113,114,114,114,115,
115,115,116,116,116,116,117,117,117,118,
118,118,119,119,119,119,120,120,120,120,
121,121,121,122,122,122,122,123,123,123,
123,123,124,124,124,124,125,125,125,125,
126,126,126,126,126,127,127,127
};
static void ctl_channel_note(int ch, /*int note, int vel,*/ int start)
{
int k, slot=-1, i=voices, v=0, totalvel=0, total_sustain=0;
FLOAT_T total_amp = 0, total_amp_s = 0;
if (start == -1) return;
ch &= 0x1f;
if (slot == -1 /* && start > 10 */)
for (k = 0; k < NQUEUE; k++)
if (Panel->ctime[k][ch] >= start && Panel->ctime[k][ch] < start + 8) {
slot = k;
break;
}
if (slot == -1)
for (k = 0; k < NQUEUE; k++)
if (Panel->ctime[k][ch] == -1) {
slot = k;
break;
}
/* if (slot == -1) { fprintf(stderr,"D"); return; } */
if (slot == -1) return;
Panel->ctime[slot][ch] = start;
while (i--) if (!(voice[i].status&VOICE_FREE) && (voice[i].channel&0x1f) == ch) {
FLOAT_T amp;
if (voice[i].clone_type) continue;
amp = voice[i].left_amp + voice[i].right_amp;
v++;
if ( !(voice[i].status&(VOICE_ON|VOICE_SUSTAINED))) amp /= 2;
if ( (voice[i].sample->modes & MODES_SUSTAIN) &&
(voice[i].status&(VOICE_ON|VOICE_SUSTAINED)) )
total_amp_s += amp;
else total_amp += amp;
}
if (v) {
totalvel = (int)( 370.0 * total_amp / v );
total_sustain = (int)( 370.0 * total_amp_s / v );
if (totalvel > 127) totalvel = 127;
if (total_sustain > 127) total_sustain = 127;
}
Panel->notecount[slot][ch] = (int16)v;
Panel->ctotal[slot][ch] = (uint8)vcurve[totalvel];
Panel->ctotal_sustain[slot][ch] = (uint8)vcurve[total_sustain];
if (channel[ch].kit) Panel->c_flags[ch] |= FLAG_PERCUSSION;
else Panel->c_flags[ch] &= ~FLAG_PERCUSSION;
Panel->panning[slot][ch] = (uint8)channel[ch].panning;
Panel->expression[slot][ch] = (uint8)channel[ch].expression;
Panel->reverberation[slot][ch] = (uint8)channel[ch].reverberation;
Panel->chorusdepth[slot][ch] = (uint8)channel[ch].chorusdepth;
Panel->volume[slot][ch] = (uint8)channel[ch].volume;
/*Panel->c_bank[ch] = (uint8)channel[ch].bank; */
/*Panel->c_variationbank[ch] = (uint8)channel[ch].variationbank; */
}
static void ctl_note(int v)
{
int ch, note, vel, start;
if (!ctl.trace_playing)
return;
if (voice[v].clone_type != 0) return;
start = (voice[v].starttime + (voice[v].sample_offset>>FRACTION_BITS)) /(play_mode->rate/100);
ch = voice[v].channel;
ch &= 0x1f;
if (ch < 0 || ch >= MAXCHAN) return;
note = voice[v].note;
vel = voice[v].velocity;
#if 0
switch(voice[v].status)
{
case VOICE_DIE:
vel /= 2;
start = -1;
break;
case VOICE_FREE:
vel = 0;
/* start = -1; */
break;
case VOICE_ON:
break;
case VOICE_OFF:
/* start = -1; */
case VOICE_SUSTAINED:
/* start = -1; */
break;
}
#endif
ctl_channel_note(ch, /* note, vel,*/ start);
}
static void ctl_program( int ch, int val, const char *name)
{
char noname[2];
if (!ctl.trace_playing)
return;
ch &= 0x1f;
if (channel[ch].kit) Panel->c_bank[ch] = (uint8)channel[ch].kit;
else Panel->c_bank[ch] = (uint8)channel[ch].bank;
Panel->c_variationbank[ch] = (uint8)channel[ch].variationbank;
noname[0] = '*';
noname[1] = '\0';
pipe_int_write(PROGRAM_MESSAGE);
pipe_int_write(ch);
pipe_int_write(val);
if (name && strlen(name) > 0 && strlen(name) < 99) pipe_string_write(name);
else pipe_string_write(noname);
/*
Panel->channel[ch].program = val;
Panel->c_flags[ch] |= FLAG_PROG;
*/
}
static void ctl_volume( int ch, int val )
{
#ifdef MISC_PANEL_UPDATE
if (!ctl.trace_playing)
return;
ch &= 0x1f;
/* Panel->channel[ch].volume = val; */
ctl_channel_note(ch, Panel->cnote[ch], Panel->cvel[ch], -1);
#else
ch=val=0;
#endif
}
static void ctl_expression( int ch, int val )
{
if (!ctl.trace_playing)
return;
ch &= 0x1f;
ctl_channel_note(ch, current_event->time);
}
static void ctl_panning( int ch, int val )
{
#ifdef MISC_PANEL_UPDATE
if (!ctl.trace_playing)
return;
ch &= 0x1f;
/* Panel->channel[ch].panning = val; */
Panel->c_flags[ch] |= FLAG_PAN;
#else
ch=val=0;
#endif
}
static void ctl_sustain( int ch, int val )
{
#ifdef MISC_PANEL_UPDATE
if (!ctl.trace_playing)
return;
ch &= 0x1f;
/* Panel->channel[ch].sustain = val; */
Panel->c_flags[ch] |= FLAG_SUST;
#else
ch=val=0;
#endif
}
static void ctl_pitch_bend( int ch, int val )
{
ch=val=0;
}
static void ctl_reset(void)
{
int i, j;
/* pipe_int_write(TOTALTIME_MESSAGE);*/ /* This is crap */
/* pipe_int_write( ctl.trace_playing);*/
if (!ctl.trace_playing)
return;
Panel->buffer_state = 100;
Panel->various_flags = 0;
Panel->reset_panel = 10;
for (i = 0; i < MAXDISPCHAN; i++) {
#if 0
ctl_program(i, channel[i].program, channel[i].name);
ctl_volume(i, channel[i].volume);
ctl_expression(i, channel[i].expression);
ctl_panning(i, channel[i].panning);
ctl_sustain(i, channel[i].sustain);
ctl_pitch_bend(i, channel[i].pitchbend);
ctl_channel_note(i, Panel->cnote[i], 0, -1);
#endif
for (j = 0; j < NQUEUE; j++) {
Panel->ctime[j][i] = -1;
Panel->notecount[j][i] = 0;
Panel->ctotal[j][i] = 0;
Panel->ctotal_sustain[j][i] = 0;
}
}
}
/***********************************************************************/
/* OPEN THE CONNECTION */
/***********************************************************************/
static int ctl_open(int using_stdin, int using_stdout)
{
int tcount = 30;
shm_alloc();
Panel->currentpatchset = cfg_select;
Panel->buffer_state = 100;
Panel->various_flags = 0;
Panel->max_patch_megs = max_patch_memory / 1000000;
pipe_open();
/* if (child_pid == 0)
start_panel();*/
signal(SIGCHLD, get_child);
signal(SIGTERM, shm_free);
signal(SIGINT, shm_free);
ctl.opened=1;
while (!pipe_read_ready() && tcount) {
sleep(1);
tcount--;
if (!tcount)
fprintf(stderr,"Internal error: no pipe open.\n");
}
return 0;
}
/* Tells the window to disapear */
static void ctl_close(void)
{
if (ctl.opened) {
pipe_int_write(CLOSE_MESSAGE);
/*kill(child_pid, SIGTERM);*/
/* wait((int *)0); */
shm_free(100);
ctl.opened=0;
}
}
/*
* Read information coming from the window in a BLOCKING way
*/
/* commands are: PREV, NEXT, QUIT, STOP, LOAD, JUMP, VOLM */
static int ctl_blocking_read(int32 *valp)
{
int command;
int new_volume;
int new_centiseconds;
int arg, argopt, i;
int pausing = 0;
pipe_int_read(&command);
while (1) /* Loop after pause sleeping to treat other buttons! */
{
switch(command)
{
case MOTIF_CHANGE_VOLUME:
pipe_int_read(&new_volume);
if (!pausing) {
change_in_volume = *valp= new_volume - amplification ;
return RC_CHANGE_VOLUME;
}
amplification=new_volume;
break;
case MOTIF_CHANGE_LOCATOR:
pipe_int_read(&new_centiseconds);
songoffset =
*valp= new_centiseconds*(play_mode->rate / 100) ;
ctl_reset();
pausing = 0;
return RC_JUMP;
case MOTIF_FWD:
pipe_int_read(&new_centiseconds);
songoffset +=
*valp= new_centiseconds*(play_mode->rate / 100) ;
pausing = 0;
return RC_FORWARD;
case MOTIF_RWD:
pipe_int_read(&new_centiseconds);
songoffset -=
*valp= new_centiseconds*(play_mode->rate / 100) ;
pausing = 0;
return RC_BACK;
case MOTIF_QUIT:
songoffset = 0;
ctl_reset();
pausing = 0;
return RC_QUIT;
case MOTIF_STOP:
songoffset = 0;
ctl_reset();
pausing = 0;
return RC_STOP;
case MOTIF_PLAY_FILE:
songoffset = 0;
ctl_reset();
pausing = 0;
return RC_LOAD_FILE;
case MOTIF_NEXT:
songoffset = 0;
ctl_reset();
pausing = 0;
return RC_NEXT;
case MOTIF_PREV:
songoffset = 0;
ctl_reset();
pausing = 0;
return RC_REALLY_PREVIOUS;
case MOTIF_RESTART:
songoffset = 0;
ctl_reset();
pausing = 0;
return RC_RESTART;
case MOTIF_PATCHSET:
pipe_int_read(&arg);
/*if (cfg_select == arg) return RC_NONE;*/
cfg_select = arg;
pausing = 0;
return RC_PATCHCHANGE;
/* fprintf(stderr,"ctl_blocking_read set #%d\n", cfg_select); */
#if 0
if (!pausing) return RC_PATCHCHANGE;
free_instruments();
end_soundfont();
clear_config();
/* what if read_config fails?? */
if (!read_config_file(current_config_file, 0))
Panel->currentpatchset = cfg_select;
/* else fprintf(stderr,"couldn't read config file\n"); */
break;
#endif
case MOTIF_EFFECTS:
pipe_int_read(&arg);
*valp= arg;
effect_activate(arg);
if (!pausing) return RC_NONE;
break;
case MOTIF_FILTER:
pipe_int_read(&arg);
*valp= arg;
/*command_cutoff_allowed = arg;*/
dont_filter_drums = arg;
if (!pausing) return RC_NONE;
break;
case MOTIF_REVERB:
pipe_int_read(&arg);
*valp= arg;
if (arg == 1) arg = 32;
else if (arg == 2) arg = 64;
else if (arg == 3) arg = 96;
else if (arg == 4) arg = 127;
global_reverb = arg;
for (i=0; i<MAXCHAN; i++)
if (channel[i].reverberation < arg)
channel[i].reverberation = arg;
if (!pausing) return RC_NONE;
break;
case MOTIF_CHORUS:
pipe_int_read(&arg);
*valp= arg;
if (arg == 1) arg = 32;
else if (arg == 2) arg = 64;
else if (arg == 3) arg = 96;
else if (arg == 4) arg = 127;
global_chorus = arg;
for (i=0; i<MAXCHAN; i++)
if (channel[i].chorusdepth < arg)
channel[i].chorusdepth = arg;
if (!pausing) return RC_NONE;
break;
case MOTIF_DRY:
pipe_int_read(&arg);
*valp= arg;
opt_dry = arg;
if (!pausing) return RC_NONE;
break;
case MOTIF_EVS:
pipe_int_read(&arg);
*valp= arg;
opt_stereo_surround = arg & 0x0f;
opt_volume_curve = (arg>>4) & 0x0f;
opt_expression_curve = (arg>>8) & 0x0f;
if (!pausing) return RC_NONE;
break;
case MOTIF_INTERPOLATION:
pipe_int_read(&arg);
*valp= arg;
current_interpolation = arg;
if (!pausing) return RC_NONE;
break;
case MOTIF_CHANGE_VOICES:
pipe_int_read(&arg);
change_in_voices =
*valp= arg;
pausing = 0;
return RC_CHANGE_VOICES;
case MOTIF_CHECK_STATE:
pipe_int_read(&arg);
/* arg >>4 = checkbox 0,1,2,3; arg&0x0f = 0 (off), 1 (no change), 2 (on) */
/*fprintf(stderr, "box %d, state %d\n", arg>>4, arg&0x0f);*/
argopt = arg & 0x0f;
switch (arg>>4) {
case 0:
/* stereo */
if (!argopt) reverb_options &= ~(OPT_STEREO_VOICE | OPT_STEREO_EXTRA);
else reverb_options |= OPT_STEREO_VOICE;
if (argopt == 2) reverb_options |= OPT_STEREO_EXTRA;
break;
case 1:
/* reverb */
if (!argopt) reverb_options &= ~(OPT_REVERB_VOICE | OPT_REVERB_EXTRA);
else reverb_options |= OPT_REVERB_VOICE;
if (argopt >= 2) reverb_options |= OPT_REVERB_EXTRA;
if (argopt < 2) global_echo = 0;
else if (argopt == 2) global_echo = 32;
else if (argopt == 3) global_echo = 64;
else if (argopt == 4) global_echo = 96;
else if (argopt == 5) global_echo = 127;
break;
case 2:
/* chorus */
if (!argopt) reverb_options &= ~(OPT_CHORUS_VOICE | OPT_CHORUS_EXTRA);
else reverb_options |= OPT_CHORUS_VOICE;
if (argopt >= 2) reverb_options |= OPT_CHORUS_EXTRA;
if (argopt < 2) global_detune = 0;
else if (argopt == 2) global_detune = 32;
else if (argopt == 3) global_detune = 64;
else if (argopt == 4) global_detune = 96;
else if (argopt == 5) global_detune = 127;
break;
case 3:
/* verbosity */
ctl.verbosity = argopt;
break;
}
if (!pausing) return RC_NONE;
break;
case TRY_OPEN_DEVICE:
pausing = 0;
return RC_TRY_OPEN_DEVICE;
case MOTIF_KEYUP:
case MOTIF_KEYDOWN:
case MOTIF_SLOWER:
case MOTIF_FASTER:
case MOTIF_TOGGLE_DRUMS:
if (!pausing) return RC_NONE;
break;
}
if (command==MOTIF_PAUSE)
{
if (pausing) {
pausing = 0;
return RC_NONE; /* Resume where we stopped */
}
ctl_reset();
pausing = 1;
}
if (pausing) pipe_int_read(&command);
else
{
#ifdef KMIDI
fprintf(stderr,"UNKNOWN KMIDI MESSAGE %i\n",command);
#else
fprintf(stderr,"UNKNOWN GTK MESSAGE %i\n",command);
#endif
return RC_NONE;
}
}
}
/*
* Read information coming from the window in a non blocking way
*/
static int ctl_read(int32 *valp)
{
int num;
if (last_rc_command)
{
*valp = last_rc_arg;
num = last_rc_command;
last_rc_command = 0;
return num;
}
/* We don't wan't to lock on reading */
num=pipe_read_ready();
if (num==0)
return RC_NONE;
return(ctl_blocking_read(valp));
}
static void ctl_pass_playing_list(int number_of_files, const char *list_of_files[])
{
int i=0;
char file_to_play[1000];
int command;
int32 val;
Panel->currentpatchset = cfg_select;
/* Pass the list to the interface */
/* The commandline files now come from the c++ ui side. */
#ifndef KMIDI
pipe_int_write(FILE_LIST_MESSAGE);
pipe_int_write(number_of_files);
for (i=0;i<number_of_files;i++)
pipe_string_write(list_of_files[i]);
#endif
/* Ask the interface for a filename to play -> begin to play automatically */
pipe_int_write(NEXT_FILE_MESSAGE);
command = ctl_blocking_read(&val);
/* Main Loop */
for (;;)
{
if (command==RC_LOAD_FILE)
{
max_patch_memory = 1000000 * Panel->max_patch_megs;
/* Read a LoadFile command */
pipe_string_read(file_to_play);
command=play_midi_file(file_to_play);
}
else
{
if (command==RC_QUIT)
return;
if (command==RC_ERROR)
command=RC_TUNE_END; /* Launch next file */
switch(command)
{
case RC_TRY_OPEN_DEVICE:
if( output_device_open == 0){
if (play_mode->open_output()<0){
output_device_open = 0;
pipe_int_write(DEVICE_NOT_OPEN);
}
else{
output_device_open = 1;
pipe_int_write(DEVICE_OPEN);
}
}
break;
case RC_CHANGE_VOLUME:
if (change_in_volume>0 || amplification > -change_in_volume)
amplification += change_in_volume;
else amplification = 0;
change_in_volume = 0;
if (amplification > MAX_AMPLIFICATION)
amplification=MAX_AMPLIFICATION;
ctl_master_volume(amplification);
break;
case RC_NEXT:
pipe_int_write(NEXT_FILE_MESSAGE);
break;
case RC_REALLY_PREVIOUS:
pipe_int_write(PREV_FILE_MESSAGE);
break;
case RC_TUNE_END:
pipe_int_write(TUNE_END_MESSAGE);
break;
case RC_JUMP:
pipe_int_write(JUMP_MESSAGE);
break;
case RC_PATCHCHANGE:
free_instruments();
end_soundfont();
clear_config();
/* what if read_config fails?? */
if (!read_config_file(current_config_file, 0))
Panel->currentpatchset = cfg_select;
/* else fprintf(stderr,"couldn't read config file\n"); */
pipe_int_write(PATCH_CHANGED_MESSAGE);
break;
case RC_CHANGE_VOICES:
voices = change_in_voices;
break;
case RC_FORWARD:
case RC_BACK:
case RC_NONE:
case RC_STOP:
break;
default:
printf("UNKNOWN COMMAND ERROR: %i\n",command);
}
command = ctl_blocking_read(&val);
}
}
}
void pipe_open()
{
int res;
res=pipe(pipeAppli);
if (res!=0) pipe_error("PIPE_APPLI CREATION");
res=pipe(pipeMotif);
if (res!=0) pipe_error("PIPE_KMIDI CREATION");
if ((child_pid=fork())==0) /*child*/
{
close(pipeMotif[1]);
close(pipeAppli[0]);
fpip_in=pipeMotif[0];
fpip_out= pipeAppli[1];
#ifdef KMIDI
Launch_KMidi_Process(fpip_in);
#else
Launch_Gtk_Process(fpip_in);
#endif
exit(0);
}
close(pipeMotif[0]);
close(pipeAppli[1]);
fpip_in= pipeAppli[0];
fpip_out= pipeMotif[1];
}
/***********************************************************************/
/* PIPE COMUNICATION */
/***********************************************************************/
void pipe_error(const char *st)
{
fprintf(stderr,"Kmidi:Problem with %s due to:%s\n",
st,
sys_errlist[errno]);
exit(1);
}
/*
void pipe_printf(char *fmt, ...)