drummer/lv2_plugin.h
Arnaud G. GIBERT 5cce284879 - Drop local libnode version, now use the official one, V2.3.x,
- Replace internal log system with LibLog V1.0.x,
- Code cleanup,
- Add GPL Licenses files.
2024-04-21 20:21:45 +02:00

633 lines
18 KiB
C

/*----------------------------------------------------------------------------*/
/* lv2_plugin.h */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* This file is part of Drummer. */
/* */
/* Drummer 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 3 of the License, or */
/* (at your option) any later version. */
/* */
/* Drummer 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 Drummer. If not, see <https://www.gnu.org/licenses/>. */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* Includes */
/*----------------------------------------------------------------------------*/
#ifndef _LV2_PLUGIN_H_
#define _LV2_PLUGIN_H_
/*----------------------------------------------------------------------------*/
/* Global definitions */
/*----------------------------------------------------------------------------*/
// lv2 stuff
#define DRD_DRUMMER_URI "http://rx3.org/AlkorZ3/drummer"
#define DRD_GAIN_MIN -60.0f
#define DRD_GAIN_MAX 6.0f
#define DRD_VELOCITY_MIN 0
#define DRD_VELOCITY_MAX 127
#define DRD_DB3SCALE -0.8317830986718104f
#define DRD_DB3SCALEPO 1.8317830986718104f
// taken from lv2 example amp plugin
#define DRD_DB_CO(g) ( ( g) > DRD_GAIN_MIN ? powf( 10.0f, ( g) * 0.05f) : 0.0f)
#define DRD_PORT_NUMBER_MAX 32
#define DRD_REQ_BUF_SIZE 10
typedef enum
{
DRD_LV2_CONTROL = 0,
DRD_LV2_MASTER_LEFT,
DRD_LV2_MASTER_RIGHT,
DRD_LV2_LEFT_00,
DRD_LV2_RIGHT_00,
DRD_LV2_LEFT_01,
DRD_LV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_25,
DRD_LV2_PAN_26,
DRD_LV2_PAN_27,
DRD_LV2_PAN_28,
DRD_LV2_PAN_29,
DRD_LV2_PAN_30,
DRD_LV2_PAN_31,
DRD_LV2_CORE_EVENT,
DRD_LV2_NUM_PORTS
} DRT_Port_Index;
/*
typedef struct DRT_Drummer_URIS
{
LV2_URID Atom_Object;
LV2_URID String_URId;
LV2_URID Bool_URId;
LV2_URID Int_URId;
LV2_URID Long_URId;
LV2_URID Tuple_URId;
LV2_URID Midi_Event;
LV2_URID Atom_EventTransfer;
LV2_URID UI_Msg;
LV2_URID UI_Enable;
LV2_URID UI_Disable;
LV2_URID Kit_Update_Request;
LV2_URID Kit_Update_Reply;
LV2_URID Velocity_Ignore_Flag_Toggle;
LV2_URID Note_Off_Ignore_Flag_Toggle;
// LV2_URID kit_path;
// LV2_URID get_state;
// LV2_URID midi_info;
// LV2_URID sample_trigger;
// LV2_URID channel_id;
// LV2_URID velocity_toggle;
// LV2_URID note_off_toggle;
// LV2_URID zero_position;
// LV2_URID sample_add;
// LV2_URID sample_remove;
} DRT_Drummer_URIS;
*/
typedef struct DRT_Sample
{
DRT_Instrument *Instrument_Ptr;
DRT_Layer *Layer_Ptr;
float *Data_Ptr;
uint32_t Limit;
SF_INFO *SF_Info_Ptr;
int Data_Offset;
char Active;
uint32_t Offset;
float Velocity;
bool Sustained;
} DRT_Sample;
typedef struct DRT_LV2_Base
{
// Ports
float *Master_Left;
float *Master_Right;
float **Left;
float **Right;
LV2_Atom_Sequence *Control_Port;
LV2_Atom_Sequence *Core_Event_Port;
LV2_Atom_Forge Forge;
// params
// int Channel;
// int Channel_Nb;
int Zero_Position;
float **Gains;
float **Pans;
bool Sustain;
// URIs
LV2_URID_Map *Map_Ptr;
DRT_Drummer_URIS URIS;
// Logger
LV2_Log_Logger Logger;
// Kit info
DRT_Kit *Kit_Ptr;
DRT_Kit_Id Kit_Id;
DRT_Kit_Id Kit_Id_New;
uint8_t Bank_Id_LSB;
uint8_t Bank_Id_MSB;
uint8_t Program_Id;
uint8_t Bank_Id_LSB_New;
uint8_t Bank_Id_MSB_New;
uint8_t Program_Id_New;
int Kit_Updated_Flag;
char *Current_Path;
char **Request_Buf;
int CurReq;
// Samples
DRT_Sample Samples[DRD_PORT_NUMBER_MAX];
uint8_t Sample_Number;
// Loading Thread Stuff
pthread_mutex_t Load_Mutex;
pthread_cond_t Load_Cond;
pthread_t Load_Thread;
} DRT_LV2_Base;
/*
typedef struct
{
// Ports
float *master_left;
float *master_right;
float **left;
float **right;
LV2_Atom_Sequence *control_port;
LV2_Atom_Sequence *core_event_port;
LV2_Atom_Forge forge;
// params
int channel;
bool ignore_velocity;
bool ignore_note_off;
int channel_nb;
int zero_position;
float **gains;
float **pans;
float *baseNote;
double rate;
// URIs
LV2_URID_Map *map;
drmr_uris uris;
// Kit info
char *current_path;
char **request_buf;
int curReq;
// Samples
drmr_sample *samples;
uint8_t num_samples;
// loading thread stuff
pthread_mutex_t load_mutex;
pthread_cond_t load_cond;
pthread_t load_thread;
} DrMr;
*/
/*----------------------------------------------------------------------------*/
/* DRD DATA & API definition */
/*----------------------------------------------------------------------------*/
# ifdef _LV2_PLUGIN_C_
# define DRD_LV2_DATA
# define DRD_LV2_API
# else
# define DRD_LV2_DATA extern
# define DRD_LV2_API extern
# endif
/*----------------------------------------------------------------------------*/
/* Public Data */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* Public Prototypes */
/*----------------------------------------------------------------------------*/
# ifdef _LV2_PLUGIN_C_
/*----------------------------------------------------------------------------*/
/* Private Definitions */
/*----------------------------------------------------------------------------*/
#define DRD_MODULE_NAME "lv2"
#define LGD_MODULE_NAME "lv2"
/*----------------------------------------------------------------------------*/
/* DRG_LV2_Base */
/*----------------------------------------------------------------------------*/
DRT_LV2_Base DRG_LV2_Base;
/*----------------------------------------------------------------------------*/
/* Private Prototypes */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static void *DR_LV2_Load_Thread();
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static inline LV2_Atom *DR_LV2_Message_Midi_Info_Build( uint8_t *);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
DRT_Status DR_UI_Port_Notify( LV2_URID, float);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
DRT_Status DR_LV2_Kit_Samples_Load( DRT_Kit *);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
DRT_Status DR_LV2_CurKit_Samples_Load();
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static inline void DR_Layer_To_Sample( DRT_Sample *, float);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static inline void DR_Sample_Trigger( int, uint8_t *const, uint32_t);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static inline void DR_Sample_Untrigger( int, uint32_t);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static inline void DR_Sample_UnSustain( uint32_t);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static LV2_Handle DR_LV2_Instantiate(const LV2_Descriptor *, double, const char *, const LV2_Feature * const *);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static void DR_LV2_Connect_Port( LV2_Handle, uint32_t, void *);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static void DR_LV2_Activate( LV2_Handle);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static void DR_LV2_Run( LV2_Handle, uint32_t);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static void DR_LV2_DeActivate( LV2_Handle);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static void DR_LV2_Cleanup( LV2_Handle);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static LV2_State_Status DR_LV2_Save_State( LV2_Handle, LV2_State_Store_Function, void *, uint32_t, const LV2_Feature *const *);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static LV2_State_Status DR_LV2_Restore_State( LV2_Handle, LV2_State_Retrieve_Function, void *, uint32_t, const LV2_Feature *const *);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
static const void *DR_LV2_Extension_Data( const char *);
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
LV2_SYMBOL_EXPORT const LV2_Descriptor *lv2_descriptor( uint32_t);
/*----------------------------------------------------------------------------*/
/* Post Private Definitions */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* DRG_LV2_Descritor */
/*----------------------------------------------------------------------------*/
static const LV2_Descriptor DRG_LV2_Descriptor =
{
DRD_DRUMMER_URI,
DR_LV2_Instantiate,
DR_LV2_Connect_Port,
DR_LV2_Activate,
DR_LV2_Run,
DR_LV2_DeActivate,
DR_LV2_Cleanup,
DR_LV2_Extension_Data
};
# else // ifdef _LV2_PLUGIN_C_
/*----------------------------------------------------------------------------*/
/* Public Prototypes */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* DR_LV2_Map_URIS */
/*----------------------------------------------------------------------------*/
//extern inline void DR_LV2_Map_URIS( LV2_URID_Map *, DRT_Drummer_URIS *);
# endif // ifdef _LV2_PLUGIN_C_
/*----------------------------------------------------------------------------*/
#endif // ifndef _LV2_PLUGIN_H_