-
Notifications
You must be signed in to change notification settings - Fork 0
/
freevamp.c
3184 lines (2645 loc) · 93.6 KB
/
freevamp.c
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
/*
* freevamp.c
*
* by Gary Wong <[email protected]>, 2002, 2003.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* 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
*
* $Id: freevamp.c,v 1.13 2006/02/08 01:12:13 gtw Exp $
*/
#include "config.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <gtk/gtk.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "fvicon.h"
#include "getopt.h"
#include "gettext.h"
#define _(X) gettext(X)
#define N_(X) gettext_noop(X)
extern char szCopying[], szWarranty[];
#define RCFILE ".freevamprc"
#define CTRL_WAH_PEDAL 1
#define CTRL_VOLUME_PEDAL 7
#define CTRL_AMP_GAIN 12
#define CTRL_AMP_TREBLE 13
#define CTRL_AMP_MID 14
#define CTRL_AMP_BASS 15
#define CTRL_AMP_VOL 16
#define CTRL_FX_ASSIGN_AMP_PRESENCE 17
#define CTRL_FX_ASSIGN_V1 17
#define CTRL_AMP_PRESENCE_V2 17
#define CTRL_REVERB_MIX 18
#define CTRL_AMP_TYPE_AMP_TYPE_DEFAULT 19
#define CTRL_AMP_TYPE_V1 19
#define CTRL_AMP_TYPE_DEFAULT_V2 19
#define CTRL_FX_TYPE_DEFAULT 20
#define CTRL_FX 21
#define CTRL_REVERB 22
#define CTRL_CABINET_TYPE 23
#define CTRL_REVERB_TYPE 24
#define CTRL_NOISE_GATE 25
#define CTRL_DRIVE 26
#define CTRL_WAH 27
#define CTRL_PRE_FX_TYPE 44
#define CTRL_PRE_FX_1 45
#define CTRL_PRE_FX_2 46
#define CTRL_PRE_FX_3 47
#define CTRL_PRE_FX_4 48
#define CTRL_DELAY_TYPE 49
#define CTRL_DELAY_TIME_HI 50
#define CTRL_DELAY_TIME_LO 51
#define CTRL_DELAY_SPREAD 52
#define CTRL_DELAY_FEEDBACK 53
#define CTRL_DELAY_MIX 54
#define CTRL_POST_FX_MODE 55
#define CTRL_POST_FX_1 56
#define CTRL_POST_FX_2 57
#define CTRL_POST_FX_3 58
#define CTRL_POST_FX_MIX 59
#define CTRL_FX_ASSIGN_V2 60
#define CTRL_AMP_TYPE_V2 61
#define CTRL_TAP 64
#define CTRL_REQUEST 80
#define CTRL_NAME 81
#define CTRL_TUNER_VOLUME_V2 82
#define CTRL_TUNER_FREQ_V2 83
#define CTRL_CONFIG_V2 84
#define CTRL_LIVE_EQ_TREBLE_V2 85
#define CTRL_LIVE_EQ_MID_V2 86
#define CTRL_LIVE_EQ_BASS_V2 87
#define PARM_AMP_GAIN 0
#define PARM_AMP_TREBLE 1
#define PARM_AMP_MID 2
#define PARM_AMP_BASS 3
#define PARM_AMP_VOL 4
#define PARM_AMP_PRESENCE_V2 5
#define PARM_REVERB_MIX 6
#define PARM_AMP_TYPE 7
#define PARM_FX_MIX_ASSIGN 8
#define PARM_FX 9
#define PARM_FX_REVERB 10
#define PARM_CABINET_TYPE 11
#define PARM_REVERB_TYPE 12
#define PARM_NOISE_GATE 13
#define PARM_DRIVE 14
#define PARM_WAH 15
#define PARM_PRE_FX_TYPE 16
#define PARM_PRE_FX_1 17
#define PARM_PRE_FX_2 18
#define PARM_PRE_FX_3 19
#define PARM_PRE_FX_4 20
#define PARM_DELAY_TYPE 21
#define PARM_DELAY_TIME_HI 22
#define PARM_DELAY_TIME_LO 23
#define PARM_DELAY_SPREAD 24
#define PARM_DELAY_FEEDBACK 25
#define PARM_DELAY_MIX 26
#define PARM_POST_FX_MODE 27
#define PARM_POST_FX_1 28
#define PARM_POST_FX_2 29
#define PARM_POST_FX_3 30
#define PARM_POST_FX 31
#define PARM_PRESET_NAME 32
#define PARM_PRESET_LEN 16
#define NUM_PARMS 48
#define PRE_FX_NONE 0
#define PRE_FX_COMPRESSOR 1
#define PRE_FX_AUTO_WAH 2
#define POST_FX_ROTARY 0
#define POST_FX_PHASER 1
#define POST_FX_TREMOLO 2
#define POST_FX_MONO_CHORUS 3
#define POST_FX_STEREO_CHORUS 4
#define POST_FX_MONO_FLANGER 5
#define POST_FX_STEREO_FLANGER 6
#define DELAY_SIMPLE 0
#define DELAY_ECHO 1
#define DELAY_PING_PONG 2
#define NUM_BANKS 25
#define PRESETS_PER_BANK 5
#define NUM_PRESETS (NUM_BANKS * PRESETS_PER_BANK)
#define PRESET_CURRENT 0x7F
#define PRESET_TUNER 0x7F
#define CMD_IDENTIFY_DEV 0x01
#define CMD_IDENTIFY_RESPONSE 0x02
#define CMD_WRITE_PRESET 0x20
#define CMD_WRITE_ALL_PRESETS 0x21
#define CMD_SET_CHANNEL 0x22
#define CMD_SET_TUNER_VOL 0x23
#define CMD_SET_TUNER_FREQ 0x24
#define CMD_REQUEST_PRESET 0x60
#define CMD_REQUEST_ALL_PRESETS 0x61
#define MIDI_DATA 0x7F
#define MIDI_STATUS 0x80
#define MIDI_OPERATION 0xF0
#define MIDI_CHANNEL 0x0F
#define MIDI_NOTEOFF 0x80
#define MIDI_NOTEON 0x90
#define MIDI_AFTERTOUCH 0xA0
#define MIDI_CTRLCHANGE 0xB0
#define MIDI_PROGCHANGE 0xC0
#define MIDI_CHANPRESSURE 0xD0
#define MIDI_PITCHWHEEL 0xE0
#define MIDI_SYSTEM 0xF0
#define MIDI_SYSEX 0xF0
#define MIDI_MTCQUARTERFRAME 0xF1
#define MIDI_SONGPOS 0xF2
#define MIDI_SONGSEL 0xF3
#define MIDI_TUNEREQ 0xF6
#define MIDI_SYSEX_END 0xF7
#define MIDI_SYSREALTIME 0xF8
#define MIDI_CLOCK 0xF8
#define MIDI_TICK 0xF9
#define MIDI_START 0xFA
#define MIDI_CONTINUE 0xFB
#define MIDI_STOP 0xFC
#define MIDI_ACTIVESENSE 0xFE
#define MIDI_RESET 0xFF
#define PROG_TUNER 0x7F
#define ID_BEHRINGER1 0x00
#define ID_BEHRINGER2 0x20
#define ID_BEHRINGER3 0x32
#define ID_MODEL_V_AMP_1 0x0D
#define ID_MODEL_V_AMP_2 0x10
#define DEV_BROADCAST 0x7F
#define MOD_BROADCAST 0x7F
#define POINTS_INCH 72
#define POINTS_MM (POINTS_INCH/25.4)
#define PAPER_ISO_A4_X (210*POINTS_MM)
#define PAPER_ISO_A4_Y (297*POINTS_MM)
#define PAPER_US_LETTER_X (8.5*POINTS_INCH)
#define PAPER_US_LETTER_Y (11*POINTS_INCH)
#define PRINT_AREA_X 451
#define PRINT_AREA_Y 648
#define VLB_HEADER_SIZE 16
#define VLB_PATCH_SIZE 276
#define VLB_PATCH_OFFSET 220
typedef struct _vamp {
int h; /* MIDI device file descriptor */
GIOChannel *pioc;
char *szMidiDevice, *szDevice, *szFileName;
unsigned char nDeviceID, nModelID, iChannel, iProgram, nRunningStatus;
char achPreset[ PRESET_CURRENT + 1 ][ NUM_PARMS ];
char achClipboard[ NUM_PARMS ];
int fClipboard, fSysex;
char achCommand[ 3 ];
int cchCommand;
GtkWidget *pwEditor, *pwList, *pwLog, *pwLogList;
GtkListStore *plsLog;
GtkAccelGroup *pag;
struct _listwindow *plw;
struct _editorwindow *pew;
void *pvSysex;
void (*control)( struct _vamp *pv, char iController, char nValue );
void (*program)( struct _vamp *pv, char iProgram );
void (*sysex)( struct _vamp *pv, unsigned char n, void *p,
int cRemaining );
} vamp;
typedef struct _preferences {
int fLog, fLogScroll, cLogMax, cxPaper, cyPaper;
char *szPrint;
} preferences;
static char *aszPreEffectsName[] = { N_("None"), N_("Compressor"),
N_("Auto wah"), NULL };
static char *aszModulationName[] = { N_("Rotary"), N_("Phaser"), N_("Tremolo"),
N_("Mono chorus"), N_("Stereo chorus"),
N_("Mono flanger"), N_("Stereo flanger"),
NULL };
static char *aszDelayName[] = { N_("Delay"), N_("Echo"), N_("Ping pong"),
NULL };
static char *aszReverbName[] = { N_("Tiny room"), N_("Small room"),
N_("Medium room"), N_("Large room"),
N_("Ultra room"), N_("Small spring"),
N_("Medium spring"), N_("Short ambience"),
N_("Long ambience"), NULL };
static char *aszAmpNameV1[] = { N_("American Blues"), N_("Modern Class A"),
N_("Tweed Combo"), N_("Classic Clean"),
N_("British Blues"), N_("British Class A"),
N_("British Classic"), N_("British Hi Gain"),
N_("Rectified Hi Gain"), N_("Modern Hi Gain"),
N_("Fuzz Box"), N_("Ultimate V-AMP"),
N_("Drive V-AMP"), N_("Crunch V-AMP"),
N_("Clean V-AMP"), N_("Tube Pre-amp"), NULL },
*aszAmpNameV2[] = { N_("None"), N_("American Blues"), N_("And Deluxe"),
N_("Modern Class A"), N_("Custom Class A"),
N_("Tweed Combo"), N_("Small Combo"),
N_("Classic Clean"), N_("Black Twin"),
N_("British Blues"), N_("And Custom"),
N_("British Class A"), N_("Non Top Boost"),
N_("British Classic"), N_("Classic 50W"),
N_("British Hi Gain"), N_("British Class A 15W"),
N_("Rectified Hi Gain"), N_("Rectified Head"),
N_("Modern Hi Gain"), N_("Savage Beast"),
N_("Fuzz Box"), N_("Custom Hi Gain"),
N_("Ultimate V-AMP"), N_("Ultimate Plus"),
N_("Drive V-AMP"), N_("California Drive"),
N_("Crunch V-AMP"), N_("Custom Drive"),
N_("Clean V-AMP"), N_("California Clean"),
N_("Tube Pre-amp"), N_("Custom Clean"), NULL };
static char *aszCabinetName[] = { N_("None"), N_("1 x 8\" Vintage Tweed"),
N_("4 x 10\" Vintage Bass"),
N_("4 x 10\" V-AMP Custom"),
N_("1 x 12\" Mid Combo"),
N_("1 x 12\" Blackface"),
N_("1 x 12\" Brit '60"),
N_("1 x 12\" Deluxe '52"),
N_("2 x 12\" Twin Combo"),
N_("2 x 12\" U.S. Class A"),
N_("2 x 12\" V-AMP Custom"),
N_("2 x 12\" Brit '67"),
N_("4 x 12\" Vintage 30"),
N_("4 x 12\" Standard '78"),
N_("4 x 12\" Off Axis"),
N_("4 x 12\" V-AMP Custom"), NULL };
static char *aszEffectsAssignName[] = { N_("Echo"), N_("Delay"),
N_("Ping pong"), N_("Phaser/Delay"),
N_("Flanger/Delay 1"),
N_("Flanger/Delay 2"),
N_("Chorus/Delay 1"),
N_("Chorus/Delay 2"),
N_("Chorus/Compressor"),
N_("Compressor"), N_("Auto wah"),
N_("Phaser"), N_("Chorus"),
N_("Flanger"), N_("Tremolo"),
N_("Rotary"), NULL };
static char *aszAutoWahLabel[ 4 ] = { N_("Spd"), N_("Dpt"), N_("Off"),
N_("Frq") };
static char *aszModulationLabel[ 4 ] = { N_("Spd"), N_("Dpt"), N_("Fdb"),
N_("Mix") };
static char *aszDelayLabel[ 4 ] = { N_("Tim"), N_("Spr"), N_("Fdb"),
N_("Mix") };
static char *aszAmpLabel[ 6 ] = { N_("Gan"), N_("Bas"), N_("Mid"), N_("Tre"),
N_("Pre"), N_("Vol") };
static char szIcon[] = "freevamp-icon";
static char achDefaultParm[ NUM_PARMS ] = {
64, 64, 64, 64, 64, 64, 64, 32, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'U','n','n','a','m','e','d',' ',' ',' ',' ',' ',' ',' ',' ',' '
};
static preferences pref = { FALSE, TRUE, 100, PAPER_ISO_A4_X, PAPER_ISO_A4_Y,
NULL };
static int VAmp2( vamp *pva ) {
return pva->nModelID >= ID_MODEL_V_AMP_2;
}
static char *PreEffectsName( int i ) {
return ( i < 0 || i > 2 ) ? NULL : gettext( aszPreEffectsName[ i ] );
}
static char *ModulationName( int i ) {
return ( i < 0 || i > 6 ) ? NULL : gettext( aszModulationName[ i ] );
}
static char *DelayName( int i ) {
return ( i < 0 || i > 2 ) ? NULL : gettext( aszDelayName[ i ] );
}
static char *ReverbName( int i ) {
return ( i < 0 || i > 8 ) ? NULL : gettext( aszReverbName[ i ] );
}
static char *AmpName( vamp *pva, int i ) {
if( VAmp2( pva ) ) {
if( i < 0x10 )
return gettext( aszAmpNameV2[ ( i << 1 ) + 1 ] );
else if( i < 0x20 )
return gettext( aszAmpNameV2[ ( ( i & 0x0F ) << 1 ) + 2 ] );
else
return gettext( aszAmpNameV2[ 0 ] );
} else {
if( i >= 0 && i < 0x10 )
return gettext( aszAmpNameV1[ i ] );
else
return _("n/a");
}
}
static char *CabinetName( int i ) {
return ( i < 0 || i > 15 ) ? NULL : gettext( aszCabinetName[ i ] );
}
static char *EffectsAssignName( int i ) {
return ( i < 0 || i > 15 ) ? NULL : gettext( aszEffectsAssignName[ i ] );
}
static int AutoWahSpeed( int n ) {
static int anAutoWahSpeed[ 10 ] = { 10, 20, 50, 100, 200, 300, 400, 500,
750, 1000 };
return ( n < 0 || n > 129 ) ? 0 : anAutoWahSpeed[ n / 13 ];
}
static int Message( GtkWindow *pwParent, GtkMessageType mt, GtkButtonsType bt,
char *szFormat, ... ) G_GNUC_PRINTF( 4, 5 );
static int Message( GtkWindow *pwParent, GtkMessageType mt, GtkButtonsType bt,
char *szFormat, ... ) {
va_list val;
char *pch;
GtkWidget *pw;
int f;
va_start( val, szFormat );
pch = g_strdup_vprintf( szFormat, val );
va_end( val );
pw = gtk_message_dialog_new( pwParent, GTK_DIALOG_DESTROY_WITH_PARENT,
mt, bt, "%s", pch );
g_free( pch );
f = gtk_dialog_run( GTK_DIALOG( pw ) );
gtk_widget_destroy( pw );
return f;
}
static void LogTrimScroll( vamp *pva ) {
int c;
GtkAdjustment *padj;
GtkTreeIter ti;
if( !pva->plsLog )
return;
for( c = gtk_tree_model_iter_n_children( GTK_TREE_MODEL( pva->plsLog ),
NULL ) - pref.cLogMax;
c > 0; c-- ) {
gtk_tree_model_get_iter_first( GTK_TREE_MODEL( pva->plsLog ),
&ti );
gtk_list_store_remove( pva->plsLog, &ti );
}
if( pref.fLogScroll ) {
padj = gtk_tree_view_get_vadjustment( GTK_TREE_VIEW(
pva->pwLogList ) );
gtk_adjustment_set_value( padj, G_MAXDOUBLE );
}
}
static void Log( vamp *pva, unsigned char chStatus, char *szFormat, ... ) {
char sz[ 1024 ], szStatus[ 3 ], szChannel[ 4 ];
va_list val;
GtkTreeIter ti;
if( !pva->plsLog )
return;
va_start( val, szFormat );
vsnprintf( sz, sizeof sz, szFormat, val );
va_end( val );
if( ( chStatus & MIDI_OPERATION ) == MIDI_SYSTEM )
strcpy( szChannel, "N/A" );
else
sprintf( szChannel, "%d", ( chStatus & MIDI_CHANNEL ) + 1 );
sprintf( szStatus, "%02X", chStatus );
gtk_list_store_append( pva->plsLog, &ti );
gtk_list_store_set( pva->plsLog, &ti, 0, pva->szMidiDevice, 1, szChannel,
2, szStatus, 3, sz, -1 );
LogTrimScroll( pva );
}
static char *ControllerName( vamp *pva, unsigned char i ) {
switch( i ) {
case CTRL_WAH_PEDAL:
return _("Wah Pedal");
case CTRL_VOLUME_PEDAL:
return _("Volume Pedal");
case CTRL_AMP_GAIN:
return _("Amp Gain");
case CTRL_AMP_TREBLE:
return _("Amp Treble");
case CTRL_AMP_MID:
return _("Amp Mid");
case CTRL_AMP_BASS:
return _("Amp Bass");
case CTRL_AMP_VOL:
return _("Amp Vol");
case CTRL_FX_ASSIGN_AMP_PRESENCE:
return VAmp2( pva ) ? _("Presence") : _("Assign Effects");
case CTRL_REVERB_MIX:
return _("Reverb Mix");
case CTRL_AMP_TYPE_AMP_TYPE_DEFAULT:
return VAmp2( pva ) ? _("Amp Type with default cabinet") :
_("Amp Type");
case CTRL_FX_TYPE_DEFAULT:
return _("Fx Type with defaults");
case CTRL_FX:
return _("Fx Enable");
case CTRL_REVERB:
return _("Reverb Enable");
case CTRL_CABINET_TYPE:
return _("Cabinet Type");
case CTRL_REVERB_TYPE:
return _("Reverb Type");
case CTRL_NOISE_GATE:
return _("Noise Gate Level");
case CTRL_DRIVE:
return _("Drive");
case CTRL_WAH:
return _("Wah position");
case CTRL_PRE_FX_TYPE:
return _("pre Effect Type");
case CTRL_PRE_FX_1:
return _("pre Effect 1");
case CTRL_PRE_FX_2:
return _("pre Effect 2");
case CTRL_PRE_FX_3:
return _("pre Effect 3");
case CTRL_PRE_FX_4:
return _("pre Effect 4");
case CTRL_DELAY_TYPE:
return _("Delay Type");
case CTRL_DELAY_TIME_HI:
return _("Delay Time hi");
case CTRL_DELAY_TIME_LO:
return _("Delay Time lo");
case CTRL_DELAY_SPREAD:
return _("Delay Spread");
case CTRL_DELAY_FEEDBACK:
return _("Delay Feedback");
case CTRL_DELAY_MIX:
return _("Delay Mix");
case CTRL_POST_FX_MODE:
return _("post Fx Mode");
case CTRL_POST_FX_1:
return _("post Fx 1");
case CTRL_POST_FX_2:
return _("post Fx 2");
case CTRL_POST_FX_3:
return _("post Fx 3");
case CTRL_POST_FX_MIX:
return _("post Fx Mix");
case CTRL_FX_ASSIGN_V2:
return _("Assign Effects");
case CTRL_AMP_TYPE_V2:
return _("Amp Type w/o cabinet change");
case CTRL_TAP:
return _("Tap");
case CTRL_REQUEST:
return _("Request Controls");
case CTRL_NAME:
return _("Preset Name");
case CTRL_TUNER_VOLUME_V2:
return _("Tuner Bypass Volume");
case CTRL_TUNER_FREQ_V2:
return _("Tuner Centre Frequency");
case CTRL_CONFIG_V2:
return _("Configuration");
case CTRL_LIVE_EQ_TREBLE_V2:
return _("Live EQ Treble");
case CTRL_LIVE_EQ_MID_V2:
return _("Live EQ Mid");
case CTRL_LIVE_EQ_BASS_V2:
return _("Live EQ Bass");
default:
return _("unknown");
}
}
static char *PresetName( char *achPreset ) {
static char ach[ 17 ];
char *pch;
memcpy( ach, &achPreset[ PARM_PRESET_NAME ], PARM_PRESET_LEN );
ach[ 16 ] = 0;
for( pch = ach + 15; *pch == ' '; pch-- )
*pch = 0;
return ach;
}
static int ReadMIDI( vamp *pva ) {
unsigned char ach[ 1024 ], *pch;
int n;
static char *aszNote[ 12 ] = {
"C", "C#", "D", "Eb", "E", "F", "F#", "G", "G#", "A", "Bb", "B"
};
if( ( n = read( pva->h, ach, sizeof ach ) ) <= 0 )
return -1;
for( pch = ach; n; pch++, n-- ) {
if( pva->fSysex && pva->sysex )
pva->sysex( pva, *pch, pva->pvSysex, n - 1 );
if( *pch & MIDI_STATUS ) {
if( ( *pch & MIDI_SYSREALTIME ) == MIDI_SYSREALTIME )
switch( *pch ) {
case MIDI_CLOCK:
Log( pva, *pch, _("System Clock") );
break;
case MIDI_TICK:
Log( pva, *pch, _("System Tick") );
break;
case MIDI_START:
Log( pva, *pch, _("System Start") );
break;
case MIDI_CONTINUE:
Log( pva, *pch, _("System Continue") );
break;
case MIDI_STOP:
Log( pva, *pch, _("System Stop") );
break;
case MIDI_ACTIVESENSE:
Log( pva, *pch, _("System Active Sense") );
break;
case MIDI_RESET:
Log( pva, *pch, _("System Clock") );
break;
}
else if( *pch == MIDI_TUNEREQ ) {
Log( pva, *pch, _("System Tune Request") );
pva->nRunningStatus = 0;
pva->cchCommand = 0;
pva->fSysex = FALSE;
break;
} else if( pva->nRunningStatus == MIDI_SYSEX &&
*pch == MIDI_SYSEX_END ) {
Log( pva, pva->nRunningStatus,
_("System Exclusive: %d bytes"), pva->cchCommand );;
pva->nRunningStatus = 0;
pva->cchCommand = 0;
pva->fSysex = FALSE;
} else {
pva->nRunningStatus = *pch;
pva->cchCommand = 0;
pva->fSysex = *pch == MIDI_SYSEX;
}
} else {
if( pva->cchCommand < 3 )
pva->achCommand[ pva->cchCommand ] = *pch;
pva->cchCommand++;
switch( pva->nRunningStatus & MIDI_OPERATION ) {
case MIDI_NOTEOFF:
case MIDI_NOTEON:
if( pva->cchCommand >= 2 ) {
Log( pva, pva->nRunningStatus, _("Note %d (%s%d) %s "
"(velocity %d)"), pva->achCommand[ 0 ],
aszNote[ pva->achCommand[ 0 ] % 12 ],
pva->achCommand[ 0 ] / 12,
( ( pva->nRunningStatus & MIDI_OPERATION ) ==
MIDI_NOTEOFF ) || !pva->achCommand[ 1 ] ? _("off") :
_("on"), pva->achCommand[ 1 ] );
pva->cchCommand = 0;
}
break;
case MIDI_AFTERTOUCH:
if( pva->cchCommand >= 2 ) {
Log( pva, pva->nRunningStatus,
_("Note %d (%s%d) aftertouch (pressure %d)"),
pva->achCommand[ 0 ],
aszNote[ pva->achCommand[ 0 ] % 12 ],
pva->achCommand[ 0 ] / 12,
pva->achCommand[ 1 ] );
pva->cchCommand = 0;
}
break;
case MIDI_CTRLCHANGE:
if( pva->cchCommand >= 2 ) {
if( pva->achCommand[ 0 ] == CTRL_NAME ) {
if( pva->achCommand[ 1 ] < ' ' )
Log( pva, pva->nRunningStatus,
_("Controller %d (%s): position %d"),
pva->achCommand[ 0 ],
ControllerName( pva, pva->achCommand[ 0 ] ),
pva->achCommand[ 1 ] );
else
Log( pva, pva->nRunningStatus,
_("Controller %d (%s): character '%c'"),
pva->achCommand[ 0 ],
ControllerName( pva, pva->achCommand[ 0 ] ),
pva->achCommand[ 1 ] );
} else
Log( pva, pva->nRunningStatus,
_("Controller %d (%s): %d"), pva->achCommand[ 0 ],
ControllerName( pva, pva->achCommand[ 0 ] ),
pva->achCommand[ 1 ] );
pva->control( pva, pva->achCommand[ 0 ],
pva->achCommand[ 1 ] );
pva->cchCommand = 0;
}
break;
case MIDI_PROGCHANGE:
if( pva->achCommand[ 0 ] < NUM_PRESETS )
Log( pva, pva->nRunningStatus,
_("Program %d (%d%c, %s)"), pva->achCommand[ 0 ],
pva->achCommand[ 0 ] / PRESETS_PER_BANK + 1,
'A' + ( pva->achCommand[ 0 ] % PRESETS_PER_BANK ),
PresetName( pva->achPreset[
(int) pva->achCommand[ 0 ] ] ) );
else if( pva->achCommand[ 0 ] == PRESET_TUNER )
Log( pva, pva->nRunningStatus,
_("Program %d (Tuner)"), pva->achCommand[ 0 ] );
else
Log( pva, pva->nRunningStatus,
_("Program %d (unknown)"), pva->achCommand[ 0 ] );
pva->program( pva, pva->achCommand[ 0 ] );
pva->cchCommand = 0;
break;
case MIDI_CHANPRESSURE:
Log( pva, pva->nRunningStatus, _("Channel pressure %d\n"),
pva->achCommand[ 0 ] );
pva->cchCommand = 0;
break;
case MIDI_PITCHWHEEL:
if( pva->cchCommand >= 2 ) {
Log( pva, pva->nRunningStatus, _("Pitch bend %d (%dc)"),
pva->achCommand[ 0 ] | ( pva->achCommand[ 1 ] << 7 ),
( ( pva->achCommand[ 0 ] |
( pva->achCommand[ 1 ] << 7 ) ) - 0x2000 )
* 100 / 0x1000 );
pva->cchCommand = 0;
}
break;
case MIDI_MTCQUARTERFRAME:
Log( pva, pva->nRunningStatus,
_("System MTC quarter frame %d\n"),
pva->achCommand[ 0 ] );
pva->cchCommand = 0;
pva->nRunningStatus = 0;
break;
case MIDI_SONGPOS:
if( pva->cchCommand >= 2 ) {
Log( pva, pva->nRunningStatus,
_("System Song position %d"), pva->achCommand[ 0 ] |
( pva->achCommand[ 1 ] << 7 ) );
pva->cchCommand = 0;
pva->nRunningStatus = 0;
}
break;
case MIDI_SONGSEL:
Log( pva, pva->nRunningStatus, _("System Song select %d\n"),
pva->achCommand[ 0 ] );
pva->cchCommand = 0;
pva->nRunningStatus = 0;
break;
default:
/* ignore */
;
}
}
}
return 0;
}
typedef struct _sysexstate {
int cch, cchAlloc, cchExpected, cchOld, fFailed;
char *pch;
GtkWidget *pwDialog, *pwProgress;
} sysexstate;
static void HandleSysex( vamp *pva, unsigned char ch, void *p,
int cRemaining ) {
sysexstate *pses = p;
if( !cRemaining ) {
if( pses->cchExpected )
gtk_progress_bar_set_fraction(
GTK_PROGRESS_BAR( pses->pwProgress ),
(double) pses->cch / pses->cchExpected );
else
gtk_progress_bar_pulse( GTK_PROGRESS_BAR( pses->pwProgress ) );
while( gtk_events_pending() )
gtk_main_iteration();
}
/* we need to recheck pses->fFailed, since it may have been modified
in gtk_main_iteration() above */
if( pses->fFailed )
return;
if( ch == MIDI_SYSEX_END ) {
/* success */
pva->sysex = NULL; /* don't call us again */
gtk_dialog_response( GTK_DIALOG( pses->pwDialog ), GTK_RESPONSE_OK );
return;
} else if( !( ch & MIDI_STATUS ) ) {
pses->pch[ pses->cch++ ] = ch;
if( pses->cch < pses->cchAlloc )
return;
if( ( pses->pch = realloc( pses->pch, pses->cchAlloc <<= 1 ) ) )
return;
}
pses->fFailed = TRUE;
gtk_dialog_response( GTK_DIALOG( pses->pwDialog ), GTK_RESPONSE_REJECT );
}
static unsigned char *ReadSysex( vamp *pva, GtkWindow *pwParent, int *cb,
int cbExpected ) {
sysexstate ses;
GtkWidget *pw;
int n;
if( pva->h < 0 ) {
errno = EBADF;
return NULL;
}
ses.cch = ses.cchOld = 0;
ses.cchExpected = cbExpected;
ses.fFailed = FALSE;
pw = gtk_dialog_new_with_buttons( _("Free V-AMP - Progress"), pwParent,
GTK_DIALOG_MODAL, GTK_STOCK_CANCEL,
GTK_RESPONSE_REJECT, NULL );
ses.pwDialog = pw;
ses.pwProgress = gtk_progress_bar_new();
gtk_container_add( GTK_CONTAINER( GTK_DIALOG( pw )->vbox ),
ses.pwProgress );
gtk_widget_show_all( pw );
if( ( ses.pch = malloc( ses.cchAlloc = 1024 ) ) ) {
pva->pvSysex = &ses;
pva->sysex = HandleSysex;
n = gtk_dialog_run( GTK_DIALOG( pw ) );
gtk_widget_destroy( pw );
pva->pvSysex = NULL;
pva->sysex = NULL;
}
if( n != GTK_RESPONSE_OK ) {
free( ses.pch );
ses.pch = NULL;
ses.cch = 0;
}
if( cb )
*cb = ses.cch;
return realloc( ses.pch, ses.cch );
}
static int ControlChange( vamp *pva, char iController, char nValue ) {
unsigned char ach[ 3 ] = { MIDI_CTRLCHANGE | pva->iChannel,
iController & MIDI_DATA, nValue & MIDI_DATA };
write( pva->h, ach, 3 );
pva->control( pva, iController, nValue );
return 0;
}
static int RequestAllControllers( vamp *pva ) {
return ControlChange( pva, CTRL_REQUEST, CTRL_REQUEST );
}
static int ProgramChange( vamp *pva, char iProgram ) {
unsigned char ach[ 2 ] = { MIDI_PROGCHANGE | pva->iChannel,
iProgram & MIDI_DATA };
if( write( pva->h, ach, 2 ) < 0 )
return -1;
return 0;
}
static int StartSysEx( vamp *pva, char idCommand ) {
unsigned char ach[ 7 ] = { MIDI_SYSEX, ID_BEHRINGER1, ID_BEHRINGER2,
ID_BEHRINGER3, pva->nDeviceID, pva->nModelID,
idCommand };
if( write( pva->h, ach, 7 ) < 0 )
return -1;
return 0;
}
static int EndSysEx( vamp *pva ) {
static unsigned char ch = MIDI_SYSEX_END;
if( write( pva->h, &ch, 1 ) < 0 )
return -1;
return 0;
}
static int IdentifyDevice( vamp *pva, GtkWindow *pw, char ach[ 256 ] ) {
int cb;
unsigned char *pch;
if( StartSysEx( pva, CMD_IDENTIFY_DEV ) < 0 )
return -1;
if( EndSysEx( pva ) < 0 )
return -1;
if( !( pch = ReadSysex( pva, pw, &cb, 0 ) ) )
return -1;
if( cb < 6 || pch[ 0 ] != ID_BEHRINGER1 || pch[ 1 ] != ID_BEHRINGER2 ||
pch[ 2 ] != ID_BEHRINGER3 || pch[ 5 ] != CMD_IDENTIFY_RESPONSE ) {
free( pch );
return -1;
}
pva->nDeviceID = pch[ 3 ];
pva->nModelID = pch[ 4 ];
if( ( cb -= 6 ) > 255 )
cb = 255;
memcpy( ach, pch + 6, cb );
ach[ cb ] = 0;
free( pch );
return 0;
}
static int WritePreset( vamp *pva, char iPreset, char ach[ NUM_PARMS ] ) {
char achCommand[ NUM_PARMS + 2 ];
int i;
achCommand[ 0 ] = iPreset;
achCommand[ 1 ] = NUM_PARMS;
for( i = 0; i < NUM_PARMS; i++ )
achCommand[ i + 2 ] = ach[ i ] & MIDI_DATA;
if( StartSysEx( pva, CMD_WRITE_PRESET ) < 0 )
return -1;
if( write( pva->h, achCommand, NUM_PARMS + 2 ) < 0 )
return -1;
return EndSysEx( pva );
}
static int WriteAllPresets( vamp *pva, char ach[ NUM_PRESETS ][ NUM_PARMS ] ) {
static char achCommand[ 2 ] = { NUM_PRESETS, NUM_PARMS };
int i;
if( StartSysEx( pva, CMD_WRITE_ALL_PRESETS ) < 0 )
return -1;
if( write( pva->h, achCommand, 2 ) < 0 )
return -1;
for( i = 0; i < NUM_PRESETS * NUM_PARMS; i++ )
ach[ 0 ][ i ] &= MIDI_DATA;
if( write( pva->h, ach, NUM_PRESETS * NUM_PARMS ) < 0 )
return -1;
return EndSysEx( pva );
}
static int SetChannel( vamp *pva, char i ) {
if( StartSysEx( pva, CMD_SET_CHANNEL ) < 0 )
return -1;
if( write( pva->h, &i, 1 ) < 0 )
return -1;
if( EndSysEx( pva ) < 0 )
return -1;
pva->iChannel = i;
return 0;
}
static int SetTunerVol( vamp *pva, char n ) {
if( StartSysEx( pva, CMD_SET_TUNER_VOL ) < 0 )
return -1;
if( write( pva->h, &n, 1 ) < 0 )