// -*-c++-*- #ifndef MUSTANG2_H #define MUSTANG2_H #include #include #include #include #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 { unsigned char execute[64]; static const unsigned char state_prefix[]; static const unsigned char tuner_prefix[]; libusb_device_handle *usb_io; pthread_t worker; pthread_mutex_t shutdown_lock = PTHREAD_MUTEX_INITIALIZER; bool want_shutdown; template 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); } }; Condition preset_names_sync; char preset_names[100][33]; unsigned curr_preset_idx; // Manage access to each DSP block Condition dsp_sync[6]; unsigned char dsp_parms[6][64]; // Received {0x1c, 0x01, 0x00, ...} Condition cc_ack_eom; // Received {0x00, 0x00, 0x19, ... } Condition efx_toggle_sync; static const unsigned char efx_toggle_ack[]; // Synchronize init on end of initial parm dump Condition parm_read_sync; static const unsigned char parm_read_ack[]; // Synchronize on receipt of model change acknowledge Condition model_change_sync; static const unsigned char model_change_ack[]; // Synchronize on receipt of control change acknowledge Condition cc_ack_sync; static const unsigned char cc_ack[]; Condition tuner_ack_sync; static const unsigned char tuner_ack[]; struct usb_id { // product id int pid; // magic value for init packet int init_value; // v2? bool isV2; }; // For device probe static const usb_id amp_ids[]; bool isV2; bool tuner_active; AmpCC * curr_amp; StompCC * curr_stomp; ModCC * curr_mod; DelayCC * curr_delay; ReverbCC * curr_reverb; 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 ); inline bool is_type(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