From 84e23826c3364fd352f9a23d39ac38599687dcaf Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Wed, 20 Apr 2022 12:37:32 +0200 Subject: [PATCH] - Add Sample loading and unloading support, - Add preliminary LV2 sample loading support, - Add LV2 multy layer sample play, - Add LV2 Bank select & Program change midi message support, - Fix minor bugs... - No GFX --- datastruct.c | 460 +++++++++--- datastruct.h | 214 ++++-- drummer.c | 1906 ++------------------------------------------------ drummer.h | 371 +--------- go.sh | 31 +- libnode.c | 4 +- lv2_plugin.c | 1183 ++++++++++++++++++++++++++++++- lv2_plugin.h | 377 +++++++--- node.h | 2 +- 9 files changed, 2054 insertions(+), 2494 deletions(-) diff --git a/datastruct.c b/datastruct.c index af42fe9..4f620f0 100644 --- a/datastruct.c +++ b/datastruct.c @@ -92,11 +92,14 @@ NDT_Status DR_Layer_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_N ( *Layer_Ptr_Ptr)->Sample_Ptr = Layer_Template_Ptr->Sample_Ptr; ( *Layer_Ptr_Ptr)->Sample_Size = Layer_Template_Ptr->Sample_Size; + ( *Layer_Ptr_Ptr)->SF_Info_Ptr = Layer_Template_Ptr->SF_Info_Ptr; ( *Layer_Ptr_Ptr)->Min = Layer_Template_Ptr->Min; ( *Layer_Ptr_Ptr)->Max = Layer_Template_Ptr->Max; ( *Layer_Ptr_Ptr)->Gain = Layer_Template_Ptr->Gain; ( *Layer_Ptr_Ptr)->Pitch = Layer_Template_Ptr->Pitch; +// fprintf( stderr, ""); + return( NDS_OK); } else @@ -113,10 +116,7 @@ NDT_Status DR_Layer_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_N Command_Name = "NDD_CMD_VALUE_FREE"; - if( Layer_Ptr->Sample_Ptr != NULL) - { - free(Layer_Ptr->Sample_Ptr); - } + DR_Layer_Sample_UnLoad( Layer_Ptr); free( Layer_Ptr); @@ -329,7 +329,32 @@ NDT_Status DR_Layer_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_N } } - default: + case NDD_CMD_SAMPLE_UNLOAD: + { + ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); + + ND_VA_LIST_OPEN( user_args, *Args_Ptr); + + ND_VA_ARG_GET( Kit_Ptr, user_args, DRT_Kit *); + + ND_VA_LIST_CLOSE( user_args); + + DRT_Layer *Layer_Ptr = Node_Ptr->Value; + + + Command_Name = "NDD_CMD_SAMPLE_UNLOAD"; + + if( DR_Layer_Sample_UnLoad( Layer_Ptr) != DRS_OK) + { + return( NDS_OK); + } + else + { + return( NDS_OK); + } + } + + default: { printf( "Layer_Manager() called with an undefined command %d\n", Command); return( NDS_ERRAPI); @@ -684,6 +709,23 @@ NDT_Status DR_Instrument_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, return( ND_DataStruct_Traverse( Instrument_Ptr->Layer_DS_Ptr, NDD_CMD_SAMPLE_LOAD, Kit_Ptr, SampleRate)); } + case NDD_CMD_SAMPLE_UNLOAD: + { + ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); + + ND_VA_LIST_OPEN( user_args, *Args_Ptr); + + ND_VA_ARG_GET( Kit_Ptr, user_args, DRT_Kit *); + + ND_VA_LIST_CLOSE( user_args); + + DRT_Instrument *Instrument_Ptr = Node_Ptr->Value; + + Command_Name = "NDD_CMD_SAMPLE_UNLOAD"; + + return( ND_DataStruct_Traverse( Instrument_Ptr->Layer_DS_Ptr, NDD_CMD_SAMPLE_UNLOAD, Kit_Ptr)); + } + default: { printf( "Instrument_Manager() called with an undefined command %d\n", Command); @@ -745,7 +787,22 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod ... */ - case NDD_CMD_INDEX0_PRINT: + case NDD_CMD_VALUE_FIND: + { + if( Kit_Ptr->Name[0] == 0) + { + *Reply_Index_Id_Ptr = 0; + } + else + { + *Reply_Index_Id_Ptr = 1; + } + + *Reply_Command_Ptr = Cmd; + break; + } + + case NDD_CMD_INDEX0_PRINT: { *Reply_Index_Id_Ptr = 0; *Reply_Command_Ptr = Cmd; @@ -787,8 +844,8 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod { ( *Kit_Ptr_Ptr)->Id = Root_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; - strncpy( ( *Kit_Ptr_Ptr)->Name, Kit_Template_Ptr->Name, NAME_SIZE); - strncpy( ( *Kit_Ptr_Ptr)->Desc, Kit_Template_Ptr->Desc, DESC_SIZE); + strncpy( ( *Kit_Ptr_Ptr)->Name, Kit_Template_Ptr->Name, NAME_SIZE); + strncpy( ( *Kit_Ptr_Ptr)->Desc, Kit_Template_Ptr->Desc, DESC_SIZE); strncpy( ( *Kit_Ptr_Ptr)->DirName, Kit_Template_Ptr->DirName, DIRNAME_SIZE); if( ( nd_status = ND_DataStruct_Open( &((*Kit_Ptr_Ptr)->Instrument_DS_Ptr), DRD_INSTRUMENT_DS_INDEX_NB, DRG_Instrument_DS_Index_Tab_Initial, "Instrument_Manager", DR_Instrument_Manager, NULL, NULL, NULL, NULL, NDD_TRUE, NULL)) != NDS_OK) @@ -1043,7 +1100,7 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod /* case NDD_CMD_PHONEBOOK_SAVE: { - /* +*/ /* ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); ND_VA_LIST_OPEN( user_args, *Args_Ptr); @@ -1127,12 +1184,31 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr, DRT_Kit *Kit_Ptr, doub DRT_Status status; SNDFILE *sndf_ptr; -// int load_sample(char* path, drmr_layer* layer, double target_rate) { -// long size; - fprintf( stderr, "Loading: [%s]\n", Layer_Ptr->FileName); + if( Layer_Ptr->SF_Info_Ptr != NULL) + { + if( Layer_Ptr->Sample_Ptr != NULL) + { + fprintf( stderr, "Skiping: [%s]\n", Layer_Ptr->FileName); + return( DRS_OK); + } + else + { + fprintf( stderr, "Freeing SF_Info: [%s]\n", Layer_Ptr->FileName); + free( Layer_Ptr->SF_Info_Ptr ); + } + } + else + { + if( Layer_Ptr->Sample_Ptr != NULL) + { + fprintf( stderr, "Freeing Sample: [%s]\n", Layer_Ptr->FileName); + free( Layer_Ptr->Sample_Ptr); + } + } + if( ( Layer_Ptr->SF_Info_Ptr = malloc( sizeof(SF_INFO))) == NULL) { fprintf( stderr, "Can't allocate SF_Info buffer !\n"); @@ -1143,7 +1219,7 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr, DRT_Kit *Kit_Ptr, doub if( ( sndf_ptr = sf_open( Layer_Ptr->FileName, SFM_READ, Layer_Ptr->SF_Info_Ptr)) == NULL) { - fprintf( stderr, "Can't open sample file [%s] (%d)!\n", Layer_Ptr->FileName, sf_strerror( (SNDFILE *)( Layer_Ptr->Sample_Ptr))); + fprintf( stderr, "Can't open sample file [%s] (%ld)!\n", Layer_Ptr->FileName, (long)sf_strerror( (SNDFILE *)( Layer_Ptr->Sample_Ptr))); status = DRS_KO; } else @@ -1155,16 +1231,16 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr, DRT_Kit *Kit_Ptr, doub } else { - Layer_Ptr->Sample_Size = Layer_Ptr->SF_Info_Ptr->frames * Layer_Ptr->SF_Info_Ptr->channels * sizeof( float); + Layer_Ptr->Sample_Size = Layer_Ptr->SF_Info_Ptr->frames * Layer_Ptr->SF_Info_Ptr->channels; - if( ( Layer_Ptr->Sample_Ptr = malloc( Layer_Ptr->Sample_Size)) == NULL) + if( ( Layer_Ptr->Sample_Ptr = malloc( Layer_Ptr->Sample_Size * sizeof( float))) == NULL) { - fprintf(stderr,"Can't allocate sample memory: (%d) for [%s]!\n", Layer_Ptr->Sample_Size, Layer_Ptr->FileName); + fprintf(stderr,"Can't allocate sample memory: (%ld) for [%s]!\n", Layer_Ptr->Sample_Size, Layer_Ptr->FileName); status = DRS_KO; } else { - sf_read_float( sndf_ptr, Layer_Ptr->Sample_Ptr, ( Layer_Ptr->Sample_Size / sizeof( float))); + sf_read_float( sndf_ptr, Layer_Ptr->Sample_Ptr, ( Layer_Ptr->Sample_Size)); status = DRS_OK; @@ -1176,6 +1252,8 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr, DRT_Kit *Kit_Ptr, doub long out_size; + fprintf( stderr, "Resampling: [%s] (%d)->(%lf)\n", Layer_Ptr->FileName, Layer_Ptr->SF_Info_Ptr->samplerate, SampleRate); + src_data.data_in = Layer_Ptr->Sample_Ptr; src_data.input_frames = Layer_Ptr->SF_Info_Ptr->frames; src_data.src_ratio = SampleRate / Layer_Ptr->SF_Info_Ptr->samplerate; @@ -1185,7 +1263,7 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr, DRT_Kit *Kit_Ptr, doub if( ( src_data.data_out = malloc( out_size)) == NULL) { - fprintf( stderr,"Can't allocate resample memory: (%d) for [%s]!\n", out_size, Layer_Ptr->FileName); + fprintf( stderr,"Can't allocate resample memory: (%ld) for [%s]!\n", out_size, Layer_Ptr->FileName); status = DRS_KO; } else @@ -1208,7 +1286,7 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr, DRT_Kit *Kit_Ptr, doub free( Layer_Ptr->Sample_Ptr); Layer_Ptr->Sample_Ptr = src_data.data_out; - Layer_Ptr->Sample_Size = src_data.output_frames_gen * Layer_Ptr->SF_Info_Ptr->channels * sizeof( float); + Layer_Ptr->Sample_Size = src_data.output_frames_gen * Layer_Ptr->SF_Info_Ptr->channels; Layer_Ptr->SF_Info_Ptr->samplerate = SampleRate; Layer_Ptr->SF_Info_Ptr->frames = src_data.output_frames_gen; } @@ -1219,8 +1297,10 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr, DRT_Kit *Kit_Ptr, doub sf_close( sndf_ptr); } - - free( Layer_Ptr->SF_Info_Ptr); + +// fprintf( stderr, "Debug !\n"); +// DR_Layer_Dump(Layer_Ptr, 0); +// free( Layer_Ptr->SF_Info_Ptr); return( status); } @@ -1235,6 +1315,22 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr, DRT_Kit *Kit_Ptr, doub DRT_Status DR_Layer_Sample_UnLoad( DRT_Layer *Layer_Ptr) { + fprintf( stderr, "UnLoading: [%s]\n", Layer_Ptr->FileName); + + + if( Layer_Ptr->Sample_Ptr != NULL) + { + fprintf( stderr, "Freeing Sample!\n"); + free( Layer_Ptr->Sample_Ptr); + } + + if( Layer_Ptr->SF_Info_Ptr != NULL) + { + fprintf( stderr, "Freeing SF_Info!\n"); + free( Layer_Ptr->SF_Info_Ptr); + } + + return( NDS_OK); } @@ -1250,10 +1346,18 @@ DRT_Status DR_Layer_Dump( DRT_Layer *Layer_Ptr, long count) NDT_Status nd_status; - fprintf( stderr, " %03d) Layer: ", count); - fprintf( stderr, " Id: (% 3d) File Name: [%s] Sample: [%lx] Sample Size: (%d) Min: (%f) Max: (%f) Gain: (%f) Pitch: (%f)\n", - Layer_Ptr->Id, Layer_Ptr->FileName, Layer_Ptr->Sample_Ptr, Layer_Ptr->Sample_Size, Layer_Ptr->Min, Layer_Ptr->Max, Layer_Ptr->Gain, Layer_Ptr->Pitch); -// fprintf( stderr, "\n"); + fprintf( stderr, " %03ld) Layer: ", count); + fprintf( stderr, " Id: (% 3d) File Name: [%s] Sample: [%lx] Sample Size: (%ld) Min: (%f) Max: (%f) Gain: (%f) Pitch: (%f)", + Layer_Ptr->Id, Layer_Ptr->FileName, (long)Layer_Ptr->Sample_Ptr, Layer_Ptr->Sample_Size, Layer_Ptr->Min, Layer_Ptr->Max, Layer_Ptr->Gain, Layer_Ptr->Pitch); + + if( Layer_Ptr->SF_Info_Ptr != NULL) + { + fprintf( stderr, " Channels: (%d) Rate: (%d)\n", Layer_Ptr->SF_Info_Ptr->channels, Layer_Ptr->SF_Info_Ptr->samplerate); + } + else + { + fprintf( stderr, "\n"); + } return( DRS_OK); } @@ -1293,7 +1397,7 @@ DRT_Status DR_Instrument_Add( DRT_Instrument **Instrument_Ptr_Ptr, NDT_Root * /*---------------------------------------------------------------------------------*/ -/* DR_Instrument_Dump */ +/* DR_Instrument_Dump */ /*---------------------------------------------------------------------------------*/ DRT_Status DR_Instrument_Dump( DRT_Instrument *Instrument_Ptr, long Count) @@ -1302,7 +1406,7 @@ DRT_Status DR_Instrument_Dump( DRT_Instrument *Instrument_Ptr, long Count) long count2; - fprintf( stderr, " %03d) Instrument: ", Count); + fprintf( stderr, " %03ld) Instrument: ", Count); fprintf( stderr, " Id: (% 3d) Name: [%s] Gain: (%f) Pan Left: (%f) Pan Right: (%f)\n", Instrument_Ptr->Id, Instrument_Ptr->Name, Instrument_Ptr->Gain, Instrument_Ptr->Pan_Left, Instrument_Ptr->Pan_Right); // fprintf( stderr, "\n"); @@ -1363,21 +1467,77 @@ DRT_Status DR_Kit_Add( DRT_Kit **Kit_Ptr_Ptr, NDT_Root *DS_Ptr, DRT_Kit *Kit /*---------------------------------------------------------------------------------*/ -/* DR_Kit_Sample_Load */ +/* DR_Kit_Id_Find */ /*---------------------------------------------------------------------------------*/ -DRT_Status DR_Kit_Sample_Load( DRT_Kit *Kit_Ptr, double SampleRate) +DRT_Status DR_Kit_Id_Find( DRT_Kit **Kit_Ptr_Ptr, NDT_Root *DS_Ptr, DRT_Kit_Id Kit_Id) { + DRT_Status status; NDT_Status nd_status; + DRT_Kit kit_template; + + kit_template.Id = Kit_Id; + kit_template.Name[0] = '\0'; - if( ( nd_status = ND_DataStruct_Traverse( Kit_Ptr->Instrument_DS_Ptr, NDD_CMD_SAMPLE_LOAD, Kit_Ptr, SampleRate)) != NDS_OK) + if( ( nd_status = ND_DataStruct_Value_Find( (void **)Kit_Ptr_Ptr, DS_Ptr, &kit_template)) != NDS_OK) { - printf( "Cant't load kit samples: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); - return( DRS_KO); + fprintf( stderr, "DR_Kit_Id_Find: Find error: (%d)!\n", nd_status); + status = DRS_KO; + } + else + { + if( *Kit_Ptr_Ptr == NULL) + { + fprintf( stderr, "Can't find: Kit with id: (%ld)!\n", Kit_Id); + status = DRS_KO; + } + else + { + status = DRS_OK; + } } - return( DRS_OK); + return( status); +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Kit_Name_Find */ +/*---------------------------------------------------------------------------------*/ + +extern DRT_Status DR_Kit_Name_Find( DRT_Kit **Kit_Ptr_Ptr, NDT_Root *DS_Ptr, char *Kit_Name) +{ + DRT_Status status; + NDT_Status nd_status; + DRT_Kit kit_template; + + + kit_template.Id = 1; + strncpy( kit_template.Name, Kit_Name, NAME_LEN); + + if( ( nd_status = ND_DataStruct_Value_Find( (void **)Kit_Ptr_Ptr, DS_Ptr, &kit_template)) != NDS_OK) + { + fprintf( stderr, "DR_Kit_Name_Find: Find error: (%d)!\n", nd_status); + status = DRS_KO; + } + else + { + if( *Kit_Ptr_Ptr == NULL) + { + fprintf( stderr, "Can't find: Kit with name: [%s]!\n", Kit_Name); + status = DRS_KO; + } + else + { + status = DRS_OK; + } + } + + return( status); } @@ -1395,7 +1555,7 @@ DRT_Status DR_Kit_Dump( DRT_Kit *Kit_Ptr, long Count) - fprintf( stderr, " %03d) DrumKit:", Count); + fprintf( stderr, " %03ld) DrumKit:", Count); fprintf( stderr, " Id: (% 3d) Name: [%s] Descrition: [%.32s] Dir Name: [%s]\n", Kit_Ptr->Id, Kit_Ptr->Name, Kit_Ptr->Desc, Kit_Ptr->DirName); fprintf( stderr, " Instruments List:\n"); @@ -1436,7 +1596,7 @@ DRT_Status DR_XML_Node_Exist( xmlDocPtr Xml_Doc, xmlXPathContextPtr Xml_Xpath long tmpval_len; - if( ( xml_xpathobj = xmlXPathEvalExpression( Xpath_Request, Xml_XpathCtx)) == NULL) + if( ( xml_xpathobj = xmlXPathEvalExpression( (xmlChar *)Xpath_Request, Xml_XpathCtx)) == NULL) { fprintf( stderr, "DR_XML_Node_Exist: xmlXPathEvalExpression failed [%s]!\n", Xpath_Request); status = DRS_KO; @@ -1483,7 +1643,7 @@ DRT_Status DR_XML_Value_Get( char *Value_Ptr, long Max_Len, xmlDocPtr Xml_Do strcpy( xpath_request, Xpath_HeadRequest); strcat( xpath_request, Xpath_TailRequest); - if( ( xml_xpathobj = xmlXPathEvalExpression( xpath_request, Xml_XpathCtx)) == NULL) + if( ( xml_xpathobj = xmlXPathEvalExpression( (xmlChar *)xpath_request, Xml_XpathCtx)) == NULL) { fprintf( stderr, "DR_XML_Value_Get: xmlXPathEvalExpression failed! [%s]\n", xpath_request); status = DRS_KO; @@ -1499,7 +1659,7 @@ DRT_Status DR_XML_Value_Get( char *Value_Ptr, long Max_Len, xmlDocPtr Xml_Do } else { - if( ( tmpval_ptr = xmlNodeListGetString( Xml_Doc, nodeset->nodeTab[0]->xmlChildrenNode, 1)) == NULL) + if( ( tmpval_ptr = (char *)xmlNodeListGetString( Xml_Doc, nodeset->nodeTab[0]->xmlChildrenNode, 1)) == NULL) { fprintf( stderr, "[%s] value not found!\n", xpath_request); status = DRS_KO; @@ -1510,7 +1670,7 @@ DRT_Status DR_XML_Value_Get( char *Value_Ptr, long Max_Len, xmlDocPtr Xml_Do if( ( tmpval_len = strlen( tmpval_ptr)) > Max_Len) { - fprintf( stderr, "Value too long (%d)>(%d)!\n", tmpval_len, Max_Len); + fprintf( stderr, "Value too long (%ld)>(%ld)!\n", tmpval_len, Max_Len); status = DRS_OK; } else @@ -1637,6 +1797,7 @@ DRT_Status DR_Kit_Load( DRT_Base *Base_Ptr, char *FileName) layer_template.Sample_Ptr = NULL; layer_template.Sample_Size = 0; + layer_template.SF_Info_Ptr = NULL; fprintf( stderr, "Loading: [%s]...\n", FileName); @@ -1665,7 +1826,7 @@ DRT_Status DR_Kit_Load( DRT_Base *Base_Ptr, char *FileName) } else { - if( xmlXPathRegisterNs( xml_xpathCtx, "drumkit", "http://www.hydrogen-music.org/drumkit") != 0) + if( xmlXPathRegisterNs( xml_xpathCtx, (xmlChar *)"drumkit", (xmlChar *)"http://www.hydrogen-music.org/drumkit") != 0) { fprintf( stderr,"Error: unable to register default NS!\n"); status = DRS_KO; @@ -1757,6 +1918,152 @@ DRT_Status DR_Kit_Load( DRT_Base *Base_Ptr, char *FileName) +/*---------------------------------------------------------------------------------*/ +/* DR_Kit_Sample_Load */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Kit_Sample_Load( DRT_Kit *Kit_Ptr, double SampleRate) +{ + NDT_Status nd_status; + + + if( ( nd_status = ND_DataStruct_Traverse( Kit_Ptr->Instrument_DS_Ptr, NDD_CMD_SAMPLE_LOAD, Kit_Ptr, SampleRate)) != NDS_OK) + { + printf( "Cant't load kit samples: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); + return( DRS_KO); + } + + return( DRS_OK); +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Kit_Sample_UnLoad */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Kit_Sample_UnLoad( DRT_Kit *Kit_Ptr) +{ + NDT_Status nd_status; + + + if( ( nd_status = ND_DataStruct_Traverse( Kit_Ptr->Instrument_DS_Ptr, NDD_CMD_SAMPLE_UNLOAD, Kit_Ptr)) != NDS_OK) + { + printf( "Cant't unload kit samples: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); + return( DRS_KO); + } + + return( DRS_OK); +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* DR_DataStruct_Init */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_DataStruct_Init( DRT_Base *Base_Ptr, double SampleRate) +{ + NDT_Status nd_status; + + + if( ( nd_status = ND_Library_Open( NDD_TRUE)) != NDS_OK) + { + fprintf( stderr, "Can't open node library (%d) !", nd_status); + return( DRS_KO); + } + + if( ( nd_status = ND_DataStruct_Open( &(Base_Ptr->Kit_DS_Ptr), DRD_KIT_DS_INDEX_NB, DRG_Kit_DS_Index_Tab_Initial, "Kit_Manager", DR_Kit_Manager, NULL, NULL, NULL, NULL, NDD_TRUE, NULL)) != NDS_OK) + { + printf( "Kit_DS: ND_DataStruct_Open() failed (%d) !\n", nd_status); + return( DRS_KO); + } + + Base_Ptr->SampleRate = SampleRate; + + return( DRS_OK); +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* DR_DataStruct_DeInit */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_DataStruct_DeInit( DRT_Base *Base_Ptr) +{ + NDT_Status nd_status; + + + if( ( nd_status = ND_DataStruct_Close( Base_Ptr->Kit_DS_Ptr)) != NDS_OK) + { + printf( "Can't close Kit_DS (%d)!\n", nd_status); + return( DRS_KO); + } + + if( ( nd_status = ND_Library_Close()) != NDS_OK) + { + fprintf( stderr, "Can't close node library (%d)!", nd_status); + return( DRS_KO); + } + + return( DRS_OK); +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Kits_Sample_Load */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Kits_Sample_Load( DRT_Base *Base_Ptr) +{ + NDT_Status nd_status; + + + if( ( nd_status = ND_DataStruct_Traverse( Base_Ptr->Kit_DS_Ptr, NDD_CMD_SAMPLE_LOAD, Base_Ptr->SampleRate)) != NDS_OK) + { + printf( "Cant't load kit samples: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); + return( DRS_KO); + } + + return( DRS_OK); +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Kits_Sample_UnLoad */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Kits_Sample_UnLoad( DRT_Base *Base_Ptr) +{ + NDT_Status nd_status; + + + if( ( nd_status = ND_DataStruct_Traverse( Base_Ptr->Kit_DS_Ptr, NDD_CMD_SAMPLE_UNLOAD, Base_Ptr->SampleRate)) != NDS_OK) + { + printf( "Cant't unload kit samples: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); + return( DRS_KO); + } + + return( DRS_OK); +} + + + + + /*---------------------------------------------------------------------------------*/ /* DR_Kits_Load */ /*---------------------------------------------------------------------------------*/ @@ -1765,9 +2072,10 @@ DRT_Status DR_Kits_Load( DRT_Base *Base_Ptr) { DRT_Status status; NDT_Status nd_status; - char glob_pattern[] = "~/.hydrogen/data/drumkits/*/drumkit.xml"; +// char glob_pattern[] = "~/.hydrogen/data/drumkits/*/drumkit.xml"; // char glob_pattern[] = "~/.hydrogen/data/drumkits/AVL-BlackPearl-4A-1.1/drumkit.xml"; // char glob_pattern[] = "~/.hydrogen/data/drumkits/Mars Lindrum: 02-Kit 2/drumkit.xml"; + char glob_pattern[] = "~/.hydrogen/data/drumkits/Mars Mod */drumkit.xml"; glob_t glob_struct; int i; @@ -1804,7 +2112,7 @@ DRT_Status DR_Kits_Load( DRT_Base *Base_Ptr) globfree( &glob_struct); - Base_Ptr->SampleRate=44100; +// Base_Ptr->SampleRate=44100; /* status = DR_Layer_Sample_Load( (DRT_Layer *)( @@ -1815,15 +2123,14 @@ DRT_Status DR_Kits_Load( DRT_Base *Base_Ptr) (DRT_Kit *)(Base_Ptr->Kit_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head->Value), Base_Ptr->SampleRate); */ /* - status = DR_Kit_Sample_Load( (DRT_Kit *)(Base_Ptr->Kit_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head->Value), - Base_Ptr->SampleRate); + if( Base_Ptr->Kit_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head != NULL) + { + status = DR_Kit_Sample_Load( (DRT_Kit *)(Base_Ptr->Kit_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head->Value), + Base_Ptr->SampleRate); + } */ - if( ( nd_status = ND_DataStruct_Traverse( Base_Ptr->Kit_DS_Ptr, NDD_CMD_SAMPLE_LOAD, Base_Ptr->SampleRate)) != NDS_OK) - { - printf( "Cant't load kit samples: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); - return( DRS_KO); - } + status = DR_Kits_Sample_Load( Base_Ptr); return( status); } @@ -1848,6 +2155,7 @@ DRT_Status DR_Kits_Dump( DRT_Base *Base_Ptr) fprintf( stderr, "\n"); + fprintf( stderr, "Sample Rate: (%lf)\n", Base_Ptr->SampleRate); fprintf( stderr, "DrumKit List:\n"); /* if( ( nd_status = ND_DataStruct_Info_Print( stderr, Base_Ptr->Kit_DS_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0)) != NDS_OK) @@ -1894,59 +2202,3 @@ DRT_Status DR_Kits_Dump( DRT_Base *Base_Ptr) return( DRS_OK); } - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_DataStruct_Init */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_DataStruct_Init( DRT_Base *Base_Ptr) -{ - NDT_Status nd_status; - - - if( ( nd_status = ND_Library_Open( NDD_TRUE)) != NDS_OK) - { - fprintf( stderr, "Can't open node library (%d) !", nd_status); - return( DRS_KO); - } - - if( ( nd_status = ND_DataStruct_Open( &(Base_Ptr->Kit_DS_Ptr), DRD_KIT_DS_INDEX_NB, DRG_Kit_DS_Index_Tab_Initial, "Kit_Manager", DR_Kit_Manager, NULL, NULL, NULL, NULL, NDD_TRUE, NULL)) != NDS_OK) - { - printf( "Kit_DS: ND_DataStruct_Open() failed (%d) !\n", nd_status); - return( DRS_KO); - } - - return( DRS_OK); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_DataStruct_DeInit */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_DataStruct_DeInit( DRT_Base *Base_Ptr) -{ - NDT_Status nd_status; - - - if( ( nd_status = ND_DataStruct_Close( Base_Ptr->Kit_DS_Ptr)) != NDS_OK) - { - printf( "Can't close Kit_DS (%d)!\n", nd_status); - return( DRS_KO); - } - - if( ( nd_status = ND_Library_Close()) != NDS_OK) - { - fprintf( stderr, "Can't close node library (%d)!", nd_status); - return( DRS_KO); - } - - return( DRS_OK); -} diff --git a/datastruct.h b/datastruct.h index 2a79b15..dd380b0 100644 --- a/datastruct.h +++ b/datastruct.h @@ -45,6 +45,10 @@ typedef short DRT_Boolean; #define DESC_LEN (short) 4096 #define DESC_SIZE (DESC_LEN + 1) +typedef long DRT_Layer_Id; +typedef long DRT_Instrument_Id; +typedef long DRT_Kit_Id; + @@ -55,38 +59,38 @@ typedef short DRT_Boolean; typedef struct DRT_Layer { - short Id; - char FileName[ FILENAME_SIZE]; - float *Sample_Ptr; - long Sample_Size; - SF_INFO *SF_Info_Ptr; - double Min; - double Max; - double Gain; - double Pitch; + DRT_Layer_Id Id; + char FileName[ FILENAME_SIZE]; + float *Sample_Ptr; + long Sample_Size; + SF_INFO *SF_Info_Ptr; + double Min; + double Max; + double Gain; + double Pitch; } DRT_Layer; typedef struct DRT_Instrument { - short Id; - char Name[ NAME_SIZE]; - double Gain; - double Pan_Left; - double Pan_Right; - NDT_Root *Layer_DS_Ptr; + DRT_Instrument_Id Id; + char Name[ NAME_SIZE]; + double Gain; + double Pan_Left; + double Pan_Right; + NDT_Root *Layer_DS_Ptr; } DRT_Instrument; typedef struct DRT_Kit { - short Id; - char Name[ NAME_SIZE]; - char Desc[ DESC_SIZE]; - char DirName[ DIRNAME_SIZE]; - NDT_Root *Instrument_DS_Ptr; + DRT_Kit_Id Id; + char Name[ NAME_SIZE]; + char Desc[ DESC_SIZE]; + char DirName[ DIRNAME_SIZE]; + NDT_Root *Instrument_DS_Ptr; } DRT_Kit; @@ -283,6 +287,46 @@ DRT_XML_Query DRG_XML_Query_Tab_Kit[] = /* Public Prototypes */ /*----------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/* DR_Layer_Dump */ +/*----------------------------------------------------------------------------*/ + +extern DRT_Status DR_Layer_Dump( DRT_Layer *, long); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Kit_Id_Find */ +/*---------------------------------------------------------------------------------*/ + +extern DRT_Status DR_Kit_Id_Find( DRT_Kit **, NDT_Root *, DRT_Kit_Id); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Kit_Name_Find */ +/*---------------------------------------------------------------------------------*/ + +extern DRT_Status DR_Kit_Name_Find( DRT_Kit **, NDT_Root *, char *); + + + +/*----------------------------------------------------------------------------*/ +/* DR_Kit_Dump */ +/*----------------------------------------------------------------------------*/ + +extern DRT_Status DR_Kit_Dump( DRT_Kit *, long); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Kit_Load */ +/*---------------------------------------------------------------------------------*/ + +extern DRT_Status DR_Kit_Load( DRT_Base *, char *); + + + /*---------------------------------------------------------------------------------*/ /* DR_Kit_Sample_Load */ /*---------------------------------------------------------------------------------*/ @@ -292,15 +336,47 @@ extern DRT_Status DR_Kit_Sample_Load( DRT_Kit *, double); /*---------------------------------------------------------------------------------*/ -/* DR_Kit_Load */ +/* DR_Kit_Sample_UnLoad */ /*---------------------------------------------------------------------------------*/ -extern DRT_Status DR_Kit_Load( DRT_Base *, char *); +extern DRT_Status DR_Kit_Sample_UnLoad( DRT_Kit *); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_DataStruct_Init */ +/*---------------------------------------------------------------------------------*/ + +extern DRT_Status DR_DataStruct_Init( DRT_Base *, double); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_DataStruct_DeInit */ +/*---------------------------------------------------------------------------------*/ + +extern DRT_Status DR_DataStruct_DeInit( DRT_Base *); /*----------------------------------------------------------------------------*/ -/* DR_Kits_Load */ +/* DR_Kits_Sample_Load */ +/*----------------------------------------------------------------------------*/ + +extern DRT_Status DR_Kits_Sample_Load( DRT_Base *); + + + +/*----------------------------------------------------------------------------*/ +/* DR_Kits_Sample_UnLoad */ +/*----------------------------------------------------------------------------*/ + +extern DRT_Status DR_Kits_Sample_UnLoad( DRT_Base *); + + + +/*----------------------------------------------------------------------------*/ +/* DR_Kits_Load */ /*----------------------------------------------------------------------------*/ extern DRT_Status DR_Kits_Load( DRT_Base *); @@ -315,22 +391,6 @@ extern DRT_Status DR_Kits_Dump( DRT_Base *); -/*---------------------------------------------------------------------------------*/ -/* DR_DataStruct_Init */ -/*---------------------------------------------------------------------------------*/ - -extern DRT_Status DR_DataStruct_Init( DRT_Base *); - - - -/*---------------------------------------------------------------------------------*/ -/* DR_DataStruct_DeInit */ -/*---------------------------------------------------------------------------------*/ - -extern DRT_Status DR_DataStruct_DeInit( DRT_Base *); - - - # else // ifndef _DATA_STRUCT_C_ @@ -406,10 +466,18 @@ DRT_Status DR_Kit_Add( DRT_Kit **, NDT_Root *, DRT_Kit *); /*---------------------------------------------------------------------------------*/ -/* DR_Kit_Sample_Load */ +/* DR_Kit_Id_Find */ /*---------------------------------------------------------------------------------*/ -DRT_Status DR_Kit_Sample_Load( DRT_Kit *, double); +DRT_Status DR_Kit_Id_Find( DRT_Kit **, NDT_Root *, DRT_Kit_Id); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Kit_Name_Find */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Kit_Name_Find( DRT_Kit **, NDT_Root *, char *); @@ -453,8 +521,56 @@ DRT_Status DR_Kit_Load( DRT_Base *, char *); +/*---------------------------------------------------------------------------------*/ +/* DR_Kit_Sample_Load */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Kit_Sample_Load( DRT_Kit *, double); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Kit_Sample_UnLoad */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Kit_Sample_UnLoad( DRT_Kit *); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_DataStruct_Init */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_DataStruct_Init( DRT_Base *, double); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_DataStruct_DeInit */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_DataStruct_DeInit( DRT_Base *); + + + /*----------------------------------------------------------------------------*/ -/* DR_Kits_Load */ +/* DR_Kits_Sample_Load */ +/*----------------------------------------------------------------------------*/ + +DRT_Status DR_Kits_Sample_Load( DRT_Base *); + + + +/*----------------------------------------------------------------------------*/ +/* DR_Kits_Sample_UnLoad */ +/*----------------------------------------------------------------------------*/ + +DRT_Status DR_Kits_Sample_UnLoad( DRT_Base *); + + + +/*----------------------------------------------------------------------------*/ +/* DR_Kits_Load */ /*----------------------------------------------------------------------------*/ DRT_Status DR_Kits_Load( DRT_Base *); @@ -469,20 +585,6 @@ DRT_Status DR_Kits_Dump( DRT_Base *); -/*---------------------------------------------------------------------------------*/ -/* DR_DataStruct_Init */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_DataStruct_Init( DRT_Base *); - - - -/*---------------------------------------------------------------------------------*/ -/* DR_DataStruct_DeInit */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_DataStruct_DeInit( DRT_Base *); - # endif // ifndef _DATASTRUCT_C_ diff --git a/drummer.c b/drummer.c index bfb7300..441d835 100644 --- a/drummer.c +++ b/drummer.c @@ -2,7 +2,7 @@ /* Includes */ /*---------------------------------------------------------------------------------*/ -#define _IMRD_C_ +#define _DRUMMER_C_ @@ -12,1865 +12,22 @@ -/*---------------------------------------------------------------------------------*/ -/* */ -/*---------------------------------------------------------------------------------*/ - -NDT_Status DR_Layer_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Command, va_list *Args_Ptr) -{ - NDT_Command_Name Command_Name; - - - switch( Command) - { - case NDD_CMD_MANAGER_VERSION: - { - ND_VA_ARG_GET( Version_Name_Ptr, *Args_Ptr, NDT_Version_Name *); - - - Command_Name = "NDD_CMD_MANAGER_VERSION"; - - *Version_Name_Ptr = "$Revision: 1.0 $ $Name: Layer_Manager $ $Date: 2021/12/12 21:27:12 $ $Author: agibert $"; - - return( NDS_OK); - } - - case NDD_CMD_INDEX_GET: - { - ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *); - ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *); - ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command); - ND_VA_ARG_GET( Layer_Ptr, *Args_Ptr, DRT_Layer *); - - - Command_Name = "NDD_CMD_INDEX_GET"; - - switch(Cmd) - { - case NDD_CMD_INDEX0_PRINT: - { - *Reply_Index_Id_Ptr = 0; - *Reply_Command_Ptr = Cmd; - break; - } - - case NDD_CMD_INDEX1_PRINT: - { - *Reply_Index_Id_Ptr = 1; - *Reply_Command_Ptr = Cmd; - break; - } - - default: - { - *Reply_Index_Id_Ptr = Index_Id; - *Reply_Command_Ptr = Cmd; - break; - } - } - - return( NDS_OK); - } - - case NDD_CMD_VALUE_ALLOC: - { - ND_VA_ARG_GET( Layer_Ptr_Ptr, *Args_Ptr, DRT_Layer **); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - ND_VA_ARG_GET( Layer_Template_Ptr, user_args, DRT_Layer *); - - ND_VA_LIST_CLOSE( user_args); - - - Command_Name = "NDD_CMD_VALUE_ALLOC"; - - if( ( *Layer_Ptr_Ptr = (DRT_Layer *)malloc( sizeof( DRT_Layer))) != NULL) - { - ( *Layer_Ptr_Ptr)->Id = Root_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; - - strncpy( ( *Layer_Ptr_Ptr)->FileName, Layer_Template_Ptr->FileName, FILENAME_SIZE); - - ( *Layer_Ptr_Ptr)->Sample_Ptr = Layer_Template_Ptr->Sample_Ptr; - ( *Layer_Ptr_Ptr)->Sample_Size = Layer_Template_Ptr->Sample_Size; - ( *Layer_Ptr_Ptr)->Min = Layer_Template_Ptr->Min; - ( *Layer_Ptr_Ptr)->Max = Layer_Template_Ptr->Max; - ( *Layer_Ptr_Ptr)->Gain = Layer_Template_Ptr->Gain; - ( *Layer_Ptr_Ptr)->Pitch = Layer_Template_Ptr->Pitch; - - return( NDS_OK); - } - else - { - return( NDS_KO); - } - } - - case NDD_CMD_VALUE_FREE: - { - ND_VA_ARG_GET( Layer_Ptr, *Args_Ptr, DRT_Layer *); - - - Command_Name = "NDD_CMD_VALUE_FREE"; - - - free( Layer_Ptr); - - return( NDS_OK); - } - - case NDD_CMD_VALUE_COMP: - { - ND_VA_ARG_GET( Layer1_Ptr, *Args_Ptr, DRT_Layer *); - ND_VA_ARG_GET( Layer2_Ptr, *Args_Ptr, DRT_Layer *); - - long rc; - - - Command_Name = "NDD_CMD_VALUE_COMP"; - - switch( Index_Id) - { - case 0: - { - rc = Layer1_Ptr->Id - Layer2_Ptr->Id; - break; - } - - case 1: - { - rc = strcmp( Layer1_Ptr->FileName, Layer2_Ptr->FileName); - break; - } - - default: - { - printf( "Unknown COMP idx (%d) !\n", Index_Id); - return( NDS_KO); - } - } - - if( rc < 0) - { - return( NDS_LOWER); - } - else - { - if( rc > 0) - { - return( NDS_GREATER); - } - else - { - return( NDS_EQUAL); - } - } - } - - case NDD_CMD_VALUE_ADD: - { - /* - ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - - - Command_Name = "NDD_CMD_VALUE_ADD"; - - return( NDS_OK); - } - - case NDD_CMD_VALUE_REMOVE: - { - /* - ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - - - Command_Name = "NDD_CMD_VALUE_REMOVE"; - - return( NDS_OK); - } - - case NDD_CMD_VALUE_PRINT: - { - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( lib_args, *Args_Ptr); - - ND_VA_ARG_GET( Out, lib_args, FILE *); - ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode); - ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth); - ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset); - - ND_VA_LIST_OPEN( user_args, lib_args); - - ND_VA_ARG_GET( Count_Ptr, user_args, long *); - - ND_VA_LIST_CLOSE( user_args); - ND_VA_LIST_CLOSE( lib_args); - - DRT_Layer *Layer_Ptr = Node_Ptr->Value; - - - Command_Name = "NDD_CMD_VALUE_PRINT"; - - if( DR_Layer_Dump( Layer_Ptr, ++(*Count_Ptr)) != DRS_OK) - { - return( NDS_KO); - } - else - { - return( NDS_OK); - } - } - - case NDD_CMD_INFO_PRINT: - { - Command_Name = "NDD_CMD_INFO_PRINT"; - - return( NDS_OK); - - } - - case NDD_CMD_INDEX0_PRINT: - case NDD_CMD_INDEX1_PRINT: - { - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( Out, user_args, FILE *); - ND_VA_ARG_GET( Count_Ptr, user_args, long *); - - ND_VA_LIST_CLOSE( user_args); - - DRT_Layer *Layer_Ptr = Node_Ptr->Value; - - - Command_Name = "NDD_CMD_INDEX_PRINT"; - - if( DR_Layer_Dump( Layer_Ptr, ++(*Count_Ptr)) != DRS_OK) - { - return( NDS_KO); - } - else - { - return( NDS_OK); - } - } - - case NDD_CMD_SAMPLE_LOAD: - { - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( Kit_Ptr, user_args, DRT_Kit *); - ND_VA_ARG_GET( SampleRate, user_args, double); - - ND_VA_LIST_CLOSE( user_args); - - DRT_Layer *Layer_Ptr = Node_Ptr->Value; - - - Command_Name = "NDD_CMD_SAMPLE_LOAD"; - - if( DR_Layer_Sample_Load( Layer_Ptr, Kit_Ptr, SampleRate) != DRS_OK) - { - return( NDS_KO); - } - else - { - return( NDS_OK); - } - } - - default: - { - printf( "Layer_Manager() called with an undefined command %d\n", Command); - return( NDS_ERRAPI); - - } - } - - printf( "Layer_Manager() called with command %d (%s)\n", Command, Command_Name); - return( NDS_OK); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* */ -/*---------------------------------------------------------------------------------*/ - -NDT_Status DR_Instrument_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Command, va_list *Args_Ptr) -{ - NDT_Command_Name Command_Name; - - - switch( Command) - { - case NDD_CMD_MANAGER_VERSION: - { - ND_VA_ARG_GET( Version_Name_Ptr, *Args_Ptr, NDT_Version_Name *); - - - Command_Name = "NDD_CMD_MANAGER_VERSION"; - - *Version_Name_Ptr = "$Revision: 1.0 $ $Name: Instrument_Manager $ $Date: 2021/12/12 21:27:12 $ $Author: agibert $"; - - return( NDS_OK); - } - - case NDD_CMD_INDEX_GET: - { - ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *); - ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *); - ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command); - ND_VA_ARG_GET( Instrument_Ptr, *Args_Ptr, DRT_Instrument *); - - - Command_Name = "NDD_CMD_INDEX_GET"; - - switch(Cmd) - { - case NDD_CMD_INDEX0_PRINT: - { - *Reply_Index_Id_Ptr = 0; - *Reply_Command_Ptr = Cmd; - break; - } - - case NDD_CMD_INDEX1_PRINT: - { - *Reply_Index_Id_Ptr = 1; - *Reply_Command_Ptr = Cmd; - break; - } - - default: - { - *Reply_Index_Id_Ptr = Index_Id; - *Reply_Command_Ptr = Cmd; - break; - } - } - - return( NDS_OK); - } - - case NDD_CMD_VALUE_ALLOC: - { - ND_VA_ARG_GET( Instrument_Ptr_Ptr, *Args_Ptr, DRT_Instrument **); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - ND_VA_ARG_GET( Instrument_Template_Ptr, user_args, DRT_Instrument *); - - ND_VA_LIST_CLOSE( user_args); - - NDT_Status nd_status; - - - Command_Name = "NDD_CMD_VALUE_ALLOC"; - - if( ( *Instrument_Ptr_Ptr = (DRT_Instrument *)malloc( sizeof( DRT_Instrument))) != NULL) - { - ( *Instrument_Ptr_Ptr)->Id = Root_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; - - strncpy( ( *Instrument_Ptr_Ptr)->Name, Instrument_Template_Ptr->Name, NAME_SIZE); - - ( *Instrument_Ptr_Ptr)->Gain = Instrument_Template_Ptr->Gain; - ( *Instrument_Ptr_Ptr)->Pan_Left = Instrument_Template_Ptr->Pan_Left; - ( *Instrument_Ptr_Ptr)->Pan_Right = Instrument_Template_Ptr->Pan_Right; - - - if( ( nd_status = ND_DataStruct_Open( &((*Instrument_Ptr_Ptr)->Layer_DS_Ptr), DRD_LAYER_DS_INDEX_NB, DRG_Layer_DS_Index_Tab_Initial, "Layer_Manager", DR_Layer_Manager, NULL, NULL, NULL, NULL, NDD_TRUE, NULL)) != NDS_OK) - { - printf( "DR_Instrument_Manager: ND_DataStruct_Open() failed (%d) !\n", nd_status); - return( NDS_KO); - } - else - { - return( NDS_OK); - } - } - else - { - return( NDS_KO); - } - } - - case NDD_CMD_VALUE_FREE: - { - ND_VA_ARG_GET( Instrument_Ptr, *Args_Ptr, DRT_Instrument *); - - NDT_Status nd_status; - - - Command_Name = "NDD_CMD_VALUE_FREE"; - - if( ( nd_status = ND_DataStruct_Close( Instrument_Ptr->Layer_DS_Ptr)) != NDS_OK) - { - printf( "DR_Instrument_Manager: Can't close Kit_DS (%d)!\n", nd_status); - return( DRS_KO); - } - - free( Instrument_Ptr); - - return( NDS_OK); - } - - case NDD_CMD_VALUE_COMP: - { - ND_VA_ARG_GET( Instrument1_Ptr, *Args_Ptr, DRT_Instrument *); - ND_VA_ARG_GET( Instrument2_Ptr, *Args_Ptr, DRT_Instrument *); - - long rc; - - - Command_Name = "NDD_CMD_VALUE_COMP"; - - switch( Index_Id) - { - case 0: - { - rc = Instrument1_Ptr->Id - Instrument2_Ptr->Id; - break; - } - - case 1: - { - rc = strcmp( Instrument1_Ptr->Name, Instrument2_Ptr->Name); - break; - } - - default: - { - printf( "Unknown COMP idx (%d) !\n", Index_Id); - return( NDS_KO); - } - } - - if( rc < 0) - { - return( NDS_LOWER); - } - else - { - if( rc > 0) - { - return( NDS_GREATER); - } - else - { - return( NDS_EQUAL); - } - } - } - - case NDD_CMD_VALUE_ADD: - { - /* - ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - - - Command_Name = "NDD_CMD_VALUE_ADD"; - - return( NDS_OK); - } - - case NDD_CMD_VALUE_REMOVE: - { - /* - ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - - - Command_Name = "NDD_CMD_VALUE_REMOVE"; - - return( NDS_OK); - } - - case NDD_CMD_VALUE_PRINT: - { - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( lib_args, *Args_Ptr); - - ND_VA_ARG_GET( Out, lib_args, FILE *); - ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode); - ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth); - ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset); - - ND_VA_LIST_OPEN( user_args, lib_args); - - ND_VA_ARG_GET( Count_Ptr, user_args, long *); - - ND_VA_LIST_CLOSE( user_args); - ND_VA_LIST_CLOSE( lib_args); - - DRT_Instrument *Instrument_Ptr = Node_Ptr->Value; - - - Command_Name = "NDD_CMD_VALUE_PRINT"; - - if( DR_Instrument_Dump( Instrument_Ptr, ++(*Count_Ptr)) != DRS_OK) - { - return( NDS_KO); - } - else - { - return( NDS_OK); - } - } - - case NDD_CMD_INFO_PRINT: - { - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( lib_args, *Args_Ptr); - - ND_VA_ARG_GET( Out, lib_args, FILE *); - ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode); - ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth); - ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset); - - ND_VA_LIST_CLOSE( lib_args); - - NDT_Status nd_status; - DRT_Instrument *Instrument_Ptr = Node_Ptr->Value; - - - Command_Name = "NDD_CMD_INFO_PRINT"; - - if( ( nd_status = ND_DataStruct_Info_Print( Out, Instrument_Ptr->Layer_DS_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0)) != NDS_OK) - { - printf( "DR_Instrument_Manager: ND_DataStruct_Info_Print() failed (%d) !\n", nd_status); - return( DRS_KO); - } - - return( NDS_OK); - } - - case NDD_CMD_INDEX0_PRINT: - case NDD_CMD_INDEX1_PRINT: - { - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( Out, user_args, FILE *); - ND_VA_ARG_GET( Count_Ptr, user_args, long *); - - ND_VA_LIST_CLOSE( user_args); - - DRT_Instrument *Instrument_Ptr = Node_Ptr->Value; - - - Command_Name = "NDD_CMD_INDEX_PRINT"; - - if( DR_Instrument_Dump( Instrument_Ptr, ++(*Count_Ptr)) != DRS_OK) - { - return( NDS_KO); - } - else - { - return( NDS_OK); - } - } - - case NDD_CMD_STATS_GET: - { - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( Instruments_Count_Ptr, user_args, long *); - ND_VA_ARG_GET( Layers_Count_Ptr, user_args, long *); - - ND_VA_LIST_CLOSE( user_args); - - DRT_Instrument *Instrument_Ptr = Node_Ptr->Value; - - - Command_Name = "NDD_CMD_STATS_GET"; - - (*Instruments_Count_Ptr)++; - (*Layers_Count_Ptr) += Instrument_Ptr->Layer_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; - - return( NDS_OK); - } - - case NDD_CMD_SAMPLE_LOAD: - { - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( Kit_Ptr, user_args, DRT_Kit *); - ND_VA_ARG_GET( SampleRate, user_args, double); - - ND_VA_LIST_CLOSE( user_args); - - DRT_Instrument *Instrument_Ptr = Node_Ptr->Value; - - Command_Name = "NDD_CMD_SAMPLE_LOAD"; - - return( ND_DataStruct_Traverse( Instrument_Ptr->Layer_DS_Ptr, NDD_CMD_SAMPLE_LOAD, Kit_Ptr, SampleRate)); - } - - default: - { - printf( "Instrument_Manager() called with an undefined command %d\n", Command); - return( NDS_ERRAPI); - - } - } - - printf( "Instrument_Manager() called with command %d (%s)\n", Command, Command_Name); - return( NDS_OK); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* */ -/*---------------------------------------------------------------------------------*/ - -NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Command, va_list *Args_Ptr) -{ - NDT_Command_Name Command_Name; - - - switch( Command) - { - case NDD_CMD_MANAGER_VERSION: - { - ND_VA_ARG_GET( Version_Name_Ptr, *Args_Ptr, NDT_Version_Name *); - - - Command_Name = "NDD_CMD_MANAGER_VERSION"; - - *Version_Name_Ptr = "$Revision: 1.0 $ $Name: Kit_Manager $ $Date: 2021/12/12 21:27:12 $ $Author: agibert $"; - - return( NDS_OK); - } - - case NDD_CMD_INDEX_GET: - { - ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *); - ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *); - ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command); - ND_VA_ARG_GET( Kit_Ptr, *Args_Ptr, DRT_Kit *); - - - Command_Name = "NDD_CMD_INDEX_GET"; - - switch(Cmd) - { - /* - case NDT_CMD_SOME_USER_CMD: - { - *Reply_Index_Id_Ptr = 0; - *Reply_Command_Ptr = NDD_CMD_SOME_OTHER_CMD; - break; - } - ... - */ - - case NDD_CMD_INDEX0_PRINT: - { - *Reply_Index_Id_Ptr = 0; - *Reply_Command_Ptr = Cmd; - break; - } - - case NDD_CMD_VALUE_PRINT: - case NDD_CMD_INDEX1_PRINT: - { - *Reply_Index_Id_Ptr = 1; - *Reply_Command_Ptr = Cmd; - break; - } - - default: - { - *Reply_Index_Id_Ptr = Index_Id; - *Reply_Command_Ptr = Cmd; - break; - } - } - - return( NDS_OK); - } - - case NDD_CMD_VALUE_ALLOC: - { - ND_VA_ARG_GET( Kit_Ptr_Ptr, *Args_Ptr, DRT_Kit **); - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - ND_VA_ARG_GET( Kit_Template_Ptr, user_args, DRT_Kit *); - ND_VA_LIST_CLOSE( user_args); - - NDT_Status nd_status; - - - Command_Name = "NDD_CMD_VALUE_ALLOC"; - - if( ( *Kit_Ptr_Ptr = (DRT_Kit *)malloc( sizeof( DRT_Kit))) != NULL) - { - ( *Kit_Ptr_Ptr)->Id = Root_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; - - strncpy( ( *Kit_Ptr_Ptr)->Name, Kit_Template_Ptr->Name, NAME_SIZE); - strncpy( ( *Kit_Ptr_Ptr)->Desc, Kit_Template_Ptr->Desc, DESC_SIZE); - strncpy( ( *Kit_Ptr_Ptr)->DirName, Kit_Template_Ptr->DirName, DIRNAME_SIZE); - - if( ( nd_status = ND_DataStruct_Open( &((*Kit_Ptr_Ptr)->Instrument_DS_Ptr), DRD_INSTRUMENT_DS_INDEX_NB, DRG_Instrument_DS_Index_Tab_Initial, "Instrument_Manager", DR_Instrument_Manager, NULL, NULL, NULL, NULL, NDD_TRUE, NULL)) != NDS_OK) - { - printf( "DR_Kit_Manager: ND_DataStruct_Open() failed (%d) !\n", nd_status); - return( NDS_KO); - } - - return( NDS_OK); - } - else - { - return( NDS_KO); - } - } - - case NDD_CMD_VALUE_FREE: - { - ND_VA_ARG_GET( Kit_Ptr, *Args_Ptr, DRT_Kit *); - - NDT_Status nd_status; - - - Command_Name = "NDD_CMD_VALUE_FREE"; - - if( ( nd_status = ND_DataStruct_Close( Kit_Ptr->Instrument_DS_Ptr)) != NDS_OK) - { - printf( "DR_Kit_Manager: Can't close Kit_DS (%d)!\n", nd_status); - return( DRS_KO); - } - - free( Kit_Ptr); - - return( NDS_OK); - } - - case NDD_CMD_VALUE_COMP: - { - ND_VA_ARG_GET( Kit1_Ptr, *Args_Ptr, DRT_Kit *); - ND_VA_ARG_GET( Kit2_Ptr, *Args_Ptr, DRT_Kit *); - - long rc; - - - Command_Name = "NDD_CMD_VALUE_COMP"; - - switch( Index_Id) - { - case 0: - { - rc = Kit1_Ptr->Id - Kit2_Ptr->Id; - break; - } - - case 1: - { - rc = strcmp( Kit1_Ptr->Name, Kit2_Ptr->Name); - break; - } - - default: - { - printf( "Unknown COMP idx (%d) !\n", Index_Id); - return( NDS_KO); - } - } - - if( rc < 0) - { - return( NDS_LOWER); - } - else - { - if( rc > 0) - { - return( NDS_GREATER); - } - else - { - return( NDS_EQUAL); - } - } - } - - case NDD_CMD_VALUE_ADD: - { - /* - ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - - - Command_Name = "NDD_CMD_VALUE_ADD"; - - return( NDS_OK); - } - - case NDD_CMD_VALUE_REMOVE: - { - /* - ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - - - Command_Name = "NDD_CMD_VALUE_REMOVE"; - - return( NDS_OK); - } - - case NDD_CMD_VALUE_PRINT: - { - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( lib_args, *Args_Ptr); - - ND_VA_ARG_GET( Out, lib_args, FILE *); - ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode); - ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth); - ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset); - - ND_VA_LIST_OPEN( user_args, lib_args); - - ND_VA_ARG_GET( Count_Ptr, user_args, long *); - - ND_VA_LIST_CLOSE( user_args); - ND_VA_LIST_CLOSE( lib_args); - - DRT_Kit *Kit_Ptr = Node_Ptr->Value; - - - Command_Name = "NDD_CMD_VALUE_PRINT"; - - if( DR_Kit_Dump( Kit_Ptr, ++(*Count_Ptr)) != DRS_OK) - { - return( NDS_KO); - } - else - { - return( NDS_OK); - } - } - - case NDD_CMD_INFO_PRINT: - { - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( lib_args, *Args_Ptr); - - ND_VA_ARG_GET( Out, lib_args, FILE *); - ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode); - ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth); - ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset); - - ND_VA_LIST_CLOSE( lib_args); - - NDT_Status nd_status; - DRT_Kit *Kit_Ptr = Node_Ptr->Value; - - - Command_Name = "NDD_CMD_INFO_PRINT"; - - if( ( nd_status = ND_DataStruct_Info_Print( Out, Kit_Ptr->Instrument_DS_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0)) != NDS_OK) - { - printf( "DR_Kit_Manager: ND_DataStruct_Info_Print() failed (%d) !\n", nd_status); - return( DRS_KO); - } - - return( NDS_OK); - } - - case NDD_CMD_INDEX0_PRINT: - case NDD_CMD_INDEX1_PRINT: - { - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( Out, user_args, FILE *); - ND_VA_ARG_GET( Count_Ptr, user_args, long *); - - ND_VA_LIST_CLOSE( user_args); - - DRT_Kit *Kit_Ptr = Node_Ptr->Value; - - - Command_Name = "NDD_CMD_INDEX_PRINT"; - - if( DR_Kit_Dump( Kit_Ptr, ++(*Count_Ptr)) != DRS_OK) - { - return( NDS_KO); - } - else - { - return( NDS_OK); - } - } - - case NDD_CMD_STATS_GET: - { - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( Kits_Count_Ptr, user_args, long *); - ND_VA_ARG_GET( Instruments_Count_Ptr, user_args, long *); - ND_VA_ARG_GET( Layers_Count_Ptr, user_args, long *); - - ND_VA_LIST_CLOSE( user_args); - - DRT_Kit *Kit_Ptr = Node_Ptr->Value; - - - Command_Name = "NDD_CMD_STATS_GET"; - - (*Kits_Count_Ptr)++; - - return( ND_DataStruct_Traverse( Kit_Ptr->Instrument_DS_Ptr, NDD_CMD_STATS_GET, Instruments_Count_Ptr, Layers_Count_Ptr)); - } - - case NDD_CMD_SAMPLE_LOAD: - { - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( SampleRate, user_args, double); - - ND_VA_LIST_CLOSE( user_args); - - DRT_Kit *Kit_Ptr = Node_Ptr->Value; - - - Command_Name = "NDD_CMD_SAMPLE_LOAD"; - - return( ND_DataStruct_Traverse( Kit_Ptr->Instrument_DS_Ptr, NDD_CMD_SAMPLE_LOAD, Kit_Ptr, SampleRate)); - } - -/* - case NDD_CMD_PHONEBOOK_SAVE: - { - /* - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ /* - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( Out, user_args, FILE *); - ND_VA_ARG_GET( Count_Ptr, user_args, long *); - - ND_VA_LIST_CLOSE( user_args); - - DRT_Kit *Kit_Ptr = Node_Ptr->Value; - - - Command_Name = "NDD_CMD_PHONEBOOK_SAVE"; - - fprintf( Out, "%s:%s:%s:%s\n", Kit_Ptr->Number, Kit_Ptr->Name, Kit_Ptr->Address, Kit_Ptr->Email); - (*Count_Ptr)++; - - return( NDS_OK); - } -*/ - default: - { - printf( "Kit_Manager() called with an undefined command %d\n", Command); - return( NDS_ERRAPI); - } - } - - printf( "Kit_Manager() called with command %d (%s)\n", Command, Command_Name); - return( NDS_OK); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Layer_Add */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Layer_Add( DRT_Layer **Layer_Ptr_Ptr, NDT_Root *DS_Ptr, DRT_Layer *Layer_Template_Ptr) -{ - NDT_Status nd_status; - - - if( ( nd_status = ND_Value_Alloc( DS_Ptr, (void **)Layer_Ptr_Ptr, Layer_Template_Ptr)) != NDS_OK) - { - printf( "Can't allocate new layer: ND_Value_Alloc() failed (%d) !\n", nd_status); - return( DRS_KO); - } - else - { - if( ( nd_status = ND_DataStruct_Value_Add( DS_Ptr, (void *)*Layer_Ptr_Ptr)) != NDS_OK) - { - printf( "Can't add new layer: ND_Value_Add() failed (%d) !\n", nd_status); - return( DRS_KO); - } - } - - return( DRS_OK); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Layer_Sample_Load */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr, DRT_Kit *Kit_Ptr, double SampleRate) -{ - DRT_Status status; - SNDFILE *sndf_ptr; - -// int load_sample(char* path, drmr_layer* layer, double target_rate) { -// long size; - - - fprintf( stderr, "Loading: [%s]\n", Layer_Ptr->FileName); - - if( ( Layer_Ptr->SF_Info_Ptr = malloc( sizeof(SF_INFO))) == NULL) - { - fprintf( stderr, "Can't allocate SF_Info buffer !\n"); - return( DRS_KO); - } - - if( ( sndf_ptr = sf_open( Layer_Ptr->FileName, SFM_READ, Layer_Ptr->SF_Info_Ptr)) == NULL) - { - fprintf( stderr, "Can't open sample file [%s] (%d)!\n", Layer_Ptr->FileName, sf_strerror( (SNDFILE *)( Layer_Ptr->Sample_Ptr))); - status = DRS_KO; - } - else - { - if( Layer_Ptr->SF_Info_Ptr->channels > 2) - { - fprintf(stderr, "Too many channels: Can only handle mono / stereo samples!\n"); - status = DRS_KO; - } - else - { - Layer_Ptr->Sample_Size = Layer_Ptr->SF_Info_Ptr->frames * Layer_Ptr->SF_Info_Ptr->channels * sizeof( float); - - if( ( Layer_Ptr->Sample_Ptr = malloc( Layer_Ptr->Sample_Size)) == NULL) - { - fprintf(stderr,"Can't allocate sample memory: (%d) for [%s]!\n", Layer_Ptr->Sample_Size, Layer_Ptr->FileName); - status = DRS_KO; - } - else - { - sf_read_float( sndf_ptr, Layer_Ptr->Sample_Ptr, ( Layer_Ptr->Sample_Size / sizeof( float))); - - status = DRS_OK; - - // convert rate if needed - if( Layer_Ptr->SF_Info_Ptr->samplerate != SampleRate) - { - int src_status; - SRC_DATA src_data; - long out_size; - float *data_out; - - - src_data.data_in = Layer_Ptr->Sample_Ptr; - src_data.input_frames = Layer_Ptr->SF_Info_Ptr->frames; - src_data.src_ratio = SampleRate / Layer_Ptr->SF_Info_Ptr->samplerate; - src_data.output_frames = (long)ceil( Layer_Ptr->SF_Info_Ptr->frames * src_data.src_ratio); - - out_size = src_data.output_frames * Layer_Ptr->SF_Info_Ptr->channels * sizeof( float); - - if( ( src_data.data_out = malloc( out_size)) == NULL) - { - fprintf(stderr,"Can't allocate resample memory: (%d) for [%s]!\n", out_size, Layer_Ptr->FileName); - status = DRS_KO; - } - else - { - - if( ( src_status = src_simple( &src_data, RATE_CONV_QUALITY, Layer_Ptr->SF_Info_Ptr->channels)) != 0) - { - fprintf( stderr,"Can't convert rate for [%s]: [%s]\n", Layer_Ptr->FileName, src_strerror( src_status)); - } - else - { - if( src_data.input_frames_used != Layer_Ptr->SF_Info_Ptr->frames) - { - fprintf(stderr,"Didn't consume all input frames. used: %li had: %li gened: %li\n", - src_data.input_frames_used, Layer_Ptr->SF_Info_Ptr->frames, src_data.output_frames_gen); - } - - free( Layer_Ptr->Sample_Ptr); - - Layer_Ptr->Sample_Ptr = data_out; - Layer_Ptr->Sample_Size = src_data.output_frames_gen * Layer_Ptr->SF_Info_Ptr->channels * sizeof( float); - Layer_Ptr->SF_Info_Ptr->samplerate = SampleRate; - Layer_Ptr->SF_Info_Ptr->frames = src_data.output_frames_gen; - } - - free( data_out); - } - } - } - } - - sf_close( sndf_ptr); - } - - free( Layer_Ptr->SF_Info_Ptr); - - return( status); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Layer_Sample_UnLoad */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Layer_Sample_UnLoad( DRT_Layer *Layer_Ptr) -{ -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Layer_Dump */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Layer_Dump( DRT_Layer *Layer_Ptr, long count) -{ - NDT_Status nd_status; - - - fprintf( stderr, " %03d) Layer: ", count); - fprintf( stderr, " Id: (% 3d) File Name: [%s] Sample: [%lx] Sample Size: (%d) Min: (%f) Max: (%f) Gain: (%f) Pitch: (%f)\n", - Layer_Ptr->Id, Layer_Ptr->FileName, Layer_Ptr->Sample_Ptr, Layer_Ptr->Sample_Size, Layer_Ptr->Min, Layer_Ptr->Max, Layer_Ptr->Gain, Layer_Ptr->Pitch); -// fprintf( stderr, "\n"); - - return( DRS_OK); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Instrument_Add */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Instrument_Add( DRT_Instrument **Instrument_Ptr_Ptr, NDT_Root *DS_Ptr, DRT_Instrument *Instrument_Template_Ptr) -{ - NDT_Status nd_status; - - - if( ( nd_status = ND_Value_Alloc( DS_Ptr, (void **)Instrument_Ptr_Ptr, Instrument_Template_Ptr)) != NDS_OK) - { - printf( "Can't allocate new instrument: ND_Value_Alloc() failed (%d) !\n", nd_status); - return( DRS_KO); - } - else - { - if( ( nd_status = ND_DataStruct_Value_Add( DS_Ptr, (void *)*Instrument_Ptr_Ptr)) != NDS_OK) - { - printf( "Can't add new instrument: ND_Value_Add() failed (%d) !\n", nd_status); - return( DRS_KO); - } - } - - return( DRS_OK); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Instrument_Dump */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Instrument_Dump( DRT_Instrument *Instrument_Ptr, long Count) -{ - NDT_Status nd_status; - long count2; - - - fprintf( stderr, " %03d) Instrument: ", Count); - fprintf( stderr, " Id: (% 3d) Name: [%s] Gain: (%f) Pan Left: (%f) Pan Right: (%f)\n", - Instrument_Ptr->Id, Instrument_Ptr->Name, Instrument_Ptr->Gain, Instrument_Ptr->Pan_Left, Instrument_Ptr->Pan_Right); -// fprintf( stderr, "\n"); - fprintf( stderr, " Layer List:\n"); - - if( Instrument_Ptr->Layer_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number == 0) - { - fprintf( stderr, " Empty list!\n"); - } - else - { - count2 = 0; - - if( ( nd_status = ND_DataStruct_Value_Print( stderr, Instrument_Ptr->Layer_DS_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0, &count2)) != NDS_OK) - { - printf( "Cant't dump layers: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); - return( DRS_KO); - } - } - - fprintf( stderr, "\n"); - - return( DRS_OK); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Kit_Add */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Kit_Add( DRT_Kit **Kit_Ptr_Ptr, NDT_Root *DS_Ptr, DRT_Kit *Kit_Template_Ptr) -{ - NDT_Status nd_status; - - - if( ( nd_status = ND_Value_Alloc( DS_Ptr, (void **)Kit_Ptr_Ptr, Kit_Template_Ptr)) != NDS_OK) - { - printf( "Can't allocate new kit: ND_Value_Alloc() failed (%d) !\n", nd_status); - return( DRS_KO); - } - else - { - if( ( nd_status = ND_DataStruct_Value_Add( DS_Ptr, (void **)*Kit_Ptr_Ptr)) != NDS_OK) - { - printf( "Can't add new kit: ND_Value_Add() failed (%d) !\n", nd_status); - return( DRS_KO); - } - } - - return( DRS_OK); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Kit_Sample_Load */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Kit_Sample_Load( DRT_Kit *Kit_Ptr, double SampleRate) -{ - NDT_Status nd_status; - - - if( ( nd_status = ND_DataStruct_Traverse( Kit_Ptr->Instrument_DS_Ptr, NDD_CMD_SAMPLE_LOAD, Kit_Ptr, SampleRate)) != NDS_OK) - { - printf( "Cant't load kit samples: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); - return( DRS_KO); - } - - return( DRS_OK); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Kit_Dump */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Kit_Dump( DRT_Kit *Kit_Ptr, long Count) -{ - NDT_Status nd_status; - long count2; - - - - fprintf( stderr, " %03d) DrumKit:", Count); - fprintf( stderr, " Id: (% 3d) Name: [%s] Descrition: [%.32s] Dir Name: [%s]\n", Kit_Ptr->Id, Kit_Ptr->Name, Kit_Ptr->Desc, Kit_Ptr->DirName); - fprintf( stderr, " Instruments List:\n"); - - if( Kit_Ptr->Instrument_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number == 0) - { - fprintf( stderr, " Empty list!\n"); - } - else - { - count2 = 0; - - if( ( nd_status = ND_DataStruct_Value_Print( stderr, Kit_Ptr->Instrument_DS_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0, &count2)) != NDS_OK) - { - printf( "Cant't dump intruments: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); - return( DRS_KO); - } - } - - fprintf( stderr, "\n"); - - return( DRS_OK); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_XML_Node_Exist */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_XML_Node_Exist( xmlDocPtr Xml_Doc, xmlXPathContextPtr Xml_XpathCtx, char *Xpath_Request) -{ - DRT_Status status; - xmlXPathObjectPtr xml_xpathobj; - xmlNodeSetPtr nodeset; - char *tmpval_ptr; - long tmpval_len; - - - if( ( xml_xpathobj = xmlXPathEvalExpression( Xpath_Request, Xml_XpathCtx)) == NULL) - { - fprintf( stderr, "DR_XML_Node_Exist: xmlXPathEvalExpression failed [%s]!\n", Xpath_Request); - status = DRS_KO; - } - else - { - nodeset = xml_xpathobj->nodesetval; - - if( xmlXPathNodeSetIsEmpty( nodeset)) - { -// fprintf( stderr, "[%s] not found!\n", Xpath_Request); - status = DRS_KO; - } - else - { -// fprintf( stderr, "[%s] found!\n", Xpath_Request); - status = DRS_OK; - } - } - - return( status); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_XML_Value_Get */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_XML_Value_Get( char *Value_Ptr, long Max_Len, xmlDocPtr Xml_Doc, xmlXPathContextPtr Xml_XpathCtx, char *Xpath_HeadRequest, char *Xpath_TailRequest) -{ - DRT_Status status; - xmlXPathObjectPtr xml_xpathobj; - xmlNodeSetPtr nodeset; - char *tmpval_ptr; - long tmpval_len; - char xpath_request[1024]; - - - strcpy( xpath_request, Xpath_HeadRequest); - strcat( xpath_request, Xpath_TailRequest); - - if( ( xml_xpathobj = xmlXPathEvalExpression( xpath_request, Xml_XpathCtx)) == NULL) - { - fprintf( stderr, "DR_XML_Value_Get: xmlXPathEvalExpression failed! [%s]\n", xpath_request); - status = DRS_KO; - } - else - { - nodeset = xml_xpathobj->nodesetval; - - if( xmlXPathNodeSetIsEmpty( nodeset)) - { - fprintf( stderr, "[%s] not found!\n", xpath_request); - status = DRS_KO; - } - else - { - if( ( tmpval_ptr = xmlNodeListGetString( Xml_Doc, nodeset->nodeTab[0]->xmlChildrenNode, 1)) == NULL) - { - fprintf( stderr, "[%s] value not found!\n", xpath_request); - status = DRS_KO; - } - else - { -// fprintf( stderr, "[%s] = [%s] found!\n", nodeset->nodeTab[0]->name, tmpval_ptr); - - if( ( tmpval_len = strlen( tmpval_ptr)) > Max_Len) - { - fprintf( stderr, "Value too long (%d)>(%d)!\n", tmpval_len, Max_Len); - status = DRS_OK; - } - else - { - strcpy( Value_Ptr, tmpval_ptr); - status = DRS_OK; - } - } - - xmlFree( tmpval_ptr); - } - } - - return( status); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_XML_Query_Tab_Exec */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_XML_Query_Tab_Exec( void *Value_Ptr, xmlDocPtr XML_Doc, xmlXPathContextPtr XML_XpathCtx, char *Xpath_Head, DRT_XML_Query *XML_Query_Tab) -{ - DRT_Status status; - char reply_str[DESC_SIZE]; - int i; - - - i=0; - - while( XML_Query_Tab[i].XPath_Query != NULL) - { - if( ( status = DR_XML_Value_Get( reply_str, DESC_LEN, XML_Doc, XML_XpathCtx, Xpath_Head, XML_Query_Tab[i].XPath_Query)) != DRS_OK) - { - strcpy( reply_str, ""); - } - - switch( XML_Query_Tab[i].Value_Type) - { - case XML_QUERY_VALUE_STRING: - { - strncpy( ( Value_Ptr + XML_Query_Tab[i].Value_Offset), reply_str, XML_Query_Tab[i].Value_Len); - break; - } - - case XML_QUERY_VALUE_INT: - { - *( (int *)( Value_Ptr + XML_Query_Tab[i].Value_Offset)) = atoi( reply_str); - break; - } - - case XML_QUERY_VALUE_LONG: - { - *( (long *)( Value_Ptr + XML_Query_Tab[i].Value_Offset)) = strtol( reply_str, NULL, 10); - break; - } - - case XML_QUERY_VALUE_LONGLONG: - { - *( (long long *)( Value_Ptr + XML_Query_Tab[i].Value_Offset)) = strtoll( reply_str, NULL, 10); - break; - } - - case XML_QUERY_VALUE_FLOAT: - { - *( (float *)( Value_Ptr + XML_Query_Tab[i].Value_Offset)) = strtof( reply_str, NULL); - break; - } - - case XML_QUERY_VALUE_DOUBLE: - { - *( (double *)( Value_Ptr + XML_Query_Tab[i].Value_Offset)) = strtod( reply_str, NULL); - break; - } - - default: - { - fprintf( stderr, "Unknown valute type: (%d)\n", XML_Query_Tab[i].Value_Type); - break; - } - } - - i++; - } - - return( DRS_OK); -} - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Kit_Load */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Kit_Load( DRT_Base *Base_Ptr, char *FileName) -{ - DRT_Status status; - NDT_Status nd_status; - - DRT_Kit kit_template; - DRT_Kit *kit_ptr; - DRT_Instrument instrument_template; - DRT_Instrument *instrument_ptr; - DRT_Layer layer_template; - DRT_Layer *layer_ptr; - - xmlDocPtr xml_doc; - xmlXPathContextPtr xml_xpathCtx; - xmlXPathObjectPtr xml_xpathObj; - - char tmp_filename[FILENAME_SIZE]; - char xpath_head[1024]; - char reply_str[256]; - - int instrument, layer; - short i; - - - layer_template.Sample_Ptr = NULL; - layer_template.Sample_Size = 0; - - - fprintf( stderr, "Loading: [%s]...\n", FileName); - - if( strlen( FileName) > FILENAME_LEN) - { - fprintf( stderr, "Kit file name too long [%s]!", FileName); - status = DRS_KO; - } - else - { - strcpy( tmp_filename, FileName); - strcpy( kit_template.DirName, dirname(tmp_filename)); - - if( ( xml_doc = xmlParseFile( FileName)) == NULL) - { - fprintf( stderr, "xml_doc failed!\n"); - status = DRS_KO; - } - else - { - if( ( xml_xpathCtx = xmlXPathNewContext( xml_doc)) == NULL) - { - fprintf( stderr, "xmlXPathNewContext failed!\n"); - status = DRS_KO; - } - else - { - if( xmlXPathRegisterNs( xml_xpathCtx, "drumkit", "http://www.hydrogen-music.org/drumkit") != 0) - { - fprintf( stderr,"Error: unable to register default NS!\n"); - status = DRS_KO; - } - - if( ( status = DR_XML_Node_Exist( xml_doc, xml_xpathCtx, XML_XPATH_DRUMKIT_BASE_STR) != DRS_OK)) - { - fprintf( stderr, "Bad drumkit file!\n"); - } - else - { - DR_XML_Query_Tab_Exec( &kit_template, xml_doc, xml_xpathCtx, XML_XPATH_DRUMKIT_BASE_STR, DRG_XML_Query_Tab_Kit); - - if( ( status = DR_Kit_Add( &kit_ptr, Base_Ptr->Kit_DS_Ptr, &kit_template)) != DRS_OK) - { - fprintf( stderr, "Can't create a new kit!\n"); - } - else - { -// fprintf( stderr, "New kit!\n"); - - status = DRS_OK; - instrument = 1; - while( ( status == DRS_OK) - && ( sprintf( xpath_head, XML_XPATH_DRUMKIT_INSTRUMENT_FULL, instrument) > 0) - && ( DR_XML_Node_Exist( xml_doc, xml_xpathCtx, xpath_head) == DRS_OK)) - { - instrument_template.Id = -1; - - DR_XML_Query_Tab_Exec( &instrument_template, xml_doc, xml_xpathCtx, xpath_head, DRG_XML_Query_Tab_Instrument); - - if( instrument_template.Id == -1) - { - fprintf( stderr, "Instrument id not found!\n"); - } - else - { - if( ( status = DR_Instrument_Add( &instrument_ptr, kit_ptr->Instrument_DS_Ptr, &instrument_template)) != DRS_OK) - { - fprintf( stderr, "Can't create a new instrument!\n"); - } - else - { -// fprintf( stderr, "New Instrument!\n"); - } - - layer = 1; - while( ( status == DRS_OK) - && ( sprintf( xpath_head, XML_XPATH_DRUMKIT_LAYER_FULL, instrument, layer) > 0) - && ( DR_XML_Node_Exist( xml_doc, xml_xpathCtx, xpath_head) == DRS_OK)) - { - DR_XML_Query_Tab_Exec( &layer_template, xml_doc, xml_xpathCtx, xpath_head, DRG_XML_Query_Tab_Layer); - - strcpy( tmp_filename, kit_template.DirName); - strcat( tmp_filename, "/"); - strcat( tmp_filename, layer_template.FileName); - strcpy( layer_template.FileName, tmp_filename); - - if( ( status = DR_Layer_Add( &layer_ptr, instrument_ptr->Layer_DS_Ptr, &layer_template)) != DRS_OK) - { - fprintf( stderr, "Can't create a new layer!\n"); - } - else - { -// fprintf( stderr, "New layer!\n"); - layer++; - } - } - } - - instrument++; - } - } - } - - xmlXPathFreeContext( xml_xpathCtx); - } - - xmlFreeDoc( xml_doc); - } - } - - xmlCleanupParser(); - - return( status); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Kits_Load */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Kits_Load( DRT_Base *Base_Ptr) -{ - DRT_Status status; - NDT_Status nd_status; - char glob_pattern[] = "~/.hydrogen/data/drumkits/*/drumkit.xml"; -// char glob_pattern[] = "~/.hydrogen/data/drumkits/AVL-BlackPearl-4A-1.1/drumkit.xml"; -// char glob_pattern[] = "~/.hydrogen/data/drumkits/Mars Lindrum: 02-Kit 2/drumkit.xml"; - glob_t glob_struct; - int i; - - - LIBXML_TEST_VERSION; - - if( glob( glob_pattern, (GLOB_NOSORT + GLOB_TILDE), NULL, &glob_struct) != 0) - { - fprintf( stderr, "glob() error!\n"); - status = DRS_KO; - } - else - { - for( i = 0; i < glob_struct.gl_pathc; i++) - { -// printf( "[%s]\n", glob_struct.gl_pathv[i]); - - if( ( status = DR_Kit_Load( Base_Ptr, glob_struct.gl_pathv[i])) != DRS_OK) - { - fprintf( stderr, "Can't load kit [%s]!\n", glob_struct.gl_pathv[i]); - } - } - - if( ( nd_status = ND_DataStruct_Convert( Base_Ptr->Kit_DS_Ptr, DRG_Kit_DS_Index_Tab_Final)) != NDS_OK) - { - fprintf( stderr, "ND_DataStruct_Convert() failed (%d) !\n", status); - status = DRS_KO; - } - else - { - status = DRS_OK; - } - } - - globfree( &glob_struct); - - Base_Ptr->SampleRate=44100; - -/* - status = DR_Layer_Sample_Load( (DRT_Layer *)( - ((DRT_Instrument *)( - ((DRT_Kit *)(Base_Ptr->Kit_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head->Value)) - ->Instrument_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head->Value)) - ->Layer_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head->Value), - (DRT_Kit *)(Base_Ptr->Kit_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head->Value), Base_Ptr->SampleRate); -*/ - status = DR_Kit_Sample_Load( (DRT_Kit *)(Base_Ptr->Kit_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head->Value), - Base_Ptr->SampleRate); - - return( status); -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Kits_Dump */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Kits_Dump( DRT_Base *Base_Ptr) -{ - NDT_Status nd_status; - short index; - long count = 0; - long kits_count = 0; - long instruments_count = 0; - long layers_count = 0; - - - fprintf( stderr, "\n"); - fprintf( stderr, "DrumKit List:\n"); -/* - if( ( nd_status = ND_DataStruct_Info_Print( stderr, Base_Ptr->Kit_DS_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0)) != NDS_OK) - { - printf( "ND_DataStruct_Info_Print() failed (%d) !\n", nd_status); - return( DRS_KO); - } - - for( index = 0; index < Base_Ptr->Kit_DS_Ptr->Index_Nb; index++) - { - count = 0; - fprintf( stderr, "Dump Index: (%d)\n", index); - - if( Base_Ptr-> Kit_DS_Ptr->Index_Tab[index].Node_Number == 0) - { - fprintf( stderr, " Empty list!\n"); - } - else - { - if( ( nd_status = ND_DataStruct_Traverse( Base_Ptr->Kit_DS_Ptr, (NDD_CMD_INDEX0_PRINT + index), stderr, &count)) != NDS_OK) - { - printf( "Can't dump kits: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); - return( DRS_KO); - } - } - - fprintf( stderr, "\n"); - } -*/ - - if( ( nd_status = ND_DataStruct_Value_Print( stderr, Base_Ptr->Kit_DS_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0, &count)) != NDS_OK) - { - printf( "Can't dump kits: ND_DataStruct_Value_Print() failed (%d) !\n", nd_status); - return( DRS_KO); - } - - if( ( nd_status = ND_DataStruct_Traverse( Base_Ptr->Kit_DS_Ptr, NDD_CMD_STATS_GET, &kits_count, &instruments_count, &layers_count)) != NDS_OK) - { - printf( "Can't compute stats: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); - return( DRS_KO); - } - - fprintf( stderr, "Number of Kits: (%ld) Number of Instruments: (%ld) Number of Layers: (%ld)\n", kits_count, instruments_count, layers_count); - - return( DRS_OK); -} - - - - - /*---------------------------------------------------------------------------------*/ /* DR_Init */ /*---------------------------------------------------------------------------------*/ DRT_Status DR_Init( DRT_Base *Base_Ptr) { - NDT_Status nd_status; + DRT_Status status; - if( ( nd_status = ND_Library_Open( NDD_TRUE)) != NDS_OK) + if( ( status = DR_DataStruct_Init( Base_Ptr, DRD_SAMPLE_RATE_DEFAULT)) != DRS_OK) { - fprintf( stderr, "Can't open node library (%d) !", nd_status); - return( DRS_KO); - } - - if( ( nd_status = ND_DataStruct_Open( &(Base_Ptr->Kit_DS_Ptr), DRD_KIT_DS_INDEX_NB, DRG_Kit_DS_Index_Tab_Initial, "Kit_Manager", DR_Kit_Manager, NULL, NULL, NULL, NULL, NDD_TRUE, NULL)) != NDS_OK) - { - printf( "Kit_DS: ND_DataStruct_Open() failed (%d) !\n", nd_status); - return( DRS_KO); + fprintf( stderr, "Can't init data structures (%d) !", status); + return( status); } - return( DRS_OK); + return( status); } @@ -1883,22 +40,16 @@ DRT_Status DR_Init( DRT_Base *Base_Ptr) DRT_Status DR_DeInit( DRT_Base *Base_Ptr) { - NDT_Status nd_status; + DRT_Status status; - if( ( nd_status = ND_DataStruct_Close( Base_Ptr->Kit_DS_Ptr)) != NDS_OK) + if( ( status = DR_DataStruct_DeInit( Base_Ptr)) != DRS_OK) { - printf( "Can't close Kit_DS (%d)!\n", nd_status); - return( DRS_KO); + printf( "Can't deinit data structures (%d)!\n", status); + return( status); } - if( ( nd_status = ND_Library_Close()) != NDS_OK) - { - fprintf( stderr, "Can't close node library (%d)!", nd_status); - return( DRS_KO); - } - - return( DRS_OK); + return( status); } @@ -1912,8 +63,9 @@ DRT_Status DR_DeInit( DRT_Base *Base_Ptr) int main( int argc, char **argv) { - DRT_Base base; - DRT_Status status; + DRT_Base base; + DRT_Status status; + DRT_Kit *kit_ptr; if( ( status = DR_Init( &base)) != DRS_OK) @@ -1926,7 +78,35 @@ int main( int argc, char **argv) exit( -1); } - printf( "hello world!\n"); + + if( ( status = DR_Kit_Id_Find( &kit_ptr, base.Kit_DS_Ptr, 0)) != DRS_OK) +// if( ( status = DR_Kit_Name_Find( &kit_ptr, base.Kit_DS_Ptr, "Mars LM1: 01-777 Clean Kit")) != DRS_OK) + { + exit( -1); + } + else + { + if( ( status = DR_Kit_Sample_Load( kit_ptr, base.SampleRate)) != DRS_OK) + { + exit( -1); + } +/* + fprintf( stderr, "Before!\n"); + + if( ( status = DR_Kit_Sample_UnLoad( kit_ptr)) != DRS_OK) + { + exit( -1); + } +*/ + fprintf( stderr, "After!\n"); + + if( ( status = DR_Kit_Sample_Load( kit_ptr, base.SampleRate)) != DRS_OK) + { + exit( -1); + } + } + + fprintf( stderr, "hello world!\n"); if( ( status = DR_Kits_Dump( &base)) != DRS_OK) { diff --git a/drummer.h b/drummer.h index f9d009f..9a3f74c 100644 --- a/drummer.h +++ b/drummer.h @@ -48,20 +48,7 @@ typedef short DRT_Boolean; #define DRD_MAX(A,B) (((A) < (B)) ? (B) : (A)) #define DRD_MIN(A,B) (((A) > (B)) ? (B) : (A)) -#define NDD_CMD_STATS_GET ( NDT_Command) 65 -#define NDD_CMD_SAMPLE_LOAD ( NDT_Command) 66 -#define NDD_CMD_SAMPLE_UNLOAD ( NDT_Command) 67 -#define NDD_CMD_INDEX0_PRINT ( NDT_Command) 68 -#define NDD_CMD_INDEX1_PRINT ( NDT_Command) 69 - -#define NAME_LEN (short) 256 -#define NAME_SIZE (NAME_LEN + 1) -#define DIRNAME_LEN (short) 1024 -#define DIRNAME_SIZE (DIRNAME_LEN) -#define FILENAME_LEN (short) 1024 -#define FILENAME_SIZE (FILENAME_LEN) -#define DESC_LEN (short) 2048 -#define DESC_SIZE (DESC_LEN + 1) +#define DRD_SAMPLE_RATE_DEFAULT 44100 @@ -87,177 +74,10 @@ typedef short DRT_Status; -/*----------------------------------------------------------------------------*/ -/* Layer_DS Indexes */ -/*----------------------------------------------------------------------------*/ - -#define DRD_LAYER_DS_INDEX_NB (short)2 - -static NDT_Index_Type DRG_Layer_DS_Index_Tab_Initial[DRD_LAYER_DS_INDEX_NB] = -{ - (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_SORTED), - (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_SORTED) -}; - -static NDT_Index_Type DRG_Layer_DS_Index_Tab_Final[DRD_LAYER_DS_INDEX_NB] = -{ - (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_TREE | NDD_INDEX_SUBTYPE_BALANCED), - (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_TREE | NDD_INDEX_SUBTYPE_BALANCED) -}; - - - -/*----------------------------------------------------------------------------*/ -/* Instrument_DS Indexes */ -/*----------------------------------------------------------------------------*/ - -#define DRD_INSTRUMENT_DS_INDEX_NB (short)2 - -static NDT_Index_Type DRG_Instrument_DS_Index_Tab_Initial[DRD_INSTRUMENT_DS_INDEX_NB] = -{ - (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_SORTED), - (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_SORTED) -}; - -static NDT_Index_Type DRG_Instrument_DS_Index_Tab_Final[DRD_INSTRUMENT_DS_INDEX_NB] = -{ - (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_TREE | NDD_INDEX_SUBTYPE_BALANCED), - (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_TREE | NDD_INDEX_SUBTYPE_BALANCED) -}; - - - -/*----------------------------------------------------------------------------*/ -/* Kit_DS Indexes */ -/*----------------------------------------------------------------------------*/ - -#define DRD_KIT_DS_INDEX_NB (short)2 - -static NDT_Index_Type DRG_Kit_DS_Index_Tab_Initial[DRD_KIT_DS_INDEX_NB] = -{ - (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_SORTED), - (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_SORTED) -}; - -static NDT_Index_Type DRG_Kit_DS_Index_Tab_Final[DRD_KIT_DS_INDEX_NB] = -{ - (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_TREE | NDD_INDEX_SUBTYPE_BALANCED), - (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_TREE | NDD_INDEX_SUBTYPE_BALANCED) -}; - - - - - /*---------------------------------------------------------------------------------*/ -/* XML XPATH Tags */ +/* DRT_Base */ /*---------------------------------------------------------------------------------*/ -#define STR(A) #A -#define TAG(A) STR(A) - -#define XML_XPATH_ELEMENT(A) *[local-name()=(A)] -#define XML_SLASH / - -#define XML_XPATH_DRUMKIT_BASE_TAG XML_XPATH_ELEMENT('drumkit_info') -#define XML_XPATH_DRUMKIT_NAME_TAG XML_XPATH_ELEMENT('name') -#define XML_XPATH_DRUMKIT_INFO_TAG XML_XPATH_ELEMENT('info') -#define XML_XPATH_DRUMKIT_INSTRUMENTLIST_TAG XML_XPATH_ELEMENT('instrumentList') -#define XML_XPATH_DRUMKIT_INSTRUMENT_TAG XML_XPATH_ELEMENT('instrument') -#define XML_XPATH_DRUMKIT_ID_TAG XML_XPATH_ELEMENT('id') -#define XML_XPATH_DRUMKIT_GAIN_TAG XML_XPATH_ELEMENT('gain') -#define XML_XPATH_DRUMKIT_PAN_LEFT_TAG XML_XPATH_ELEMENT('pan_L') -#define XML_XPATH_DRUMKIT_PAN_RIGHT_TAG XML_XPATH_ELEMENT('pan_R') -#define XML_XPATH_DRUMKIT_INSTRUMENTCOMPONENT_TAG XML_XPATH_ELEMENT('instrumentComponent') -#define XML_XPATH_DRUMKIT_LAYER_TAG XML_XPATH_ELEMENT('layer') -#define XML_XPATH_DRUMKIT_FILENAME_TAG XML_XPATH_ELEMENT('filename') -#define XML_XPATH_DRUMKIT_MIN_TAG XML_XPATH_ELEMENT('min') -#define XML_XPATH_DRUMKIT_MAX_TAG XML_XPATH_ELEMENT('max') -#define XML_XPATH_DRUMKIT_PITCH_TAG XML_XPATH_ELEMENT('pitch') - -#define XML_XPATH_DRUMKIT_BASE_STR TAG(/XML_XPATH_DRUMKIT_BASE_TAG) -#define XML_XPATH_DRUMKIT_NAME_STR TAG(/XML_XPATH_DRUMKIT_NAME_TAG) -#define XML_XPATH_DRUMKIT_INFO_STR TAG(/XML_XPATH_DRUMKIT_INFO_TAG) -#define XML_XPATH_DRUMKIT_ID_STR TAG(/XML_XPATH_DRUMKIT_ID_TAG) -#define XML_XPATH_DRUMKIT_GAIN_STR TAG(/XML_XPATH_DRUMKIT_GAIN_TAG) -#define XML_XPATH_DRUMKIT_PAN_LEFT_STR TAG(/XML_XPATH_DRUMKIT_PAN_LEFT_TAG) -#define XML_XPATH_DRUMKIT_PAN_RIGHT_STR TAG(/XML_XPATH_DRUMKIT_PAN_RIGHT_TAG) -#define XML_XPATH_DRUMKIT_FILENAME_STR TAG(/XML_XPATH_DRUMKIT_FILENAME_TAG) -#define XML_XPATH_DRUMKIT_MIN_STR TAG(/XML_XPATH_DRUMKIT_MIN_TAG) -#define XML_XPATH_DRUMKIT_MAX_STR TAG(/XML_XPATH_DRUMKIT_MAX_TAG) -#define XML_XPATH_DRUMKIT_PITCH_STR TAG(/XML_XPATH_DRUMKIT_PITCH_TAG) - -#define XML_XPATH_DRUMKIT_KIT_NAME_FULL TAG(/XML_XPATH_DRUMKIT_BASE_TAG/XML_XPATH_DRUMKIT_NAME_TAG) -#define XML_XPATH_DRUMKIT_KIT_INFO_FULL TAG(/XML_XPATH_DRUMKIT_BASE_TAG/XML_XPATH_DRUMKIT_INFO_TAG) -#define XML_XPATH_DRUMKIT_INSTRUMENT_FULL TAG(/XML_XPATH_DRUMKIT_BASE_TAG/XML_XPATH_DRUMKIT_INSTRUMENTLIST_TAG/XML_XPATH_DRUMKIT_INSTRUMENT_TAG[%i]) -#define XML_XPATH_DRUMKIT_LAYER_FULL2 TAG(/XML_XPATH_DRUMKIT_BASE_TAG/XML_XPATH_DRUMKIT_INSTRUMENTLIST_TAG/XML_XPATH_DRUMKIT_INSTRUMENT_TAG[%i]/XML_XPATH_DRUMKIT_INSTRUMENTCOMPONENT_TAG/XML_XPATH_DRUMKIT_LAYER_TAG[%i]) -#define XML_XPATH_DRUMKIT_LAYER_FULL TAG(/XML_XPATH_DRUMKIT_BASE_TAG/XML_XPATH_DRUMKIT_INSTRUMENTLIST_TAG/XML_XPATH_DRUMKIT_INSTRUMENT_TAG[%i]XML_SLASH/XML_XPATH_DRUMKIT_LAYER_TAG[%i]) - - - - -/*---------------------------------------------------------------------------------*/ -/* LibSamplerate */ -/*---------------------------------------------------------------------------------*/ - -// Quality of conversion for libsamplerate. -// See http://www.mega-nerd.com/SRC/api_misc.html#Converters -// for info about availble qualities -#define RATE_CONV_QUALITY SRC_SINC_MEDIUM_QUALITY - - - - - -/*---------------------------------------------------------------------------------*/ -/* Layer / Instrument / Kit */ -/*---------------------------------------------------------------------------------*/ - -typedef struct DRT_Layer -{ - short Id; - char FileName[ FILENAME_SIZE]; - float *Sample_Ptr; - long Sample_Size; - SF_INFO *SF_Info_Ptr; - double Min; - double Max; - double Gain; - double Pitch; -} DRT_Layer; - - - -typedef struct DRT_Instrument -{ - short Id; - char Name[ NAME_SIZE]; - double Gain; - double Pan_Left; - double Pan_Right; - NDT_Root *Layer_DS_Ptr; -} DRT_Instrument; - - - -typedef struct DRT_Kit -{ - short Id; - char Name[ NAME_SIZE]; - char Desc[ DESC_SIZE]; - char DirName[ DIRNAME_SIZE]; - NDT_Root *Instrument_DS_Ptr; -} DRT_Kit; - - -/* -typedef struct DRT_Library -{ - NDT_Root *Kit_DS; -} DRT_Library; -*/ - - typedef struct DRT_Base { NDT_Root *Kit_DS_Ptr; @@ -268,194 +88,10 @@ typedef struct DRT_Base -/*---------------------------------------------------------------------------------*/ -/* XML_Query */ -/*---------------------------------------------------------------------------------*/ - -#define XML_QUERY_VALUE_UNKNOWN (short) 0 -#define XML_QUERY_VALUE_STRING (short) 1 -#define XML_QUERY_VALUE_INT (short) 2 -#define XML_QUERY_VALUE_LONG (short) 3 -#define XML_QUERY_VALUE_LONGLONG (short) 4 -#define XML_QUERY_VALUE_FLOAT (short) 5 -#define XML_QUERY_VALUE_DOUBLE (short) 6 - -typedef struct DRT_XML_Query -{ - char *Query_Name; - char *XPath_Query; - short Value_Type; - long Value_Offset; - short Value_Len; -} DRT_XML_Query; - - - -DRT_XML_Query DRG_XML_Query_Tab_Layer[] = -{ - { "File Name", XML_XPATH_DRUMKIT_FILENAME_STR, XML_QUERY_VALUE_STRING, offsetof( DRT_Layer, FileName), FILENAME_LEN }, - { "Min", XML_XPATH_DRUMKIT_MIN_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Layer, Min), 0 }, - { "Max", XML_XPATH_DRUMKIT_MAX_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Layer, Max), 0 }, - { "Gain", XML_XPATH_DRUMKIT_GAIN_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Layer, Gain), 0 }, - { "Pitch", XML_XPATH_DRUMKIT_PITCH_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Layer, Pitch), 0 }, - { NULL, NULL, XML_QUERY_VALUE_UNKNOWN, 0, 0 } -}; - -DRT_XML_Query DRG_XML_Query_Tab_Instrument[] = -{ - { "Id", XML_XPATH_DRUMKIT_ID_STR, XML_QUERY_VALUE_LONG, offsetof( DRT_Instrument, Id), 0 }, - { "Name", XML_XPATH_DRUMKIT_NAME_STR, XML_QUERY_VALUE_STRING, offsetof( DRT_Instrument, Name), NAME_LEN }, - { "Gain", XML_XPATH_DRUMKIT_GAIN_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Instrument, Gain), 0 }, - { "Pan_Left", XML_XPATH_DRUMKIT_PAN_LEFT_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Instrument, Pan_Left), 0 }, - { "Pan_Right", XML_XPATH_DRUMKIT_PAN_RIGHT_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Instrument, Pan_Right), 0 }, - { NULL, NULL, XML_QUERY_VALUE_UNKNOWN, 0, 0 } -}; - -DRT_XML_Query DRG_XML_Query_Tab_Kit[] = -{ - { "File", XML_XPATH_DRUMKIT_NAME_STR, XML_QUERY_VALUE_STRING, offsetof( DRT_Kit, Name), NAME_LEN }, - { "Desc", XML_XPATH_DRUMKIT_INFO_STR, XML_QUERY_VALUE_STRING, offsetof( DRT_Kit, Desc), DESC_LEN }, - { NULL, NULL, XML_QUERY_VALUE_UNKNOWN, 0, 0 } -}; - - - - - /*----------------------------------------------------------------------------*/ /* Prototypes */ /*----------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------------*/ -/* DS Managers */ -/*---------------------------------------------------------------------------------*/ - -NDT_Status DR_Layer_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); -NDT_Status DR_Instrument_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); -NDT_Status DR_Kit_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Layer_Add */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Layer_Add( DRT_Layer **, NDT_Root *, DRT_Layer *); - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Layer_Sample_Load */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Layer_Sample_Load( DRT_Layer *, DRT_Kit *, double); - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Layer_Sample_UnLoad */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Layer_Sample_UnLoad( DRT_Layer *); - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Layer_Dump */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Layer_Dump( DRT_Layer *, long); - - - -/*----------------------------------------------------------------------------*/ -/* DR_Instrument_Add */ -/*----------------------------------------------------------------------------*/ - -DRT_Status DR_Instrument_Add( DRT_Instrument **, NDT_Root *, DRT_Instrument *); - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Instrument_Dump */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Instrument_Dump( DRT_Instrument *, long); - - - -/*----------------------------------------------------------------------------*/ -/* DR_Kit_Add */ -/*----------------------------------------------------------------------------*/ - -DRT_Status DR_Kit_Add( DRT_Kit **, NDT_Root *, DRT_Kit *); - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Kit_Sample_Load */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Kit_Sample_Load( DRT_Kit *, double); - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Kit_Dump */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Kit_Dump( DRT_Kit *, long); - - - -/*---------------------------------------------------------------------------------*/ -/* DR_XML_Node_Exist */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_XML_Node_Exist( xmlDocPtr, xmlXPathContextPtr, char *); - - - -/*---------------------------------------------------------------------------------*/ -/* DR_XML_Query_Tab_Exec */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_XML_Query_Tab_Exec( void *, xmlDocPtr, xmlXPathContextPtr, char *, DRT_XML_Query *); - - - -/*---------------------------------------------------------------------------------*/ -/* DR_XML_Value_Get */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_XML_Value_Get( char *, long, xmlDocPtr, xmlXPathContextPtr, char *, char *); - - - -/*---------------------------------------------------------------------------------*/ -/* DR_Kit_Load */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_Kit_Load( DRT_Base *, char *); - - - -/*----------------------------------------------------------------------------*/ -/* DR_Kits_Load */ -/*----------------------------------------------------------------------------*/ - -DRT_Status DRT_Kits_Load( DRT_Base *); - - - -/*----------------------------------------------------------------------------*/ -/* DR_Kits_Dump */ -/*----------------------------------------------------------------------------*/ - -DRT_Status DRT_Kits_Dump( DRT_Base *); - - - /*----------------------------------------------------------------------------*/ /* DR_Init */ /*----------------------------------------------------------------------------*/ @@ -487,4 +123,7 @@ int main( int, char **); /*----------------------------------------------------------------------------*/ +#include +#include + #endif diff --git a/go.sh b/go.sh index d3b5646..d9ca4ac 100755 --- a/go.sh +++ b/go.sh @@ -1,6 +1,31 @@ -gcc -g -c -I . -o libnode.o libnode.c +#!/bin/bash +module_list="libnode.c datastruct.c" +main_list="drummer.c lv2_plugin.c" + +for module in ${module_list} ${main_list} +do + cmd="gcc -g -c -I. -I/usr/include/libxml2 -o ${module//.c/.o} -fPIC ${module}" + + echo ${cmd} + eval ${cmd} +done + + + +cmd="gcc -g -o drummer ${module_list//.c/.o} drummer.o -fPIC -ldl -lxml2 -lz -llzma -lm -lsndfile -lsamplerate" + +echo ${cmd} +eval ${cmd} + +cmd="gcc -g -o drummer.so ${module_list//.c/.o} lv2_plugin.o -shared -fPIC -ldl -lxml2 -lz -llzma -lm -lsndfile -lsamplerate" + +echo ${cmd} +eval ${cmd} + +cmd="./drummer-mkttl" + +#echo ${cmd} +#eval ${cmd} #gcc -g -I . -L . -shared -o drummer.so -fPIC drummer.c - -gcc -g -I. -I/usr/include/libxml2 -o drummer -fPIC libnode.o -ldl -lxml2 -lz -llzma -lm -lsndfile -lsamplerate drummer.c #gcc -g -I. -I/usr/include/libxml2 -o xpath -fPIC -ldl -lxml2 -lz -llzma -lm xpath.c diff --git a/libnode.c b/libnode.c index 9bc22af..ea4c612 100644 --- a/libnode.c +++ b/libnode.c @@ -2281,7 +2281,7 @@ NDT_Status ND_Index_Info_Print_I( FILE *Out, NDT_Root *Root_Ptr, NDT_Index_Id memset( offset, ' ', Recursive_Offset * ND_RECURSIVE_PRINT_OFFSET); offset[Recursive_Offset * ND_RECURSIVE_PRINT_OFFSET] = '\0'; - fprintf( Out, "%s Index Id: (%d)\tType: (%#06x) [%s:%s:%s]\tNode Nb: (%d)\tHead: (%s%p)\tTail: (%s%p)\n%s Min Depth: (%d)\tMax Depth: (%d)\tMax Dif: (%d)\tNb Equ: (%d)\tSave: (%s%p)\n\n", + fprintf( Out, "%s Index Id: (%d)\tType: (%#06x) [%s:%s:%s]\tNode Nb: (%ld)\tHead: (%s%p)\tTail: (%s%p)\n%s Min Depth: (%ld)\tMax Depth: (%ld)\tMax Dif: (%ld)\tNb Equ: (%ld)\tSave: (%s%p)\n\n", offset, Index_Id, Root_Ptr->Index_Tab[Index_Id].Type, ND_INDEX_STATUS_ASCII_GET( Root_Ptr, Index_Id), ND_INDEX_TYPE_ASCII_GET( Root_Ptr, Index_Id), ND_INDEX_SUBTYPE_ASCII_GET( Root_Ptr, Index_Id), Root_Ptr->Index_Tab[Index_Id].Node_Number, NDD_PRINTF_PTR_PREFIX, Root_Ptr->Index_Tab[Index_Id].Head, NDD_PRINTF_PTR_PREFIX, Root_Ptr->Index_Tab[Index_Id].Tail, @@ -2565,7 +2565,7 @@ NDT_Status ND_DataStruct_Value_Add_C( NDT_Root *Root_Ptr, void *Value_Ptr) if( !Value_Ptr) { - sprintf( NDG_Base.Err_String, "Error ND_DatatStruct_Value_Add_C: the value to add is null"); + sprintf( NDG_Base.Err_String, "Error ND_DataStruct_Value_Add_C: the value to add is null"); ND_Error_Print(); return( NDS_ERRAPI); diff --git a/lv2_plugin.c b/lv2_plugin.c index de945e2..3226a24 100644 --- a/lv2_plugin.c +++ b/lv2_plugin.c @@ -1,6 +1,6 @@ -/*---------------------------------------------------------------------------------*/ -/* Includes */ -/*---------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/* Includes */ +/*----------------------------------------------------------------------------*/ #define _LV2_PLUGIN_C_ @@ -12,13 +12,1176 @@ -/*---------------------------------------------------------------------------------*/ -/* */ -/*---------------------------------------------------------------------------------*/ +static int current_kit_changed = 0; -static LV2_Handle instantiate(const LV2_Descriptor *descriptor, - double rate, - const char* bundle_path, - const LV2_Feature* const* features) + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static void *DR_LV2_Load_Thread( DRT_LV2_Base *LV2_Base_Ptr) { + +// drmr_sample *loaded_samples,*old_samples; + DRT_Sample *loaded_samples = NULL, *old_samples = NULL; + int loaded_count, old_scount; + char *request, *request_orig; + + + fprintf( stderr, "Start Load Thread!\n"); + + return(0); + + for(;;) + { + pthread_mutex_lock( &( LV2_Base_Ptr->Load_Mutex)); + pthread_cond_wait( &( LV2_Base_Ptr->Load_Cond), &( LV2_Base_Ptr->Load_Mutex)); + + fprintf( stderr, "Load_Thread: New load!\n"); + + pthread_mutex_unlock( &(LV2_Base_Ptr->Load_Mutex)); + +// old_samples = LV2_Base_Ptr->Samples; +// old_scount = LV2_Base_Ptr->Num_Samples; + + request_orig = request = LV2_Base_Ptr->Request_Buf[ LV2_Base_Ptr->CurReq]; + + if( !strncmp( request, "file://", 7)) + { + request += 7; + } + +// loaded_samples = load_hydrogen_kit(request,drmr->rate,&loaded_count); + + if( !loaded_samples) + { + fprintf(stderr,"Failed to load kit at: %s\n",request); + + pthread_mutex_lock( &(LV2_Base_Ptr->Load_Mutex)); + +// LV2_Base_Ptr->Num_Samples = 0; +// LV2_Base_Ptr->Samples = NULL; + + pthread_mutex_unlock( &(LV2_Base_Ptr->Load_Mutex)); + } + else + { + // just lock for the critical moment when we swap in the new kit + printf( "loaded kit at: %s\n", request); + + pthread_mutex_lock( &(LV2_Base_Ptr->Load_Mutex)); + +// LV2_Base_Ptr->Samples = loaded_samples; +// LV2_Base_Ptr->Num_Samples = loaded_count; + + pthread_mutex_unlock( &(LV2_Base_Ptr->Load_Mutex)); + } + +// if( old_scount > 0) free_samples( old_samples, old_scount); + + LV2_Base_Ptr->Current_Path = request_orig; + current_kit_changed = 1; + } + + return 0; +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ +/* +static inline LV2_Atom *build_update_message(DrMr *drmr) +{ + LV2_Atom_Forge_Frame set_frame; + LV2_Atom *msg = (LV2_Atom *)lv2_atom_forge_object( &drmr->forge, &set_frame, 1, drmr->uris.ui_msg); + + + if (drmr->current_path) + { + lv2_atom_forge_property_head( &drmr->forge, drmr->uris.kit_path, 0); + lv2_atom_forge_string( &drmr->forge, drmr->current_path, strlen(drmr->current_path)); + } + + lv2_atom_forge_pop( &drmr->forge,&set_frame); + + return msg; +} +*/ + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ +/* +static inline LV2_Atom *build_state_message(DrMr *drmr) +{ + LV2_Atom_Forge_Frame set_frame; + LV2_Atom *msg = (LV2_Atom *)lv2_atom_forge_object( &drmr->forge, &set_frame, 1, drmr->uris.get_state); + + + if( drmr->current_path) + { + lv2_atom_forge_property_head( &drmr->forge, drmr->uris.kit_path, 0); + lv2_atom_forge_string( &drmr->forge, drmr->current_path, strlen( drmr->current_path)); + } + + lv2_atom_forge_property_head(&drmr->forge, drmr->uris.velocity_toggle,0); + lv2_atom_forge_bool(&drmr->forge, drmr->ignore_velocity?true:false); + lv2_atom_forge_property_head(&drmr->forge, drmr->uris.note_off_toggle,0); + lv2_atom_forge_bool(&drmr->forge, drmr->ignore_note_off?true:false); + lv2_atom_forge_property_head(&drmr->forge, drmr->uris.channel_nb,0); + lv2_atom_forge_int(&drmr->forge, drmr->channel_nb); + lv2_atom_forge_property_head(&drmr->forge, drmr->uris.zero_position,0); + lv2_atom_forge_int(&drmr->forge, drmr->zero_position); + lv2_atom_forge_pop(&drmr->forge,&set_frame); + + return msg; +} +*/ + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static inline LV2_Atom *DR_LV2_Message_Midi_Info_Build( DRT_LV2_Base *LV2_Base_Ptr, uint8_t *Data) +{ + LV2_Atom_Forge_Frame set_frame; + LV2_Atom *msg; + + + msg = (LV2_Atom *)lv2_atom_forge_object( &( LV2_Base_Ptr->Forge), &set_frame, 1, LV2_Base_Ptr->URIS.midi_info); + lv2_atom_forge_property_head( &( LV2_Base_Ptr->Forge), LV2_Base_Ptr->URIS.midi_event, 0); + lv2_atom_forge_write( &( LV2_Base_Ptr->Forge), Data, 3); + lv2_atom_forge_pop( &( LV2_Base_Ptr->Forge), &set_frame); + + return( msg); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +DRT_Status DR_LV2_Kit_Sample_Load( DRT_LV2_Base *LV2_Base_Ptr, DRT_Kit *Kit_Ptr) +{ + DRT_Status status; + NDT_Node *cur_node_ptr; + int sample_id = 0; + + + if( Kit_Ptr != NULL) + { + fprintf( stderr, "Sample Rate: (%lf)\n", LV2_Base_Ptr->Base.SampleRate); + + if( ( status = DR_Kit_Sample_Load( Kit_Ptr, LV2_Base_Ptr->Base.SampleRate)) == DRS_OK) + { + LV2_Base_Ptr->Kit_Cur_Ptr = Kit_Ptr; + + cur_node_ptr = Kit_Ptr->Instrument_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head; + + for( sample_id = 0; sample_id < DRD_PORT_NUMBER_MAX; sample_id++) + { + LV2_Base_Ptr->Samples[sample_id].Active = 0; + LV2_Base_Ptr->Samples[sample_id].Offset = 0; + LV2_Base_Ptr->Samples[sample_id].Limit = 0; + LV2_Base_Ptr->Samples[sample_id].Velocity = 0; + LV2_Base_Ptr->Samples[sample_id].Layer_Ptr = 0; + LV2_Base_Ptr->Samples[sample_id].Data_Ptr = NULL; + LV2_Base_Ptr->Samples[sample_id].Data_Offset = 0; + + if( cur_node_ptr == NULL) + { + fprintf( stderr, "Skip sample\n"); + LV2_Base_Ptr->Samples[sample_id].Instrument_Ptr = NULL; + } + else + { + LV2_Base_Ptr->Samples[sample_id].Instrument_Ptr = (DRT_Instrument *)cur_node_ptr->Value; + cur_node_ptr = cur_node_ptr->Right; + + fprintf( stderr, "Add sample: [%s]\n", LV2_Base_Ptr->Samples[sample_id].Instrument_Ptr->Name); + } + } + + LV2_Base_Ptr->Sample_Number = Kit_Ptr->Instrument_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; + fprintf( stderr, "Loaded: (%d) samples!\n", LV2_Base_Ptr->Sample_Number); + + DR_Kit_Dump( Kit_Ptr, 0); + } + } + + return( status); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +DRT_Status DR_LV2_CurKit_Sample_Load( DRT_LV2_Base *LV2_Base_Ptr) +{ + DRT_Status status; + DRT_Kit *Kit_Ptr; + DRT_Kit_Id kit_id; + + + kit_id = ( LV2_Base_Ptr->Bank_Id_LSB_New * 128 + LV2_Base_Ptr->Bank_Id_MSB_New) * 128 + LV2_Base_Ptr->Program_Id_New; + + if( kit_id == LV2_Base_Ptr->Kit_Id) + { + fprintf( stderr, "Same Kit id: (%d) Bank/Program: (%d/%d/%d)!\n", kit_id, LV2_Base_Ptr->Bank_Id_LSB_New, LV2_Base_Ptr->Bank_Id_MSB_New, LV2_Base_Ptr->Program_Id_New); + status = DRS_OK; + } + else + { + if( ( status = DR_Kit_Id_Find( &Kit_Ptr, LV2_Base_Ptr->Base.Kit_DS_Ptr, kit_id)) == DRS_OK) + { + fprintf( stderr, "New Kit id: (%d) Bank/Program: (%d/%d/%d)!\n", kit_id, LV2_Base_Ptr->Bank_Id_LSB_New, LV2_Base_Ptr->Bank_Id_MSB_New, LV2_Base_Ptr->Program_Id_New); + + LV2_Base_Ptr->Bank_Id_LSB = LV2_Base_Ptr->Bank_Id_LSB_New; + LV2_Base_Ptr->Bank_Id_MSB = LV2_Base_Ptr->Bank_Id_MSB_New; + LV2_Base_Ptr->Program_Id = LV2_Base_Ptr->Program_Id_New; + LV2_Base_Ptr->Kit_Id = kit_id; + LV2_Base_Ptr->Kit_Cur_Ptr = Kit_Ptr; + + status = DR_LV2_Kit_Sample_Load( LV2_Base_Ptr, Kit_Ptr); + } + } + + return( status); +} + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ +/* +static inline void layer_to_sample( drmr_sample *sample, float gain) +{ + int i; + float mapped_gain = ( 1 - ( gain / GAIN_MIN)); + + + if( mapped_gain > 1.0f) mapped_gain = 1.0f; + + for( i = 0; i < sample->layer_count; i++) + { + if( sample->layers[i].min <= mapped_gain && + (sample->layers[i].max > mapped_gain || + (sample->layers[i].max == 1 && mapped_gain == 1))) + { + sample->limit = sample->layers[i].limit; + sample->info = sample->layers[i].info; + sample->data = sample->layers[i].data; + return; + } + } + + fprintf(stderr,"Couldn't find layer for gain %f in sample\n\n",gain); + // to avoid not playing something, and to deal with kits like the + // k-27_trash_kit, let's just use the first layer + + sample->limit = sample->layers[0].limit; + sample->info = sample->layers[0].info; + sample->data = sample->layers[0].data; +} +*/ + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static inline void DR_Layer_To_Sample( DRT_Sample *Sample_Ptr, float Gain) +{ + NDT_Node *first_node_ptr, *cur_node_ptr; + DRT_Layer *cur_layer_ptr; + int i = 0; + DRT_Boolean found = DRD_FALSE; +// float mapped_gain = ( 1 - ( Gain / DRD_GAIN_MIN)); + float mapped_gain = Gain; + + + if( mapped_gain > 1.0f) mapped_gain = 1.0f; + + first_node_ptr = Sample_Ptr->Instrument_Ptr->Layer_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head; + cur_node_ptr = first_node_ptr; + + while( ( cur_node_ptr != NULL) && ( found == DRD_FALSE)) + { + cur_layer_ptr = (DRT_Layer *)cur_node_ptr->Value; + + if( ( cur_layer_ptr->Min <= mapped_gain) && + ( ( cur_layer_ptr->Max > mapped_gain) || ( ( cur_layer_ptr->Max == 1) && ( mapped_gain == 1)))) + { + found = DRD_TRUE; + } + else + { + cur_node_ptr = cur_node_ptr->Right; + i++; + } + } + + if( cur_node_ptr == NULL) + { + cur_node_ptr = first_node_ptr; + cur_layer_ptr = (DRT_Layer *)cur_node_ptr->Value; + i=0; + } + + Sample_Ptr->Layer_Ptr = cur_layer_ptr; + Sample_Ptr->Data_Ptr = cur_layer_ptr->Sample_Ptr; + Sample_Ptr->Limit = cur_layer_ptr->Sample_Size; + Sample_Ptr->SF_Info_Ptr = cur_layer_ptr->SF_Info_Ptr; + + fprintf( stderr, "Layer: (%d) MGain: (%f) Gain: (%f)\n", i, mapped_gain, Gain); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static inline void DR_Sample_Trigger( DRT_LV2_Base *LV2_Base_Ptr, int Sample_Id, uint8_t *const Data, uint32_t Offset) +{ + // need to mutex this to avoid getting the samples array + // changed after the check that the midi-note is valid + pthread_mutex_lock( &( LV2_Base_Ptr->Load_Mutex)); + + fprintf( stderr, "Trigger Sample: Id: (%d) Offset: (%d)\n", Sample_Id, Offset); + + + if( ( Sample_Id >= 0) && ( Sample_Id < LV2_Base_Ptr->Sample_Number)) + { + if( Data) + { + lv2_atom_forge_frame_time( &( LV2_Base_Ptr->Forge), 0); + DR_LV2_Message_Midi_Info_Build( LV2_Base_Ptr, Data); + } + + LV2_Base_Ptr->Samples[Sample_Id].Active = 1; + LV2_Base_Ptr->Samples[Sample_Id].Offset = 0; + LV2_Base_Ptr->Samples[Sample_Id].Velocity = LV2_Base_Ptr->Ignore_Velocity ? 1.0f : ( (float)Data[2]) / DRD_VELOCITY_MAX; + LV2_Base_Ptr->Samples[Sample_Id].Data_Offset = Offset; + + if( LV2_Base_Ptr->Samples[Sample_Id].Instrument_Ptr->Layer_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number > 0) + { + // drmr currently has 32 hard-coded gains so just use the last gain + // to prevent a segfault + int gain_idx = Sample_Id < 32 ? Sample_Id : 31; + +// DR_Layer_To_Sample( &(LV2_Base_Ptr->Samples[Sample_Id]), *( LV2_Base_Ptr->Gains[ gain_idx])); + DR_Layer_To_Sample( &(LV2_Base_Ptr->Samples[Sample_Id]), LV2_Base_Ptr->Samples[Sample_Id].Velocity); + + if( LV2_Base_Ptr->Samples[Sample_Id].Limit == 0) + fprintf(stderr,"Failed to find layer at: %i for %f\n", Sample_Id, *( LV2_Base_Ptr->Gains[ gain_idx])); + } + } + + pthread_mutex_unlock( &( LV2_Base_Ptr->Load_Mutex)); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static inline void DR_Sample_Untrigger( DRT_LV2_Base *LV2_Base_Ptr, int Sample_Id, uint32_t Offset) +{ + pthread_mutex_lock( &( LV2_Base_Ptr->Load_Mutex)); + + fprintf( stderr, "UnTrigger Sample: Id: (%d) Offset: (%d)\n", Sample_Id, Offset); + +/* + if (nn >= 0 && nn < drmr->num_samples) { + if (drmr->samples[nn].layer_count > 0) { + layer_to_sample(drmr->samples+nn,*(drmr->gains[nn])); + if (drmr->samples[nn].limit == 0) + fprintf(stderr,"Failed to find layer at: %i for %f\n",nn,*drmr->gains[nn]); + } + drmr->samples[nn].active = 0; + drmr->samples[nn].dataoffset = offset; + } +*/ + LV2_Base_Ptr->Samples[Sample_Id].Active = 0; + LV2_Base_Ptr->Samples[Sample_Id].Data_Offset = Offset; + + pthread_mutex_unlock( &( LV2_Base_Ptr->Load_Mutex)); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static LV2_Handle DR_LV2_Instantiate( const LV2_Descriptor *LV2_Descriptor_Ptr, + double Rate, + const char *Bundle_Path, + const LV2_Feature* const *LV2_Features_Ptr) +{ + DRT_Status status; + int i; + DRT_LV2_Base *lv2_base_ptr; + + + fprintf( stderr, "LV2 Instantiate\n"); + + if( ( lv2_base_ptr = malloc( sizeof( DRT_LV2_Base))) == NULL) + { + fprintf( stderr, "Can't allocate LV2 Base!\n"); + return( (LV2_Handle)NULL); + } + + + lv2_base_ptr->Kit_Cur_Ptr = NULL; + lv2_base_ptr->Bank_Id_LSB = -1; + lv2_base_ptr->Bank_Id_LSB = -1; + lv2_base_ptr->Program_Id = -1; + lv2_base_ptr->Bank_Id_LSB_New = 0; + lv2_base_ptr->Bank_Id_MSB_New = 0; + lv2_base_ptr->Program_Id_New = 0; + lv2_base_ptr->Kit_Id = -1; + lv2_base_ptr->Current_Path = NULL; + lv2_base_ptr->CurReq = -1; + + lv2_base_ptr->Ignore_Velocity = false; + lv2_base_ptr->Ignore_Note_Off = true; +// lv2_base_ptr->Ignore_Note_Off = false; + lv2_base_ptr->Channel_Nb = 0; + lv2_base_ptr->Zero_Position = 0; + + lv2_base_ptr->Sample_Number = 0; + + while( *LV2_Features_Ptr != NULL) + { + if( !strcmp( (*LV2_Features_Ptr)->URI, LV2_URID_URI "#map")) + { + lv2_base_ptr->Map_Ptr = (LV2_URID_Map *)((*LV2_Features_Ptr)->data); + } + + LV2_Features_Ptr++; + } + + if( lv2_base_ptr->Map_Ptr == NULL) + { + fprintf( stderr, "LV2 host does not support urid#map!\n"); + } + else + { + if( pthread_mutex_init( &( lv2_base_ptr->Load_Mutex), 0)) + { + fprintf( stderr, "Could not initialize load_mutex!\n"); + } + else if( pthread_cond_init( &( lv2_base_ptr->Load_Cond), 0)) + { + fprintf( stderr, "Could not initialize load_cond!\n"); + } + else + { + DR_Map_Drummer_URIS( lv2_base_ptr->Map_Ptr, &(lv2_base_ptr->URIS)); + + lv2_atom_forge_init( &(lv2_base_ptr->Forge), lv2_base_ptr->Map_Ptr); + + if( pthread_create( &lv2_base_ptr->Load_Thread, 0, (void * (*)(void *))DR_LV2_Load_Thread, lv2_base_ptr)) + { + fprintf( stderr, "Could not initialize loading thread!\n"); + } + else + { + if( ( lv2_base_ptr->Request_Buf = malloc( DRD_REQ_BUF_SIZE * sizeof(char *))) == NULL) + { + fprintf( stderr, "Cant'allocate Request buffer!\n"); + } + else + { + memset( lv2_base_ptr->Request_Buf, 0, DRD_REQ_BUF_SIZE * sizeof(char *)); + + if( ( lv2_base_ptr->Left = malloc( DRD_PORT_NUMBER_MAX * sizeof(float *))) == NULL) + { + fprintf( stderr, "Cant'allocate Left buffer!\n"); + free( lv2_base_ptr); + + return( NULL); + } + else + { + if( ( lv2_base_ptr->Right = malloc( DRD_PORT_NUMBER_MAX * sizeof(float *))) == NULL) + { + fprintf( stderr, "Cant'allocate Right buffer!\n"); + } + else + { + if( ( lv2_base_ptr->Gains = malloc( DRD_PORT_NUMBER_MAX * sizeof(float *))) == NULL) + { + fprintf( stderr, "Cant'allocate Gains buffer!\n"); + } + else + { + if( ( lv2_base_ptr->Pans = malloc( DRD_PORT_NUMBER_MAX * sizeof(float *))) == NULL) + { + fprintf( stderr, "Cant'allocate Pans buffer!\n"); + } + else + { + for( i = 0; i < 32; i++) + { + lv2_base_ptr->Gains[i] = NULL; + lv2_base_ptr->Pans[i] = NULL; + } + + if( ( status = DR_DataStruct_Init( &( lv2_base_ptr->Base), Rate)) != DRS_OK) + { + fprintf( stderr, "Can't init data structures (%d) !", status); + } + else + { + if( ( status = DR_Kits_Load( & ( lv2_base_ptr->Base))) != DRS_OK) + { + fprintf( stderr, "Can't load kits (%d) !", status); + } + else + { + if( ( status = DR_LV2_CurKit_Sample_Load( lv2_base_ptr)) != DRS_OK) + { + fprintf( stderr, "Can't load kit sample (%d) !", status); + } + else + { + return( (LV2_Handle)lv2_base_ptr); + } + } + + DR_DataStruct_DeInit( &( lv2_base_ptr->Base)); + } + } + + free( lv2_base_ptr->Gains); + } + + free( lv2_base_ptr->Right); + + } + + free( lv2_base_ptr->Left); + } + + free( lv2_base_ptr->Request_Buf); + } + } + } + } + + free( lv2_base_ptr); + + return( (LV2_Handle)NULL); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static void DR_LV2_Connect_Port( LV2_Handle Instance_Ptr, uint32_t Port_Id, void *Data_Ptr) +{ + DRT_LV2_Base *lv2_base_ptr = (DRT_LV2_Base *)Instance_Ptr; + DRT_Port_Index port_index = (DRT_Port_Index)Port_Id; + + +// fprintf( stderr, "LV2 Connect Port (%d)!\n", Port_Id); + + switch( port_index) + { + case DRD_LV2_CONTROL: + { + lv2_base_ptr->Control_Port = (LV2_Atom_Sequence *)Data_Ptr; + break; + } + + case DRD_LV2_CORE_EVENT: + { + lv2_base_ptr->Core_Event_Port = (LV2_Atom_Sequence *)Data_Ptr; + break; + } + + case DRD_LV2_BASENOTE: + { + if( Data_Ptr) lv2_base_ptr->BaseNote = (float *)Data_Ptr; + break; + } + + default: + { + if( port_index == DRD_LV2_MASTER_LEFT) + { + lv2_base_ptr->Master_Left = (float *)Data_Ptr; + } + else if( port_index == DRD_LV2_MASTER_RIGHT) + { + lv2_base_ptr->Master_Right = (float *)Data_Ptr; + } + else if( port_index >= DRD_LV2_LEFT_00 && port_index <= DRD_LV2_RIGHT_31) + { + int outoff = (port_index - DRD_LV2_LEFT_00) / 2; + + if( ( port_index - DRD_LV2_LEFT_00) % 2) + { + lv2_base_ptr->Right[outoff] = (float *)Data_Ptr; + } + else + { + lv2_base_ptr->Left[outoff] = (float *)Data_Ptr; + } + } + else if( port_index >= DRD_LV2_GAIN_00 && port_index <= DRD_LV2_GAIN_31) + { + int goff = port_index - DRD_LV2_GAIN_00; + lv2_base_ptr->Gains[goff] = (float *)Data_Ptr; + } + else if( port_index >= DRD_LV2_PAN_00 && port_index <= DRD_LV2_PAN_31) + { + int poff = port_index - DRD_LV2_PAN_00; + lv2_base_ptr->Pans[poff] = (float *)Data_Ptr; + } + else + { + fprintf( stderr, "LV2 Connect Port: unknown port: (%d)!\n", Port_Id); + } + + break; + } + } +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static void DR_LV2_Run( LV2_Handle Instance_Ptr, uint32_t N_Samples) +{ + DRT_Status status; + int i, j, basenote; + DRT_LV2_Base *lv2_base_ptr = (DRT_LV2_Base *)Instance_Ptr; + + +// fprintf( stderr, "LV2 Run!\n"); + + basenote = (int)floorf( *( lv2_base_ptr->BaseNote)); + + const uint32_t event_capacity = lv2_base_ptr->Core_Event_Port->atom.size; + + lv2_atom_forge_set_buffer( &lv2_base_ptr->Forge, (uint8_t *)lv2_base_ptr->Core_Event_Port, event_capacity); + + LV2_Atom_Forge_Frame seq_frame; + lv2_atom_forge_sequence_head( &(lv2_base_ptr->Forge), &seq_frame, 0); + + LV2_ATOM_SEQUENCE_FOREACH( lv2_base_ptr->Control_Port, ev_ptr) + { + fprintf( stderr, "LV2 Event!\n"); + + if( ev_ptr->body.type == lv2_base_ptr->URIS.midi_event) + { + uint8_t nn; + uint8_t *const data = (uint8_t *const)(ev_ptr + 1); + uint32_t offset = ( ev_ptr->time.frames > 0 && ev_ptr->time.frames < N_Samples) ? ev_ptr->time.frames : 0; + uint8_t channel = *data & 15; + uint8_t controler; + uint8_t value; + + + fprintf( stderr, " Midi Event!\n"); + + if( ( lv2_base_ptr->Channel_Nb == 0) || ( channel == ( lv2_base_ptr->Channel_Nb - 1))) + { + switch( ( *data) >> 4) + { + case 8: // Note Off + { + if( !lv2_base_ptr->Ignore_Note_Off) + { + nn = data[1]; + nn -= basenote; + + DR_Sample_Untrigger( lv2_base_ptr, nn, offset); + } + + break; + } + + case 9: // Note On + { + nn = data[1]; + nn -= basenote; + + DR_Sample_Trigger( lv2_base_ptr, nn, data, offset); + + break; + } + + case 11: // Control Change + { + controler = data[1]; + value = data[2]; + + switch( controler) + { + case 0: // Bank MSB Select + { + fprintf( stderr, "Bank MSB select: (%d)!\n", value); + + lv2_base_ptr->Bank_Id_MSB_New = value; + break; + } + + case 32: // Bank LSB Select + { + fprintf( stderr, "Bank LSB select: (%d)!\n", value); + + lv2_base_ptr->Bank_Id_LSB_New = value; + break; + } + + default: + { + fprintf( stderr, "Unhandled controler: (%d) value: (%d)!\n", controler, value); + break; + } + } + + break; + } + + case 12: // Program Change + { + value = data[1]; + + fprintf( stderr, "Program change: (%d)!\n", value); + + lv2_base_ptr->Program_Id_New = value; + + if( ( status = DR_LV2_CurKit_Sample_Load( lv2_base_ptr)) != DRS_OK) + { + fprintf( stderr, "Can't load kit sample (%d) !", status); + } + + /* + int reqpos = ( lv2_base_ptr->CurReq + 1) % DRD_REQ_BUF_SIZE; + char *tmp = NULL; + + + if( reqpos >= 0 && lv2_base_ptr->Request_Buf[reqpos]) + tmp = lv2_base_ptr->Request_Buf[reqpos]; + lv2_base_ptr->Request_Buf[reqpos] = strdup( LV2_ATOM_BODY( lv2_base_ptr->Kit_Id)); + lv2_base_ptr->CurReq = reqpos; + + if( tmp) free(tmp); + + fprintf( stderr, "Path!\n"); + */ + + break; + } + + default: + { + fprintf( stderr, "Unhandeled status: (%i) Data 1: (%i) Data 2: (%d)\n", ( *data) >> 4, data[1], data[2]); + break; + } + } + } + } + else if( ev_ptr->body.type == lv2_base_ptr->URIS.atom_object) + { + fprintf( stderr, "LV2 AO...\n"); + + const LV2_Atom_Object *obj_ptr = (LV2_Atom_Object *)&(ev_ptr->body); + + if( obj_ptr->body.otype == lv2_base_ptr->URIS.ui_msg) + { + const LV2_Atom *path = NULL; + const LV2_Atom *trigger = NULL; + const LV2_Atom *ignvel = NULL; + const LV2_Atom *ignno = NULL; + const LV2_Atom *channel_nb = NULL; + const LV2_Atom *zerop = NULL; + const LV2_Atom *sample_add = NULL; + const LV2_Atom *sample_remove = NULL; + + + lv2_atom_object_get( obj_ptr, + lv2_base_ptr->URIS.kit_path, &path, + lv2_base_ptr->URIS.sample_trigger, &trigger, + lv2_base_ptr->URIS.velocity_toggle, &ignvel, + lv2_base_ptr->URIS.note_off_toggle, &ignno, + lv2_base_ptr->URIS.channel_nb, &channel_nb, + lv2_base_ptr->URIS.zero_position, &zerop, + lv2_base_ptr->URIS.sample_add, &sample_add, + lv2_base_ptr->URIS.sample_remove, &sample_remove, + 0); + + if( path) + { + int reqpos = ( lv2_base_ptr->CurReq + 1) % DRD_REQ_BUF_SIZE; + char *tmp = NULL; + + + if( reqpos >= 0 && lv2_base_ptr->Request_Buf[reqpos]) + tmp = lv2_base_ptr->Request_Buf[reqpos]; + lv2_base_ptr->Request_Buf[reqpos] = strdup( LV2_ATOM_BODY( path)); + lv2_base_ptr->CurReq = reqpos; + + if( tmp) free(tmp); + + fprintf( stderr, "Path!\n"); + } + + if( trigger) + { + int32_t si = ( ( const LV2_Atom_Int *)trigger)->body; + uint8_t mdata[3]; + uint32_t offset = ( ev_ptr->time.frames > 0 && ev_ptr->time.frames < N_Samples) ? ev_ptr->time.frames : 0; + + fprintf(stderr, "Trigger event!\n"); + + mdata[0] = 0x90; // note on + mdata[1] = si + basenote; + mdata[2] = 0x7f; + + DR_Sample_Trigger( lv2_base_ptr, si, mdata, offset); + } + + if( ignvel) + lv2_base_ptr->Ignore_Velocity = ((const LV2_Atom_Bool*)ignvel)->body; + + if( ignno) + lv2_base_ptr->Ignore_Note_Off = ((const LV2_Atom_Bool*)ignno)->body; + + if( channel_nb) + lv2_base_ptr->Channel_Nb = ((const LV2_Atom_Int*)channel_nb)->body; + + if( zerop) + lv2_base_ptr->Zero_Position = ((const LV2_Atom_Int*)zerop)->body; + + if( sample_add) + { + fprintf(stderr, "Sample Add event!\n"); + + lv2_atom_forge_frame_time( &lv2_base_ptr->Forge, 0); +// build_update_message( lv2_base_ptr); + } + + if( sample_remove) + { + fprintf(stderr, "Sample Remove event (%d)\n", ( ( const LV2_Atom_Int *)sample_remove)->body); + + lv2_atom_forge_frame_time( &(lv2_base_ptr->Forge), 0); +// build_update_message( lv2_base_ptr); + } + + fprintf( stderr, "LV2 AO End!\n"); + } + else if( obj_ptr->body.otype == lv2_base_ptr->URIS.get_state) + { + lv2_atom_forge_frame_time( &(lv2_base_ptr->Forge), 0); +// build_state_message( lv2_base_ptr); + } + } + else + { + fprintf( stderr, "unrecognized event (%d) != (%d)\n", ev_ptr->body.type, lv2_base_ptr->URIS.atom_object); + } + } +/* + if( ( lv2_base_ptr->curReq >= 0) && + lv2_base_ptr->request_buf[lv2_base_ptr->curReq] && + ( !lv2_base_ptr->Current_Path || strcmp( lv2_base_ptr->Current_Path, lv2_base_ptr->Request_Buf[lv2_base_ptr->Cur_Req]))) + { + pthread_cond_signal( &( lv2_base_ptr->Load_Cond)); + } +*/ +/* + if( current_kit_changed) + { + current_kit_changed = 0; + lv2_atom_forge_frame_time( &drmr->forge, 0); + build_update_message( drmr); + + fprintf(stderr, "Kit Changes!\n"); + } +*/ + lv2_atom_forge_pop( &( lv2_base_ptr->Forge), &seq_frame); + + pthread_mutex_lock( &( lv2_base_ptr->Load_Mutex)); + + for( j = 0; j < N_Samples; j++) + { + lv2_base_ptr->Master_Left[j] = 0.0f; + lv2_base_ptr->Master_Right[j] = 0.0f; + } + + for( i = 0; i < lv2_base_ptr->Sample_Number; i++) + { + int pos,lim; + DRT_Sample *cur_sample = lv2_base_ptr->Samples + i; + + + if( ( cur_sample->Active || cur_sample->Data_Offset) && ( cur_sample->Limit > 0)) + { + float coef_right, coef_left; + + +// fprintf( stderr, "."); + + if( i < 32) + { + float gain = DRD_DB_CO( *( lv2_base_ptr->Gains[i])); + float pan_right = ( ( *( lv2_base_ptr->Pans[i])) + 1 ) / 2.0f; + float pan_left = 1 - pan_right; + + + coef_right = ( pan_right * ( DRD_DB3SCALE * pan_right + DRD_DB3SCALEPO)) * gain * cur_sample->Velocity; + coef_left = ( pan_left * ( DRD_DB3SCALE * pan_left + DRD_DB3SCALEPO)) * gain * cur_sample->Velocity; + } + else + { + coef_right = coef_left = 1.0f; + } + + int data_start, data_end; + + + if( cur_sample->Active) + { + data_start = cur_sample->Data_Offset; + data_end = N_Samples; + } + else + { + data_start = 0; + data_end = cur_sample->Data_Offset; + } + cur_sample->Data_Offset = 0; + + for( j = 0; j < N_Samples; j++) + { + lv2_base_ptr->Left[i][j] = 0.0f; + lv2_base_ptr->Right[i][j] = 0.0f; + } + + if( cur_sample->SF_Info_Ptr->channels == 1) + { // play mono sample + lim = ( N_Samples < ( cur_sample->Limit - cur_sample->Offset) ? N_Samples : ( cur_sample->Limit - cur_sample->Offset)); + + for( pos = data_start; ( pos < lim) && ( pos < data_end); pos++) + { + lv2_base_ptr->Master_Left[pos] += cur_sample->Data_Ptr[ cur_sample->Offset] * coef_left; + lv2_base_ptr->Left[i][pos] += cur_sample->Data_Ptr[ cur_sample->Offset] * coef_left; + + lv2_base_ptr->Master_Right[pos] += cur_sample->Data_Ptr[ cur_sample->Offset] * coef_right; + lv2_base_ptr->Right[i][pos] += cur_sample->Data_Ptr[ cur_sample->Offset] * coef_right; + + cur_sample->Offset++; + } + } + else + { // play stereo sample + lim = ( cur_sample->Limit - cur_sample->Offset) / cur_sample->SF_Info_Ptr->channels; + + if( lim > N_Samples) lim = N_Samples; + + for( pos = data_start; ( pos < lim) && ( pos < data_end); pos++) + { + lv2_base_ptr->Master_Left[pos] += cur_sample->Data_Ptr[ cur_sample->Offset] * coef_left; + lv2_base_ptr->Left[i][pos] += cur_sample->Data_Ptr[ cur_sample->Offset++] * coef_left; + + lv2_base_ptr->Master_Right[pos] += cur_sample->Data_Ptr[ cur_sample->Offset] * coef_right; + lv2_base_ptr->Right[i][pos] += cur_sample->Data_Ptr[ cur_sample->Offset++] * coef_right; + } + } + + if( cur_sample->Offset >= cur_sample->Limit) cur_sample->Active = 0; + } + } + + pthread_mutex_unlock( &( lv2_base_ptr->Load_Mutex)); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static void DR_LV2_Cleanup( LV2_Handle Instance_Ptr) +{ + DRT_Status status; + DRT_LV2_Base *lv2_base_ptr = (DRT_LV2_Base *)Instance_Ptr; + + + fprintf( stderr, "LV2 Cleanup!\n"); + + if( ( status = DR_DataStruct_DeInit( &( lv2_base_ptr->Base))) != DRS_OK) + { + printf( "Can't deinit data structures (%d)!\n", status); + } + + free( lv2_base_ptr->Gains); + free( lv2_base_ptr->Right); + free( lv2_base_ptr->Left); + free( lv2_base_ptr->Request_Buf); + free( lv2_base_ptr); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static LV2_State_Status DR_LV2_Save_State( LV2_Handle instance, + LV2_State_Store_Function store, + void *handle, + uint32_t flags, + const LV2_Feature *const *features) +{ + LV2_State_Status lv2_status = LV2_STATE_SUCCESS; + + + fprintf( stderr, "LV2 Save State!\n"); + return( lv2_status); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static LV2_State_Status DR_LV2_Restore_State( LV2_Handle instance, + LV2_State_Retrieve_Function retrieve, + void *handle, + uint32_t flags, + const LV2_Feature *const *features) +{ + LV2_State_Status lv2_status = LV2_STATE_SUCCESS; + + + fprintf( stderr, "LV2 Restore State!\n"); + return( lv2_status); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* LV2_State_Interface */ +/*----------------------------------------------------------------------------*/ + +static const LV2_State_Interface DRG_LV2_State_Interface = +{ + DR_LV2_Save_State, + DR_LV2_Restore_State +}; + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static const void *DR_LV2_Extension_Data( const char *uri) +{ + + + if( !strcmp( uri, LV2_STATE__interface)) + { + return &DRG_LV2_State_Interface; + } + + return NULL; +} + + + + + +/*----------------------------------------------------------------------------*/ +/* LV2_Descritor */ +/*----------------------------------------------------------------------------*/ + +static const LV2_Descriptor DRG_LV2_Descriptor = +{ + DRD_DRUMMER_URI, + DR_LV2_Instantiate, + DR_LV2_Connect_Port, + NULL, // activate + DR_LV2_Run, + NULL, // deactivate + DR_LV2_Cleanup, + DR_LV2_Extension_Data +}; + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +LV2_SYMBOL_EXPORT const LV2_Descriptor *lv2_descriptor( uint32_t index) +{ + switch (index) + { + case 0: + { + return &DRG_LV2_Descriptor; + } + + default: + { + return NULL; + } + } } diff --git a/lv2_plugin.h b/lv2_plugin.h index f9b103f..4a0a87d 100644 --- a/lv2_plugin.h +++ b/lv2_plugin.h @@ -26,9 +26,23 @@ // lv2 stuff -#define DRD_DRUMMER_URI "http://rx3.net/AlkorZ3/drummer" -#define DRD_GAIN_MIN -60.0f -#define DRD_GAIN_MAX 6.0f +#define DRD_DRUMMER_URI "http://rx3.net/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 @@ -102,70 +116,70 @@ typedef enum DRD_LV2_LEFT_31, DRD_LV2_RIGHT_31, DRD_LV2_BASENOTE, - DRD_LV2_GAIN_ONE, - DRD_LV2_GAIN_TWO, - DRD_LV2_GAIN_THREE, - DRD_LV2_GAIN_FOUR, - DRD_LV2_GAIN_FIVE, - DRD_LV2_GAIN_SIX, - DRD_LV2_GAIN_SEVEN, - DRD_LV2_GAIN_EIGHT, - DRD_LV2_GAIN_NINE, - DRD_LV2_GAIN_TEN, - DRD_LV2_GAIN_ELEVEN, - DRD_LV2_GAIN_TWELVE, - DRD_LV2_GAIN_THIRTEEN, - DRD_LV2_GAIN_FOURTEEN, - DRD_LV2_GAIN_FIFTEEN, - DRD_LV2_GAIN_SIXTEEN, - DRD_LV2_GAIN_SEVENTEEN, - DRD_LV2_GAIN_EIGHTEEN, - DRD_LV2_GAIN_NINETEEN, - DRD_LV2_GAIN_TWENTY, - DRD_LV2_GAIN_TWENTYONE, - DRD_LV2_GAIN_TWENTYTWO, - DRD_LV2_GAIN_TWENTYTHREE, - DRD_LV2_GAIN_TWENTYFOUR, - DRD_LV2_GAIN_TWENTYFIVE, - DRD_LV2_GAIN_TWENTYSIX, - DRD_LV2_GAIN_TWENTYSEVEN, - DRD_LV2_GAIN_TWENTYEIGHT, - DRD_LV2_GAIN_TWENTYNINE, - DRD_LV2_GAIN_THIRTY, - DRD_LV2_GAIN_THIRTYONE, - DRD_LV2_GAIN_THIRTYTWO, - DRD_LV2_PAN_ONE, - DRD_LV2_PAN_TWO, - DRD_LV2_PAN_THREE, - DRD_LV2_PAN_FOUR, - DRD_LV2_PAN_FIVE, - DRD_LV2_PAN_SIX, - DRD_LV2_PAN_SEVEN, - DRD_LV2_PAN_EIGHT, - DRD_LV2_PAN_NINE, - DRD_LV2_PAN_TEN, - DRD_LV2_PAN_ELEVEN, - DRD_LV2_PAN_TWELVE, - DRD_LV2_PAN_THIRTEEN, - DRD_LV2_PAN_FOURTEEN, - DRD_LV2_PAN_FIFTEEN, - DRD_LV2_PAN_SIXTEEN, - DRD_LV2_PAN_SEVENTEEN, - DRD_LV2_PAN_EIGHTEEN, - DRD_LV2_PAN_NINETEEN, - DRD_LV2_PAN_TWENTY, - DRD_LV2_PAN_TWENTYONE, - DRD_LV2_PAN_TWENTYTWO, - DRD_LV2_PAN_TWENTYTHREE, - DRD_LV2_PAN_TWENTYFOUR, - DRD_LV2_PAN_TWENTYFIVE, - DRD_LV2_PAN_TWENTYSIX, - DRD_LV2_PAN_TWENTYSEVEN, - DRD_LV2_PAN_TWENTYEIGHT, - DRD_LV2_PAN_TWENTYNINE, - DRD_LV2_PAN_THIRTY, - DRD_LV2_PAN_THIRTYONE, - DRD_LV2_PAN_THIRTYTWO, + DRD_LV2_GAIN_00, + DRD_LV2_GAIN_01, + DRD_LV2_GAIN_02, + DRD_LV2_GAIN_03, + DRD_LV2_GAIN_04, + DRD_LV2_GAIN_05, + DRD_LV2_GAIN_06, + DRD_LV2_GAIN_07, + DRD_LV2_GAIN_08, + DRD_LV2_GAIN_09, + DRD_LV2_GAIN_10, + DRD_LV2_GAIN_11, + DRD_LV2_GAIN_12, + DRD_LV2_GAIN_13, + DRD_LV2_GAIN_14, + DRD_LV2_GAIN_15, + DRD_LV2_GAIN_16, + DRD_LV2_GAIN_17, + DRD_LV2_GAIN_18, + DRD_LV2_GAIN_19, + DRD_LV2_GAIN_20, + DRD_LV2_GAIN_21, + DRD_LV2_GAIN_22, + DRD_LV2_GAIN_23, + DRD_LV2_GAIN_24, + DRD_LV2_GAIN_25, + DRD_LV2_GAIN_26, + DRD_LV2_GAIN_27, + DRD_LV2_GAIN_28, + DRD_LV2_GAIN_29, + DRD_LV2_GAIN_30, + DRD_LV2_GAIN_31, + DRD_LV2_PAN_00, + DRD_LV2_PAN_01, + DRD_LV2_PAN_02, + DRD_LV2_PAN_03, + DRD_LV2_PAN_04, + DRD_LV2_PAN_05, + DRD_LV2_PAN_06, + DRD_LV2_PAN_07, + DRD_LV2_PAN_08, + DRD_LV2_PAN_09, + DRD_LV2_PAN_10, + DRD_LV2_PAN_11, + DRD_LV2_PAN_12, + DRD_LV2_PAN_13, + DRD_LV2_PAN_14, + DRD_LV2_PAN_15, + DRD_LV2_PAN_16, + DRD_LV2_PAN_17, + DRD_LV2_PAN_18, + DRD_LV2_PAN_19, + DRD_LV2_PAN_20, + DRD_LV2_PAN_21, + DRD_LV2_PAN_22, + DRD_LV2_PAN_23, + DRD_LV2_PAN_24, + DRD_LV2_PAN_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; @@ -194,9 +208,38 @@ typedef struct } DRT_Drummer_URIS; - +/* typedef struct { + SF_INFO *Info; + char Active; + uint32_t Offset; + uint32_t Limit; + uint32_t Layer_Count; + float Velocity; +// drmr_layer *layers; + float *Data; + int Data_Offset; +} DRT_Sample; +*/ +typedef struct +{ + 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; +} DRT_Sample; + + +typedef struct DRT_LV2_Base +{ + DRT_Base Base; + // Ports float *Master_Left; float *Master_Right; @@ -206,10 +249,47 @@ typedef struct 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; + + // URIs + LV2_URID_Map *Map_Ptr; + DRT_Drummer_URIS URIS; + + // Kit info + DRT_Kit *Kit_Cur_Ptr; + 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; + DRT_Kit_Id Kit_Id; + 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 @@ -251,28 +331,29 @@ typedef struct pthread_cond_t load_cond; pthread_t load_thread; } DrMr; +*/ -static inline void map_drmr_uris( LV2_URID_Map *map, drmr_uris *uris) +static inline void DR_Map_Drummer_URIS( LV2_URID_Map *Map_Ptr, DRT_Drummer_URIS *URIS) { - uris->midi_event = map->map(map->handle, "http://lv2plug.in/ns/ext/midi#MidiEvent"); - uris->string_urid = map->map(map->handle, LV2_ATOM__String); - uris->bool_urid = map->map(map->handle, LV2_ATOM__Bool); - uris->int_urid = map->map(map->handle, LV2_ATOM__Int); - uris->ui_msg = map->map(map->handle, DRD_LV2_URI "#uimsg"); - uris->kit_path = map->map(map->handle, DRD_LV2_URI "#kitpath"); - uris->get_state = map->map(map->handle, DRD_LV2_URI "#getstate"); - uris->midi_info = map->map(map->handle, DRD_LV2_URI "#midiinfo"); - uris->sample_trigger = map->map(map->handle, DRD_LV2_URI "#sampletrigger"); - uris->velocity_toggle = map->map(map->handle, DRD_LV2_URI "#velocitytoggle"); - uris->note_off_toggle = map->map(map->handle, DRD_LV2_URI "#noteofftoggle"); - uris->channel_nb = map->map(map->handle, DRD_LV2_URI "#channelnb"); - uris->zero_position = map->map(map->handle, DRD_LV2_URI "#zeroposition"); - uris->sample_add = map->map(map->handle, DRD_LV2_URI "#sampleadd"); - uris->sample_remove = map->map(map->handle, DRD_LV2_URI "#sampleremove"); - uris->atom_eventTransfer = map->map(map->handle, LV2_ATOM__eventTransfer); - uris->atom_object = map->map(map->handle, LV2_ATOM__Object); + URIS->midi_event = Map_Ptr->map( Map_Ptr->handle, "http://lv2plug.in/ns/ext/midi#MidiEvent"); + URIS->string_urid = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__String); + URIS->bool_urid = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__Bool); + URIS->int_urid = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__Int); + URIS->ui_msg = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#uimsg"); + URIS->kit_path = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#kitpath"); + URIS->get_state = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#getstate"); + URIS->midi_info = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#midiinfo"); + URIS->sample_trigger = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#sampletrigger"); + URIS->velocity_toggle = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#velocitytoggle"); + URIS->note_off_toggle = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#noteofftoggle"); + URIS->channel_nb = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#channelnb"); + URIS->zero_position = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#zeroposition"); + URIS->sample_add = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#sampleadd"); + URIS->sample_remove = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#sampleremove"); + URIS->atom_eventTransfer = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__eventTransfer); + URIS->atom_object = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__Object); } @@ -289,8 +370,6 @@ static inline void map_drmr_uris( LV2_URID_Map *map, drmr_uris *uris) /* Private Definitions */ /*----------------------------------------------------------------------------*/ - - # endif // ifdef _LV2_PLUGIN_C_ @@ -313,6 +392,126 @@ static inline void map_drmr_uris( LV2_URID_Map *map, drmr_uris *uris) /* Private Prototypes */ /*----------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static void *DR_LV2_Load_Thread( DRT_LV2_Base *); + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static inline LV2_Atom *DR_LV2_Message_Midi_Info_Build( DRT_LV2_Base *, uint8_t *); + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +DRT_Status DR_LV2_Kit_Samples_Load( DRT_LV2_Base *, DRT_Kit *); + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +DRT_Status DR_LV2_CurKit_Samples_Load( DRT_LV2_Base *); + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static inline void DR_Layer_To_Sample( DRT_Sample *, float); + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static inline void DR_Sample_Trigger( DRT_LV2_Base *, int, uint8_t *const, uint32_t); + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static inline void DR_Sample_Untrigger( DRT_LV2_Base *, int, 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_Run( LV2_Handle, uint32_t); + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +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); + + + # endif // ifndef _LV2_PLUGIN_C_ diff --git a/node.h b/node.h index 7964390..27dd1d5 100644 --- a/node.h +++ b/node.h @@ -594,7 +594,7 @@ typedef struct NDT_Index long Max_Dif; /* Différence maximale autorisée entre la branche la plus courte et la plus longue */ long Nb_Equ; /* Nombre de réquilibrages réalisés sur l'arbre */ struct NDT_Node *Head; /* Noeud de tête */ - struct NDT_Node *Tail; /* Noeud de queue */ + struct NDT_Node *Tail; /* Noeud de queue */ struct NDT_Node *Save; /* Pointeur de sauvegarde (utile pour la fonction de restauration) */ } NDT_Index;