-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmustang.cpp
1375 lines (1144 loc) · 31.4 KB
/
mustang.cpp
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
#include "mustang.h"
#include <cstdio>
#include <unistd.h>
#include "amp_models.h"
#include "amp_defaults.h"
#include "amp.h"
#include "stomp_models.h"
#include "stomp_defaults.h"
#include "stomp.h"
#include "mod_models.h"
#include "mod_defaults.h"
#include "mod.h"
#include "delay_models.h"
#include "delay_defaults.h"
#include "delay.h"
#include "reverb_models.h"
#include "reverb_defaults.h"
#include "reverb.h"
// Parameter report (preset names + DSP states)
const unsigned char Mustang::state_prefix[] = { 0x1c, 0x01 };
// End of full parameter dump
const unsigned char Mustang::parm_read_ack[] = { 0xff, 0x01 };
// Acknowledge tuner change
const unsigned char Mustang::tuner_ack[] = { 0x0a, 0x01 };
// Acknowledge model-select
const unsigned char Mustang::model_change_ack[] = { 0x00, 0x00, 0x1c };
// Acknowledge EFX toggle
const unsigned char Mustang::efx_toggle_ack[] = { 0x00, 0x00, 0x19 };
// Acknowledge CC
const unsigned char Mustang::cc_ack[] = { 0x00, 0x00, 0x05 };
const Mustang::usb_id Mustang::amp_ids[] = {
{ MI_II_V1, 0x03, false },
{ MIII_IV_V_V1, 0xc1, false },
{ M_BRONCO_40, 0x03, false },
{ M_MINI, 0x03, false },
{ M_FLOOR, 0x03, false },
{ MI_II_V2, 0xc1, true },
{ MIII_IV_V_V2, 0xc1, true },
{ 0, 0x00, false }
};
Mustang::Mustang( void ) {
// Make model select effective
memset( execute, 0x00, 64 );
execute[0] = 0x1c;
execute[1] = 0x03;
// So far, this is the only state flag we need to pre-condition
tuner_ack_sync.value = false;
}
void *
Mustang::threadStarter( void *self ) {
((Mustang *)self)->handleInput();
return NULL;
}
void
Mustang::handleInput( void ) {
int rc;
unsigned char read_buf[64];
int total_count = 0;
while ( 1 ) {
int count;
rc = libusb_interrupt_transfer( usb_io, USB_IN, read_buf, 64, &count, USB_TIMEOUT_MS );
total_count += count;
// Check for exit flag
pthread_mutex_lock( &shutdown_lock );
bool finished = want_shutdown;
pthread_mutex_unlock( &shutdown_lock );
if ( finished ) break;
if ( rc!=0 ) {
// Always retry on timeout since we expect it. Otherwise exit
if ( rc!=LIBUSB_ERROR_TIMEOUT ) break;
}
// Retry on short read
if ( total_count!=64 ) continue;
total_count = 0;
#ifdef DEBUG
for ( int i=0; i<64; i++ ) fprintf( stderr, "%02x ", read_buf[i] );
fprintf( stderr, "\n" );
#endif
if ( 0==memcmp(read_buf,state_prefix,2) ) {
// Only care about amp state messages, and not even all of them...
int dsp_category = read_buf[2];
// 0 = AMP preset / DSP state, 1 = MI/II Mod preset, 2 = MI/II Delay/Reverb preset
int preset_category = read_buf[3];
switch( dsp_category ) {
// Response for DSP data and/or patch-change
//
case 0x00:
{
// Patch change acknowledge sequence done
pthread_mutex_lock( &pc_ack_sync.lock );
pc_ack_sync.value = true;
pthread_cond_signal( &pc_ack_sync.cond );
pthread_mutex_unlock( &pc_ack_sync.lock );
break;
}
case 0x04:
{
// PRESET NAME
// Rank within preset category
int idx = read_buf[4];
// Mod
if ( 1 == preset_category ) idx += 100;
// Rev/Delay
else if ( 2 == preset_category ) idx += 112;
// Preset name
pthread_mutex_lock( &preset_names_sync.lock );
strncpy( preset_names[idx], (const char *)read_buf+16, 32 );
preset_names[idx][32] = '\0';
// Always take the most recent amp preset name as
// current. This will properly account for its appearance at
// the end of a complete parm dump or when manual patch
// change occurs. Not clear if or how current EFX preset
// is reported.
if ( 0 == preset_category ) curr_preset_idx = idx;
pthread_mutex_unlock( &preset_names_sync.lock );
break;
}
case 0x05:
{
// AMP
if ( 0==preset_category ) {
// (Don't want MI/II preset data here)
// DSP parms (make 0x05..0x0a normal to zero)
int idx = dsp_category - 5;
pthread_mutex_lock( &dsp_sync[idx].lock );
memcpy( dsp_parms[idx], (const char *)read_buf, 64 );
updateAmpObj( read_buf );
pthread_mutex_unlock( &dsp_sync[idx].lock );
}
break;
}
case 0x06:
{
// STOMP
if ( 0==preset_category ) {
int idx = dsp_category - 5;
pthread_mutex_lock( &dsp_sync[idx].lock );
memcpy( dsp_parms[idx], (const char *)read_buf, 64 );
updateStompObj( read_buf );
pthread_mutex_unlock( &dsp_sync[idx].lock );
}
break;
}
case 0x07:
{
// MOD
if ( 0==preset_category ) {
int idx = dsp_category - 5;
pthread_mutex_lock( &dsp_sync[idx].lock );
memcpy( dsp_parms[idx], (const char *)read_buf, 64 );
updateModObj( read_buf );
pthread_mutex_unlock( &dsp_sync[idx].lock );
}
break;
}
case 0x08:
{
// DELAY
if ( 0==preset_category ) {
int idx = dsp_category - 5;
pthread_mutex_lock( &dsp_sync[idx].lock );
memcpy( dsp_parms[idx], (const char *)read_buf, 64 );
updateDelayObj( read_buf );
pthread_mutex_unlock( &dsp_sync[idx].lock );
}
break;
}
case 0x09:
{
// REVERB
if ( 0==preset_category ) {
int idx = dsp_category - 5;
pthread_mutex_lock( &dsp_sync[idx].lock );
memcpy( dsp_parms[idx], (const char *)read_buf, 64 );
updateReverbObj( read_buf );
pthread_mutex_unlock( &dsp_sync[idx].lock );
}
break;
}
case 0x0a:
{
// EXP PEDAL
// (No need to guard for MI/II EFX preset here, since they
// do not support pedals)
//
int idx = dsp_category - 5;
pthread_mutex_lock( &dsp_sync[idx].lock );
memcpy( dsp_parms[idx], (const char *)read_buf, 64 );
pthread_mutex_unlock( &dsp_sync[idx].lock );
break;
}
default:
// Filler or unknown packet type
break;
}
}
else if ( 0==memcmp(read_buf,model_change_ack,3) ) {
// Model change acknowledge
pthread_mutex_lock( &model_change_sync.lock );
model_change_sync.value = true;
pthread_cond_signal( &model_change_sync.cond );
pthread_mutex_unlock( &model_change_sync.lock );
}
else if ( 0==memcmp(read_buf,cc_ack,3) ){
// Direct command acknowledge
pthread_mutex_lock( &cc_ack_sync.lock );
cc_ack_sync.value = true;
pthread_cond_signal( &cc_ack_sync.cond );
pthread_mutex_unlock( &cc_ack_sync.lock );
}
else if ( 0==memcmp(read_buf,efx_toggle_ack,3) ){
// EFX toggle acknowledge
pthread_mutex_lock( &efx_toggle_sync.lock );
efx_toggle_sync.value = true;
pthread_cond_signal( &efx_toggle_sync.cond );
pthread_mutex_unlock( &efx_toggle_sync.lock );
}
else if ( 0==memcmp(read_buf,parm_read_ack,2) ){
// Parameter dump completion acknowledge
pthread_mutex_lock( &parm_read_sync.lock );
parm_read_sync.value = true;
pthread_cond_signal( &parm_read_sync.cond );
pthread_mutex_unlock( &parm_read_sync.lock );
}
else if ( 0==memcmp(read_buf,tuner_ack,2) ){
// Tuner toggle notify
pthread_mutex_lock( &tuner_ack_sync.lock );
tuner_ack_sync.value = read_buf[2]==0x01 ? true : false;
pthread_cond_signal( &tuner_ack_sync.cond );
pthread_mutex_unlock( &tuner_ack_sync.lock );
}
}
long result = rc;
pthread_exit( (void *)result );
}
int
Mustang::sendCmd( unsigned char *buffer ) {
int total_count = 0;
int attempts = 5;
while ( total_count < 64 ) {
int count;
int rc = libusb_interrupt_transfer( usb_io, USB_OUT, buffer, 64, &count, USB_TIMEOUT_MS );
if ( rc ) {
if ( rc==LIBUSB_ERROR_TIMEOUT ) {
// Up to five retries on timeout
if ( attempts==0 ) return rc;
else attempts--;
}
// All other errors immediately fatal
else return rc;
}
total_count += count;
}
return 0;
}
int
Mustang::initialize( void ) {
int rc;
if ( usb_io!=NULL ) return -1;
int init_value = -1;
rc = libusb_init( NULL );
if ( rc ) return rc;
for ( int idx=0; amp_ids[idx].pid != 0; idx++ ) {
if ( ( usb_io = libusb_open_device_with_vid_pid(NULL, FENDER_VID, amp_ids[idx].pid)) != NULL ) {
init_value = amp_ids[idx].init_value;
isV2 = amp_ids[idx].isV2;
break;
}
}
if ( init_value < 0 ) {
// No amp found
libusb_exit( NULL );
fprintf( stderr, "S - No Mustang USB device found\n" );
return -1;
}
// If kernel driver is active, detach it
if ( libusb_kernel_driver_active( usb_io,0) ) {
// If detach fails, we're hosed...
if ( 0 != (rc = libusb_detach_kernel_driver(usb_io,0)) ) return rc;
}
// Make it ours
if ( 0 != (rc = libusb_claim_interface(usb_io,0)) ) return rc;
unsigned char buffer[64];
int total_count;
// Phase 1 of amp init
memset( buffer, 0, 64 );
buffer[1] = 0xc3;
rc = sendCmd( buffer );
if ( rc!=0 ) return rc;
// Clear reply
total_count = 0;
while ( total_count < 64 ) {
int count;
rc = libusb_interrupt_transfer( usb_io, USB_IN, buffer, 64, &count, USB_TIMEOUT_MS );
if ( rc && rc!=LIBUSB_ERROR_TIMEOUT ) return rc;
total_count += count;
}
// Phase 2 of amp init
memset( buffer, 0, 64 );
buffer[0] = 0x1a;
buffer[1] = init_value;
rc = sendCmd( buffer );
if ( rc!=0 ) return rc;
// Clear reply
total_count = 0;
while ( total_count < 64 ) {
int count;
rc = libusb_interrupt_transfer( usb_io, USB_IN, buffer, 64, &count, USB_TIMEOUT_MS );
if ( rc && rc!=LIBUSB_ERROR_TIMEOUT ) return rc;
total_count += count;
}
return 0;
}
int
Mustang::commStart( void ) {
int rc;
unsigned char buffer[64];
// Mark as running
want_shutdown = false;
///// Critical Section
//
pthread_mutex_lock( &parm_read_sync.lock );
parm_read_sync.value = false;
// Start thread
pthread_create( &worker, NULL, threadStarter, this );
// Request parm dump
memset( buffer, 0, 64 );
buffer[0] = 0xff;
buffer[1] = 0xc1;
rc = sendCmd( buffer );
// Block until background thread tells us it's done
while ( rc==0 && !parm_read_sync.value ) pthread_cond_wait( &parm_read_sync.cond, &parm_read_sync.lock );
pthread_mutex_unlock( &parm_read_sync.lock );
//
/////
return 0;
}
int
Mustang::commShutdown( void ) {
pthread_mutex_lock( &shutdown_lock );
want_shutdown = true;
pthread_mutex_unlock( &shutdown_lock );
void *status;
pthread_join( worker, &status );
int rc = (long)status;
return rc;
}
int
Mustang::deinitialize( void ) {
if ( usb_io==NULL) return 0;
int rc = libusb_release_interface( usb_io, 0 );
if ( rc && rc != LIBUSB_ERROR_NO_DEVICE ) return rc;
if ( (rc = libusb_attach_kernel_driver( usb_io,0)) ) return rc;
libusb_close( usb_io );
usb_io = NULL;
libusb_exit( NULL );
return 0;
}
int
Mustang::requestDump( void ) {
int rc;
unsigned char buffer[64];
///// Critical Section
//
pthread_mutex_lock( &parm_read_sync.lock );
// Request parm dump
memset( buffer, 0, 64 );
buffer[0] = 0xff;
buffer[1] = 0xc1;
parm_read_sync.value = false;
rc = sendCmd( buffer );
// Block until background thread tells us it's done
while ( rc==0 && !parm_read_sync.value ) pthread_cond_wait( &parm_read_sync.cond, &parm_read_sync.lock );
pthread_mutex_unlock( &parm_read_sync.lock );
//
//////
#ifdef DEBUG
fprintf( stderr, "DEBUG: Parm dump completion acknowledged\n" );
#endif
return 0;
}
int
Mustang::executeModelChange( unsigned char *buffer ) {
// 5..9 --> 0..4
int idx = buffer[2] - 5;
/////// Critical Section 1
//
pthread_mutex_lock( &model_change_sync.lock );
// Setup amp personality
model_change_sync.value = false;
int rc = sendCmd( buffer );
while ( rc==0 && !model_change_sync.value ) pthread_cond_wait( &model_change_sync.cond, &model_change_sync.lock );
// Execute command
model_change_sync.value = false;
rc = sendCmd( execute );
while ( rc==0 && !model_change_sync.value ) pthread_cond_wait( &model_change_sync.cond, &model_change_sync.lock );
pthread_mutex_unlock( &model_change_sync.lock );
//
//////
#ifdef DEBUG
fprintf( stderr, "DEBUG: Model change acknowledged\n" );
#endif
///// Critical Section 2
//
// Lock the DSP device and update for what we just sent
pthread_mutex_lock( &dsp_sync[idx].lock );
// Update DSP state buffer
memcpy( dsp_parms[idx], (const char *)buffer, 64 );
unsigned char *curr = dsp_parms[idx];
// Make it look like a status report:
curr[1] = 0x03;
curr[4] = 0x00;
curr[7] = 0x01;
switch ( idx ) {
case 0:
updateAmpObj( curr );
break;
case 1:
updateStompObj( curr );
break;
case 2:
updateModObj( curr );
break;
case 3:
updateDelayObj( curr );
break;
case 4:
updateReverbObj( curr );
break;
}
pthread_mutex_unlock( &dsp_sync[idx].lock );
//
///////
#ifdef DEBUG
fprintf( stderr, "DEBUG: State updated\n" );
#endif
return rc;
}
void
Mustang::updateAmpObj( const unsigned char *data ) {
AmpCC * new_amp = NULL;
const unsigned char *model = data + MODEL;
if ( match16(f57_deluxe_id,model) ||
match16(f57_champ_id,model) ||
match16(f65_deluxe_id,model) ||
match16(f65_princeton_id,model) ||
match16(s60s_thrift_id,model) ) {
new_amp = new AmpCC( this, model, 0 );
}
else if ( match16(f59_bassman_id,model) ||
match16(brit_70s_id,model) ) {
new_amp = new AmpCC1( this, model, 0 );
}
else if ( match16(f_supersonic_id,model) ) {
new_amp = new AmpCC2( this, model, 0 );
}
else if ( match16(brit_60s_id,model) ) {
new_amp = new AmpCC3( this, model, 0);
}
else if ( match16(brit_80s_id,model) ||
match16(us_90s_id,model) ||
match16(metal_2k_id,model) ||
match16(brit_watt_id,model) ) {
new_amp = new AmpCC4( this, model, 0 );
}
else if ( match16(studio_preamp_id,model) ) {
new_amp = new AmpCC5( this, model, 0 );
}
else if ( match16(brit_color_id,model) ) {
new_amp = new AmpCC6( this, model, 0 );
}
else if ( match16(f57_twin_id,model) ) {
new_amp = new AmpCC7( this, model, 0 );
}
else if ( match16(f65_twin_id,model) ) {
new_amp = new AmpCC8( this, model, 0 );
}
else if ( match16(null_amp_id,model) ) {
new_amp = new NullAmpCC( this, model, 0 );
}
else {
fprintf( stderr, "W - Amp id {%x,%x} not expected\n", model[0], model[1] );
}
if ( new_amp!=NULL ) {
delete curr_amp;
curr_amp = new_amp;
}
}
int
Mustang::setAmp( int ord ) {
if ( checkOrDisableTuner() < 0 ) return -1;
unsigned char *buffer;
switch (ord) {
case 0:
buffer = amp_none;
break;
case 1:
buffer = f57_deluxe;
break;
case 2:
buffer = f59_bassman;
break;
case 3:
buffer = f57_champ;
break;
case 4:
buffer = f65_deluxe;
break;
case 5:
buffer = f65_princeton;
break;
case 6:
buffer = f65_twin;
break;
case 7:
buffer = f_supersonic;
break;
case 8:
buffer = brit_60;
break;
case 9:
buffer = brit_70;
break;
case 10:
buffer = brit_80;
break;
case 11:
buffer = us_90;
break;
case 12:
buffer = metal_2k;
break;
default:
if ( isV2 ) {
switch (ord) {
case 13:
buffer = studio_preamp;
break;
case 14:
buffer = f57_twin;
break;
case 15:
buffer = sixties_thrift;
break;
case 16:
buffer = brit_watts;
break;
case 17:
buffer = brit_color;
break;
default:
return 0;
}
}
else {
return 0;
}
}
return executeModelChange( buffer );
}
int
Mustang::ampControl( int cc, int value ) {
if ( checkOrDisableTuner() < 0 ) return -1;
unsigned char cmd[64];
memset( cmd, 0, 64 );
pthread_mutex_lock( &dsp_sync[AMP_STATE].lock );
int rc = curr_amp->dispatch( cc, value, cmd );
pthread_mutex_unlock( &dsp_sync[AMP_STATE].lock );
// If value out-of-range, just return gracefully
if ( rc<0 ) return 0;
rc = direct_control( cmd );
return rc;
}
void
Mustang::updateStompObj( const unsigned char *data ) {
StompCC * new_stomp = NULL;
const unsigned char *model = data + MODEL;
const unsigned char slot = data[FXSLOT];
if ( match16(overdrive_id,model) ) {
new_stomp = new OverdriveCC( this, model, slot );
}
else if ( match16(wah_id,model) ||
match16(touch_wah_id,model) ) {
new_stomp = new WahCC( this, model, slot );
}
else if ( match16(fuzz_id,model) ) {
new_stomp = new FuzzCC( this, model, slot );
}
else if ( match16(fuzz_twah_id,model) ) {
new_stomp = new FuzzTouchWahCC( this, model, slot );
}
else if ( match16(simple_comp_id,model) ) {
new_stomp = new SimpleCompCC( this, model, slot );
}
else if ( match16(comp_id,model) ) {
new_stomp = new CompCC( this, model, slot );
}
else if ( match16(range_boost_id,model) ) {
new_stomp = new RangerCC( this, model, slot );
}
else if ( match16(green_box_id,model) ) {
new_stomp = new GreenBoxCC( this, model, slot );
}
else if ( match16(orange_box_id,model) ) {
new_stomp = new OrangeBoxCC( this, model, slot );
}
else if ( match16(black_box_id,model) ) {
new_stomp = new BlackBoxCC( this, model, slot );
}
else if ( match16(big_fuzz_id,model) ) {
new_stomp = new BigFuzzCC( this, model, slot );
}
else if ( match16(null_stomp_id,model) ) {
new_stomp = new NullStompCC( this, model, 0 );
}
else {
fprintf( stderr, "W - Stomp id {%x,%x} not expected\n", model[0], model[1] );
}
if ( new_stomp!=NULL ) {
delete curr_stomp;
curr_stomp = new_stomp;
}
}
int
Mustang::setStomp( int ord ) {
if ( checkOrDisableTuner() < 0 ) return -1;
unsigned char *buffer;
switch (ord) {
case 0:
buffer = stomp_none;
break;
case 1:
buffer = overdrive;
break;
case 2:
buffer = wah;
break;
case 3:
buffer = touch_wah;
break;
case 4:
buffer = fuzz;
break;
case 5:
if ( isV2 ) {
return 0;
}
else {
buffer = fuzz_touch_wah;
}
break;
case 6:
buffer = simple_comp;
break;
case 7:
buffer = compressor;
break;
default:
if ( isV2 ) {
switch (ord) {
case 8:
buffer = ranger_boost;
break;
case 9:
buffer = green_box;
break;
case 10:
buffer = orange_box;
break;
case 11:
buffer = black_box;
break;
case 12:
buffer = big_fuzz;
break;
default:
return 0;
}
}
else {
return 0;
}
}
pthread_mutex_lock( &dsp_sync[STOMP_STATE].lock );
buffer[FXSLOT] = curr_stomp->getSlot();
pthread_mutex_unlock( &dsp_sync[STOMP_STATE].lock );
return executeModelChange( buffer );
}
int
Mustang::stompControl( int cc, int value ) {
if ( checkOrDisableTuner() < 0 ) return -1;
unsigned char cmd[64];
memset( cmd, 0, 64 );
pthread_mutex_lock( &dsp_sync[STOMP_STATE].lock );
int rc = curr_stomp->dispatch( cc, value, cmd );
pthread_mutex_unlock( &dsp_sync[STOMP_STATE].lock );
if ( rc<0 ) return 0;
rc = direct_control( cmd );
return rc;
}
void
Mustang::updateModObj( const unsigned char *data ) {
ModCC * new_mod = NULL;
const unsigned char *model = data + MODEL;
const unsigned char slot = data[FXSLOT];
if ( match16(sine_chorus_id,model) ||
match16(tri_chorus_id,model) ) {
new_mod = new ChorusCC( this, model, slot );
}
else if ( match16(sine_flange_id,model) ||
match16(tri_flange_id,model) ) {
new_mod = new FlangerCC( this, model, slot );
}
else if ( match16(vibratone_id,model) ) {
new_mod = new VibratoneCC( this, model, slot );
}
else if ( match16(vint_trem_id,model) ||
match16(sine_trem_id,model) ) {
new_mod = new TremCC( this, model, slot );
}
else if ( match16(ring_mod_id,model) ) {
new_mod = new RingModCC( this, model, slot );
}
else if ( match16(step_filt_id,model) ) {
new_mod = new StepFilterCC( this, model, slot );
}
else if ( match16(phaser_id,model) ) {
new_mod = new PhaserCC( this, model, slot );
}
else if ( match16(pitch_shift_id,model) ) {
new_mod = new PitchShifterCC( this, model, slot );
}
else if ( match16(m_wah_id,model) ||
match16(m_touch_wah_id,model) ) {
new_mod = new ModWahCC( this, model, slot );
}
else if ( match16(dia_pitch_id,model) ) {
new_mod = new DiatonicShiftCC( this, model, slot );
}
else if ( match16(null_mod_id,model) ) {
new_mod = new NullModCC( this, model, 0 );
}
else {
fprintf( stderr, "W - Mod id {%x,%x} not expected\n", model[0], model[1] );
}
if ( new_mod!=NULL ) {
delete curr_mod;
curr_mod = new_mod;
}
}
int
Mustang::setMod( int ord ) {
if ( checkOrDisableTuner() < 0 ) return -1;
unsigned char *buffer;
switch (ord) {
case 0:
buffer = mod_none;
break;
case 1:
buffer = sine_chorus;
break;
case 2:
buffer = triangle_chorus;
break;
case 3:
buffer = sine_flanger;
break;
case 4:
buffer = triangle_flanger;
break;
case 5:
buffer = vibratone;
break;
case 6:
buffer = vintage_tremolo;
break;
case 7:
buffer = sine_tremolo;
break;
case 8:
buffer = ring_modulator;
break;
case 9:
buffer = step_filter;
break;
case 10:
buffer = phaser;
break;
case 11:
buffer = pitch_shifter;
break;
default:
if ( isV2 ) {
switch (ord) {
case 12:
buffer = mod_wah;
break;
case 13:
buffer = mod_touch_wah;
break;
case 14:
buffer = diatonic_pitch_shift;
break;
default:
return 0;
}
}
else {
return 0;
}
}
pthread_mutex_lock( &dsp_sync[MOD_STATE].lock );
buffer[FXSLOT] = curr_mod->getSlot();
pthread_mutex_unlock( &dsp_sync[MOD_STATE].lock );
return executeModelChange( buffer );
}
int
Mustang::modControl( int cc, int value ) {
if ( checkOrDisableTuner() < 0 ) return -1;
unsigned char cmd[64];
memset( cmd, 0, 64 );
pthread_mutex_lock( &dsp_sync[MOD_STATE].lock );
int rc = curr_mod->dispatch( cc, value, cmd );
pthread_mutex_unlock( &dsp_sync[MOD_STATE].lock );
if ( rc<0 ) return 0;
rc = direct_control( cmd );
return rc;
}
void
Mustang::updateDelayObj( const unsigned char *data ) {
DelayCC * new_delay = NULL;
const unsigned char *model = data + MODEL;
const unsigned char slot = data[FXSLOT];
if ( match16(mono_dly_id,model) ) {
new_delay = new MonoDelayCC( this, model, slot );
}
else if ( match16(mono_filter_id,model) ||
match16(st_filter_id,model) ) {
new_delay = new EchoFilterCC( this, model, slot );