-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmustang.h
165 lines (120 loc) · 3.64 KB
/
mustang.h
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
// -*-c++-*-
#ifndef MUSTANG2_H
#define MUSTANG2_H
#include <stdint.h>
#include <cstring>
#include <libusb-1.0/libusb.h>
#include <pthread.h>
#include "constants.h"
#define USB_IN 0x81
#define USB_OUT 0x01
#define USB_TIMEOUT_MS 500
class AmpCC;
class ReverbCC;
class DelayCC;
class ModCC;
class StompCC;
class Mustang {
// Pre-built 'execute' command
unsigned char execute[64];
libusb_device_handle *usb_io;
// USB listen thread
pthread_t worker;
// Shutdown request flag
pthread_mutex_t shutdown_lock = PTHREAD_MUTEX_INITIALIZER;
bool want_shutdown;
template <class T>
class Condition {
public:
pthread_mutex_t lock;
pthread_cond_t cond;
T value;
Condition( void ) {
pthread_mutex_init( &(lock), NULL);
pthread_cond_init( &(cond), NULL);
}
};
// Identify patch-change ack / DSP parm update
static const unsigned char state_prefix[];
// Received {0x1c, 0x01, 0x00, ...}
// --> End of preset select acknowledge stream
Condition<bool> pc_ack_sync;
// Synchronize access to preset names
Condition<bool> preset_names_sync;
// 0-99 = amp preset, 100-111 = mod preset, 112-123 = rev/delay preset
char preset_names[124][33];
// Index to current amp preset
unsigned curr_preset_idx;
// Manage access to each DSP data block and/or associated object.
Condition<bool> dsp_sync[6];
unsigned char dsp_parms[6][64];
// Manage data and behavior for specific DSP models
AmpCC * curr_amp;
StompCC * curr_stomp;
ModCC * curr_mod;
DelayCC * curr_delay;
ReverbCC * curr_reverb;
// Synchronize on end of parm dump
Condition<bool> parm_read_sync;
static const unsigned char parm_read_ack[];
// Synchronize on receipt of direct control acknowledge
Condition<bool> cc_ack_sync;
static const unsigned char cc_ack[];
// Received {0x00, 0x00, 0x19, ... }
// --> Acknowledge efx on/off toggle
Condition<bool> efx_toggle_sync;
static const unsigned char efx_toggle_ack[];
// Synchronize on receipt of model change acknowledge
Condition<bool> model_change_sync;
static const unsigned char model_change_ack[];
// Sync on tuner on/off ack
Condition<bool> tuner_ack_sync;
static const unsigned char tuner_ack[];
// Attached device probe structure
struct usb_id {
// product id
int pid;
// magic value for init packet
int init_value;
// v2?
bool isV2;
};
static const usb_id amp_ids[];
bool isV2;
static void *threadStarter( void * );
void handleInput( void );
int direct_control( unsigned char *cmd );
int sendCmd( unsigned char *buffer );
int requestDump( void );
int executeModelChange( unsigned char *buffer );
void updateAmpObj( const unsigned char *data );
void updateStompObj( const unsigned char *data );
void updateReverbObj( const unsigned char *data );
void updateDelayObj( const unsigned char *data );
void updateModObj( const unsigned char *data );
int checkOrDisableTuner( void );
// Check for equality of 2-byte values
inline bool match16(const unsigned char *a, const unsigned char *b) {
return ( 0==memcmp(a,b,2) );
}
public:
Mustang( void );
int initialize( void );
int deinitialize( void );
int commStart( void );
int commShutdown( void );
int setAmp( int ord );
int ampControl( int cc, int value );
int setStomp( int ord );
int stompControl( int cc, int value );
int setMod( int ord );
int modControl( int cc, int value );
int setDelay( int ord );
int delayControl( int cc, int value );
int setReverb( int ord );
int reverbControl( int cc, int value );
int tunerMode( int value );
int patchChange( int );
int effectToggle( int cc, int value );
};
#endif